# Add compiling options
redef class ToolContext
# --output
- var opt_output = new OptionString("Output file", "-o", "--output")
+ var opt_output = new OptionString("Filename of the generated executable", "-o", "--output")
# --dir
var opt_dir = new OptionString("Output directory", "--dir")
# --no-cc
- var opt_no_cc = new OptionBool("Do not invoke C compiler", "--no-cc")
+ var opt_no_cc = new OptionBool("Do not invoke the C compiler", "--no-cc")
# --no-main
var opt_no_main = new OptionBool("Do not generate main entry point", "--no-main")
# --make-flags
- var opt_make_flags = new OptionString("Additional options to make", "--make-flags")
+ var opt_make_flags = new OptionString("Additional options to the `make` command", "--make-flags")
# --max-c-lines
var opt_max_c_lines = new OptionInt("Maximum number of lines in generated C files. Use 0 for unlimited", 10000, "--max-c-lines")
# --group-c-files
# --no-check-attr-isset
var opt_no_check_attr_isset = new OptionBool("Disable isset tests before each attribute access (dangerous)", "--no-check-attr-isset")
# --no-check-assert
- var opt_no_check_assert = new OptionBool("Disable the evaluation of explicit 'assert' and 'as' (dangerous)", "--no-check-assert")
+ var opt_no_check_assert = new OptionBool("Disable the evaluation of explicit `assert` and `as` (dangerous)", "--no-check-assert")
# --no-check-autocast
var opt_no_check_autocast = new OptionBool("Disable implicit casts on unsafe expression usage (dangerous)", "--no-check-autocast")
# --no-check-null
# --no-stacktrace
var opt_no_stacktrace = new OptionBool("Disable the generation of stack traces", "--no-stacktrace")
# --no-gcc-directives
- var opt_no_gcc_directive = new OptionArray("Disable a advanced gcc directives for optimization", "--no-gcc-directive")
+ var opt_no_gcc_directive = new OptionArray("Disable advanced gcc directives for optimization", "--no-gcc-directive")
# --release
var opt_release = new OptionBool("Compile in release mode and finalize application", "--release")
# -g
- var opt_debug = new OptionBool("Compile in debug mode (no C-side optimization)", "--debug", "-g")
+ var opt_debug = new OptionBool("Compile in debug mode (no C-side optimization)", "-g", "--debug")
redef init
do
do
if v.compiler.modelbuilder.toolcontext.opt_no_check_covariance.value then return
+ var msignature = self.msignature.as(not null)
+
for i in [0..msignature.arity[ do
# skip test for vararg since the array is instantiated with the correct polymorphic type
if msignature.vararg_rank == i then continue
if not origmtype.need_anchor then continue
# get the parameter type
- var mtype = self.msignature.mparameters[i].mtype
+ var mtype = msignature.mparameters[i].mtype
# generate the cast
# note that v decides if and how to implements the cast
- v.add("/* Covariant cast for argument {i} ({self.msignature.mparameters[i].name}) {arguments[i+1].inspect} isa {mtype} */")
+ v.add("/* Covariant cast for argument {i} ({msignature.mparameters[i].name}) {arguments[i+1].inspect} isa {mtype} */")
v.add_cast(arguments[i+1], mtype, "covariance")
end
end
redef class ASuperExpr
redef fun expr(v)
do
- var recv = v.frame.arguments.first
+ var frame = v.frame.as(not null)
+ var recv = frame.arguments.first
var callsite = self.callsite
if callsite != null then
# Add automatic arguments for the super init call
args = [recv]
for i in [0..callsite.msignature.arity[ do
- args.add(v.frame.arguments[i+1])
+ args.add(frame.arguments[i+1])
end
else
args = v.varargize(callsite.mpropdef, callsite.signaturemap, recv, self.n_args.n_exprs)
var args
if self.n_args.n_exprs.is_empty then
- args = v.frame.arguments
+ args = frame.arguments
else
args = v.varargize(mpropdef, signaturemap, recv, self.n_args.n_exprs)
end
redef class ToolContext
# --discover-call-trace
- var opt_discover_call_trace = new OptionBool("Trace calls of the first invocation of a method", "--discover-call-trace")
+ var opt_discover_call_trace = new OptionBool("Trace calls of the first invocation of methods", "--discover-call-trace")
redef init
do
n.debug("inconsitance: no value and not escaping.")
end
var implicit_cast_to = n.implicit_cast_to
- if implicit_cast_to != null then
+ if i != null and implicit_cast_to != null then
var mtype = self.unanchor_type(implicit_cast_to)
if not self.is_subtype(i.mtype, mtype) then n.fatal(self, "Cast failed. Expected `{implicit_cast_to}`, got `{i.mtype}`")
end
# Execute type checks of covariant parameters
fun parameter_check(node: ANode, mpropdef: MMethodDef, args: Array[Instance])
do
- var msignature = mpropdef.msignature
+ var msignature = mpropdef.msignature.as(not null)
for i in [0..msignature.arity[ do
# skip test for vararg since the array is instantiated with the correct polymorphic type
if msignature.vararg_rank == i then continue
# Use this method, instead of `send` to execute and control the additional behavior of the call-sites
fun callsite(callsite: nullable CallSite, arguments: Array[Instance]): nullable Instance
do
+ if callsite == null then return null
var initializers = callsite.mpropdef.initializers
if not initializers.is_empty then
var recv = arguments.first
redef fun mdoc_or_fallback
do
if mdoc != null then return mdoc
+ var default_mmodule = self.default_mmodule
if default_mmodule == null then return null
return default_mmodule.mdoc_or_fallback
end
do
model.mmodules_by_name.add_one(name, self)
model.mmodules.add(self)
+ var mgroup = self.mgroup
if mgroup != null then
mgroup.mmodules.add(self)
if mgroup.name == name then
end
end
- # Is `self` created for internal purpose?
- # Fictive modules are instantiated internally but they should not be
- # exposed to the final user.
- var is_fictive: Bool = false is writable
-
# Is `self` a unit test module used by `nitunit`?
var is_test_suite: Bool = false is writable
for npropdef in nclassdef.n_propdefs do
if npropdef isa AMethPropdef then
if not npropdef.is_autoinit then continue # Skip non tagged autoinit
- if npropdef.mpropdef == null then return # Skip broken method
- var sig = npropdef.mpropdef.msignature
+ var mpropdef = npropdef.mpropdef
+ if mpropdef == null then return # Skip broken method
+ var sig = mpropdef.msignature
if sig == null then continue # Skip broken method
for param in sig.mparameters do
var mparameter = new MParameter(param.name, ret_type, false)
mparameters.add(mparameter)
end
- initializers.add(npropdef.mpropdef.mproperty)
- npropdef.mpropdef.mproperty.is_autoinit = true
+ initializers.add(mpropdef.mproperty)
+ mpropdef.mproperty.is_autoinit = true
end
if npropdef isa AAttrPropdef then
var mreadpropdef = npropdef.mreadpropdef
- if mreadpropdef == null or mreadpropdef.msignature == null then return # Skip broken attribute
+ if mreadpropdef == null then return # Skip broken attribute
+ var msignature = mreadpropdef.msignature
+ if msignature == null then return # Skip broken attribute
if npropdef.noinit then continue # Skip noinit attribute
var atlateinit = npropdef.get_single_annotation("lateinit", self)
if atlateinit != null then
end
if npropdef.has_value then continue
var paramname = mreadpropdef.mproperty.name
- var ret_type = mreadpropdef.msignature.return_mtype
+ var ret_type = msignature.return_mtype
if ret_type == null then return
var mparameter = new MParameter(paramname, ret_type, false)
mparameters.add(mparameter)
end
end
+ var the_root_init_mmethod = self.the_root_init_mmethod
if the_root_init_mmethod == null then return
# Look for most-specific new-stype init definitions
end
# Else create the local implicit basic init definition
- var mprop = the_root_init_mmethod.as(not null)
+ var mprop = the_root_init_mmethod
var mpropdef = new MMethodDef(mclassdef, mprop, nclassdef.location)
mpropdef.has_supercall = true
mpropdef.initializers.add_all(initializers)
var precursor_ret_type = msignature.return_mtype
var ret_type = mysignature.return_mtype
if ret_type != null and precursor_ret_type == null then
- modelbuilder.error(nsig.n_type.as(not null), "Redef Error: `{mpropdef.mproperty}` is a procedure, not a function.")
+ modelbuilder.error(nsig.n_type, "Redef Error: `{mpropdef.mproperty}` is a procedure, not a function.")
mpropdef.msignature = null
mpropdef.is_broken = true
return
# For parameters, type is always useless in a redef.
# For return type, type is useless if not covariant with introduction.
redef fun check_repeated_types(modelbuilder) do
+ var mpropdef = self.mpropdef
+ if mpropdef == null then return
if mpropdef.is_intro or n_signature == null then return
# check params
for param in n_signature.n_params do
end
is_lazy = true
var mlazyprop = new MAttribute(mclassdef, "lazy _" + name, none_visibility)
+ mlazyprop.is_fictive = true
var mlazypropdef = new MAttributeDef(mclassdef, mlazyprop, self.location)
+ mlazypropdef.is_fictive = true
self.mlazypropdef = mlazypropdef
end
# Type is useless if the attribute type is the same thant the intro.
redef fun check_repeated_types(modelbuilder) do
+ var mreadpropdef = self.mreadpropdef
+ if mreadpropdef == null then return
if mreadpropdef.is_intro or n_type == null then return
# get intro
var intro = mreadpropdef.mproperty.intro