mirror of
https://github.com/dgibson/dtc.git
synced 2025-10-13 16:27:39 -04:00
annotations: add the annotation functionality
Provide the new command-line option: --annotate (abbreviated -T) --annotate provides one or more filenames and line numbers indicating the origin of a given line. The filename is expressed relative the the filename provided on the command line. Nothing is printed for overlays, etc. -T can be repeated giving more verbose annotations. These consist of one or more tuples of: filename, starting line, starting column, ending line ending column. The full path is given for the file name. Overlays, etc are annotated with <no-file>:<no-line>. The verbose annotations may be too verbose for normal use. There are numerous changes in srcpos.c to provide the relative filenames (variables initial_path, initial_pathlen and initial_cpp, new functions set_initial_path and shorten_to_initial_path, and changes in srcfile_push and srcpos_set_line). The change in srcpos_set_line takes care of the case where cpp is used as a preprocessor. In that case the initial file name is not the one provided on the command line but the one found at the beginnning of the cpp output. shorten_to_initial_path only returns a string if it has some shortening to do. Otherwise it returns NULL and relies on the caller to use the initial string. This simplifies memory management, by making clear to the caller whether a new string is allocated. The new functions srcpos_string_comment, srcpos_string_first, and srcpos_string_last print the annotations. srcpos_string_comment is recursive to print a list of source file positions. Various changes are sprinkled throughout treesource.c to print the annotations. Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
parent
8e20ccf52f
commit
5667e7ef9a
5 changed files with 170 additions and 10 deletions
46
treesource.c
46
treesource.c
|
@ -214,9 +214,18 @@ static void write_propval(FILE *f, struct property *prop)
|
|||
struct marker *m = prop->val.markers;
|
||||
struct marker dummy_marker;
|
||||
enum markertype emit_type = TYPE_NONE;
|
||||
char *srcstr;
|
||||
|
||||
if (len == 0) {
|
||||
fprintf(f, ";\n");
|
||||
fprintf(f, ";");
|
||||
if (annotate) {
|
||||
srcstr = srcpos_string_first(prop->srcpos, annotate);
|
||||
if (srcstr) {
|
||||
fprintf(f, " /* %s */", srcstr);
|
||||
free(srcstr);
|
||||
}
|
||||
}
|
||||
fprintf(f, "\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -273,7 +282,15 @@ static void write_propval(FILE *f, struct property *prop)
|
|||
emit_type = TYPE_NONE;
|
||||
}
|
||||
}
|
||||
fprintf(f, ";\n");
|
||||
fprintf(f, ";");
|
||||
if (annotate) {
|
||||
srcstr = srcpos_string_first(prop->srcpos, annotate);
|
||||
if (srcstr) {
|
||||
fprintf(f, " /* %s */", srcstr);
|
||||
free(srcstr);
|
||||
}
|
||||
}
|
||||
fprintf(f, "\n");
|
||||
}
|
||||
|
||||
static void write_tree_source_node(FILE *f, struct node *tree, int level)
|
||||
|
@ -281,14 +298,24 @@ static void write_tree_source_node(FILE *f, struct node *tree, int level)
|
|||
struct property *prop;
|
||||
struct node *child;
|
||||
struct label *l;
|
||||
char *srcstr;
|
||||
|
||||
write_prefix(f, level);
|
||||
for_each_label(tree->labels, l)
|
||||
fprintf(f, "%s: ", l->label);
|
||||
if (tree->name && (*tree->name))
|
||||
fprintf(f, "%s {\n", tree->name);
|
||||
fprintf(f, "%s {", tree->name);
|
||||
else
|
||||
fprintf(f, "/ {\n");
|
||||
fprintf(f, "/ {");
|
||||
|
||||
if (annotate) {
|
||||
srcstr = srcpos_string_first(tree->srcpos, annotate);
|
||||
if (srcstr) {
|
||||
fprintf(f, " /* %s */", srcstr);
|
||||
free(srcstr);
|
||||
}
|
||||
}
|
||||
fprintf(f, "\n");
|
||||
|
||||
for_each_property(tree, prop) {
|
||||
write_prefix(f, level+1);
|
||||
|
@ -302,10 +329,17 @@ static void write_tree_source_node(FILE *f, struct node *tree, int level)
|
|||
write_tree_source_node(f, child, level+1);
|
||||
}
|
||||
write_prefix(f, level);
|
||||
fprintf(f, "};\n");
|
||||
fprintf(f, "};");
|
||||
if (annotate) {
|
||||
srcstr = srcpos_string_last(tree->srcpos, annotate);
|
||||
if (srcstr) {
|
||||
fprintf(f, " /* %s */", srcstr);
|
||||
free(srcstr);
|
||||
}
|
||||
}
|
||||
fprintf(f, "\n");
|
||||
}
|
||||
|
||||
|
||||
void dt_to_source(FILE *f, struct dt_info *dti)
|
||||
{
|
||||
struct reserve_info *re;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue