It reduces the constant pool size in the executable.
extern char ** glob_argv;
struct trace_t {
extern char ** glob_argv;
struct trace_t {
- struct trace_t *prev;
- const char *text;
+ struct trace_t *prev; /* previous stack frame */
+ const char *file; /* source filename */
+ int line; /* line number */
+ const char *meth; /* method name */
};
extern struct trace_t *tracehead;
typedef enum {true = (1==1),false = (0==1)} bool;
};
extern struct trace_t *tracehead;
typedef enum {true = (1==1),false = (0==1)} bool;
void nit_exit(int i) {
fprintf(stderr, ",---- Stack trace -- - - -\n");
while(tracehead != NULL) {
void nit_exit(int i) {
fprintf(stderr, ",---- Stack trace -- - - -\n");
while(tracehead != NULL) {
- fprintf(stderr, "| %s\n",tracehead->text);
+ fprintf(stderr, "| %s (%s:%d)\n", tracehead->meth, tracehead->file, tracehead->line);
if (tracehead == tracehead->prev) break;
tracehead = tracehead->prev;
}
if (tracehead == tracehead->prev) break;
tracehead = tracehead->prev;
}
# Compile sep files
meth compile_mod_to_c(v: CompilerVisitor)
do
# Compile sep files
meth compile_mod_to_c(v: CompilerVisitor)
do
+ v.add_decl("#define LOCATE_{name} \"{filename}\"")
if not v.tc.global then
v.add_decl("extern const int SFT_{name}[];")
end
if not v.tc.global then
v.add_decl("extern const int SFT_{name}[];")
end
# Variable where a functionnal nit return must store its value
readable writable attr _return_value: String
# Variable where a functionnal nit return must store its value
readable writable attr _return_value: String
+
+ # Generate an fprintf to display an error location
+ meth printf_locate_error(node: PNode): String
+ do
+ var s = "fprintf(stderr, \""
+ if method != null then s.append(" in %s")
+ s.append(" (%s:%d)\\n\", ")
+ if method != null then s.append("LOCATE_{method.cname}, ")
+ s.append("LOCATE_{module.name}, {node.line_number});")
+ return s
+ end
+
redef init(module: MMSrcModule)
do
super
redef init(module: MMSrcModule)
do
super
args.add(" param{i}")
end
var cs = decl_csignature(v, args)
args.add(" param{i}")
end
var cs = decl_csignature(v, args)
+ v.add_decl("#define LOCATE_{cname} \"{full_name}\"")
v.add_instr("{cs} \{")
v.indent
var ctx_old = v.ctx
v.ctx = new CContext
v.add_instr("{cs} \{")
v.indent
var ctx_old = v.ctx
v.ctx = new CContext
- v.add_decl("struct trace_t trace = \{NULL, \"{module.name}::{local_class.name}::{name} ({node.locate})\"};")
+ v.add_decl("struct trace_t trace = \{NULL, LOCATE_{module.name}, {node.line_number}, LOCATE_{cname}};")
v.add_instr("trace.prev = tracehead; tracehead = &trace;")
var s = do_compile_inside(v, args)
v.add_instr("tracehead = trace.prev;")
v.add_instr("trace.prev = tracehead; tracehead = &trace;")
var s = do_compile_inside(v, args)
v.add_instr("tracehead = trace.prev;")
do
# Fixme: handle formaltypes
var g = local_class.global
do
# Fixme: handle formaltypes
var g = local_class.global
- v.add_instr("if (({recv}!=NIT_NULL) && !VAL_ISA({recv}, {g.color_id}, {g.id_id})) \{ fprintf(stderr, \"Cast failled at {n.locate}\\n\"); nit_exit(1); } /*cast {self}*/;")
+ v.add_instr("if (({recv}!=NIT_NULL) && !VAL_ISA({recv}, {g.color_id}, {g.id_id})) \{ fprintf(stderr, \"Cast failled\"); {v.printf_locate_error(n)} nit_exit(1); } /*cast {self}*/;")
else
v.return_value = null
end
else
v.return_value = null
end
if self isa AConcreteInitPropdef then
if self isa AConcreteInitPropdef then
v.invoke_super_init_calls_after(null)
end
if n_block != null then
v.invoke_super_init_calls_after(null)
end
if n_block != null then
redef class ADeferredMethPropdef
redef meth do_compile_inside(v, method, params)
do
redef class ADeferredMethPropdef
redef meth do_compile_inside(v, method, params)
do
- v.add_instr("fprintf(stderr, \"Deferred method {name} called ({first_token.locate})\\n\");")
+ v.add_instr("fprintf(stderr, \"Deferred method %s called\");")
+ v.add_instr(v.printf_locate_error(self))
v.add_instr("nit_exit(1);")
if method.signature.return_type != null then
return("NIT_NULL")
v.add_instr("nit_exit(1);")
if method.signature.return_type != null then
return("NIT_NULL")
redef class AAbortExpr
redef meth compile_stmt(v)
do
redef class AAbortExpr
redef meth compile_stmt(v)
do
- v.add_instr("fprintf(stderr, \"Aborted: {locate}\\n\"); nit_exit(1);")
+ v.add_instr("fprintf(stderr, \"Aborted\"); {v.printf_locate_error(self)} nit_exit(1);")
redef meth compile_stmt(v)
do
var e = v.compile_expr(n_expr)
redef meth compile_stmt(v)
do
var e = v.compile_expr(n_expr)
- s = "Assert '{n_id.text}' "
- v.add_instr("if (!UNTAG_Bool({e})) \{ fprintf(stderr, \"{s} failed: {locate}\\n\"); nit_exit(1);}")
+ v.add_instr("if (!UNTAG_Bool({e})) \{ fprintf(stderr, \"Assert%s failed\", \"{s}\"); {v.printf_locate_error(self)} nit_exit(1);}")
# Give a human readable location of the node.
meth locate: String is abstract
# Give a human readable location of the node.
meth locate: String is abstract
+ # Return only the line number of the node
+ meth line_number: Int is abstract
+
# Debug method: output a message prefixed with the location.
meth printl(str: String)
do
# Debug method: output a message prefixed with the location.
meth printl(str: String)
do
do
return "{filename}:{line},{pos}"
end
do
return "{filename}:{line},{pos}"
end
+
+ redef meth line_number do return line
end
redef meth replace_with(n: PNode)
end
redef meth replace_with(n: PNode)
+ do
+ super
+ assert n isa Prod
+ n.first_token = first_token
+ n.last_token = last_token
+ end
+
+ redef meth line_number
- super
- assert n isa Prod
- n.first_token = first_token
- n.last_token = last_token
+ if first_token != null then
+ return first_token.line
+ else
+ return 0
+ end
# Give a human readable location of the node.
meth locate: String is abstract
# Give a human readable location of the node.
meth locate: String is abstract
+ # Return only the line number of the node
+ meth line_number: Int is abstract
+
# Debug method: output a message prefixed with the location.
meth printl(str: String)
do
# Debug method: output a message prefixed with the location.
meth printl(str: String)
do
do
return "{filename}:{line},{pos}"
end
do
return "{filename}:{line},{pos}"
end
+
+ redef meth line_number do return line
end
redef meth replace_with(n: PNode)
end
redef meth replace_with(n: PNode)
+ do
+ super
+ assert n isa Prod
+ n.first_token = first_token
+ n.last_token = last_token
+ end
+
+ redef meth line_number
- super
- assert n isa Prod
- n.first_token = first_token
- n.last_token = last_token
+ if first_token != null then
+ return first_token.line
+ else
+ return 0
+ end