1 #ifndef SASS_ENVIRONMENT_H
2 #define SASS_ENVIRONMENT_H
7 #include "ast_fwd_decl.hpp"
8 #include "ast_def_macros.hpp"
14 // TODO: test with map
15 std::map<std::string, T> local_frame_;
16 ADD_PROPERTY(Environment*, parent)
17 ADD_PROPERTY(bool, is_shadow)
20 Environment(bool is_shadow = false);
21 Environment(Environment* env, bool is_shadow = false);
22 Environment(Environment& env, bool is_shadow = false);
24 // link parent to create a stack
25 void link(Environment& env);
26 void link(Environment* env);
28 // this is used to find the global frame
29 // which is the second last on the stack
30 bool is_lexical() const;
32 // only match the real root scope
33 // there is still a parent around
34 // not sure what it is actually use for
35 // I guess we store functions etc. there
36 bool is_global() const;
38 // scope operates on the current frame
40 std::map<std::string, T>& local_frame();
42 bool has_local(const std::string& key) const;
44 T& get_local(const std::string& key);
46 // set variable on the current frame
47 void set_local(const std::string& key, T val);
49 void del_local(const std::string& key);
51 // global operates on the global frame
52 // which is the second last on the stack
53 Environment* global_env();
54 // get the env where the variable already exists
55 // if it does not yet exist, we return current env
56 Environment* lexical_env(const std::string& key);
58 bool has_global(const std::string& key);
60 T& get_global(const std::string& key);
62 // set a variable on the global frame
63 void set_global(const std::string& key, T val);
65 void del_global(const std::string& key);
67 // see if we have a lexical variable
68 // move down the stack but stop before we
69 // reach the global frame (is not included)
70 bool has_lexical(const std::string& key) const;
72 // see if we have a lexical we could update
73 // either update already existing lexical value
74 // or we create a new one on the current frame
75 void set_lexical(const std::string& key, T val);
77 // look on the full stack for key
78 // include all scopes available
79 bool has(const std::string& key) const;
81 // use array access for getter and setter functions
82 T& operator[](const std::string& key);
85 size_t print(std::string prefix = "");
90 // define typedef for our use case
91 typedef Environment<AST_Node_Obj> Env;