summaryrefslogtreecommitdiff
path: root/srcpos.c
diff options
context:
space:
mode:
authorJulia Lawall <Julia.Lawall@lip6.fr>2018-11-16 17:29:59 +0100
committerDavid Gibson <david@gibson.dropbear.id.au>2018-11-19 11:06:20 +1100
commit8e20ccf52f90ed7e5ee29f870c7ee8bd0854794c (patch)
treeee95557a960d33ddd47d037d03bf6265372cb2e6 /srcpos.c
parentca930e20bb54d823a90598f1f861a76bd18bc7c7 (diff)
downloaddevice-tree-compiler-8e20ccf52f90ed7e5ee29f870c7ee8bd0854794c.tar.gz
annotations: add positions
Extend the parser to record positions, in build_node, build_node_delete, and build_property. srcpos structures are added to the property and node types, and to the parameter lists of the above functions that construct these types. Nodes and properties that are created by the compiler rather than from parsing source code have NULL as the srcpos value. merge_nodes, defined in livetree.c, uses srcpos_extend to combine multiple positions, resulting in a list of positions. srcpos_extend is defined in srcpos.c. New elements are added at the end. This requires the srcpos type, define in srcpos.h, to be a list structure with a next field. This next field is initialized to NULL in srcpos.h, in the macro YYLLOC_DEFAULT invoked implicitly by the generated parser code. Another change to srcpos.c is to make srcpos_copy always do a full copy, including a copy of the file substructure. This is required because when dtc is used on the output of cpp, the successive detected file names overwrite the file name in the file structure. The next field does not need to be deep copied, because it is always NULL when srcpos_copy is called; an assert checks for this. File names are only updated in uncopied position structures. Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'srcpos.c')
-rw-r--r--srcpos.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/srcpos.c b/srcpos.c
index ea82d88..77b50c9 100644
--- a/srcpos.c
+++ b/srcpos.c
@@ -222,13 +222,35 @@ struct srcpos *
srcpos_copy(struct srcpos *pos)
{
struct srcpos *pos_new;
+ struct srcfile_state *srcfile_state;
+
+ if (!pos)
+ return NULL;
pos_new = xmalloc(sizeof(struct srcpos));
+ assert(pos->next == NULL);
memcpy(pos_new, pos, sizeof(struct srcpos));
+ /* allocate without free */
+ srcfile_state = xmalloc(sizeof(struct srcfile_state));
+ memcpy(srcfile_state, pos->file, sizeof(struct srcfile_state));
+ pos_new->file = srcfile_state;
+
return pos_new;
}
+struct srcpos *srcpos_extend(struct srcpos *pos, struct srcpos *newtail)
+{
+ struct srcpos *p;
+
+ if (!pos)
+ return newtail;
+
+ for (p = pos; p->next != NULL; p = p->next);
+ p->next = newtail;
+ return pos;
+}
+
char *
srcpos_string(struct srcpos *pos)
{