blob: d99d97bf54ffae20dca2ec33571b7296d932227a (
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
|
#ifndef BINDINGS_HPP
#define BINDINGS_HPP
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
class Type;
typedef std::shared_ptr<Type> TypePtr;
// struct containing information on the variable declaration
struct DeclarationData
{
TypePtr type;
int stack_position;
};
// stores bindings for the current scope and where they are in the stack
class Bindings
{
private:
static std::vector<std::string> string_literals;
std::unordered_map<std::string, DeclarationData> bindings_;
std::string break_label_;
std::string continue_label_;
int stack_counter_;
int expression_stack_;
public:
Bindings();
void insertBinding(const std::string &id, TypePtr type, const int &stack_position);
int insertStringLiteral(const std::string &string_literal);
void increaseStackPosition();
void increaseStackPosition(const int &position);
void setStackPosition(const int &stack_counter);
void nextExpressionStackPosition();
void setExpressionStackPosition(const int &stack_counter);
TypePtr getType(const std::string &id) const;
std::string breakLabel();
std::string breakLabel(const std::string &label);
std::string continueLabel();
std::string continueLabel(const std::string &label);
int currentStackPosition() const;
int stackPosition(const std::string &id) const;
int currentExpressionStackPosition() const;
std::pair<std::vector<std::string>::const_iterator, std::vector<std::string>::const_iterator>
getStringLiteralIterator() const;
bool bindingExists(const std::string &id) const;
};
#endif
|