new T
nitc :: ANewExpr :: defaultinit
nitc :: ANewExpr :: init_anewexpr
nitc :: pretty $ ANewExpr :: accept_pretty_printer
Start visit ofself
using a PrettyPrinterVisitor
nitc :: rapid_type_analysis $ ANewExpr :: accept_rapid_type_visitor
nitc :: typing $ ANewExpr :: accept_typing
nitc :: contracts $ ANewExpr :: check_callsite
nitc :: htmlight $ ANewExpr :: decorate_tag
Add aditionnal information on a child-token and return an additionnal HInfoBox on itnitc :: java_compiler $ ANewExpr :: expr
Try to compile self as an expressionnitc :: naive_interpreter $ ANewExpr :: expr
Evaluate the node as a possible expression.nitc :: abstract_compiler $ ANewExpr :: expr
Try to compile self as an expressionnitc :: ssa $ ANewExpr :: generate_basic_blocks
Generate recursively basic block for this expressionnitc :: pretty $ ANewExpr :: is_inlinable
Isself
printable in one line?
nitc :: parser_prod $ ANewExpr :: replace_child
Replace a child 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 itcore :: Cloneable :: defaultinit
nitc :: ANewExpr :: defaultinit
nitc :: AExpr :: defaultinit
core :: Object :: defaultinit
nitc :: Prod :: defaultinit
nitc :: ANode :: 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 :: ANewExpr :: init_anewexpr
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?
# An explicit instantiation. eg `new T`
class ANewExpr
super AExpr
# The `new` keyword
var n_kwnew: TKwnew is writable, noinit
# The `type` keyword
var n_type: AType is writable, noinit
# The name of the named-constructor, if any
var n_qid: nullable AQid = null is writable
# The arguments of the `new`
var n_args: AExprs is writable, noinit
end
src/parser/parser_nodes.nit:2373,1--2388,3
redef class ANewExpr
init init_anewexpr (
n_kwnew: nullable TKwnew,
n_type: nullable AType,
n_qid: nullable AQid,
n_args: nullable AExprs
)
do
_n_kwnew = n_kwnew.as(not null)
n_kwnew.parent = self
_n_type = n_type.as(not null)
n_type.parent = self
_n_qid = n_qid
if n_qid != null then n_qid.parent = self
_n_args = n_args.as(not null)
n_args.parent = self
end
redef fun replace_child(old_child: ANode, new_child: nullable ANode)
do
if _n_kwnew == old_child then
n_kwnew = new_child.as(TKwnew)
return
end
if _n_type == old_child then
n_type = new_child.as(AType)
return
end
if _n_qid == old_child then
n_qid = new_child.as(nullable AQid)
return
end
if _n_args == old_child then
n_args = new_child.as(AExprs)
return
end
end
redef fun n_kwnew=(node)
do
_n_kwnew = node
node.parent = self
end
redef fun n_type=(node)
do
_n_type = node
node.parent = self
end
redef fun n_qid=(node)
do
_n_qid = node
if node != null then node.parent = self
end
redef fun n_args=(node)
do
_n_args = node
node.parent = self
end
redef fun visit_all(v: Visitor)
do
v.enter_visit(_n_kwnew)
v.enter_visit(_n_type)
v.enter_visit(_n_qid)
v.enter_visit(_n_args)
end
end
src/parser/parser_prod.nit:5135,1--5202,3
redef class ANewExpr
redef fun accept_pretty_printer(v) do
var can_inline = v.can_inline(self)
v.visit n_kwnew
v.adds
v.visit n_type
if n_qid != null then
v.consume "."
if not can_inline then
v.forcen
v.indent += 1
v.addt
v.indent -= 1
end
v.visit n_qid
end
v.visit_args n_args.n_exprs
end
redef fun is_inlinable do return true
end
src/pretty.nit:1734,1--1758,3
redef class ANewExpr
# The constructor invoked by the new.
var callsite: nullable CallSite
# The designated type
var recvtype: nullable MClassType
redef fun accept_typing(v)
do
var recvtype = v.resolve_mtype(self.n_type)
if recvtype == null then return
if not recvtype isa MClassType then
if recvtype isa MNullableType then
v.error(self, "Type Error: cannot instantiate the nullable type `{recvtype}`.")
return
else if recvtype isa MFormalType then
v.error(self, "Type Error: cannot instantiate the formal type `{recvtype}`.")
return
else
v.error(self, "Type Error: cannot instantiate the type `{recvtype}`.")
return
end
end
self.recvtype = recvtype
var kind = recvtype.mclass.kind
var name: String
var nqid = self.n_qid
var node: ANode
if nqid != null then
name = nqid.n_id.text
node = nqid
else
name = "new"
node = self.n_kwnew
end
if name == "intern" then
if kind != concrete_kind then
v.error(self, "Type Error: cannot instantiate {kind} {recvtype}.")
return
end
if n_args.n_exprs.not_empty then
v.error(n_args, "Type Error: the intern constructor expects no arguments.")
return
end
# Our job is done
self.mtype = recvtype
return
end
var callsite = v.build_callsite_by_name(node, recvtype, name, false)
if callsite == null then return
if not callsite.mproperty.is_new then
if kind != concrete_kind then
v.error(self, "Type Error: cannot instantiate {kind} `{recvtype}`.")
return
end
self.mtype = recvtype
else
self.mtype = callsite.msignature.return_mtype
assert self.mtype != null
end
self.callsite = callsite
if not callsite.mproperty.is_init_for(recvtype.mclass) then
v.error(self, "Error: `{name}` is not a constructor.")
return
end
var args = n_args.to_a
callsite.check_signature(v, node, args)
end
redef fun dump_info(v) do
var res = super
var callsite = self.callsite
if callsite != null then
res += v.yellow(" call="+callsite.dump_info(v))
end
return res
end
end
src/semantize/typing.nit:2399,1--2484,3
redef class ANewExpr
private init make(callsite: CallSite, args: nullable Array[AExpr])
do
_n_kwnew = new TKwnew
_n_type = new AType.make
_n_args = new AListExprs
if args != null then
n_args.n_exprs.add_all(args)
end
self.callsite = callsite
self.recvtype = callsite.recv.as(MClassType)
if callsite.mproperty.is_new then
self.mtype = callsite.msignature.return_mtype
else
self.mtype = callsite.recv
end
self.is_typed = true
end
end
src/astbuilder.nit:600,1--618,3
redef class ANewExpr
redef fun expr(v)
do
var mtype = v.unanchor_type(self.recvtype.as(not null))
var recv: Instance = new MutableInstance(mtype)
v.init_instance(recv)
var callsite = self.callsite
if callsite == null then return recv
var args = v.varargize(callsite.mpropdef, callsite.signaturemap, recv, self.n_args.n_exprs)
if args == null then return null
var res2 = v.callsite(callsite, args)
if res2 != null then
#self.debug("got {res2} from {mproperty}. drop {recv}")
return res2
end
return recv
end
end
src/interpreter/naive_interpreter.nit:2374,1--2392,3
redef class ANewExpr
redef fun expr(v)
do
var mtype = self.recvtype
assert mtype != null
if mtype.mclass.name == "NativeArray" then
assert self.n_args.n_exprs.length == 1
var l = v.expr(self.n_args.n_exprs.first, null)
assert mtype isa MGenericType
var elttype = mtype.arguments.first
return v.native_array_instance(elttype, l)
end
var callsite = self.callsite
if callsite == null then return v.init_instance_or_extern(mtype)
if callsite.is_broken then return null
var recv
# new factories are badly implemented.
# They assume a stub temporary receiver exists.
# This temporary receiver is required because it
# currently holds the method and the formal types.
#
# However, this object could be reused if the formal types are the same.
# Therefore, the following code will `once` it in these case
if callsite.mproperty.is_new and not mtype.need_anchor then
var name = v.get_name("varoncenew")
var guard = v.get_name(name + "_guard")
v.add_decl("static {mtype.ctype} {name};")
v.add_decl("static int {guard};")
recv = v.new_var(mtype)
v.add("if (likely({guard})) \{")
v.add("{recv} = {name};")
v.add("\} else \{")
var i = v.init_instance_or_extern(mtype)
v.add("{recv} = {i};")
v.add("{name} = {recv};")
v.add("{guard} = 1;")
v.add("\}")
else
recv = v.init_instance_or_extern(mtype)
end
var args = v.varargize(callsite.mpropdef, callsite.signaturemap, recv, self.n_args.n_exprs)
var res2 = v.compile_callsite(callsite, args)
if res2 != null then
#self.debug("got {res2} from {mproperty}. drop {recv}")
return res2
end
return recv
end
end
src/compiler/abstract_compiler.nit:4493,1--4545,3
redef class ANewExpr
redef fun expr(v)
do
var mtype = self.recvtype
assert mtype != null
if mtype.mclass.name == "NativeArray" then
# TODO handle native arrays
v.info("NOT YET IMPLEMENTED new NativeArray")
end
var recv = v.init_instance(mtype)
var callsite = self.callsite
if callsite == null then return recv
var args = v.varargize(callsite.mpropdef, callsite.signaturemap, recv, self.n_args.n_exprs)
var res2 = v.compile_callsite(callsite, args)
if res2 != null then
return res2
end
return recv
end
end
src/compiler/java_compiler.nit:1941,1--1964,3