diff options
author | ymherklotz <ymherklotz@gmail.com> | 2017-03-10 15:23:46 +0000 |
---|---|---|
committer | ymherklotz <ymherklotz@gmail.com> | 2017-03-10 15:23:46 +0000 |
commit | b751d9ade81f47d75a5dc16f40890f30a6a1d1c5 (patch) | |
tree | d2ff52856eff330ad2b9df60d88884c2a73569e1 /c_compiler/include/bindings.hpp | |
parent | 21c873789eda041f7004d12637be3f3ed6f4cebc (diff) | |
download | Compiler-b751d9ade81f47d75a5dc16f40890f30a6a1d1c5.tar.gz Compiler-b751d9ade81f47d75a5dc16f40890f30a6a1d1c5.zip |
Got variables and bindings kind of working
Diffstat (limited to 'c_compiler/include/bindings.hpp')
-rw-r--r-- | c_compiler/include/bindings.hpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/c_compiler/include/bindings.hpp b/c_compiler/include/bindings.hpp new file mode 100644 index 0000000..9ca862f --- /dev/null +++ b/c_compiler/include/bindings.hpp @@ -0,0 +1,39 @@ +#ifndef BINDINGS_HPP +#define BINDINGS_HPP + +#include <cstdint> +#include <map> +#include <string> + +class Type; + + +// struct containing information on the variable declaration +struct DeclarationData +{ + Type* 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; + +public: + VariableStackBindings(); + + void insertBinding(std::string id, Type* type, int32_t stack_position); + void increaseStackPosition(); + + int32_t getCurrentStackPosition() const; + int32_t getStackPosition(const std::string& id) const; + + bool bindingExists(const std::string& id) const; +}; + + +#endif |