Skip to content

Commit

Permalink
add extra annotate
Browse files Browse the repository at this point in the history
* add comment "/* __[|>*DELETED*<|]__ */" for
  deteled nodes, labels and properties
* comment deleted nodes, labels and properties
  • Loading branch information
bmx666 committed Dec 23, 2021
1 parent 17739b7 commit b10c3f0
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 14 deletions.
4 changes: 2 additions & 2 deletions dtc-parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ devicetree:
struct node *target = get_node_by_ref($1, $3);

if (target)
delete_node(target);
delete_node_by_name(target->parent, target->name, &@$);

This comment has been minimized.

Copy link
@dgibson

dgibson Dec 28, 2021

It's not obvious to me why this has to change to a delete_node_by_name as well as adding the srcpos argument.

This comment has been minimized.

Copy link
@bmx666

bmx666 Jan 5, 2022

Author Owner

It's can help trace dts-file where /delete-node/ was called, to generate full list of files which related to this node

else
ERROR(&@3, "Label or path %s not found", $3);

Expand Down Expand Up @@ -278,7 +278,7 @@ propdef:
}
| DT_DEL_PROP DT_PROPNODENAME ';'
{
$$ = build_property_delete($2);
$$ = build_property_delete($2, &@$);
}
| DT_LABEL propdef
{
Expand Down
5 changes: 4 additions & 1 deletion dtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ static const char * const usage_opts_help[] = {
"\n\tEnable/disable errors (prefix with \"no-\")",
"\n\tEnable generation of symbols",
"\n\tEnable auto-alias of labels",
"\n\tAnnotate output .dts with input source file and line (-T -T for more details)",
"\n\tAnnotate output .dts with input source file and line (-T -T for more details)\n"

This comment has been minimized.

Copy link
@dgibson

dgibson Dec 28, 2021

Convention here is to put the \n at the beginning of the next line, rather than the end.

This comment has been minimized.

Copy link
@bmx666

bmx666 Jan 5, 2022

Author Owner

I'm not sure what are you talking about...I did same as above

	"\n\tValid phandle formats are:\n"
	 "\t\tlegacy - \"linux,phandle\" properties only\n"
	 "\t\tepapr  - \"phandle\" properties only\n"
	 "\t\tboth   - Both \"linux,phandle\" and \"phandle\" properties",
"\t-T -T -T - annotate property with all sources\n"

This comment has been minimized.

Copy link
@dgibson

dgibson Dec 28, 2021

It's not really clear to me what this means. It you're adding more levels here, it would also be good to say what -T -T does more clearly than "more details".

This comment has been minimized.

Copy link
@bmx666

bmx666 Jan 5, 2022

Author Owner

I created pull-request to remove -T -T -T -> dgibson#67
I still working on refactoring annotation > X conditions. Also I'm not using -T -T -T -T anymore, so I decided to abandon it and left only -T -T -T -T -T but represent it in different way.

"\t-T -T -T -T - annotate deleted nodes and properties\n"
"\t-T -T -T -T -T - annotate childs of deleted nodes",
"\n\tPrint this help and exit",
"\n\tPrint version and exit",
NULL,
Expand Down
10 changes: 8 additions & 2 deletions dtc.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ bool data_is_one_string(struct data d);
/* Live trees */
struct label {
bool deleted;
bool was_deleted;
char *label;
struct label *next;
};
Expand All @@ -205,6 +206,7 @@ struct bus_type {

struct property {
bool deleted;
bool was_deleted;
char *name;
struct data val;

Expand All @@ -216,6 +218,7 @@ struct property {

struct node {
bool deleted;
bool was_deleted;
char *name;
struct property *proplist;
struct node *children;
Expand Down Expand Up @@ -262,7 +265,7 @@ void delete_labels(struct label **labels);

struct property *build_property(char *name, struct data val,
struct srcpos *srcpos);
struct property *build_property_delete(char *name);
struct property *build_property_delete(char *name, struct srcpos *srcpos);
struct property *chain_property(struct property *first, struct property *list);
struct property *reverse_properties(struct property *first);

Expand All @@ -280,7 +283,7 @@ void add_property(struct node *node, struct property *prop);
void delete_property_by_name(struct node *node, char *name);
void delete_property(struct property *prop);
void add_child(struct node *parent, struct node *child);
void delete_node_by_name(struct node *parent, char *name);
void delete_node_by_name(struct node *parent, char *name, struct srcpos *srcpos);
void delete_node(struct node *node);
void append_to_property(struct node *node,
char *name, const void *data, int len,
Expand Down Expand Up @@ -365,4 +368,7 @@ void dt_to_yaml(FILE *f, struct dt_info *dti);

struct dt_info *dt_from_fs(const char *dirname);

/* mark deleted properties and nodes */
#define DELETED_TAG "__[|>*DELETED*<|]__"

#endif /* DTC_H */
69 changes: 60 additions & 9 deletions livetree.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "dtc.h"
#include "srcpos.h"

static struct node *build_and_name_child_node(struct node *parent, char *name);

/*
* Tree building functions
*/
Expand Down Expand Up @@ -50,14 +52,19 @@ struct property *build_property(char *name, struct data val,
return new;
}

struct property *build_property_delete(char *name)
struct property *build_property_delete(char *name,
struct srcpos *srcpos)
{
struct property *new = xmalloc(sizeof(*new));

memset(new, 0, sizeof(*new));

new->name = name;
new->deleted = 1;
if (annotate > 3) {

This comment has been minimized.

Copy link
@dgibson

dgibson Dec 28, 2021

What information you store shouldn't depend on the annotation level - only what information you print.

new->was_deleted = 1;
new->srcpos = srcpos_copy(srcpos);
}

return new;
}
Expand Down Expand Up @@ -112,6 +119,9 @@ struct node *build_node_delete(struct srcpos *srcpos)

new->deleted = 1;
new->srcpos = srcpos_copy(srcpos);
if (annotate > 3) {
new->was_deleted = 1;
}

return new;
}
Expand Down Expand Up @@ -159,7 +169,7 @@ struct node *merge_nodes(struct node *old_node, struct node *new_node)
new_node->proplist = new_prop->next;
new_prop->next = NULL;

if (new_prop->deleted) {
if (new_prop->deleted && annotate <= 3) {
delete_property_by_name(old_node, new_prop->name);
free(new_prop);
continue;
Expand All @@ -173,9 +183,19 @@ struct node *merge_nodes(struct node *old_node, struct node *new_node)
add_label(&old_prop->labels, l->label);

old_prop->val = new_prop->val;
old_prop->deleted = 0;
free(old_prop->srcpos);
old_prop->srcpos = new_prop->srcpos;

if (annotate > 3)
old_prop->was_deleted = new_prop->deleted;
else
old_prop->deleted = 0;

if (annotate > 2) {
old_prop->srcpos = srcpos_extend(old_prop->srcpos, new_prop->srcpos);
} else {
free(old_prop->srcpos);
old_prop->srcpos = new_prop->srcpos;
}

free(new_prop);
new_prop = NULL;
break;
Expand All @@ -197,7 +217,7 @@ struct node *merge_nodes(struct node *old_node, struct node *new_node)
new_child->next_sibling = NULL;

if (new_child->deleted) {
delete_node_by_name(old_node, new_child->name);
delete_node_by_name(old_node, new_child->name, new_child->srcpos);
free(new_child);
continue;
}
Expand All @@ -217,6 +237,8 @@ struct node *merge_nodes(struct node *old_node, struct node *new_node)
}

old_node->srcpos = srcpos_extend(old_node->srcpos, new_node->srcpos);
if (old_node->was_deleted && !new_node->was_deleted)
old_node->was_deleted = 0;

/* The new node contents are now merged into the old node. Free
* the new node. */
Expand Down Expand Up @@ -293,6 +315,11 @@ void delete_property(struct property *prop)
{
prop->deleted = 1;
delete_labels(&prop->labels);
if (annotate > 3) {
prop->was_deleted = 1;
if (annotate > 4)
prop->deleted = 0;
}
}

void add_child(struct node *parent, struct node *child)
Expand All @@ -309,13 +336,28 @@ void add_child(struct node *parent, struct node *child)
*p = child;
}

void delete_node_by_name(struct node *parent, char *name)
void delete_node_by_name(struct node *parent, char *name, struct srcpos *srcpos)
{
struct node *node = parent->children;
struct srcpos *pos = NULL;

while (node) {
if (streq(node->name, name)) {

if (annotate > 3) {
srcpos->first_line = srcpos->last_line;
pos = srcpos_copy(srcpos);
pos = srcpos_extend(node->srcpos, pos);
}

delete_node(node);

if (annotate == 4) {
node = build_and_name_child_node(parent, name);
node->srcpos = pos;
node->was_deleted = 1;
}

return;
}
node = node->next_sibling;
Expand All @@ -328,6 +370,11 @@ void delete_node(struct node *node)
struct node *child;

node->deleted = 1;
if (annotate > 3) {
node->was_deleted = 1;
if (annotate > 4)
node->deleted = 0;
}
for_each_child(node, child)
delete_node(child);
for_each_property(node, prop)
Expand Down Expand Up @@ -605,11 +652,11 @@ cell_t get_node_phandle(struct node *root, struct node *node)
d = data_add_marker(d, TYPE_UINT32, NULL);
d = data_append_cell(d, phandle);

if (!get_property(node, "linux,phandle")
if (!get_property(node, "linux,phandle") && !node->was_deleted

This comment has been minimized.

Copy link
@dgibson

dgibson Dec 28, 2021

How does checking node->was_deleted differ from checking node->deleted?

This comment has been minimized.

Copy link
@bmx666

bmx666 Jan 5, 2022

Author Owner

because it's not easy avoid direct logic implemented for deleted flag, especially in merge_node in livetree.c to remove old node including child nodes and properties. My goal was re-create full chain from beginning to the end, because same node can be removed and re-created multiple times and same node can include same property which was deleted, but added later. So was_deleted helps me avoid refactoring whole implemented logic and put mark on deleted nodes without touching them and in final process when write to file or stdout filter them out.

&& (phandle_format & PHANDLE_LEGACY))
add_property(node, build_property("linux,phandle", d, NULL));

if (!get_property(node, "phandle")
if (!get_property(node, "phandle") && !node->was_deleted
&& (phandle_format & PHANDLE_EPAPR))
add_property(node, build_property("phandle", d, NULL));

Expand Down Expand Up @@ -849,6 +896,10 @@ static void generate_label_tree_internal(struct dt_info *dti,
data_copy_escape_string(node->fullpath,
strlen(node->fullpath)),
NULL);

if (annotate > 4)
p->was_deleted = l->was_deleted;

add_property(an, p);
}

Expand Down
14 changes: 14 additions & 0 deletions treesource.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ static void write_propval(FILE *f, struct property *prop)
if (len == 0) {
fprintf(f, ";");
if (annotate) {
if (annotate > 3 && prop->was_deleted)

This comment has been minimized.

Copy link
@dgibson

dgibson Dec 28, 2021

Again, how does this differ from checking prop->deleted?

fprintf(f, "*/");
srcstr = srcpos_string_first(prop->srcpos, annotate);
if (srcstr) {
fprintf(f, " /* %s */", srcstr);
Expand Down Expand Up @@ -261,6 +263,8 @@ static void write_propval(FILE *f, struct property *prop)
}
fprintf(f, ";");
if (annotate) {
if (annotate > 3 && prop->was_deleted)
fprintf(f, "*/");
srcstr = srcpos_string_first(prop->srcpos, annotate);
if (srcstr) {
fprintf(f, " /* %s */", srcstr);
Expand All @@ -278,6 +282,8 @@ static void write_tree_source_node(FILE *f, struct node *tree, int level)
char *srcstr;

write_prefix(f, level);
if (annotate > 3 && tree->was_deleted)
fprintf(f, "/* %s */ /*", DELETED_TAG);
for_each_label(tree->labels, l)
fprintf(f, "%s: ", l->label);
if (tree->name && (*tree->name))
Expand All @@ -286,6 +292,8 @@ static void write_tree_source_node(FILE *f, struct node *tree, int level)
fprintf(f, "/ {");

if (annotate) {
if (annotate > 3 && tree->was_deleted)
fprintf(f, "*/");
srcstr = srcpos_string_first(tree->srcpos, annotate);
if (srcstr) {
fprintf(f, " /* %s */", srcstr);
Expand All @@ -296,6 +304,8 @@ static void write_tree_source_node(FILE *f, struct node *tree, int level)

for_each_property(tree, prop) {
write_prefix(f, level+1);
if (annotate > 3 && prop->was_deleted)
fprintf(f, "/* %s */ /*", DELETED_TAG);
for_each_label(prop->labels, l)
fprintf(f, "%s: ", l->label);
fprintf(f, "%s", prop->name);
Expand All @@ -306,7 +316,11 @@ 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);
if (annotate > 3 && tree->was_deleted)
fprintf(f, "/* %s */ /*", DELETED_TAG);
fprintf(f, "};");
if (annotate > 3 && tree->was_deleted)
fprintf(f, "*/");
if (annotate) {
srcstr = srcpos_string_last(tree->srcpos, annotate);
if (srcstr) {
Expand Down

0 comments on commit b10c3f0

Please sign in to comment.