|
TS_CPP
An efficient & easy to use implementation of a Symbol table used in most compilers
|
#include <SymbolTable.h>
Public Member Functions | |
| SymbolTable (int id, int *entryId, const std::string &tableName) | |
| SymbolTable (int id, int *entryId) | |
| ~SymbolTable () | |
| int | getId () const |
| std::string | getTableName () const |
| Entry * | createNewEntry (const std::string &lexeme) |
| Entry * | getEntry (int entryId) |
| Entry * | searchEntry (const std::string &lexeme) |
| bool | deleteEntry (const std::string &lexeme) |
| bool | deleteEntry (int entryId) |
| int | getTableEntriesSize () const |
| void | _addTableEntriesSize (int size) |
| int | _getDisplacement () const |
| AttributeValue * | getAttribute (const std::string &attributeName) |
| void | setNumericAttribute (const std::string &attributeName, long long value) |
| void | setStringAttribute (const std::string &attributeName, const char *value) |
| std::vector< Entry * > & | _getEntriesStorage () |
SymbolTable class provides the Abstract Data Type (ADT) of a symbol table, which consists of an id, a table name, and a set of rows (aka Entries) consisting of a lexeme, an id, and zero or more attributes.
Definition at line 17 of file SymbolTable.h.
| SymbolTable::SymbolTable | ( | int | id, |
| int * | entryId, | ||
| const std::string & | tableName ) |
The constructor of a SymbolTable It should not be used directly, but using the method TSManager::createNewTable
| id | The inuqie identifier of the table |
| entryId | A pointer to the entries ID counter |
| tableName | The name of the table |
Definition at line 13 of file SymbolTable.cpp.
| SymbolTable::SymbolTable | ( | int | id, |
| int * | entryId ) |
The constructor of a SymbolTable It should not be used directly, but using the method TSManager::createNewTable
| id | The inuqie identifier of the table |
| entryId | A pointer to the entries ID counter |
Definition at line 6 of file SymbolTable.cpp.
| SymbolTable::~SymbolTable | ( | ) |
The destructor of a SymbolTable It deletes all its entries before deleting itself It should not be used directly, but using the method TSManager::deleteTable
Definition at line 182 of file SymbolTable.cpp.
| void SymbolTable::_addTableEntriesSize | ( | int | size | ) |
This function should not be used during normal operation and is intended for advanced users only This function adds the provided size to the summation of the size of all the entries in the table and also advances the displacement of the next entry to be added to the table
| size | the size added to the summation of the size of all the entries in the table |
Definition at line 131 of file SymbolTable.cpp.
| int SymbolTable::_getDisplacement | ( | ) | const |
This function should not be used during normal operation and is intended for advanced users only This function provides the displacement of the next entry to be added to the table
Definition at line 195 of file SymbolTable.cpp.
| std::vector< Entry * > & SymbolTable::_getEntriesStorage | ( | ) |
This function should not be used during normal operation and is intended for advanced users only This function provides access to the Entries Storage object
Definition at line 190 of file SymbolTable.cpp.
| Entry * SymbolTable::createNewEntry | ( | const std::string & | lexeme | ) |
This function create a new void entry (row) in the symbol table and set the lexeme property of it
| lexeme | The name of the lexeme stored in this Entry |
Definition at line 30 of file SymbolTable.cpp.
| bool SymbolTable::deleteEntry | ( | const std::string & | lexeme | ) |
This function removes the entry that has its lexeme equal to the provided one from its table
| lexeme | The name of the entry to delete |
Definition at line 81 of file SymbolTable.cpp.
| bool SymbolTable::deleteEntry | ( | int | entryId | ) |
This function removes the entry that has its lexeme equal to the provided one from its table
| entryId | The id of the entry to delete |
Definition at line 94 of file SymbolTable.cpp.
| AttributeValue * SymbolTable::getAttribute | ( | const std::string & | attributeName | ) |
This function search for the attribute with the specified name and returns its value If the attribute does not exist, it returns a special attribute with attributeType=Null and data.str = nullptr (or data.num = 0)
| attributeName | The name of the attribute to search for |
Definition at line 137 of file SymbolTable.cpp.
| Entry * SymbolTable::getEntry | ( | int | entryId | ) |
This function gets the Entry referenced by the provided entryId
| entryId | The unique identifier of the entry |
Definition at line 51 of file SymbolTable.cpp.
| int SymbolTable::getId | ( | ) | const |
This function returns the ID of the symbol table
Definition at line 20 of file SymbolTable.cpp.
| int SymbolTable::getTableEntriesSize | ( | ) | const |
This function returns the summation of the size of all the entries in the table It is useful to calculate the size of the activation register of the function represented by this table.
Definition at line 126 of file SymbolTable.cpp.
| std::string SymbolTable::getTableName | ( | ) | const |
This function returns the name of the symbol table
Definition at line 25 of file SymbolTable.cpp.
| Entry * SymbolTable::searchEntry | ( | const std::string & | lexeme | ) |
This function search and return the entry that has its lexeme equal to the provided one
| lexeme | The name of the entry to search for |
Definition at line 66 of file SymbolTable.cpp.
| void SymbolTable::setNumericAttribute | ( | const std::string & | attributeName, |
| long long | value ) |
This function stores a new attribute with the desired name and value If the attribute already exist, it overwrites it
| attributeName | The name of the attribute to store |
| value | The value of the attribute to store |
Definition at line 151 of file SymbolTable.cpp.
| void SymbolTable::setStringAttribute | ( | const std::string & | attributeName, |
| const char * | value ) |
This function stores a new attribute with the desired name and value If the attribute already exist, it overwrites it
| attributeName | The name of the attribute to store |
| value | The value of the attribute to store |
Definition at line 166 of file SymbolTable.cpp.