Commit 83a92d81 by Aaron Leung

Putting the node type-tag enum back inside the Node class.

parent 4808d322
......@@ -177,10 +177,10 @@ namespace Sass {
{
switch (type)
{
case number:
case numeric_percentage:
case Node::number:
case Node::numeric_percentage:
return value.numeric;
case numeric_dimension:
case Node::numeric_dimension:
return value.dimension.numeric;
default:
break;
......@@ -193,11 +193,11 @@ namespace Sass {
{
switch (type)
{
case numeric_percentage: {
case Node::numeric_percentage: {
return "\"%\"";
} break;
case numeric_dimension: {
case Node::numeric_dimension: {
string result("\"");
result += value.dimension.unit.to_string();
result += "\"";
......
......@@ -6,7 +6,18 @@
namespace Sass {
using namespace std;
enum Node_Type {
struct Node_Impl;
class Node {
private:
friend class Node_Factory;
Node_Impl* ip_;
// private constructors; must use a Node_Factory
Node();
Node(Node_Impl* ip); // : ip_(ip) { }
public:
enum Type {
none,
flags,
comment,
......@@ -90,18 +101,7 @@ namespace Sass {
assignment
};
struct Node_Impl;
class Node {
private:
friend class Node_Factory;
Node_Impl* ip_;
// private constructors; must use a Node_Factory
Node();
Node(Node_Impl* ip); // : ip_(ip) { }
public:
Node_Type type(); // { return ip_->type; }
Type type(); // { return ip_->type; }
bool has_children(); // { return ip_->has_children; }
bool has_statements(); // { return ip_->has_statements; }
......@@ -197,7 +197,7 @@ namespace Sass {
string* file_name;
size_t line_number;
Node_Type type;
Node::Type type;
bool has_children;
bool has_statements;
......@@ -219,7 +219,7 @@ namespace Sass {
// bool boolean_value();
bool is_numeric()
{ return type >= number && type <= numeric_dimension; }
{ return type >= Node::number && type <= Node::numeric_dimension; }
size_t size()
{ return children.size(); }
......@@ -252,7 +252,7 @@ namespace Sass {
inline Node::Node(Node_Impl* ip) : ip_(ip) { }
inline Node_Type Node::type() { return ip_->type; }
inline Node::Type Node::type() { return ip_->type; }
inline bool Node::has_children() { return ip_->has_children; }
inline bool Node::has_statements() { return ip_->has_statements; }
......
......@@ -2,7 +2,7 @@
namespace Sass {
Node_Impl* Node_Factory::alloc_Node_Impl(Node_Type type, string* file, size_t line)
Node_Impl* Node_Factory::alloc_Node_Impl(Node::Type type, string* file, size_t line)
{
Node_Impl* ip = new Node_Impl();
ip->type = type;
......@@ -12,14 +12,14 @@ namespace Sass {
return ip;
}
Node Node_Factory::node(Node_Type type, string* file, size_t line, const Token& t)
Node Node_Factory::node(Node::Type type, string* file, size_t line, const Token& t)
{
Node_Impl* ip = alloc_Node_Impl(type, file, line);
ip->value.token = t;
return Node(ip);
}
Node Node_Factory::node(Node_Type type, string* file, size_t line, size_t size)
Node Node_Factory::node(Node::Type type, string* file, size_t line, size_t size)
{
Node_Impl* ip = alloc_Node_Impl(type, file, line);
ip->has_children = true;
......@@ -29,14 +29,14 @@ namespace Sass {
Node Node_Factory::node(string* file, size_t line, double v)
{
Node_Impl* ip = alloc_Node_Impl(number, file, line);
Node_Impl* ip = alloc_Node_Impl(Node::number, file, line);
ip->value.numeric = v;
return Node(ip);
}
Node Node_Factory::node(string* file, size_t line, double v, const Token& t)
{
Node_Impl* ip = alloc_Node_Impl(numeric_dimension, file, line);
Node_Impl* ip = alloc_Node_Impl(Node::numeric_dimension, file, line);
ip->value.dimension.numeric = v;
ip->value.dimension.unit = t;
return Node(ip);
......@@ -44,7 +44,7 @@ namespace Sass {
Node Node_Factory::node(string* file, size_t line, double r, double g, double b, double a)
{
Node color(node(numeric_color, file, line, 4));
Node color(node(Node::numeric_color, file, line, 4));
color << node(file, line, r)
<< node(file, line, g)
<< node(file, line, b)
......
......@@ -12,10 +12,10 @@ namespace Sass {
class Node_Factory {
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:
Node node(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 node(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 node(string* file, size_t line, double v);
Node node(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);
......
......@@ -16,7 +16,7 @@ int main()
Node_Factory make = Node_Factory();
Node interior(make.node(block, 0, 0, 3));
Node interior(make.node(Node::block, 0, 0, 3));
cout << interior.size() << endl;
cout << interior.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