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>
# 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
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)
# 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)
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
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
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
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)
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
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
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
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}")
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.
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)
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
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>
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
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
-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