model: use the robust `intro_mmodule` instead of `intro.mmodule`.
[nit.git] / src / ffi / extern_classes.nit
index e1b8463..40459df 100644 (file)
 # Manages all extern classes and their associated foreign type.
 module extern_classes
 
-import ffi_base
+import light_ffi_base
+import modelize
 
 redef class ToolContext
-       var extern_classes_typing_phase_ast: Phase = new ExternClassesTypingPhaseAst(self, [ffi_language_assignation_phase])
+       var extern_classes_typing_phase_ast: Phase = new ExternClassesTypingPhaseAst(self, [ffi_language_assignation_phase, modelize_class_phase])
 
        var extern_classes_typing_phase_model: Phase = new ExternClassesTypingPhaseModel(self,
                [extern_classes_typing_phase_ast, modelize_class_phase, modelize_property_phase])
@@ -38,18 +39,18 @@ private class ExternClassesTypingPhaseAst
                if code_block == null then return
 
                if nclassdef.n_kwredef != null then
-                       # A redef cannot specifiy a different extern type
-                       toolcontext.error(nclassdef.location, "Only the introduction of a class can specify an extern type.")
+                       # A redef cannot specify a different extern type
+                       toolcontext.error(nclassdef.location, "FFI Error: only the introduction of a class can declare an extern type.")
                        return
                end
 
                var ftype = code_block.language.get_ftype(code_block, nclassdef)
-               nclassdef.ftype_cache = ftype
-               nclassdef.ftype_computed = true
+               nclassdef.mclassdef.ftype_cache = ftype
+               nclassdef.mclassdef.ftype_computed = true
        end
 end
 
-redef class AClassdef
+redef class MClassDef
        private var ftype_cache: nullable ForeignType = null
        private var ftype_computed = false
 
@@ -68,10 +69,11 @@ private class ExternClassesTypingPhaseModel
                if not nclassdef isa AStdClassdef then return
 
                var mclassdef = nclassdef.mclassdef
-               var mclass = nclassdef.mclass
+               if mclassdef == null then return
+               var mclass = mclassdef.mclass
 
                # We only need to do this once per class
-               if mclass.intro != mclassdef then return
+               if not mclassdef.is_intro then return
 
                if mclass.kind != extern_kind then return
 
@@ -103,13 +105,12 @@ redef class MClass
                        return ftype_cache
                end
 
-               var intro_nclassdef = v.toolcontext.modelbuilder.mclassdef2nclassdef[intro]
-               var ftype = intro_nclassdef.ftype
+               var ftype = intro.ftype
                if ftype == null then
                        var ftype_b: nullable ForeignType = null # FIXME hack to circumvent bug where ftype is typed null
 
                        # look in super classes
-                       for s in in_hierarchy(intro.mmodule).direct_greaters do
+                       for s in in_hierarchy(intro_mmodule).direct_greaters do
                                var super_ftype = s.compute_ftype(v)
                                if super_ftype != null then
                                        if ftype_b == null then
@@ -118,7 +119,7 @@ redef class MClass
                                        else
                                                # detect conflict
                                                if super_ftype != ftype_b then
-                                                       v.toolcontext.error(null, "Extern type conflict in {self}")
+                                                       v.toolcontext.error(null, "FFI Error: extern type conflict in `{self}`.")
                                                        return null
                                                end
                                        end