blob: 05bd288f33cafa1303cf8bb41518e1df8885b68a (
plain)
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
|
#include "bindings.hpp"
#include <iostream>
// VariableStackBindings definition
VariableStackBindings::VariableStackBindings()
: stack_counter_(0), expression_stack_(-4)
{}
void VariableStackBindings::insertBinding(std::string id, TypePtr type, int stack_position)
{
DeclarationData decl_data;
decl_data.type = type;
decl_data.stack_position = stack_position;
bindings_.insert(std::pair<std::string, DeclarationData>(id, decl_data));
}
void VariableStackBindings::increaseStackPosition()
{
stack_counter_ += 4;
}
void VariableStackBindings::setStackPosition(int stack_counter)
{
stack_counter_ = stack_counter;
}
void VariableStackBindings::nextExpressionStackPosition()
{
expression_stack_ -= 4;
}
int VariableStackBindings::currentStackPosition() const
{
return stack_counter_;
}
int VariableStackBindings::stackPosition(const std::string &id) const
{
auto binding = bindings_.find(id);
if(binding != bindings_.end())
return (*binding).second.stack_position;
else return 0;
}
int VariableStackBindings::currentExpressionStackPosition() const
{
return expression_stack_;
}
bool VariableStackBindings::bindingExists(const std::string &id) const
{
auto binding = bindings_.find(id);
if(binding == bindings_.end())
return false;
else
return true;
}
|