ag: namen geaendert und debug meldung fix
[uebersetzerbau-ss10.git] / ag / symtable.c
index 7242f0684ebf51eefb9ba9fc2cda816114f3e73d..8c175e5e0421d1e15cd31e1c81f50fe560dc4402 100755 (executable)
@@ -3,6 +3,8 @@
 #include <stdio.h>
 #include "symtable.h"
 
+#define DD
+
 struct symbol *new_tab(void)
 {
        return SYMNULL;
@@ -12,6 +14,9 @@ struct symbol *clone_tab(struct symbol *tab)
 {
        struct symbol *elm;
        struct symbol *new_tabx;
+#ifdef DD
+       printf("clone_tab: tab(%08X)\n", tab);
+#endif
 
        elm = tab;
        new_tabx = new_tab();
@@ -27,13 +32,16 @@ struct symbol *tab_add_symbol(struct symbol *tab, char *ident, short type, short
 {
        struct symbol *elm;
        struct symbol *new_elm;
+#ifdef DD
+       printf("tab_add_symbol: tab(%08X), ident(%s), type(%i), check(%i)\n", tab, ident, type, check);
+#endif
 
-       if(tab_lookup(tab, ident) != SYMNULL) {
+       if(tab_lookup(tab, ident, type) != SYMNULL) {
                if(check) {
-                       fprintf(stderr, "Feld doppelt vorhanden: \"%s\"\n", ident);
+                       fprintf(stderr, "Identifier doppelt vorhanden: \"%s\"\n", ident);
                        exit(3);
                } else {
-                       tab = tab_remove_symbol(tab, ident);
+                       tab = tab_remove_symbol(tab, ident, type);
                }
        }
        
@@ -55,7 +63,7 @@ struct symbol *tab_add_symbol(struct symbol *tab, char *ident, short type, short
        return tab;
 }
 
-struct symbol *tab_lookup(struct symbol *tab, char *ident)
+struct symbol *tab_lookup(struct symbol *tab, char *ident, short type)
 {
        struct symbol *elm = tab;
 
@@ -64,7 +72,7 @@ struct symbol *tab_lookup(struct symbol *tab, char *ident)
        }
 
        do {
-               if(strcmp(elm->ident, ident) == 0) {
+               if((elm->type == type) && (strcmp(elm->ident, ident) == 0)) {
                        return elm;
                }
                elm = elm->next;
@@ -77,6 +85,9 @@ struct symbol *tab_merge(struct symbol *tab, struct symbol *to_add, short check)
 {
        struct symbol *elm = to_add;
        struct symbol *new_tab = clone_tab(tab);
+#ifdef DD
+       printf("tab_merge: tab(%08X), to_add(%08X), check(%i), new_tab(%08X)\n", tab, to_add, check, new_tab);
+#endif
        
        while(elm != SYMNULL) {
                new_tab = tab_add_symbol(new_tab, elm->ident, elm->type, check);
@@ -86,13 +97,13 @@ struct symbol *tab_merge(struct symbol *tab, struct symbol *to_add, short check)
        return new_tab;
 }
 
-struct symbol *tab_remove_symbol(struct symbol *tab, char *ident)
+struct symbol *tab_remove_symbol(struct symbol *tab, char *ident, short type)
 {
        struct symbol *elm = tab;
        struct symbol *previous_elm = SYMNULL;
 
        while(elm != SYMNULL) {
-               if(strcmp(elm->ident, ident) == 0) {
+               if((elm->type == type) && (strcmp(elm->ident, ident) == 0)) {
                        if(previous_elm == SYMNULL) {
                                tab = elm->next;
                        } else {
@@ -109,29 +120,22 @@ struct symbol *tab_remove_symbol(struct symbol *tab, char *ident)
        return tab;
 }
 
-void check_variable(struct symbol *tab, char *ident)
+void check(struct symbol *tab, char *ident, short type)
 {
-       struct symbol *elm = tab_lookup(tab, ident);
-       if(elm != SYMNULL) {
-               if(elm->type != S_VAR) {
-                       fprintf(stderr, "Identifier ist keine Variable: \"%s\"\n", ident);
-                       exit(3);
+       struct symbol *elm;
+#ifdef DD
+       printf("check: tab(%08X), ident(%s), type(%i), elm(%08X)\n", tab, ident, type, elm);
+#endif
+
+       if(type == S_VAR) {
+               elm = tab_lookup(tab, ident, type);
+               if(elm != SYMNULL) {
+                       return;
                }
-       } else {
-               fprintf(stderr, "Unbekannter Identifier: \"%s\"\n", ident);
-               exit(3);
        }
-}
 
-void check_field(struct symbol *tab, char *ident)
-{
-       struct symbol *elm = tab_lookup(tab, ident);
-       if(elm != SYMNULL) {
-               if(elm->type != S_FIELD) {
-                       fprintf(stderr, "Identifier ist kein Feld: \"%s\"\n", ident);
-                       exit(3);
-               }
-       } else {
+       elm = tab_lookup(tab, ident, S_FIELD);
+       if(elm == SYMNULL) {
                fprintf(stderr, "Unbekannter Identifier: \"%s\"\n", ident);
                exit(3);
        }