-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathData.cpp
More file actions
89 lines (74 loc) · 2 KB
/
Data.cpp
File metadata and controls
89 lines (74 loc) · 2 KB
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
#include "Data.h"
namespace Data {
// Instruction implementation starts here
Instruction::Instruction()
: kind(Undefined), value() {}
Instruction::Instruction(const std::string& v, bool call)
: kind(call ? Call : StringLit), value(v) { }
Instruction::Instruction(char c)
: kind(CharLit), value(c) { }
Instruction::Instruction(int n)
: kind(IntLit), value(n) { }
Instruction::Instruction(double n)
: kind(DoubleLit), value(n) { }
Instruction::Value Instruction::getValue() const
{
return value;
}
Instruction::Type Instruction::getType() const
{
return kind;
}
std::ostream& operator<<(std::ostream& os, const Instruction& ins)
{
switch(ins.getType()) {
case Instruction::CharLit:
os << "(Character)";
break;
case Instruction::IntLit:
os << "(Integer)";
break;
case Instruction::DoubleLit:
os << "(Real)";
break;
case Instruction::StringLit:
os << "(String)";
break;
case Instruction::Call:
os << "(Call)";
break;
default:
os << "(Undefined)";
break;
}
return os << ins.getValue();
}
// Subroutine implementation starts here
Subroutine::~Subroutine()
{
for(Instruction* ins : instructions) {
if(ins != nullptr)
delete ins;
}
}
void Subroutine::addInstruction(Instruction* i)
{
instructions.push_back(i);
}
bool Subroutine::hasParent() const
{
return parent != nullptr;
}
Subroutine* Subroutine::getParent() const
{
return parent;
}
std::string Subroutine::getName() const
{
return name;
}
InstructionTable Subroutine::getInstructions() const
{
return instructions;
}
}