Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Add back gcc 4.4 compatibility #1623

Open
wants to merge 2 commits into
base: 3.4-stable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,15 @@ namespace Sass {

bool Compound_Selector::has_parent_ref() const
{
for (Simple_Selector_Obj s : *this) {
for (Simple_Selector_Obj s : elements()) {
if (s && s->has_parent_ref()) return true;
}
return false;
}

bool Compound_Selector::has_real_parent_ref() const
{
for (Simple_Selector_Obj s : *this) {
for (Simple_Selector_Obj s : elements()) {
if (s && s->has_real_parent_ref()) return true;
}
return false;
Expand Down
10 changes: 5 additions & 5 deletions src/ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ namespace Sass {
: elements_(ExpressionMap(s)),
list_(std::vector<Expression_Obj>()),
hash_(0), duplicate_key_(NULL)
{ elements_.reserve(s); list_.reserve(s); }
{ list_.reserve(s); reset_duplicate_key(); }
virtual ~Hashed();
size_t length() const { return list_.size(); }
bool empty() const { return list_.empty(); }
Expand Down Expand Up @@ -1478,7 +1478,7 @@ namespace Sass {
if (hash_ == 0) {
hash_ = std::hash<std::string>()(name());
for (auto argument : arguments()->elements())
hash_combine(hash_, argument->hash());
{ hash_combine(hash_, argument->hash()); }
}
return hash_;
}
Expand Down Expand Up @@ -1583,9 +1583,9 @@ namespace Sass {
if (hash_ == 0) {
hash_ = std::hash<double>()(value_);
for (const auto numerator : numerator_units())
hash_combine(hash_, std::hash<std::string>()(numerator));
{ hash_combine(hash_, std::hash<std::string>()(numerator)); }
for (const auto denominator : denominator_units())
hash_combine(hash_, std::hash<std::string>()(denominator));
{ hash_combine(hash_, std::hash<std::string>()(denominator)); }
}
return hash_;
}
Expand Down Expand Up @@ -1768,7 +1768,7 @@ namespace Sass {
{
if (hash_ == 0) {
for (auto string : elements())
hash_combine(hash_, string->hash());
{ hash_combine(hash_, string->hash()); }
}
return hash_;
}
Expand Down
2 changes: 1 addition & 1 deletion src/color_maps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ namespace Sass {
Color_Ptr_Const name_to_color(const std::string& key)
{
// case insensitive lookup. See #2462
std::string lower{key};
std::string lower(key);
std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower);

auto p = names_to_colors.find(lower.c_str());
Expand Down
11 changes: 7 additions & 4 deletions src/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,13 @@ namespace Sass {
collect_plugin_paths(c_options.plugin_paths);

// load plugins and register custom behaviors
for(auto plug : plugin_paths) plugins.load_plugins(plug);
for(auto fn : plugins.get_headers()) c_headers.push_back(fn);
for(auto fn : plugins.get_importers()) c_importers.push_back(fn);
for(auto fn : plugins.get_functions()) c_functions.push_back(fn);
for(auto plug : plugin_paths) { plugins.load_plugins(plug); }
const std::vector<Sass_Importer_Entry> headers = plugins.get_headers();
const std::vector<Sass_Importer_Entry> importers = plugins.get_importers();
const std::vector<Sass_Function_Entry> functions = plugins.get_functions();
for(Sass_Importer_Entry fn : headers) { c_headers.push_back(fn); }
for(Sass_Importer_Entry fn : importers) { c_importers.push_back(fn); }
for(Sass_Function_Entry fn : functions) { c_functions.push_back(fn); }

// sort the items by priority (lowest first)
sort (c_headers.begin(), c_headers.end(), sort_importers);
Expand Down
2 changes: 1 addition & 1 deletion src/emitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ namespace Sass {

char Emitter::last_char()
{
return wbuf.buffer.back();
return *wbuf.buffer.rbegin();
}

// append a single char to the buffer
Expand Down
33 changes: 19 additions & 14 deletions src/eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,15 +337,16 @@ namespace Sass {
// try to use generic function
if (env->has("@warn[f]")) {

// add call stack entry
ctx.callee_stack.push_back({
struct Sass_Callee callee = {
"@warn",
w->pstate().path,
w->pstate().line + 1,
w->pstate().column + 1,
SASS_CALLEE_FUNCTION,
{ env }
});
};
// add call stack entry
ctx.callee_stack.push_back(callee);

Definition_Ptr def = Cast<Definition>((*env)["@warn[f]"]);
// Block_Obj body = def->block();
Expand Down Expand Up @@ -384,15 +385,16 @@ namespace Sass {
// try to use generic function
if (env->has("@error[f]")) {

// add call stack entry
ctx.callee_stack.push_back({
struct Sass_Callee callee = {
"@error",
e->pstate().path,
e->pstate().line + 1,
e->pstate().column + 1,
SASS_CALLEE_FUNCTION,
{ env }
});
};
// add call stack entry
ctx.callee_stack.push_back(callee);

Definition_Ptr def = Cast<Definition>((*env)["@error[f]"]);
// Block_Obj body = def->block();
Expand Down Expand Up @@ -428,15 +430,16 @@ namespace Sass {
// try to use generic function
if (env->has("@debug[f]")) {

// add call stack entry
ctx.callee_stack.push_back({
struct Sass_Callee callee = {
"@debug",
d->pstate().path,
d->pstate().line + 1,
d->pstate().column + 1,
SASS_CALLEE_FUNCTION,
{ env }
});
};
// add call stack entry
ctx.callee_stack.push_back(callee);

Definition_Ptr def = Cast<Definition>((*env)["@debug[f]"]);
// Block_Obj body = def->block();
Expand Down Expand Up @@ -1007,14 +1010,15 @@ namespace Sass {
bind(std::string("Function"), c->name(), params, args, &ctx, &fn_env, this);
Backtrace here(backtrace(), c->pstate(), ", in function `" + c->name() + "`");
exp.backtrace_stack.push_back(&here);
ctx.callee_stack.push_back({
struct Sass_Callee callee = {
c->name().c_str(),
c->pstate().path,
c->pstate().line + 1,
c->pstate().column + 1,
SASS_CALLEE_FUNCTION,
{ env }
});
};
ctx.callee_stack.push_back(callee);

// eval the body if user-defined or special, invoke underlying CPP function if native
if (body /* && !Prelexer::re_special_fun(name.c_str()) */) {
Expand Down Expand Up @@ -1048,14 +1052,15 @@ namespace Sass {

Backtrace here(backtrace(), c->pstate(), ", in function `" + c->name() + "`");
exp.backtrace_stack.push_back(&here);
ctx.callee_stack.push_back({
struct Sass_Callee callee = {
c->name().c_str(),
c->pstate().path,
c->pstate().line + 1,
c->pstate().column + 1,
SASS_CALLEE_C_FUNCTION,
{ env }
});
};
ctx.callee_stack.push_back(callee);

To_C to_c;
union Sass_Value* c_args = sass_make_list(params->length(), SASS_COMMA);
Expand Down Expand Up @@ -1177,7 +1182,7 @@ namespace Sass {
List_Obj ll = SASS_MEMORY_NEW(List, l->pstate(), 0, l->separator());
// this fixes an issue with bourbon sample, not really sure why
// if (l->size() && Cast<Null>((*l)[0])) { res += ""; }
for(Expression_Obj item : *l) {
for(Expression_Obj item : l->elements()) {
item->is_interpolant(l->is_interpolant());
std::string rl(""); interpolation(ctx, rl, item, into_quotes, l->is_interpolant());
bool is_null = Cast<Null>(item) != 0; // rl != ""
Expand Down
5 changes: 3 additions & 2 deletions src/expand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -715,14 +715,15 @@ namespace Sass {
Arguments_Obj args = Cast<Arguments>(rv);
Backtrace new_bt(backtrace(), c->pstate(), ", in mixin `" + c->name() + "`");
backtrace_stack.push_back(&new_bt);
ctx.callee_stack.push_back({
struct Sass_Callee callee = {
c->name().c_str(),
c->pstate().path,
c->pstate().line + 1,
c->pstate().column + 1,
SASS_CALLEE_MIXIN,
{ env }
});
};
ctx.callee_stack.push_back(callee);

Env new_env(def->environment());
env_stack.push_back(&new_env);
Expand Down
5 changes: 3 additions & 2 deletions src/extend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1936,7 +1936,7 @@ namespace Sass {
recseen.insert(cur->head());
// create a copy since we add multiple items if stuff get unwrapped
Compound_Selector_Obj cpy_head = SASS_MEMORY_NEW(Compound_Selector, cur->pstate());
for (Simple_Selector_Obj hs : *cur->head()) {
for (Simple_Selector_Obj hs : cur->head()->elements()) {
if (Wrapped_Selector_Obj ws = Cast<Wrapped_Selector>(hs)) {
ws->selector(SASS_MEMORY_CLONE(ws->selector()));
if (Selector_List_Obj sl = Cast<Selector_List>(ws->selector())) {
Expand Down Expand Up @@ -2085,7 +2085,8 @@ namespace Sass {
// we set `extended` flag on extended selectors
if (b->is_root()) {
// debug_subset_map(subset_map);
for(auto const &it : subset_map.values()) {
auto values = subset_map.values();
for(auto it : values) {
Complex_Selector_Ptr sel = NULL;
Compound_Selector_Ptr ext = NULL;
if (it.first) sel = it.first->first();
Expand Down
77 changes: 69 additions & 8 deletions src/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,24 @@
#include "wincrypt.h"
#endif

#if defined __GNUC__ && ! defined __llvm__
#define GCC_VERSION (__GNUC__ * 10000 \
+ __GNUC_MINOR__ * 100 \
+ __GNUC_PATCHLEVEL__)
#if GCC_VERSION < 40500
#include <tr1/random>
#define IMPLEMENT_TR1
#define tr1ns std::tr1
#define uniform_real_distribution uniform_real
#else
#include <random>
#define tr1ns std
#endif
#else
#include <random>
#define tr1ns std
#endif

#define ARG(argname, argtype) get_arg<argtype>(argname, env, sig, pstate, backtrace)
#define ARGR(argname, argtype, lo, hi) get_arg_r(argname, env, sig, pstate, lo, hi, backtrace)
#define ARGM(argname, argtype, ctx) get_arg_m(argname, env, sig, pstate, backtrace, ctx)
Expand Down Expand Up @@ -215,9 +233,43 @@ namespace Sass {
// random_device degrades sharply once the entropy pool
// is exhausted. For practical use, random_device is
// generally only used to seed a PRNG such as mt19937.
static std::mt19937 rand(static_cast<unsigned int>(GetSeed()));
static tr1ns::mt19937 rand(static_cast<unsigned int>(GetSeed()));

tr1ns::uniform_real_distribution<> std_dist(0, 1);
#ifdef IMPLEMENT_TR1
tr1ns::variate_generator <
tr1ns::mt19937,
tr1ns::uniform_real_distribution <double>
> gen_std_dist(rand, std_dist);
#endif

// Using ULONG_MAX here seems to fail on Mac OSX Clang!?
tr1ns::uniform_real_distribution<> full_dist(0, 4294967296);
#ifdef IMPLEMENT_TR1
tr1ns::variate_generator <
tr1ns::mt19937,
tr1ns::uniform_real_distribution <double>
> gen_full_dist(rand, full_dist);
#endif

// helper function to retrieve a random number in interval
// works around some compiler issues with older gcc versions
static double random(double min, double max)
{
tr1ns::uniform_real_distribution<> distributor(min, max);
#ifdef IMPLEMENT_TR1
tr1ns::variate_generator <
tr1ns::mt19937,
tr1ns::uniform_real_distribution <>
> gen(rand, distributor);
distributor(rand);
return gen();
#else
return distributor(rand);
#endif
}

// features
// supported features lookup table
static std::set<std::string> features {
"global-variable-shadowing",
"extend-selector-pseudoclass",
Expand Down Expand Up @@ -1199,13 +1251,19 @@ namespace Sass {
err << "Expected $limit to be an integer but got " << lv << " for `random'";
error(err.str(), pstate);
}
std::uniform_real_distribution<> distributor(1, lv + 1);
uint_fast32_t distributed = static_cast<uint_fast32_t>(distributor(rand));
// std::uniform_real_distribution<> distributor(1, lv + 1);
// uint_fast32_t distributed = static_cast<uint_fast32_t>(distributor(rand));
uint_fast32_t distributed = random(1, lv + 1);
return SASS_MEMORY_NEW(Number, pstate, (double)distributed);
}
else if (b) {
std::uniform_real_distribution<> distributor(0, 1);
double distributed = static_cast<double>(distributor(rand));
// std::uniform_real_distribution<> distributor(0, 1);
// double distributed = static_cast<double>(distributor(rand));
#ifdef IMPLEMENT_TR1
double distributed = gen_std_dist();
#else
double distributed = std_dist(rand);
#endif
return SASS_MEMORY_NEW(Number, pstate, distributed);
} else if (v) {
throw Exception::InvalidArgumentType(pstate, "random", "$limit", "number", v);
Expand Down Expand Up @@ -1973,8 +2031,11 @@ namespace Sass {
BUILT_IN(unique_id)
{
std::stringstream ss;
std::uniform_real_distribution<> distributor(0, 4294967296); // 16^8
uint_fast32_t distributed = static_cast<uint_fast32_t>(distributor(rand));
#ifdef IMPLEMENT_TR1
uint_fast32_t distributed = gen_full_dist();
#else
uint_fast32_t distributed = full_dist(rand);
#endif
ss << "u" << std::setfill('0') << std::setw(8) << std::hex << distributed;
return SASS_MEMORY_NEW(String_Quoted, pstate, ss.str());
}
Expand Down
3 changes: 2 additions & 1 deletion src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ namespace Sass {
do {
while (lex< block_comment >());
if (lex< quoted_string >()) {
to_import.push_back(std::pair<std::string,Function_Call_Obj>(std::string(lexed), 0));
to_import.push_back(std::pair<std::string,Function_Call_Obj>(std::string(lexed), (Function_Call*) NULL));
}
else if (lex< uri_prefix >()) {
Arguments_Obj args = SASS_MEMORY_NEW(Arguments, pstate);
Expand Down Expand Up @@ -2967,6 +2967,7 @@ namespace Sass {
if (left_subpos && ellipsis_left) left = ellipsis + left.substr(left_subpos);
if (right_subpos && ellipsis_right) right = right.substr(right_subpos) + ellipsis;
// now pass new message to the more generic error function
if (source == NULL || *source == 0) source = pstate.src;
error(msg + prefix + quote(left) + middle + quote(right), pstate);
}

Expand Down
2 changes: 1 addition & 1 deletion src/subset_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace Sass {
continue;
}
const std::vector<std::pair<Compound_Selector_Obj, size_t> >& subsets = hash_[(*sel)[i]];
for (const std::pair<Compound_Selector_Obj, size_t>& item : subsets) {
for (const auto& item : subsets) {
bool include = true;
for (const Simple_Selector_Obj& it : item.first->elements()) {
auto found = dict.find(it);
Expand Down