Merge: Less fixme and todo
authorJean Privat <jean@pryen.org>
Thu, 8 Jan 2015 02:49:52 +0000 (21:49 -0500)
committerJean Privat <jean@pryen.org>
Thu, 8 Jan 2015 02:49:52 +0000 (21:49 -0500)
Looked at http://jenkins.gresil.org/jenkins/job/nit/tasks and did some work.

Pull-Request: #1077
Reviewed-by: Romain Chanoir <chanoir.romain@courrier.uqam.ca>
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>

13 files changed:
lib/standard/collection/array.nit
src/annotation.nit
src/compiler/abstract_compiler.nit
src/compiler/compiler_ffi.nit
src/compiler/separate_compiler.nit
src/ffi/header_dependency.nit
src/loader.nit
src/modelbuilder.nit
src/modelize/modelize_class.nit
src/nitlight.nit
src/nitpretty.nit
src/testing/testing_doc.nit
tests/sav/test_new_native_alt1.res

index e70acd2..68f84e7 100644 (file)
@@ -374,10 +374,6 @@ class Array[E]
        # The internal storage.
        private var items: nullable NativeArray[E] = null
 
-       # Do not use this method
-       # FIXME: Remove it once modules can intrude non local modules
-       fun intern_items: NativeArray[E] do return _items.as(not null)
-
        # The size of `_items`.
        private var capacity: Int = 0
 
index 19653a3..882b645 100644 (file)
@@ -87,8 +87,8 @@ redef class ModelBuilder
        do
                var annotations = new Array[AAnnotation]
                for mmod in mmodule.in_importation.greaters do
-                       if not mmodule2nmodule.keys.has(mmod) then continue
-                       var amod = mmodule2nmodule[mmod]
+                       var amod = mmodule2node(mmod)
+                       if amod == null then continue
                        var module_decl = amod.n_moduledecl
                        if module_decl == null then continue
                        var aas = module_decl.get_annotations(name)
@@ -101,8 +101,8 @@ redef class ModelBuilder
        # Obviously, if there is no ast associated to `mmodule`, then nothing is returned.
        fun get_mmodule_annotation(name: String, mmodule: MModule): nullable AAnnotation
        do
-               if not mmodule2nmodule.keys.has(mmodule) then return null
-               var amod = mmodule2nmodule[mmodule]
+               var amod = mmodule2node(mmodule)
+               if amod == null then return null
                var module_decl = amod.n_moduledecl
                if module_decl == null then return null
                var res = module_decl.get_single_annotation(name, self)
index f64fc79..d681036 100644 (file)
@@ -1462,10 +1462,11 @@ abstract class AbstractCompilerVisitor
                self.require_declaration(s)
        end
 
-       # look for a needed .h and .c file for a given .nit source-file
-       # FIXME: bad API, parameter should be a `MModule`, not its source-file
-       fun add_extern(file: String)
+       # Look for a needed .h and .c file for a given module
+       # This is used for the legacy FFI
+       fun add_extern(mmodule: MModule)
        do
+               var file = mmodule.location.file.filename
                file = file.strip_extension(".nit")
                var tryfile = file + ".nit.h"
                if tryfile.file_exists then
@@ -2161,10 +2162,7 @@ redef class AMethPropdef
                else
                        return false
                end
-               if location.file != null then
-                       var file = location.file.filename
-                       v.add_extern(file)
-               end
+               v.add_extern(mpropdef.mclassdef.mmodule)
                var res: nullable RuntimeVariable = null
                var ret = mpropdef.msignature.return_mtype
                if ret != null then
@@ -2196,10 +2194,7 @@ redef class AMethPropdef
                else
                        return false
                end
-               if location.file != null then
-                       var file = location.file.filename
-                       v.add_extern(file)
-               end
+               v.add_extern(mpropdef.mclassdef.mmodule)
                v.adapt_signature(mpropdef, arguments)
                v.unbox_signature_extern(mpropdef, arguments)
                var ret = arguments.first.mtype
index b6cb920..ca22005 100644 (file)
@@ -27,8 +27,7 @@ redef class MModule
 
        private fun nmodule(v: AbstractCompilerVisitor): nullable AModule
        do
-               var m2n = v.compiler.modelbuilder.mmodule2nmodule
-               return m2n.get_or_null(self)
+               return v.compiler.modelbuilder.mmodule2node(self)
        end
 
        redef fun finalize_ffi(compiler: AbstractCompiler)
@@ -100,7 +99,7 @@ redef class AMethPropdef
        do
                var mmodule = mpropdef.mclassdef.mmodule
                var mainmodule = v.compiler.mainmodule
-               var amodule = v.compiler.modelbuilder.mmodule2nmodule[mmodule]
+               var amodule = v.compiler.modelbuilder.mmodule2node(mmodule)
                var mclass_type = mpropdef.mclassdef.bound_mtype
 
                # Declare as extern
index c298f93..8152658 100644 (file)
@@ -1077,8 +1077,8 @@ class SeparateCompilerVisitor
        do
                var rta = compiler.runtime_type_analysis
                var mmethod = callsite.mproperty
-               # TODO: Inlining of new-style constructors
-               if compiler.modelbuilder.toolcontext.opt_direct_call_monomorph.value and rta != null and not mmethod.is_root_init then
+               # TODO: Inlining of new-style constructors with initializers
+               if compiler.modelbuilder.toolcontext.opt_direct_call_monomorph.value and rta != null and callsite.mpropdef.initializers.is_empty then
                        var tgs = rta.live_targets(callsite)
                        if tgs.length == 1 then
                                # DIRECT CALL
index 485ba1f..10c1db3 100644 (file)
@@ -58,8 +58,8 @@ redef class MModule
                        end
 
                        # does the super module itself has extern dependancies?
-                       var amodule = v.toolcontext.modelbuilder.mmodule2nmodule[m]
-                       if amodule.has_public_c_header then header_dependencies.add(m)
+                       var amodule = v.toolcontext.modelbuilder.mmodule2node(m)
+                       if amodule != null and amodule.has_public_c_header then header_dependencies.add(m)
                end
 
                header_dependencies_cache = header_dependencies
index b0d6479..6149ffa 100644 (file)
@@ -501,9 +501,7 @@ redef class ModelBuilder
        do
                # Check the module name
                var decl = nmodule.n_moduledecl
-               if decl == null then
-                       #warning(nmodule, "Warning: Missing 'module' keyword") #FIXME: NOT YET FOR COMPATIBILITY
-               else
+               if decl != null then
                        var decl_name = decl.n_name.n_id.text
                        if decl_name != mod_name then
                                error(decl.n_name, "Error: module name missmatch; declared {decl_name} file named {mod_name}")
@@ -606,8 +604,18 @@ redef class ModelBuilder
        var nmodules = new Array[AModule]
 
        # Register the nmodule associated to each mmodule
-       # FIXME: why not refine the `MModule` class with a nullable attribute?
-       var mmodule2nmodule = new HashMap[MModule, AModule]
+       #
+       # Public clients need to use `mmodule2node` to access stuff.
+       private var mmodule2nmodule = new HashMap[MModule, AModule]
+
+       # Retrieve the associated AST node of a mmodule.
+       # This method is used to associate model entity with syntactic entities.
+       #
+       # If the module is not associated with a node, returns null.
+       fun mmodule2node(mmodule: MModule): nullable AModule
+       do
+               return mmodule2nmodule.get_or_null(mmodule)
+       end
 end
 
 # File-system location of a module (file) that is identified but not always loaded.
index b38bdac..30f5885 100644 (file)
@@ -86,7 +86,7 @@ redef class ModelBuilder
                model.mmodule_importation_hierarchy.sort(mmodules)
                var nmodules = new Array[AModule]
                for mm in mmodules do
-                       nmodules.add(mmodule2nmodule[mm])
+                       nmodules.add(mmodule2node(mm).as(not null))
                end
                toolcontext.run_phases(nmodules)
 
index 5112e25..65840a8 100644 (file)
@@ -283,9 +283,8 @@ redef class ModelBuilder
                nmodule.build_classes_is_done = true
                var mmodule = nmodule.mmodule.as(not null)
                for imp in mmodule.in_importation.direct_greaters do
-
-                       if not mmodule2nmodule.has_key(imp) then continue
-                       build_classes(mmodule2nmodule[imp])
+                       var nimp = mmodule2node(imp)
+                       if nimp != null then build_classes(nimp)
                end
 
                if errcount != toolcontext.error_count then return
index 256e91e..0c8998b 100644 (file)
@@ -67,7 +67,8 @@ for mm in mmodules do
        if opt_last_line.value != 0 then v.last_line = opt_last_line.value
        if opt_ast.value then v.with_ast = true
        var page = null
-       var m = modelbuilder.mmodule2nmodule[mm]
+       var m = modelbuilder.mmodule2node(mm)
+       assert m != null
        if not opt_fragment.value then
                page = new HTMLTag("html")
                page.add_raw_html """<head>
index 7ff0b16..af3fae0 100644 (file)
@@ -82,12 +82,11 @@ if not dir.file_exists then dir.mkdir
 var v = new PrettyPrinterVisitor
 
 for mmodule in mmodules do
-       if not mbuilder.mmodule2nmodule.has_key(mmodule) then
+       var nmodule = mbuilder.mmodule2node(mmodule)
+       if nmodule == null then
                print " Error: no source file for module {mmodule}"
                return
        end
-
-       var nmodule = mbuilder.mmodule2nmodule[mmodule]
        var file = "{dir}/{mmodule.name}.nit"
        var tpl = v.pretty_nmodule(nmodule)
        tpl.write_to_file file
index f0b8102..e975d85 100644 (file)
@@ -318,9 +318,9 @@ redef class ModelBuilder
        do
                var ts = new HTMLTag("testsuite")
                toolcontext.info("nitunit: doc-unit {mmodule}", 2)
-               if not mmodule2nmodule.has_key(mmodule) then return ts
 
-               var nmodule = mmodule2nmodule[mmodule]
+               var nmodule = mmodule2node(mmodule)
+               if nmodule == null then return ts
 
                # usualy, only the original module must be imported in the unit test.
                var o = mmodule
index 2ebac03..d21eb0d 100644 (file)
@@ -1,4 +1,4 @@
-Runtime error: Cast failed. Expected `E`, got `Bool` (../lib/standard/collection/array.nit:812)
+Runtime error: Cast failed. Expected `E`, got `Bool` (../lib/standard/collection/array.nit:808)
 NativeString
 N
 Nit