icode: ITypeCheck requires a receiver
[nit.git] / src / analysis / icode_dump.nit
index 18a2881..926a6fc 100644 (file)
@@ -65,9 +65,16 @@ redef class IClosureDecl
 end
 
 class ICodeDumper
+       readable var _dump_locations: Bool
+       readable var _dump_line_numbers: Bool
        var _ids: HashMap[Object, String] = new HashMap[Object, String]
        var _last_value: Int = 0
 
+       init(dump_locations: Bool, dump_line_numbers: Bool) do
+               _dump_locations = dump_locations
+               _dump_line_numbers = dump_line_numbers
+       end
+
        # Return the name of e
        # If e is unknown, a new name is gived
        fun register(e: IRegister): String
@@ -127,7 +134,7 @@ class ICodeDumper
        var _last_label: Int = 0
        # Return the name of e
        # If e is unknown, a new name is gived
-       fun lab(e: ISeq): String
+       fun lab(e: IEscapeMark): String
        do
                if _ids.has_key(e) then
                        return _ids[e]
@@ -154,7 +161,7 @@ class ICodeDumper
        end
 
        # Is the label e known? (because we goto to it)
-       fun has_lab(e: ISeq): Bool
+       fun has_lab(e: IEscapeMark): Bool
        do
                return _ids.has_key(e)
        end
@@ -168,7 +175,7 @@ class ICodeDumper
                print s
        end
 
-       var _indent_level: Int = 0
+       readable var _indent_level: Int = 0
 
        # Indent the next writes
        fun indent do _indent_level += 1
@@ -182,15 +189,19 @@ redef class ICode
        fun dump(icd: ICodeDumper)
        do
                var result = result
-               var s = ""
-               var l = location
-               if l != null then
-                       s = "        ... {l}"
+               var s_loc = ""
+               var s_line = ""
+               var loc = location
+               if loc != null and icd.dump_locations then
+                       s_loc = "        ... {loc}"
+               end
+               if icd.dump_line_numbers then
+                       s_line = "{icd.line(self)}: "
                end
                if result == null then
-                       icd.write "{icd.line(self)}: {dump_intern(icd)}{s}"
+                       icd.write "{s_line}{dump_intern(icd)}{s_loc}"
                else
-                       icd.write "{icd.line(self)}: {icd.register(result)} := {dump_intern(icd)}{s}"
+                       icd.write "{s_line}{icd.register(result)} := {dump_intern(icd)}{s_loc}"
                end
        end
 
@@ -224,7 +235,8 @@ redef class ISeq
                for ic in icodes do
                        ic.dump(icd)
                end
-               if icd.has_lab(self) then icd.write("{icd.lab(self)}:")
+               var mark = iescape_mark
+               if mark != null and icd.has_lab(mark) then icd.write("{icd.lab(mark)}:")
        end
 end
 
@@ -253,14 +265,15 @@ redef class ILoop
                end
                icd.unindent
                icd.write "}"
-               if icd.has_lab(self) then icd.write("{icd.lab(self)}:")
+               var mark = iescape_mark
+               if mark != null and icd.has_lab(mark) then icd.write("{icd.lab(mark)}:")
        end
 end
 
 redef class IEscape
        redef fun dump_intern(icd)
        do
-               return "ESCAPE {icd.lab(seq)}"
+               return "ESCAPE {icd.lab(iescape_mark)}"
        end
 end
 
@@ -351,18 +364,49 @@ end
 redef class ITypeCheck
        redef fun dump_intern(icd)
        do
-               return "CHECKTYPE {icd.register(expr)} isa {stype}"
+               return "CHECKTYPE {icd.register(expr2)} isa {stype}"
        end
 end
 
 redef class INative
        redef fun dump_intern(icd)
        do
-               if exprs.is_empty then
-                       return "NATIVE \"{code}\""
-               else
-                       return "NATIVE \"{code}\"({icd.register_all(exprs)})"
-               end
+               return "NATIVE \"{method.full_name}\"({icd.register_all(exprs)})"
+       end
+end
+
+redef class IIntValue
+       redef fun dump_intern(icd)
+       do
+               return "INTVALUE {value}"
+       end
+end
+
+redef class IBoolValue
+       redef fun dump_intern(icd)
+       do
+               return "BOOLVALUE {value}"
+       end
+end
+
+redef class IStringValue
+       redef fun dump_intern(icd)
+       do
+               return "STRINGVALUE {value}"
+       end
+end
+
+redef class ICharValue
+       redef fun dump_intern(icd)
+       do
+               return "CHARVALUE {value}"
+       end
+end
+
+redef class IFloatValue
+       redef fun dump_intern(icd)
+       do
+               return "FLOATVALUE {value}"
        end
 end