nitj: build naive type tables using Java HashMaps
authorAlexandre Terrasa <alexandre@moz-code.org>
Thu, 9 Jul 2015 23:55:32 +0000 (19:55 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Tue, 21 Jul 2015 21:23:20 +0000 (17:23 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

src/compiler/java_compiler.nit

index 05d6de1..958127a 100644 (file)
@@ -372,7 +372,7 @@ redef class MClass
                v.add("  private {rt_name}() \{")
                v.add("    this.class_name = \"{name}\";")
                compile_vft(v)
-               # TODO compile_type_table(v)
+               compile_type_table(v)
                v.add("  \}")
                v.add("  public static RTClass get{rt_name}() \{")
                v.add("    if(instance == null) \{")
@@ -408,6 +408,17 @@ redef class MClass
                        end
                end
        end
+
+       # Compile the type table for the MClass
+       fun compile_type_table(v: JavaCompilerVisitor) do
+               for pclass in in_hierarchy(v.compiler.mainmodule).greaters do
+                       if pclass == self then
+                               v.add("supers.put(\"{pclass.jname}\", this);")
+                       else
+                               v.add("supers.put(\"{pclass.jname}\", {pclass.rt_name}.get{pclass.rt_name}());")
+                       end
+               end
+       end
 end
 
 redef class MMethodDef