Mercurial > hg > index.cgi
annotate lwcc/symbol.c @ 304:d85d173ba120 ccdev
Checkpoint lwcc development - preprocessor is runnable but nonfunctional
The preprocessor is currently runnable but doesn't actually do anything
useful. This is just a checkpoint.
author | William Astle <lost@l-w.ca> |
---|---|
date | Tue, 17 Sep 2013 19:33:41 -0600 |
parents | 856caf91ffaa |
children | 54f213c8fb81 |
rev | line source |
---|---|
296 | 1 /* |
2 lwcc/symbol.c | |
3 | |
4 Copyright © 2013 William Astle | |
5 | |
6 This file is part of LWTOOLS. | |
7 | |
8 LWTOOLS is free software: you can redistribute it and/or modify it under the | |
9 terms of the GNU General Public License as published by the Free Software | |
10 Foundation, either version 3 of the License, or (at your option) any later | |
11 version. | |
12 | |
13 This program is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
16 more details. | |
17 | |
18 You should have received a copy of the GNU General Public License along with | |
19 this program. If not, see <http://www.gnu.org/licenses/>. | |
20 */ | |
21 | |
22 #include <string.h> | |
23 | |
24 #include <lw_alloc.h> | |
25 #include <lw_string.h> | |
26 | |
27 #include "cpp.h" | |
28 #include "symbol.h" | |
29 #include "token.h" | |
30 | |
31 void symbol_free(struct symtab_e *s) | |
32 { | |
33 int i; | |
299
856caf91ffaa
Added token list structure and switched some stuff to use it
William Astle <lost@l-w.ca>
parents:
296
diff
changeset
|
34 |
296 | 35 lw_free(s -> name); |
36 | |
37 for (i = 0; i < s -> nargs; i++) | |
38 lw_free(s -> params[i]); | |
39 lw_free(s -> params); | |
299
856caf91ffaa
Added token list structure and switched some stuff to use it
William Astle <lost@l-w.ca>
parents:
296
diff
changeset
|
40 token_list_destroy(s -> tl); |
296 | 41 } |
42 | |
43 struct symtab_e *symtab_find(struct preproc_info *pp, char *name) | |
44 { | |
45 struct symtab_e *s; | |
46 | |
47 for (s = pp -> sh; s; s = s -> next) | |
48 { | |
49 if (strcmp(s -> name, name) == 0) | |
50 { | |
51 return s; | |
52 } | |
53 } | |
54 return NULL; | |
55 } | |
56 | |
57 void symtab_undef(struct preproc_info *pp, char *name) | |
58 { | |
59 struct symtab_e *s, **p; | |
60 | |
61 p = &(pp -> sh); | |
62 for (s = pp -> sh; s; s = s -> next) | |
63 { | |
64 if (strcmp(s -> name, name) == 0) | |
65 { | |
66 (*p) -> next = s -> next; | |
67 symbol_free(s); | |
68 return; | |
69 } | |
70 p = &((*p) -> next); | |
71 } | |
72 } | |
73 | |
299
856caf91ffaa
Added token list structure and switched some stuff to use it
William Astle <lost@l-w.ca>
parents:
296
diff
changeset
|
74 void symtab_define(struct preproc_info *pp, char *name, struct token_list *def, int nargs, char **params, int vargs) |
296 | 75 { |
76 struct symtab_e *s; | |
77 | |
78 s = lw_alloc(sizeof(struct symtab_e)); | |
79 s -> name = lw_strdup(name); | |
80 s -> tl = def; | |
81 s -> nargs = nargs; | |
82 s -> params = params; | |
83 s -> vargs = vargs; | |
84 s -> next = pp -> sh; | |
85 pp -> sh = s; | |
86 } |