class ExternCFile
super ExternFile
- init (filename, cflags: String)
- do
- super filename
-
- self.cflags = cflags
- end
-
# Additionnal specific CC compiler -c flags
var cflags: String
var mainmodule: MModule is writable
# The real main module of the program
- var realmainmodule: MModule
+ var realmainmodule: MModule is noinit
# The modelbuilder used to know the model and the AST
var modelbuilder: ModelBuilder is protected writable
# Is hardening asked? (see --hardening)
fun hardening: Bool do return self.modelbuilder.toolcontext.opt_hardening.value
- init(mainmodule: MModule, modelbuilder: ModelBuilder)
+ init
do
- self.mainmodule = mainmodule
self.realmainmodule = mainmodule
- self.modelbuilder = modelbuilder
end
# Force the creation of a new file
fun new_visitor: VISITOR is abstract
# Where global declaration are stored (the main .h)
- var header: CodeWriter is writable
+ var header: CodeWriter is writable, noinit
# Provide a declaration that can be requested (before or latter) by a visitor
fun provide_declaration(key: String, s: String)
# (used for local or global declaration)
fun add_decl(s: String) do self.decl_lines.add(s)
- init(file: CodeFile)
+ init
do
- self.file = file
file.writers.add(self)
end
end
var current_node: nullable ANode = null is writable
# The current `Frame`
- var frame: nullable Frame is writable
+ var frame: nullable Frame = null is writable
# Alias for self.compiler.mainmodule.object_type
fun object_type: MClassType do return self.compiler.mainmodule.object_type
# Alias for self.compiler.mainmodule.bool_type
fun bool_type: MClassType do return self.compiler.mainmodule.bool_type
- var writer: CodeWriter
+ var writer: CodeWriter is noinit
- init(compiler: COMPILER)
+ init
do
- self.compiler = compiler
self.writer = new CodeWriter(compiler.files.last)
end
# false (usual value) means that the variable is a mcasttype or a subtype.
var is_exact: Bool = false is writable
- init(name: String, mtype: MType, mcasttype: MType)
+ init
do
- self.name = name
- self.mtype = mtype
- self.mcasttype = mcasttype
assert not mtype.need_anchor
assert not mcasttype.need_anchor
end
var poset: POSet[E]
- init(poset: POSet[E]) do
- self.poset = poset
+ init do
extract_core
extract_border
extract_crown
private var poset: POSet[H]
private var conflicts: Map[H, Set[H]]
- init(poset: POSet[H], conflicts: Map[H, Set[H]]) do
- self.poset = poset
- self.conflicts = conflicts
- end
-
# Colorize buckets using the POSet and conflict graph
fun colorize(buckets: Map[H, Set[E]]): Map[E, Int] do
colors.clear
# The result of the RTA (used to know live types and methods)
var runtime_type_analysis: RapidTypeAnalysis
- init(mainmodule: MModule, modelbuilder: ModelBuilder, runtime_type_analysis: RapidTypeAnalysis)
+ init
do
- super(mainmodule, modelbuilder)
var file = new_file("{mainmodule.name}.nitgg")
self.header = new CodeWriter(file)
- self.runtime_type_analysis = runtime_type_analysis
self.live_primitive_types = new Array[MClassType]
for t in runtime_type_analysis.live_types do
if t.ctype != "val*" or t.mclass.name == "Pointer" then
# Subset of runtime_type_analysis.live_types that contains only primitive types
# Used to implement the equal test
- var live_primitive_types: Array[MClassType]
+ var live_primitive_types: Array[MClassType] is noinit
# Add a new todo task
fun todo(m: AbstractRuntimeFunction)
# (usually is a live type but no strong guarantee)
var recv: MClassType
- init(mmethoddef: MMethodDef, recv: MClassType)
- do
- super(mmethoddef)
- self.recv = recv
- end
-
redef fun build_c_name
do
var res = self.c_name_cache
private var undead_types: Set[MType] = new HashSet[MType]
private var live_unresolved_types: Map[MClassDef, Set[MType]] = new HashMap[MClassDef, HashSet[MType]]
- private var type_ids: Map[MType, Int]
- private var type_colors: Map[MType, Int]
- private var opentype_colors: Map[MType, Int]
- protected var method_colors: Map[PropertyLayoutElement, Int]
- protected var attr_colors: Map[MAttribute, Int]
-
- init(mainmodule: MModule, mmbuilder: ModelBuilder, runtime_type_analysis: nullable RapidTypeAnalysis) do
- super(mainmodule, mmbuilder)
+ private var type_ids: Map[MType, Int] is noinit
+ private var type_colors: Map[MType, Int] is noinit
+ private var opentype_colors: Map[MType, Int] is noinit
+ protected var method_colors: Map[PropertyLayoutElement, Int] is noinit
+ protected var attr_colors: Map[MAttribute, Int] is noinit
+
+ init do
var file = new_file("nit.common")
self.header = new CodeWriter(file)
- self.runtime_type_analysis = runtime_type_analysis
self.compile_box_kinds
end
class SeparateErasureCompiler
super SeparateCompiler
- private var class_ids: Map[MClass, Int]
- private var class_colors: Map[MClass, Int]
- protected var vt_colors: Map[MVirtualTypeProp, Int]
+ private var class_ids: Map[MClass, Int] is noinit
+ private var class_colors: Map[MClass, Int] is noinit
+ protected var vt_colors: Map[MVirtualTypeProp, Int] is noinit
- init(mainmodule: MModule, mmbuilder: ModelBuilder, runtime_type_analysis: nullable RapidTypeAnalysis) do
- super
+ init do
# Class coloring
var poset = mainmodule.flatten_mclass_hierarchy
# Stats
- private var class_tables: Map[MClass, Array[nullable MClass]]
- private var vt_tables: Map[MClass, Array[nullable MPropDef]]
+ private var class_tables: Map[MClass, Array[nullable MClass]] is noinit
+ private var vt_tables: Map[MClass, Array[nullable MPropDef]] is noinit
redef fun display_sizes
do
# The Nitdoc class explores the model and generate pages for each mentities found
class Nitdoc
+ var ctx: ToolContext
var model: Model
var mainmodule: MModule
- var ctx: ToolContext
-
- init(ctx: ToolContext, model: Model, mainmodule: MModule) do
- self.ctx = ctx
- self.model = model
- self.mainmodule = mainmodule
- end
fun generate do
init_output_dir
private var mclasses = new HashSet[MClass]
private var mpropdefs = new HashMap[String, Set[MPropDef]]
- init(ctx: ToolContext, model: Model) do
+ var ctx: ToolContext
+ var model: Model
+
+ init do
for mmodule in model.mmodules do
if mmodule.is_fictive then continue
mmodules.add mmodule
private var mainmodule: MModule
private var name_sorter = new MEntityNameSorter
- init(ctx: ToolContext, model: Model, mainmodule: MModule) do
- self.ctx = ctx
- self.model = model
- self.mainmodule = mainmodule
- end
-
# Render the page as a html template
fun render: Template do
var shareurl = "."
private var mgroup: MGroup
- private var concerns: ConcernsTree
- private var intros: Set[MClass]
- private var redefs: Set[MClass]
+ private var concerns: ConcernsTree is noinit
+ private var intros: Set[MClass] is noinit
+ private var redefs: Set[MClass] is noinit
- init(ctx: ToolContext, model: Model, mainmodule: MModule, mgroup: MGroup) do
- super
- self.mgroup = mgroup
+ init do
self.concerns = model.concerns_tree(mgroup.collect_mmodules)
self.concerns.sort_with(new MConcernRankSorter)
self.intros = mgroup.in_nesting_intro_mclasses(ctx.min_visibility)
super NitdocPage
private var mmodule: MModule
- private var concerns: ConcernsTree
- private var mclasses2mdefs: Map[MClass, Set[MClassDef]]
- private var mmodules2mclasses: Map[MModule, Set[MClass]]
+ private var concerns: ConcernsTree is noinit
+ private var mclasses2mdefs: Map[MClass, Set[MClassDef]] is noinit
+ private var mmodules2mclasses: Map[MModule, Set[MClass]] is noinit
- init(ctx: ToolContext, model: Model, mainmodule: MModule, mmodule: MModule) do
- super
- self.mmodule = mmodule
+ init do
var mclassdefs = new HashSet[MClassDef]
mclassdefs.add_all mmodule.intro_mclassdefs(ctx.min_visibility)
mclassdefs.add_all mmodule.redef_mclassdefs(ctx.min_visibility)
super NitdocPage
private var mclass: MClass
- private var concerns: ConcernsTree
- private var mprops2mdefs: Map[MProperty, Set[MPropDef]]
- private var mmodules2mprops: Map[MModule, Set[MProperty]]
+ private var concerns: ConcernsTree is noinit
+ private var mprops2mdefs: Map[MProperty, Set[MPropDef]] is noinit
+ private var mmodules2mprops: Map[MModule, Set[MProperty]] is noinit
- init(ctx: ToolContext, model: Model, mainmodule: MModule, mclass: MClass) do
- super
- self.mclass = mclass
+ init do
var mpropdefs = new HashSet[MPropDef]
mpropdefs.add_all mclass.intro_mpropdefs(ctx.min_visibility)
mpropdefs.add_all mclass.redef_mpropdefs(ctx.min_visibility)
super NitdocPage
private var mproperty: MProperty
- private var concerns: ConcernsTree
- private var mmodules2mdefs: Map[MModule, Set[MPropDef]]
+ private var concerns: ConcernsTree is noinit
+ private var mmodules2mdefs: Map[MModule, Set[MPropDef]] is noinit
- init(ctx: ToolContext, model: Model, mainmodule: MModule, mproperty: MProperty) do
- super
+ init do
self.mproperty = mproperty
self.mmodules2mdefs = sort_by_mmodule(collect_mpropdefs)
self.concerns = model.concerns_tree(mmodules2mdefs.keys)
# JS scripts to append at the end of the body
var scripts = new Array[TplScript]
- init do end
-
# Add a section to this page
fun add_section(section: TplSection) do
sections.add section
# Used to select the active link.
private var current_url: String
- init(current_url: String) do
- self.current_url = current_url
- end
-
# Add a new link to the menu.
fun add_link(content: TplLink) do
var is_active = content.href == current_url
# Box HTML id
# equals to `title.to_cmangle` by default
# Used for collapsing
- var id: String
+ var id: String is noinit
# Content to display in the box
# box will not be rendered if the content is null
- var content: nullable Streamable is writable
+ var content: nullable Streamable = null is writable
# Is the box opened by default
# otherwise, the user will have to clic on the title to display the content
var is_open = false is writable
- init(title: String) do
- self.title = title
+ init do
self.id = title.to_cmangle
end
# Will be displayed as a tree
var children = new Array[TplSummaryElt]
- init(text: Streamable) do self.text = text
-
redef fun add_child(child) do children.add child
redef fun rendering do
# Title to display if any
# if both `title` and `summary_title` are null then
# the section will not appear in the summary
- var title: nullable Streamable is writable
+ var title: nullable Streamable = null is writable
# Subtitle to display if any
- var subtitle: nullable Streamable is writable
+ var subtitle: nullable Streamable = null is writable
# Title that appear in the summary
# if null use `title` instead
- var summary_title: nullable String is writable
+ var summary_title: nullable String = null is writable
# CSS classes to apply on the section element
var css_classes = new Array[String]
var title_classes = new Array[String]
# Parent article/section if any
- var parent: nullable TplSectionElt
-
- init(id: String) do self.id = id
+ var parent: nullable TplSectionElt = null
init with_title(id: String, title: Streamable) do
init(id)
var text: Streamable is writable
# Optional title
- var title: nullable String is writable
-
- init(href, text: String) do
- self.href = href
- self.text = text
- end
+ var title: nullable String = null is writable
init with_title(href, text, title: String) do
init(href, text)
# The panel id.
#
# Used to show/hide panel.
- var id: String
+ var id: String is noinit
# The panel name.
#
var name: String
var value: nullable String
- init(name: String, value: nullable String) do
- self.name = name
- self.value = value
- end
-
redef fun rendering do
var value = self.value
if value == null then
var tracker_url: String
var site_id: String
- init(tracker_url, site_id: String) do
- super
- self.tracker_url = tracker_url
- self.site_id = site_id
- end
-
redef fun render_content do
add "<!-- Piwik -->"
add "var _paq = _paq || [];"
super ForeignType
redef var ctype: String
-
- init(ctype: String)
- do
- self.ctype = ctype
- end
end
redef class NitniCallback
class ToCCallContext
super CallContext
- private init do end
+ # TODO: private init because singleton instance (see `to_c_call_context`)
redef fun name_mtype(mtype)
do
class FromCCallContext
super CallContext
- private init do end
+ # TODO: private init because singleton instance (see `from_c_call_context`)
redef fun name_mtype(mtype) do return mtype.cname
end
super CCompilerOption
var option: String
- init (opt: String) do option = opt
end
class ExecCCompilerOption
var command: Array[String]
var exec_node: ACallExpr
-
- init (command: Array[String], exec_node: ACallExpr)
- do
- self.command = command
- self.exec_node = exec_node
- end
end
super ExternFile
var mmodule: MModule
- init(path: String, mmodule: MModule)
- do
- super
- self.mmodule = mmodule
- end
redef fun makefile_rule_name do return "{filename.basename("")}.o"
redef fun makefile_rule_content do return "$(CXX) $(CFLAGS) {mmodule.cpp_compiler_options} -c {filename.basename("")} -o {filename.basename("")}.o"
super ForeignType
var cpp_type: String
-
- init (cpp_type: String)
- do
- self.cpp_type = cpp_type
- end
end
redef class NitniCallback
# Visitor for a specific languages. Works kinda like a `Phase` and is executed
# by a `Phase`.
class FFILanguage
- init(ffi_language_assignation_phase: FFILanguageAssignationPhase)
+ var ffi_language_assignation_phase: FFILanguageAssignationPhase
+
+ init
do
ffi_language_assignation_phase.languages.add(self)
end
super Template
var java_class_name: String
- init(name: String) do self.java_class_name = name
var header = new Template
var class_content = new Template
super ForeignType
var java_type: String
- init (java_type: String) do self.java_type = java_type
end
redef class NitniCallback
private class CachedPhase
super Phase
- init(toolcontext, depends)
+ init
do
# FIXME The phase has to be executed just after `modelize_property_phase`
# But there is no simple way to express this
# The mmodule is the current module
var mmodule: MModule
- init(toolcontext: ToolContext, mmodule: MModule)
- do
- self.toolcontext = toolcontext
- self.mmodule = mmodule
- end
-
redef fun visit(node)
do
# Recursively visit all sub-nodes
var mclassdef: MClassDef
var toolcontext: ToolContext
- init(npropdef: AMethPropdef, mclassdef: MClassDef, toolcontext: ToolContext)
- do
- self.npropdef = npropdef
- self.mclassdef = mclassdef
- self.toolcontext = toolcontext
- end
-
redef fun visit(n) do n.accept_precise_type_visitor(self)
end
do
toolcontext.warning(node.hot_location, tag, msg)
end
-
- init(toolcontext: ToolContext)
- do
- self.toolcontext = toolcontext
- end
end
redef class ScopeVisitor
- redef init(toolcontext)
+ redef init
do
super
if toolcontext.dbg != null then
private class TraceObject
# Map of the local names bound to a frame
- var trace_map: HashMap[Frame, String]
+ var trace_map = new HashMap[Frame, String]
+
# Decides if breaking or printing statement when the variable is encountered
var break_on_encounter: Bool
- init(break_on_encounter: Bool)
- do
- trace_map = new HashMap[Frame, String]
- self.break_on_encounter = break_on_encounter
- end
-
# Adds the local alias for a variable and the frame bound to it
fun add_frame_variable(frame: Frame, variable_name: String)
do
var arguments: Array[String]
# The main Sys instance
- var mainobj: nullable Instance
+ var mainobj: nullable Instance is noinit
- init(modelbuilder: ModelBuilder, mainmodule: MModule, arguments: Array[String])
+ init
do
- self.modelbuilder = modelbuilder
- self.mainmodule = mainmodule
- self.arguments = arguments
self.true_instance = new PrimitiveInstance[Bool](mainmodule.bool_type, true)
self.false_instance = new PrimitiveInstance[Bool](mainmodule.bool_type, false)
self.null_instance = new MutableInstance(mainmodule.model.null_type)
end
# The unique instance of the `true` value.
- var true_instance: Instance
+ var true_instance: Instance is noinit
# The unique instance of the `false` value.
- var false_instance: Instance
+ var false_instance: Instance is noinit
# The unique instance of the `null` value.
- var null_instance: Instance
+ var null_instance: Instance is noinit
# Return a new array made of `values`.
# The dynamic type of the result is Array[elttype].
# The real value encapsulated
redef var val: E
- init(mtype: MType, val: E)
- do
- super(mtype)
- self.val = val
- end
-
redef fun is_true
do
if val == true then return true
var toolcontext: ToolContext
- init(toolcontext: ToolContext)
- do
- self.toolcontext = toolcontext
- end
-
redef fun visit(n)
do
n.accept_literal(self)
var filename: String
# The content of the source
- var string: String
+ var string: String is noinit
- # Create a new sourcefile using a filename and a stream
- init(filename: String, stream: IStream)
+ # The original stream used to initialize `string`
+ var stream: IStream
+
+ init
do
- self.filename = filename
string = stream.read_all
line_starts[0] = 0
end
var column_start: Int
var column_end: Int
- init(f: nullable SourceFile, line_s: Int, line_e: Int, column_s: Int, column_e: Int) do
- file = f
- line_start = line_s
- line_end = line_e
- column_start = column_s
- column_end = column_e
- end
-
# The index in the start character in the source
fun pstart: Int do return file.line_starts[line_start-1] + column_start-1
return res
end
- private var text_cache: nullable String
+ private var text_cache: nullable String = null
init with_file(f: SourceFile) do init(f,0,0,0,0)
# The view of the module in the `model.mmodule_nesting_hierarchy`
#
# TODO REMOVE, rely on mgroup instead
- var in_nesting: POSetElement[MModule]
+ var in_nesting: POSetElement[MModule] is noinit
# The view of the module in the `model.mmodule_importation_hierarchy`
- var in_importation: POSetElement[MModule]
+ var in_importation: POSetElement[MModule] is noinit
# The canonical name of the module
# Example: `"project::name"`
end
# Create a new empty module and register it to a model
- init(model: Model, mgroup: nullable MGroup, name: String, location: Location)
+ init
do
- self.model = model
- self.name = name
- self.location = location
model.mmodules_by_name.add_one(name, self)
model.mmodules.add(self)
self.in_nesting = model.mmodule_nesting_hierarchy.add_node(self)
- self.mgroup = mgroup
if mgroup != null then
mgroup.mmodules.add(self)
if mgroup.name == name then
# The number of generic formal parameters
# 0 if the class is not generic
- var arity: Int
+ var arity: Int is noinit
# Each generic formal parameters in order.
# is empty if the class is not generic
var mparameters = new Array[MParameterType]
- # The kind of the class (interface, abstract class, etc.)
- # In Nit, the kind of a class cannot evolve in refinements
- var kind: MClassKind
-
- # The visibility of the class
- # In Nit, the visibility of a class cannot evolve in refinements
- var visibility: MVisibility
-
- init(intro_mmodule: MModule, name: String, parameter_names: nullable Array[String], kind: MClassKind, visibility: MVisibility)
+ protected fun setup_parameter_names(parameter_names: nullable Array[String]) is
+ autoinit
do
- self.intro_mmodule = intro_mmodule
- self.name = name
if parameter_names == null then
self.arity = 0
else
self.arity = parameter_names.length
end
- self.kind = kind
- self.visibility = visibility
- intro_mmodule.intro_mclasses.add(self)
- var model = intro_mmodule.model
- model.mclasses_by_name.add_one(name, self)
- model.mclasses.add(self)
# Create the formal parameter types
if arity > 0 then
end
end
+ # The kind of the class (interface, abstract class, etc.)
+ # In Nit, the kind of a class cannot evolve in refinements
+ var kind: MClassKind
+
+ # The visibility of the class
+ # In Nit, the visibility of a class cannot evolve in refinements
+ var visibility: MVisibility
+
+ init
+ do
+ intro_mmodule.intro_mclasses.add(self)
+ var model = intro_mmodule.model
+ model.mclasses_by_name.add_one(name, self)
+ model.mclasses.add(self)
+ end
+
redef fun model do return intro_mmodule.model
# All class definitions (introduction and refinements)
#
# Warning: such a definition may not exist in the early life of the object.
# In this case, the method will abort.
- var intro: MClassDef
+ var intro: MClassDef is noinit
# Return the class `self` in the class hierarchy of the module `mmodule`.
#
# To get other types based on a generic class, see `get_mtype`.
#
# ENSURE: `mclass_type.mclass == self`
- var mclass_type: MClassType
+ var mclass_type: MClassType is noinit
# Return a generic type based on the class
# Is the class is not generic, then the result is `mclass_type`
var mmodule: MModule
# The associated `MClass`
- var mclass: MClass
+ var mclass: MClass is noinit
# The bounded type associated to the mclassdef
#
# Internal name combining the module and the class
# Example: "mymodule#MyClass"
- redef var to_s: String
+ redef var to_s: String is noinit
- init(mmodule: MModule, bound_mtype: MClassType, location: Location)
+ init
do
- self.bound_mtype = bound_mtype
- self.mmodule = mmodule
self.mclass = bound_mtype.mclass
- self.location = location
mmodule.mclassdefs.add(self)
mclass.mclassdefs.add(self)
if mclass.intro_mmodule == mmodule then
redef fun model do return self.mclass.intro_mmodule.model
- private init(mclass: MClass)
- do
- self.mclass = mclass
- end
+ # TODO: private init because strongly bounded to its mclass. see `mclass.mclass_type`
# The formal arguments of the type
# ENSURE: `result.length == self.mclass.arity`
class MGenericType
super MClassType
- private init(mclass: MClass, arguments: Array[MType])
+ redef var arguments
+
+ # TODO: private init because strongly bounded to its mclass. see `mclass.get_mtype`
+
+ init
do
- super(mclass)
assert self.mclass.arity == arguments.length
- self.arguments = arguments
self.need_anchor = false
for t in arguments do
# Recursively print the type of the arguments within brackets.
# Example: `"Map[String, List[Int]]"`
- redef var to_s: String
+ redef var to_s: String is noinit
- redef var need_anchor: Bool
+ redef var need_anchor: Bool is noinit
redef fun resolve_for(mtype, anchor, mmodule, cleanup_virtual)
do
end
redef fun to_s do return self.mproperty.to_s
-
- init(mproperty: MProperty)
- do
- self.mproperty = mproperty
- end
end
# The type associated to a formal parameter generic type of a class
end
return mtype.collect_mclassdefs(mmodule).has(mclass.intro)
end
-
- init(mclass: MClass, rank: Int, name: String)
- do
- self.mclass = mclass
- self.rank = rank
- self.name = name
- end
end
# A type prefixed with "nullable"
redef fun model do return self.mtype.model
- init(mtype: MType)
+ init
do
- self.mtype = mtype
self.to_s = "nullable {mtype}"
end
- redef var to_s: String
+ redef var to_s: String is noinit
redef fun need_anchor do return mtype.need_anchor
redef fun as_nullable do return self
class MNullType
super MType
redef var model: Model
- protected init(model: Model)
- do
- self.model = model
- end
redef fun to_s do return "null"
redef fun as_nullable do return self
redef fun need_anchor do return false
end
# REQUIRE: 1 <= mparameters.count p -> p.is_vararg
- init(mparameters: Array[MParameter], return_mtype: nullable MType)
+ init
do
var vararg_rank = -1
for i in [0..mparameters.length[ do
vararg_rank = i
end
end
- self.mparameters = mparameters
- self.return_mtype = return_mtype
self.vararg_rank = vararg_rank
end
# The rank of the ellipsis (`...`) for vararg (starting from 0).
# value is -1 if there is no vararg.
# Example: for "(a: Int, b: Bool..., c: Char)" #-> vararg_rank=1
- var vararg_rank: Int
+ var vararg_rank: Int is noinit
# The number or parameters
fun arity: Int do return mparameters.length
# Is the parameter a vararg?
var is_vararg: Bool
- init(name: String, mtype: MType, is_vararg: Bool) do
- self.name = name
- self.mtype = mtype
- self.is_vararg = is_vararg
- end
-
redef fun to_s
do
if is_vararg then
# The visibility of the property
var visibility: MVisibility
- init(intro_mclassdef: MClassDef, name: String, visibility: MVisibility)
+ init
do
- self.intro_mclassdef = intro_mclassdef
- self.name = name
- self.visibility = visibility
intro_mclassdef.intro_mproperties.add(self)
var model = intro_mclassdef.mmodule.model
model.mproperties_by_name.add_one(name, self)
#
# Warning: such a definition may not exist in the early life of the object.
# In this case, the method will abort.
- var intro: MPROPDEF
+ var intro: MPROPDEF is noinit
redef fun model do return intro.model
redef type MPROPDEF: MMethodDef
- init(intro_mclassdef: MClassDef, name: String, visibility: MVisibility)
- do
- super
- end
-
# Is the property defined at the top_level of the module?
# Currently such a property are stored in `Object`
var is_toplevel: Bool = false is writable
redef type MPROPDEF: MAttributeDef
- init(intro_mclassdef: MClassDef, name: String, visibility: MVisibility)
- do
- super
- end
end
# A global virtual type
redef type MPROPDEF: MVirtualTypeDef
- init(intro_mclassdef: MClassDef, name: String, visibility: MVisibility)
- do
- super
- end
-
# The formal type associated to the virtual type property
var mvirtualtype = new MVirtualType(self)
end
# Self class
type MPROPDEF: MPropDef
- # The origin of the definition
- var location: Location
-
# The class definition where the property definition is
var mclassdef: MClassDef
# The associated global property
var mproperty: MPROPERTY
- init(mclassdef: MClassDef, mproperty: MPROPERTY, location: Location)
+ # The origin of the definition
+ var location: Location
+
+ init
do
- self.mclassdef = mclassdef
- self.mproperty = mproperty
- self.location = location
mclassdef.mpropdefs.add(self)
mproperty.mpropdefs.add(self)
if mproperty.intro_mclassdef == mclassdef then
# Internal name combining the module, the class and the property
# Example: "mymodule#MyClass#mymethod"
- redef var to_s: String
+ redef var to_s: String is noinit
# Is self the definition that introduce the property?
fun is_intro: Bool do return mproperty.intro == self
redef type MPROPERTY: MMethod
redef type MPROPDEF: MMethodDef
- init(mclassdef: MClassDef, mproperty: MPROPERTY, location: Location)
- do
- super
- end
-
# The signature attached to the property definition
var msignature: nullable MSignature = null is writable
redef type MPROPERTY: MAttribute
redef type MPROPDEF: MAttributeDef
- init(mclassdef: MClassDef, mproperty: MPROPERTY, location: Location)
- do
- super
- end
-
# The static type of the attribute
var static_mtype: nullable MType = null is writable
end
redef type MPROPERTY: MVirtualTypeProp
redef type MPROPDEF: MVirtualTypeDef
- init(mclassdef: MClassDef, mproperty: MPROPERTY, location: Location)
- do
- super
- end
-
# The bound of the virtual type
var bound: nullable MType = null is writable
# Is a constructor required?
var need_init: Bool
- private init(s: String, need_init: Bool)
- do
- self.to_s = s
- self.need_init = need_init
- end
+
+ # TODO: private init because enumeration.
# Can a class of kind `self` specializes a class of kine `other`?
fun can_specialize(other: MClassKind): Bool
private var level: Int
- private init(s: String, level: Int)
- do
- self.to_s = s
- self.level = level
- end
+ # TODO: private init because enumeration.
# Is self give less visibility than other
# none < private < protected < public < intrude
# The model where to look for information
var model: Model
- init(model: Model) do self.model = model
-
redef fun display(a) do
if a isa MGroup then
if a.parent == null then return "{a.mproject.name} ({a.filepath.to_s})"
redef fun to_s do return name
- init(name: String, model: Model)
+ init
do
- self.name = name
- self.model = model
model.mprojects.add(self)
model.mproject_by_name.add_one(name, self)
end
# The group is the group tree on the project (`mproject.mgroups`)
# nested groups (children) are smaller
# nesting group (see `parent`) is bigger
- var in_nesting: POSetElement[MGroup]
+ var in_nesting: POSetElement[MGroup] is noinit
# Is `self` the root of its project?
fun is_root: Bool do return mproject.root == self
# The filepath (usually a directory) of the group, if any
- var filepath: nullable String is writable
+ var filepath: nullable String = null is writable
- init (name: String, mproject: MProject, parent: nullable MGroup)
+ init
do
- self.name = name
- self.mproject = mproject
- self.parent = parent
var tree = mproject.mgroups
self.in_nesting = tree.add_node(self)
+ var parent = self.parent
if parent != null then
tree.add_edge(self, parent)
end
# Instantiate a modelbuilder for a model and a toolcontext
# Important, the options of the toolcontext must be correctly set (parse_option already called)
- init(model: Model, toolcontext: ToolContext)
+ init
do
- self.model = model
- self.toolcontext = toolcontext
assert toolcontext.modelbuilder_real == null
toolcontext.modelbuilder_real = self
# Length of the signature of a C function (long version hase the module name as prefix)
class SignatureLength
private var long: Bool
- private init(long: Bool) do self.long = long
+
+ # TODO: private init because singleton class.
end
# then wait for query on std in to display documentation
class NitIndex
private var toolcontext: ToolContext
- private var model: Model
- private var mbuilder: ModelBuilder
- private var mainmodule: MModule
- private var arguments: Array[String]
- private var renderer: PagerMatchesRenderer
+ private var model: Model is noinit
+ private var mbuilder: ModelBuilder is noinit
+ private var mainmodule: MModule is noinit
+ private var arguments: Array[String] is noinit
+ private var renderer: PagerMatchesRenderer is noinit
# New constructor to use the pre-calculated model when interpreting a module
init with_infos(mbuilder: ModelBuilder, mmodule: MModule) do
renderer = new PagerMatchesRenderer(self)
end
- init(toolcontext: ToolContext) do
+ init do
# We need a model to collect stufs
- self.toolcontext = toolcontext
self.arguments = toolcontext.option_context.rest
if arguments.length > 2 then
private class IndexQuery
var string: String
var keyword: String
- init(string: String, keyword: String) do
- self.string = string
- self.keyword = keyword
- end
end
private class IndexQueryPair
super IndexQuery
var category: String
- init(string: String, keyword: String, category: String) do
- super(string, keyword)
- self.category = category
- end
end
# A match to a query in the nit index
private class PagerMatchesRenderer
var index: NitIndex
- init(index: NitIndex) do self.index = index
fun render_matches(query: IndexQuery, matches: Collection[IndexMatch]) do
var pager = new Pager
# It is better user with the Parser
class Lexer
super TablesCapable
+
# Last peeked token
- var token: nullable Token
+ var token: nullable Token = null
# Lexer current state
private var state: Int = 0
# Constante state values
private fun state_initial: Int do return 0 end
- # Create a new lexer for a stream (and a name)
- init(file: SourceFile)
- do
- self.file = file
- end
-
# The last peeked token to chain them
private var last_token: nullable Token = null
class Start
super Prod
var n_base: nullable AModule is writable
- var n_eof: EOF is writable, noinit
- init(n_base: nullable AModule, n_eof: EOF)
- do
- self._n_base = n_base
- self._n_eof = n_eof
- end
+ var n_eof: EOF is writable
end
# The node stored with the state in the stack
var nodes: nullable Object
-
- init(state: Int, nodes: nullable Object)
- do
- _state = state
- _nodes = nodes
- end
end
# The parser of the Nit language.
var lexer: Lexer
# Stack of pushed states and productions
- private var stack: Array[State]
+ private var stack = new Array[State]
# Position in the stack
- private var stack_pos: Int
+ private var stack_pos: Int = -1
- # Create a new parser based on a given lexer
- init(lexer: Lexer)
+ init
do
- _lexer = lexer
- _stack = new Array[State]
- _stack_pos = -1
build_reduce_table
end
end
end
- private var reduce_table: Array[ReduceAction]
+ private var reduce_table: Array[ReduceAction] is noinit
private fun build_reduce_table is abstract
end
return l1
end
var goto: Int
- init(g: Int) do _goto = g
end
private class CollectTokensByTextVisitor
super Visitor
var text: String
- init(text: String) do self.text = text
var result = new Array[Token]
redef fun visit(node)
do
private class CollectAnnotationsByNameVisitor
super Visitor
var name: String
- init(name: String) do self.name = name
var result = new Array[AAnnotation]
redef fun visit(node)
do
var toolcontext: ToolContext
# The dependence relation of the phase with the other phases
- var in_hierarchy: POSetElement[Phase]
+ var in_hierarchy: POSetElement[Phase] is noinit
+
+ # The explicit dependences, used to initialize `in_importation`
+ var depends: nullable Collection[Phase]
# Initialize and register a phase to the toolcontext
- init(toolcontext: ToolContext, depends: nullable Collection[Phase])
+ init
do
- self.toolcontext = toolcontext
in_hierarchy = toolcontext.phases.add_node(self)
+ var depends = self.depends
if depends != null then
for d in depends do
toolcontext.phases.add_edge(self, d)
var receiver: MClassType
var mpropdef: MPropDef
- init(analysis: RapidTypeAnalysis, receiver: MClassType, mpropdef: MPropDef)
+ init
do
- self.analysis = analysis
- self.receiver = receiver
- self.mpropdef = mpropdef
assert not receiver.need_anchor
end
private class FlowVisitor
super Visitor
- var current_flow_context: FlowContext
+ var current_flow_context = new FlowContext
var toolcontext: ToolContext
- init(toolcontext: ToolContext)
+ init
do
- self.toolcontext = toolcontext
- current_flow_context = new FlowContext
flows.add(current_flow_context)
current_flow_context.is_start = true
end
- var first: nullable ANode
+ var first: nullable ANode = null
redef fun visit(node)
do
var toolcontext: ToolContext
- init(toolcontext: ToolContext)
- do
- self.toolcontext = toolcontext
- end
-
# Local variables that are possibly unset (ie local variable without an initial value)
var maybe_unset_vars: Set[Variable] = new HashSet[Variable]
var selfvariable = new Variable("self")
- init(toolcontext: ToolContext)
+ init
do
- self.toolcontext = toolcontext
scopes.add(new Scope)
end
# The static type of the receiver
# Mainly used for type tests and type resolutions
- var anchor: nullable MClassType
+ var anchor: nullable MClassType = null
# The analyzed mclassdef
- var mclassdef: nullable MClassDef
+ var mclassdef: nullable MClassDef = null
# The analyzed property
var mpropdef: nullable MPropDef
# * method called on the implicit self must be top-level
var is_toplevel_context = false
- init(modelbuilder: ModelBuilder, mmodule: MModule, mpropdef: nullable MPropDef)
+ init
do
- self.modelbuilder = modelbuilder
- self.mmodule = mmodule
+ var mpropdef = self.mpropdef
if mpropdef != null then
self.mpropdef = mpropdef
class NitUnitExecutor
super Doc2Mdwn
- # The module to import
- var mmodule: MModule
-
# The prefix of the generated Nit source-file
var prefix: String
+ # The module to import
+ var mmodule: MModule
+
# The XML node associated to the module
var testsuite: HTMLTag
- # Initialize a new e
- init(toolcontext: ToolContext, prefix: String, mmodule: MModule, testsuite: HTMLTag)
- do
- super(toolcontext)
- self.prefix = prefix
- self.mmodule = mmodule
- self.testsuite = testsuite
- end
-
# All blocks of code from a same `ADoc`
var blocks = new Array[Array[String]]
end
# The associated node to localize warnings
- var ndoc: nullable ADoc
+ var ndoc: nullable ADoc = null
# used to generate distinct names
var cpt = 0
var toolcontext: ToolContext
- init(toolcontext: ToolContext) do
- self.toolcontext = toolcontext
- end
-
private fun extract_options_names: Array[String] do
var names = new Array[String]
for option in toolcontext.option_context.options do
do
var val
- var v = new TransformVisitor(self, npropdef)
+ var v = new TransformVisitor(self, npropdef.mpropdef.as(not null))
v.enter_visit(npropdef)
val = new ASTValidationVisitor
super Visitor
var phase: TransformPhase
- var mmodule: MModule
- var mclassdef: MClassDef
+ var mmodule: MModule is noinit
+ var mclassdef: MClassDef is noinit
var mpropdef: MPropDef
- var builder: ASTBuilder
+ var builder: ASTBuilder is noinit
- init(phase: TransformPhase, npropdef: APropdef)
+ init
do
- self.phase = phase
- self.mpropdef = npropdef.mpropdef.as(not null)
self.mclassdef = mpropdef.mclassdef
self.mmodule = mclassdef.mmodule
self.builder = new ASTBuilder(mmodule, mpropdef.mclassdef.bound_mtype)