Make env a class.
This commit is contained in:
parent
8b897c9636
commit
3fbca52845
41
13/env.hpp
41
13/env.hpp
@ -2,33 +2,38 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
struct env {
|
class env {
|
||||||
virtual ~env() = default;
|
public:
|
||||||
|
virtual ~env() = default;
|
||||||
|
|
||||||
virtual int get_offset(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;
|
virtual bool has_variable(const std::string& name) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
using env_ptr = std::shared_ptr<env>;
|
using env_ptr = std::shared_ptr<env>;
|
||||||
|
|
||||||
struct env_var : public env {
|
class env_var : public env {
|
||||||
std::string name;
|
private:
|
||||||
env_ptr parent;
|
std::string name;
|
||||||
|
env_ptr parent;
|
||||||
|
|
||||||
env_var(std::string n, env_ptr p)
|
public:
|
||||||
: name(std::move(n)), parent(std::move(p)) {}
|
env_var(std::string n, env_ptr p)
|
||||||
|
: name(std::move(n)), parent(std::move(p)) {}
|
||||||
|
|
||||||
int get_offset(const std::string& name) const;
|
int get_offset(const std::string& name) const;
|
||||||
bool has_variable(const std::string& name) const;
|
bool has_variable(const std::string& name) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct env_offset : public env {
|
class env_offset : public env {
|
||||||
int offset;
|
private:
|
||||||
env_ptr parent;
|
int offset;
|
||||||
|
env_ptr parent;
|
||||||
|
|
||||||
env_offset(int o, env_ptr p)
|
public:
|
||||||
: offset(o), parent(std::move(p)) {}
|
env_offset(int o, env_ptr p)
|
||||||
|
: offset(o), parent(std::move(p)) {}
|
||||||
|
|
||||||
int get_offset(const std::string& name) const;
|
int get_offset(const std::string& name) const;
|
||||||
bool has_variable(const std::string& name) const;
|
bool has_variable(const std::string& name) const;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user