# Display stats about compilation process
# Metrics used:
- # * type tests against resolved types (x isa Collection[Animal])
- # * type tests against unresolved types (x isa Collection[E])
+ # * type tests against resolved types (`x isa Collection[Animal]`)
+ # * type tests against unresolved types (`x isa Collection[E]`)
# * type tests skipped
# * type tests total
# *
# The current visited AST node
var current_node: nullable ANode writable = null
- # The current Frame
+ # The current `Frame`
var frame: nullable Frame writable
# Alias for self.compiler.mainmodule.object_type
self.writer = new CodeWriter(compiler.files.last)
end
- # Force to get the primitive class named `name' or abort
+ # Force to get the primitive class named `name` or abort
fun get_class(name: String): MClass do return self.compiler.mainmodule.get_primitive_class(name)
- # Force to get the primitive property named `name' in the instance `recv' or abort
+ # Force to get the primitive property named `name` in the instance `recv` or abort
fun get_property(name: String, recv: MType): MMethod
do
assert recv isa MClassType
fun native_array_def(pname: String, ret_type: nullable MType, arguments: Array[RuntimeVariable]) is abstract
- # Transform varargs, in raw arguments, into a single argument of type Array
+ # Transform varargs, in raw arguments, into a single argument of type `Array`
# Note: this method modify the given `args`
# If there is no vararg, then `args` is not modified.
fun varargize(mpropdef: MPropDef, msignature: MSignature, args: Array[RuntimeVariable])
# Unsafely cast a value to a new type
# ie the result share the same C variable but my have a different mcasttype
- # NOTE: if the adaptation is useless then `value' is returned as it.
- # ENSURE: return.name == value.name
+ # NOTE: if the adaptation is useless then `value` is returned as it.
+ # ENSURE: `(return).name == value.name`
fun autoadapt(value: RuntimeVariable, mtype: MType): RuntimeVariable
do
mtype = self.anchor(mtype)
# Generate a static call on a method definition
fun call(m: MMethodDef, recvtype: MClassType, args: Array[RuntimeVariable]): nullable RuntimeVariable is abstract
- # Generate a polymorphic send for the method `m' and the arguments `args'
+ # Generate a polymorphic send for the method `m` and the arguments `args`
fun send(m: MMethod, args: Array[RuntimeVariable]): nullable RuntimeVariable is abstract
- # Generate a monomorphic send for the method `m', the type `t' and the arguments `args'
+ # Generate a monomorphic send for the method `m`, the type `t` and the arguments `args`
fun monomorphic_send(m: MMethod, t: MType, args: Array[RuntimeVariable]): nullable RuntimeVariable
do
assert t isa MClassType
private var names: HashSet[String] = new HashSet[String]
private var last: Int = 0
- # Return a new name based on `s' and unique in the visitor
+ # Return a new name based on `s` and unique in the visitor
fun get_name(s: String): String
do
if not self.names.has(s) then
private var escapemark_names = new HashMap[EscapeMark, String]
# Return a "const char*" variable associated to the classname of the dynamic type of an object
- # NOTE: we do not return a RuntimeVariable "NativeString" as the class may not exist in the module/program
+ # NOTE: we do not return a `RuntimeVariable` "NativeString" as the class may not exist in the module/program
fun class_name_string(value: RuntimeVariable): String is abstract
# Variables handling
end
# look for a needed .h and .c file for a given .nit source-file
- # FIXME: bad API, parameter should be a MModule, not its source-file
+ # FIXME: bad API, parameter should be a `MModule`, not its source-file
fun add_extern(file: String)
do
file = file.strip_extension(".nit")
self.compiler.extern_bodies.add(f)
end
- # Return a new local runtime_variable initialized with the C expression `cexpr'.
+ # Return a new local runtime_variable initialized with the C expression `cexpr`.
fun new_expr(cexpr: String, mtype: MType): RuntimeVariable
do
var res = new_var(mtype)
self.add("exit(1);")
end
- # Generate a return with the value `s'
+ # Generate a return with the value `s`
fun ret(s: RuntimeVariable)
do
self.assign(self.frame.returnvar.as(not null), s)
return res
end
- # Alias for `self.expr(nexpr, self.bool_type)'
+ # Alias for `self.expr(nexpr, self.bool_type)`
fun expr_bool(nexpr: AExpr): RuntimeVariable do return expr(nexpr, bool_type)
# Safely show a debug message on the current node and repeat the message in the C code as a comment
# May inline the body or generate a C function call
fun call(v: VISITOR, arguments: Array[RuntimeVariable]): nullable RuntimeVariable is abstract
- # Generate the code for the RuntimeFunction
+ # Generate the code for the `AbstractRuntimeFunction`
# Warning: compile more than once compilation makes CC unhappy
fun compile_to_c(compiler: COMPILER) is abstract
end
# A runtime variable hold a runtime value in C.
# Runtime variables are associated to Nit local variables and intermediate results in Nit expressions.
#
-# The tricky point is that a single C variable can be associated to more than one RuntimeVariable because the static knowledge of the type of an expression can vary in the C code.
+# The tricky point is that a single C variable can be associated to more than one `RuntimeVariable` because the static knowledge of the type of an expression can vary in the C code.
class RuntimeVariable
# The name of the variable in the C code
var name: String
end
end
-# A frame correspond to a visited property in a GlobalCompilerVisitor
+# A frame correspond to a visited property in a `GlobalCompilerVisitor`
class Frame
type VISITOR: AbstractCompilerVisitor
redef class AExpr
# Try to compile self as an expression
- # Do not call this method directly, use `v.expr' instead
+ # Do not call this method directly, use `v.expr` instead
private fun expr(v: AbstractCompilerVisitor): nullable RuntimeVariable
do
v.add("printf(\"NOT YET IMPLEMENTED {class_name}:{location.to_s}\\n\");")
end
# Try to compile self as a statement
- # Do not call this method directly, use `v.stmt' instead
+ # Do not call this method directly, use `v.stmt` instead
private fun stmt(v: AbstractCompilerVisitor)
do
var res = expr(v)
# Utils
redef class Array[E]
- # Return a new Array with the elements only contened in 'self' and not in 'o'
+ # Return a new `Array` with the elements only contened in self and not in `o`
fun -(o: Array[E]): Array[E] do
var res = new Array[E]
for e in self do if not o.has(e) then res.add(e)
end
redef class MModule
- # All 'mproperties' associated to all 'mclassdefs' of `mclass`
+ # All `MProperty` associated to all `MClassDef` of `mclass`
fun properties(mclass: MClass): Set[MProperty] do
if not self.properties_cache.has_key(mclass) then
var properties = new HashSet[MProperty]
cache_mpropdef.static_mtype = mtype.as_nullable
# Create another new private attribute to store the boolean «is the function cached?»
- # The point is to manage the case where `null' is a genuine return value of the method
+ # The point is to manage the case where `null` is a genuine return value of the method
var is_cached_mpropdef = new MAttributeDef(mclassdef, new MAttribute(mclassdef, "@{name}<is_cached>", private_visibility), location)
is_cached_mpropdef.static_mtype = mclassdef.mmodule.get_primitive_class("Bool").mclass_type
# FIXME? Because there is a default value ("false") a real propdef is required
proxy_body.collect_tokens_by_text("_cache_write").first.text = cache_mpropdef.mproperty.name
proxy_body.collect_tokens_by_text("call_real").first.text = real_mpropdef.mproperty.name
- # FIXME a last transformation cannot be done yet. So, the call to `super` (ASuperExpr) is broken in cached methods.
+ # FIXME a last transformation cannot be done yet. So, the call to `super` (`ASuperExpr`) is broken in cached methods.
# Give the original body to the private real methoddef
real_npropdef.n_block.replace_with(real_body)
end
# Detach `n` from its original AST and attach it to `m` (and its related AST)
- # `n' must not be already attached to an existing model entity
- # `m' must not be already attached to an existing AST node
+ # `n` must not be already attached to an existing model entity
+ # `m` must not be already attached to an existing AST node
fun associate_propdef(m: MPropDef, n: APropdef)
do
# FIXME: the model-AST relations **must** be rationalized:
import poset
# A counter counts occurrences of things
-# Use this instead of a HashMap[E, Int]
+# Use this instead of a `HashMap[E, Int]`
class Counter[E: Object]
super Map[E, Int]
private var map = new HashMap[E, Int]
- # The number of counted occurrences of `e'
+ # The number of counted occurrences of `e`
redef fun [](e: E): Int
do
var map = self.map
redef fun values do return map.values
- # Count one more occurrence of `e'
+ # Count one more occurrence of `e`
fun inc(e: E)
do
self.map[e] = self[e] + 1
# Use `element_to_s` to display the element
fun print_elements(count: Int)
do
- # Display most used types (ie the last of `types')
print " list:"
var list = self.sort
var min = count
end
end
-# Helper function to display n/d and handle division by 0
+# Helper function to display `n/d` and handle division by 0
fun div(n: Int, d: Int): String
do
if d == 0 then return "na"
end
redef class ModelBuilder
- # Execute the program from the entry point (Sys::main) of the `mainmodule'
- # `arguments' are the command-line arguments in order
+ # Execute the program from the entry point (Sys::main) of the `mainmodule`
+ # `arguments` are the command-line arguments in order
# REQUIRE that:
# 1. the AST is fully loaded.
# 2. the model is fully built.
end
end
-# The class extending NaiveInterpreter by adding debugging methods
+# The class extending `NaiveInterpreter` by adding debugging methods
class Debugger
super NaiveInterpreter
end
# A Node in the static flow graph.
-# A same FlowContext can be shared by more than one ANode.
+# A same `FlowContext` can be shared by more than one `ANode`.
class FlowContext
# The reachable previous flow
var previous: Array[FlowContext] = new Array[FlowContext]
# Additional reachable flow that loop up to self.
- # Loops apears in 'loop', 'while', 'for', closure and with 'continue'
+ # Loops apears in `loop`, `while`, `for`, closure and with `continue`
var loops: Array[FlowContext] = new Array[FlowContext]
private var is_marked_unreachable: Bool = false
protected var classids: HashMap[MClassType, String] = new HashMap[MClassType, String]
# Declaration of structures the live Nit types
- # Each live type is generated as an independent C `struct' type.
+ # Each live type is generated as an independent C `struct` type.
# They only share a common first field `classid` used to implement the polymorphism.
- # Usualy, all C variables that refers to a Nit object are typed on the abstract struct `val' that contains only the `classid` field.
+ # Usualy, all C variables that refers to a Nit object are typed on the abstract struct `val` that contains only the `classid` field.
redef fun compile_header_structs do
self.header.add_decl("typedef struct \{int classid;\} val; /* general C type representing a Nit instance. */")
end
# Table layout builders
# Tables are used to implement objects mecanisms like:
-# * message sending
-# * attribute accessing
-# * typing
-# * resolution (for generic types)
+# * message sending
+# * attribute accessing
+# * typing
+# * resolution (for generic types)
# This module provides various layout for object tables:
-# * coloring
-# * binary matrix
-# * perfect hashing (and & mod operators)
+# * coloring
+# * binary matrix
+# * perfect hashing (and & mod operators)
module layout_builders
import abstract_compiler
f.close
end
-# Helper function for `generate_module_hierarchy'.
+# Helper function for `generate_module_hierarchy`.
# Create graphviz nodes for the module and recusrively for its nested modules
private fun generate_module_hierarchy_for(mmodule: MModule, buf: Buffer)
do
var nullable_sends: Int = 0
var buggy_sends: Int = 0
- # Get a new visitor on a classef to add type count in `typecount'.
+ # Get a new visitor on a classef to add type count in `typecount`.
init(modelbuilder: ModelBuilder, nclassdef: AClassdef)
do
self.modelbuilder = modelbuilder
var typecount: Counter[MType]
- # Get a new visitor on a classef to add type count in `typecount'.
+ # Get a new visitor on a classef to add type count in `typecount`.
init(modelbuilder: ModelBuilder, nclassdef: AClassdef, typecount: Counter[MType])
do
self.modelbuilder = modelbuilder
end
# Load a bunch of modules.
- # `modules' can contains filenames or module names.
+ # `modules` can contains filenames or module names.
# Imported modules are automatically loaded and modelized.
# The result is the corresponding model elements.
# Errors and warnings are printed with the toolcontext.
return mmodules
end
- # Return a class named `name' visible by the module `mmodule'.
+ # Return a class named `name` visible by the module `mmodule`.
# Visibility in modules is correctly handled.
# If no such a class exists, then null is returned.
- # If more than one class exists, then an error on `anode' is displayed and null is returned.
+ # If more than one class exists, then an error on `anode` is displayed and null is returned.
# FIXME: add a way to handle class name conflict
fun try_get_mclass_by_name(anode: ANode, mmodule: MModule, name: String): nullable MClass
do
return res
end
- # Return a property named `name' on the type `mtype' visible in the module `mmodule'.
+ # Return a property named `name` on the type `mtype` visible in the module `mmodule`.
# Visibility in modules is correctly handled.
# Protected properties are returned (it is up to the caller to check and reject protected properties).
# If no such a property exists, then null is returned.
- # If more than one property exists, then an error on `anode' is displayed and null is returned.
+ # If more than one property exists, then an error on `anode` is displayed and null is returned.
# FIXME: add a way to handle property name conflict
fun try_get_mproperty_by_name2(anode: ANode, mmodule: MModule, mtype: MType, name: String): nullable MProperty
do
var paths: Array[String] = new Array[String]
# Get a module by its short name; if required, the module is loaded, parsed and its hierarchies computed.
- # If `mmodule' is set, then the module search starts from it up to the top level (see `paths');
- # if `mmodule' is null then the module is searched in the top level only.
- # If no module exists or there is a name conflict, then an error on `anode' is displayed and null is returned.
+ # If `mmodule` is set, then the module search starts from it up to the top level (see `paths`);
+ # if `mmodule` is null then the module is searched in the top level only.
+ # If no module exists or there is a name conflict, then an error on `anode` is displayed and null is returned.
# FIXME: add a way to handle module name conflict
fun get_mmodule_by_name(anode: ANode, mmodule: nullable MModule, name: String): nullable MModule
do
var nmodules: Array[AModule] = new Array[AModule]
# Register the nmodule associated to each mmodule
- # FIXME: why not refine the MModule class with a nullable attribute?
+ # FIXME: why not refine the `MModule` class with a nullable attribute?
var mmodule2nmodule: HashMap[MModule, AModule] = new HashMap[MModule, AModule]
# Helper function to display an error on a node.
- # Alias for `self.toolcontext.error(n.hot_location, text)'
+ # Alias for `self.toolcontext.error(n.hot_location, text)`
fun error(n: ANode, text: String)
do
self.toolcontext.error(n.hot_location, text)
end
# Helper function to display a warning on a node.
- # Alias for: `self.toolcontext.warning(n.hot_location, text)'
+ # Alias for: `self.toolcontext.warning(n.hot_location, text)`
fun warning(n: ANode, text: String)
do
self.toolcontext.warning(n.hot_location, text)
end
- # Force to get the primitive method named `name' on the type `recv' or do a fatal error on `n'
+ # Force to get the primitive method named `name` on the type `recv` or do a fatal error on `n`
fun force_get_primitive_method(n: ANode, name: String, recv: MClass, mmodule: MModule): MMethod
do
var res = mmodule.try_get_primitive_method(name, recv)
end
redef class AModule
- # The associated MModule once build by a `ModelBuilder'
+ # The associated MModule once build by a `ModelBuilder`
var mmodule: nullable MModule
# Flag that indicate if the importation is already completed
var is_importation_done: Bool = false
end
redef class ModelBuilder
- # Visit the AST and create the MClass objects
+ # Visit the AST and create the `MClass` objects
private fun build_a_mclass(nmodule: AModule, nclassdef: AClassdef)
do
var mmodule = nmodule.mmodule.as(not null)
nmodule.mclass2nclassdef[mclass] = nclassdef
end
- # Visit the AST and create the MClassDef objects
+ # Visit the AST and create the `MClassDef` objects
private fun build_a_mclassdef(nmodule: AModule, nclassdef: AClassdef)
do
var mmodule = nmodule.mmodule.as(not null)
end
end
- # Visit the AST and set the super-types of the MClassdef objects
+ # Visit the AST and set the super-types of the `MClassDef` objects
private fun collect_a_mclassdef_inheritance(nmodule: AModule, nclassdef: AClassdef)
do
var mmodule = nmodule.mmodule.as(not null)
end
end
- # Build the classes of the module `nmodule'.
- # REQUIRE: classes of imported modules are already build. (let `phase' do the job)
+ # Build the classes of the module `nmodule`.
+ # REQUIRE: classes of imported modules are already build. (let `phase` do the job)
private fun build_classes(nmodule: AModule)
do
var errcount = toolcontext.error_count
end
# Register the nclassdef associated to each mclassdef
- # FIXME: why not refine the MClassDef class with a nullable attribute?
+ # FIXME: why not refine the `MClassDef` class with a nullable attribute?
var mclassdef2nclassdef: HashMap[MClassDef, AClassdef] = new HashMap[MClassDef, AClassdef]
- # Return the static type associated to the node `ntype'.
- # `classdef' is the context where the call is made (used to understand formal types)
- # The mmodule used as context is `nclassdef.mmodule'
- # In case of problem, an error is displayed on `ntype' and null is returned.
+ # Return the static type associated to the node `ntype`.
+ # `nclassdef` is the context where the call is made (used to understand formal types)
+ # The mmodule used as context is `nclassdef.mmodule`
+ # In case of problem, an error is displayed on `ntype` and null is returned.
# FIXME: the name "resolve_mtype" is awful
fun resolve_mtype_unchecked(nclassdef: AClassdef, ntype: AType, with_virtual: Bool): nullable MType
do
return null
end
- # Return the static type associated to the node `ntype'.
- # `classdef' is the context where the call is made (used to understand formal types)
- # The mmodule used as context is `nclassdef.mmodule'
- # In case of problem, an error is displayed on `ntype' and null is returned.
+ # Return the static type associated to the node `ntype`.
+ # `nclassdef` is the context where the call is made (used to understand formal types)
+ # The mmodule used as context is `nclassdef.mmodule`
+ # In case of problem, an error is displayed on `ntype` and null is returned.
# FIXME: the name "resolve_mtype" is awful
fun resolve_mtype(nclassdef: AClassdef, ntype: AType): nullable MType
do
redef class AModule
# Flag that indicate if the class building is already completed
var build_classes_is_done: Bool = false
- # What is the AClassdef associated to a MClass?
+ # What is the AClassdef associated to a `MClass`?
# Used to check multiple definition of a class.
var mclass2nclassdef: Map[MClass, AClassdef] = new HashMap[MClass, AClassdef]
end
redef class AClassdef
- # The associated MClass once build by a `ModelBuilder'
+ # The associated MClass once build by a `ModelBuilder`
var mclass: nullable MClass
- # The associated MClassDef once build by a `ModelBuilder'
+ # The associated MClassDef once build by a `ModelBuilder`
var mclassdef: nullable MClassDef
end
redef class ModelBuilder
# Register the npropdef associated to each mpropdef
- # FIXME: why not refine the MPropDef class with a nullable attribute?
+ # FIXME: why not refine the `MPropDef` class with a nullable attribute?
var mpropdef2npropdef: HashMap[MPropDef, APropdef] = new HashMap[MPropDef, APropdef]
- # Build the properties of `nclassdef'.
+ # Build the properties of `nclassdef`.
# REQUIRE: all superclasses are built.
private fun build_properties(nclassdef: AClassdef)
do
end
# Introduce or inherit default constructor
- # This is the last part of `build_properties'.
+ # This is the last part of `build_properties`.
private fun process_default_constructors(nclassdef: AClassdef)
do
var mclassdef = nclassdef.mclassdef.as(not null)
# The free init (implicitely constructed by the class if required)
var mfree_init: nullable MMethodDef = null
- # What is the APropdef associated to a MProperty?
+ # What is the `APropdef` associated to a `MProperty`?
# Used to check multiple definition of a property.
var mprop2npropdef: Map[MProperty, APropdef] = new HashMap[MProperty, APropdef]
end
# The associated main model entity
type MPROPDEF: MPropDef
- # The associated propdef once build by a `ModelBuilder'
+ # The associated propdef once build by a `ModelBuilder`
var mpropdef: nullable MPROPDEF writable
private fun build_property(modelbuilder: ModelBuilder, nclassdef: AClassdef) is abstract
end
redef class ModelBuilder
- # Execute the program from the entry point (Sys::main) of the `mainmodule'
- # `arguments' are the command-line arguments in order
+ # Execute the program from the entry point (`Sys::main`) of the `mainmodule`
+ # `arguments` are the command-line arguments in order
# REQUIRE that:
# 1. the AST is fully loaded.
# 2. the model is fully built.
var returnmark: nullable Frame = null
# Is a break executed?
- # Set this mark to skip the evaluation until a labeled statement catch it with `is_break'
+ # Set this mark to skip the evaluation until a labeled statement catch it with `is_break`
var breakmark: nullable EscapeMark = null
# Is a continue executed?
- # Set this mark to skip the evaluation until a labeled statement catch it with `is_continue'
+ # Set this mark to skip the evaluation until a labeled statement catch it with `is_continue`
var continuemark: nullable EscapeMark = null
# Is a return or a break or a continue executed?
# Read the value when you catch a mark or reach the end of a method
var escapevalue: nullable Instance = null
- # If there is a break and is associated with `escapemark', then return true an clear the mark.
- # If there is no break or if `escapemark' is null then return false.
+ # If there is a break and is associated with `escapemark`, then return true an clear the mark.
+ # If there is no break or if `escapemark` is null then return false.
# Use this function to catch a potential break.
fun is_break(escapemark: nullable EscapeMark): Bool
do
end
end
- # If there is a continue and is associated with `escapemark', then return true an clear the mark.
- # If there is no continue or if `escapemark' is null then return false.
+ # If there is a continue and is associated with `escapemark`, then return true an clear the mark.
+ # If there is no continue or if `escapemark` is null then return false.
# Use this function to catch a potential continue.
fun is_continue(escapemark: nullable EscapeMark): Bool
do
end
end
- # Evaluate `n' as an expression in the current context.
+ # Evaluate `n` as an expression in the current context.
# Return the value of the expression.
- # If `n' cannot be evaluated, then aborts.
+ # If `n` cannot be evaluated, then aborts.
fun expr(n: AExpr): nullable Instance
do
var frame = self.frame
return i
end
- # Evaluate `n' as a statement in the current context.
- # Do nothing if `n' is sull.
- # If `n' cannot be evaluated, then aborts.
+ # Evaluate `n` as a statement in the current context.
+ # Do nothing if `n` is null.
+ # If `n` cannot be evaluated, then aborts.
fun stmt(n: nullable AExpr)
do
if n != null then
end
end
- # Map used to store values of nodes that must be evaluated once in the system (AOnceExpr)
+ # Map used to store values of nodes that must be evaluated once in the system (`AOnceExpr`)
var onces: Map[ANode, Instance] = new HashMap[ANode, Instance]
- # Return the boolean instance associated with `val'.
+ # Return the boolean instance associated with `val`.
fun bool_instance(val: Bool): Instance
do
if val then return self.true_instance else return self.false_instance
end
- # Return the integer instance associated with `val'.
+ # Return the integer instance associated with `val`.
fun int_instance(val: Int): Instance
do
var ic = self.mainmodule.get_primitive_class("Int")
return new PrimitiveInstance[Int](ic.mclass_type, val)
end
- # Return the char instance associated with `val'.
+ # Return the char instance associated with `val`.
fun char_instance(val: Char): Instance
do
var ic = self.mainmodule.get_primitive_class("Char")
return new PrimitiveInstance[Char](ic.mclass_type, val)
end
- # Return the float instance associated with `val'.
+ # Return the float instance associated with `val`.
fun float_instance(val: Float): Instance
do
var ic = self.mainmodule.get_primitive_class("Float")
return new PrimitiveInstance[Float](ic.mclass_type, val)
end
- # The unique intance of the `true' value.
+ # The unique intance of the `true` value.
var true_instance: Instance
- # The unique intance of the `false' value.
+ # The unique intance of the `false` value.
var false_instance: Instance
- # The unique intance of the `null' value.
+ # The unique intance of the `null` value.
var null_instance: Instance
- # Return a new array made of `values'.
+ # Return a new array made of `values`.
# The dynamic type of the result is Array[elttype].
fun array_instance(values: Array[Instance], elttype: MType): Instance
do
return res
end
- # Return a new native string initialized with `txt'
+ # Return a new native string initialized with `txt`
fun native_string_instance(txt: String): Instance
do
var val = new Buffer.from(txt)
# Store known method, used to trace methods as thez are reached
var discover_call_trace: Set[MMethodDef] = new HashSet[MMethodDef]
- # Execute `mpropdef' for a `args' (where args[0] is the receiver).
- # Return a falue if `mpropdef' is a function, or null if it is a procedure.
+ # Execute `mpropdef` for a `args` (where `args[0]` is the receiver).
+ # Return a falue if `mpropdef` is a function, or null if it is a procedure.
# The call is direct/static. There is no message-seding/late-bindng.
fun call(mpropdef: MMethodDef, args: Array[Instance]): nullable Instance
do
return null
end
- # Execute `mproperty' for a `args' (where args[0] is the receiver).
- # Return a falue if `mproperty' is a function, or null if it is a procedure.
+ # Execute `mproperty` for a `args` (where `args[0]` is the receiver).
+ # Return a falue if `mproperty` is a function, or null if it is a procedure.
# The call is polimotphic. There is a message-seding/late-bindng according to te receiver (args[0]).
fun send(mproperty: MMethod, args: Array[Instance]): nullable Instance
do
return self.call(propdef, args)
end
- # Read the attribute `mproperty' of an instance `recv' and return its value.
+ # Read the attribute `mproperty` of an instance `recv` and return its value.
# If the attribute in not yet initialized, then aborts with an error message.
fun read_attribute(mproperty: MAttribute, recv: Instance): Instance
do
var collect_attr_propdef_cache = new HashMap[MType, Array[AAttrPropdef]]
- # Fill the initial values of the newly created instance `recv'.
- # `recv.mtype' is used to know what must be filled.
+ # Fill the initial values of the newly created instance `recv`.
+ # `recv.mtype` is used to know what must be filled.
fun init_instance(recv: Instance)
do
for npropdef in collect_attr_propdef(recv.mtype) do
end
end
- # Check that non nullable attributes of `recv' are correctly initialized.
+ # Check that non nullable attributes of `recv` are correctly initialized.
# This function is used as the last instruction of a new
fun check_init_instance(recv: Instance)
do
# else aborts
fun is_true: Bool do abort
- # Return true if `self' IS `o' (using the Nit semantic of is)
+ # Return true if `self` IS `o` (using the Nit semantic of is)
fun eq_is(o: Instance): Bool do return self is o
# Human readable object identity "Type#number"
redef class ANode
# Aborts the program with a message
- # `v' is used to know if a colored message is displayed or not
+ # `v` is used to know if a colored message is displayed or not
private fun fatal(v: NaiveInterpreter, message: String)
do
if v.modelbuilder.toolcontext.opt_no_color.value == true then
end
redef class APropdef
- # Execute a `mpropdef' associated with the current node.
+ # Execute a `mpropdef` associated with the current node.
private fun call(v: NaiveInterpreter, mpropdef: MMethodDef, args: Array[Instance]): nullable Instance
do
fatal(v, "NOT YET IMPLEMENTED method kind {class_name}. {mpropdef}")
end
end
- # Evaluate and set the default value of the attribute in `recv'
+ # Evaluate and set the default value of the attribute in `recv`
private fun init_expr(v: NaiveInterpreter, recv: Instance)
do
assert recv isa MutableInstance
end
redef class AClassdef
- # Execute an implicit `mpropdef' associated with the current node.
+ # Execute an implicit `mpropdef` associated with the current node.
private fun call(v: NaiveInterpreter, mpropdef: MMethodDef, args: Array[Instance]): nullable Instance
do
var super_inits = self.super_inits
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'
+ # NOTE: Do not call this method directly, but use `v.expr`
# This method is here to be implemented by subclasses.
private fun expr(v: NaiveInterpreter): nullable Instance
do
end
# Evaluate the node as a statement.
- # NOTE: Do not call this method directly, but use `v.stmt'
+ # 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).
private fun stmt(v: NaiveInterpreter)
do
# The name of the variable (as used in the program)
var name: String
- # Alias of `name'
+ # Alias of `name`
redef fun to_s do return self.name
end
# Visit a npropdef and:
# * Identify variables, closures and labels
# * Associate each break and continue to its escapemark
-# * Transform ACallFormExpr that access a variable into AVarFormExpr
-# * Transform ACallFormExpr that call a closure into AClosureCallExpr
+# * Transform `ACallFormExpr` that access a variable into `AVarFormExpr`
+# * Transform `ACallFormExpr` that call a closure into `AClosureCallExpr`
# FIXME: Should the class be private?
private class ScopeVisitor
super Visitor
scopes.add(new Scope)
end
- # All stacked scope. `scopes.first' is the current scope
+ # All stacked scope. `scopes.first` is the current scope
private var scopes: List[Scope] = new List[Scope]
# Regiter a local variable.
return true
end
- # Look for a variable named `name'.
+ # Look for a variable named `name`.
# Return null if no such a variable is found.
fun search_variable(name: String): nullable Variable
do
n.accept_scope_visitor(self)
end
- # Enter in a statement block `node' as inside a new scope.
- # The block can be optionally attached to an `escapemark'.
+ # Enter in a statement block `node` as inside a new scope.
+ # The block can be optionally attached to an `escapemark`.
private fun enter_visit_block(node: nullable AExpr, escapemark: nullable EscapeMark)
do
if node == null then return
scopes.shift
end
- # Look for a label `name'.
+ # Look for a label `name`.
# Return nulll if no such a label is found.
private fun search_label(name: String): nullable EscapeMark
do
# Look for an escape mark optionally associated with a label.
# If a label is given, the the escapemark of this label is returned.
- # If there is no label, the nearest escapemark that is `for loop' ir returned.
+ # If there is no label, the nearest escapemark that is `for loop` is returned.
# If there is no valid escapemark, then an error is displayed ans null is returned.
# Return nulll if no such a label is found.
private fun get_escapemark(node: ANode, nlabel: nullable ALabel): nullable EscapeMark
return res
end
- # Retrieve the signature of a MMethodDef resolved for a specific call.
+ # Retrieve the signature of a `MMethodDef` resolved for a specific call.
# This method is an helper to symplify the query on the model.
#
# Note: `for_self` indicates if the reciever is self or not.
# Check that `sub` is a subtype of `sup`.
# If `sub` is not a valud suptype, then display an error on `node` an return null.
# If `sub` is a safe subtype of `sup` then return `sub`.
- # If `sun` is an insafe subtype (ie an imlicit cast is required), then return `sup`.
+ # If `sub` is an insafe subtype (ie an imlicit cast is required), then return `sup`.
#
# The point of the return type is to determinate the usable type on an expression:
# If the suptype is safe, then the return type is the one on the expression typed by `sub`.
# Return the type of the expression
# Display an error and return null if:
# * the type cannot be determined or
- # * `nexpr' is a statement
+ # * `nexpr` is a statement
fun visit_expr(nexpr: AExpr): nullable MType
do
nexpr.accept_typing(self)
return null
end
- # Visit an expression and expect its static type is a least a `sup'
- # Return the type of the expression
+ # Visit an expression and expect its static type is a least a `sup`
+ # Return the type of the expression or null if
# * the type cannot be determined or
- # * `nexpr' is a statement
- # * `nexpt' is not a `sup'
+ # * `nexpr` is a statement or
+ # * `nexpr` is not a `sup`
fun visit_expr_subtype(nexpr: AExpr, sup: nullable MType): nullable MType
do
var sub = visit_expr(nexpr)
return res
end
- # Visit an expression and expect its static type is a bool
- # Return the type of the expression
+ # Visit an expression and expect its static type is a `Bool`
+ # Return the type of the expression or null if
# * the type cannot be determined or
- # * `nexpr' is a statement
- # * `nexpt' is not a `sup'
+ # * `nexpr` is a statement or
+ # * `nexpr` is not a `Bool`
fun visit_expr_bool(nexpr: AExpr): nullable MType
do
return self.visit_expr_subtype(nexpr, self.type_bool(nexpr))
var mtype: nullable MType = null
# Is the statement correctly typed?
- # Used to distinguish errors and statements when `mtype' == null
+ # Used to distinguish errors and statements when `mtype == null`
var is_typed: Bool = false
- # If required, the following implicit cast ".as(XXX)"
+ # 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 read_type: nullable MType = null
- # Determine the `reassign_property'
- # `readtype' is the type of the reading of the left value.
- # `writetype' is the type of the writing of the left value.
- # (Because of ACallReassignExpr, both can be different.
+ # Determine the `reassign_property`
+ # `readtype` is the type of the reading of the left value.
+ # `writetype` is the type of the writing of the left value.
+ # (Because of `ACallReassignExpr`, both can be different.
# Return the static type of the value to store.
private fun resolve_reassignment(v: TypeVisitor, readtype, writetype: MType): nullable MType
do
redef class AIsaExpr
# The static type to cast to.
- # (different from the static type of the expression that is Bool).
+ # (different from the static type of the expression that is `Bool`).
var cast_type: nullable MType
redef fun accept_typing(v)
do