summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2019-12-20 23:44:05 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2019-12-20 23:44:05 -0500
commitb268bf59a6efbca460fef5bbd56f514df570a0bf (patch)
tree34a87d28d67236dc19c4afcd5c7b612586b95d46
parentf6fa7bba675f78365f7f31d44fb96b52b11dfa77 (diff)
switched to different ID system for identgs
-rw-r--r--identifiers.c7
-rw-r--r--types.h3
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 {