nitg: add add_raw_abort to allow complex runtime error messages
authorJean Privat <jean@pryen.org>
Tue, 26 Nov 2013 14:09:01 +0000 (09:09 -0500)
committerJean Privat <jean@pryen.org>
Tue, 26 Nov 2013 14:09:01 +0000 (09:09 -0500)
Signed-off-by: Jean Privat <jean@pryen.org>

src/abstract_compiler.nit

index 857cb37..a0d0148 100644 (file)
@@ -894,10 +894,16 @@ abstract class AbstractCompilerVisitor
        # used by aborts, asserts, casts, etc.
        fun add_abort(message: String)
        do
+               self.add("fprintf(stderr, \"Runtime error: %s\", \"{message.escape_to_c}\");")
+               add_raw_abort
+       end
+
+       fun add_raw_abort
+       do
                if self.current_node != null and self.current_node.location.file != null then
-                       self.add("fprintf(stderr, \"Runtime error: %s (%s:%d)\\n\", \"{message.escape_to_c}\", \"{self.current_node.location.file.filename.escape_to_c}\", {current_node.location.line_start});")
+                       self.add("fprintf(stderr, \" (%s:%d)\\n\", \"{self.current_node.location.file.filename.escape_to_c}\", {current_node.location.line_start});")
                else
-                       self.add("fprintf(stderr, \"Runtime error: %s\\n\", \"{message.escape_to_c}\");")
+                       self.add("fprintf(stderr, \"\\n\");")
                end
                self.add("exit(1);")
        end