-
Notifications
You must be signed in to change notification settings - Fork 0
/
ASTLoopNode.cpp
101 lines (75 loc) · 1.95 KB
/
ASTLoopNode.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
92
93
94
95
96
97
98
99
100
101
/*
* File: ASTLoopNode.cpp
* Author: daniel
*
* Created on October 8, 2013, 2:28 AM
*/
#include "ASTLoopNode.h"
ASTLoopNode::ASTLoopNode() : ASTStatementNode(), statement(NULL), contLabel(""),
endLabel("")
{
}
ASTLoopNode::ASTLoopNode(const ASTLoopNode& orig) : ASTStatementNode(orig), statement(orig.statement),
contLabel(""), endLabel("")
{
}
ASTLoopNode& ASTLoopNode::operator= (const ASTLoopNode &rhs)
{
ASTStatementNode::operator=(rhs);
// do the copy
statement = rhs.statement;
contLabel = rhs.contLabel;
endLabel = rhs.endLabel;
// return the existing object
return *this;
}
ASTLoopNode::~ASTLoopNode() {
delete statement;
}
void ASTLoopNode::semAnalyze(){
if(init || !this->isGlobalDec){
this->scopeAnalyze();
if(init)
return;
}
this->statement->semAnalyze();
if(this->next != NULL)
this->next->semAnalyze();
//this->typeAnalyze();
}
string ASTLoopNode::genQuadruples(){
contLabel = getLabel();
endLabel = getLabel();
// Start of loop
vec.push_back(Quadruple("lab","","",contLabel));
// Do stuff
statement->genQuadruples();
// Repeat from start of loop
vec.push_back(Quadruple("goto","","",contLabel));
// Outside end of loop
vec.push_back(Quadruple("lab","","",endLabel));
if(this->next != NULL) {
this->next->genQuadruples();
}
return "";
}
void ASTLoopNode::scopeAnalyze(){
//nothing
}
bool ASTLoopNode::returnAnalyze() {
// If first statement returns, then so does this
bool firstRets = this->statement->returnAnalyze();
if(next != NULL) {
return firstRets || dynamic_cast<ASTStatementNode *>(next)->returnAnalyze();
}
return firstRets;
}
void ASTLoopNode::printNode(int indent, ostream * output) {
this->output = output;
printIndented("loop", indent);
printIndented("statement:", indent + 2);
statement->printNode(indent + 4, output);
if(next != NULL) {
next->printNode(indent, output);
}
}