Commit 55d82671 by Aaron Leung

Cloning values fetched from variables in order to set their paths and…

Cloning values fetched from variables in order to set their paths and line-numbers to the point of reference. (Using the original values would result in paths and line-numbers being reported as the point of assignment, which is not helpful for debugging.)
parent d935b77e
...@@ -286,7 +286,7 @@ namespace Sass { ...@@ -286,7 +286,7 @@ namespace Sass {
case Node::variable: { case Node::variable: {
if (!env.query(expr.token())) throw_eval_error("reference to unbound variable " + expr.token().to_string(), expr.path(), expr.line()); if (!env.query(expr.token())) throw_eval_error("reference to unbound variable " + expr.token().to_string(), expr.path(), expr.line());
return env[expr.token()]; return new_Node(expr.path(), expr.line(), env[expr.token()]);
} break; } break;
case Node::image_url: { case Node::image_url: {
......
...@@ -27,6 +27,21 @@ namespace Sass { ...@@ -27,6 +27,21 @@ namespace Sass {
return ip_cpy; return ip_cpy;
} }
// returns a deep-copy of its argument, but uses the path and line that are passed in
Node_Impl* Node_Factory::alloc_Node_Impl(string& path, size_t line, Node_Impl* ip)
{
Node_Impl* ip_cpy = new Node_Impl(*ip);
pool_.push_back(ip_cpy);
if (ip_cpy->has_children) {
for (size_t i = 0, S = ip_cpy->size(); i < S; ++i) {
Node n(ip_cpy->at(i));
ip_cpy->at(i) = (*this)(path, line, n);
}
}
return ip_cpy;
}
// for cloning nodes // for cloning nodes
Node Node_Factory::operator()(const Node& n1) Node Node_Factory::operator()(const Node& n1)
{ {
...@@ -34,6 +49,15 @@ namespace Sass { ...@@ -34,6 +49,15 @@ namespace Sass {
return Node(ip_cpy); return Node(ip_cpy);
} }
// for cloning nodes and resetting their path and line-number fields
Node Node_Factory::operator()(string& path, size_t line, const Node& n1)
{
Node_Impl* ip_cpy = alloc_Node_Impl(path, line, n1.ip_); // deep-copy the implementation object
ip_cpy->path = path;
ip_cpy->line = line;
return Node(ip_cpy);
}
// for making leaf nodes out of terminals/tokens // for making leaf nodes out of terminals/tokens
Node Node_Factory::operator()(Node::Type type, string path, size_t line, Token t) Node Node_Factory::operator()(Node::Type type, string path, size_t line, Token t)
{ {
......
...@@ -17,9 +17,11 @@ namespace Sass { ...@@ -17,9 +17,11 @@ namespace Sass {
Node_Impl* alloc_Node_Impl(Node::Type type, string file, size_t line); Node_Impl* alloc_Node_Impl(Node::Type type, string file, size_t line);
// returns a deep-copy of its argument // returns a deep-copy of its argument
Node_Impl* alloc_Node_Impl(Node_Impl* ip); Node_Impl* alloc_Node_Impl(Node_Impl* ip);
Node_Impl* alloc_Node_Impl(string& path, size_t line, Node_Impl* ip);
public: public:
// for cloning nodes // for cloning nodes
Node operator()(const Node& n1); Node operator()(const Node& n1);
Node operator()(string& path, size_t line, const Node& n1);
// for making leaf nodes out of terminals/tokens // for making leaf nodes out of terminals/tokens
Node operator()(Node::Type type, string file, size_t line, Token t); Node operator()(Node::Type type, string file, size_t line, Token t);
// for making boolean values or interior nodes that have children // for making boolean values or interior nodes that have children
......
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