aboutsummaryrefslogtreecommitdiff
path: root/srcpos.c
diff options
context:
space:
mode:
authorJulia Lawall <Julia.Lawall@lip6.fr>2018-10-26 17:44:33 +0200
committerDavid Gibson <david@gibson.dropbear.id.au>2018-11-13 15:29:27 +1100
commitbaa1d2cf7894a32bf2f640ef40ebce561b2df565 (patch)
tree375454c91eef6ff64df067a1aef86896ae7dd09e /srcpos.c
parentff2ad38f6a5a87603c519096fd7066082c4c6f75 (diff)
downloaddtc-baa1d2cf7894a32bf2f640ef40ebce561b2df565.zip
dtc-baa1d2cf7894a32bf2f640ef40ebce561b2df565.tar.gz
dtc-baa1d2cf7894a32bf2f640ef40ebce561b2df565.tar.bz2
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. The srcpos type, define in srcpos.h, is now a list structure with a next field. 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 only updated in newly copied positions and the positions to which it points have also been copied. 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 cb6ed0e..cba1c0f 100644
--- a/srcpos.c
+++ b/srcpos.c
@@ -207,6 +207,7 @@ struct srcpos srcpos_empty = {
.last_line = 0,
.last_column = 0,
.file = NULL,
+ .next = NULL,
};
void srcpos_update(struct srcpos *pos, const char *text, int len)
@@ -234,13 +235,34 @@ 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));
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)
{