-
Notifications
You must be signed in to change notification settings - Fork 0
/
Declarations.cpp
78 lines (66 loc) · 1.75 KB
/
Declarations.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
#include "Declarations.hpp"
Declarations::Declarations()
{
procedureDeclarations = new ProcedureDeclarations();
}
Declarations::~Declarations()
{
}
void Declarations::declare(Context& context)
{
constDeclarations.declare(context);
typeDeclarations.declare(context);
varDeclarations.declare(context);
procedureDeclarations->declare(context);
}
void ConstDeclaration::declare(Context& context)
{
//std::cerr << "Declaring const " << identifier << std::endl;
context.declareAndSetVariable(identifier, expression->evaluate(context));
}
void ConstDeclarations::declare(Context& context)
{
//std::cerr << "Declaring consts" << std::endl;
for (auto& declaration : constDeclarations)
{
declaration.declare(context);
}
}
void ConstDeclarations::addDeclaration(ConstDeclaration constDeclaration)
{
constDeclarations.push_back(constDeclaration);
}
void TypeDeclaration::declare(Context& context)
{
//std::cerr << "Declaring type " << identifier << std::endl;
context.declareType(identifier, type);
}
void TypeDeclarations::declare(Context& context)
{
//std::cerr << "Declaring types" << std::endl;
for (auto& declaration : typeDeclarations)
{
declaration.declare(context);
}
}
void TypeDeclarations::addDeclaration(TypeDeclaration typeDeclaration)
{
typeDeclarations.push_back(typeDeclaration);
}
void VarDeclaration::declare(Context& context)
{
//std::cerr << "Declaring variable " << varIdentifier << std::endl;
context.declareVariable(varIdentifier, varType);
}
void VarDeclarations::declare(Context& context)
{
//std::cerr << "Declaring variables" << std::endl;
for (auto& declaration : varDeclarations)
{
declaration.declare(context);
}
}
void VarDeclarations::addDeclaration(VarDeclaration varDeclaration)
{
varDeclarations.push_back(varDeclaration);
}