added depth management
This commit is contained in:
parent
2d954f1a29
commit
7fafcbbd7d
2 changed files with 16 additions and 4 deletions
15
table.c
15
table.c
|
@ -46,7 +46,7 @@ int getIndex(char* name){
|
|||
void clearOutOfScopeVariable(){
|
||||
for(int i=0; i < currentIndex; i++){
|
||||
if (symbolTable[i].depth == currentDepth){
|
||||
suppressElement(symbolTable[i]);
|
||||
suppressElement(i);
|
||||
}
|
||||
}
|
||||
error("No index found");
|
||||
|
@ -97,8 +97,8 @@ int initOffset(int index){
|
|||
|
||||
|
||||
/* Removes an element */
|
||||
void suppressElement(Symbol element){
|
||||
for(int i = getIndex(element.name); i < (currentIndex - 1); i ++){
|
||||
void suppressElement(int index){
|
||||
for(int i = index; i < (currentIndex - 1); i ++){
|
||||
symbolTable[i] = symbolTable[i+1];
|
||||
}
|
||||
currentIndex --;
|
||||
|
@ -130,4 +130,13 @@ void reallocateArray(int size){
|
|||
}
|
||||
|
||||
symbolTable = newSymbolTable;
|
||||
}
|
||||
|
||||
void increaseDepth(){
|
||||
currentDepth++;
|
||||
}
|
||||
|
||||
void decreaseDepth(){
|
||||
clearOutOfScopeVariable();
|
||||
currentDepth--;
|
||||
}
|
5
table.h
5
table.h
|
@ -31,7 +31,7 @@ typedef struct {
|
|||
|
||||
void reallocateArray(int size);
|
||||
void checkArraySanity();
|
||||
void suppressElement(Symbol element);
|
||||
void suppressElement(int index);
|
||||
int initOffset(int index);
|
||||
void addElement(Symbol element);
|
||||
void toggleInit(char *name);
|
||||
|
@ -39,5 +39,8 @@ int getIndex(char* name);
|
|||
Symbol getStruct(char* name);
|
||||
void error(char* mess);
|
||||
int getOffset(char* name);
|
||||
void clearOutOfScopeVariable();
|
||||
void increaseDepth();
|
||||
void decreaseDepth();
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue