Chris Lattner | 633a5b1 | 2002-09-17 23:03:30 +0000 | [diff] [blame] | 1 | char rcsid_string[] = "$Id$"; |
| 2 | |
| 3 | #include <stdio.h> |
| 4 | #include <string.h> |
| 5 | #include "b.h" |
| 6 | #include "fe.h" |
| 7 | |
| 8 | static StrTableElement newStrTableElement ARGS((void)); |
| 9 | |
| 10 | StrTable |
| 11 | newStrTable() |
| 12 | { |
| 13 | return (StrTable) zalloc(sizeof(struct strTable)); |
| 14 | } |
| 15 | |
| 16 | static StrTableElement |
| 17 | newStrTableElement() |
| 18 | { |
| 19 | return (StrTableElement) zalloc(sizeof(struct strTableElement)); |
| 20 | } |
| 21 | |
| 22 | void |
| 23 | dumpStrTable(t) StrTable t; |
| 24 | { |
| 25 | List e; |
| 26 | IntList r; |
| 27 | |
| 28 | printf("Begin StrTable\n"); |
| 29 | for (e = t->elems; e; e = e->next) { |
| 30 | StrTableElement el = (StrTableElement) e->x; |
| 31 | printf("%s: ", el->str); |
| 32 | for (r = el->erulenos; r; r = r->next) { |
| 33 | int i = r->x; |
| 34 | printf("(%d)", i); |
| 35 | } |
| 36 | printf("\n"); |
| 37 | } |
| 38 | printf("End StrTable\n"); |
| 39 | } |
| 40 | |
| 41 | StrTableElement |
| 42 | addString(t, s, eruleno, new) StrTable t; char *s; int eruleno; int *new; |
| 43 | { |
| 44 | List l; |
| 45 | StrTableElement ste; |
| 46 | |
| 47 | assert(t); |
| 48 | for (l = t->elems; l; l = l->next) { |
| 49 | StrTableElement e = (StrTableElement) l->x; |
| 50 | |
| 51 | assert(e); |
| 52 | if (!strcmp(s, e->str)) { |
| 53 | e->erulenos = newIntList(eruleno, e->erulenos); |
| 54 | *new = 0; |
| 55 | return e; |
| 56 | } |
| 57 | } |
| 58 | ste = newStrTableElement(); |
| 59 | ste->erulenos = newIntList(eruleno, 0); |
| 60 | ste->str = (char *) zalloc(strlen(s) + 1); |
| 61 | strcpy(ste->str, s); |
| 62 | t->elems = newList(ste, t->elems); |
| 63 | *new = 1; |
| 64 | return ste; |
| 65 | } |