import partial_order
import location
+import symbol
# The main singleton which knows everything
-class MMContext
+abstract class MMContext
init do end
readable var _modules: Array[MMModule] = new Array[MMModule]
# Register a new module with the modules it depends on
- fun add_module(module: MMModule, supers: Array[MMModule])
+ fun add_module(mod: MMModule, supers: Array[MMModule])
do
- _module_hierarchy.add(module, _module_hierarchy.select_smallests(supers))
- _modules.add(module)
- module._mhe = _module_hierarchy[module]
+ _module_hierarchy.add(mod, _module_hierarchy.select_smallests(supers))
+ _modules.add(mod)
+ mod._mhe = _module_hierarchy[mod]
end
# Register a global class
readable var _modules: Map[Symbol, MMModule] = new HashMap[Symbol, MMModule]
# Register a new module
- fun add_module(module: MMModule)
+ fun add_module(mod: MMModule)
do
- assert not _modules.has_key(module.name)
- _modules[module.name] = module
+ assert not _modules.has_key(mod.name)
+ _modules[mod.name] = mod
end
init(name: Symbol, path: String, parent: nullable MMDirectory) do
end
end
-# A module is a NIT package
-class MMModule
+# A module is a Nit file
+abstract class MMModule
# Global context
readable var _context: MMContext
# Dictionary of global classes
var _global_class_by_name: Map[Symbol, MMGlobalClass] = new HashMap[Symbol, MMGlobalClass]
+ # Is a hybrid module partially implemented in extern code
+ # It is if it contains a new extern class or an
+ # extern class declaration
+ var is_extern_hybrid : Bool writable = false
+
+ # Uses foreign function interface
+ fun uses_ffi : Bool is abstract
+
protected init(name: Symbol, dir: MMDirectory, context: MMContext, loc: Location)
do
_name = name
end
# The module that introduces the global class
- fun module: MMModule
+ fun mmmodule: MMModule
do
- return intro.module
+ return intro.mmmodule
end
redef fun to_s
do
var sup = new Array[MMLocalClass]
for s in class_refinement_hierarchy do
- if c.module.mhe < s.module and s isa MMConcreteClass then
+ if c.mmmodule.mhe < s.mmmodule and s isa MMConcreteClass then
sup.add(s)
end
end
# Is the global class an abstract class?
readable writable var _is_abstract: Bool = false
- # Is the global class a universal class?
- readable writable var _is_universal: Bool = false
+ # Is the global class a enum class?
+ readable writable var _is_enum: Bool = false
+
+ # Is the global class an extern class?
+ readable writable var _is_extern: Bool = false
# Visibility of the global class
# 1 -> public
end
# Local classes are classes defined, refined or imported in a module
-class MMLocalClass
+abstract class MMLocalClass
# The name of the local class
readable var _name: Symbol
readable var _arity : Int
# The module of the local class
- readable var _module: MMModule
+ readable var _mmmodule: MMModule
# The global class of the local class
fun global: MMGlobalClass do return _global.as(not null)
# Create a new class with a given name and arity
protected init(mod: MMModule, name: Symbol, arity: Int)
do
- _module = mod
+ _mmmodule = mod
_name = name
_arity = arity
mod._local_classes.add(self)
fun new_global
do
var g = new MMGlobalClass(self)
- _module._global_classes.add(g)
- _module._global_class_by_name[name] = g
+ _mmmodule._global_classes.add(g)
+ _mmmodule._global_class_by_name[name] = g
set_global(g)
end
do
_global = g
_global.register_local_class(self)
- _module.register_global_class(self)
+ _mmmodule.register_global_class(self)
end
# Is there a global propery with a given name
return _global_properties.has(glob)
end
- # Get a local proprty by its global property
+ # Get a local property by its global property
fun [](glob: MMGlobalProperty): MMLocalProperty
do
return _local_property_by_global[glob]
end
# The current MMContext
- fun context: MMContext do return module.context
+ fun context: MMContext do return mmmodule.context
redef fun to_s
do
var a = self
if a == b then
return 0
- else if a.module.mhe < b.module then
+ else if a.mmmodule.mhe < b.mmmodule then
return 1
- else if b.module.mhe < a.module then
+ else if b.mmmodule.mhe < a.mmmodule then
return -1
end
var ar = a.cshe.rank
end
# Local properties are properties defined (explicitely or not) in a local class
-class MMLocalProperty
+abstract class MMLocalProperty
# The name of the property
readable var _name: Symbol
fun prhe: PartialOrderElement[MMLocalProperty] do return _prhe.as(not null)
# The module of the local property
- fun module: MMModule do return _local_class.module
+ fun mmmodule: MMModule do return _local_class.mmmodule
# Full expanded name with all qualifications
fun full_name: String
do
if _global == null then
- return "{local_class.module}::{local_class}::(?::{name})"
+ return "{local_class.mmmodule}::{local_class}::(?::{name})"
else if global.intro == self then
- return "{local_class.module}::{local_class}::{name}"
+ return "{local_class.mmmodule}::{local_class}::{name}"
else
- return "{local_class.module}::{local_class}::({global.intro.full_name})"
+ return "{local_class.mmmodule}::{local_class}::({global.intro.full_name})"
end
end
end
# Attribute local properties
-class MMAttribute
-special MMLocalProperty
+abstract class MMAttribute
+ super MMLocalProperty
+end
+
+class MMExplicitImport
+ var local_class : MMLocalClass
+ var method : MMMethod
end
# Method local properties
-class MMMethod
-special MMLocalProperty
+abstract class MMMethod
+ super MMLocalProperty
# Is the method defined with intern
fun is_intern: Bool is abstract
# Is the method abstract
fun is_abstract: Bool is abstract
- # Is the method extern, if yes what is the extern_name
+ # Is the method extern
+ fun is_extern: Bool is abstract
+
+ # extern name when specified explicitly in nit code
fun extern_name: nullable String is abstract
+
+ # properties explicitly exported to native code
+ fun explicit_imports : Set[ MMExplicitImport ] is abstract
end
# Concrete local classes
-class MMConcreteClass
-special MMLocalClass
+abstract class MMConcreteClass
+ super MMLocalClass
end