X-Git-Url: http://nitlanguage.org diff --git a/src/model/model.nit b/src/model/model.nit index 629dadb..f26eb2e 100644 --- a/src/model/model.nit +++ b/src/model/model.nit @@ -14,39 +14,34 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Object model of the Nit language +# Classes, types and properties # -# This module define the entities of the Nit meta-model like modules, -# classes, types and properties -# -# It also provide an API to build and query models. -# -# All model classes starts with the M letter (`MModule`, `MClass`, etc.) -# -# TODO: better doc +# All three concepts are defined in this same module because these are strongly connected: +# * types are based on classes +# * classes contains properties +# * some properties are types (virtual types) # # TODO: liearization, extern stuff # FIXME: better handling of the types module model -import poset -import location import mmodule import mdoc +import ordered_tree private import more_collections redef class Model # All known classes - var mclasses: Array[MClass] = new Array[MClass] + var mclasses = new Array[MClass] # All known properties - var mproperties: Array[MProperty] = new Array[MProperty] + var mproperties = new Array[MProperty] # Hierarchy of class definition. # # Each classdef is associated with its super-classdefs in regard to # its module of definition. - var mclassdef_hierarchy: POSet[MClassDef] = new POSet[MClassDef] + var mclassdef_hierarchy = new POSet[MClassDef] # Class-type hierarchy restricted to the introduction. # @@ -57,7 +52,7 @@ redef class Model # This poset will evolve in a monotonous way: # * Two non connected nodes will remain unconnected # * New nodes can appear with new edges - private var intro_mtype_specialization_hierarchy: POSet[MClassType] = new POSet[MClassType] + private var intro_mtype_specialization_hierarchy = new POSet[MClassType] # Global overlapped class-type hierarchy. # The hierarchy when all modules are combined. @@ -66,10 +61,10 @@ redef class Model # This poset will evolve in an anarchic way. Loops can even be created. # # FIXME decide what to do on loops - private var full_mtype_specialization_hierarchy: POSet[MClassType] = new POSet[MClassType] + private var full_mtype_specialization_hierarchy = new POSet[MClassType] # Collections of classes grouped by their short name - private var mclasses_by_name: MultiHashMap[String, MClass] = new MultiHashMap[String, MClass] + private var mclasses_by_name = new MultiHashMap[String, MClass] # Return all class named `name`. # @@ -87,7 +82,7 @@ redef class Model end # Collections of properties grouped by their short name - private var mproperties_by_name: MultiHashMap[String, MProperty] = new MultiHashMap[String, MProperty] + private var mproperties_by_name = new MultiHashMap[String, MProperty] # Return all properties named `name`. # @@ -105,16 +100,45 @@ redef class Model end # The only null type - var null_type: MNullType = new MNullType(self) + var null_type = new MNullType(self) + + # Build an ordered tree with from `concerns` + fun concerns_tree(mconcerns: Collection[MConcern]): ConcernsTree do + var seen = new HashSet[MConcern] + var res = new ConcernsTree + + var todo = new Array[MConcern] + todo.add_all mconcerns + + while not todo.is_empty do + var c = todo.pop + if seen.has(c) then continue + var pc = c.parent_concern + if pc == null then + res.add(null, c) + else + res.add(pc, c) + todo.add(pc) + end + seen.add(c) + end + + return res + end +end + +# An OrderedTree that can be easily refined for display purposes +class ConcernsTree + super OrderedTree[MConcern] end redef class MModule # All the classes introduced in the module - var intro_mclasses: Array[MClass] = new Array[MClass] + var intro_mclasses = new Array[MClass] # All the class definitions of the module # (introduction and refinement) - var mclassdefs: Array[MClassDef] = new Array[MClassDef] + var mclassdefs = new Array[MClassDef] # Does the current module has a given class `mclass`? # Return true if the mmodule introduces, refines or imports a class. @@ -151,14 +175,14 @@ redef class MModule return res end - # Sort a given array of classes using the linerarization order of the module + # Sort a given array of classes using the linearization order of the module # The most general is first, the most specific is last fun linearize_mclasses(mclasses: Array[MClass]) do self.flatten_mclass_hierarchy.sort(mclasses) end - # Sort a given array of class definitions using the linerarization order of the module + # Sort a given array of class definitions using the linearization order of the module # the refinement link is stronger than the specialisation link # The most general is first, the most specific is last fun linearize_mclassdefs(mclassdefs: Array[MClassDef]) @@ -167,7 +191,7 @@ redef class MModule sorter.sort(mclassdefs) end - # Sort a given array of property definitions using the linerarization order of the module + # Sort a given array of property definitions using the linearization order of the module # the refinement link is stronger than the specialisation link # The most general is first, the most specific is last fun linearize_mpropdefs(mpropdefs: Array[MPropDef]) @@ -190,6 +214,9 @@ redef class MModule private var object_type_cache: nullable MClassType + # The type `Pointer`, super class to all extern classes + var pointer_type: MClassType = self.get_primitive_class("Pointer").mclass_type is lazy + # The primitive type `Bool` fun bool_type: MClassType do @@ -210,14 +237,23 @@ redef class MModule return get_primitive_class("Sys").mclass_type end + # The primitive type `Finalizable` + # Used to tag classes that need to be finalized. + fun finalizable_type: nullable MClassType + do + var clas = self.model.get_mclasses_by_name("Finalizable") + if clas == null then return null + return get_primitive_class("Finalizable").mclass_type + end + # Force to get the primitive class named `name` or abort fun get_primitive_class(name: String): MClass do var cla = self.model.get_mclasses_by_name(name) if cla == null then if name == "Bool" then - var c = new MClass(self, name, 0, enum_kind, public_visibility) - var cladef = new MClassDef(self, c.mclass_type, new Location(null, 0,0,0,0), new Array[String]) + var c = new MClass(self, name, null, enum_kind, public_visibility) + var cladef = new MClassDef(self, c.mclass_type, new Location(null, 0,0,0,0)) return c end print("Fatal Error: no primitive class {name}") @@ -257,7 +293,8 @@ redef class MModule end private class MClassDefSorter - super AbstractSorter[MClassDef] + super Comparator + redef type COMPARED: MClassDef var mmodule: MModule redef fun compare(a, b) do @@ -269,7 +306,8 @@ private class MClassDefSorter end private class MPropDefSorter - super AbstractSorter[MPropDef] + super Comparator + redef type COMPARED: MPropDef var mmodule: MModule redef fun compare(pa, pb) do @@ -289,9 +327,20 @@ end # # This characteristic helps the reasoning about classes in a program since a # single `MClass` object always denote the same class. -# However, because a `MClass` is global, it does not really have properties nor -# belong to a hierarchy since the property and the -# hierarchy of a class depends of a module. +# +# The drawback is that classes (`MClass`) contain almost nothing by themselves. +# These do not really have properties nor belong to a hierarchy since the property and the +# hierarchy of a class depends of the refinement in the modules. +# +# Most services on classes require the precision of a module, and no one can asks what are +# the super-classes of a class nor what are properties of a class without precising what is +# the module considered. +# +# For instance, during the typing of a source-file, the module considered is the module of the file. +# eg. the question *is the method `foo` exists in the class `Bar`?* must be reformulated into +# *is the method `foo` exists in the class `Bar` in the current module?* +# +# During some global analysis, the module considered may be the main module of the program. class MClass super MEntity @@ -302,7 +351,7 @@ class MClass # The short name of the class # In Nit, the name of a class cannot evolve in refinements - var name: String + redef var name: String # The canonical name of the class # Example: `"owner::module::MyClass"` @@ -315,6 +364,10 @@ class MClass # 0 if the class is not generic var arity: Int + # 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 @@ -323,11 +376,15 @@ class MClass # In Nit, the visibility of a class cannot evolve in refinements var visibility: MVisibility - init(intro_mmodule: MModule, name: String, arity: Int, kind: MClassKind, visibility: MVisibility) + init(intro_mmodule: MModule, name: String, parameter_names: nullable Array[String], kind: MClassKind, visibility: MVisibility) do self.intro_mmodule = intro_mmodule self.name = name - self.arity = arity + 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) @@ -337,11 +394,13 @@ class MClass # Create the formal parameter types if arity > 0 then + assert parameter_names != null var mparametertypes = new Array[MParameterType] for i in [0..arity[ do - var mparametertype = new MParameterType(self, i) + var mparametertype = new MParameterType(self, i, parameter_names[i]) mparametertypes.add(mparametertype) end + self.mparameters = mparametertypes var mclass_type = new MGenericType(self, mparametertypes) self.mclass_type = mclass_type self.get_mtype_cache.add(mclass_type) @@ -350,8 +409,10 @@ class MClass end end + redef fun model do return intro_mmodule.model + # All class definitions (introduction and refinements) - var mclassdefs: Array[MClassDef] = new Array[MClassDef] + var mclassdefs = new Array[MClassDef] # Alias for `name` redef fun to_s do return self.name @@ -410,7 +471,7 @@ class MClass return res end - private var get_mtype_cache: Array[MGenericType] = new Array[MGenericType] + private var get_mtype_cache = new Array[MGenericType] end @@ -418,7 +479,14 @@ end # # A `MClassDef` is associated with an explicit (or almost) definition of a # class. Unlike `MClass`, a `MClassDef` is a local definition that belong to -# a specific module +# a specific class and a specific module, and contains declarations like super-classes +# or properties. +# +# It is the class definitions that are the backbone of most things in the model: +# ClassDefs are defined with regard with other classdefs. +# Refinement and specialization are combined to produce a big poset called the `Model::mclassdef_hierarchy`. +# +# Moreover, the extension and the intention of types is defined by looking at the MClassDefs. class MClassDef super MEntity @@ -440,9 +508,6 @@ class MClassDef # ENSURE: `bound_mtype.mclass == self.mclass` var bound_mtype: MClassType - # Name of each formal generic parameter (in order of declaration) - var parameter_names: Array[String] - # The origin of the definition var location: Location @@ -450,22 +515,25 @@ class MClassDef # Example: "mymodule#MyClass" redef var to_s: String - init(mmodule: MModule, bound_mtype: MClassType, location: Location, parameter_names: Array[String]) + init(mmodule: MModule, bound_mtype: MClassType, location: Location) do - assert bound_mtype.mclass.arity == parameter_names.length self.bound_mtype = bound_mtype self.mmodule = mmodule self.mclass = bound_mtype.mclass self.location = location mmodule.mclassdefs.add(self) mclass.mclassdefs.add(self) - self.parameter_names = parameter_names self.to_s = "{mmodule}#{mclass}" end + # Actually the name of the `mclass` + redef fun name do return mclass.name + + redef fun model do return mmodule.model + # All declared super-types # FIXME: quite ugly but not better idea yet - var supertypes: Array[MClassType] = new Array[MClassType] + var supertypes = new Array[MClassType] # Register some super-types for the class (ie "super SomeType") # @@ -518,10 +586,10 @@ class MClassDef fun is_intro: Bool do return mclass.intro == self # All properties introduced by the classdef - var intro_mproperties: Array[MProperty] = new Array[MProperty] + var intro_mproperties = new Array[MProperty] # All property definitions in the class (introductions and redefinitions) - var mpropdefs: Array[MPropDef] = new Array[MPropDef] + var mpropdefs = new Array[MPropDef] end # A global static type @@ -554,8 +622,7 @@ end abstract class MType super MEntity - # The model of the type - fun model: Model is abstract + redef fun name do return to_s # Return true if `self` is an subtype of `sup`. # The typing is done using the standard typing policy of Nit. @@ -575,8 +642,8 @@ abstract class MType end # First, resolve the formal types to a common version in the receiver - # The trick here is that fixed formal type will be associed to the bound - # And unfixed formal types will be associed to a canonical formal type. + # The trick here is that fixed formal type will be associated to the bound + # And unfixed formal types will be associated to a canonical formal type. if sub isa MParameterType or sub isa MVirtualType then assert anchor != null sub = sub.resolve_for(anchor.mclass.mclass_type, anchor, mmodule, false) @@ -736,7 +803,7 @@ abstract class MType # Replace formals generic types in self with resolved values in `mtype` # If `cleanup_virtual` is true, then virtual types are also replaced - # with their bounds + # with their bounds. # # This function returns self if `need_anchor` is false. # @@ -797,8 +864,6 @@ abstract class MType # # The resolution can be done because `E` make sense for the class A (see `can_resolve_for`) # - # TODO: Explain the cleanup_virtual - # # FIXME: the parameter `cleanup_virtual` is just a bad idea, but having # two function instead of one seems also to be a bad idea. # @@ -839,10 +904,20 @@ abstract class MType return res end + # Return the not nullable version of the type + # Is the type is already not nullable, then self is returned. + # + # Note: this just remove the `nullable` notation, but the result can still contains null. + # For instance if `self isa MNullType` or self is a formal type bounded by a nullable type. + fun as_notnullable: MType + do + return self + end + private var as_nullable_cache: nullable MType = null - # The deph of the type seen as a tree. + # The depth of the type seen as a tree. # # * A -> 1 # * G[A] -> 2 @@ -920,7 +995,7 @@ class MClassType # The formal arguments of the type # ENSURE: `result.length == self.mclass.arity` - var arguments: Array[MType] = new Array[MType] + var arguments = new Array[MType] redef fun to_s do return mclass.to_s @@ -995,9 +1070,9 @@ class MClassType collect_mtypes_cache[mmodule] = types end - private var collect_mclassdefs_cache: HashMap[MModule, Set[MClassDef]] = new HashMap[MModule, Set[MClassDef]] - private var collect_mclasses_cache: HashMap[MModule, Set[MClass]] = new HashMap[MModule, Set[MClass]] - private var collect_mtypes_cache: HashMap[MModule, Set[MClassType]] = new HashMap[MModule, Set[MClassType]] + private var collect_mclassdefs_cache = new HashMap[MModule, Set[MClassDef]] + private var collect_mclasses_cache = new HashMap[MModule, Set[MClass]] + private var collect_mtypes_cache = new HashMap[MModule, Set[MClassType]] end @@ -1105,6 +1180,20 @@ class MVirtualType abort end + # Is the virtual type fixed for a given resolved_receiver? + fun is_fixed(mmodule: MModule, resolved_receiver: MType): Bool + do + assert not resolved_receiver.need_anchor + var props = self.mproperty.lookup_definitions(mmodule, resolved_receiver) + if props.is_empty then + abort + end + for p in props do + if p.as(MVirtualTypeDef).is_fixed then return true + end + return false + end + redef fun resolve_for(mtype, anchor, mmodule, cleanup_virtual) do assert can_resolve_for(mtype, anchor, mmodule) @@ -1123,17 +1212,19 @@ class MVirtualType var verbatim_bound = lookup_bound(mmodule, resolved_reciever) # The bound is exactly as declared in the "type" property, so we must resolve it again var res = verbatim_bound.resolve_for(mtype, anchor, mmodule, cleanup_virtual) - #print "{class_name}: {self}/{mtype}/{anchor} -> {self}/{resolved_reciever}/{anchor} -> {verbatim_bound}/{mtype}/{anchor} -> {res}" + #print "{class_name}: {self}/{mtype}/{anchor} -> {self}/{resolved_receiver}/{anchor} -> {verbatim_bound}/{mtype}/{anchor} -> {res}" # What to return here? There is a bunch a special cases: # If 'cleanup_virtual' we must return the resolved type, since we cannot return self if cleanup_virtual then return res - # If the reciever is a intern class, then the virtual type cannot be redefined since there is no possible subclass. self is just fixed. so simply return the resolution + # If the receiver is a intern class, then the virtual type cannot be redefined since there is no possible subclass. self is just fixed. so simply return the resolution if resolved_reciever isa MNullableType then resolved_reciever = resolved_reciever.mtype if resolved_reciever.as(MClassType).mclass.kind == enum_kind then return res # If the resolved type isa MVirtualType, it means that self was bound to it, and cannot be unbound. self is just fixed. so return the resolution. if res isa MVirtualType then return res - # It the resolved type isa intern class, then there is no possible valid redefinition is any potentiel subclass. self is just fixed. so simply return the resolution + # If we are final, just return the resolution + if is_fixed(mmodule, resolved_reciever) then return res + # If the resolved type isa intern class, then there is no possible valid redefinition in any potential subclass. self is just fixed. so simply return the resolution if res isa MClassType and res.mclass.kind == enum_kind then return res # TODO: Add 'fixed' virtual type in the specification. # TODO: What if bound to a MParameterType? @@ -1160,14 +1251,14 @@ class MVirtualType end end -# The type associated the a formal parameter generic type of a class +# The type associated to a formal parameter generic type of a class # # Each parameter type is associated to a specific class. -# It's mean that all refinements of a same class "share" the parameter type, -# but that a generic subclass has its on parameter types. +# It means that all refinements of a same class "share" the parameter type, +# but that a generic subclass has its own parameter types. # -# However, in the sense of the meta-model, the a parameter type of a class is -# a valid types in a subclass. The "in the sense of the meta-model" is +# However, in the sense of the meta-model, a parameter type of a class is +# a valid type in a subclass. The "in the sense of the meta-model" is # important because, in the Nit language, the programmer cannot refers # directly to the parameter types of the super-classes. # @@ -1197,12 +1288,9 @@ class MParameterType # FIXME: is `position` a better name? var rank: Int - # Internal name of the parameter type - # Names of parameter types changes in each class definition - # Therefore, this method return an internal name. - # Example: return "G#1" for the second parameter of the class G - # FIXME: add a way to get the real name in a classdef - redef fun to_s do return "{mclass}#{rank}" + redef var name + + redef fun to_s do return name # Resolve the bound for a given resolved_receiver # The result may be a other virtual type (or a parameter type) @@ -1228,13 +1316,19 @@ class MParameterType #print "{class_name}: {self}/{mtype}/{anchor}?" if mtype isa MGenericType and mtype.mclass == self.mclass then - return mtype.arguments[self.rank] + var res = mtype.arguments[self.rank] + if anchor != null and res.need_anchor then + # Maybe the result can be resolved more if are bound to a final class + var r2 = res.anchor_to(mmodule, anchor) + if r2 isa MClassType and r2.mclass.kind == enum_kind then return r2 + end + return res end # self is a parameter type of mtype (or of a super-class of mtype) # The point of the function it to get the bound of the virtual type that make sense for mtype # But because mtype is maybe a virtual/formal type, we need to get a real receiver first - # FIXME: What happend here is far from clear. Thus this part must be validated and clarified + # FIXME: What happens here is far from clear. Thus this part must be validated and clarified var resolved_receiver if mtype.need_anchor then assert anchor != null @@ -1281,10 +1375,11 @@ class MParameterType return mtype.collect_mclassdefs(mmodule).has(mclass.intro) end - init(mclass: MClass, rank: Int) + init(mclass: MClass, rank: Int, name: String) do self.mclass = mclass self.rank = rank + self.name = name end end @@ -1307,6 +1402,7 @@ class MNullableType redef fun need_anchor do return mtype.need_anchor redef fun as_nullable do return self + redef fun as_notnullable do return mtype redef fun resolve_for(mtype, anchor, mmodule, cleanup_virtual) do var res = self.mtype.resolve_for(mtype, anchor, mmodule, cleanup_virtual) @@ -1463,8 +1559,10 @@ end # A parameter in a signature class MParameter + super MEntity + # The name of the parameter - var name: String + redef var name: String # The static type of the parameter var mtype: MType @@ -1472,6 +1570,12 @@ class MParameter # 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 @@ -1488,6 +1592,8 @@ class MParameter var res = new MParameter(self.name, newtype, self.is_vararg) return res end + + redef fun model do return mtype.model end # A service (global property) that generalize method, attribute, etc. @@ -1514,7 +1620,7 @@ abstract class MProperty var intro_mclassdef: MClassDef # The (short) name of the property - var name: String + redef var name: String # The canonical name of the property # Example: "owner::my_module::MyClass::my_method" @@ -1540,7 +1646,7 @@ abstract class MProperty # All definitions of the property. # The first is the introduction, # The other are redefinitions (in refinements and in subclasses) - var mpropdefs: Array[MPROPDEF] = new Array[MPROPDEF] + var mpropdefs = new Array[MPROPDEF] # The definition that introduced the property # Warning: the introduction is the first `MPropDef` object @@ -1548,6 +1654,8 @@ abstract class MProperty # associated definition, this method will abort fun intro: MPROPDEF do return mpropdefs.first + redef fun model do return intro.model + # Alias for `name` redef fun to_s do return name @@ -1560,7 +1668,7 @@ abstract class MProperty fun lookup_definitions(mmodule: MModule, mtype: MType): Array[MPROPDEF] do assert not mtype.need_anchor - if mtype isa MNullableType then mtype = mtype.mtype + mtype = mtype.as_notnullable var cache = self.lookup_definitions_cache[mmodule, mtype] if cache != null then return cache @@ -1586,7 +1694,7 @@ abstract class MProperty return select_most_specific(mmodule, candidates) end - private var lookup_definitions_cache: HashMap2[MModule, MType, Array[MPROPDEF]] = new HashMap2[MModule, MType, Array[MPROPDEF]] + private var lookup_definitions_cache = new HashMap2[MModule, MType, Array[MPROPDEF]] # Return the most specific property definitions inherited by a type. # The selection knows that refinement is stronger than specialization; @@ -1599,7 +1707,7 @@ abstract class MProperty fun lookup_super_definitions(mmodule: MModule, mtype: MType): Array[MPROPDEF] do assert not mtype.need_anchor - if mtype isa MNullableType then mtype = mtype.mtype + mtype = mtype.as_notnullable # First, select all candidates var candidates = new Array[MPROPDEF] @@ -1661,7 +1769,7 @@ abstract class MProperty # If you want to know the next properties in the linearization, # look at `MPropDef::lookup_next_definition`. # - # FIXME: the linearisation is still unspecified + # FIXME: the linearization is still unspecified # # REQUIRE: `not mtype.need_anchor` # REQUIRE: `mtype.has_mproperty(mmodule, self)` @@ -1671,12 +1779,12 @@ abstract class MProperty return lookup_all_definitions(mmodule, mtype).first end - # Return all definitions in a linearisation order - # Most speficic first, most general last + # Return all definitions in a linearization order + # Most specific first, most general last fun lookup_all_definitions(mmodule: MModule, mtype: MType): Array[MPROPDEF] do assert not mtype.need_anchor - if mtype isa MNullableType then mtype = mtype.mtype + mtype = mtype.as_notnullable var cache = self.lookup_all_definitions_cache[mmodule, mtype] if cache != null then return cache @@ -1704,7 +1812,7 @@ abstract class MProperty return candidates end - private var lookup_all_definitions_cache: HashMap2[MModule, MType, Array[MPROPDEF]] = new HashMap2[MModule, MType, Array[MPROPDEF]] + private var lookup_all_definitions_cache = new HashMap2[MModule, MType, Array[MPROPDEF]] end # A global method @@ -1718,13 +1826,20 @@ class MMethod 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 + # Is the property a constructor? # Warning, this property can be inherited by subclasses with or without being a constructor # therefore, you should use `is_init_for` the verify if the property is a legal constructor for a given class - var is_init: Bool writable = false + var is_init: Bool = false is writable + + # The constructor is a (the) root init with empty signature but a set of initializers + var is_root_init: Bool = false is writable - # The the property a 'new' contructor? - var is_new: Bool writable = false + # Is the property a 'new' constructor? + var is_new: Bool = false is writable # Is the property a legal constructor for a given class? # As usual, visibility is not considered. @@ -1759,7 +1874,7 @@ class MVirtualTypeProp end # The formal type associated to the virtual type property - var mvirtualtype: MVirtualType = new MVirtualType(self) + var mvirtualtype = new MVirtualType(self) end # A definition of a property (local property) @@ -1795,6 +1910,11 @@ abstract class MPropDef self.to_s = "{mclassdef}#{mproperty}" end + # Actually the name of the `mproperty` + redef fun name do return mproperty.name + + redef fun model do return mclassdef.model + # Internal name combining the module, the class and the property # Example: "mymodule#MyClass#mymethod" redef var to_s: String @@ -1834,16 +1954,39 @@ class MMethodDef end # The signature attached to the property definition - var msignature: nullable MSignature writable = null + var msignature: nullable MSignature = null is writable + + # The signature attached to the `new` call on a root-init + # This is a concatenation of the signatures of the initializers + # + # REQUIRE `mproperty.is_root_init == (new_msignature != null)` + var new_msignature: nullable MSignature = null is writable + + # List of initialisers to call in root-inits + # + # They could be setters or attributes + # + # REQUIRE `mproperty.is_root_init == (new_msignature != null)` + var initializers = new Array[MProperty] # Is the method definition abstract? - var is_abstract: Bool writable = false + var is_abstract: Bool = false is writable # Is the method definition intern? - var is_intern writable = false + var is_intern = false is writable # Is the method definition extern? - var is_extern writable = false + var is_extern = false is writable + + # An optional constant value returned in functions. + # + # Only some specific primitife value are accepted by engines. + # Is used when there is no better implementation available. + # + # Currently used only for the implementation of the `--define` + # command-line option. + # SEE: module `mixin`. + var constant_value: nullable Object = null is writable end # A local definition of an attribute @@ -1859,7 +2002,7 @@ class MAttributeDef end # The static type of the attribute - var static_mtype: nullable MType writable = null + var static_mtype: nullable MType = null is writable end # A local definition of a virtual type @@ -1875,7 +2018,10 @@ class MVirtualTypeDef end # The bound of the virtual type - var bound: nullable MType writable = null + var bound: nullable MType = null is writable + + # Is the bound fixed? + var is_fixed = false is writable end # A kind of class. @@ -1907,7 +2053,7 @@ class MClassKind # no other case for interfaces return false else if self == extern_kind then - # only compatible with themselve + # only compatible with themselves return self == other else if other == enum_kind or other == extern_kind then # abstract_kind and concrete_kind are incompatible @@ -1918,8 +2064,13 @@ class MClassKind end end +# The class kind `abstract` fun abstract_kind: MClassKind do return once new MClassKind("abstract class", true) +# The class kind `concrete` fun concrete_kind: MClassKind do return once new MClassKind("class", true) +# The class kind `interface` fun interface_kind: MClassKind do return once new MClassKind("interface", false) +# The class kind `enum` fun enum_kind: MClassKind do return once new MClassKind("enum", false) +# The class kind `extern` fun extern_kind: MClassKind do return once new MClassKind("extern class", false)