Skip to content

Commit

Permalink
Cleaning up [WIP]
Browse files Browse the repository at this point in the history
  • Loading branch information
mgreter committed May 16, 2015
1 parent f982f83 commit e5e003d
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 56 deletions.
2 changes: 1 addition & 1 deletion ast_fwd_decl.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef SASS_AST_FWD_DECL_H
#define SASS_AST_FWD_DECL_H


/////////////////////////////////////////////
// Forward declarations for the AST visitors.
/////////////////////////////////////////////
namespace Sass {

enum Output_Style { NESTED, EXPANDED, COMPACT, COMPRESSED, FORMATTED };
Expand Down
2 changes: 2 additions & 0 deletions bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ namespace Sass {

void bind(string callee, Parameters* ps, Arguments* as, Context& ctx, Env* env, Eval* eval)
{

// Context& ctx = eval->context();
map<string, Parameter*> param_map;

// Set up a map to ensure named arguments refer to actual parameters. Also
Expand Down
30 changes: 24 additions & 6 deletions context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ namespace Sass {

Block* Context::parse_file()
{

Block* root = 0;
for (size_t i = 0; i < queue.size(); ++i) {
Sass_Import_Entry import = sass_make_import(
Expand All @@ -322,29 +323,46 @@ namespace Sass {
sass_delete_import(import_stack.back());
import_stack.pop_back();
if (i == 0) root = ast;
// ToDo: we store by load_path, which can lead
// to duplicates if importer reports the same path
// Maybe we should add an error for duplicates!?
style_sheets[queue[i].load_path] = ast;
}
if (root == 0) return 0;
Env tge;
Backtrace backtrace(0, ParserState("", 0), "");
register_built_in_functions(*this, &tge);

Env global; // create root environment
// register built-in functions on env
register_built_in_functions(*this, &global);
for (size_t i = 0, S = c_functions.size(); i < S; ++i) {
register_c_function(*this, &tge, c_functions[i]);
register_c_function(*this, &global, c_functions[i]);
}
Expand expand(*this, &tge, &backtrace);
Cssize cssize(*this, &tge, &backtrace);
// create initial backtrace entry
Backtrace backtrace(0, ParserState("", 0), "");
// create crtp visitor objects
Expand expand(*this, &global, &backtrace);
Cssize cssize(*this, &global, &backtrace);
// expand and eval the tree
root = root->perform(&expand)->block();
// merge and bubble certain rules
root = root->perform(&cssize)->block();
// should we extend something?
if (!subset_map.empty()) {
// create crtp visitor object
Extend extend(*this, subset_map);
// extend tree nodes
root->perform(&extend);
}

// clean up by removing empty placeholders
// ToDo: maybe we can do this somewhere else?
Remove_Placeholders remove_placeholders(*this);
root->perform(&remove_placeholders);

// return processed tree
return root;

}
// EO parse_file

Block* Context::parse_string()
{
Expand Down
Empty file removed contextualize.cpp
Empty file.
7 changes: 0 additions & 7 deletions contextualize.hpp

This file was deleted.

Empty file removed contextualize_eval.cpp
Empty file.
9 changes: 0 additions & 9 deletions contextualize_eval.hpp

This file was deleted.

36 changes: 12 additions & 24 deletions eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ namespace Sass {
{ }
Eval::~Eval() { }

// for setting the env before eval'ing an expression

Context& Eval::context()
{
return ctx;
Expand All @@ -73,8 +71,6 @@ namespace Sass {
return exp ? exp->backtrace() : 0;
}



// for setting the env before eval'ing an expression
// gets the env and other stuff from expander scope
Eval* Eval::snapshot()
Expand Down Expand Up @@ -609,8 +605,8 @@ namespace Sass {
}

Parameters* params = def->parameters();
Env new_env;
new_env.link(def->environment());
Env new_env(def->environment());
exp->env_stack.push_back(&new_env);
// bind("function " + c->name(), params, args, ctx, &new_env, this);
// Env* old_env = env;
// env = &new_env;
Expand Down Expand Up @@ -729,6 +725,7 @@ namespace Sass {
result->is_delayed(result->concrete_type() == Expression::STRING);
result = result->perform(this);
} while (result->concrete_type() == Expression::NONE);
exp->env_stack.pop_back();
return result;
}

Expand Down Expand Up @@ -1514,24 +1511,15 @@ namespace Sass {

Expression* Eval::operator()(Parent_Selector* p)
{
Selector* pr = exp->selector_stack.back();
if (dynamic_cast<Selector_List*>(pr)) {
exp->selector_stack.pop_back();
exp->selector_stack.push_back(0);
// I cannot listize here (would help)
auto rv = pr ? pr->perform(this)->perform(listize) : 0;
exp->selector_stack.pop_back();
exp->selector_stack.push_back(pr);
return rv;
} else {
exp->selector_stack.pop_back();
exp->selector_stack.push_back(0);
// I cannot listize here (would help)
auto rv = pr ? pr->perform(this) : 0;
exp->selector_stack.pop_back();
exp->selector_stack.push_back(pr);
return rv;
}
Selector* pr = selector();
exp->selector_stack.pop_back();
exp->selector_stack.push_back(0);
auto rv = pr ? pr->perform(this) : 0;
if (dynamic_cast<Selector_List*>(pr))
rv = rv->perform(listize);
exp->selector_stack.pop_back();
exp->selector_stack.push_back(pr);
return rv;
}

}
15 changes: 6 additions & 9 deletions expand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "backtrace.hpp"
#include "context.hpp"
#include "parser.hpp"
#include "debugger.hpp"

namespace Sass {

Expand Down Expand Up @@ -84,10 +83,9 @@ namespace Sass {
// process and add to last block on stack
inline void Expand::append_block(Block* b)
{
Block* current_block = block_stack.back();
for (size_t i = 0, L = b->length(); i < L; ++i) {
Statement* ith = (*b)[i]->perform(this);
if (ith) *current_block << ith;
if (ith) *block_stack.back() << ith;
}
}

Expand Down Expand Up @@ -145,11 +143,9 @@ namespace Sass {
property_stack.push_back(p->property_fragment());
Block* expanded_block = p->block()->perform(this)->block();

Block* current_block = block_stack.back();
for (size_t i = 0, L = expanded_block->length(); i < L; ++i) {
Statement* stm = (*expanded_block)[i];
if (typeid(*stm) == typeid(Declaration)) {
Declaration* dec = static_cast<Declaration*>(stm);
if (Declaration* dec = static_cast<Declaration*>(stm)) {
String_Schema* combined_prop = new (ctx.mem) String_Schema(p->pstate());
if (!property_stack.empty()) {
*combined_prop << property_stack.back()
Expand All @@ -160,7 +156,7 @@ namespace Sass {
*combined_prop << dec->property();
}
dec->property(combined_prop);
*current_block << dec;
*block_stack.back() << dec;
}
else if (typeid(*stm) == typeid(Comment)) {
// drop comments in propsets
Expand Down Expand Up @@ -238,7 +234,6 @@ namespace Sass {
String* old_p = d->property();
String* new_p = static_cast<String*>(old_p->perform(eval.snapshot()));
Expression* value = d->value()->perform(eval.snapshot());
if (!value) debug_ast(d->value());
if (!value || (value->is_invisible() && !d->is_important())) return 0;
Declaration* decl = new (ctx.mem) Declaration(d->pstate(),
new_p,
Expand Down Expand Up @@ -599,10 +594,12 @@ namespace Sass {
return call->perform(this);
}

// produce an error if something is not implemented
inline Statement* Expand::fallback_impl(AST_Node* n)
{
string err = string("`Expand` doesn't handle ") + typeid(*n).name();
String_Constant* msg = new (ctx.mem) String_Constant(ParserState("[WARN]"), err);
error("unknown internal error; please contact the LibSass maintainers", n->pstate(), backtrace());
String_Constant* msg = new (ctx.mem) String_Constant(ParserState("[WARN]"), string("`Expand` doesn't handle ") + typeid(*n).name());
return new (ctx.mem) Warning(ParserState("[WARN]"), msg);
}

Expand Down

0 comments on commit e5e003d

Please sign in to comment.