From f2f88ab9ca608a7e7d63b63be2f4c33edadf85b3 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Tue, 15 Sep 2020 19:12:12 -0700 Subject: [PATCH] Make env a class. --- code/compiler/13/env.hpp | 41 ++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/code/compiler/13/env.hpp b/code/compiler/13/env.hpp index 9d0dfbe..5413bba 100644 --- a/code/compiler/13/env.hpp +++ b/code/compiler/13/env.hpp @@ -2,33 +2,38 @@ #include #include -struct env { - virtual ~env() = default; +class env { + public: + virtual ~env() = default; - virtual int get_offset(const std::string& name) const = 0; - virtual bool has_variable(const std::string& name) const = 0; + virtual int get_offset(const std::string& name) const = 0; + virtual bool has_variable(const std::string& name) const = 0; }; using env_ptr = std::shared_ptr; -struct env_var : public env { - std::string name; - env_ptr parent; +class env_var : public env { + private: + std::string name; + env_ptr parent; - env_var(std::string n, env_ptr p) - : name(std::move(n)), parent(std::move(p)) {} + public: + env_var(std::string n, env_ptr p) + : name(std::move(n)), parent(std::move(p)) {} - int get_offset(const std::string& name) const; - bool has_variable(const std::string& name) const; + int get_offset(const std::string& name) const; + bool has_variable(const std::string& name) const; }; -struct env_offset : public env { - int offset; - env_ptr parent; +class env_offset : public env { + private: + int offset; + env_ptr parent; - env_offset(int o, env_ptr p) - : offset(o), parent(std::move(p)) {} + public: + env_offset(int o, env_ptr p) + : offset(o), parent(std::move(p)) {} - int get_offset(const std::string& name) const; - bool has_variable(const std::string& name) const; + int get_offset(const std::string& name) const; + bool has_variable(const std::string& name) const; };