added flush

This commit is contained in:
Raphaël LACROIX 2023-04-14 15:37:57 +02:00
parent 977d225f25
commit 322afd388c
2 changed files with 33 additions and 1 deletions

31
table.c
View file

@ -2,6 +2,8 @@
#include <stdlib.h>
#include <string.h>
#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);
}
}

View file

@ -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);