From 97121b05168a955066efdceada9305363dd64028 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Sun, 1 May 2016 11:42:20 -0400 Subject: [PATCH] model: promote location to any `MEntity` Signed-off-by: Jean Privat --- src/model/mmodule.nit | 4 +--- src/model/model.nit | 8 ++++---- src/model/model_base.nit | 16 ++++++++++++++++ src/semantize/typing.nit | 3 +-- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/model/mmodule.nit b/src/model/mmodule.nit index 8927f8c..1b56250 100644 --- a/src/model/mmodule.nit +++ b/src/model/mmodule.nit @@ -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 diff --git a/src/model/model.nit b/src/model/model.nit index 6c8798b..2de65f5 100644 --- a/src/model/model.nit +++ b/src/model/model.nit @@ -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 diff --git a/src/model/model_base.nit b/src/model/model_base.nit index 5cfe9b2..0c136b8 100644 --- a/src/model/model_base.nit +++ b/src/model/model_base.nit @@ -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 diff --git a/src/semantize/typing.nit b/src/semantize/typing.nit index 69329f9..6c4de01 100644 --- a/src/semantize/typing.nit +++ b/src/semantize/typing.nit @@ -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 -- 1.7.9.5