From 7fafcbbd7d9b24269d8c68941404ccef13cb3c54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20LACROIX?= Date: Thu, 6 Apr 2023 11:40:37 +0200 Subject: [PATCH] added depth management --- table.c | 15 ++++++++++++--- table.h | 5 ++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/table.c b/table.c index e6f09f0..cc2cb2a 100644 --- a/table.c +++ b/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--; } \ No newline at end of file diff --git a/table.h b/table.h index de3045c..958ab18 100644 --- a/table.h +++ b/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