/* Install all local declarations (identifiers) present in a function into that function's local symbol table */ void localInstall(Tnode *root,struct Lsymbol **Lhead) { struct Lsymbol *lnode; if(root == NULL) return; switch(root->NODETYPE) { case CONTINUE : localInstall(root->Ptr1,Lhead); localInstall(root->Ptr2,Lhead); break; case DECLSTATEMENT : decnode = root->Ptr1; localInstall(root->Ptr2,Lhead); break; case IDFRDECL : lnode = Llookup(root->NAME,Lhead); if(lnode != NULL) { if(root->TYPE != lnode->TYPE) printf("\nSIL:%d: Error: conflicting types for '%s'",root->LINE,root->NAME); else printf("\nSIL:%d: Error: redeclaration of '%s'",root->LINE,root->NAME); error++; } else Linstall(root->NAME,decnode->TYPE,Lhead); break; } }
struct ArgStruct *Arginstall(char* name,int type,int passType){ struct ArgStruct *temp; temp = (struct ArgStruct *)malloc(sizeof(struct ArgStruct)); temp->name = (char *)malloc(sizeof(name)); strcpy(temp->name,name); temp->type = type; temp->passType = passType; temp->next = NULL; if(type == STYPE_INT){ if(passType == PTYPE_REF) Linstall(name,ARG_REF_INT); else if(passType == PTYPE_VAL) Linstall(name,ARG_INT); } else if(type == STYPE_BOOLEAN){ if(passType == PTYPE_REF) Linstall(name,ARG_REF_BOOLEAN); else if(passType == PTYPE_VAL) Linstall(name,ARG_BOOLEAN); } else if(type == STYPE_PAIR){ if(passType == PTYPE_REF) Linstall(name,ARG_REF_PAIR); else if(passType == PTYPE_VAL) Linstall(name,ARG_PAIR); } return temp; }
/* Installs function arguments into that function's local symbol table (with semantic checking) */ void argLocalInstall(Tnode *root,struct Lsymbol **Lhead) { struct Lsymbol *lnode; ArgStruct *arg; char typ[10]; if(root == NULL) return; switch(root->NODETYPE) { case CONTINUE : argLocalInstall(root->Ptr1,Lhead); argLocalInstall(root->Ptr2,Lhead); break; case ARGSTATEMENT : argnode = root->Ptr1; argLocalInstall(root->Ptr2,Lhead); break; case IDALIASARG : case IDARG : lnode = Llookup(root->NAME,Lhead); if(lnode != NULL) { if(argnode->TYPE != lnode->TYPE) printf("\nSIL:%d: Error: conflicting types for '%s'",root->LINE,root->NAME); else printf("\nSIL:%d: Error: redefinition of parameter '%s'",root->LINE,root->NAME); error++; } else Linstall(root->NAME,argnode->TYPE,Lhead); break; } }