summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkugwa <kugwa2000@gmail.com>2015-10-21 15:39:27 +0800
committerkugwa <kugwa2000@gmail.com>2015-10-21 15:39:27 +0800
commit743795359c565ea59cd0f4f960075032c2b1b295 (patch)
tree016673936b3993baf3c8004671ba495321041d90
parente56bbe7525c971a4b918f815b1a572e7838f6b3c (diff)
downloadcompiler2015-743795359c565ea59cd0f4f960075032c2b1b295.tar
compiler2015-743795359c565ea59cd0f4f960075032c2b1b295.tar.gz
compiler2015-743795359c565ea59cd0f4f960075032c2b1b295.tar.bz2
compiler2015-743795359c565ea59cd0f4f960075032c2b1b295.tar.lz
compiler2015-743795359c565ea59cd0f4f960075032c2b1b295.tar.xz
compiler2015-743795359c565ea59cd0f4f960075032c2b1b295.tar.zst
compiler2015-743795359c565ea59cd0f4f960075032c2b1b295.zip
Change the usage of fillTab()
-rw-r--r--symbol-table.c17
-rw-r--r--symbol-table.h2
2 files changed, 16 insertions, 3 deletions
diff --git a/symbol-table.c b/symbol-table.c
index ca8dd3f..665c39c 100644
--- a/symbol-table.c
+++ b/symbol-table.c
@@ -83,18 +83,31 @@ void printSymTab(void) {
}
}
-int fillTab(symtab **tp) {
+symtab **fillTab(int *len) {
int cnt = 0;
for (int i = 0; i < TABLE_SIZE; i++)
{
symtab *symptr = hash_table[i];
while (symptr != NULL)
{
+ cnt++;
+ symptr = symptr->front;
+ }
+ }
+
+ symtab **tp = malloc(sizeof(symtab*)*cnt);
+ cnt = 0;
+ for (int i = 0; i < TABLE_SIZE; i++)
+ {
+ symtab *symptr = hash_table[i];
+ while (symptr != NULL)
+ {
tp[cnt++] = symptr;
symptr = symptr->front;
}
}
- return cnt;
+ *len = cnt;
+ return tp;
}
// vim: set sw=4 ts=4 sts=4 et:
diff --git a/symbol-table.h b/symbol-table.h
index c92986d..774b46c 100644
--- a/symbol-table.h
+++ b/symbol-table.h
@@ -10,6 +10,6 @@ typedef struct symtab symtab;
symtab* lookup(char *name);
void insertID(char *name);
void printSymTab(void);
-int fillTab(symtab **tp);
+symtab **fillTab(int *len);
// vim: set sw=4 ts=4 sts=4 et: