Commit c97227b8
c97227b87e68Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified
Description
codegen: Ruby-map the unsupported() emit-time diagnostic
The #line machinery (ea60d5f) already attributes cc errors on the
generated C back to Ruby lines, but codegen's own emit-time gaps --
unsupported(...) -- named only an opaque node id (node 25 (CallNode <<)), so a user / a tool (spinel-doctor) had nothing to anchor on.
Prepend the source position the parser stamps (the same node_line /
node_file the #line directives use) to every unsupported message:
spinel: app.rb:7: unsupported call: node 25 (CallNode <<) ...
This is the emit-time-guard half of #1338 -- where codegen does have authoritative knowledge that it can't emit a construct, it now reports against the .rb line, complementing the cc-deferred #line attribution. Falls back to the bare node form when the position wasn't stamped.
Fixes #1338
Details
- Commit
- c97227b87e68
- Parent
- fc89c7aeb0e6
src/codegen_util.cmodifiedView file
}void unsupported(Compiler *c, int id, const char *what) { const char *ty = nt_type(c->nt, id); /* Ruby-map the diagnostic (#1338): a codegen gap reports against the source line the parser stamped (the same position the #line machinery uses), so the message is anchored to the .rb file instead of an opaque node id. Falls back to the bare form when the position wasn't stamped. */ int ln = (int)nt_int(c->nt, id, "node_line", 0); char pos[1200]; pos[0] = 0; if (ln > 0) { int fid = (int)nt_int(c->nt, id, "node_file", 0); const char *file = nt_file_path(c->nt, fid); if (!file || !*file) file = c->nt->source_file; if (!file || !*file) file = "source.rb"; snprintf(pos, sizeof pos, "%s:%d: ", file, ln); } const char *mname = ty && !strcmp(ty, "CallNode") ? nt_str(c->nt, id, "name") : NULL; if (mname) { int recv = nt_ref(c->nt, id, "receiver"); int args = nt_ref(c->nt, id, "arguments"); int ac = 0; const int *av = args >= 0 ? nt_arr(c->nt, args, "arguments", &ac) : NULL; fprintf(stderr, "spinel: unsupported %s: node %d (%s `%s`) recv=%s/ty%d argc=%d", what, id, ty, mname, fprintf(stderr, "spinel: %sunsupported %s: node %d (%s `%s`) recv=%s/ty%d argc=%d", pos, what, id, ty, mname, recv >= 0 ? nt_type(c->nt, recv) : "-", recv >= 0 ? (int)comp_ntype(c, recv) : -1, ac); if (ac > 0 && av) fprintf(stderr, " arg0ty%d", (int)comp_ntype(c, av[0])); fprintf(stderr, "\n"); } else fprintf(stderr, "spinel: unsupported %s: node %d (%s)\n", what, id, ty ? ty : "?"); fprintf(stderr, "spinel: %sunsupported %s: node %d (%s)\n", pos, what, id, ty ? ty : "?"); /* SP_COLLECT_ERRORS: don't abort on the first gap -- keep going so one run surfaces every unsupported construct (the emitted C is then malformed and only the stderr list is useful). */