-
Notifications
You must be signed in to change notification settings - Fork 1
/
symbol.cpp
executable file
·74 lines (60 loc) · 1.96 KB
/
symbol.cpp
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
65
66
67
68
69
70
71
72
73
74
#include "symbol.h"
Symbol::Symbol(int lexemeIndex, int scope, const char *lexemeScope) {
this->lexemeIndex = lexemeIndex;
this->lexemeScope = lexemeScope;
this->scope = scope;
this->nextSymbol = nullptr;
}
Symbol::~Symbol() {
free(this->nextSymbol);
}
Symbol::Symbol(int lexemeIndex) {
this->lexemeIndex = lexemeIndex;
this->lexemeScope = nullptr;
this->scope = -1;
this->nextSymbol = nullptr;
}
Symbol::Symbol() {
this->lexemeIndex = 0;
this->lexemeScope = nullptr;
this->scope = -1;
this->nextSymbol = nullptr;
}
ReservedTokenSymbol::ReservedTokenSymbol(int lexemeIndex, int tokenID) : Symbol(lexemeIndex) {
this->tokenID = tokenID;
}
VarSymbol::VarSymbol(int lexemeIndex, int scope, const char *lexemeScope, TypeNode *type,
bool pointer, int arraySize, bool parameter) : Symbol(lexemeIndex, scope, lexemeScope) {
this->type = type;
this->pointer = pointer;
this->arraySize = arraySize;
this->parameter = parameter;
this->offset = 0;
this->size = 0;
}
VarSymbol::~VarSymbol() {
this->type = nullptr;
}
FunctionSymbol::FunctionSymbol(int lexemeIndex, int scope, const char *lexemeScope, TypeNode *returnType,
bool pointer, FormalListNode *varDecl) : Symbol(lexemeIndex, scope, lexemeScope) {
this->returnType = returnType;
this->pointer = pointer;
this->varDecl = varDecl;
this->localSize = 0;
this->paramSize = 0;
this->callSize = 0;
}
FunctionSymbol::~FunctionSymbol() {
this->returnType = nullptr;
this->varDecl = nullptr;
}
StructSymbol::StructSymbol(int lexemeIndex, int scope, const char *lexemeScope, VarDeclNode *varDecl)
: Symbol(lexemeIndex, scope, lexemeScope) {
this->varDecl = varDecl;
}
StructSymbol::~StructSymbol() {
this->varDecl = nullptr;
}
StructSymbol::StructSymbol(int scope, const char *lexemeScope, VarDeclNode *varDecl) : Symbol(0, scope, lexemeScope) {
this->varDecl = varDecl;
}