StringFormat¶
A formatted string built from a format and a list of values.
Declaration¶
Syntax¶
StringFormat(expr? fmt, expr* args, string_format_kind kind,
ttype type, expr? value)
Arguments¶
Argument |
Description |
|---|---|
|
the format, or |
|
the values to format. |
|
which formatting language the format is written in; see string_format_kind. |
|
the string type of the result. |
|
the compile time value of the expression, when the frontend could fold it; |
Return values¶
The value of the expression.
Description¶
Formatting is an expression producing a string, not a property of the I/O statements. Print and FileWrite therefore carry a StringFormat rather than a format and an output list of their own, and a backend that can build the string has already implemented both.
kind distinguishes Fortran edit descriptors from C’s printf and from
Python’s several formatting languages, so one node serves every frontend.
Examples¶
(StringFormat
:fmt nil
:args [
(Var
:v (SymbolRef 1 "n")
)
]
:kind :FormatFortran
:type (String
:kind 1
:len nil
:len_kind :DeferredLength
:physical_type :DescriptorString
)
:value nil
)
It comes from this complete ASR text document:
(TranslationUnit
:symtab (SymbolTable
:id 0
:symbols {
"main" (Program
:symtab (SymbolTable
:id 1
:symbols {
"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 []
)
}
)
:name "main"
:dependencies []
:body [
(Print
:text (StringFormat
:fmt nil
:args [
(Var
:v (SymbolRef 1 "n")
)
]
:kind :FormatFortran
:type (String
:kind 1
:len nil
:len_kind :DeferredLength
:physical_type :DescriptorString
)
:value nil
)
)
]
)
}
)
:items []
)