Skip to content

Commit f348f71

Browse files
committed
Improve compiler compatibility for early gcc versions
1 parent 267df0d commit f348f71

File tree

11 files changed

+128
-67
lines changed

11 files changed

+128
-67
lines changed

src/ast.cpp

Lines changed: 17 additions & 21 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
{
@@ -151,7 +147,7 @@ namespace Sass {
151147

152148
bool SimpleSequence_Selector::has_parent_ref()
153149
{
154-
for (Simple_Selector* s : *this) {
150+
for (Simple_Selector* s : elements()) {
155151
if (s && s->has_parent_ref()) return true;
156152
}
157153
return false;
@@ -508,12 +504,12 @@ namespace Sass {
508504
}
509505

510506
SimpleSequence_Selector* Id_Selector::unify_with(SimpleSequence_Selector* rhs, Context& ctx)
511-
{
512-
for (size_t i = 0, L = rhs->length(); i < L; ++i)
513507
{
514-
Simple_Selector* rhs_i = (*rhs)[i];
508+
for (size_t i = 0, L = rhs->length(); i < L; ++i)
509+
{
510+
Simple_Selector* rhs_i = (*rhs)[i];
515511
if (typeid(*rhs_i) == typeid(Id_Selector) && static_cast<Id_Selector*>(rhs_i)->name() != name()) {
516-
return 0;
512+
return 0;
517513
}
518514
}
519515
rhs->has_line_break(has_line_break());
@@ -1093,7 +1089,7 @@ namespace Sass {
10931089

10941090
CommaSequence_Selector* CommaSequence_Selector::resolve_parent_refs(Context& ctx, CommaSequence_Selector* ps, bool implicit_parent)
10951091
{
1096-
if (!this->has_parent_ref()/* && !implicit_parent*/) return this;
1092+
if (!this->has_parent_ref()) return this;
10971093
CommaSequence_Selector* ss = SASS_MEMORY_NEW(ctx.mem, CommaSequence_Selector, pstate());
10981094
for (size_t pi = 0, pL = ps->length(); pi < pL; ++pi) {
10991095
CommaSequence_Selector* list = SASS_MEMORY_NEW(ctx.mem, CommaSequence_Selector, pstate());
@@ -1110,7 +1106,7 @@ namespace Sass {
11101106
Sequence_Selector* tail = this->tail();
11111107
SimpleSequence_Selector* head = this->head();
11121108

1113-
// first resolve_parent_refs the tail (which may return an expanded list)
1109+
// first parentize the tail (which may return an expanded list)
11141110
CommaSequence_Selector* tails = tail ? tail->resolve_parent_refs(ctx, parents, implicit_parent) : 0;
11151111

11161112
if (head && head->length() > 0) {
@@ -1189,7 +1185,7 @@ namespace Sass {
11891185
retval = this->tails(ctx, tails);
11901186
}
11911187

1192-
for (Simple_Selector* ss : *head) {
1188+
for (Simple_Selector* ss : head->elements()) {
11931189
if (Wrapped_Selector* ws = dynamic_cast<Wrapped_Selector*>(ss)) {
11941190
if (CommaSequence_Selector* sl = dynamic_cast<CommaSequence_Selector*>(ws->selector())) {
11951191
if (parents) ws->selector(sl->resolve_parent_refs(ctx, parents, implicit_parent));
@@ -1358,7 +1354,7 @@ namespace Sass {
13581354
}
13591355

13601356
/* not used anymore - remove?
1361-
Placeholder_Selector* Selector::find_placeholder()
1357+
Selector_Placeholder* Selector::find_placeholder()
13621358
{
13631359
return 0;
13641360
}*/
@@ -1390,7 +1386,7 @@ namespace Sass {
13901386

13911387
bool CommaSequence_Selector::has_parent_ref()
13921388
{
1393-
for (Sequence_Selector* s : *this) {
1389+
for (Sequence_Selector* s : elements()) {
13941390
if (s && s->has_parent_ref()) return true;
13951391
}
13961392
return false;
@@ -1470,7 +1466,7 @@ namespace Sass {
14701466
}
14711467
}
14721468

1473-
// Creates the final CommaSequence_Selector by combining all the complex selectors
1469+
// Creates the final Selector_List by combining all the complex selectors
14741470
CommaSequence_Selector* final_result = SASS_MEMORY_NEW(ctx.mem, CommaSequence_Selector, pstate());
14751471
for (auto itr = unified_complex_selectors.begin(); itr != unified_complex_selectors.end(); ++itr) {
14761472
*final_result << *itr;

src/ast.hpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ namespace Sass {
309309
virtual void adjust_after_pushing(std::pair<Expression*, Expression*> p) { }
310310
public:
311311
Hashed(size_t s = 0) : elements_(ExpressionMap(s)), list_(std::vector<Expression*>())
312-
{ elements_.reserve(s); list_.reserve(s); reset_duplicate_key(); }
312+
{ /* elements_.reserve(s); */ list_.reserve(s); reset_duplicate_key(); }
313313
virtual ~Hashed();
314314
size_t length() const { return list_.size(); }
315315
bool empty() const { return list_.empty(); }
@@ -1231,7 +1231,7 @@ namespace Sass {
12311231
if (hash_ == 0) {
12321232
hash_ = std::hash<std::string>()(name());
12331233
for (auto argument : arguments()->elements())
1234-
hash_combine(hash_, argument->hash());
1234+
{ hash_combine(hash_, argument->hash()); }
12351235
}
12361236
return hash_;
12371237
}
@@ -1359,10 +1359,12 @@ namespace Sass {
13591359
{
13601360
if (hash_ == 0) {
13611361
hash_ = std::hash<double>()(value_);
1362-
for (const auto numerator : numerator_units())
1362+
for (const auto numerator : numerator_units()) {
13631363
hash_combine(hash_, std::hash<std::string>()(numerator));
1364-
for (const auto denominator : denominator_units())
1364+
}
1365+
for (const auto denominator : denominator_units()) {
13651366
hash_combine(hash_, std::hash<std::string>()(denominator));
1367+
}
13661368
}
13671369
return hash_;
13681370
}
@@ -1512,7 +1514,7 @@ namespace Sass {
15121514
{
15131515
if (hash_ == 0) {
15141516
for (auto string : elements())
1515-
hash_combine(hash_, string->hash());
1517+
{ hash_combine(hash_, string->hash()); }
15161518
}
15171519
return hash_;
15181520
}

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
@@ -387,7 +387,7 @@ inline void debug_ast(AST_Node* node, std::string ind, Env* env)
387387
std::cerr << " (" << pstate_source_position(node) << ")";
388388
std::cerr << " " << block->tabs() << std::endl;
389389
// std::vector<std::string> files_;
390-
for (auto imp : block->urls()) debug_ast(imp, ind + "@: ", env);
390+
for (auto imp : block->urls()) { debug_ast(imp, ind + "@: ", env); }
391391
debug_ast(block->media_queries(), ind + "@@ ");
392392
} else if (dynamic_cast<Assignment*>(node)) {
393393
Assignment* block = dynamic_cast<Assignment*>(node);

src/eval.cpp

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

10371037
if (Arguments* args = dynamic_cast<Arguments*>(ex)) {
10381038
List* ll = SASS_MEMORY_NEW(ctx.mem, List, args->pstate(), 0, SASS_COMMA);
1039-
for(auto arg : *args) {
1039+
for(auto arg : args->elements()) {
10401040
*ll << arg->value();
10411041
}
10421042
ll->is_interpolant(args->is_interpolant());
@@ -1072,7 +1072,7 @@ namespace Sass {
10721072
List* ll = SASS_MEMORY_NEW(ctx.mem, List, l->pstate(), 0, l->separator());
10731073
// this fixes an issue with bourbon sample, not really sure why
10741074
// if (l->size() && dynamic_cast<Null*>((*l)[0])) { res += ""; }
1075-
for(auto item : *l) {
1075+
for(auto item : l->elements()) {
10761076
item->is_interpolant(l->is_interpolant());
10771077
std::string rl(""); interpolation(ctx, rl, item, into_quotes, l->is_interpolant());
10781078
bool is_null = dynamic_cast<Null*>(item) != 0; // rl != ""
@@ -1333,11 +1333,11 @@ namespace Sass {
13331333
true);
13341334

13351335
if (ls && ls->is_arglist()) {
1336-
for (auto as : *ls) *arglist << as;
1336+
for (auto as : ls->elements()) { *arglist << as; }
13371337
} else if (ms) {
13381338
*aa << SASS_MEMORY_NEW(ctx.mem, Argument, splat->pstate(), ms, "", false, true);
13391339
} else if (ls) {
1340-
for (auto as : *ls) *arglist << as;
1340+
for (auto as : ls->elements()) { *arglist << as; }
13411341
} else {
13421342
*arglist << splat;
13431343
}

src/expand.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ namespace Sass {
234234
Expression* value = d->value()->perform(&eval);
235235
Block* bb = ab ? ab->perform(this)->block() : 0;
236236
if (!bb) {
237-
if (!value || (value->is_invisible() && !d->is_important())) return 0;
237+
if (!value || (value->is_invisible() && !d->is_important())) return 0;
238238
}
239239
Declaration* decl = SASS_MEMORY_NEW(ctx.mem, Declaration,
240240
d->pstate(),
@@ -611,7 +611,7 @@ namespace Sass {
611611
if (schema->has_parent_ref()) s = eval(schema);
612612
}
613613
if (CommaSequence_Selector* sl = dynamic_cast<CommaSequence_Selector*>(s)) {
614-
for (Sequence_Selector* cs : *sl) {
614+
for (Sequence_Selector* cs : sl->elements()) {
615615
if (cs != NULL && cs->head() != NULL) {
616616
cs->head()->media_block(media_block_stack.back());
617617
}
@@ -689,7 +689,7 @@ namespace Sass {
689689

690690

691691
block_stack.push_back(trace_block);
692-
for (auto bb : *body) {
692+
for (auto bb : body->elements()) {
693693
Statement* ith = bb->perform(this);
694694
if (ith) *trace->block() << ith;
695695
}

src/extend.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ namespace Sass {
9494
return os;
9595
}
9696

97-
// Print a string representation of a SimpleSequence_Selector
97+
// Print a string representation of a Compound_Selector
9898
static void printSimpleSelector(Simple_Selector* pSimpleSelector, const char* message=NULL, bool newline=true) {
9999

100100
if (message) {
@@ -112,12 +112,12 @@ namespace Sass {
112112
}
113113
}
114114

115-
// Print a string representation of a SimpleSequence_Selector
115+
// Print a string representation of a Compound_Selector
116116
typedef std::pair<SimpleSequence_Selector*, Sequence_Selector*> SelsNewSeqPair;
117117
typedef std::vector<SelsNewSeqPair> SelsNewSeqPairCollection;
118118

119119

120-
// Print a string representation of a SimpleSequence_Selector
120+
// Print a string representation of a Compound_Selector
121121
static void printCompoundSelector(SimpleSequence_Selector* pCompoundSelector, const char* message=NULL, bool newline=true) {
122122

123123
if (message) {
@@ -169,7 +169,7 @@ namespace Sass {
169169
}
170170

171171

172-
// Print a string representation of a Sequence_Selector
172+
// Print a string representation of a Complex_Selector
173173
static void printComplexSelector(Sequence_Selector* pComplexSelector, const char* message=NULL, bool newline=true) {
174174

175175
if (message) {
@@ -288,7 +288,7 @@ namespace Sass {
288288
#endif
289289

290290
static bool parentSuperselector(Sequence_Selector* pOne, Sequence_Selector* pTwo, Context& ctx) {
291-
// TODO: figure out a better way to create a Sequence_Selector from scratch
291+
// TODO: figure out a better way to create a Complex_Selector from scratch
292292
// TODO: There's got to be a better way. This got ugly quick...
293293
Position noPosition(-1, -1, -1);
294294
Element_Selector fakeParent(ParserState("[FAKE]"), "temp");
@@ -651,7 +651,7 @@ namespace Sass {
651651

652652

653653
static bool parentSuperselector(const Node& one, const Node& two, Context& ctx) {
654-
// TODO: figure out a better way to create a Sequence_Selector from scratch
654+
// TODO: figure out a better way to create a Complex_Selector from scratch
655655
// TODO: There's got to be a better way. This got ugly quick...
656656
Position noPosition(-1, -1, -1);
657657
Element_Selector fakeParent(ParserState("[FAKE]"), "temp");
@@ -1588,7 +1588,7 @@ namespace Sass {
15881588
Sequence_Selector* pExtComplexSelector = &seq; // The selector up to where the @extend is (ie, the thing to merge)
15891589
SimpleSequence_Selector* pExtCompoundSelector = pSels; // All the simple selectors to be replaced from the current compound selector from all extensions
15901590

1591-
// TODO: This can return a SimpleSequence_Selector with no elements. Should that just be returning NULL?
1591+
// TODO: This can return a Compound_Selector with no elements. Should that just be returning NULL?
15921592
// RUBY: self_without_sel = Sass::Util.array_minus(members, sels)
15931593
SimpleSequence_Selector* pSelectorWithoutExtendSelectors = pSelector->minus(pExtCompoundSelector, ctx);
15941594

@@ -1618,8 +1618,8 @@ namespace Sass {
16181618
// next if group.map {|e, _| check_directives_match!(e, parent_directives)}.none?
16191619

16201620
// TODO: This seems a little fishy to me. See if it causes any problems. From the ruby, we should be able to just
1621-
// get rid of the last SimpleSequence_Selector and replace it with this one. I think the reason this code is more
1622-
// complex is that Sequence_Selector contains a combinator, but in ruby combinators have already been filtered
1621+
// get rid of the last Compound_Selector and replace it with this one. I think the reason this code is more
1622+
// complex is that Complex_Selector contains a combinator, but in ruby combinators have already been filtered
16231623
// out and aren't operated on.
16241624
Sequence_Selector* pNewSelector = pExtComplexSelector->cloneFully(ctx); // ->first();
16251625

@@ -1642,7 +1642,7 @@ namespace Sass {
16421642

16431643

16441644
// if (pSelector && pSelector->has_line_feed()) pNewInnerMost->has_line_feed(true);
1645-
// Set the sources on our new Sequence_Selector to the sources of this simple sequence plus the thing we're extending.
1645+
// Set the sources on our new Complex_Selector to the sources of this simple sequence plus the thing we're extending.
16461646
DEBUG_PRINTLN(EXTEND_COMPOUND, "SOURCES SETTING ON NEW SEQ: " << complexSelectorToNode(pNewSelector, ctx))
16471647

16481648
DEBUG_EXEC(EXTEND_COMPOUND, SourcesSet oldSet = pNewSelector->sources(); printSourcesSet(oldSet, ctx, "SOURCES NEW SEQ BEGIN: "))
@@ -1723,7 +1723,7 @@ namespace Sass {
17231723

17241724
if (pHead) {
17251725
if (seen.find(*pHead) == seen.end()) {
1726-
for (Simple_Selector* pSimple : *pHead) {
1726+
for (Simple_Selector* pSimple : pHead->elements()) {
17271727
if (Wrapped_Selector* ws = dynamic_cast<Wrapped_Selector*>(pSimple)) {
17281728
if (CommaSequence_Selector* sl = dynamic_cast<CommaSequence_Selector*>(ws->selector())) {
17291729
for (Sequence_Selector* cs : sl->elements()) {
@@ -1809,7 +1809,7 @@ namespace Sass {
18091809
// RUBY: next [[sseq_or_op]] unless sseq_or_op.is_a?(SimpleSequence)
18101810
if (!sseqOrOp.isSelector()) {
18111811
// Wrap our Combinator in two collections to match ruby. This is essentially making a collection Node
1812-
// with one collection child. The collection child represents a Sequence_Selector that is only a combinator.
1812+
// with one collection child. The collection child represents a Complex_Selector that is only a combinator.
18131813
Node outer = Node::createCollection();
18141814
Node inner = Node::createCollection();
18151815
outer.collection()->push_back(inner);
@@ -1826,7 +1826,7 @@ namespace Sass {
18261826
DEBUG_PRINTLN(EXTEND_COMPLEX, "EXTENDED: " << extended)
18271827

18281828

1829-
// Prepend the SimpleSequence_Selector based on the choices logic; choices seems to be extend but with an ruby Array instead of a Sequence
1829+
// Prepend the Compound_Selector based on the choices logic; choices seems to be extend but with an ruby Array instead of a Sequence
18301830
// due to the member mapping: choices = extended.map {|seq| seq.members}
18311831
Sequence_Selector* pJustCurrentCompoundSelector = sseqOrOp.selector();
18321832

@@ -1961,7 +1961,7 @@ namespace Sass {
19611961
pNewSelectors = remove_placeholders.remove_placeholders(pNewSelectors);
19621962

19631963
// unwrap all wrapped selectors with inner lists
1964-
for (Sequence_Selector* cur : *pNewSelectors) {
1964+
for (Sequence_Selector* cur : pNewSelectors->elements()) {
19651965
// process tails
19661966
while (cur) {
19671967
// process header
@@ -1970,7 +1970,7 @@ namespace Sass {
19701970
recseen.insert(*cur->head());
19711971
// create a copy since we add multiple items if stuff get unwrapped
19721972
SimpleSequence_Selector* cpy_head = SASS_MEMORY_NEW(ctx.mem, SimpleSequence_Selector, cur->pstate());
1973-
for (Simple_Selector* hs : *cur->head()) {
1973+
for (Simple_Selector* hs : cur->head()->elements()) {
19741974
if (Wrapped_Selector* ws = dynamic_cast<Wrapped_Selector*>(hs)) {
19751975
if (CommaSequence_Selector* sl = dynamic_cast<CommaSequence_Selector*>(ws->selector())) {
19761976
// special case for ruby ass
@@ -2092,7 +2092,8 @@ namespace Sass {
20922092
// we set `extended` flag on extended selectors
20932093
if (b->is_root()) {
20942094
// debug_subset_map(subset_map);
2095-
for(auto const &it : subset_map.values()) {
2095+
auto values = subset_map.values();
2096+
for(auto it : values) {
20962097
Sequence_Selector* sel = it.first ? it.first->first() : NULL;
20972098
SimpleSequence_Selector* ext = it.second ? it.second : NULL;
20982099
if (ext && (ext->extended() || ext->is_optional())) continue;
@@ -2127,7 +2128,7 @@ namespace Sass {
21272128

21282129
void Extend::operator()(Directive* a)
21292130
{
2130-
// CommaSequence_Selector* ls = dynamic_cast<CommaSequence_Selector*>(a->selector());
2131+
// Selector_List* ls = dynamic_cast<Selector_List*>(a->selector());
21312132
// selector_stack.push_back(ls);
21322133
if (a->block()) a->block()->perform(this);
21332134
// exp.selector_stack.pop_back();

0 commit comments

Comments
 (0)