Skip to content

Commit 69e6552

Browse files
committed
Improve compiler compatibility for early gcc versions
1 parent 5b92405 commit 69e6552

File tree

11 files changed

+131
-70
lines changed

11 files changed

+131
-70
lines changed

src/ast.cpp

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,23 @@ namespace Sass {
2828
dynamic_cast<Supports_Operator*>(cond);
2929
}
3030

31-
std::string & str_ltrim(std::string & str)
31+
void str_rtrim(std::string& s, const std::string& delimiters = " \f\n\r\t\v" )
3232
{
33-
auto it2 = std::find_if( str.begin() , str.end() , [](char ch){ return !std::isspace<char>(ch , std::locale::classic() ) ; } );
34-
str.erase( str.begin() , it2);
35-
return str;
33+
s.erase( s.find_last_not_of( delimiters ) + 1 );
3634
}
3735

38-
std::string & str_rtrim(std::string & str)
36+
void str_ltrim(std::string& s, const std::string& delimiters = " \f\n\r\t\v" )
3937
{
40-
auto it1 = std::find_if( str.rbegin() , str.rend() , [](char ch){ return !std::isspace<char>(ch , std::locale::classic() ) ; } );
41-
str.erase( it1.base() , str.end() );
42-
return str;
38+
s.erase( 0, s.find_first_not_of( delimiters ) );
4339
}
4440

4541
void String_Constant::rtrim()
4642
{
47-
value_ = str_rtrim(value_);
43+
str_rtrim(value_);
4844
}
4945
void String_Constant::ltrim()
5046
{
51-
value_ = str_ltrim(value_);
47+
str_ltrim(value_);
5248
}
5349
void String_Constant::trim()
5450
{
@@ -156,15 +152,15 @@ namespace Sass {
156152

157153
bool SimpleSequence_Selector::has_parent_ref()
158154
{
159-
for (Simple_Selector* s : *this) {
155+
for (Simple_Selector* s : elements()) {
160156
if (s && s->has_parent_ref()) return true;
161157
}
162158
return false;
163159
}
164160

165161
bool SimpleSequence_Selector::has_real_parent_ref()
166162
{
167-
for (Simple_Selector* s : *this) {
163+
for (Simple_Selector* s : elements()) {
168164
if (s && s->has_real_parent_ref()) return true;
169165
}
170166
return false;
@@ -527,12 +523,12 @@ namespace Sass {
527523
}
528524

529525
SimpleSequence_Selector* Id_Selector::unify_with(SimpleSequence_Selector* rhs, Context& ctx)
530-
{
531-
for (size_t i = 0, L = rhs->length(); i < L; ++i)
532526
{
533-
Simple_Selector* rhs_i = (*rhs)[i];
527+
for (size_t i = 0, L = rhs->length(); i < L; ++i)
528+
{
529+
Simple_Selector* rhs_i = (*rhs)[i];
534530
if (typeid(*rhs_i) == typeid(Id_Selector) && static_cast<Id_Selector*>(rhs_i)->name() != name()) {
535-
return 0;
531+
return 0;
536532
}
537533
}
538534
rhs->has_line_break(has_line_break());
@@ -1120,7 +1116,7 @@ namespace Sass {
11201116

11211117
CommaSequence_Selector* CommaSequence_Selector::resolve_parent_refs(Context& ctx, CommaSequence_Selector* ps, bool implicit_parent)
11221118
{
1123-
if (!this->has_parent_ref()/* && !implicit_parent*/) return this;
1119+
if (!this->has_parent_ref()) return this;
11241120
CommaSequence_Selector* ss = SASS_MEMORY_NEW(ctx.mem, CommaSequence_Selector, pstate());
11251121
for (size_t pi = 0, pL = ps->length(); pi < pL; ++pi) {
11261122
CommaSequence_Selector* list = SASS_MEMORY_NEW(ctx.mem, CommaSequence_Selector, pstate());
@@ -1143,7 +1139,7 @@ namespace Sass {
11431139
return retval;
11441140
}
11451141

1146-
// first resolve_parent_refs the tail (which may return an expanded list)
1142+
// first parentize the tail (which may return an expanded list)
11471143
CommaSequence_Selector* tails = tail ? tail->resolve_parent_refs(ctx, parents, implicit_parent) : 0;
11481144

11491145
if (head && head->length() > 0) {
@@ -1244,7 +1240,7 @@ namespace Sass {
12441240
retval = this->tails(ctx, tails);
12451241
}
12461242

1247-
for (Simple_Selector* ss : *head) {
1243+
for (Simple_Selector* ss : head->elements()) {
12481244
if (Wrapped_Selector* ws = dynamic_cast<Wrapped_Selector*>(ss)) {
12491245
if (CommaSequence_Selector* sl = dynamic_cast<CommaSequence_Selector*>(ws->selector())) {
12501246
if (parents) ws->selector(sl->resolve_parent_refs(ctx, parents, implicit_parent));
@@ -1413,7 +1409,7 @@ namespace Sass {
14131409
}
14141410

14151411
/* not used anymore - remove?
1416-
Placeholder_Selector* Selector::find_placeholder()
1412+
Selector_Placeholder* Selector::find_placeholder()
14171413
{
14181414
return 0;
14191415
}*/
@@ -1445,15 +1441,15 @@ namespace Sass {
14451441

14461442
bool CommaSequence_Selector::has_parent_ref()
14471443
{
1448-
for (Sequence_Selector* s : *this) {
1444+
for (Sequence_Selector* s : elements()) {
14491445
if (s && s->has_parent_ref()) return true;
14501446
}
14511447
return false;
14521448
}
14531449

14541450
bool CommaSequence_Selector::has_real_parent_ref()
14551451
{
1456-
for (Sequence_Selector* s : *this) {
1452+
for (Sequence_Selector* s : elements()) {
14571453
if (s && s->has_real_parent_ref()) return true;
14581454
}
14591455
return false;
@@ -1542,7 +1538,7 @@ namespace Sass {
15421538
}
15431539
}
15441540

1545-
// Creates the final CommaSequence_Selector by combining all the complex selectors
1541+
// Creates the final Selector_List by combining all the complex selectors
15461542
CommaSequence_Selector* final_result = SASS_MEMORY_NEW(ctx.mem, CommaSequence_Selector, pstate());
15471543
for (auto itr = unified_complex_selectors.begin(); itr != unified_complex_selectors.end(); ++itr) {
15481544
*final_result << *itr;
@@ -1695,8 +1691,8 @@ namespace Sass {
16951691

16961692
bool Ruleset::is_invisible() const {
16971693
if (CommaSequence_Selector* sl = dynamic_cast<CommaSequence_Selector*>(selector())) {
1698-
for (size_t i = 0, L = sl->length(); i < L; ++i)
1699-
if (!(*sl)[i]->has_placeholder()) return false;
1694+
for (size_t i = 0, L = sl->length(); i < L; ++i)
1695+
if (!(*sl)[i]->has_placeholder()) return false;
17001696
}
17011697
return true;
17021698
}

src/ast.hpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ namespace Sass {
311311
virtual void adjust_after_pushing(std::pair<Expression*, Expression*> p) { }
312312
public:
313313
Hashed(size_t s = 0) : elements_(ExpressionMap(s)), list_(std::vector<Expression*>())
314-
{ elements_.reserve(s); list_.reserve(s); reset_duplicate_key(); }
314+
{ /* elements_.reserve(s); */ list_.reserve(s); reset_duplicate_key(); }
315315
virtual ~Hashed();
316316
size_t length() const { return list_.size(); }
317317
bool empty() const { return list_.empty(); }
@@ -1224,7 +1224,7 @@ namespace Sass {
12241224
if (hash_ == 0) {
12251225
hash_ = std::hash<std::string>()(name());
12261226
for (auto argument : arguments()->elements())
1227-
hash_combine(hash_, argument->hash());
1227+
{ hash_combine(hash_, argument->hash()); }
12281228
}
12291229
return hash_;
12301230
}
@@ -1352,10 +1352,12 @@ namespace Sass {
13521352
{
13531353
if (hash_ == 0) {
13541354
hash_ = std::hash<double>()(value_);
1355-
for (const auto numerator : numerator_units())
1355+
for (const auto numerator : numerator_units()) {
13561356
hash_combine(hash_, std::hash<std::string>()(numerator));
1357-
for (const auto denominator : denominator_units())
1357+
}
1358+
for (const auto denominator : denominator_units()) {
13581359
hash_combine(hash_, std::hash<std::string>()(denominator));
1360+
}
13591361
}
13601362
return hash_;
13611363
}
@@ -1506,7 +1508,7 @@ namespace Sass {
15061508
{
15071509
if (hash_ == 0) {
15081510
for (auto string : elements())
1509-
hash_combine(hash_, string->hash());
1511+
{ hash_combine(hash_, string->hash()); }
15101512
}
15111513
return hash_;
15121514
}

src/check_nesting.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ namespace Sass {
6969
}
7070

7171
if (b) {
72-
for (auto n : *b) {
72+
for (auto n : b->elements()) {
7373
n->perform(this);
7474
}
7575
}

src/context.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ namespace Sass {
9898
collect_plugin_paths(c_options.plugin_paths);
9999

100100
// load plugins and register custom behaviors
101-
for(auto plug : plugin_paths) plugins.load_plugins(plug);
102-
for(auto fn : plugins.get_headers()) c_headers.push_back(fn);
103-
for(auto fn : plugins.get_importers()) c_importers.push_back(fn);
104-
for(auto fn : plugins.get_functions()) c_functions.push_back(fn);
101+
for(auto plug : plugin_paths) { plugins.load_plugins(plug); }
102+
for(auto fn : plugins.get_headers()) { c_headers.push_back(fn); }
103+
for(auto fn : plugins.get_importers()) { c_importers.push_back(fn); }
104+
for(auto fn : plugins.get_functions()) { c_functions.push_back(fn); }
105105

106106
// sort the items by priority (lowest first)
107107
sort (c_headers.begin(), c_headers.end(), sort_importers);

src/debugger.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ inline void debug_ast(AST_Node* node, std::string ind, Env* env)
394394
std::cerr << " (" << pstate_source_position(node) << ")";
395395
std::cerr << " " << block->tabs() << std::endl;
396396
// std::vector<std::string> files_;
397-
for (auto imp : block->urls()) debug_ast(imp, ind + "@: ", env);
397+
for (auto imp : block->urls()) { debug_ast(imp, ind + "@: ", env); }
398398
debug_ast(block->media_queries(), ind + "@@ ");
399399
} else if (dynamic_cast<Assignment*>(node)) {
400400
Assignment* block = dynamic_cast<Assignment*>(node);

src/eval.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,7 +1053,7 @@ namespace Sass {
10531053

10541054
if (Arguments* args = dynamic_cast<Arguments*>(ex)) {
10551055
List* ll = SASS_MEMORY_NEW(ctx.mem, List, args->pstate(), 0, SASS_COMMA);
1056-
for(auto arg : *args) {
1056+
for(auto arg : args->elements()) {
10571057
*ll << arg->value();
10581058
}
10591059
ll->is_interpolant(args->is_interpolant());
@@ -1089,7 +1089,7 @@ namespace Sass {
10891089
List* ll = SASS_MEMORY_NEW(ctx.mem, List, l->pstate(), 0, l->separator());
10901090
// this fixes an issue with bourbon sample, not really sure why
10911091
// if (l->size() && dynamic_cast<Null*>((*l)[0])) { res += ""; }
1092-
for(auto item : *l) {
1092+
for(auto item : l->elements()) {
10931093
item->is_interpolant(l->is_interpolant());
10941094
std::string rl(""); interpolation(ctx, rl, item, into_quotes, l->is_interpolant());
10951095
bool is_null = dynamic_cast<Null*>(item) != 0; // rl != ""
@@ -1351,11 +1351,11 @@ namespace Sass {
13511351
true);
13521352

13531353
if (ls && ls->is_arglist()) {
1354-
for (auto as : *ls) *arglist << as;
1354+
for (auto as : ls->elements()) { *arglist << as; }
13551355
} else if (ms) {
13561356
*aa << SASS_MEMORY_NEW(ctx.mem, Argument, splat->pstate(), ms, "", false, true);
13571357
} else if (ls) {
1358-
for (auto as : *ls) *arglist << as;
1358+
for (auto as : ls->elements()) { *arglist << as; }
13591359
} else {
13601360
*arglist << splat;
13611361
}

src/expand.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ namespace Sass {
238238
Expression* value = d->value()->perform(&eval);
239239
Block* bb = ab ? ab->perform(this)->block() : 0;
240240
if (!bb) {
241-
if (!value || (value->is_invisible() && !d->is_important())) return 0;
241+
if (!value || (value->is_invisible() && !d->is_important())) return 0;
242242
}
243243
Declaration* decl = SASS_MEMORY_NEW(ctx.mem, Declaration,
244244
d->pstate(),
@@ -615,7 +615,7 @@ namespace Sass {
615615
if (schema->has_parent_ref()) s = eval(schema);
616616
}
617617
if (CommaSequence_Selector* sl = dynamic_cast<CommaSequence_Selector*>(s)) {
618-
for (Sequence_Selector* cs : *sl) {
618+
for (Sequence_Selector* cs : sl->elements()) {
619619
if (cs != NULL && cs->head() != NULL) {
620620
cs->head()->media_block(media_block_stack.back());
621621
}
@@ -699,7 +699,7 @@ namespace Sass {
699699

700700

701701
block_stack.push_back(trace_block);
702-
for (auto bb : *body) {
702+
for (auto bb : body->elements()) {
703703
Statement* ith = bb->perform(this);
704704
if (ith) *trace->block() << ith;
705705
}

0 commit comments

Comments
 (0)