98 lines
2.2 KiB
C
98 lines
2.2 KiB
C
#ifndef TABLE_H
|
|
#define TABLE_H
|
|
|
|
#include <stdio.h>
|
|
#include <stdbool.h>
|
|
|
|
/*defined constants*/
|
|
#define START_TABLE_SIZE 128
|
|
#define NAME_MAX_LENGTH 30
|
|
|
|
// a list of all type
|
|
typedef enum enumVarType {INT, FLOAT} enumVarType;
|
|
|
|
// a list of all type's sizes
|
|
extern int memorySizes[2]; // TODO : PROBLEM DOES'NT COMPILE
|
|
|
|
typedef struct {
|
|
char name[NAME_MAX_LENGTH];
|
|
bool init;
|
|
enumVarType varType;
|
|
int offset;
|
|
int depth;
|
|
} Symbol;
|
|
|
|
/*============================
|
|
Array and Reallocation
|
|
============================*/
|
|
|
|
/*reallocates the array with the specified size*/
|
|
void reallocateArray(int size);
|
|
|
|
/*Checks for the length of the array and reallocates if necessary*/
|
|
void checkArraySanity();
|
|
|
|
/* /!\ To be called at the beginning
|
|
* Initializes the array of Symbols*/
|
|
void initSymbolTable();
|
|
|
|
|
|
/*============================
|
|
Element Management
|
|
============================*/
|
|
|
|
/* removes all symbols associated with the current Depth*/
|
|
void clearOutOfScopeVariable();
|
|
|
|
|
|
/* Adds an element */
|
|
void addElement(char* name, enumVarType type);
|
|
|
|
/*creates a new structure and updates variables*/
|
|
Symbol createNewStructure(char* name, enumVarType type);
|
|
|
|
|
|
/*============================
|
|
Element Edition
|
|
============================*/
|
|
|
|
/* sets the init state of the symbol to true */
|
|
void setInit(char *name);
|
|
|
|
/*============================
|
|
Element Access
|
|
============================*/
|
|
|
|
/* Returns the index with this name*/
|
|
int getIndex(char* name);
|
|
|
|
/* Returns the structure with this name */
|
|
Symbol getStruct(char* name);
|
|
|
|
/* Returns the offset from EBP to the symbol in the stack */
|
|
int getOffset(char* name);
|
|
|
|
|
|
/*==========================
|
|
Flow/Block control
|
|
=========================*/
|
|
|
|
/*increases the depth (i.e. when entering a block)*/
|
|
void increaseDepth();
|
|
|
|
/*decreases the depth (i.e. when leaving a block)*/
|
|
void decreaseDepth();
|
|
|
|
/*============================================
|
|
Display, Todo : put in another .h file
|
|
============================================*/
|
|
|
|
void error(char* mess);
|
|
void line();
|
|
void doubleLine();
|
|
|
|
/*displays the entire table at this moment including all information
|
|
* regarding the symbols and the current depth*/
|
|
void displayTable();
|
|
|
|
#endif
|