From a AST point of view there is no distinction between statement and expressions (even if the parser has to distinguish them)
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 :: AExpr :: _implicit_cast_to
If required, the following implicit cast.as(XXX)
nitc :: AExpr :: _vararg_decl
It indicates the number of arguments collected as a vararg.nitc :: AExpr :: _variable_cache
nitc :: AExpr :: accept_explain_assert
Fillv
to explain this node if the parent assert fails
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 :: AExpr :: allocate_mtype
Make themtype
of the expression live
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 :: AExpr :: defaultinit
nitc :: AExpr :: detach_with_placeholder
Thedetach
method completely remove the node in the parent.
nitc :: AExpr :: generate_basic_blocks
Generate recursively basic block for this expressionnitc :: 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 :: AExpr :: make_var_read
Return a new variable read that contains the value of the expressionnitc :: 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 :: astbuilder $ AExpr :: accept_ast_validation
nitc :: htmlight $ AExpr :: decorate_tag
Add aditionnal information on a child-token and return an additionnal HInfoBox on itnitc :: transform $ AExpr :: full_transform_visitor
nitc :: transform $ AExpr :: replace_with
Replace itself with an other node in the ASTnitc :: 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 :: 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 :: 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 :: 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 :: ANode :: create_contracts
nitc :: ANode :: decorate_tag
Add aditionnal information on a child-token and return an additionnal HInfoBox on itnitc :: Prod :: defaultinit
nitc :: AExpr :: defaultinit
core :: Cloneable :: defaultinit
nitc :: ANode :: defaultinit
core :: Object :: defaultinit
nitc :: AExpr :: detach_with_placeholder
Thedetach
method completely remove the node in the parent.
nitc :: ANode :: do_cloneable
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 :: 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 :: Prod :: last_token
The last token of the production in the ASTnitc :: Prod :: last_token=
The last token of the production in the ASTnitc :: 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.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 :: 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 :: 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?
= something
nitc :: ABinOpHelper
Used to factorize work on Or, And, Implies and Binop expressions.nitc :: AIfexprExpr
Aif
expression (ternary conditional). eg. if true then 1 else 0
nitc :: ALambdaExpr
+= something
nitc :: AVarargExpr
An ellipsis notation used to pass an expression as it, in a vararg parameternitc :: AugmentedStringFormExpr
Any kind of string form with augmentations from prefixes or suffixesnitc :: ABraFormExpr
Whatever looks-like a call of the brackets[]
operator.
x[y,z]+=t
x.m(y)=z
. OR just a simple assignment.
x.m(y)+=z
. OR just a simple complex assignment.
nitc :: ACallrefExpr
A reference to a method with a captured receiver. eg.&x.foo
or just &foo
is self is captured.
self
is implicit
redef class AExpr
# Get `self` as a single identifier.
# Return null if not a single identifier.
fun as_id: nullable String
do
if self isa AMethidExpr then
return self.collect_text
end
if not self isa ACallExpr then return null
if not self.n_expr isa AImplicitSelfExpr then return null
if not self.n_args.n_exprs.is_empty then return null
return self.n_qid.n_id.text
end
end
src/parser/parser_work.nit:302,1--316,3
redef class AExpr
# Warn in case of superfluous parentheses
private fun warn_parentheses(v: SimpleMiscVisitor) do end
end
src/frontend/simple_misc_analysis.nit:105,1--108,3
redef class AExpr
# Get `self` as a `String`.
# Return null if not a string.
fun as_string: nullable String
do
if not self isa AStringFormExpr then return null
return self.value
end
# Get `self` as an `Int`.
# Return null if not an integer.
fun as_int: nullable Int
do
if not self isa AIntegerExpr then return null
return self.value.as(not null).to_i
end
end
src/literal.nit:59,1--75,3
redef class AExpr
# The flow after the full evaluation of the expression/statement
var after_flow_context: nullable FlowContext
end
src/semantize/flow.nit:279,1--282,3
redef class AExpr
# The static type of the expression.
# null if self is a statement or in case of error
var mtype: nullable MType = null
# Is the statement correctly typed?
# Used to distinguish errors and statements when `mtype == null`
var is_typed: Bool = false
# If required, the following implicit cast `.as(XXX)`
# Such a cast may by required after evaluating the expression when
# a unsafe operation is detected (silently accepted by the Nit language).
# The attribute is computed by `check_subtype`
var implicit_cast_to: nullable MType = null
# Return the variable read (if any)
# Used to perform adaptive typing
fun its_variable: nullable Variable do return null
private fun accept_typing(v: TypeVisitor)
do
v.error(self, "no implemented accept_typing for {self.class_name}")
end
# Is non-null if `self` is a leaf of a comprehension array construction.
# In this case, the enclosing literal array node is designated.
# The result of the evaluation of `self` must be
# stored inside the designated array (there is an implicit `push`)
var comprehension: nullable AArrayExpr = null
# It indicates the number of arguments collected as a vararg.
#
# When 0, the argument is used as is, without transformation.
# When 1, the argument is transformed into an singleton array.
# Above 1, the arguments and the next ones are transformed into a common array.
#
# This attribute is meaning less on expressions not used as attributes.
var vararg_decl: Int = 0
redef fun dump_info(v) do
var res = super
var mtype = self.mtype
if mtype != null then
res += v.yellow(":{mtype}")
end
var ict = self.implicit_cast_to
if ict != null then
res += v.yellow("(.as({ict}))")
end
return res
end
# Type the expression as if located in `visited_mpropdef`
# `TypeVisitor` and `PostTypingVisitor` will be used to do the typing, see them for more information.
#
# `visited_mpropdef`: Correspond to the evaluation context in which the expression is located.
fun do_typing(modelbuilder: ModelBuilder, visited_mpropdef: MPropDef)
do
var type_visitor = new TypeVisitor(modelbuilder, visited_mpropdef)
type_visitor.visit_stmt(self)
var post_visitor = new PostTypingVisitor(type_visitor)
post_visitor.enter_visit(self)
end
end
src/semantize/typing.nit:990,1--1053,3
redef class AExpr
# Return a new variable read that contains the value of the expression
# This method take care efficiently of creating and initalising an anonymous local variable
#
# Note: since this method do side-effects (AST replacement), there could be unexpected effects when used as
# argument of other methods related to AST transformations.
fun make_var_read: AVarExpr
do
var variable = self.variable_cache
if variable == null then
assert parent != null
var place = detach_with_placeholder
variable = new Variable("")
variable.declared_type = self.mtype
var nvar = new AVarAssignExpr.make(variable, self)
place.replace_with(nvar)
self.variable_cache = variable
end
return new AVarExpr.make(variable, variable.declared_type.as(not null))
end
private var variable_cache: nullable Variable
# The `detach` method completely remove the node in the parent.
# However, sometime, it is useful to keep the emplacement of the removed child.
#
# The standard use case is the insertion of a node between a parent `p` and a child `p.c`.
# To create the new node `n`, we need to attach the child to it.
# But, to put `n` where `c` was in `p`, the place has to be remembered.
#
# ~~~nitish
# var p: AExpr
# var c = p.c
# var h = c.detach_with_placeholder
# var n = astbuilder.make_XXX(c)
# h.replace_with(n)
# ~~~
fun detach_with_placeholder: AExpr
do
var h = new APlaceholderExpr.make
self.replace_with(h)
return h
end
# Add `expr` at the end of the block
#
# REQUIRE: self isa ABlockExpr
#
# Note: this method, aimed to `ABlockExpr` is promoted to `AExpr` because of the limitations of the hierarchies generated by sablecc3
fun add(expr: AExpr)
do
print "add not implemented in {inspect}"
abort
end
redef fun accept_ast_validation(v)
do
super
if mtype == null and not is_typed then
#debug "TYPING: untyped expression"
end
end
end
src/astbuilder.nit:216,1--279,3
redef class AExpr
# Make the `mtype` of the expression live
# Used by literals and instantiations
fun allocate_mtype(v: RapidTypeVisitor)
do
var mtype = self.mtype
if not mtype isa MClassType then return
v.add_type(self.mtype.as(MClassType))
end
end
src/rapid_type_analysis.nit:544,1--553,3
redef class AExpr
# Evaluate the node as a possible expression.
# Return a possible value
# NOTE: Do not call this method directly, but use `v.expr`
# This method is here to be implemented by subclasses.
protected fun expr(v: NaiveInterpreter): nullable Instance
do
fatal(v, "NOT YET IMPLEMENTED expr {class_name}")
abort
end
# Evaluate the node as a statement.
# NOTE: Do not call this method directly, but use `v.stmt`
# This method is here to be implemented by subclasses (no need to return something).
protected fun stmt(v: NaiveInterpreter)
do
expr(v)
end
end
src/interpreter/naive_interpreter.nit:1669,1--1688,3
redef class AExpr
# Fill `v` to explain this node if the parent assert fails
private fun accept_explain_assert(v: ExplainAssertVisitor)
do if mtype != null then v.explain_expr self
end
src/frontend/explain_assert.nit:188,1--192,3
redef class AExpr
# Give a position to each variable declared in the node.
# NOTE: Do not call this method directly, but use `v.numbering`
# This method is here to be implemented by subclasses.
# *`v` The current instance of the virtual machine
# *`position` The first available position in the environment a variable can have
# Return the next available position a variable can have
public fun numbering(v: VirtualMachine, position: Int): Int
do
return position
end
end
src/vm/variables_numbering.nit:82,1--93,3
redef class AExpr
# Try to compile self as an expression
# Do not call this method directly, use `v.expr` instead
private fun expr(v: AbstractCompilerVisitor): nullable RuntimeVariable
do
v.add("PRINT_ERROR(\"NOT YET IMPLEMENTED {class_name}:{location.to_s}\\n\");")
var mtype = self.mtype
if mtype == null then
return null
else
var res = v.new_var(mtype)
v.add("/* {res} = NOT YET {class_name} */")
return res
end
end
# Try to compile self as a statement
# Do not call this method directly, use `v.stmt` instead
private fun stmt(v: AbstractCompilerVisitor)
do
expr(v)
end
end
src/compiler/abstract_compiler.nit:3721,1--3743,3
redef class AExpr
# Generate recursively basic block for this expression
# *`ssa` An instance of the SSA class initialized with the enclosing `APropdef`
# *`old_block` A basic block not completely filled
# Return the last created block (the last block can be nested)
fun generate_basic_blocks(ssa: SSA, old_block: BasicBlock): BasicBlock
do
return old_block
end
end
src/ssa.nit:573,1--582,3
redef class AExpr
redef fun full_transform_visitor(v: TransformVisitor)
do
var na = comprehension
if na != null then
# We are building a comprehension array `array`
# Replace `self` with `array.push(self)`
var place = detach_with_placeholder
var recv = na.nnew.make_var_read
var nadd = v.builder.make_call(recv, na.push_callsite.as(not null), [self])
place.replace_with(nadd)
end
visit_all(v)
if is_broken then return # Skip broken
accept_transform_visitor(v)
end
redef fun replace_with(other)
do
super
if other isa AExpr then
if other.implicit_cast_to == null then other.implicit_cast_to = implicit_cast_to
other.vararg_decl = vararg_decl
end
end
end
src/transform.nit:94,1--122,3
redef class AExpr
# Try to compile self as an expression
# Do not call this method directly, use `v.expr` instead
private fun expr(v: JavaCompilerVisitor): nullable RuntimeVariable do
v.info("NOT YET IMPLEMENTED {class_name}::expr")
return null
end
# Try to compile self as a statement
# Do not call this method directly, use `v.stmt` instead
private fun stmt(v: JavaCompilerVisitor) do expr(v)
end
src/compiler/java_compiler.nit:1903,1--1914,3