-
Notifications
You must be signed in to change notification settings - Fork 0
/
ASTMarkerNode.cpp
88 lines (67 loc) · 1.71 KB
/
ASTMarkerNode.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
/*
* File: ASTMarkerNode.cpp
* Author: daniel
*
* Created on October 8, 2013, 2:07 PM
*/
#include "ASTMarkerNode.h"
#include "SemanticAnalyzer.h"
#include "ASTLoopNode.h"
ASTMarkerNode::ASTMarkerNode() : ASTStatementNode(), type(0), enabled(false),
corrLoop(NULL)
{
}
ASTMarkerNode::ASTMarkerNode(const ASTMarkerNode& orig) : ASTStatementNode(orig),type(orig.type),
enabled(orig.enabled), corrLoop(NULL)
{
}
ASTMarkerNode& ASTMarkerNode::operator= (const ASTMarkerNode &rhs)
{
ASTStatementNode::operator=(rhs);
// do the copy
type = rhs.type;
enabled = rhs.enabled;
corrLoop = rhs.corrLoop;
// return the existing object
return *this;
}
ASTMarkerNode::~ASTMarkerNode() {
}
string ASTMarkerNode::genQuadruples() {
switch(type) {
case Scanner::EXIT:
vec.push_back(Quadruple("goto","","",corrLoop->endLabel));
break;
case Scanner::CONTINUE:
vec.push_back(Quadruple("goto","","",corrLoop->contLabel));
break;
}
return "";
}
void ASTMarkerNode::semAnalyze(){
if(init || !this->isGlobalDec){
this->scopeAnalyze();
if(init)
return;
}
loopAnalyze();
if(this->next != NULL)
this->next->semAnalyze();
//this->typeAnalyze();
}
void ASTMarkerNode::scopeAnalyze(){
}
void ASTMarkerNode::loopAnalyze() {
if(!enabled && (type == Scanner::EXIT ||
type == Scanner::CONTINUE)) {
sa->semanticError("Use of exit or continue outside of loop body", lineNumber);
}
}
void ASTMarkerNode::printNode(int indent, ostream * output) {
this->output = output;
printIndented("marker", indent);
printIndented("type: " + Scanner::namesRev[type], indent + 2);
if(next != NULL) {
next->printNode(indent, output);
}
}