Skip to content

Commit dea8ceb

Browse files
committed
Improve compiler compatibility for early gcc versions
1 parent dba57b2 commit dea8ceb

File tree

9 files changed

+107
-39
lines changed

9 files changed

+107
-39
lines changed

src/ast.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,15 @@ namespace Sass {
129129

130130
bool Compound_Selector::has_parent_ref() const
131131
{
132-
for (Simple_Selector_Obj s : *this) {
132+
for (Simple_Selector_Obj s : elements()) {
133133
if (s && s->has_parent_ref()) return true;
134134
}
135135
return false;
136136
}
137137

138138
bool Compound_Selector::has_real_parent_ref() const
139139
{
140-
for (Simple_Selector_Obj s : *this) {
140+
for (Simple_Selector_Obj s : elements()) {
141141
if (s && s->has_real_parent_ref()) return true;
142142
}
143143
return false;

src/ast.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ namespace Sass {
363363
: elements_(ExpressionMap(s)),
364364
list_(std::vector<Expression_Obj>()),
365365
hash_(0), duplicate_key_(NULL)
366-
{ elements_.reserve(s); list_.reserve(s); }
366+
{ list_.reserve(s); reset_duplicate_key(); }
367367
virtual ~Hashed();
368368
size_t length() const { return list_.size(); }
369369
bool empty() const { return list_.empty(); }
@@ -1474,7 +1474,7 @@ namespace Sass {
14741474
if (hash_ == 0) {
14751475
hash_ = std::hash<std::string>()(name());
14761476
for (auto argument : arguments()->elements())
1477-
hash_combine(hash_, argument->hash());
1477+
{ hash_combine(hash_, argument->hash()); }
14781478
}
14791479
return hash_;
14801480
}
@@ -1579,9 +1579,9 @@ namespace Sass {
15791579
if (hash_ == 0) {
15801580
hash_ = std::hash<double>()(value_);
15811581
for (const auto numerator : numerator_units())
1582-
hash_combine(hash_, std::hash<std::string>()(numerator));
1582+
{ hash_combine(hash_, std::hash<std::string>()(numerator)); }
15831583
for (const auto denominator : denominator_units())
1584-
hash_combine(hash_, std::hash<std::string>()(denominator));
1584+
{ hash_combine(hash_, std::hash<std::string>()(denominator)); }
15851585
}
15861586
return hash_;
15871587
}
@@ -1764,7 +1764,7 @@ namespace Sass {
17641764
{
17651765
if (hash_ == 0) {
17661766
for (auto string : elements())
1767-
hash_combine(hash_, string->hash());
1767+
{ hash_combine(hash_, string->hash()); }
17681768
}
17691769
return hash_;
17701770
}

src/context.cpp

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

102102
// load plugins and register custom behaviors
103-
for(auto plug : plugin_paths) plugins.load_plugins(plug);
104-
for(auto fn : plugins.get_headers()) c_headers.push_back(fn);
105-
for(auto fn : plugins.get_importers()) c_importers.push_back(fn);
106-
for(auto fn : plugins.get_functions()) c_functions.push_back(fn);
103+
for(auto plug : plugin_paths) { plugins.load_plugins(plug); }
104+
for(auto fn : plugins.get_headers()) { c_headers.push_back(fn); }
105+
for(auto fn : plugins.get_importers()) { c_importers.push_back(fn); }
106+
for(auto fn : plugins.get_functions()) { c_functions.push_back(fn); }
107107

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

src/eval.cpp

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -336,15 +336,16 @@ namespace Sass {
336336
// try to use generic function
337337
if (env->has("@warn[f]")) {
338338

339-
// add call stack entry
340-
ctx.callee_stack.push_back({
339+
struct Sass_Callee callee = {
341340
"@warn",
342341
w->pstate().path,
343342
w->pstate().line + 1,
344343
w->pstate().column + 1,
345344
SASS_CALLEE_FUNCTION,
346345
{ env }
347-
});
346+
};
347+
// add call stack entry
348+
ctx.callee_stack.push_back(callee);
348349

349350
Definition_Ptr def = Cast<Definition>((*env)["@warn[f]"]);
350351
// Block_Obj body = def->block();
@@ -383,15 +384,16 @@ namespace Sass {
383384
// try to use generic function
384385
if (env->has("@error[f]")) {
385386

386-
// add call stack entry
387-
ctx.callee_stack.push_back({
387+
struct Sass_Callee callee = {
388388
"@error",
389389
e->pstate().path,
390390
e->pstate().line + 1,
391391
e->pstate().column + 1,
392392
SASS_CALLEE_FUNCTION,
393393
{ env }
394-
});
394+
};
395+
// add call stack entry
396+
ctx.callee_stack.push_back(callee);
395397

396398
Definition_Ptr def = Cast<Definition>((*env)["@error[f]"]);
397399
// Block_Obj body = def->block();
@@ -427,15 +429,16 @@ namespace Sass {
427429
// try to use generic function
428430
if (env->has("@debug[f]")) {
429431

430-
// add call stack entry
431-
ctx.callee_stack.push_back({
432+
struct Sass_Callee callee = {
432433
"@debug",
433434
d->pstate().path,
434435
d->pstate().line + 1,
435436
d->pstate().column + 1,
436437
SASS_CALLEE_FUNCTION,
437438
{ env }
438-
});
439+
};
440+
// add call stack entry
441+
ctx.callee_stack.push_back(callee);
439442

440443
Definition_Ptr def = Cast<Definition>((*env)["@debug[f]"]);
441444
// Block_Obj body = def->block();
@@ -1000,14 +1003,15 @@ namespace Sass {
10001003
bind(std::string("Function"), c->name(), params, args, &ctx, &fn_env, this);
10011004
Backtrace here(backtrace(), c->pstate(), ", in function `" + c->name() + "`");
10021005
exp.backtrace_stack.push_back(&here);
1003-
ctx.callee_stack.push_back({
1006+
struct Sass_Callee callee = {
10041007
c->name().c_str(),
10051008
c->pstate().path,
10061009
c->pstate().line + 1,
10071010
c->pstate().column + 1,
10081011
SASS_CALLEE_FUNCTION,
10091012
{ env }
1010-
});
1013+
};
1014+
ctx.callee_stack.push_back(callee);
10111015

10121016
// eval the body if user-defined or special, invoke underlying CPP function if native
10131017
if (body /* && !Prelexer::re_special_fun(name.c_str()) */) {
@@ -1041,14 +1045,15 @@ namespace Sass {
10411045

10421046
Backtrace here(backtrace(), c->pstate(), ", in function `" + c->name() + "`");
10431047
exp.backtrace_stack.push_back(&here);
1044-
ctx.callee_stack.push_back({
1048+
struct Sass_Callee callee = {
10451049
c->name().c_str(),
10461050
c->pstate().path,
10471051
c->pstate().line + 1,
10481052
c->pstate().column + 1,
10491053
SASS_CALLEE_C_FUNCTION,
10501054
{ env }
1051-
});
1055+
};
1056+
ctx.callee_stack.push_back(callee);
10521057

10531058
To_C to_c;
10541059
union Sass_Value* c_args = sass_make_list(params->length(), SASS_COMMA);
@@ -1170,7 +1175,7 @@ namespace Sass {
11701175
List_Obj ll = SASS_MEMORY_NEW(List, l->pstate(), 0, l->separator());
11711176
// this fixes an issue with bourbon sample, not really sure why
11721177
// if (l->size() && Cast<Null>((*l)[0])) { res += ""; }
1173-
for(Expression_Obj item : *l) {
1178+
for(Expression_Obj item : l->elements()) {
11741179
item->is_interpolant(l->is_interpolant());
11751180
std::string rl(""); interpolation(ctx, rl, item, into_quotes, l->is_interpolant());
11761181
bool is_null = Cast<Null>(item) != 0; // rl != ""

src/expand.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -702,14 +702,15 @@ namespace Sass {
702702
Arguments_Obj args = Cast<Arguments>(rv);
703703
Backtrace new_bt(backtrace(), c->pstate(), ", in mixin `" + c->name() + "`");
704704
backtrace_stack.push_back(&new_bt);
705-
ctx.callee_stack.push_back({
705+
struct Sass_Callee callee = {
706706
c->name().c_str(),
707707
c->pstate().path,
708708
c->pstate().line + 1,
709709
c->pstate().column + 1,
710710
SASS_CALLEE_MIXIN,
711711
{ env }
712-
});
712+
};
713+
ctx.callee_stack.push_back(callee);
713714

714715
Env new_env(def->environment());
715716
env_stack.push_back(&new_env);

src/extend.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1928,7 +1928,7 @@ namespace Sass {
19281928
recseen.insert(cur->head());
19291929
// create a copy since we add multiple items if stuff get unwrapped
19301930
Compound_Selector_Obj cpy_head = SASS_MEMORY_NEW(Compound_Selector, cur->pstate());
1931-
for (Simple_Selector_Obj hs : *cur->head()) {
1931+
for (Simple_Selector_Obj hs : cur->head()->elements()) {
19321932
if (Wrapped_Selector_Obj ws = Cast<Wrapped_Selector>(hs)) {
19331933
ws->selector(SASS_MEMORY_CLONE(ws->selector()));
19341934
if (Selector_List_Obj sl = Cast<Selector_List>(ws->selector())) {
@@ -2068,7 +2068,8 @@ namespace Sass {
20682068
// we set `extended` flag on extended selectors
20692069
if (b->is_root()) {
20702070
// debug_subset_map(subset_map);
2071-
for(auto const &it : subset_map.values()) {
2071+
auto values = subset_map.values();
2072+
for(auto it : values) {
20722073
Complex_Selector_Ptr sel = NULL;
20732074
Compound_Selector_Ptr ext = NULL;
20742075
if (it.first) sel = it.first->first();

src/functions.cpp

Lines changed: 69 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,24 @@
3030
#include "wincrypt.h"
3131
#endif
3232

33+
#if defined __GNUC__ && ! defined __llvm__
34+
#define GCC_VERSION (__GNUC__ * 10000 \
35+
+ __GNUC_MINOR__ * 100 \
36+
+ __GNUC_PATCHLEVEL__)
37+
#if GCC_VERSION < 40500
38+
#include <tr1/random>
39+
#define IMPLEMENT_TR1
40+
#define tr1ns std::tr1
41+
#define uniform_real_distribution uniform_real
42+
#else
43+
#include <random>
44+
#define tr1ns std
45+
#endif
46+
#else
47+
#include <random>
48+
#define tr1ns std
49+
#endif
50+
3351
#define ARG(argname, argtype) get_arg<argtype>(argname, env, sig, pstate, backtrace)
3452
#define ARGR(argname, argtype, lo, hi) get_arg_r(argname, env, sig, pstate, lo, hi, backtrace)
3553
#define ARGM(argname, argtype, ctx) get_arg_m(argname, env, sig, pstate, backtrace, ctx)
@@ -215,9 +233,43 @@ namespace Sass {
215233
// random_device degrades sharply once the entropy pool
216234
// is exhausted. For practical use, random_device is
217235
// generally only used to seed a PRNG such as mt19937.
218-
static std::mt19937 rand(static_cast<unsigned int>(GetSeed()));
236+
static tr1ns::mt19937 rand(static_cast<unsigned int>(GetSeed()));
237+
238+
tr1ns::uniform_real_distribution<> std_dist(0, 1);
239+
#ifdef IMPLEMENT_TR1
240+
tr1ns::variate_generator <
241+
tr1ns::mt19937,
242+
tr1ns::uniform_real_distribution <double>
243+
> gen_std_dist(rand, std_dist);
244+
#endif
245+
246+
// Using ULONG_MAX here seems to fail on Mac OSX Clang!?
247+
tr1ns::uniform_real_distribution<> full_dist(0, 4294967296);
248+
#ifdef IMPLEMENT_TR1
249+
tr1ns::variate_generator <
250+
tr1ns::mt19937,
251+
tr1ns::uniform_real_distribution <double>
252+
> gen_full_dist(rand, full_dist);
253+
#endif
254+
255+
// helper function to retrieve a random number in interval
256+
// works around some compiler issues with older gcc versions
257+
static double random(double min, double max)
258+
{
259+
tr1ns::uniform_real_distribution<> distributor(min, max);
260+
#ifdef IMPLEMENT_TR1
261+
tr1ns::variate_generator <
262+
tr1ns::mt19937,
263+
tr1ns::uniform_real_distribution <>
264+
> gen(rand, distributor);
265+
distributor(rand);
266+
return gen();
267+
#else
268+
return distributor(rand);
269+
#endif
270+
}
219271

220-
// features
272+
// supported features lookup table
221273
static std::set<std::string> features {
222274
"global-variable-shadowing",
223275
"extend-selector-pseudoclass",
@@ -1199,13 +1251,19 @@ namespace Sass {
11991251
err << "Expected $limit to be an integer but got " << lv << " for `random'";
12001252
error(err.str(), pstate);
12011253
}
1202-
std::uniform_real_distribution<> distributor(1, lv + 1);
1203-
uint_fast32_t distributed = static_cast<uint_fast32_t>(distributor(rand));
1254+
// std::uniform_real_distribution<> distributor(1, lv + 1);
1255+
// uint_fast32_t distributed = static_cast<uint_fast32_t>(distributor(rand));
1256+
uint_fast32_t distributed = random(1, lv + 1);
12041257
return SASS_MEMORY_NEW(Number, pstate, (double)distributed);
12051258
}
12061259
else if (b) {
1207-
std::uniform_real_distribution<> distributor(0, 1);
1208-
double distributed = static_cast<double>(distributor(rand));
1260+
// std::uniform_real_distribution<> distributor(0, 1);
1261+
// double distributed = static_cast<double>(distributor(rand));
1262+
#ifdef IMPLEMENT_TR1
1263+
double distributed = gen_std_dist();
1264+
#else
1265+
double distributed = std_dist(rand);
1266+
#endif
12091267
return SASS_MEMORY_NEW(Number, pstate, distributed);
12101268
} else if (v) {
12111269
throw Exception::InvalidArgumentType(pstate, "random", "$limit", "number", v);
@@ -1973,8 +2031,11 @@ namespace Sass {
19732031
BUILT_IN(unique_id)
19742032
{
19752033
std::stringstream ss;
1976-
std::uniform_real_distribution<> distributor(0, 4294967296); // 16^8
1977-
uint_fast32_t distributed = static_cast<uint_fast32_t>(distributor(rand));
2034+
#ifdef IMPLEMENT_TR1
2035+
uint_fast32_t distributed = gen_full_dist();
2036+
#else
2037+
uint_fast32_t distributed = full_dist(rand);
2038+
#endif
19782039
ss << "u" << std::setfill('0') << std::setw(8) << std::hex << distributed;
19792040
return SASS_MEMORY_NEW(String_Quoted, pstate, ss.str());
19802041
}

src/parser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ namespace Sass {
318318
do {
319319
while (lex< block_comment >());
320320
if (lex< quoted_string >()) {
321-
to_import.push_back(std::pair<std::string,Function_Call_Obj>(std::string(lexed), 0));
321+
to_import.push_back(std::pair<std::string,Function_Call_Obj>(std::string(lexed), (Function_Call*) NULL));
322322
}
323323
else if (lex< uri_prefix >()) {
324324
Arguments_Obj args = SASS_MEMORY_NEW(Arguments, pstate);

src/subset_map.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace Sass {
2424
continue;
2525
}
2626
const std::vector<std::pair<Compound_Selector_Obj, size_t> >& subsets = hash_[(*sel)[i]];
27-
for (const std::pair<Compound_Selector_Obj, size_t>& item : subsets) {
27+
for (const auto& item : subsets) {
2828
bool include = true;
2929
for (const Simple_Selector_Obj& it : item.first->elements()) {
3030
auto found = dict.find(it);

0 commit comments

Comments
 (0)