if
statementnitc :: AIfExpr :: collect_kwelse
Lookup forelse
token in self
.
nitc :: AIfExpr :: defaultinit
nitc :: AIfExpr :: init_aifexpr
nitc :: flow $ AIfExpr :: accept_flow_visitor
nitc :: saf_base $ AIfExpr :: accept_forward_analysis
Merge flow on if .. else constructs.nitc :: pretty $ AIfExpr :: accept_pretty_printer
Start visit ofself
using a PrettyPrinterVisitor
nitc :: scope $ AIfExpr :: accept_scope_visitor
nitc :: typing $ AIfExpr :: accept_typing
nitc :: abstract_compiler $ AIfExpr :: expr
Try to compile self as an expressionnitc :: java_compiler $ AIfExpr :: expr
Try to compile self as an expressionnitc :: naive_interpreter $ AIfExpr :: expr
Evaluate the node as a possible expression.nitc :: ssa $ AIfExpr :: generate_basic_blocks
Generate recursively basic block for this expressionnitc :: pretty $ AIfExpr :: is_inlinable
Isself
printable in one line?
nitc :: variables_numbering $ AIfExpr :: numbering
Give a position to each variable declared in the node.nitc :: parser_prod $ AIfExpr :: replace_child
Replace a child with an other node in the ASTnitc :: java_compiler $ AIfExpr :: stmt
Try to compile self as a statementnitc :: naive_interpreter $ AIfExpr :: stmt
Evaluate the node as a statement.nitc :: abstract_compiler $ AIfExpr :: stmt
Try to compile self as a statementnitc :: 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 :: AIfExpr :: collect_kwelse
Lookup forelse
token in self
.
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 :: AIfExpr :: defaultinit
nitc :: ANode :: defaultinit
core :: Cloneable :: defaultinit
nitc :: AExpr :: defaultinit
nitc :: Prod :: 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 :: AIfExpr :: init_aifexpr
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?
# A `if` statement
class AIfExpr
super AExpr
# The `if` keyword
var n_kwif: TKwif is writable, noinit
# The expression used as the condition of the `if`
var n_expr: AExpr is writable, noinit
# The `then` keyword
var n_kwthen: TKwthen is writable, noinit
# The body of the `then` part
var n_then: nullable AExpr = null is writable
# The `else` keyword
var n_kwelse: nullable TKwelse = null is writable
# The body of the `else` part
var n_else: nullable AExpr = null is writable
end
src/parser/parser_nodes.nit:1957,1--1978,3
redef class AIfExpr
init init_aifexpr (
n_kwif: nullable TKwif,
n_expr: nullable AExpr,
n_kwthen: nullable TKwthen,
n_then: nullable AExpr,
n_kwelse: nullable TKwelse,
n_else: nullable AExpr
)
do
_n_kwif = n_kwif.as(not null)
n_kwif.parent = self
_n_expr = n_expr.as(not null)
n_expr.parent = self
_n_kwthen = n_kwthen.as(not null)
n_kwthen.parent = self
_n_then = n_then
if n_then != null then n_then.parent = self
_n_kwelse = n_kwelse
if n_kwelse != null then n_kwelse.parent = self
_n_else = n_else
if n_else != null then n_else.parent = self
end
redef fun replace_child(old_child: ANode, new_child: nullable ANode)
do
if _n_kwif == old_child then
n_kwif = new_child.as(TKwif)
return
end
if _n_expr == old_child then
n_expr = new_child.as(AExpr)
return
end
if _n_kwthen == old_child then
n_kwthen = new_child.as(TKwthen)
return
end
if _n_then == old_child then
n_then = new_child.as(nullable AExpr)
return
end
if _n_kwelse == old_child then
n_kwelse = new_child.as(nullable TKwelse)
return
end
if _n_else == old_child then
n_else = new_child.as(nullable AExpr)
return
end
end
redef fun n_kwif=(node)
do
_n_kwif = node
node.parent = self
end
redef fun n_expr=(node)
do
_n_expr = node
node.parent = self
end
redef fun n_kwthen=(node)
do
_n_kwthen = node
node.parent = self
end
redef fun n_then=(node)
do
_n_then = node
if node != null then node.parent = self
end
redef fun n_kwelse=(node)
do
_n_kwelse = node
if node != null then node.parent = self
end
redef fun n_else=(node)
do
_n_else = node
if node != null then node.parent = self
end
redef fun visit_all(v: Visitor)
do
v.enter_visit(_n_kwif)
v.enter_visit(_n_expr)
v.enter_visit(_n_kwthen)
v.enter_visit(_n_then)
v.enter_visit(_n_kwelse)
v.enter_visit(_n_else)
end
end
src/parser/parser_prod.nit:3018,1--3111,3
redef class AIfExpr
redef fun after_simple_misc(v)
do
n_expr.warn_parentheses(v)
end
end
src/frontend/simple_misc_analysis.nit:193,1--198,3
redef class AIfExpr
# Merge flow on if .. else constructs.
redef fun accept_forward_analysis(v) do
v.enter_visit(n_expr)
var inset = v.current_inset
var outset = v.current_outset
if n_then != null then v.enter_visit(n_then)
var then_outset = v.current_outset
v.current_inset = inset
v.current_outset = outset
if n_else != null then
v.enter_visit(n_else)
outset = v.merge(then_outset, v.current_outset)
else
outset = v.merge(then_outset, v.current_inset)
end
v.current_inset = inset
v.current_outset = outset
end
end
src/saf/saf_base.nit:142,1--165,3
redef class AIfExpr
redef fun accept_scope_visitor(v)
do
v.enter_visit(n_expr)
v.enter_visit_block(n_then, null)
v.enter_visit_block(n_else, null)
end
end
src/semantize/scope.nit:368,1--375,3
redef class AIfExpr
redef fun accept_flow_visitor(v)
do
var after_expr = v.visit_expr(self.n_expr)
v.current_flow_context = after_expr.when_true
v.enter_visit(self.n_then)
var after_then = v.current_flow_context
v.current_flow_context = after_expr.when_false
v.enter_visit(self.n_else)
var after_else = v.current_flow_context
v.make_merge_flow(after_then, after_else)
end
end
src/semantize/flow.nit:367,1--382,3
redef class AIfExpr
redef fun accept_pretty_printer(v) do
var before = v.indent
var can_inline = v.can_inline(self)
v.visit n_kwif
v.adds
if v.can_inline(n_expr) then
v.visit n_expr
v.adds
else
v.visit n_expr
v.forcen
v.addt
end
# skip comments before `then` token
while not v.current_token isa TKwthen do v.skip
v.consume "then"
var n_else = self.n_else
if can_inline then
v.adds
if n_then != null then v.visit n_then
if has_else(v) then
n_else.force_inline = true
v.adds
v.consume "else"
v.adds
v.visit n_else
else if n_then == null then
v.add "end"
end
v.skip_to last_token.last_real_token_in_line
else
v.finish_line
if was_inline then
v.forcen
else if not v.skip_empty and n_then != null and
n_then.was_inline and
n_then.location.line_end == location.line_start then
v.forcen # Xymus fucking syntax
else
v.addn
end
v.indent += 1
if n_then != null then
if n_then isa ABlockExpr then
n_then.force_block = true
v.visit n_then
else
v.addt
v.visit n_then
if n_then.was_inline then
v.forcen
else
v.addn
end
end
end
v.consume_comments
# FIXME: for some unknown reasons, has_else can be true even if
# there is no `else` keyword but a `end` instead.
if has_else(v) and v.current_token isa TKwelse then
v.indent -= 1
v.addt
v.consume "else"
if n_else isa AIfExpr then
n_else.force_block = true
v.adds
v.visit n_else
else
v.finish_line
if was_inline then
v.forcen
else
v.addn
end
v.indent += 1
if n_else isa ABlockExpr then
n_else.force_block = true
v.visit n_else
else
v.addt
v.visit n_else
if n_else.was_inline then
v.forcen
else
v.addn
end
end
if last_token isa TKwend then
v.catch_up last_token
v.indent -= 1
v.addt
v.consume "end"
else
v.indent -= 1
v.addt
v.add "end"
end
end
else
if last_token.location >= v.current_token.location then v.catch_up last_token
v.indent -= 1
v.addt
v.add "end"
if v.current_token isa TKwend then v.skip
end
end
assert v.indent == before
end
redef fun is_inlinable do
if not super then return false
if n_then != null and not n_then.is_inlinable then return false
var n_else = self.n_else
if (n_else isa ABlockExpr and not n_else.n_expr.is_empty) or
(not n_else isa ABlockExpr and n_else != null) then
return false
end
if not collect_comments.is_empty then return false
return true
end
# Does this `if` statement contains a `else` part?
private fun has_else(v: PrettyPrinterVisitor): Bool do
var n_else = n_else
if n_else == null then return false
var n_kwelse = collect_kwelse
if n_kwelse == null then return false
if n_else isa ABlockExpr then
var comments: Array[TComment]
if n_then == null then
comments = v.collect_comments(n_expr.last_token, n_else.last_token)
else
comments = v.collect_comments(n_then.last_token, n_else.last_token)
end
if not comments.is_empty then return true
return not n_else.n_expr.is_empty
end
return true
end
# Lookup for `else` token in `self`.
private fun collect_kwelse: nullable TKwelse do
var token = first_token
while token != last_token do
if token isa TKwelse then return token
token = token.next_token
end
return null
end
end
src/pretty.nit:1231,1--1399,3
redef class AIfExpr
private init make(condition: AExpr, mtype: nullable MType)
do
_n_kwif = new TKwif
_n_expr = condition
_n_expr.parent = self
_n_kwthen = new TKwthen
_n_then = new ABlockExpr.make
_n_kwelse = new TKwelse
_n_else = new ABlockExpr.make
self.mtype = mtype
if mtype != null then self.is_typed = true
end
end
src/astbuilder.nit:495,1--508,3
redef class AIfExpr
redef fun expr(v)
do
var cond = v.expr(self.n_expr)
if cond == null then return null
if cond.is_true then
return v.expr(self.n_then.as(not null))
else
return v.expr(self.n_else.as(not null))
end
end
redef fun stmt(v)
do
var cond = v.expr(self.n_expr)
if cond == null then return
if cond.is_true then
v.stmt(self.n_then)
else
v.stmt(self.n_else)
end
end
end
src/interpreter/naive_interpreter.nit:1793,1--1815,3
redef class AIfExpr
redef fun numbering(v, position)
do
# Attribute numbers separetely for the two branches
var pos = v.numbering(self.n_then, position)
var pos1 = v.numbering(self.n_else, position)
if pos > pos1 then
return pos
else
return pos1
end
end
end
src/vm/variables_numbering.nit:203,1--216,3
redef class AIfExpr
redef fun generate_basic_blocks(ssa, old_block)
do
# Terminate the previous block
old_block.last = self
# We start two new blocks if the if has two branches
var block_then = new BasicBlock
# Visit the test of the if
self.n_expr.generate_basic_blocks(ssa, old_block)
# Launch the recursion in two successors if they exist
if self.n_then != null then
old_block.link(block_then)
block_then.first = self.n_then.as(not null)
block_then.last = self.n_then.as(not null)
self.n_then.generate_basic_blocks(ssa, block_then)
end
var block_else = new BasicBlock
if self.n_else != null then
old_block.link(block_else)
block_else.first = self.n_else.as(not null)
block_else.last = self.n_else.as(not null)
self.n_else.generate_basic_blocks(ssa, block_else)
end
# Create a new BasicBlock to represent the two successor
# branches of the if
var new_block = new BasicBlock
new_block.first = self
new_block.last = self
if self.n_then != null then block_then.link(new_block)
# The new block needs to be filled by the caller
new_block.need_update = true
if block_else.predecessors.length != 0 then block_else.link(new_block)
return new_block
end
end
src/ssa.nit:959,1--1005,3
redef class AIfExpr
redef fun stmt(v)
do
var cond = v.expr_bool(self.n_expr)
v.add("if ({cond})\{")
v.stmt(self.n_then)
v.add("\} else \{")
v.stmt(self.n_else)
v.add("\}")
end
redef fun expr(v)
do
var res = v.new_var(self.mtype.as(not null))
var cond = v.expr_bool(self.n_expr)
v.add("if ({cond})\{")
v.assign(res, v.expr(self.n_then.as(not null), null))
v.add("\} else \{")
v.assign(res, v.expr(self.n_else.as(not null), null))
v.add("\}")
return res
end
end
src/compiler/abstract_compiler.nit:3837,1--3859,3
redef class AIfExpr
redef fun stmt(v) do
var cond = v.expr_bool(self.n_expr)
v.add("if ({cond})\{")
v.stmt(self.n_then)
v.add("\} else \{")
v.stmt(self.n_else)
v.add("\}")
end
redef fun expr(v) do
var res = v.new_var(self.mtype.as(not null))
var cond = v.expr_bool(self.n_expr)
v.add("if ({cond})\{")
v.assign(res, v.expr(self.n_then.as(not null), null))
v.add("\} else \{")
v.assign(res, v.expr(self.n_else.as(not null), null))
v.add("\}")
return res
end
end
src/compiler/java_compiler.nit:2065,1--2085,3