parser: node locations are not nullable
[nit.git] / src / syntax / syntax_base.nit
index f693dd4..09b7573 100644 (file)
@@ -285,70 +285,84 @@ end
 # Visitor used during the syntax analysis
 class AbsSyntaxVisitor
 special 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)
+               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)
+               return cls.get_instantiate_type(vtype)
+       end
+
        # The root type Object
        fun type_object: MMType
        do
-               return _module.class_by_name(once ("Object".to_symbol)).get_type
+               return get_type_by_name(once ("Object".to_symbol))
        end
 
        # The primitive type Bool
        fun type_bool: MMType
        do
-               return _module.class_by_name(once ("Bool".to_symbol)).get_type
+               return get_type_by_name(once ("Bool".to_symbol))
        end
        
        # The primitive type Int 
        fun type_int: MMType
        do
-               return _module.class_by_name(once ("Int".to_symbol)).get_type
+               return get_type_by_name(once ("Int".to_symbol))
        end
 
        # The primitive type Float
        fun type_float: MMType
        do
-               return _module.class_by_name(once ("Float".to_symbol)).get_type
+               return get_type_by_name(once ("Float".to_symbol))
        end
 
        # The primitive type Char
        fun type_char: MMType
        do
-               return _module.class_by_name(once ("Char".to_symbol)).get_type
+               return get_type_by_name(once ("Char".to_symbol))
        end
 
        # The primitive type String
        fun type_string: MMType
        do
-               return _module.class_by_name(once ("String".to_symbol)).get_type
+               return get_type_by_name(once ("String".to_symbol))
        end
 
        # The primitive type Collection[nullable Object]
        fun type_collection: MMType
        do
-               return _module.class_by_name(once ("Collection".to_symbol)).get_instantiate_type([type_object.as_nullable])
+               return get_instantiated_type_by_name(once ("Collection".to_symbol), [type_object.as_nullable])
        end
 
        # The primitive type NativeString
        fun type_nativestring: MMType
        do
-               return _module.class_by_name(once ("NativeString".to_symbol)).get_type
+               return get_type_by_name(once ("NativeString".to_symbol))
        end
 
        # The primitive type Array[?]
        fun type_array(stype: MMType): MMType
        do
-               return _module.class_by_name(once ("Array".to_symbol)).get_instantiate_type([stype])
+               return get_instantiated_type_by_name(once ("Array".to_symbol), [stype])
        end
 
        # The primitive type Discrete
        fun type_discrete: MMType
        do
-               return _module.class_by_name(once ("Discrete".to_symbol)).get_type
+               return get_type_by_name(once ("Discrete".to_symbol))
        end
 
        # The primitive type Range[?]
        fun type_range(stype: MMType): MMType
        do
-               return _module.class_by_name(once ("Range".to_symbol)).get_instantiate_type([stype])
+               return get_instantiated_type_by_name(once ("Range".to_symbol), [stype])
        end
 
        # The primitive type of null
@@ -418,12 +432,7 @@ special Visitor
        do
                if not n.is_typed then
                        if tc.error_count == 0 then
-                               var loc = n.location
-                               if loc == null then
-                                       print("Unknown node not typed but not error")
-                               else
-                                       print("{loc} not typed but not error")
-                               end
+                               print("{n.location} not typed but not error")
                                abort
                        end
                        # An error occured in a sub node,
@@ -474,12 +483,7 @@ special Visitor
                                if node == null then
                                        error(n, "Type error: no most general type. Got {n.stype} and {stype}.")
                                else
-                                       var loc = node.location
-                                       if loc == null then
-                                               error(n, "Type error: no most general type. Got {n.stype} and {stype} at ????.")
-                                       else
-                                               error(n, "Type error: no most general type. Got {n.stype} and {stype} at {loc.relative_to(n.location)}.")
-                                       end
+                                       error(n, "Type error: no most general type. Got {n.stype} and {stype} at {node.location.relative_to(n.location)}.")
                                end
                                return null
                        end
@@ -734,8 +738,8 @@ special AExpr
        # The signature of the called property (require is_typed)
        fun prop_signature: MMSignature is abstract
 
-       # The real arguments used (after star transformation) (require is_typed)
-       fun arguments: Array[AExpr] is abstract
+       # The raw arguments used (without vararg transformation) (require is_typed)
+       fun raw_arguments: Array[AExpr] is abstract
 end
 
 class AAbsSendExpr