Commit 11aeaa6a by Aaron Leung

Improving the interface and correcting some behavior.

parent 6a8b096a
...@@ -198,7 +198,7 @@ namespace Sass { ...@@ -198,7 +198,7 @@ namespace Sass {
vector<Node> children; vector<Node> children;
string* file_name; string* file_name;
size_t line_number; size_t line_number;
Node::Type type; Node::Type type;
...@@ -216,6 +216,9 @@ namespace Sass { ...@@ -216,6 +216,9 @@ namespace Sass {
size_t size() size_t size()
{ return children.size(); } { return children.size(); }
bool empty()
{ return children.empty(); }
Node& at(size_t i) Node& at(size_t i)
{ return children.at(i); } { return children.at(i); }
...@@ -224,10 +227,10 @@ namespace Sass { ...@@ -224,10 +227,10 @@ namespace Sass {
{ return children.back(); } { return children.back(); }
void push_back(const Node& n) void push_back(const Node& n)
{ children.push_back(n); } { children.push_back(n); has_children = true; }
void pop_back() void pop_back()
{ children.pop_back(); } { children.pop_back(); if (empty()) has_children = false; }
bool boolean_value() bool boolean_value()
{ return value.boolean; } { return value.boolean; }
...@@ -239,7 +242,7 @@ namespace Sass { ...@@ -239,7 +242,7 @@ namespace Sass {
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// Node method implementations // Node method implementations
// -- in the header so they can be easily declared inline // -- in the header file so they can easily be declared inline
// -- outside of their class definition to get the right declaration order // -- outside of their class definition to get the right declaration order
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
......
...@@ -12,29 +12,28 @@ namespace Sass { ...@@ -12,29 +12,28 @@ namespace Sass {
return ip; return ip;
} }
Node Node_Factory::node(Node::Type type, string* file, size_t line, const Token& t) Node Node_Factory::operator()(Node::Type type, string* file, size_t line, const Token& t)
{ {
Node_Impl* ip = alloc_Node_Impl(type, file, line); Node_Impl* ip = alloc_Node_Impl(type, file, line);
ip->value.token = t; ip->value.token = t;
return Node(ip); return Node(ip);
} }
Node Node_Factory::node(Node::Type type, string* file, size_t line, size_t size) Node Node_Factory::operator()(Node::Type type, string* file, size_t line, size_t size)
{ {
Node_Impl* ip = alloc_Node_Impl(type, file, line); Node_Impl* ip = alloc_Node_Impl(type, file, line);
ip->has_children = true;
ip->children.reserve(size); ip->children.reserve(size);
return Node(ip); return Node(ip);
} }
Node Node_Factory::node(string* file, size_t line, double v) Node Node_Factory::operator()(string* file, size_t line, double v)
{ {
Node_Impl* ip = alloc_Node_Impl(Node::number, file, line); Node_Impl* ip = alloc_Node_Impl(Node::number, file, line);
ip->value.numeric = v; ip->value.numeric = v;
return Node(ip); return Node(ip);
} }
Node Node_Factory::node(string* file, size_t line, double v, const Token& t) Node Node_Factory::operator()(string* file, size_t line, double v, const Token& t)
{ {
Node_Impl* ip = alloc_Node_Impl(Node::numeric_dimension, file, line); Node_Impl* ip = alloc_Node_Impl(Node::numeric_dimension, file, line);
ip->value.dimension.numeric = v; ip->value.dimension.numeric = v;
...@@ -42,13 +41,13 @@ namespace Sass { ...@@ -42,13 +41,13 @@ namespace Sass {
return Node(ip); return Node(ip);
} }
Node Node_Factory::node(string* file, size_t line, double r, double g, double b, double a) Node Node_Factory::operator()(string* file, size_t line, double r, double g, double b, double a)
{ {
Node color(node(Node::numeric_color, file, line, 4)); Node color((*this)(Node::numeric_color, file, line, 4));
color << node(file, line, r) color << (*this)(file, line, r)
<< node(file, line, g) << (*this)(file, line, g)
<< node(file, line, b) << (*this)(file, line, b)
<< node(file, line, a); << (*this)(file, line, a);
return color; return color;
} }
......
...@@ -14,11 +14,11 @@ namespace Sass { ...@@ -14,11 +14,11 @@ namespace Sass {
vector<Node_Impl*> pool_; vector<Node_Impl*> pool_;
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);
public: public:
Node node(Node::Type type, string* file, size_t line, const Token& t); Node operator()(Node::Type type, string* file, size_t line, const Token& t);
Node node(Node::Type type, string* file, size_t line, size_t size); Node operator()(Node::Type type, string* file, size_t line, size_t size);
Node node(string* file, size_t line, double v); Node operator()(string* file, size_t line, double v);
Node node(string* file, size_t line, double v, const Token& t); Node operator()(string* file, size_t line, double v, const Token& t);
Node node(string* file, size_t line, double r, double g, double b, double a = 1.0); Node operator()(string* file, size_t line, double r, double g, double b, double a = 1.0);
}; };
} }
\ No newline at end of file
...@@ -11,20 +11,21 @@ int main() ...@@ -11,20 +11,21 @@ int main()
using namespace Sass; using namespace Sass;
using namespace std; using namespace std;
cout << sizeof(Node_Impl*) << endl;
cout << sizeof(Node) << endl; cout << sizeof(Node) << endl;
cout << sizeof(Node_Impl) << endl << endl; cout << sizeof(Node_Impl) << endl << endl;
Node_Factory make = Node_Factory(); Node_Factory new_Node = Node_Factory();
Node interior(make.node(Node::block, 0, 0, 3)); Node interior(new_Node(Node::block, 0, 0, 3));
cout << interior.size() << endl; cout << interior.size() << endl;
cout << interior.has_children() << endl; cout << interior.has_children() << endl;
cout << interior.should_eval() << endl << endl; cout << interior.should_eval() << endl << endl;
Node num(make.node(0, 0, 255, 123, 32)); Node num(new_Node(0, 0, 255, 123, 32));
Node num2(make.node(0, 0, 255, 123, 32)); Node num2(new_Node(0, 0, 255, 123, 32));
Node num3(make.node(0, 0, 255, 122, 20, .75)); Node num3(new_Node(0, 0, 255, 122, 20, .75));
cout << num.size() << endl; cout << num.size() << endl;
cout << num.has_children() << endl; cout << num.has_children() << endl;
......
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