From 322afd388c9c3112e81c839eb7258cfb06cfcba9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20LACROIX?= Date: Fri, 14 Apr 2023 15:37:57 +0200 Subject: [PATCH] added flush --- table.c | 31 ++++++++++++++++++++++++++++++- table.h | 3 +++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/table.c b/table.c index 4469232..bfbd20f 100644 --- a/table.c +++ b/table.c @@ -2,6 +2,8 @@ #include #include +#define VERBOSITY 1 // 1 -> displays the table, 0 no display + int memorySizes[2] = {1,1}; /*At the start of the execution : the whole array is empty*/ @@ -83,12 +85,22 @@ void clearOutOfScopeVariable(){ // and we free their memory (i.e. decrease esp) esp -= memoryFreed; + + if (VERBOSITY) { + printf("\n\nclearOutOfScopeVariable::After"); + displayTable(); + } } /* sets the init state of the symbol to true */ void setInit(char *name){ symbolTable[getIndex(name)].init = true; + + if (VERBOSITY) { + printf("\n\nsetInit %s", name); + displayTable(); + } } /*creates a new structure and updates variables*/ @@ -115,14 +127,31 @@ void addElement(char* name, enumVarType type){ currentIndex ++; esp += memorySizes[type]; + + if (VERBOSITY) { + printf("\n\nAddElement %s", name); + displayTable(); + } } + +/* removes all symbols */ +void flushSymbolTable(){ + currentIndex = 0; + checkArraySanity(); + if (VERBOSITY) { + printf("\n\nflushSymbolTable::After"); + displayTable(); + } +} + + /*Checks for the length of the array and reallocates if necessary*/ void checkArraySanity(){ if (currentIndex == maxIndex){ reallocateArray(maxIndex * 2); } else { - if (currentIndex < maxIndex / 2){ + if (currentIndex < maxIndex / 2 && maxIndex / 2 > START_TABLE_SIZE){ reallocateArray(maxIndex / 2); } } diff --git a/table.h b/table.h index 96aa89b..f4bc062 100644 --- a/table.h +++ b/table.h @@ -44,6 +44,9 @@ void initSymbolTable(); /* removes all symbols associated with the current Depth*/ void clearOutOfScopeVariable(); +/* removes all symbols */ +void flushSymbolTable(); + /* Adds an element */ void addElement(char* name, enumVarType type);