-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSymbolTable.cpp
More file actions
64 lines (49 loc) · 1.92 KB
/
SymbolTable.cpp
File metadata and controls
64 lines (49 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "SymbolTable.h"
#include "ASTNode.h"
bool SymbolTable::isIdExist(const std::string& identifierName) const {
return symbolTable.find(identifierName) != symbolTable.end();
}
void SymbolTable::addNewIdentifier(const std::string& name) {
symbolTable.emplace(name, Identifier{});
}
void SymbolTable::addNewIdentifier(const std::string& name, bool value) {
Identifier id;
id.Type = ValueType::Bool;
id.boolValue = value;
symbolTable.emplace(name, id);
}
void SymbolTable::addNewIdentifier(const std::string& name, double value) {
Identifier id;
id.Type = ValueType::Number;
id.numValue = value;
symbolTable.emplace(name, id);
}
void SymbolTable::setIdValueDouble(const std::string& identifierName, double value) {
symbolTable[identifierName].Type = ValueType::Number;
symbolTable[identifierName].numValue = value;
}
void SymbolTable::setIdValueBool(const std::string& identifierName, bool value) {
symbolTable[identifierName].Type = ValueType::Bool;
symbolTable[identifierName].boolValue = value;
}
double SymbolTable::getIdValueDouble(const std::string& identifierName) const {
return symbolTable.at(identifierName).numValue;
}
bool SymbolTable::getIdValueBool(const std::string& identifierName) const {
return symbolTable.at(identifierName).boolValue;
}
ValueType::Type SymbolTable::getIdValueType(const std::string& identifierName) const {
return symbolTable.at(identifierName).Type;
}
bool SymbolTable::isFuncExist(const std::string& funcName) {
return funcSymbolTable.find(funcName) != funcSymbolTable.end();
}
void SymbolTable::addNewFunc(DeclFuncNode* funcDecl) {
funcSymbolTable.emplace(funcDecl->name, funcDecl);
}
DeclFuncNode* SymbolTable::getFunc(const std::string& funcName) const {
return funcSymbolTable.at(funcName);
}
ValueType::Type SymbolTable::getFuncValueType(const std::string& funcName) const {
return funcSymbolTable.at(funcName)->returnType;
}