aboutsummaryrefslogtreecommitdiffstats
path: root/symbol.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@home.transmeta.com>2003-03-13 18:10:50 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-07 20:59:15 -0700
commita9400ca17ec93398a39a69079f10f429d37de18b (patch)
tree2c721188234b441b53f7f15b8ad01168d1c14249 /symbol.c
parent24104678556e6d8cc7ff3f775dfdd42c21c9f995 (diff)
downloadsparse-a9400ca17ec93398a39a69079f10f429d37de18b.tar.gz
Start handling minimal semantic information, needed for types.
This adds a layer of symbol information on top of the raw tokens.
Diffstat (limited to 'symbol.c')
-rw-r--r--symbol.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/symbol.c b/symbol.c
new file mode 100644
index 00000000..ed09a167
--- /dev/null
+++ b/symbol.c
@@ -0,0 +1,33 @@
+#include <stdlib.h>
+#include "token.h"
+#include "symbol.h"
+
+struct symbol *alloc_symbol(struct token *token, int type)
+{
+ struct symbol *sym = malloc(sizeof(struct symbol));
+ struct ident *ident;
+
+ if (token->type != TOKEN_IDENT)
+ die("Internal error: trying to make a symbol out of a non-identifier");
+ ident = token->ident;
+ if (!sym)
+ die("out of memory for symbol information");
+ sym->token = token;
+ sym->next = ident->symbol;
+ sym->type = type;
+ ident->symbol = sym;
+ return sym;
+}
+
+struct symbol *create_symbol(int stream, const char *name, int type)
+{
+ return alloc_symbol(built_in_token(stream, name), type);
+}
+
+void init_symbols(void)
+{
+ int stream = init_stream("builtin");
+ struct symbol *sym;
+
+ sym = create_symbol(stream, "int", SYM_TYPEDEF);
+}