struct macro_source_file * macro_lookup_inclusion (struct macro_source_file *source, const char *name) { /* Is SOURCE itself named NAME? */ if (filename_cmp (name, source->filename) == 0) return source; /* It's not us. Try all our children, and return the lowest. */ { struct macro_source_file *child; struct macro_source_file *best = NULL; int best_depth = 0; for (child = source->includes; child; child = child->next_included) { struct macro_source_file *result = macro_lookup_inclusion (child, name); if (result) { int result_depth = inclusion_depth (result); if (! best || result_depth < best_depth) { best = result; best_depth = result_depth; } } } return best; } }
struct macro_scope * sal_macro_scope (struct symtab_and_line sal) { struct macro_source_file *main; struct macro_scope *ms; if (! sal.symtab || ! sal.symtab->macro_table) return 0; ms = (struct macro_scope *) xmalloc (sizeof (*ms)); main = macro_main (sal.symtab->macro_table); ms->file = macro_lookup_inclusion (main, sal.symtab->filename); if (! ms->file) internal_error (__FILE__, __LINE__, "\n" "the symtab `%s' refers to a preprocessor macro table which doesn't\n" "have any record of processing a file by that name.\n", sal.symtab->filename); ms->line = sal.line; return ms; }
struct macro_scope * sal_macro_scope (struct symtab_and_line sal) { struct macro_source_file *main_file, *inclusion; struct macro_scope *ms; struct compunit_symtab *cust; if (sal.symtab == NULL) return NULL; cust = SYMTAB_COMPUNIT (sal.symtab); if (COMPUNIT_MACRO_TABLE (cust) == NULL) return NULL; ms = XNEW (struct macro_scope); main_file = macro_main (COMPUNIT_MACRO_TABLE (cust)); inclusion = macro_lookup_inclusion (main_file, sal.symtab->filename); if (inclusion) { ms->file = inclusion; ms->line = sal.line; } else { /* There are, unfortunately, cases where a compilation unit can have a symtab for a source file that doesn't appear in the macro table. For example, at the moment, Dwarf doesn't have any way in the .debug_macinfo section to describe the effect of #line directives, so if you debug a YACC parser you'll get a macro table which only mentions the .c files generated by YACC, but symtabs that mention the .y files consumed by YACC. In the long run, we should extend the Dwarf macro info representation to handle #line directives, and get GCC to emit it. For the time being, though, we'll just treat these as occurring at the end of the main source file. */ ms->file = main_file; ms->line = -1; complaint (&symfile_complaints, _("symtab found for `%s', but that file\n" "is not covered in the compilation unit's macro information"), symtab_to_filename_for_display (sal.symtab)); } return ms; }