-
Notifications
You must be signed in to change notification settings - Fork 0
/
ASTNode.cpp
91 lines (67 loc) · 1.64 KB
/
ASTNode.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
* File: ASTNode.cpp
* Author: claire
*
* Created on October 6, 2013, 11:47 AM
*/
#include "ASTNode.h"
#include "ScopeTable.h"
Scanner * ASTNode::lookup = 0;
SemanticAnalyzer * ASTNode::sa = 0;
int ASTNode:: tempCounter=1;
int ASTNode:: labelCounter=1;
bool ASTNode::init = true;
vector<Quadruple> ASTNode::vec;
int ASTNode::curLevel = 0;
int ASTNode::curDisplacement = 0;
ASTNode::ASTNode() : next(NULL), output(NULL), isGlobalDec(false), lineNumber(0){
}
ASTNode::ASTNode(const ASTNode& orig) : next(orig.next), output(orig.output),
isGlobalDec(orig.isGlobalDec), lineNumber(orig.lineNumber)
{
}
ASTNode& ASTNode:: operator = (const ASTNode& rhs){
next = rhs.next;
output = rhs.output;
isGlobalDec = rhs.isGlobalDec;
lineNumber = rhs.lineNumber;
return *this;
}
ASTNode::~ASTNode() {
delete next;
}
string ASTNode::genQuadruples() {
return "";
}
void ASTNode::semAnalyze(){
if(init || !this->isGlobalDec){
this->scopeAnalyze();
if(init)
return;
}
this->typeAnalyze();
if(this->next != NULL)
this->next->semAnalyze();
}
void ASTNode::scopeAnalyze(){
}
void ASTNode::typeAnalyze() {
}
void ASTNode::printIndented(string text, int indent) {
for(int i = 0; i < indent; i++) {
*output << " ";
}
*output << text << endl;
}
string ASTNode::getLabel(){
std::stringstream sstm;
sstm<<"L"<<labelCounter++;
return sstm.str();
}
string ASTNode::getTemp(){
std:stringstream sstm;
//sstm<<"t"<<tempCounter++;
sstm << "(" << curLevel << "," << curDisplacement << ")";
curDisplacement++;
return sstm.str();
}