String

A character type.

Declaration

Syntax

String(int kind, expr? len, string_length_kind len_kind,
    string_physical_type physical_type)

Arguments

Argument

Description

kind

the character kind. Kind 1, a byte, is the only one supported.

len

the length, as an expression, or nil when len_kind says there is none to give.

len_kind

how the length is determined; see string_length_kind.

physical_type

how the value is represented; see StringPhysicalType.

Return values

None. A type is not evaluated.

Description

A Fortran character value is a sequence of bytes with a length, and the four ways of fixing that length are what len_kind distinguishes: a constant or runtime expression (ExpressionLength), inherited from the actual argument (AssumedLength), decided at allocation (DeferredLength), or implied by the operation that produced the value (ImplicitLength).

physical_type is separate from all of that: it says whether the value is carried as a descriptor or as a bare pointer, and StringPhysicalCast is what moves between the two without changing the logical type.

Examples

(String
  :kind 1
  :len (IntegerConstant
    :n 1
    :type (Integer
      :kind 4
    )
    :intboz_type :Decimal
  )
  :len_kind :ExpressionLength
  :physical_type :DescriptorString
)

It comes from this complete ASR text document:

(TranslationUnit
  :symtab (SymbolTable
    :id 0
    :symbols {
      "main" (Program
        :symtab (SymbolTable
          :id 1
          :symbols {
            "b" (Variable
              :parent_symtab 1
              :name "b"
              :dependencies []
              :intent :Local
              :symbolic_value nil
              :value nil
              :storage :Default
              :type (Logical
                :kind 4
              )
              :type_declaration nil
              :abi :Source
              :access :Public
              :presence :Required
              :value_attr false
              :target_attr false
              :contiguous_attr false
              :bindc_name nil
              :is_volatile false
              :is_protected false
              :pass_attr :NotMethod
              :self_argument nil
              :codims []
            )
            "c" (Variable
              :parent_symtab 1
              :name "c"
              :dependencies []
              :intent :Local
              :symbolic_value nil
              :value nil
              :storage :Default
              :type (String
                :kind 1
                :len (IntegerConstant
                  :n 1
                  :type (Integer
                    :kind 4
                  )
                  :intboz_type :Decimal
                )
                :len_kind :ExpressionLength
                :physical_type :DescriptorString
              )
              :type_declaration nil
              :abi :Source
              :access :Public
              :presence :Required
              :value_attr false
              :target_attr false
              :contiguous_attr false
              :bindc_name nil
              :is_volatile false
              :is_protected false
              :pass_attr :NotMethod
              :self_argument nil
              :codims []
            )
            "n" (Variable
              :parent_symtab 1
              :name "n"
              :dependencies []
              :intent :Local
              :symbolic_value nil
              :value nil
              :storage :Default
              :type (Integer
                :kind 4
              )
              :type_declaration nil
              :abi :Source
              :access :Public
              :presence :Required
              :value_attr false
              :target_attr false
              :contiguous_attr false
              :bindc_name nil
              :is_volatile false
              :is_protected false
              :pass_attr :NotMethod
              :self_argument nil
              :codims []
            )
            "s" (Variable
              :parent_symtab 1
              :name "s"
              :dependencies []
              :intent :Local
              :symbolic_value nil
              :value nil
              :storage :Default
              :type (String
                :kind 1
                :len (IntegerConstant
                  :n 5
                  :type (Integer
                    :kind 4
                  )
                  :intboz_type :Decimal
                )
                :len_kind :ExpressionLength
                :physical_type :DescriptorString
              )
              :type_declaration nil
              :abi :Source
              :access :Public
              :presence :Required
              :value_attr false
              :target_attr false
              :contiguous_attr false
              :bindc_name nil
              :is_volatile false
              :is_protected false
              :pass_attr :NotMethod
              :self_argument nil
              :codims []
            )
            "t" (Variable
              :parent_symtab 1
              :name "t"
              :dependencies []
              :intent :Local
              :symbolic_value nil
              :value nil
              :storage :Default
              :type (Allocatable
                :type (String
                  :kind 1
                  :len nil
                  :len_kind :DeferredLength
                  :physical_type :DescriptorString
                )
              )
              :type_declaration nil
              :abi :Source
              :access :Public
              :presence :Required
              :value_attr false
              :target_attr false
              :contiguous_attr false
              :bindc_name nil
              :is_volatile false
              :is_protected false
              :pass_attr :NotMethod
              :self_argument nil
              :codims []
            )
          }
        )
        :name "main"
        :dependencies []
        :body [
          (Assignment
            :target (Var
              :v (SymbolRef 1 "s")
            )
            :value (StringConstant
              :s "hello"
              :type (String
                :kind 1
                :len (IntegerConstant
                  :n 5
                  :type (Integer
                    :kind 4
                  )
                  :intboz_type :Decimal
                )
                :len_kind :ExpressionLength
                :physical_type :DescriptorString
              )
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
          (Assignment
            :target (Var
              :v (SymbolRef 1 "t")
            )
            :value (StringConcat
              :left (Var
                :v (SymbolRef 1 "s")
              )
              :right (StringConstant
                :s "!"
                :type (String
                  :kind 1
                  :len (IntegerConstant
                    :n 1
                    :type (Integer
                      :kind 4
                    )
                    :intboz_type :Decimal
                  )
                  :len_kind :ExpressionLength
                  :physical_type :DescriptorString
                )
              )
              :type (String
                :kind 1
                :len nil
                :len_kind :DeferredLength
                :physical_type :DescriptorString
              )
              :value nil
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
          (Assignment
            :target (Var
              :v (SymbolRef 1 "t")
            )
            :value (StringRepeat
              :left (Var
                :v (SymbolRef 1 "s")
              )
              :right (IntegerConstant
                :n 3
                :type (Integer
                  :kind 4
                )
                :intboz_type :Decimal
              )
              :type (String
                :kind 1
                :len nil
                :len_kind :DeferredLength
                :physical_type :DescriptorString
              )
              :value nil
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
          (Assignment
            :target (Var
              :v (SymbolRef 1 "n")
            )
            :value (StringLen
              :arg (Var
                :v (SymbolRef 1 "s")
              )
              :type (Integer
                :kind 4
              )
              :value nil
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
          (Assignment
            :target (Var
              :v (SymbolRef 1 "c")
            )
            :value (StringItem
              :arg (Var
                :v (SymbolRef 1 "s")
              )
              :idx (IntegerConstant
                :n 1
                :type (Integer
                  :kind 4
                )
                :intboz_type :Decimal
              )
              :type (String
                :kind 1
                :len (IntegerConstant
                  :n 1
                  :type (Integer
                    :kind 4
                  )
                  :intboz_type :Decimal
                )
                :len_kind :ExpressionLength
                :physical_type :DescriptorString
              )
              :value nil
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
          (Assignment
            :target (Var
              :v (SymbolRef 1 "t")
            )
            :value (StringSection
              :arg (Var
                :v (SymbolRef 1 "s")
              )
              :start (IntegerConstant
                :n 2
                :type (Integer
                  :kind 4
                )
                :intboz_type :Decimal
              )
              :end (IntegerConstant
                :n 4
                :type (Integer
                  :kind 4
                )
                :intboz_type :Decimal
              )
              :step (IntegerConstant
                :n 1
                :type (Integer
                  :kind 4
                )
                :intboz_type :Decimal
              )
              :type (String
                :kind 1
                :len (IntegerConstant
                  :n 3
                  :type (Integer
                    :kind 4
                  )
                  :intboz_type :Decimal
                )
                :len_kind :ExpressionLength
                :physical_type :DescriptorString
              )
              :value nil
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
          (Assignment
            :target (Var
              :v (SymbolRef 1 "b")
            )
            :value (StringCompare
              :left (Var
                :v (SymbolRef 1 "s")
              )
              :op :Eq
              :right (StringConstant
                :s "world"
                :type (String
                  :kind 1
                  :len (IntegerConstant
                    :n 5
                    :type (Integer
                      :kind 4
                    )
                    :intboz_type :Decimal
                  )
                  :len_kind :ExpressionLength
                  :physical_type :DescriptorString
                )
              )
              :type (Logical
                :kind 4
              )
              :value nil
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
          (Assignment
            :target (Var
              :v (SymbolRef 1 "b")
            )
            :value (StringContains
              :substr (StringConstant
                :s "ell"
                :type (String
                  :kind 1
                  :len (IntegerConstant
                    :n 3
                    :type (Integer
                      :kind 4
                    )
                    :intboz_type :Decimal
                  )
                  :len_kind :ExpressionLength
                  :physical_type :DescriptorString
                )
              )
              :str (Var
                :v (SymbolRef 1 "s")
              )
              :type (Logical
                :kind 4
              )
              :value nil
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
          (Assignment
            :target (Var
              :v (SymbolRef 1 "n")
            )
            :value (StringOrd
              :arg (Var
                :v (SymbolRef 1 "c")
              )
              :type (Integer
                :kind 4
              )
              :value nil
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
          (Assignment
            :target (Var
              :v (SymbolRef 1 "c")
            )
            :value (StringChr
              :arg (IntegerConstant
                :n 65
                :type (Integer
                  :kind 4
                )
                :intboz_type :Decimal
              )
              :type (String
                :kind 1
                :len (IntegerConstant
                  :n 1
                  :type (Integer
                    :kind 4
                  )
                  :intboz_type :Decimal
                )
                :len_kind :ExpressionLength
                :physical_type :DescriptorString
              )
              :value nil
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
          (Assignment
            :target (Var
              :v (SymbolRef 1 "n")
            )
            :value (Ichar
              :arg (Var
                :v (SymbolRef 1 "c")
              )
              :type (Integer
                :kind 4
              )
              :value nil
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
          (Assignment
            :target (Var
              :v (SymbolRef 1 "n")
            )
            :value (Iachar
              :arg (Var
                :v (SymbolRef 1 "c")
              )
              :type (Integer
                :kind 4
              )
              :value nil
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
        ]
      )
    }
  )
  :items []
)

See Also

StringPhysicalType, string_length_kind, StringConstant, StringPhysicalCast