blob: 5dd1e1f6bece172cde7f416bcef0ac33d51bf5de (
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
|
#ifndef BINDINGS_HPP
#define BINDINGS_HPP
#include <cstdint>
#include <map>
#include <memory>
#include <string>
class Type;
typedef std::shared_ptr<Type> TypePtr;
// struct containing information on the variable declaration
struct DeclarationData
{
TypePtr type;
int32_t stack_position;
};
// stores bindings for the current scope and where they are in the stack
class VariableStackBindings
{
private:
std::map<std::string, DeclarationData> bindings;
int32_t stack_counter;
int8_t current_register;
public:
VariableStackBindings();
void insertBinding(std::string id, TypePtr type, int32_t stack_position);
void increaseStackPosition();
void resetRegister();
void increaseRegister();
int32_t getCurrentStackPosition() const;
int32_t getStackPosition(const std::string& id) const;
int8_t getCurrentRegister() const;
bool bindingExists(const std::string& id) const;
};
#endif
|