Skip to content

Commit 451980e

Browse files
committed
Merge pull request #1346 from mgreter/feature/code-clean-ups
Code clean ups from preparation branch
2 parents cb62a37 + cc7136c commit 451980e

31 files changed

+578
-382
lines changed

Makefile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,18 +159,20 @@ SOURCES = \
159159
constants.cpp \
160160
context.cpp \
161161
cssize.cpp \
162-
listize.cpp \
162+
emitter.cpp \
163+
environment.cpp \
163164
error_handling.cpp \
164165
eval.cpp \
165166
expand.cpp \
166167
extend.cpp \
167168
file.cpp \
168169
functions.cpp \
169170
inspect.cpp \
171+
json.cpp \
170172
lexer.cpp \
173+
listize.cpp \
174+
memory_manager.cpp \
171175
node.cpp \
172-
json.cpp \
173-
emitter.cpp \
174176
output.cpp \
175177
parser.cpp \
176178
plugins.cpp \
@@ -308,4 +310,4 @@ lib-opts-shared:
308310
install install-static install-shared \
309311
lib-opts lib-opts-shared lib-opts-static \
310312
lib-file lib-file-shared lib-file-static
311-
.DELETE_ON_ERROR:
313+
.DELETE_ON_ERROR:

Makefile.am

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ lib_LTLIBRARIES = libsass.la
3131

3232
libsass_la_SOURCES = \
3333
ast_fwd_decl.hpp ast_def_macros.hpp \
34-
kwd_arg_macros.hpp memory_manager.hpp \
34+
kwd_arg_macros.hpp \
3535
position.cpp position.hpp \
3636
operation.hpp \
3737
subset_map.hpp mapping.hpp \
3838
color_names.hpp backtrace.hpp \
3939
cencode.c b64/cencode.h b64/encode.h \
40-
token.hpp environment.hpp \
40+
token.hpp \
4141
paths.hpp debug.hpp \
4242
utf8.h utf8/core.h \
4343
utf8/checked.h utf8/unchecked.h \
@@ -46,6 +46,7 @@ libsass_la_SOURCES = \
4646
bind.cpp bind.hpp \
4747
constants.cpp constants.hpp \
4848
context.cpp context.hpp \
49+
environment.cpp environment.hpp \
4950
error_handling.cpp error_handling.hpp \
5051
eval.cpp eval.hpp \
5152
expand.cpp expand.hpp \
@@ -56,6 +57,7 @@ libsass_la_SOURCES = \
5657
functions.cpp functions.hpp \
5758
inspect.cpp inspect.hpp \
5859
lexer.cpp lexer.hpp \
60+
memory_manager.cpp memory_manager.hpp \
5961
node.cpp node.hpp \
6062
json.cpp json.hpp \
6163
emitter.cpp emitter.hpp \

ast.hpp

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848

4949
#include "sass.h"
5050
#include "sass_values.h"
51+
#include "sass_context.h"
5152
#include "sass_functions.h"
5253

5354
namespace Sass {
@@ -122,7 +123,7 @@ namespace Sass {
122123
virtual operator bool() { return true; }
123124
virtual ~Expression() { }
124125
virtual string type() { return ""; /* TODO: raise an error? */ }
125-
virtual bool is_invisible() { return false; }
126+
virtual bool is_invisible() const { return false; }
126127
static string type_name() { return ""; }
127128
virtual bool is_false() { return false; }
128129
virtual bool operator==( Expression& rhs) const { return false; }
@@ -177,7 +178,7 @@ namespace Sass {
177178
size_t length() const { return elements_.size(); }
178179
bool empty() const { return elements_.empty(); }
179180
T last() { return elements_.back(); }
180-
T first() { return elements_.front(); }
181+
T first() { return elements_.front(); }
181182
T& operator[](size_t i) { return elements_[i]; }
182183
const T& operator[](size_t i) const { return elements_[i]; }
183184
Vectorized& operator<<(T element)
@@ -259,6 +260,12 @@ namespace Sass {
259260
}
260261
const unordered_map<Expression*, Expression*>& pairs() const { return elements_; }
261262
const vector<Expression*>& keys() const { return list_; }
263+
264+
unordered_map<Expression*, Expression*>::iterator end() { return elements_.end(); }
265+
unordered_map<Expression*, Expression*>::iterator begin() { return elements_.begin(); }
266+
unordered_map<Expression*, Expression*>::const_iterator end() const { return elements_.end(); }
267+
unordered_map<Expression*, Expression*>::const_iterator begin() const { return elements_.begin(); }
268+
262269
};
263270
inline Hashed::~Hashed() { }
264271

@@ -292,7 +299,7 @@ namespace Sass {
292299
virtual ~Statement() = 0;
293300
// needed for rearranging nested rulesets during CSS emission
294301
virtual bool is_hoistable() { return false; }
295-
virtual bool is_invisible() { return false; }
302+
virtual bool is_invisible() const { return false; }
296303
virtual bool bubbles() { return false; }
297304
virtual Block* block() { return 0; }
298305
};
@@ -347,7 +354,7 @@ namespace Sass {
347354
Ruleset(ParserState pstate, Selector* s = 0, Block* b = 0)
348355
: Has_Block(pstate, b), selector_(s), at_root_(false)
349356
{ statement_type(RULESET); }
350-
bool is_invisible();
357+
bool is_invisible() const;
351358
// nested rulesets need to be hoisted out of their enclosing blocks
352359
bool is_hoistable() { return true; }
353360
ATTACH_OPERATIONS()
@@ -393,7 +400,7 @@ namespace Sass {
393400
{ statement_type(MEDIA); }
394401
bool bubbles() { return true; }
395402
bool is_hoistable() { return true; }
396-
bool is_invisible() {
403+
bool is_invisible() const {
397404
bool is_invisible = true;
398405
for (size_t i = 0, L = block()->length(); i < L && is_invisible; i++)
399406
is_invisible &= (*block())[i]->is_invisible();
@@ -571,13 +578,12 @@ namespace Sass {
571578
////////////////////////////////////
572579
// The Sass `@if` control directive.
573580
////////////////////////////////////
574-
class If : public Statement {
581+
class If : public Has_Block {
575582
ADD_PROPERTY(Expression*, predicate)
576-
ADD_PROPERTY(Block*, consequent)
577583
ADD_PROPERTY(Block*, alternative)
578584
public:
579585
If(ParserState pstate, Expression* pred, Block* con, Block* alt = 0)
580-
: Statement(pstate), predicate_(pred), consequent_(con), alternative_(alt)
586+
: Has_Block(pstate, con), predicate_(pred), alternative_(alt)
581587
{ }
582588
ATTACH_OPERATIONS()
583589
};
@@ -752,21 +758,19 @@ namespace Sass {
752758
///////////////////////////////////////////////////////////////////////
753759
class List : public Expression, public Vectorized<Expression*> {
754760
void adjust_after_pushing(Expression* e) { is_expanded(false); }
755-
public:
756-
enum Separator { SPACE, COMMA };
757761
private:
758-
ADD_PROPERTY(Separator, separator)
762+
ADD_PROPERTY(enum Sass_Separator, separator)
759763
ADD_PROPERTY(bool, is_arglist)
760764
public:
761765
List(ParserState pstate,
762-
size_t size = 0, Separator sep = SPACE, bool argl = false)
766+
size_t size = 0, enum Sass_Separator sep = SASS_SPACE, bool argl = false)
763767
: Expression(pstate),
764768
Vectorized<Expression*>(size),
765769
separator_(sep), is_arglist_(argl)
766770
{ concrete_type(LIST); }
767771
string type() { return is_arglist_ ? "arglist" : "list"; }
768772
static string type_name() { return "list"; }
769-
bool is_invisible() { return !length(); }
773+
bool is_invisible() const { return empty(); }
770774
Expression* value_at_index(size_t i);
771775

772776
virtual size_t size() const;
@@ -777,7 +781,7 @@ namespace Sass {
777781
{
778782
if (hash_ > 0) return hash_;
779783

780-
hash_ = std::hash<string>()(separator() == COMMA ? "comma" : "space");
784+
hash_ = std::hash<string>()(separator() == SASS_COMMA ? "comma" : "space");
781785
for (size_t i = 0, L = length(); i < L; ++i)
782786
hash_combine(hash_, (elements()[i])->hash());
783787

@@ -807,7 +811,7 @@ namespace Sass {
807811
{ concrete_type(MAP); }
808812
string type() { return "map"; }
809813
static string type_name() { return "map"; }
810-
bool is_invisible() { return !length(); }
814+
bool is_invisible() const { return empty(); }
811815

812816
virtual bool operator==(Expression& rhs) const
813817
{
@@ -847,21 +851,14 @@ namespace Sass {
847851
// subclassing.
848852
//////////////////////////////////////////////////////////////////////////
849853
class Binary_Expression : public Expression {
850-
public:
851-
enum Type {
852-
AND, OR, // logical connectives
853-
EQ, NEQ, GT, GTE, LT, LTE, // arithmetic relations
854-
ADD, SUB, MUL, DIV, MOD, // arithmetic functions
855-
NUM_OPS // so we know how big to make the op table
856-
};
857854
private:
858-
ADD_PROPERTY(Type, type)
855+
ADD_PROPERTY(enum Sass_OP, type)
859856
ADD_PROPERTY(Expression*, left)
860857
ADD_PROPERTY(Expression*, right)
861858
size_t hash_;
862859
public:
863860
Binary_Expression(ParserState pstate,
864-
Type t, Expression* lhs, Expression* rhs)
861+
enum Sass_OP t, Expression* lhs, Expression* rhs)
865862
: Expression(pstate), type_(t), left_(lhs), right_(rhs), hash_(0)
866863
{ }
867864
const string type_name() {
@@ -1553,7 +1550,7 @@ namespace Sass {
15531550
Null(ParserState pstate) : Expression(pstate) { concrete_type(NULL_VAL); }
15541551
string type() { return "null"; }
15551552
static string type_name() { return "null"; }
1556-
bool is_invisible() { return true; }
1553+
bool is_invisible() const { return true; }
15571554
operator bool() { return false; }
15581555
bool is_false() { return true; }
15591556

@@ -2133,7 +2130,7 @@ namespace Sass {
21332130
ATTACH_OPERATIONS()
21342131
};
21352132

2136-
inline bool Ruleset::is_invisible() {
2133+
inline bool Ruleset::is_invisible() const {
21372134
bool is_invisible = true;
21382135
Selector_List* sl = static_cast<Selector_List*>(selector());
21392136
for (size_t i = 0, L = sl->length(); i < L && is_invisible; ++i)

ast_def_macros.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ virtual Statement* perform(Operation<Statement*>* op) { return (*op)(this); }\
3333
virtual Expression* perform(Operation<Expression*>* op) { return (*op)(this); }\
3434
virtual Selector* perform(Operation<Selector*>* op) { return (*op)(this); }\
3535
virtual string perform(Operation<string>* op) { return (*op)(this); }\
36-
virtual Sass_Value* perform(Operation<Sass_Value*>* op) { return (*op)(this); }
36+
virtual union Sass_Value* perform(Operation<union Sass_Value*>* op) { return (*op)(this); }
3737

3838
#define ADD_PROPERTY(type, name)\
3939
protected:\

ast_factory.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace Sass {
3737
Definition<FUNCTION>* new_Function_Definition(string p, size_t l, string n, Parameters* params, Block* b);
3838
Mixin_Call* new_Mixin_Call(string p, size_t l, string n, Arguments* args, Block* b = 0);
3939
// expressions
40-
List* new_List(string p, size_t l, size_t size = 0, List::Separator sep = List::space, bool argl = false);
40+
List* new_List(string p, size_t l, size_t size = 0, enum Sass_Separator sep = List::space, bool argl = false);
4141
Map* new_Map(string p, size_t l, size_t size = 0);
4242
Binary_Expression<AND>* new_And(string p, size_t l, Expression* lhs, Expression* rhs);
4343
Binary_Expression<OR>* new_Or(string p, size_t l, Expression* lhs, Expression* rhs);

bind.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ namespace Sass {
9898
} else if (a->is_keyword_argument()) {
9999

100100
// expand keyword arguments into their parameters
101-
List* arglist = new (ctx.mem) List(p->pstate(), 0, List::COMMA, true);
101+
List* arglist = new (ctx.mem) List(p->pstate(), 0, SASS_COMMA, true);
102102
env->local_frame()[p->name()] = arglist;
103103
Map* argmap = static_cast<Map*>(a->value());
104104
for (auto key : argmap->keys()) {
@@ -115,7 +115,7 @@ namespace Sass {
115115
// create a new list object for wrapped items
116116
List* arglist = new (ctx.mem) List(p->pstate(),
117117
0,
118-
List::COMMA,
118+
SASS_COMMA,
119119
true);
120120
// consume the next args
121121
while (ia < LA) {
@@ -238,7 +238,7 @@ namespace Sass {
238238
if (leftover->is_rest_parameter()) {
239239
env->local_frame()[leftover->name()] = new (ctx.mem) List(leftover->pstate(),
240240
0,
241-
List::COMMA,
241+
SASS_COMMA,
242242
true);
243243
}
244244
else if (leftover->default_value()) {

cssize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ namespace Sass {
480480
{
481481
List* qq = new (ctx.mem) List(m1->media_queries()->pstate(),
482482
m1->media_queries()->length(),
483-
List::COMMA);
483+
SASS_COMMA);
484484

485485
for (size_t i = 0, L = m1->media_queries()->length(); i < L; i++) {
486486
for (size_t j = 0, K = m2->media_queries()->length(); j < K; j++) {

debugger.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ inline void debug_ast(AST_Node* node, string ind = "", Env* env = 0)
283283
cerr << " (" << pstate_source_position(node) << ")";
284284
cerr << " " << block->tabs() << endl;
285285
debug_ast(block->predicate(), ind + " = ");
286-
debug_ast(block->consequent(), ind + " <>");
286+
debug_ast(block->block(), ind + " <>");
287287
debug_ast(block->alternative(), ind + " ><");
288288
} else if (dynamic_cast<Return*>(node)) {
289289
Return* block = dynamic_cast<Return*>(node);
@@ -480,7 +480,7 @@ inline void debug_ast(AST_Node* node, string ind = "", Env* env = 0)
480480
cerr << ind << "List " << expression;
481481
cerr << " (" << pstate_source_position(node) << ")";
482482
cerr << " (" << expression->length() << ") " <<
483-
(expression->separator() == Sass::List::Separator::COMMA ? "Comma " : "Space ") <<
483+
(expression->separator() == SASS_COMMA ? "Comma " : "Space ") <<
484484
" [delayed: " << expression->is_delayed() << "] " <<
485485
" [interpolant: " << expression->is_interpolant() << "] " <<
486486
" [arglist: " << expression->is_arglist() << "] " <<

0 commit comments

Comments
 (0)