Commit 6e2de911 by Aaron Leung

More work on the node refactor.

parent 885b0e50
#include "node_factory.hpp"
#include "node_impl.hpp"
namespace Sass {
Node_Impl* Node_Factory::alloc_Node_Impl(Node_Type type, string* file, size_t line)
{
Node_Impl* ip = new Node_Impl();
ip->type = type;
ip->file_name = file;
ip->line_number = line;
pool_.push_back(ip);
return ip;
}
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_Impl* ip = alloc_Node_Impl(type, file, line);
ip->has_children = true;
ip->children.reserve(size);
return Node(ip);
}
Node Node_Factory::node(string* file, size_t line, double v)
{
Node_Impl* ip = alloc_Node_Impl(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);
ip->value.dimension.numeric = v;
ip->value.dimension.unit = t;
return Node(ip);
}
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));
color << node(file, line, r)
<< node(file, line, g)
<< node(file, line, b)
<< node(file, line, a);
return color;
}
}
\ No newline at end of file
#include <vector>
#ifndef SASS_NODE_INCLUDED
#include "node_pimpl.hpp"
#endif
namespace Sass {
using namespace std;
struct Token;
struct Node_Impl;
class Node_Factory {
vector<Node_Impl*> pool_;
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(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);
};
}
\ No newline at end of file
......@@ -152,7 +152,7 @@ namespace Sass {
// ------------------------------------------------------------------------
inline bool Node_Impl::is_numeric()
{ return type >= number && type <= numeric_color; }
{ return type >= number && type <= numeric_dimension; }
inline size_t Node_Impl::size()
{ return children.size(); }
......@@ -180,7 +180,7 @@ namespace Sass {
case numeric_percentage:
return value.numeric;
case numeric_dimension:
return value.dimension.numeric_value;
return value.dimension.numeric;
default:
break;
// throw an exception?
......
......@@ -34,7 +34,7 @@ namespace Sass {
};
struct Dimension {
double numeric_value;
double numeric;
Token unit;
};
......
......@@ -6,6 +6,8 @@
namespace Sass {
using namespace std;
inline Node::Node(Node_Impl* ip) : ip_(ip) { }
inline Node_Type Node::type() { return ip_->type; }
......
......@@ -12,11 +12,11 @@ namespace Sass {
class Node_Impl; // forward declaration
class Node {
private:
Node_Impl* ip_;
Node(Node_Impl* ip);
friend class Node_Factory;
public:
public:
Node_Type type();
bool has_children();
......
#define SASS_NODE_TYPE_INCLUDED
namespace Sass {
enum Node_Type {
none,
flags,
comment,
root,
ruleset,
propset,
selector_group,
selector,
selector_combinator,
simple_selector_sequence,
backref,
simple_selector,
type_selector,
class_selector,
id_selector,
pseudo,
pseudo_negation,
functional_pseudo,
attribute_selector,
block,
rule,
property,
nil,
comma_list,
space_list,
disjunction,
conjunction,
relation,
eq,
neq,
gt,
gte,
lt,
lte,
expression,
add,
sub,
term,
mul,
div,
factor,
unary_plus,
unary_minus,
values,
value,
identifier,
uri,
textual_percentage,
textual_dimension,
textual_number,
textual_hex,
color_name,
string_constant,
number,
numeric_percentage,
numeric_dimension,
numeric_color,
boolean,
important,
value_schema,
string_schema,
css_import,
function_call,
mixin,
parameters,
expansion,
arguments,
variable,
assignment
};
}
\ 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