-
Notifications
You must be signed in to change notification settings - Fork 0
/
ASTCaseNode.cpp
99 lines (74 loc) · 1.93 KB
/
ASTCaseNode.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
/*
* File: ASTCaseNode.cpp
* Author: claire
*
* Created on October 9, 2013, 12:09 AM
*/
#include "ASTCaseNode.h"
#include "SemanticAnalyzer.h"
ASTCaseNode::ASTCaseNode() : ASTStatementNode(),statement(NULL), type(0), num(0) {
}
ASTCaseNode::ASTCaseNode(const ASTCaseNode& orig):ASTStatementNode(orig), statement(orig.statement),
type(orig.type), num(orig.num)
{
}
ASTCaseNode& ASTCaseNode::operator= (const ASTCaseNode &rhs)
{
ASTStatementNode::operator=(rhs);
// do the copy
statement = rhs.statement;
type = rhs.type;
num = rhs.num;
// return the existing object
return *this;
}
ASTCaseNode::~ASTCaseNode() {
delete statement;
}
// Simply do the statement within the case, since all code flow is done in branch
string ASTCaseNode::genQuadruples() {
statement->genQuadruples();
return "";
}
void ASTCaseNode::semAnalyze(){
if(init || !this->isGlobalDec){
this->scopeAnalyze();
if(init)
return;
}
this->statement->semAnalyze();
if(next != NULL) {
this->next->semAnalyze();
}
this->typeAnalyze();
if(this->next != NULL)
this->next->semAnalyze();
}
void ASTCaseNode::scopeAnalyze(){
//nothing
}
void ASTCaseNode::typeAnalyze() {
/*if(type != Scanner::NUM && type != Scanner::DEFAULT) {
// Semantic error - expected NUM or DEFAULT
sa->semanticError("Expected NUM or DEFAULT", lineNumber);
}*/
}
void ASTCaseNode::printNode(int indent, ostream * output) {
ostringstream oss;
this->output = output;
printIndented(Scanner::namesRev[type], indent);
if(type != Scanner::DEFAULT) {
oss << "value: " << num;
printIndented(oss.str(), indent + 2);
}
if(statement != NULL) {
printIndented("statements:" , indent + 2);
statement->printNode(indent + 4, output);
}
if(next != NULL) {
next->printNode(indent, output);
}
if(next != NULL) {
next->printNode(indent, output);
}
}