Skip to content

Commit

Permalink
sass#548 applied @xzyfer patch. Some clean up of commented out code
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Kimn committed Mar 17, 2015
1 parent 98977d8 commit 5b6d06a
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 11 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ SOURCES = \
contextualize.cpp \
contextualize_eval.cpp \
cssize.cpp \
listize.cpp \
error_handling.cpp \
eval.cpp \
expand.cpp \
Expand Down
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ libsass_la_SOURCES = \
expand.cpp expand.hpp \
extend.cpp extend.hpp \
cssize.cpp cssize.hpp \
listize.cpp listize.hpp \
file.cpp file.hpp \
functions.cpp functions.hpp \
inspect.cpp inspect.hpp \
Expand Down
4 changes: 3 additions & 1 deletion context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "contextualize.hpp"
#include "contextualize_eval.hpp"
#include "cssize.hpp"
#include "listize.hpp"
#include "extend.hpp"
#include "remove_placeholders.hpp"
#include "color_names.hpp"
Expand Down Expand Up @@ -313,7 +314,8 @@ namespace Sass {
register_c_function(*this, &tge, c_functions[i]);
}
Contextualize contextualize(*this, &tge, &backtrace);
Eval eval(*this, &contextualize, &tge, &backtrace);
Listize listize(*this, &tge, &backtrace);
Eval eval(*this, &contextualize, &listize, &tge, &backtrace);
Contextualize_Eval contextualize_eval(*this, &eval, &tge, &backtrace);
Expand expand(*this, &eval, &contextualize_eval, &tge, &backtrace);
Cssize cssize(*this, &tge, &backtrace);
Expand Down
12 changes: 5 additions & 7 deletions eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ namespace Sass {
add, sub, mul, div, fmod
};

Eval::Eval(Context& ctx, Contextualize* contextualize, Env* env, Backtrace* bt)
: ctx(ctx), contextualize(contextualize), env(env), backtrace(bt) { }
Eval::Eval(Context& ctx, Contextualize* contextualize, Listize* listize, Env* env, Backtrace* bt)
: ctx(ctx), contextualize(contextualize), listize(listize), env(env), backtrace(bt) { }
Eval::~Eval() { }

Eval* Eval::with(Env* e, Backtrace* bt) // for setting the env before eval'ing an expression
Expand Down Expand Up @@ -935,11 +935,9 @@ namespace Sass {

Expression* Eval::operator()(Parent_Selector* p)
{
Selector* sel = p->perform(contextualize);
Inspect isp(0);
sel->perform(&isp);
string str = isp.get_buffer();
return new (ctx.mem) String_Constant(p->pstate(), str);
Selector* s = p->perform(contextualize);
Expression* e = static_cast<Selector_List*>(s)->perform(listize);
return e;
}

inline Expression* Eval::fallback_impl(AST_Node* n)
Expand Down
5 changes: 4 additions & 1 deletion eval.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "operation.hpp"
#include "environment.hpp"
#include "contextualize.hpp"
#include "listize.hpp"
#include "sass_values.h"

namespace Sass {
Expand All @@ -16,6 +17,7 @@ namespace Sass {
typedef Environment<AST_Node*> Env;
struct Backtrace;
class Contextualize;
class Listize;

class Eval : public Operation_CRTP<Expression*, Eval> {

Expand All @@ -25,9 +27,10 @@ namespace Sass {

public:
Contextualize* contextualize;
Listize* listize;
Env* env;
Backtrace* backtrace;
Eval(Context&, Contextualize*, Env*, Backtrace*);
Eval(Context&, Contextualize*, Listize*, Env*, Backtrace*);
virtual ~Eval();
Eval* with(Env* e, Backtrace* bt); // for setting the env before eval'ing an expression
Eval* with(Selector* c, Env* e, Backtrace* bt, Selector* placeholder = 0, Selector* extender = 0); // for setting the env before eval'ing an expression
Expand Down
6 changes: 4 additions & 2 deletions functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1468,7 +1468,8 @@ namespace Sass {
}
Function_Call* func = new (ctx.mem) Function_Call(pstate, name, args);
Contextualize contextualize(ctx, &d_env, backtrace);
Eval eval(ctx, &contextualize, &d_env, backtrace);
Listize listize(ctx, &d_env, backtrace);
Eval eval(ctx, &contextualize, &listize, &d_env, backtrace);
return func->perform(&eval);

}
Expand All @@ -1487,7 +1488,8 @@ namespace Sass {
BUILT_IN(sass_if)
{
Contextualize contextualize(ctx, &d_env, backtrace);
Eval eval(ctx, &contextualize, &d_env, backtrace);
Listize listize(ctx, &d_env, backtrace);
Eval eval(ctx, &contextualize, &listize, &d_env, backtrace);
bool is_true = !ARG("$condition", Expression)->perform(&eval)->is_false();
if (is_true) {
return ARG("$if-true", Expression)->perform(&eval);
Expand Down
95 changes: 95 additions & 0 deletions listize.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#include <iostream>
#include <typeinfo>

#include "listize.hpp"
#include "to_string.hpp"
#include "context.hpp"
#include "backtrace.hpp"
#include "error_handling.hpp"

namespace Sass {

Listize::Listize(Context& ctx, Env* env, Backtrace* bt)
: ctx(ctx),
env(env),
backtrace(bt)
{ }

Expression* Listize::operator()(Selector_List* sel)
{
List* l = new (ctx.mem) List(sel->pstate(), sel->length(), List::COMMA);
for (size_t i = 0, L = sel->length(); i < L; ++i) {
*l << (*sel)[i]->perform(this);
}
return l;
}

Expression* Listize::operator()(Compound_Selector* sel)
{
To_String to_string;
string str;
for (size_t i = 0, L = sel->length(); i < L; ++i) {
Expression* e = (*sel)[i]->perform(this);
if (e) str += e->perform(&to_string);
}
return new (ctx.mem) String_Constant(sel->pstate(), str);
}

Expression* Listize::operator()(Type_Selector* sel)
{
return new (ctx.mem) String_Constant(sel->pstate(), sel->name());
}

Expression* Listize::operator()(Selector_Qualifier* sel)
{
return new (ctx.mem) String_Constant(sel->pstate(), sel->name());
}

Expression* Listize::operator()(Complex_Selector* sel)
{
List* l = new (ctx.mem) List(sel->pstate(), 2);

Compound_Selector* head = sel->head();
if (head && !head->is_empty_reference())
{
Expression* hh = head->perform(this);
if (hh) *l << hh;
}

switch(sel->combinator())
{
case Complex_Selector::PARENT_OF:
*l << new (ctx.mem) String_Constant(sel->pstate(), ">");
break;
case Complex_Selector::ADJACENT_TO:
*l << new (ctx.mem) String_Constant(sel->pstate(), "+");
break;
case Complex_Selector::PRECEDES:
*l << new (ctx.mem) String_Constant(sel->pstate(), "~");
break;
case Complex_Selector::ANCESTOR_OF:
break;
}

Complex_Selector* tail = sel->tail();
if (tail)
{
Expression* tt = tail->perform(this);
if (tt && tt->concrete_type() == Expression::LIST)
{ *l += static_cast<List*>(tt); }
else if (tt) *l << static_cast<List*>(tt);
}
if (l->length() == 0) return 0;
return l;
}

Expression* Listize::operator()(Selector_Reference* sel)
{
return 0;
}

Expression* Listize::fallback_impl(AST_Node* n)
{
return 0;
}
}
45 changes: 45 additions & 0 deletions listize.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#ifndef SASS_LISTIZE_H
#define SASS_LISTIZE_H

#include <vector>
#include <iostream>

#include "ast.hpp"
#include "context.hpp"
#include "operation.hpp"
#include "environment.hpp"

namespace Sass {
using namespace std;

typedef Environment<AST_Node*> Env;
struct Backtrace;

class Listize : public Operation_CRTP<Expression*, Listize> {

Context& ctx;
Env* env;
Backtrace* backtrace;

Expression* fallback_impl(AST_Node* n);

public:
Listize(Context&, Env*, Backtrace*);
virtual ~Listize() { }

using Operation<Expression*>::operator();

Expression* operator()(Selector_List*);
Expression* operator()(Complex_Selector*);
Expression* operator()(Compound_Selector*);
Expression* operator()(Type_Selector*);
Expression* operator()(Selector_Qualifier*);
Expression* operator()(Selector_Reference*);

template <typename U>
Expression* fallback(U x) { return fallback_impl(x); }
};

}

#endif
6 changes: 6 additions & 0 deletions win/libsass.filters
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
<ClCompile Include="..\cssize.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\listize.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\extend.cpp">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down Expand Up @@ -194,6 +197,9 @@
<ClInclude Include="..\cssize.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\listize.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\extend.hpp">
<Filter>Header Files</Filter>
</ClInclude>
Expand Down
2 changes: 2 additions & 0 deletions win/libsass.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@
<ClCompile Include="..\eval.cpp" />
<ClCompile Include="..\expand.cpp" />
<ClCompile Include="..\cssize.cpp" />
<ClCompile Include="..\listize.cpp" />
<ClCompile Include="..\extend.cpp" />
<ClCompile Include="..\file.cpp" />
<ClCompile Include="..\functions.cpp" />
Expand Down Expand Up @@ -216,6 +217,7 @@
<ClInclude Include="..\eval.hpp" />
<ClInclude Include="..\expand.hpp" />
<ClInclude Include="..\cssize.hpp" />
<ClInclude Include="..\listize.hpp" />
<ClInclude Include="..\extend.hpp" />
<ClInclude Include="..\file.hpp" />
<ClInclude Include="..\functions.hpp" />
Expand Down

0 comments on commit 5b6d06a

Please sign in to comment.