model: promote location to any `MEntity`
authorJean Privat <jean@pryen.org>
Sun, 1 May 2016 15:42:20 +0000 (11:42 -0400)
committerJean Privat <jean@pryen.org>
Fri, 13 May 2016 20:38:50 +0000 (16:38 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

src/model/mmodule.nit
src/model/model.nit
src/model/model_base.nit
src/semantize/typing.nit

index 8927f8c..1b56250 100644 (file)
@@ -17,7 +17,6 @@
 # modules and module hierarchies in the metamodel
 module mmodule
 
-import location
 import mpackage
 private import more_collections
 
@@ -95,8 +94,7 @@ class MModule
        # The short name of the module
        redef var name: String
 
-       # The origin of the definition
-       var location: Location is writable
+       redef var location: Location is writable
 
        # Alias for `name`
        redef fun to_s do return self.name
index 6c8798b..2de65f5 100644 (file)
@@ -386,6 +386,8 @@ class MClass
        # In Nit, the name of a class cannot evolve in refinements
        redef var name
 
+       redef var location
+
        # The canonical name of the class
        #
        # It is the name of the class prefixed by the full_name of the `intro_mmodule`
@@ -588,8 +590,7 @@ class MClassDef
        # ENSURE: `bound_mtype.mclass == self.mclass`
        var bound_mtype: MClassType
 
-       # The origin of the definition
-       var location: Location
+       redef var location: Location
 
        # Internal name combining the module and the class
        # Example: "mymodule$MyClass"
@@ -2241,8 +2242,7 @@ abstract class MPropDef
        # The associated global property
        var mproperty: MPROPERTY
 
-       # The origin of the definition
-       var location: Location
+       redef var location: Location
 
        init
        do
index 5cfe9b2..0c136b8 100644 (file)
@@ -16,6 +16,7 @@
 
 # The abstract concept of model and related common things
 module model_base
+import location
 
 # The container class of a Nit object-oriented model.
 # A model knows modules, classes and properties and can retrieve them.
@@ -23,6 +24,11 @@ class Model
        super MEntity
 
        redef fun model do return self
+
+       # Place-holder object that means no-location
+       #
+       # See `MEntity::location`
+       var no_location = new Location(null, 0, 0, 0, 0)
 end
 
 # A named and possibly documented entity in the model.
@@ -65,6 +71,16 @@ abstract class MEntity
        # indirect use should be restricted (e.g. to name a web-page)
        fun c_name: String is abstract
 
+       # The origin of the definition.
+       #
+       # Most model entities are defined in a specific place in the source base.
+       #
+       # Because most model entities have one,
+       # it is simpler for the client to have a non-nullable return value.
+       # For entities that lack a location, mock-up special locations are used instead.
+       # By default it is `model.no_location`.
+       fun location: Location do return model.no_location
+
        # A Model Entity has a direct link to its model
        fun model: Model is abstract
 
index 69329f9..6c4de01 100644 (file)
@@ -637,8 +637,7 @@ end
 class CallSite
        super MEntity
 
-       # The associated location of the callsite
-       var location: Location
+       redef var location: Location
 
        # The static type of the receiver (possibly unresolved)
        var recv: MType