tools: add Location to MMModule
authorJean-Sebastien Gelinas <calestar@gmail.com>
Thu, 23 Jul 2009 05:25:30 +0000 (01:25 -0400)
committerJean Privat <jean@pryen.org>
Thu, 23 Jul 2009 22:43:32 +0000 (18:43 -0400)
Signed-off-by: Jean-Sebastien Gelinas <calestar@gmail.com>
Signed-off-by: Jean Privat <jean@pryen.org>

src/abstracttool.nit
src/compiling/compiling.nit
src/compiling/compiling_global.nit
src/metamodel/abstractmetamodel.nit
src/syntax/syntax.nit
src/syntax/syntax_base.nit

index cbf42ce..35ba6fe 100644 (file)
@@ -98,7 +98,7 @@ end
 redef class MMModule
        fun dump_module_info
        do
-               var p = filename.file_path
+               var p = location.file.file_path
                var fname = "{p}/{name}"
                var f = new OFStream.open("{fname}.class_hierarchy.new.dot")
                f.write(class_specialization_hierarchy.to_dot)
index b90ca12..d89a2d6 100644 (file)
@@ -47,7 +47,7 @@ redef class MMModule
                        files.add("{tc.compdir}/{m.name}._sep.c")
                        tc.info("Generating C code for module: {m.name}",2)
                        m.compile_separate_module(tc, ga)
-                       var native_name = m.filename.strip_extension(".nit")
+                       var native_name = m.location.file.strip_extension(".nit")
                        if (native_name + "_nit.h").file_exists then
                                includes.add("-I {native_name.dirname}")
                        end
@@ -110,7 +110,7 @@ redef class MMModule
        do
                var v = new GlobalCompilerVisitor(self, tc, ga)
                v.add_decl("#include <nit_common.h>")
-               var native_name = filename.strip_extension(".nit")
+               var native_name = location.file.strip_extension(".nit")
                native_name += ("_nit.h")
                if native_name.file_exists then v.add_decl("#include <{native_name.basename("")}>")
                declare_class_tables_to_c(v)
index ddd6582..31bd86b 100644 (file)
@@ -511,7 +511,7 @@ redef class MMModule
        # Compile module file for the current module
        fun compile_local_table_to_c(v: GlobalCompilerVisitor)
        do
-               v.add_instr("const char *LOCATE_{name} = \"{filename}\";")
+               v.add_instr("const char *LOCATE_{name} = \"{location.file}\";")
 
                if v.tc.global or _local_table.is_empty then
                        return
index 4844ff3..6eb24b9 100644 (file)
@@ -19,6 +19,7 @@
 package abstractmetamodel
 
 import partial_order
+import location
 
 # The main singleton which knows everything
 class MMContext
@@ -120,8 +121,8 @@ class MMModule
        # The directory of the module
        readable var _directory: MMDirectory
 
-       # The filename of the module
-       readable var _filename: String
+       # Location of this module
+       readable var _location: Location
 
        # Module dependence hierarchy element
        readable var _mhe: nullable PartialOrderElement[MMModule]
@@ -153,13 +154,13 @@ class MMModule
        # Dictionary of global classes
        var _global_class_by_name: Map[Symbol, MMGlobalClass] = new HashMap[Symbol, MMGlobalClass]
 
-       protected init(name: Symbol, dir: MMDirectory, context: MMContext, filename: String)
+       protected init(name: Symbol, dir: MMDirectory, context: MMContext, loc: Location)
        do
                _name = name
                _directory = dir
                _context = context
                _full_name = dir.full_name_for(name)
-               _filename = filename
+               _location = loc
        end
 
        # Register that a module is imported with a visibility
index 8d3f7c8..0e18983 100644 (file)
@@ -42,7 +42,8 @@ special ModuleLoader
                end
                var node_module = node_tree.n_base
                assert node_module isa AModule
-               var module = new MMSrcModule(context, node_module, dir, name, filename)
+               var module_loc = new Location.with_file(filename)
+               var module = new MMSrcModule(context, node_module, dir, name, module_loc)
                return module
        end
 
index 925a740..23d9973 100644 (file)
@@ -29,9 +29,9 @@ special MMModule
        # Concrete NIT source local classs by name
        readable var _src_local_classes: Map[Symbol, MMSrcLocalClass]
 
-       init(c: MMContext, source: AModule, dir: MMDirectory, name: Symbol, filename: String)
+       init(c: MMContext, source: AModule, dir: MMDirectory, name: Symbol, loc: Location)
        do
-               super(name, dir, c, filename)
+               super(name, dir, c, loc)
                _node = source
                _src_local_classes = new HashMap[Symbol, MMSrcLocalClass]
        end
@@ -368,7 +368,7 @@ special Visitor
        fun locate(n: nullable PNode): String
        do
                if n != null then return n.locate
-               return _module.filename
+               return _module.location.file
        end
 
        # Check conformity and display error