Skip to content

Commit

Permalink
Merge pull request #13 from larsimmisch/master
Browse files Browse the repository at this point in the history
Even less warnings
  • Loading branch information
Aaron Leung committed Apr 27, 2012
2 parents 5e1d4fe + 8b24df9 commit d7b1361
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ libsass: libsass_objs
prelexer.o

libsass_objs: sass_interface.cpp $(CPP_FILES)
g++ -O2 -c -combine sass_interface.cpp $(CPP_FILES)
g++ -O2 -Wall -c -combine sass_interface.cpp $(CPP_FILES)

clean:
rm -rf *.o *.a
4 changes: 3 additions & 1 deletion document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,11 @@ namespace Sass {
case expanded:
root.emit_expanded_css(output, "");
break;
default:
break;
}
string retval(output.str());
if (!retval.empty()) retval.resize(retval.size()-1);
return retval;
}
}
}
26 changes: 15 additions & 11 deletions document_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ namespace Sass {
catch (string& path) {
read_error("error reading file \"" + path + "\"");
}
// unreached statement
return Node(Node::none);
}

Node Document::parse_mixin_definition()
Expand Down Expand Up @@ -370,10 +372,9 @@ namespace Sass {
else if (peek< exactly<'['> >(position)) {
return parse_attribute_selector();
}
else {
syntax_error("invalid selector after " + lexed.to_string());
}
}
syntax_error("invalid selector after " + lexed.to_string());
// unreached statement
return Node(Node::none);}

Node Document::parse_pseudo() {
if (lex< pseudo_not >()) {
Expand Down Expand Up @@ -420,9 +421,9 @@ namespace Sass {
else if (lex < sequence< pseudo_prefix, identifier > >()) {
return Node(Node::pseudo, line_number, lexed);
}
else {
syntax_error("unrecognized pseudo-class or pseudo-element");
}
syntax_error("unrecognized pseudo-class or pseudo-element");
// unreached statement
return Node(Node::none);
}

Node Document::parse_attribute_selector()
Expand Down Expand Up @@ -477,7 +478,7 @@ namespace Sass {
block.has_statements = true;
}
else {
for (int i = 0; i < imported_tree.size(); ++i) {
for (size_t i = 0; i < imported_tree.size(); ++i) {
if (imported_tree[i].type == Node::comment ||
imported_tree[i].type == Node::rule) {
block[0].has_statements = true;
Expand Down Expand Up @@ -512,7 +513,7 @@ namespace Sass {
// block << parse_ruleset();
// block.has_blocks = true;
// }
else if (const char* p = lookahead_for_selector(position)) {
else if (lookahead_for_selector(position)) {
block << parse_ruleset(definition);
block[0].has_blocks = true;
}
Expand Down Expand Up @@ -834,6 +835,8 @@ namespace Sass {
}

syntax_error("error reading values after " + lexed.to_string());
// unreached statement
return Node(Node::none);
}

extern const char hash_lbrace[] = "#{";
Expand All @@ -852,7 +855,8 @@ namespace Sass {

Node schema(Node::string_schema, context.registry, line_number, 1);
while (i < str.end) {
if (p = find_first_in_interval< sequence< negate< exactly<'\\'> >, exactly<hash_lbrace> > >(i, str.end)) {
p = find_first_in_interval< sequence< negate< exactly<'\\'> >, exactly<hash_lbrace> > >(i, str.end);
if (p) {
if (i < p) schema << Node(Node::identifier, line_number, Token::make(i, p)); // accumulate the preceding segment if it's nonempty
const char* j = find_first_in_interval< exactly<rbrace> >(p, str.end); // find the closing brace
if (j) {
Expand Down Expand Up @@ -1122,4 +1126,4 @@ namespace Sass {
//
// return p;
// }
// }
// }
15 changes: 10 additions & 5 deletions eval_apply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ namespace Sass {
case Node::gte: return (lhs >= rhs) ? T : F;
case Node::lt: return (lhs < rhs) ? T : F;
case Node::lte: return (lhs <= rhs) ? T : F;
default:
eval_error("unknown comparison operator " + expr.content.token.to_string(), expr.line_number, expr.file_name);
return Node(Node::none);
}
} break;

Expand All @@ -150,7 +153,7 @@ namespace Sass {
acc << eval(expr[0], env, f_env, registry);
Node rhs(eval(expr[2], env, f_env, registry));
accumulate(expr[1].type, acc, rhs, registry);
for (int i = 3; i < expr.size(); i += 2) {
for (size_t i = 3; i < expr.size(); i += 2) {
Node rhs(eval(expr[i+1], env, f_env, registry));
accumulate(expr[i].type, acc, rhs, registry);
}
Expand All @@ -163,7 +166,7 @@ namespace Sass {
acc << eval(expr[0], env, f_env, registry);
Node rhs(eval(expr[2], env, f_env, registry));
accumulate(expr[1].type, acc, rhs, registry);
for (int i = 3; i < expr.size(); i += 2) {
for (size_t i = 3; i < expr.size(); i += 2) {
Node rhs(eval(expr[i+1], env, f_env, registry));
accumulate(expr[i].type, acc, rhs, registry);
}
Expand Down Expand Up @@ -248,7 +251,7 @@ namespace Sass {
case Node::string_schema:
case Node::value_schema: {
// cerr << "evaluating schema of size " << expr.size() << endl;
for (int i = 0; i < expr.size(); ++i) {
for (size_t i = 0; i < expr.size(); ++i) {
expr[i] = eval(expr[i], env, f_env, registry);
}
return expr;
Expand All @@ -258,6 +261,8 @@ namespace Sass {
return expr;
}
}

return expr;
}

Node accumulate(Node::Type op, Node& acc, Node& rhs, vector<vector<Node>*>& registry)
Expand Down Expand Up @@ -400,7 +405,7 @@ namespace Sass {
}
}
// plug the holes with default arguments if any
for (int i = 0; i < params.size(); ++i) {
for (size_t i = 0; i < params.size(); ++i) {
if (params[i].type == Node::assignment) {
Node param(params[i]);
Token name(param[0].content.token);
Expand All @@ -411,7 +416,7 @@ namespace Sass {
}
// lexically link the new environment and eval the mixin's body
bindings.link(env.global ? *env.global : env);
for (int i = 0; i < body.size(); ++i) {
for (size_t i = 0; i < body.size(); ++i) {
body[i] = eval(body[i], bindings, f_env, registry);
}
return body;
Expand Down
13 changes: 6 additions & 7 deletions functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -568,12 +568,11 @@ namespace Sass {
else if (!n1.is_numeric() && !n2.is_numeric()) {
eval_error("arguments to comparable must be numeric", n1.line_number, n1.file_name);
}
else {
Node F(Node::boolean);
F.line_number = n1.line_number;
F.content.boolean_value = false;
return F;
}

Node F(Node::boolean);
F.line_number = n1.line_number;
F.content.boolean_value = false;
return F;
}

// Boolean Functions ///////////////////////////////////////////////////
Expand All @@ -597,4 +596,4 @@ namespace Sass {


}
}
}
4 changes: 2 additions & 2 deletions node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,9 @@ namespace Sass {
// result += at(0).to_string(t == backref ? prefix : "");
// }

Node::Type t = at(0).type;
result += at(0).to_string(at(0).has_backref ? prefix : "");

for (size_t i = 1; i < size(); ++i) {
Node::Type t = at(i).type;
result += " ";
result += at(i).to_string(at(i).has_backref ? prefix : "");
}
Expand Down Expand Up @@ -395,6 +393,8 @@ namespace Sass {
case value:
buf << ' ' << string(content.token);
break;
default:
break;
}
}

Expand Down
4 changes: 2 additions & 2 deletions prelexer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,8 @@ namespace Sass {
template<prelexer mx>
const char* find_first_in_interval(const char* beg, const char* end) {
while ((beg < end) && *beg) {
const char* p;
if (p = mx(beg)) return p;
const char* p = mx(beg);
if (p) return p;
++beg;
}
return 0;
Expand Down
14 changes: 8 additions & 6 deletions sass_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,28 @@ extern "C" {

using namespace std;
sass_context* sass_new_context()
{ return (sass_context*) malloc(sizeof(sass_context)); }
{ return (sass_context*) calloc(1, sizeof(sass_context)); }

void sass_free_context(sass_context* ctx)
{
free(ctx->output_string);
if (ctx->output_string)
free(ctx->output_string);
free(ctx);
}

sass_file_context* sass_new_file_context()
{ return (sass_file_context*) malloc(sizeof(sass_file_context)); }
{ return (sass_file_context*) calloc(1, sizeof(sass_file_context)); }

void sass_free_file_context(sass_file_context* ctx)
{
free(ctx->output_string);
if (ctx->output_string)
free(ctx->output_string);
free(ctx);
}

sass_folder_context* sass_new_folder_context()
{ return (sass_folder_context*) malloc(sizeof(sass_folder_context)); }
{ return (sass_folder_context*) calloc(1, sizeof(sass_folder_context)); }

static char* process_document(Sass::Document& doc, int style)
{
using namespace Sass;
Expand Down

0 comments on commit d7b1361

Please sign in to comment.