syntax: enable a generalized for with iterate
[nit.git] / src / syntax / syntax_base.nit
index 13e1372..6b9bdc0 100644 (file)
@@ -22,7 +22,7 @@ import mmloader
 
 # Concrete NIT source module
 class MMSrcModule
-special MMModule
+       super MMModule
        # A source module can locate AST nodes of related MM entities
        # Once a source module AST is no more needed, _nodes is set to null
        # See ToolContext::keep_ast property in syntax.nit for details
@@ -65,7 +65,7 @@ end
 redef class MMGlobalClass
        # Check that a module can access a class
        fun check_visibility(v: AbsSyntaxVisitor, n: ANode, cm: MMSrcModule): Bool do
-               var pm = intro.module
+               var pm = intro.mmmodule
                assert pm isa MMSrcModule
                var vpm = cm.visibility_for(pm)
                if vpm == 3 then
@@ -83,9 +83,9 @@ end
 
 # Concrete NIT source local classes
 class MMSrcLocalClass
-special MMConcreteClass
+       super MMConcreteClass
        # The first related AST node (if any)
-       fun node: nullable AClassdef do return module.nodes(self).as(nullable AClassdef)
+       fun node: nullable AClassdef do return mmmodule.nodes(self).as(nullable AClassdef)
 
        # Concrete NIT source generic formal parameter by name
        readable var _formal_dict: Map[Symbol, MMTypeFormalParameter] = new HashMap[Symbol, MMTypeFormalParameter]
@@ -104,7 +104,7 @@ end
 redef class MMGlobalProperty
        # Check that a module can access a property
        fun check_visibility(v: AbsSyntaxVisitor, n: ANode, cm: MMSrcModule, allows_protected: Bool): Bool do
-               var pm = local_class.module
+               var pm = local_class.mmmodule
                assert pm isa MMSrcModule
                var vpm = cm.visibility_for(pm)
                if vpm == 3 then
@@ -134,36 +134,37 @@ end
 
 # Concrete NIT source attribute
 class MMSrcAttribute
-special MMAttribute
-       redef fun node: nullable AAttrPropdef do return module.nodes(self).as(nullable AAttrPropdef)
+       super MMAttribute
+       redef fun node: nullable AAttrPropdef do return mmmodule.nodes(self).as(nullable AAttrPropdef)
        init(name: Symbol, cla: MMLocalClass, n: AAttrPropdef)
        do
                super(name, cla)
-               cla.module.nodes(self) = n
+               cla.mmmodule.nodes(self) = n
        end
 end
 
 # Concrete NIT source method
 class MMSrcMethod
-special MMMethod
+       super MMMethod
        redef fun is_intern do return false
        redef fun is_abstract do return false
+       redef fun extern_name do return null
 end
 
 # Concrete NIT source method for an automatic accesor
 class MMAttrImplementationMethod
-special MMSrcMethod
-       redef fun node: nullable AAttrPropdef do return module.nodes(self).as(nullable AAttrPropdef)
+       super MMSrcMethod
+       redef fun node: nullable AAttrPropdef do return mmmodule.nodes(self).as(nullable AAttrPropdef)
        init(name: Symbol, cla: MMLocalClass, n: AAttrPropdef)
        do
                super(name, cla)
-               cla.module.nodes(self) = n
+               cla.mmmodule.nodes(self) = n
        end
 end
 
 # Concrete NIT source method for an automatic read accesor
 class MMReadImplementationMethod
-special MMAttrImplementationMethod
+       super MMAttrImplementationMethod
        init(name: Symbol, cla: MMLocalClass, n: AAttrPropdef)
        do
                super(name, cla, n)
@@ -172,7 +173,7 @@ end
 
 # Concrete NIT source method for an automatic write accesor
 class MMWriteImplementationMethod
-special MMAttrImplementationMethod
+       super MMAttrImplementationMethod
        init(name: Symbol, cla: MMLocalClass, n: AAttrPropdef)
        do
                super(name, cla, n)
@@ -181,25 +182,27 @@ end
 
 # Concrete NIT source method for an explicit method
 class MMMethSrcMethod
-special MMSrcMethod
+       super MMSrcMethod
        redef readable var _is_init: Bool
        redef readable var _is_intern: Bool
        redef readable var _is_abstract: Bool
-       redef fun node: nullable AMethPropdef do return module.nodes(self).as(nullable AMethPropdef)
+       redef readable writable var _extern_name: nullable String # Will be computed during MMBuilder
+       redef fun node: nullable AMethPropdef do return mmmodule.nodes(self).as(nullable AMethPropdef)
        init(name: Symbol, cla: MMLocalClass, n: nullable AMethPropdef)
        do
                super(name, cla)
-               cla.module.nodes(self) = n
+               cla.mmmodule.nodes(self) = n
                _is_init = node isa AConcreteInitPropdef
                _is_intern = node isa AInternMethPropdef
                _is_abstract = node isa ADeferredMethPropdef
+               _extern_name = null
        end
 end
 
 # Concrete NIT source virtual type
 class MMSrcTypeProperty
-special MMLocalProperty
-special MMTypeProperty
+       super MMLocalProperty
+       super MMTypeProperty
        init(name: Symbol, cla: MMLocalClass, n: ATypePropdef)
        do
                super(name, cla)
@@ -208,7 +211,7 @@ end
 
 # Concrete NIT implicit constructor
 class MMImplicitInit
-special MMMethSrcMethod
+       super MMMethSrcMethod
        fun super_init: nullable MMLocalProperty is abstract
        redef fun is_init do return true
        readable var _unassigned_attributes: Array[MMSrcAttribute]
@@ -229,12 +232,7 @@ abstract class Variable
        # Declaration AST node
        readable var _decl: nullable ANode
 
-       # Is the variable correcly declared
-       # Return false if typed was not yet computed or
-       # if an error occured during the typing computation
-       fun is_typed: Bool do return _stype != null
-
-       # The declaration static type of the variable
+       # Static type
        readable writable var _stype: nullable MMType
 
        redef fun to_s do return _name.to_s
@@ -250,21 +248,21 @@ end
 
 # Variable declared with 'var'
 class VarVariable
-special Variable
+       super Variable
        redef fun kind do return once "variable"
        init(n: Symbol, d: ANode) do super
 end
 
 # Parameter of method (declared in signature)
 class ParamVariable
-special Variable
+       super Variable
        redef fun kind do return once "parameter"
        init(n: Symbol, d: nullable ANode) do super
 end
 
 # Automatic variable (like in the 'for' statement)
 class AutoVariable
-special Variable
+       super Variable
        redef fun kind do return once "automatic variable"
        init(n: Symbol, d: ANode) do super
 end
@@ -272,7 +270,7 @@ end
 # False variable corresponding to closures declared in signatures
 # Lives in the same namespace than variables
 class ClosureVariable
-special Variable
+       super Variable
        redef fun kind do return once "closure"
 
        # The signature of the closure
@@ -289,18 +287,18 @@ end
 
 # Visitor used during the syntax analysis
 class AbsSyntaxVisitor
-special Visitor
+       super Visitor
        fun get_type_by_name(clsname: Symbol): MMType
        do
-               if not _module.has_global_class_named(clsname) then _tc.fatal_error(_module.location, "Missing necessary class: \"{clsname}\"")
-               var cls = _module.class_by_name(clsname)
+               if not _mmmodule.has_global_class_named(clsname) then _tc.fatal_error(_mmmodule.location, "Missing necessary class: \"{clsname}\"")
+               var cls = _mmmodule.class_by_name(clsname)
                return cls.get_type
        end
 
        fun get_instantiated_type_by_name(clsname: Symbol, vtype: Array[MMType]): MMType
        do
-               if not _module.has_global_class_named(clsname) then _tc.fatal_error(_module.location, "Missing necessary class: \"{clsname}\"")
-               var cls = _module.class_by_name(clsname)
+               if not _mmmodule.has_global_class_named(clsname) then _tc.fatal_error(_mmmodule.location, "Missing necessary class: \"{clsname}\"")
+               var cls = _mmmodule.class_by_name(clsname)
                return cls.get_instantiate_type(vtype)
        end
 
@@ -373,7 +371,7 @@ special Visitor
        # The primitive type of null
        fun type_none: MMType
        do
-               return _module.type_none
+               return _mmmodule.type_none
        end
 
        fun get_method(recv: MMType, name: Symbol): MMMethod
@@ -385,7 +383,7 @@ special Visitor
        end
 
        # The current module
-       readable var _module: MMSrcModule
+       readable var _mmmodule: MMSrcModule
 
        # The current class
        fun local_class: MMSrcLocalClass do return _local_class.as(not null)
@@ -482,8 +480,9 @@ special Visitor
                                node = n
                        end
                end
+               assert stype != null
                for n in nodes do
-                       if not n.stype < stype.as(not null) then
+                       if not n.stype < stype then
                                if node == null then
                                        error(n, "Type error: no most general type. Got {n.stype} and {stype}.")
                                else
@@ -495,10 +494,10 @@ special Visitor
                return stype
        end
 
-       protected init(tc: ToolContext, module: MMSrcModule)
+       protected init(tc: ToolContext, mmmodule: MMSrcModule)
        do
                _tc = tc
-               _module = module
+               _mmmodule = mmmodule
        end
 end
 
@@ -597,7 +596,7 @@ redef class AType
        fun get_local_class(v: AbsSyntaxVisitor): nullable MMLocalClass
        do
                var name = n_id.to_symbol
-               var mod = v.module
+               var mod = v.mmmodule
                var cla = v.local_class
 
                if cla.formal_dict.has_key(name) or cla.has_global_property_by_name(name) then
@@ -627,7 +626,7 @@ redef class AType
                _stype_cached = true
 
                var name = n_id.to_symbol
-               var mod = v.module
+               var mod = v.mmmodule
                var cla = v.local_class
                var t: nullable MMType
 
@@ -738,7 +737,7 @@ redef class AExpr
 end
 
 class AAbsAbsSendExpr
-special AExpr
+       super AExpr
        # The signature of the called property (require is_typed)
        fun prop_signature: MMSignature is abstract
 
@@ -747,7 +746,7 @@ special AExpr
 end
 
 class AAbsSendExpr
-special AAbsAbsSendExpr
+       super AAbsAbsSendExpr
        # The invoked method (require is_typed)
        fun prop: MMMethod is abstract
 
@@ -756,20 +755,20 @@ special AAbsAbsSendExpr
 end
 
 class ASuperInitCall
-special AAbsSendExpr
+       super AAbsSendExpr
 end
 
 redef class ASuperExpr
-special ASuperInitCall
+       super ASuperInitCall
        fun init_in_superclass: nullable MMMethod is abstract
 end
 
 redef class ANewExpr
-special AAbsSendExpr
+       super AAbsSendExpr
 end
 
 redef class ASendExpr
-special ASuperInitCall
+       super ASuperInitCall
        # Closure definitions
        fun closure_defs: nullable Array[AClosureDef] is abstract
 end
@@ -780,19 +779,19 @@ redef class AReassignFormExpr
 end
 
 class ASendReassignExpr
-special ASendExpr
-special AReassignFormExpr
+       super ASendExpr
+       super AReassignFormExpr
        # The invoked method used to read (require is_typed)
        # prop is the method used to write
        fun read_prop: MMMethod is abstract
 end
 
 redef class ACallReassignExpr
-special ASendReassignExpr
+       super ASendReassignExpr
 end
 
 redef class ABraReassignExpr
-special ASendReassignExpr
+       super ASendReassignExpr
 end
 
 redef class AAttrFormExpr
@@ -815,7 +814,7 @@ end
 
 redef class AForExpr
        # Associated automatic local variable
-       fun variable: AutoVariable is abstract
+       fun variables: Array[AutoVariable] is abstract
 end
 
 redef class ASelfExpr
@@ -829,7 +828,7 @@ redef class AVarFormExpr
 end
 
 redef class AClosureCallExpr
-special AAbsAbsSendExpr
+       super AAbsAbsSendExpr
        # Associated closure variable
        fun variable: ClosureVariable is abstract
 end