TS_CPP
An efficient & easy to use implementation of a Symbol table used in most compilers
Loading...
Searching...
No Matches
TS_CPP::SymbolTable Class Reference

#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 ()
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ SymbolTable() [1/2]

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

Parameters
idThe inuqie identifier of the table
entryIdA pointer to the entries ID counter
tableNameThe name of the table

Definition at line 13 of file SymbolTable.cpp.

◆ SymbolTable() [2/2]

SymbolTable::SymbolTable ( int id,
int * entryId )

The constructor of a SymbolTable It should not be used directly, but using the method TSManager::createNewTable

Parameters
idThe inuqie identifier of the table
entryIdA pointer to the entries ID counter

Definition at line 6 of file SymbolTable.cpp.

◆ ~SymbolTable()

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.

Member Function Documentation

◆ _addTableEntriesSize()

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

Parameters
sizethe size added to the summation of the size of all the entries in the table

Definition at line 131 of file SymbolTable.cpp.

◆ _getDisplacement()

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

Returns
the displacement of the next entry to be added to the table

Definition at line 195 of file SymbolTable.cpp.

◆ _getEntriesStorage()

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

Returns
a reference to the Entries Storage object

Definition at line 190 of file SymbolTable.cpp.

◆ createNewEntry()

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

Parameters
lexemeThe name of the lexeme stored in this Entry
Returns
A pointer to the new Entry

Definition at line 30 of file SymbolTable.cpp.

◆ deleteEntry() [1/2]

bool SymbolTable::deleteEntry ( const std::string & lexeme)

This function removes the entry that has its lexeme equal to the provided one from its table

Parameters
lexemeThe name of the entry to delete
Returns
true if the entry was deleted and false if the entry does not exist

Definition at line 81 of file SymbolTable.cpp.

◆ deleteEntry() [2/2]

bool SymbolTable::deleteEntry ( int entryId)

This function removes the entry that has its lexeme equal to the provided one from its table

Parameters
entryIdThe id of the entry to delete
Returns
true if the entry was deleted and false if the entry does not exist

Definition at line 94 of file SymbolTable.cpp.

◆ getAttribute()

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)

Parameters
attributeNameThe name of the attribute to search for
Returns
The value of the attribute if the attribute exist or NoAttribute (a special attribute with attributeType=NOATRIB and data.str = nullptr (or data.num = 0)) if it doesn't exist

Definition at line 137 of file SymbolTable.cpp.

◆ getEntry()

Entry * SymbolTable::getEntry ( int entryId)

This function gets the Entry referenced by the provided entryId

Parameters
entryIdThe unique identifier of the entry
Returns
A pointer to the Entry referenced by the entryId or nullptr if it doesn't exist

Definition at line 51 of file SymbolTable.cpp.

◆ getId()

int SymbolTable::getId ( ) const

This function returns the ID of the symbol table

Returns
The ID of the symbol table

Definition at line 20 of file SymbolTable.cpp.

◆ getTableEntriesSize()

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.

Returns
the summation of the size of all the entries in the table

Definition at line 126 of file SymbolTable.cpp.

◆ getTableName()

std::string SymbolTable::getTableName ( ) const

This function returns the name of the symbol table

Returns
The name of the symbol table

Definition at line 25 of file SymbolTable.cpp.

◆ searchEntry()

Entry * SymbolTable::searchEntry ( const std::string & lexeme)

This function search and return the entry that has its lexeme equal to the provided one

Parameters
lexemeThe name of the entry to search for
Returns
A pointer to the Entry referenced by the entryId or nullptr if it doesn't exist

Definition at line 66 of file SymbolTable.cpp.

◆ setNumericAttribute()

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

Parameters
attributeNameThe name of the attribute to store
valueThe value of the attribute to store

Definition at line 151 of file SymbolTable.cpp.

◆ setStringAttribute()

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

Parameters
attributeNameThe name of the attribute to store
valueThe value of the attribute to store

Definition at line 166 of file SymbolTable.cpp.


The documentation for this class was generated from the following files: