Skip to content

Commit

Permalink
Merge pull request #2316 from mgreter/nschonni/cleanups
Browse files Browse the repository at this point in the history
Let's see if we see compiler warnings pop up again ...
  • Loading branch information
mgreter authored Feb 4, 2017
2 parents b31cf55 + 5923e62 commit e4e65b4
Show file tree
Hide file tree
Showing 26 changed files with 221 additions and 243 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ bin/*
.libs/
win/bin
*.user
win/*.db

# Final results

Expand Down
53 changes: 19 additions & 34 deletions src/ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ namespace Sass {
// heads are not equal
else return *l_h < *r_h;
}
return true;
}

bool Complex_Selector::operator== (const Complex_Selector& rhs) const
Expand Down Expand Up @@ -326,7 +325,6 @@ namespace Sass {
if (const Complex_Selector* cs = Cast<Complex_Selector>(&rhs)) return *this < *cs;
if (const Compound_Selector* ch = Cast<Compound_Selector>(&rhs)) return *this < *ch;
throw std::runtime_error("invalid selector base classes to compare");
return false;
}

bool Compound_Selector::operator== (const Selector& rhs) const
Expand Down Expand Up @@ -366,7 +364,6 @@ namespace Sass {
if (const Complex_Selector* cs = Cast<Complex_Selector>(&rhs)) return *this < *cs;
if (const Compound_Selector* ch = Cast<Compound_Selector>(&rhs)) return *this < *ch;
throw std::runtime_error("invalid selector base classes to compare");
return false;
}

bool Simple_Selector::operator== (const Selector& rhs) const
Expand Down Expand Up @@ -406,9 +403,9 @@ namespace Sass {
bool Selector_List::operator== (const Selector& rhs) const
{
// solve the double dispatch problem by using RTTI information via dynamic cast
if (Selector_List_Ptr_Const ls = Cast<Selector_List>(&rhs)) { return *this == *ls; }
else if (Complex_Selector_Ptr_Const ls = Cast<Complex_Selector>(&rhs)) { return *this == *ls; }
else if (Compound_Selector_Ptr_Const ls = Cast<Compound_Selector>(&rhs)) { return *this == *ls; }
if (Selector_List_Ptr_Const sl = Cast<Selector_List>(&rhs)) { return *this == *sl; }
else if (Complex_Selector_Ptr_Const cpx = Cast<Complex_Selector>(&rhs)) { return *this == *cpx; }
else if (Compound_Selector_Ptr_Const cpd = Cast<Compound_Selector>(&rhs)) { return *this == *cpd; }
// no compare method
return this == &rhs;
}
Expand Down Expand Up @@ -452,8 +449,7 @@ namespace Sass {
// advance
++i; ++n;
}
// no mismatch
return true;
// there is no break?!
}

bool Selector_List::operator< (const Selector& rhs) const
Expand Down Expand Up @@ -834,9 +830,9 @@ namespace Sass {

for (size_t i = 0, iL = length(); i < iL; ++i)
{
Selector_Obj lhs = (*this)[i];
Selector_Obj wlhs = (*this)[i];
// very special case for wrapped matches selector
if (Wrapped_Selector_Obj wrapped = Cast<Wrapped_Selector>(lhs)) {
if (Wrapped_Selector_Obj wrapped = Cast<Wrapped_Selector>(wlhs)) {
if (wrapped->name() == ":not") {
if (Selector_List_Obj not_list = Cast<Selector_List>(wrapped->selector())) {
if (not_list->is_superselector_of(rhs, wrapped->name())) return false;
Expand All @@ -845,7 +841,7 @@ namespace Sass {
}
}
if (wrapped->name() == ":matches" || wrapped->name() == ":-moz-any") {
lhs = wrapped->selector();
wlhs = wrapped->selector();
if (Selector_List_Obj list = Cast<Selector_List>(wrapped->selector())) {
if (Compound_Selector_Obj comp = Cast<Compound_Selector>(rhs)) {
if (!wrapping.empty() && wrapping != wrapped->name()) return false;
Expand All @@ -861,13 +857,11 @@ namespace Sass {
if (wrapped->name() == wrapped_r->name()) {
if (wrapped->is_superselector_of(wrapped_r)) {
continue;
rset.insert(lhs->to_string());

}}
}
}
// match from here on as strings
lset.insert(lhs->to_string());
lset.insert(wlhs->to_string());
}

for (size_t n = 0, nL = rhs->length(); n < nL; ++n)
Expand Down Expand Up @@ -1010,8 +1004,7 @@ namespace Sass {
// advance now
++i; ++n;
}
// no mismatch
return true;
// there is no break?!
}

bool Complex_Selector::is_superselector_of(Compound_Selector_Obj rhs, std::string wrapping)
Expand Down Expand Up @@ -1091,12 +1084,7 @@ namespace Sass {
{ return false; }
return lhs->tail()->is_superselector_of(marker->tail());
}
else
{
return lhs->tail()->is_superselector_of(marker->tail());
}
// catch-all
return false;
return lhs->tail()->is_superselector_of(marker->tail());
}

size_t Complex_Selector::length() const
Expand Down Expand Up @@ -1127,17 +1115,18 @@ namespace Sass {
error("Invalid parent selector", pstate_);
} else if (last()->head_ && last()->head_->length()) {
Compound_Selector_Obj rh = last()->head();
size_t i = 0, L = h->length();
size_t i;
size_t L = h->length();
if (Cast<Element_Selector>(h->first())) {
if (Class_Selector_Ptr sq = Cast<Class_Selector>(rh->last())) {
Class_Selector_Ptr sqs = SASS_MEMORY_COPY(sq);
if (Class_Selector_Ptr cs = Cast<Class_Selector>(rh->last())) {
Class_Selector_Ptr sqs = SASS_MEMORY_COPY(cs);
sqs->name(sqs->name() + (*h)[0]->name());
sqs->pstate((*h)[0]->pstate());
(*rh)[rh->length()-1] = sqs;
rh->pstate(h->pstate());
for (i = 1; i < L; ++i) rh->append((*h)[i]);
} else if (Id_Selector_Ptr sq = Cast<Id_Selector>(rh->last())) {
Id_Selector_Ptr sqs = SASS_MEMORY_COPY(sq);
} else if (Id_Selector_Ptr is = Cast<Id_Selector>(rh->last())) {
Id_Selector_Ptr sqs = SASS_MEMORY_COPY(is);
sqs->name(sqs->name() + (*h)[0]->name());
sqs->pstate((*h)[0]->pstate());
(*rh)[rh->length()-1] = sqs;
Expand Down Expand Up @@ -1353,12 +1342,7 @@ namespace Sass {

}
// has no head
else {
return this->tails(tails);
}

// unreachable
return 0;
return this->tails(tails);
}

Selector_List_Ptr Complex_Selector::tails(Selector_List_Ptr tails)
Expand Down Expand Up @@ -1762,7 +1746,8 @@ namespace Sass {
denominator_units_(std::vector<std::string>()),
hash_(0)
{
size_t l = 0, r = 0;
size_t l = 0;
size_t r;
if (!u.empty()) {
bool nominator = true;
while (true) {
Expand Down
100 changes: 50 additions & 50 deletions src/ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1147,22 +1147,22 @@ namespace Sass {

inline static const std::string sass_op_to_name(enum Sass_OP op) {
switch (op) {
case AND: return "and"; break;
case OR: return "or"; break;
case EQ: return "eq"; break;
case NEQ: return "neq"; break;
case GT: return "gt"; break;
case GTE: return "gte"; break;
case LT: return "lt"; break;
case LTE: return "lte"; break;
case ADD: return "plus"; break;
case SUB: return "sub"; break;
case MUL: return "times"; break;
case DIV: return "div"; break;
case MOD: return "mod"; break;
case AND: return "and";
case OR: return "or";
case EQ: return "eq";
case NEQ: return "neq";
case GT: return "gt";
case GTE: return "gte";
case LT: return "lt";
case LTE: return "lte";
case ADD: return "plus";
case SUB: return "sub";
case MUL: return "times";
case DIV: return "div";
case MOD: return "mod";
// this is only used internally!
case NUM_OPS: return "[OPS]"; break;
default: return "invalid"; break;
case NUM_OPS: return "[OPS]";
default: return "invalid";
}
}

Expand Down Expand Up @@ -1191,42 +1191,42 @@ namespace Sass {
{ }
const std::string type_name() {
switch (optype()) {
case AND: return "and"; break;
case OR: return "or"; break;
case EQ: return "eq"; break;
case NEQ: return "neq"; break;
case GT: return "gt"; break;
case GTE: return "gte"; break;
case LT: return "lt"; break;
case LTE: return "lte"; break;
case ADD: return "add"; break;
case SUB: return "sub"; break;
case MUL: return "mul"; break;
case DIV: return "div"; break;
case MOD: return "mod"; break;
case AND: return "and";
case OR: return "or";
case EQ: return "eq";
case NEQ: return "neq";
case GT: return "gt";
case GTE: return "gte";
case LT: return "lt";
case LTE: return "lte";
case ADD: return "add";
case SUB: return "sub";
case MUL: return "mul";
case DIV: return "div";
case MOD: return "mod";
// this is only used internally!
case NUM_OPS: return "[OPS]"; break;
default: return "invalid"; break;
case NUM_OPS: return "[OPS]";
default: return "invalid";
}
}
const std::string separator() {
switch (optype()) {
case AND: return "&&"; break;
case OR: return "||"; break;
case EQ: return "=="; break;
case NEQ: return "!="; break;
case GT: return ">"; break;
case GTE: return ">="; break;
case LT: return "<"; break;
case LTE: return "<="; break;
case ADD: return "+"; break;
case SUB: return "-"; break;
case MUL: return "*"; break;
case DIV: return "/"; break;
case MOD: return "%"; break;
case AND: return "&&";
case OR: return "||";
case EQ: return "==";
case NEQ: return "!=";
case GT: return ">";
case GTE: return ">=";
case LT: return "<";
case LTE: return "<=";
case ADD: return "+";
case SUB: return "-";
case MUL: return "*";
case DIV: return "/";
case MOD: return "%";
// this is only used internally!
case NUM_OPS: return "[OPS]"; break;
default: return "invalid"; break;
case NUM_OPS: return "[OPS]";
default: return "invalid";
}
}
bool is_left_interpolant(void) const;
Expand Down Expand Up @@ -1294,10 +1294,10 @@ namespace Sass {
{ }
const std::string type_name() {
switch (optype_) {
case PLUS: return "plus"; break;
case MINUS: return "minus"; break;
case NOT: return "not"; break;
default: return "invalid"; break;
case PLUS: return "plus";
case MINUS: return "minus";
case NOT: return "not";
default: return "invalid";
}
}
virtual bool operator==(const Expression& rhs) const
Expand Down Expand Up @@ -3001,7 +3001,7 @@ namespace Sass {
virtual unsigned long specificity() const
{
unsigned long sum = 0;
unsigned long specificity = 0;
unsigned long specificity;
for (size_t i = 0, L = length(); i < L; ++i)
{
specificity = (*this)[i]->specificity();
Expand Down
12 changes: 6 additions & 6 deletions src/bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ namespace Sass {
env->local_frame()[p->name()] = arglist;
Map_Obj argmap = Cast<Map>(a->value());
for (auto key : argmap->keys()) {
std::string name = unquote(Cast<String_Constant>(key)->value());
std::string param = unquote(Cast<String_Constant>(key)->value());
arglist->append(SASS_MEMORY_NEW(Argument,
key->pstate(),
argmap->at(key),
"$" + name,
"$" + param,
false,
false));
}
Expand Down Expand Up @@ -205,14 +205,14 @@ namespace Sass {
Map_Obj argmap = Cast<Map>(a->value());

for (auto key : argmap->keys()) {
std::string name = "$" + unquote(Cast<String_Constant>(key)->value());
std::string param = "$" + unquote(Cast<String_Constant>(key)->value());

if (!param_map.count(name)) {
if (!param_map.count(param)) {
std::stringstream msg;
msg << callee << " has no parameter named " << name;
msg << callee << " has no parameter named " << param;
error(msg.str(), a->pstate());
}
env->local_frame()[name] = argmap->at(key);
env->local_frame()[param] = argmap->at(key);
}
++ia;
continue;
Expand Down
24 changes: 11 additions & 13 deletions src/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,12 +416,12 @@ namespace Sass {
// need one correct import
bool has_import = false;
// process all custom importers (or custom headers)
for (Sass_Importer_Entry& importer : importers) {
for (Sass_Importer_Entry& importer_ent : importers) {
// int priority = sass_importer_get_priority(importer);
Sass_Importer_Fn fn = sass_importer_get_function(importer);
Sass_Importer_Fn fn = sass_importer_get_function(importer_ent);
// skip importer if it returns NULL
if (Sass_Import_List includes =
fn(load_path.c_str(), importer, c_compiler)
fn(load_path.c_str(), importer_ent, c_compiler)
) {
// get c pointer copy to iterate over
Sass_Import_List it_includes = includes;
Expand All @@ -436,15 +436,15 @@ namespace Sass {
// create the importer struct
Importer importer(uniq_path, ctx_path);
// query data from the current include
Sass_Import_Entry include = *it_includes;
char* source = sass_import_take_source(include);
char* srcmap = sass_import_take_srcmap(include);
size_t line = sass_import_get_error_line(include);
size_t column = sass_import_get_error_column(include);
const char *abs_path = sass_import_get_abs_path(include);
Sass_Import_Entry include_ent = *it_includes;
char* source = sass_import_take_source(include_ent);
char* srcmap = sass_import_take_srcmap(include_ent);
size_t line = sass_import_get_error_line(include_ent);
size_t column = sass_import_get_error_column(include_ent);
const char *abs_path = sass_import_get_abs_path(include_ent);
// handle error message passed back from custom importer
// it may (or may not) override the line and column info
if (const char* err_message = sass_import_get_error_message(include)) {
if (const char* err_message = sass_import_get_error_message(include_ent)) {
if (source || srcmap) register_resource({ importer, uniq_path }, { source, srcmap }, &pstate);
if (line == std::string::npos && column == std::string::npos) error(err_message, pstate);
else error(err_message, ParserState(ctx_path, source, Position(line, column)));
Expand Down Expand Up @@ -696,10 +696,8 @@ namespace Sass {
char* Context::render_srcmap()
{
if (source_map_file == "") return 0;
char* result = 0;
std::string map = emitter.render_srcmap(*this);
result = sass_copy_c_string(map.c_str());
return result;
return sass_copy_c_string(map.c_str());
}


Expand Down
Loading

0 comments on commit e4e65b4

Please sign in to comment.