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

@@ -275,21 +275,34 @@
275275 }
276276 void unsupported(Compiler *c, int id, const char *what) {
277277 const char *ty = nt_type(c->nt, id);
278+ /* Ruby-map the diagnostic (#1338): a codegen gap reports against the source
279+ line the parser stamped (the same position the #line machinery uses), so
280+ the message is anchored to the .rb file instead of an opaque node id.
281+ Falls back to the bare form when the position wasn't stamped. */
282+ int ln = (int)nt_int(c->nt, id, "node_line", 0);
283+ char pos[1200]; pos[0] = 0;
284+ if (ln > 0) {
285+ int fid = (int)nt_int(c->nt, id, "node_file", 0);
286+ const char *file = nt_file_path(c->nt, fid);
287+ if (!file || !*file) file = c->nt->source_file;
288+ if (!file || !*file) file = "source.rb";
289+ snprintf(pos, sizeof pos, "%s:%d: ", file, ln);
290+ }
278291 const char *mname = ty && !strcmp(ty, "CallNode") ? nt_str(c->nt, id, "name") : NULL;
279292 if (mname) {
280293 int recv = nt_ref(c->nt, id, "receiver");
281294 int args = nt_ref(c->nt, id, "arguments");
282295 int ac = 0; const int *av = args >= 0 ? nt_arr(c->nt, args, "arguments", &ac) : NULL;
283- fprintf(stderr, "spinel: unsupported %s: node %d (%s `%s`) recv=%s/ty%d argc=%d",
284- what, id, ty, mname,
296+ fprintf(stderr, "spinel: %sunsupported %s: node %d (%s `%s`) recv=%s/ty%d argc=%d",
297+ pos, what, id, ty, mname,
285298 recv >= 0 ? nt_type(c->nt, recv) : "-",
286299 recv >= 0 ? (int)comp_ntype(c, recv) : -1, ac);
287300 if (ac > 0 && av) fprintf(stderr, " arg0ty%d", (int)comp_ntype(c, av[0]));
288301 fprintf(stderr, "\n");
289302 }
290303 else
291- fprintf(stderr, "spinel: unsupported %s: node %d (%s)\n",
292- what, id, ty ? ty : "?");
304+ fprintf(stderr, "spinel: %sunsupported %s: node %d (%s)\n",
305+ pos, what, id, ty ? ty : "?");
293306 /* SP_COLLECT_ERRORS: don't abort on the first gap -- keep going so one
294307 run surfaces every unsupported construct (the emitted C is then
295308 malformed and only the stderr list is useful). */