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(){
|
void clearOutOfScopeVariable(){
|
||||||
for(int i=0; i < currentIndex; i++){
|
for(int i=0; i < currentIndex; i++){
|
||||||
if (symbolTable[i].depth == currentDepth){
|
if (symbolTable[i].depth == currentDepth){
|
||||||
suppressElement(symbolTable[i]);
|
suppressElement(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
error("No index found");
|
error("No index found");
|
||||||
|
@ -97,8 +97,8 @@ int initOffset(int index){
|
||||||
|
|
||||||
|
|
||||||
/* Removes an element */
|
/* Removes an element */
|
||||||
void suppressElement(Symbol element){
|
void suppressElement(int index){
|
||||||
for(int i = getIndex(element.name); i < (currentIndex - 1); i ++){
|
for(int i = index; i < (currentIndex - 1); i ++){
|
||||||
symbolTable[i] = symbolTable[i+1];
|
symbolTable[i] = symbolTable[i+1];
|
||||||
}
|
}
|
||||||
currentIndex --;
|
currentIndex --;
|
||||||
|
@ -131,3 +131,12 @@ void reallocateArray(int size){
|
||||||
|
|
||||||
symbolTable = newSymbolTable;
|
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 reallocateArray(int size);
|
||||||
void checkArraySanity();
|
void checkArraySanity();
|
||||||
void suppressElement(Symbol element);
|
void suppressElement(int index);
|
||||||
int initOffset(int index);
|
int initOffset(int index);
|
||||||
void addElement(Symbol element);
|
void addElement(Symbol element);
|
||||||
void toggleInit(char *name);
|
void toggleInit(char *name);
|
||||||
|
@ -39,5 +39,8 @@ int getIndex(char* name);
|
||||||
Symbol getStruct(char* name);
|
Symbol getStruct(char* name);
|
||||||
void error(char* mess);
|
void error(char* mess);
|
||||||
int getOffset(char* name);
|
int getOffset(char* name);
|
||||||
|
void clearOutOfScopeVariable();
|
||||||
|
void increaseDepth();
|
||||||
|
void decreaseDepth();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue