Skip to content

Commit 8282da7

Browse files
committed
Improve compiler compatibility for early gcc versions
1 parent d5b6fe7 commit 8282da7

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
@@ -359,7 +359,7 @@ namespace Sass {
359359
virtual void adjust_after_pushing(std::pair<Expression_Obj, Expression_Obj> p) { }
360360
public:
361361
Hashed(size_t s = 0) : elements_(ExpressionMap(s)), list_(std::vector<Expression_Obj>())
362-
{ elements_.reserve(s); list_.reserve(s); reset_duplicate_key(); }
362+
{ list_.reserve(s); reset_duplicate_key(); }
363363
virtual ~Hashed();
364364
size_t length() const { return list_.size(); }
365365
bool empty() const { return list_.empty(); }
@@ -1470,7 +1470,7 @@ namespace Sass {
14701470
if (hash_ == 0) {
14711471
hash_ = std::hash<std::string>()(name());
14721472
for (auto argument : arguments()->elements())
1473-
hash_combine(hash_, argument->hash());
1473+
{ hash_combine(hash_, argument->hash()); }
14741474
}
14751475
return hash_;
14761476
}
@@ -1625,9 +1625,9 @@ namespace Sass {
16251625
if (hash_ == 0) {
16261626
hash_ = std::hash<double>()(value_);
16271627
for (const auto numerator : numerator_units())
1628-
hash_combine(hash_, std::hash<std::string>()(numerator));
1628+
{ hash_combine(hash_, std::hash<std::string>()(numerator)); }
16291629
for (const auto denominator : denominator_units())
1630-
hash_combine(hash_, std::hash<std::string>()(denominator));
1630+
{ hash_combine(hash_, std::hash<std::string>()(denominator)); }
16311631
}
16321632
return hash_;
16331633
}
@@ -1810,7 +1810,7 @@ namespace Sass {
18101810
{
18111811
if (hash_ == 0) {
18121812
for (auto string : elements())
1813-
hash_combine(hash_, string->hash());
1813+
{ hash_combine(hash_, string->hash()); }
18141814
}
18151815
return hash_;
18161816
}

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/eval.cpp

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

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

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

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

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

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

439442
Definition_Ptr def = Cast<Definition>((*env)["@debug[f]"]);
440443
// Block_Obj body = def->block();
@@ -906,14 +909,15 @@ namespace Sass {
906909
bind(std::string("Function"), c->name(), params, args, &ctx, &fn_env, this);
907910
Backtrace here(backtrace(), c->pstate(), ", in function `" + c->name() + "`");
908911
exp.backtrace_stack.push_back(&here);
909-
ctx.callee_stack.push_back({
912+
struct Sass_Callee callee = {
910913
c->name().c_str(),
911914
c->pstate().path,
912915
c->pstate().line + 1,
913916
c->pstate().column + 1,
914917
SASS_CALLEE_FUNCTION,
915918
{ env }
916-
});
919+
};
920+
ctx.callee_stack.push_back(callee);
917921

918922
// eval the body if user-defined or special, invoke underlying CPP function if native
919923
if (body /* && !Prelexer::re_special_fun(name.c_str()) */) {
@@ -947,14 +951,15 @@ namespace Sass {
947951

948952
Backtrace here(backtrace(), c->pstate(), ", in function `" + c->name() + "`");
949953
exp.backtrace_stack.push_back(&here);
950-
ctx.callee_stack.push_back({
954+
struct Sass_Callee callee = {
951955
c->name().c_str(),
952956
c->pstate().path,
953957
c->pstate().line + 1,
954958
c->pstate().column + 1,
955959
SASS_CALLEE_C_FUNCTION,
956960
{ env }
957-
});
961+
};
962+
ctx.callee_stack.push_back(callee);
958963

959964
To_C to_c;
960965
union Sass_Value* c_args = sass_make_list(params->length(), SASS_COMMA, false);
@@ -1159,7 +1164,7 @@ namespace Sass {
11591164
List_Obj ll = SASS_MEMORY_NEW(List, l->pstate(), 0, l->separator());
11601165
// this fixes an issue with bourbon sample, not really sure why
11611166
// if (l->size() && Cast<Null>((*l)[0])) { res += ""; }
1162-
for(Expression_Obj item : *l) {
1167+
for(Expression_Obj item : l->elements()) {
11631168
item->is_interpolant(l->is_interpolant());
11641169
std::string rl(""); interpolation(ctx, rl, item, into_quotes, l->is_interpolant());
11651170
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
@@ -705,14 +705,15 @@ namespace Sass {
705705
Arguments_Obj args = Cast<Arguments>(rv);
706706
Backtrace new_bt(backtrace(), c->pstate(), ", in mixin `" + c->name() + "`");
707707
backtrace_stack.push_back(&new_bt);
708-
ctx.callee_stack.push_back({
708+
struct Sass_Callee callee = {
709709
c->name().c_str(),
710710
c->pstate().path,
711711
c->pstate().line + 1,
712712
c->pstate().column + 1,
713713
SASS_CALLEE_MIXIN,
714714
{ env }
715-
});
715+
};
716+
ctx.callee_stack.push_back(callee);
716717

717718
Env new_env(def->environment());
718719
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",
@@ -1205,13 +1257,19 @@ namespace Sass {
12051257
err << "Expected $limit to be an integer but got " << lv << " for `random'";
12061258
error(err.str(), pstate);
12071259
}
1208-
std::uniform_real_distribution<> distributor(1, lv + 1);
1209-
uint_fast32_t distributed = static_cast<uint_fast32_t>(distributor(rand));
1260+
// std::uniform_real_distribution<> distributor(1, lv + 1);
1261+
// uint_fast32_t distributed = static_cast<uint_fast32_t>(distributor(rand));
1262+
uint_fast32_t distributed = random(1, lv + 1);
12101263
return SASS_MEMORY_NEW(Number, pstate, (double)distributed);
12111264
}
12121265
else if (b) {
1213-
std::uniform_real_distribution<> distributor(0, 1);
1214-
double distributed = static_cast<double>(distributor(rand));
1266+
// std::uniform_real_distribution<> distributor(0, 1);
1267+
// double distributed = static_cast<double>(distributor(rand));
1268+
#ifdef IMPLEMENT_TR1
1269+
double distributed = gen_std_dist();
1270+
#else
1271+
double distributed = std_dist(rand);
1272+
#endif
12151273
return SASS_MEMORY_NEW(Number, pstate, distributed);
12161274
} else if (v) {
12171275
throw Exception::InvalidArgumentType(pstate, "random", "$limit", "number", v);
@@ -1987,8 +2045,11 @@ namespace Sass {
19872045
BUILT_IN(unique_id)
19882046
{
19892047
std::stringstream ss;
1990-
std::uniform_real_distribution<> distributor(0, 4294967296); // 16^8
1991-
uint_fast32_t distributed = static_cast<uint_fast32_t>(distributor(rand));
2048+
#ifdef IMPLEMENT_TR1
2049+
uint_fast32_t distributed = gen_full_dist();
2050+
#else
2051+
uint_fast32_t distributed = full_dist(rand);
2052+
#endif
19922053
ss << "u" << std::setfill('0') << std::setw(8) << std::hex << distributed;
19932054
return SASS_MEMORY_NEW(String_Quoted, pstate, ss.str());
19942055
}

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)