From b268bf59a6efbca460fef5bbd56f514df570a0bf Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Fri, 20 Dec 2019 23:44:05 -0500 Subject: switched to different ID system for identgs --- identifiers.c | 7 +++++-- types.h | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/identifiers.c b/identifiers.c index ef277e9..10aa82d 100644 --- a/identifiers.c +++ b/identifiers.c @@ -41,7 +41,7 @@ static Identifier ident_new(Identifiers *ids, Identifier parent, unsigned char i if (parent) tree->depth = (uint16_t)(parent->depth + 1); tree->index_in_parent = index_in_parent; - tree->id = block_arr_len(&ids->trees); + tree->id = 0; return tree; } @@ -49,6 +49,7 @@ static Identifier ident_new(Identifiers *ids, Identifier parent, unsigned char i static void idents_create(Identifiers *ids) { block_arr_create(&ids->trees, 10, sizeof(IdentTree)); /* blocks of 1 << 10 = 1024 */ ids->root = ident_new(ids, NULL, 0); /* create root tree */ + ids->nidents = 0; } #if CHAR_MIN < 0 @@ -70,6 +71,8 @@ static Identifier ident_insert(Identifiers *ids, char **s) { IdentTree *tree = ids->root; while (1) { if (!isident(**s)) { + if (!tree->id) + tree->id = ++ids->nidents; return tree; } int c = ident_char_to_uchar(**s); @@ -97,7 +100,7 @@ static void fprint_ident(FILE *out, Identifier id) { i = i->parent->parent; /* to go up one character, we need to go to the grandparent */ ++chars; } - printf("%lu:",(unsigned long)id->id); + printf("%lu-",(unsigned long)id->id); char *s = malloc(chars + 1); char *p = s + chars; i = id; diff --git a/types.h b/types.h index 015ec9a..91bc88b 100644 --- a/types.h +++ b/types.h @@ -173,7 +173,7 @@ typedef struct IdentTree { /* zero value is an empty trie */ uint16_t depth; unsigned char index_in_parent; /* index of this in .parent.children */ - U64 id; /* unique integer associated with this identifier - also index in Identifiers.trees */ + U64 id; /* 0 if there's no actual identifier here, otherwise unique positive integer associated with this identifier */ struct IdentTree *parent; struct IdentTree *children[TREE_NCHILDREN]; IdentDecl *decls; /* array of declarations of this identifier */ @@ -184,6 +184,7 @@ typedef IdentTree *Identifier; typedef struct Identifiers { BlockArr trees; IdentTree *root; + U64 nidents; } Identifiers; typedef enum { -- cgit v1.2.3