nitc :: AAssertExpr
assert
statementnitc :: AAssertExpr :: _n_else
The body to execute when the assert failsnitc :: AAssertExpr :: _n_expr
The expression used as the condition of theassert
nitc :: AAssertExpr :: can_explain_assert
Doesmodelbuilder
know the classes to build a superstring to explain a failed assert?
nitc :: AAssertExpr :: defaultinit
nitc :: AAssertExpr :: explain_assert
Explain assert if it failsnitc :: AAssertExpr :: explain_assert_str
Superstring explainingself
if the assert fails
nitc :: AAssertExpr :: init_aassertexpr
nitc :: AAssertExpr :: n_else=
The body to execute when the assert failsnitc :: AAssertExpr :: n_expr=
The expression used as the condition of theassert
nitc $ AAssertExpr :: SELF
Type of this instance, automatically specialized in every classnitc :: flow $ AAssertExpr :: accept_flow_visitor
nitc :: pretty $ AAssertExpr :: accept_pretty_printer
Start visit ofself
using a PrettyPrinterVisitor
nitc :: rapid_type_analysis $ AAssertExpr :: accept_rapid_type_visitor
nitc :: scope $ AAssertExpr :: accept_scope_visitor
nitc :: typing $ AAssertExpr :: accept_typing
nitc :: htmlight $ AAssertExpr :: decorate_tag
Add aditionnal information on a child-token and return an additionnal HInfoBox on itnitc :: explain_assert $ AAssertExpr :: explain_assert_str
Superstring explainingself
if the assert fails
nitc :: ssa $ AAssertExpr :: generate_basic_blocks
Generate recursively basic block for this expressionnitc :: pretty $ AAssertExpr :: is_inlinable
Isself
printable in one line?
nitc :: parser_prod $ AAssertExpr :: n_else=
The body to execute when the assert failsnitc :: parser_prod $ AAssertExpr :: n_expr=
The expression used as the condition of theassert
nitc :: parser_prod $ AAssertExpr :: n_id=
The name of the assert, if anynitc :: parser_prod $ AAssertExpr :: n_kwassert=
Theassert
keyword
nitc :: parser_prod $ AAssertExpr :: n_kwelse=
Theelse
keyword
nitc :: parser_prod $ AAssertExpr :: replace_child
Replace a child with an other node in the ASTnitc :: naive_interpreter $ AAssertExpr :: stmt
Evaluate the node as a statement.nitc :: abstract_compiler $ AAssertExpr :: stmt
Try to compile self as a statementnitc :: java_compiler $ AAssertExpr :: stmt
Try to compile self as a statementnitc :: parser_prod $ AAssertExpr :: 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 :: 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 :: AAssertExpr :: _n_else
The body to execute when the assert failsnitc :: AAssertExpr :: _n_expr
The expression used as the condition of theassert
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 :: AAssertExpr :: can_explain_assert
Doesmodelbuilder
know the classes to build a superstring to explain a failed assert?
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 :: AExpr :: defaultinit
nitc :: AAssertExpr :: defaultinit
nitc :: ANode :: defaultinit
nitc :: Prod :: defaultinit
core :: Object :: defaultinit
core :: Cloneable :: defaultinit
nitc :: AExpr :: detach_with_placeholder
Thedetach
method completely remove the node in the parent.
nitc :: ANode :: do_cloneable
nitc :: AAssertExpr :: explain_assert
Explain assert if it failsnitc :: AAssertExpr :: explain_assert_str
Superstring explainingself
if the assert fails
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 :: AAssertExpr :: init_aassertexpr
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 nodenitc :: AAssertExpr :: n_else=
The body to execute when the assert failsnitc :: AAssertExpr :: n_expr=
The expression used as the condition of theassert
core :: 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?
# An `assert` statement
class AAssertExpr
super AExpr
# The `assert` keyword
var n_kwassert: TKwassert is writable, noinit
# The name of the assert, if any
var n_id: nullable TId = null is writable
# The expression used as the condition of the `assert`
var n_expr: AExpr is writable, noinit
# The `else` keyword
var n_kwelse: nullable TKwelse = null is writable
# The body to execute when the assert fails
var n_else: nullable AExpr = null is writable
end
src/parser/parser_nodes.nit:2086,1--2104,3
redef class AAssertExpr
init init_aassertexpr (
n_kwassert: nullable TKwassert,
n_id: nullable TId,
n_expr: nullable AExpr,
n_kwelse: nullable TKwelse,
n_else: nullable AExpr
)
do
_n_kwassert = n_kwassert.as(not null)
n_kwassert.parent = self
_n_id = n_id
if n_id != null then n_id.parent = self
_n_expr = n_expr.as(not null)
n_expr.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_kwassert == old_child then
n_kwassert = new_child.as(TKwassert)
return
end
if _n_id == old_child then
n_id = new_child.as(nullable TId)
return
end
if _n_expr == old_child then
n_expr = new_child.as(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_kwassert=(node)
do
_n_kwassert = node
node.parent = self
end
redef fun n_id=(node)
do
_n_id = node
if node != null then node.parent = self
end
redef fun n_expr=(node)
do
_n_expr = node
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_kwassert)
v.enter_visit(_n_id)
v.enter_visit(_n_expr)
v.enter_visit(_n_kwelse)
v.enter_visit(_n_else)
end
end
src/parser/parser_prod.nit:3495,1--3575,3
redef class AAssertExpr
# Superstring explaining `self` if the assert fails
#
# Engines should print out this superstring.
fun explain_assert_str: nullable ASuperstringExpr do return null
end
src/frontend/explain_assert_api.nit:23,1--28,3
redef class AAssertExpr
redef fun accept_scope_visitor(v)
do
v.enter_visit(n_expr)
v.enter_visit_block(n_else, null)
end
end
src/semantize/scope.nit:469,1--475,3
redef class AAssertExpr
redef fun accept_flow_visitor(v)
do
var after_expr = v.visit_expr(self.n_expr)
v.current_flow_context = after_expr.when_false
v.enter_visit(n_else)
# the after context of n_else is a dead end, so we do not care
v.current_flow_context = after_expr.when_true
end
end
src/semantize/flow.nit:466,1--477,3
redef class AAssertExpr
redef fun accept_pretty_printer(v) do
var can_inline = v.can_inline(self)
v.visit n_kwassert
if n_id != null then
v.adds
v.visit n_id
v.consume ":"
end
v.adds
v.visit n_expr
var n_else = self.n_else
if n_else != null then
v.adds
v.consume "else"
if can_inline then
v.adds
v.visit n_else
else
v.addn
v.indent += 1
if n_else isa ABlockExpr then
n_else.force_block = true
v.visit n_else
v.indent -= 1
v.addt
v.visit n_else.n_kwend
else
v.addt
v.visit n_else
v.forcen
v.indent -= 1
v.addt
v.add "end"
end
end
end
end
redef fun is_inlinable do
if not super then return false
if n_else != null and not n_else.is_inlinable then return false
return true
end
end
src/pretty.nit:1828,1--1877,3
redef class AAssertExpr
redef fun accept_typing(v)
do
v.visit_expr_bool(n_expr)
v.visit_stmt(n_else)
self.is_typed = true
end
end
src/semantize/typing.nit:1492,1--1500,3
redef class AAssertExpr
private init make(n_id : nullable TId , n_expr : nullable AExpr , n_else : nullable AExpr)
do
n_kwassert = new TKwassert
n_kwelse = null
if n_else != null then n_kwelse = new TKwelse
self.init_aassertexpr(n_kwassert, n_id , n_expr , n_kwelse , n_else)
end
end
src/astbuilder.nit:423,1--431,3
redef class AAssertExpr
redef fun accept_rapid_type_visitor(v)
do
if can_explain_assert(v.analysis.modelbuilder) then
var str = explain_assert_str
if str != null then str.accept_rapid_type_visitor(v)
end
end
# Does `modelbuilder` know the classes to build a superstring to explain a failed assert?
private fun can_explain_assert(modelbuilder: ModelBuilder): Bool
do
var nas = modelbuilder.model.get_mclasses_by_name("NativeArray")
if nas == null then return false
nas = modelbuilder.model.get_mclasses_by_name("Array")
if nas == null or nas.is_empty then return false
nas = modelbuilder.model.get_mclasses_by_name("String")
if nas == null or nas.is_empty then return false
return true
end
end
src/rapid_type_analysis.nit:675,1--698,3
redef class AAssertExpr
redef fun stmt(v)
do
var cond = v.expr(self.n_expr)
if cond == null then return
if not cond.is_true then
v.stmt(self.n_else)
if v.is_escaping then return
# Explain assert if it fails
var explain_assert_str = explain_assert_str
if explain_assert_str != null then
var i = v.expr(explain_assert_str)
if i isa MutableInstance then
var res = v.send(v.force_get_primitive_method("to_cstring", i.mtype), [i])
if res != null then
var val = res.val
if val != null then
print_error "Runtime assert: {val.to_s}"
end
end
end
end
var nid = self.n_id
if nid != null then
fatal(v, "Assert '{nid.text}' failed")
else
fatal(v, "Assert failed")
end
exit(1)
end
end
end
src/interpreter/naive_interpreter.nit:1948,1--1981,3
redef class AAssertExpr
redef var explain_assert_str = null
end
src/frontend/explain_assert.nit:184,1--186,3
redef class AAssertExpr
redef fun generate_basic_blocks(ssa, old_block)
do
self.n_expr.generate_basic_blocks(ssa, old_block)
# The condition of the assert is the last expression of the previous block
old_block.last = self.n_expr
# The block if the assert fail
var block_false = new BasicBlock
if self.n_else != null then
block_false.first = self.n_else.as(not null)
block_false.last = self.n_else.as(not null)
self.n_else.generate_basic_blocks(ssa, block_false)
else
block_false.first = self
block_false.last = self
end
old_block.link(block_false)
# The block if the assert is true: the execution continue
var block_true = new BasicBlock
block_true.first = self
block_true.last = self
old_block.link(block_true)
return block_true
end
end
src/ssa.nit:692,1--723,3
redef class AAssertExpr
redef fun stmt(v)
do
if v.compiler.modelbuilder.toolcontext.opt_no_check_assert.value then return
var cond = v.expr_bool(self.n_expr)
v.add("if (unlikely(!{cond})) \{")
v.stmt(self.n_else)
explain_assert v
var nid = self.n_id
if nid != null then
v.add_abort("Assert '{nid.text}' failed")
else
v.add_abort("Assert failed")
end
v.add("\}")
end
# Explain assert if it fails
private fun explain_assert(v: AbstractCompilerVisitor)
do
var explain_assert_str = explain_assert_str
if explain_assert_str == null then return
var nas = v.compiler.modelbuilder.model.get_mclasses_by_name("NativeArray")
if nas == null then return
nas = v.compiler.modelbuilder.model.get_mclasses_by_name("Array")
if nas == null or nas.is_empty then return
var expr = explain_assert_str.expr(v)
if expr == null then return
var cstr = v.send(v.get_property("to_cstring", expr.mtype), [expr])
if cstr == null then return
v.add "PRINT_ERROR(\"Runtime assert: %s\\n\", {cstr});"
end
end
src/compiler/abstract_compiler.nit:3993,1--4033,3
redef class AAssertExpr
redef fun decorate_tag(v, res, token)
do
if not token isa TId then return null
res.add_class("nc_ast")
return null
end
end
src/htmlight.nit:883,1--890,3
redef class AAssertExpr
redef fun stmt(v) do
var cond = v.expr_bool(self.n_expr)
v.add("if (!{cond}) \{")
v.stmt(self.n_else)
var nid = self.n_id
if nid != null then
v.add_abort("Assert '{nid.text}' failed")
else
v.add_abort("Assert failed")
end
v.add("\}")
end
end
src/compiler/java_compiler.nit:2153,1--2166,3