"a{x}b{y}c"
Each part is modeled a sequence of expression. eg. ["a{, x, }b{, y, }c"]
nitc :: ASuperstringExpr :: _prefix
nitc :: ASuperstringExpr :: _suffix
nitc :: ASuperstringExpr :: defaultinit
nitc $ ASuperstringExpr :: SELF
Type of this instance, automatically specialized in every classnitc :: literal $ ASuperstringExpr :: accept_literal
nitc :: pretty $ ASuperstringExpr :: accept_pretty_printer
Start visit ofself
using a PrettyPrinterVisitor
nitc :: rapid_type_analysis $ ASuperstringExpr :: accept_rapid_type_visitor
nitc :: i18n_phase $ ASuperstringExpr :: accept_string_finder
nitc :: typing $ ASuperstringExpr :: accept_typing
nitc :: abstract_compiler $ ASuperstringExpr :: expr
Try to compile self as an expressionnitc :: naive_interpreter $ ASuperstringExpr :: expr
Evaluate the node as a possible expression.nitc :: ssa $ ASuperstringExpr :: generate_basic_blocks
Generate recursively basic block for this expressionnitc :: htmlight $ ASuperstringExpr :: make_tag
Optionally creates a tag that encapsulate the AST element on HTML renderingnitc :: pretty $ ASuperstringExpr :: must_be_inline
Doesself
have be rendered as a line?
nitc :: parser_prod $ ASuperstringExpr :: n_annotations=
All the annotations attached directly to the nodenitc :: parser_prod $ ASuperstringExpr :: replace_child
Replace a child with an other node in the ASTnitc :: parser_prod $ ASuperstringExpr :: visit_all
Visit all nodes in order.nitc :: AExpr :: _after_flow_context
The flow after the full evaluation of the expression/statementnitc :: AExpr :: _comprehension
Is non-null ifself
is a leaf of a comprehension array construction.
nitc :: AAugmentedLiteral :: _content
Content of the entity, without prefix nor suffixnitc :: AugmentedStringFormExpr :: _extended
Regex::extended, used for suffixb
on re
nitc :: Prod :: _first_location
Location on the first token after the start of a productionnitc :: Prod :: _first_token
The first token of the production in the ASTnitc :: AugmentedStringFormExpr :: _ignore_case
Regex::ignore_case, used for suffixi
on re
nitc :: AExpr :: _implicit_cast_to
If required, the following implicit cast.as(XXX)
nitc :: ANode :: _is_broken
The indication that the node did not pass some semantic verifications.nitc :: Prod :: _last_token
The last token of the production in the ASTnitc :: Prod :: _n_annotations
All the annotations attached directly to the nodenitc :: AugmentedStringFormExpr :: _newline
Regex::newline, used for suffixm
on re
nitc :: ASuperstringExpr :: _prefix
nitc :: AAugmentedLiteral :: _prefix
Prefix for the entity, "" if no prefix is foundnitc :: ASuperstringExpr :: _suffix
nitc :: AAugmentedLiteral :: _suffix
Suffix for the entity, "" if no prefix is foundnitc :: AugmentedStringFormExpr :: _to_bytes_with_copy
CString::to_bytes_with_copy, used for prefixb
nitc :: AugmentedStringFormExpr :: _to_re
Text::to_re, used for prefixre
nitc :: AExpr :: _vararg_decl
It indicates the number of arguments collected as a vararg.nitc :: AExpr :: _variable_cache
nitc :: ANode :: accept_ast_validation
nitc :: ANode :: accept_auto_super_init
nitc :: AExpr :: accept_explain_assert
Fillv
to explain this node if the parent assert fails
nitc :: ANode :: accept_flow_visitor
nitc :: ANode :: accept_forward_analysis
Apply the forward analysisv
to self
.
nitc :: ANode :: accept_literal
nitc :: ANode :: accept_post_typing
nitc :: ANode :: accept_pretty_printer
Start visit ofself
using a PrettyPrinterVisitor
nitc :: ANode :: accept_reaching_defs
Apply a ReachingDefsAnalysis toself
.
nitc :: ANode :: accept_regex_visitor
nitc :: ANode :: accept_scope_visitor
nitc :: ANode :: accept_simple_misc
nitc :: ANode :: accept_string_finder
nitc :: AExpr :: accept_typing
nitc :: AExpr :: after_flow_context
The flow after the full evaluation of the expression/statementnitc :: AExpr :: after_flow_context=
The flow after the full evaluation of the expression/statementnitc :: ANode :: after_simple_misc
nitc :: AExpr :: allocate_mtype
Make themtype
of the expression live
nitc :: ANode :: bad_expr_message
An additional information message to explain the role of a child expression.nitc :: ANode :: check_callsite
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
nitc :: ANode :: collect_annotations_by_name
Do a deep search and return an array of node that are annotatednitc :: Prod :: collect_comments
Collect allTComment
contained in the production
nitc :: ANode :: collect_length
Collect the length (inChar
) of the node.
nitc :: ANode :: collect_tokens_by_text
Do a deep search and return an array of tokens that match a given textnitc :: ANode :: common_parent
The most specific common parent betweenself
and other
nitc :: AExpr :: comprehension
Is non-null ifself
is a leaf of a comprehension array construction.
nitc :: AExpr :: comprehension=
Is non-null ifself
is a leaf of a comprehension array construction.
nitc :: AAugmentedLiteral :: content
Content of the entity, without prefix nor suffixnitc :: AAugmentedLiteral :: content=
Content of the entity, without prefix nor suffixnitc :: ANode :: create_contracts
nitc :: ANode :: decorate_tag
Add aditionnal information on a child-token and return an additionnal HInfoBox on itnitc :: ANode :: defaultinit
nitc :: AAugmentedLiteral :: defaultinit
core :: Object :: defaultinit
nitc :: Prod :: defaultinit
nitc :: AExpr :: defaultinit
core :: Cloneable :: defaultinit
nitc :: ASuperstringExpr :: defaultinit
nitc :: AExpr :: detach_with_placeholder
Thedetach
method completely remove the node in the parent.
nitc :: ANode :: do_cloneable
nitc :: AugmentedStringFormExpr :: extended
Regex::extended, used for suffixb
on re
nitc :: AugmentedStringFormExpr :: extended=
Regex::extended, used for suffixb
on re
nitc :: Prod :: first_location
Location on the first token after the start of a productionnitc :: Prod :: first_location=
Location on the first token after the start of a productionnitc :: Prod :: first_token
The first token of the production in the ASTnitc :: Prod :: first_token=
The first token of the production in the ASTnitc :: ANode :: force_block=
Forceself
to be rendered as a block.
nitc :: ANode :: force_inline=
Forceself
to be rendered as a line.
nitc :: ANode :: full_transform_visitor
nitc :: AExpr :: generate_basic_blocks
Generate recursively basic block for this expressionnitc :: Prod :: get_annotations
Return all its annotations of a given name in the order of their declarationnitc :: Prod :: get_single_annotation
Try to get its single annotation with a given namenitc :: ANode :: hot_location
The location of the important part of the node (identifier or whatever)nitc :: AugmentedStringFormExpr :: ignore_case
Regex::ignore_case, used for suffixi
on re
nitc :: AugmentedStringFormExpr :: ignore_case=
Regex::ignore_case, used for suffixi
on re
nitc :: AExpr :: implicit_cast_to
If required, the following implicit cast.as(XXX)
nitc :: AExpr :: implicit_cast_to=
If required, the following implicit cast.as(XXX)
nitc :: ANode :: is_broken=
The indication that the node did not pass some semantic verifications.nitc :: ANode :: is_noserialize
Is this node annotated to not be made serializable?core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
nitc :: ANode :: is_serialize
Is this node annotated to be made serializable?nitc :: ANode :: is_structural
Isself
a token or a pure-structural production like AQId
?
nitc :: AAugmentedLiteral :: is_valid_augmentation
Is the combination of prefixes and suffixes inself
valid ?
nitc :: Prod :: last_token
The last token of the production in the ASTnitc :: Prod :: last_token=
The last token of the production in the ASTnitc :: AugmentedStringFormExpr :: make_re
Factorize the making of aRegex
object from a literal prefixed string
nitc :: AugmentedStringFormExpr :: make_re
Factorize the making of aRegex
object from a literal prefixed string
nitc :: AExpr :: make_var_read
Return a new variable read that contains the value of the expressionnitc :: ANode :: must_be_block
Doesself
have to be rendered as a block?
nitc :: ANode :: must_be_inline
Doesself
have be rendered as a line?
nitc :: Prod :: n_annotations
All the annotations attached directly to the nodenitc :: Prod :: n_annotations=
All the annotations attached directly to the nodecore :: Object :: native_class_name
The class name of the object in CString format.nitc :: AugmentedStringFormExpr :: newline
Regex::newline, used for suffixm
on re
nitc :: AugmentedStringFormExpr :: newline=
Regex::newline, used for suffixm
on re
core :: Object :: output_class_name
Display class name on stdout (debug only).nitc :: ANode :: parentize_tokens
Visit the AST and computes advanced AST attributes on Tokens and Prodnitc :: AAugmentedLiteral :: prefix
Prefix for the entity, "" if no prefix is foundnitc :: AAugmentedLiteral :: prefix=
Prefix for the entity, "" if no prefix is foundnitc :: ANode :: replace_child
Replace a child with an other node in the ASTnitc :: ANode :: replace_with
Replace itself with an other node in the ASTnitc :: Prod :: start_token
The token where the production really start (skipping ADoc).nitc :: AAugmentedLiteral :: suffix
Suffix for the entity, "" if no prefix is foundnitc :: AAugmentedLiteral :: suffix=
Suffix for the entity, "" if no prefix is foundnitc :: AugmentedStringFormExpr :: to_bytes_with_copy
CString::to_bytes_with_copy, used for prefixb
nitc :: AugmentedStringFormExpr :: to_bytes_with_copy=
CString::to_bytes_with_copy, used for prefixb
nitc :: AugmentedStringFormExpr :: to_re
Text::to_re, used for prefixre
nitc :: AugmentedStringFormExpr :: to_re=
Text::to_re, used for prefixre
nitc :: AExpr :: vararg_decl
It indicates the number of arguments collected as a vararg.nitc :: AExpr :: vararg_decl=
It indicates the number of arguments collected as a vararg.nitc :: AExpr :: variable_cache
nitc :: AExpr :: variable_cache=
nitc :: AExpr :: warn_parentheses
Warn in case of superfluous parenthesesnitc :: ANode :: was_inline
Doesself
was written in one line before transformation?
nitc :: AugmentedStringFormExpr
Any kind of string form with augmentations from prefixes or suffixes
redef class ASuperstringExpr
init init_asuperstringexpr (
n_exprs: Collection[Object], # Should be Collection[AExpr]
n_annotations: nullable AAnnotations
)
do
self.n_exprs.unsafe_add_all(n_exprs)
_n_annotations = n_annotations
if n_annotations != null then n_annotations.parent = self
end
redef fun replace_child(old_child: ANode, new_child: nullable ANode)
do
if n_exprs.replace_child(old_child, new_child) then return
if _n_annotations == old_child then
n_annotations = new_child.as(nullable AAnnotations)
return
end
end
redef fun n_annotations=(node)
do
_n_annotations = node
if node != null then node.parent = self
end
redef fun visit_all(v: Visitor)
do
n_exprs.visit_all(v)
v.enter_visit(_n_annotations)
end
end
src/parser/parser_prod.nit:6846,1--6878,3
redef class ASuperstringExpr
super AugmentedStringFormExpr
redef var prefix is lazy do
var fst = n_exprs.first
if fst isa AugmentedStringFormExpr then
var prf = fst.prefix
delimiter_start = fst.delimiter_start
delimiter_end = delimiter_start
return prf
end
return ""
end
redef var suffix is lazy do
var lst = n_exprs.last
# Forces the system to update the delimiter's value
prefix
if lst isa AugmentedStringFormExpr then
lst.delimiter_end = delimiter_start
return lst.suffix
end
return ""
end
redef fun accept_literal(v)
do
if is_bytestring then
v.toolcontext.error(hot_location, "Error: cannot produce a ByteString on a Superstring")
return
end
if not is_valid_augmentation then
v.toolcontext.error(hot_location, "Error: invalid prefix/suffix combination {prefix}/{suffix}")
return
end
end
redef fun visit_all(v) do
super
if prefix != "raw" then
for i in n_exprs do
if not i isa AStringFormExpr then continue
i.bytes = i.raw_text.unescape_to_bytes
i.value = i.bytes.to_s
end
end
end
end
src/literal.nit:279,1--326,3
redef class ASuperstringExpr
redef fun accept_pretty_printer(v) do
for n_expr in n_exprs do
if not v.break_strings then
n_expr.force_inline = true
end
v.visit n_expr
end
end
redef fun must_be_inline do
if super then return true
if not n_exprs.is_empty then
var first = n_exprs.first
return first isa AStringFormExpr and first.n_string.text.has_prefix("\"\"\"")
end
return false
end
end
src/pretty.nit:2151,1--2171,3
redef class ASuperstringExpr
redef fun accept_typing(v)
do
super
var objclass = v.get_mclass(self, "Object")
if objclass == null then return # Forward error
var objtype = objclass.mclass_type
for nexpr in self.n_exprs do
v.visit_expr_subtype(nexpr, objtype)
end
end
end
src/semantize/typing.nit:1687,1--1698,3
redef class ASuperstringExpr
redef fun accept_rapid_type_visitor(v)
do
var mmodule = v.analysis.mainmodule
var object_type = mmodule.string_type
var arraytype = mmodule.array_type(object_type)
v.add_type(arraytype)
var nattype = mmodule.native_array_type(object_type)
v.add_type(nattype)
var prop = v.get_method(arraytype, "join")
v.add_monomorphic_send(arraytype, prop)
var prop2 = v.get_method(arraytype, "with_native")
v.add_monomorphic_send(arraytype, prop2)
v.add_monomorphic_send(nattype, v.get_method(nattype, "native_to_s"))
end
end
src/rapid_type_analysis.nit:606,1--621,3
redef class ASuperstringExpr
redef fun accept_string_finder(v) do
var fmt = ""
var exprs = new Array[AExpr]
for i in n_exprs do
if i isa AStartStringExpr or i isa AEndStringExpr or i isa AMidStringExpr then
assert i isa AStringFormExpr
var str = i.value
fmt += str.replace("%", "%%")
else
fmt += "%"
exprs.push i
fmt += (exprs.length-1).to_s
end
end
fmt = fmt.escape_to_gettext
v.add_string(fmt, location)
var code = "\"{fmt}\".get_translation(\"{v.domain}\", \"{v.languages_location}\").format()"
var parse = v.toolcontext.parse_expr(code)
if not parse isa ACallExpr then
v.toolcontext.error(location, "Fatal error in i18n annotation, the parsed superstring could not be generated properly")
return
end
var parse_exprs = parse.n_args.n_exprs
parse_exprs.add_all exprs
replace_with parse
end
end
src/frontend/i18n_phase.nit:141,1--169,3
redef class ASuperstringExpr
redef fun expr(v)
do
var array = new Array[Instance]
for nexpr in n_exprs do
var i = v.expr(nexpr)
if i == null then return null
array.add(i)
end
var i = v.array_instance(array, v.mainmodule.object_type)
var res = v.send(v.force_get_primitive_method("plain_to_s", i.mtype), [i])
assert res != null
if is_re then res = make_re(v, res)
return res
end
end
src/interpreter/naive_interpreter.nit:2153,1--2168,3
redef class ASuperstringExpr
redef fun generate_basic_blocks(ssa, old_block)
do
for nexpr in self.n_exprs do old_block = nexpr.generate_basic_blocks(ssa, old_block)
return old_block
end
end
src/ssa.nit:775,1--782,3
redef class ASuperstringExpr
redef fun expr(v)
do
var type_string = v.mmodule.string_type
# Collect elements of the superstring
var array = new Array[AExpr]
for ne in self.n_exprs do
# Drop literal empty string.
# They appears in things like "{a}" that is ["", a, ""]
if ne isa AStringFormExpr and ne.value == "" then continue # skip empty sub-strings
array.add(ne)
end
# Store the allocated native array in a static variable
# For reusing later
var varonce = v.get_name("varonce")
v.add("if (unlikely({varonce}==NULL)) \{")
# The native array that will contains the elements to_s-ized.
# For fast concatenation.
var a = v.native_array_instance(type_string, v.int_instance(array.length))
v.add_decl("static {a.mtype.ctype} {varonce};")
# Pre-fill the array with the literal string parts.
# So they do not need to be filled again when reused
for i in [0..array.length[ do
var ne = array[i]
if not ne isa AStringFormExpr then continue
var e = v.expr(ne, null)
v.native_array_set(a, i, e)
end
v.add("\} else \{")
# Take the native-array from the store.
# The point is to prevent that some recursive execution use (and corrupt) the same native array
# WARNING: not thread safe! (FIXME?)
v.add("{a} = {varonce};")
v.add("{varonce} = NULL;")
v.add("\}")
# Stringify the elements and put them in the native array
var to_s_method = v.get_property("to_s", v.object_type)
for i in [0..array.length[ do
var ne = array[i]
if ne isa AStringFormExpr then continue
var e = v.expr(ne, null)
# Skip the `to_s` if the element is already a String
if not e.mcasttype.is_subtype(v.compiler.mainmodule, null, type_string) then
e = v.send(to_s_method, [e]).as(not null)
end
v.native_array_set(a, i, e)
end
# Fast join the C string to get the result
var res = v.send(v.get_property("native_to_s", a.mtype), [a])
assert res != null
if is_re then res = make_re(v, res)
# We finish to work with the native array,
# so store it so that it can be reused
v.add("{varonce} = {a};")
return res
end
end
src/compiler/abstract_compiler.nit:4216,1--4283,3