Skip to content

Commit 3313d98

Browse files
committed
Add base class Value for AST node sass values
1 parent 3fc4540 commit 3313d98

File tree

4 files changed

+29
-15
lines changed

4 files changed

+29
-15
lines changed

ast.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ namespace Sass {
945945
}
946946

947947
Number::Number(ParserState pstate, double val, string u, bool zero)
948-
: Expression(pstate),
948+
: Value(pstate),
949949
value_(val),
950950
zero_(zero),
951951
numerator_units_(vector<string>()),

ast.hpp

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,18 @@ namespace Sass {
130130
virtual void set_delayed(bool delayed) { is_delayed(delayed); }
131131
virtual size_t hash() { return 0; }
132132
};
133+
134+
//////////////////////////////////////////////////////////////////////
135+
// base class for values that support operations
136+
//////////////////////////////////////////////////////////////////////
137+
class Value : public Expression {
138+
public:
139+
Value(ParserState pstate,
140+
bool d = false, bool e = false, bool i = false, Concrete_Type ct = NONE)
141+
: Expression(pstate, d, e, i, ct)
142+
{ }
143+
virtual bool operator== (Expression& rhs) const = 0;
144+
};
133145
}
134146

135147

@@ -756,15 +768,15 @@ namespace Sass {
756768
// Lists of values, both comma- and space-separated (distinguished by a
757769
// type-tag.) Also used to represent variable-length argument lists.
758770
///////////////////////////////////////////////////////////////////////
759-
class List : public Expression, public Vectorized<Expression*> {
771+
class List : public Value, public Vectorized<Expression*> {
760772
void adjust_after_pushing(Expression* e) { is_expanded(false); }
761773
private:
762774
ADD_PROPERTY(enum Sass_Separator, separator)
763775
ADD_PROPERTY(bool, is_arglist)
764776
public:
765777
List(ParserState pstate,
766778
size_t size = 0, enum Sass_Separator sep = SASS_SPACE, bool argl = false)
767-
: Expression(pstate),
779+
: Value(pstate),
768780
Vectorized<Expression*>(size),
769781
separator_(sep), is_arglist_(argl)
770782
{ concrete_type(LIST); }
@@ -804,12 +816,12 @@ namespace Sass {
804816
///////////////////////////////////////////////////////////////////////
805817
// Key value paris.
806818
///////////////////////////////////////////////////////////////////////
807-
class Map : public Expression, public Hashed {
819+
class Map : public Value, public Hashed {
808820
void adjust_after_pushing(std::pair<Expression*, Expression*> p) { is_expanded(false); }
809821
public:
810822
Map(ParserState pstate,
811823
size_t size = 0)
812-
: Expression(pstate),
824+
: Value(pstate),
813825
Hashed(size)
814826
{ concrete_type(MAP); }
815827
string type() { return "map"; }
@@ -1170,7 +1182,7 @@ namespace Sass {
11701182
////////////////////////////////////////////////
11711183
// Numbers, percentages, dimensions, and colors.
11721184
////////////////////////////////////////////////
1173-
class Number : public Expression {
1185+
class Number : public Value {
11741186
ADD_PROPERTY(double, value)
11751187
ADD_PROPERTY(bool, zero)
11761188
vector<string> numerator_units_;
@@ -1181,6 +1193,8 @@ namespace Sass {
11811193
bool zero() { return zero_; }
11821194
vector<string>& numerator_units() { return numerator_units_; }
11831195
vector<string>& denominator_units() { return denominator_units_; }
1196+
const vector<string>& numerator_units() const { return numerator_units_; }
1197+
const vector<string>& denominator_units() const { return denominator_units_; }
11841198
string type() { return "number"; }
11851199
static string type_name() { return "number"; }
11861200
string unit() const;
@@ -1208,7 +1222,7 @@ namespace Sass {
12081222
//////////
12091223
// Colors.
12101224
//////////
1211-
class Color : public Expression {
1225+
class Color : public Value {
12121226
ADD_PROPERTY(double, r)
12131227
ADD_PROPERTY(double, g)
12141228
ADD_PROPERTY(double, b)
@@ -1218,7 +1232,7 @@ namespace Sass {
12181232
size_t hash_;
12191233
public:
12201234
Color(ParserState pstate, double r, double g, double b, double a = 1, bool sixtuplet = true, const string disp = "")
1221-
: Expression(pstate), r_(r), g_(g), b_(b), a_(a), sixtuplet_(sixtuplet), disp_(disp),
1235+
: Value(pstate), r_(r), g_(g), b_(b), a_(a), sixtuplet_(sixtuplet), disp_(disp),
12221236
hash_(0)
12231237
{ concrete_type(COLOR); }
12241238
string type() { return "color"; }
@@ -1255,12 +1269,12 @@ namespace Sass {
12551269
////////////
12561270
// Booleans.
12571271
////////////
1258-
class Boolean : public Expression {
1272+
class Boolean : public Value {
12591273
ADD_PROPERTY(bool, value)
12601274
size_t hash_;
12611275
public:
12621276
Boolean(ParserState pstate, bool val)
1263-
: Expression(pstate), value_(val),
1277+
: Value(pstate), value_(val),
12641278
hash_(0)
12651279
{ concrete_type(BOOLEAN); }
12661280
virtual operator bool() { return value_; }
@@ -1297,11 +1311,11 @@ namespace Sass {
12971311
// Abstract base class for Sass string values. Includes interpolated and
12981312
// "flat" strings.
12991313
////////////////////////////////////////////////////////////////////////
1300-
class String : public Expression {
1314+
class String : public Value {
13011315
ADD_PROPERTY(bool, sass_fix_1291)
13021316
public:
13031317
String(ParserState pstate, bool delayed = false, bool sass_fix_1291 = false)
1304-
: Expression(pstate, delayed), sass_fix_1291_(sass_fix_1291)
1318+
: Value(pstate, delayed), sass_fix_1291_(sass_fix_1291)
13051319
{ concrete_type(STRING); }
13061320
static string type_name() { return "string"; }
13071321
virtual ~String() = 0;
@@ -1565,9 +1579,9 @@ namespace Sass {
15651579
//////////////////
15661580
// The null value.
15671581
//////////////////
1568-
class Null : public Expression {
1582+
class Null : public Value {
15691583
public:
1570-
Null(ParserState pstate) : Expression(pstate) { concrete_type(NULL_VAL); }
1584+
Null(ParserState pstate) : Value(pstate) { concrete_type(NULL_VAL); }
15711585
string type() { return "null"; }
15721586
static string type_name() { return "null"; }
15731587
bool is_invisible() const { return true; }

ast_fwd_decl.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ namespace Sass {
3838
class Definition;
3939
class Mixin_Call;
4040
// expressions
41+
class Value;
4142
class Expression;
4243
class List;
4344
class Map;

context.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,5 +553,4 @@ namespace Sass {
553553
(*env)[def->name() + "[f]"] = def;
554554
}
555555

556-
557556
}

0 commit comments

Comments
 (0)