metamodel: rename 'universal' to 'enum'
[nit.git] / src / primitive_info.nit
index f597e4b..60da40d 100644 (file)
@@ -17,7 +17,7 @@
 # Common things for NIT compilation and C generation
 package primitive_info
 
-#FIXME Split this package into 2: one in metamodel and one in compiling
+#FIXME Split this module into 2: one in metamodel and one in compiling
 
 import metamodel
 
@@ -30,7 +30,6 @@ redef class MMLocalClass
 
        # Return the primitive information of the class.
        # Return null if the class is not primitive
-       # FIXME: Only here since there is no universal type yet
        fun primitive_info: nullable PrimitiveInfo
        do
                if _primitive_info_b == true then return _primitive_info_cache
@@ -44,8 +43,8 @@ redef class MMLocalClass
                var i = ctypes.iterator
                while i.is_ok do
                        var n = i.key
-                       if module.has_global_class_named(n) then
-                               var c = module.class_by_name(n)
+                       if mmmodule.has_global_class_named(n) then
+                               var c = mmmodule.class_by_name(n)
                                if cshe < c then
                                        _primitive_info_cache = i.item
                                        _primitive_info_b = true
@@ -62,9 +61,9 @@ redef class MMLocalClass
        private fun primitive_ctypes: HashMap[Symbol, PrimitiveInfo]
        do
                var res = new HashMap[Symbol, PrimitiveInfo]
-               var pnames = ["Int",    "Char", "Bool", "Float", "NativeString", "NativeArray", "Pointer"]
-               var tagged = [true,     true,   true,   false,   false,          false,         false]
-               var cnames = ["bigint", "char", "int",  "float", "char *",       "val_t *",     "void *"]
+               var pnames = ["Int",    "Char", "Bool", "Float", "NativeString", "Pointer"]
+               var tagged = [true,     true,   true,   false,   false,          false]
+               var cnames = ["bigint", "char", "int",  "float", "char *",       "void *"]
                for i in [0..pnames.length[ do
                        var n = pnames[i].to_symbol
                        var pi = new PrimitiveInfo(n, tagged[i], cnames[i])
@@ -105,6 +104,14 @@ redef class MMType
                end
        end
 
+       # Is the type tagged?
+       fun is_tagged: Bool
+       do
+               if is_nullable then return false
+               var pi = local_class.primitive_info
+               return pi != null and pi.tagged
+       end
+
        # The default c value for uninitialized types.
        # Return "null" for non primitive types and something more specific for primitive types
        fun default_cvalue: String