Commit ec641613 by Aaron Leung

Moving the environment definition into its own file so I can eliminate a circular dependency.

parent b8fd9eb6
#define SASS_CONTEXT #define SASS_CONTEXT
#ifndef SASS_ENVIRONMENT
#include "environment.hpp"
#endif
#include <utility> #include <utility>
#include <map>
#include "node_factory.hpp" #include "node_factory.hpp"
#include "functions.hpp" #include "functions.hpp"
...@@ -10,35 +12,35 @@ namespace Sass { ...@@ -10,35 +12,35 @@ namespace Sass {
using std::pair; using std::pair;
using std::map; using std::map;
struct Environment { // struct Environment {
map<Token, Node> current_frame; // map<Token, Node> current_frame;
Environment* parent; // Environment* parent;
Environment* global; // Environment* global;
Environment() // Environment()
: current_frame(map<Token, Node>()), parent(0), global(0) // : current_frame(map<Token, Node>()), parent(0), global(0)
{ } // { }
void link(Environment& env) // void link(Environment& env)
{ // {
parent = &env; // parent = &env;
global = parent->global ? parent->global : parent; // global = parent->global ? parent->global : parent;
} // }
bool query(const Token& key) const // bool query(const Token& key) const
{ // {
if (current_frame.count(key)) return true; // if (current_frame.count(key)) return true;
else if (parent) return parent->query(key); // else if (parent) return parent->query(key);
else return false; // else return false;
} // }
Node& operator[](const Token& key) // Node& operator[](const Token& key)
{ // {
if (current_frame.count(key)) return current_frame[key]; // if (current_frame.count(key)) return current_frame[key];
else if (parent) return (*parent)[key]; // else if (parent) return (*parent)[key];
else return current_frame[key]; // else return current_frame[key];
} // }
}; // };
struct Context { struct Context {
Environment global_env; Environment global_env;
......
#define SASS_ENVIRONMENT
#include <map>
#ifndef SASS_NODE
#include "node.hpp"
#endif
namespace Sass {
using std::map;
struct Environment {
map<Token, Node> current_frame;
Environment* parent;
Environment* global;
Environment()
: current_frame(map<Token, Node>()), parent(0), global(0)
{ }
void link(Environment& env)
{
parent = &env;
global = parent->global ? parent->global : parent;
}
bool query(const Token& key) const
{
if (current_frame.count(key)) return true;
else if (parent) return parent->query(key);
else return false;
}
Node& operator[](const Token& key)
{
if (current_frame.count(key)) return current_frame[key];
else if (parent) return (*parent)[key];
else return current_frame[key];
}
};
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment