aboutsummaryrefslogtreecommitdiff
path: root/semantics.h
diff options
context:
space:
mode:
Diffstat (limited to 'semantics.h')
-rw-r--r--semantics.h38
1 files changed, 25 insertions, 13 deletions
diff --git a/semantics.h b/semantics.h
index 59a7a81..b3d2942 100644
--- a/semantics.h
+++ b/semantics.h
@@ -9,23 +9,37 @@ typedef struct CVar{
char *name;
struct CVar *next; /* next in the linked list */
struct CType *type;
- int ref_lvl; /* reference level: >0 for pointers */
int offset;
} CVar;
typedef struct CType {
+ enum {
+ INT,
+ CHAR,
+ VOID,
+ STRUCT,
+ UNION,
+ ARR,
+ PTR
+ } type;
char *name;
struct CType *next;
- struct CType *fields; /* for a struct or union */
+ union {
+ struct CType *fields; /* for a struct or union */
+ struct CType *ref; /* for a pointer */
+ struct {
+ struct CType *elem;
+ int len;
+ } arr; /* for an array */
+ } rec;
int size; /* memory footprint */
} CType;
-typedef int (*Cmp_t)(void *, void *);
-typedef unsigned int (*Hashfunc_t) (char *);
+typedef unsigned int (*Hashfunc_t) (const char *);
typedef struct CTable *CTable_t;
typedef struct CTNode {
- char *key;
+ const char *key;
void *val;
struct CTNode *next;
int lvl;
@@ -33,14 +47,13 @@ typedef struct CTNode {
typedef struct CTable {
struct CTNode *head[MAX_TABLE_SIZE];
- Cmp_t cmp;
Hashfunc_t hfunc;
} CTable;
-CTable_t ctable_create(Cmp_t cmp, Hashfunc_t hfunc);
-void *ctable_lookup(CTable_t ct, char *key);
-void ctable_insert(CTable_t ct, char *key, void *val, int lvl);
+CTable_t ctable_create(Hashfunc_t hfunc);
+void *ctable_lookup(CTable_t ct, const char *key);
+void ctable_insert(CTable_t ct, const char *key, void *val, int lvl);
void ctable_clip(CTable_t ct, unsigned int hv, int max_lvl);
typedef struct CSNode {
@@ -58,13 +71,12 @@ typedef struct CScope {
} CScope;
CScope_t cscope_create();
-CVar *cscope_lookup_var(CScope_t cs, char *name);
-CType *cscope_lookup_type(CScope_t cs, char *name);
+CVar *cscope_lookup_var(CScope_t cs, const char *name);
+CType *cscope_lookup_type(CScope_t cs, const char *name);
void cscope_push_var(CScope_t cs, CVar *var);
void cscope_push_type(CScope_t cs, CType *type);
void cscope_enter(CScope_t cs);
void cscope_exit(CScope_t cs);
-Cmp_t var_cmp, type_cmp;
-Hashfunc_t var_hfunc, type_hfunc;
+unsigned int bkdr_hash(const char *str);
#endif