Skip to content

Commit

Permalink
Add improved source-mapping implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
mgreter committed Dec 31, 2014
1 parent 420d7fb commit 33a9e45
Show file tree
Hide file tree
Showing 36 changed files with 1,386 additions and 1,038 deletions.
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ SOURCES = \
output_compressed.cpp \
output_nested.cpp \
parser.cpp \
position.cpp \
prelexer.cpp \
remove_placeholders.cpp \
sass.cpp \
Expand All @@ -127,14 +128,14 @@ SOURCES = \

CSOURCES = cencode.c

RESOURCES =
RESOURCES =

LIBRARIES = lib/libsass.so

ifeq (MinGW,$(UNAME))
ifeq (shared,$(BUILD))
CFLAGS += -D ADD_EXPORTS
CXXFLAGS += -D ADD_EXPORTS
CFLAGS += -D ADD_EXPORTS
CXXFLAGS += -D ADD_EXPORTS
LIBRARIES += lib/libsass.dll
RESOURCES += res/resource.rc
endif
Expand Down
3 changes: 2 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ lib_LTLIBRARIES = libsass.la
libsass_la_SOURCES = \
ast_fwd_decl.hpp ast_def_macros.hpp \
kwd_arg_macros.hpp memory_manager.hpp \
position.hpp operation.hpp \
position.cpp position.hpp \
operation.hpp \
subset_map.hpp mapping.hpp \
color_names.hpp backtrace.hpp \
cencode.c b64/cencode.h b64/encode.h \
Expand Down
70 changes: 35 additions & 35 deletions ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,34 @@ namespace Sass {
return const_cast<Complex_Selector*>(this)->perform(&to_string) <
const_cast<Complex_Selector&>(rhs).perform(&to_string);
}

bool Complex_Selector::operator==(const Complex_Selector& rhs) const {
// TODO: We have to access the tail directly using tail_ since ADD_PROPERTY doesn't provide a const version.

const Complex_Selector* pOne = this;
const Complex_Selector* pTwo = &rhs;

// Consume any empty references at the beginning of the Complex_Selector
if (pOne->combinator() == Complex_Selector::ANCESTOR_OF && pOne->head()->is_empty_reference()) {
pOne = pOne->tail_;
}
if (pTwo->combinator() == Complex_Selector::ANCESTOR_OF && pTwo->head()->is_empty_reference()) {
pTwo = pTwo->tail_;
}

while (pOne && pTwo) {
if (pOne->combinator() != pTwo->combinator()) {
return false;
}

if (*(pOne->head()) != *(pTwo->head())) {
return false;
}

pOne = pOne->tail_;
pTwo = pTwo->tail_;
}

return pOne == NULL && pTwo == NULL;
}

Expand All @@ -63,7 +63,7 @@ namespace Sass {
}
return unified;
}

bool Simple_Selector::operator==(const Simple_Selector& rhs) const
{
// Compare the string representations for equality.
Expand All @@ -75,14 +75,14 @@ namespace Sass {
To_String to_string;
return pLHS->perform(&to_string) == pRHS->perform(&to_string);
}

bool Simple_Selector::operator<(const Simple_Selector& rhs) const {
// Use the string representation for ordering.

// Cast away const here. To_String should take a const object, but it doesn't.
Simple_Selector* pLHS = const_cast<Simple_Selector*>(this);
Simple_Selector* pRHS = const_cast<Simple_Selector*>(&rhs);

To_String to_string;
return pLHS->perform(&to_string) < pRHS->perform(&to_string);
}
Expand All @@ -102,7 +102,7 @@ namespace Sass {
{
if ((typeid(*(*rhs)[i]) == typeid(Pseudo_Selector) || typeid(*(*rhs)[i]) == typeid(Wrapped_Selector)) && (*rhs)[L-1]->is_pseudo_element())
{ found = true; break; }
}
}
}
else
{
Expand All @@ -118,7 +118,7 @@ namespace Sass {
(*cpy) << this;
return cpy;
}
Compound_Selector* cpy = new (ctx.mem) Compound_Selector(rhs->path(), rhs->position());
Compound_Selector* cpy = new (ctx.mem) Compound_Selector(rhs->pstate());
for (size_t j = 0; j < i; ++j)
{ (*cpy) << (*rhs)[j]; }
(*cpy) << this;
Expand All @@ -133,15 +133,15 @@ namespace Sass {

// if the rhs is empty, just return a copy of this
if (rhs->length() == 0) {
Compound_Selector* cpy = new (ctx.mem) Compound_Selector(rhs->path(), rhs->position());
Compound_Selector* cpy = new (ctx.mem) Compound_Selector(rhs->pstate());
(*cpy) << this;
return cpy;
}

// if this is a universal selector and rhs is not empty, just return the rhs
if (name() == "*")
{ return new (ctx.mem) Compound_Selector(*rhs); }


Simple_Selector* rhs_0 = (*rhs)[0];
// otherwise, this is a tag name
Expand All @@ -150,7 +150,7 @@ namespace Sass {
// if rhs is universal, just return this tagname + rhs's qualifiers
if (static_cast<Type_Selector*>(rhs_0)->name() == "*")
{
Compound_Selector* cpy = new (ctx.mem) Compound_Selector(rhs->path(), rhs->position());
Compound_Selector* cpy = new (ctx.mem) Compound_Selector(rhs->pstate());
(*cpy) << this;
for (size_t i = 1, L = rhs->length(); i < L; ++i)
{ (*cpy) << (*rhs)[i]; }
Expand All @@ -164,7 +164,7 @@ namespace Sass {
{ return 0; }
}
// else it's a tag name and a bunch of qualifiers -- just append them
Compound_Selector* cpy = new (ctx.mem) Compound_Selector(rhs->path(), rhs->position());
Compound_Selector* cpy = new (ctx.mem) Compound_Selector(rhs->pstate());
(*cpy) << this;
(*cpy) += rhs;
return cpy;
Expand Down Expand Up @@ -208,9 +208,9 @@ namespace Sass {

Simple_Selector* lbase = base();
Simple_Selector* rbase = rhs->base();

// Check if pseudo-elements are the same between the selectors

set<string> lpsuedoset, rpsuedoset;
for (size_t i = 0, L = length(); i < L; ++i)
{
Expand Down Expand Up @@ -262,12 +262,12 @@ namespace Sass {
// catch-all
return false;
}

bool Compound_Selector::operator==(const Compound_Selector& rhs) const {
To_String to_string;

// Check if pseudo-elements are the same between the selectors

set<string> lpsuedoset, rpsuedoset;
for (size_t i = 0, L = length(); i < L; ++i)
{
Expand All @@ -290,33 +290,33 @@ namespace Sass {
}

// Check the base

const Simple_Selector* const lbase = base();
const Simple_Selector* const rbase = rhs.base();

if ((lbase && !rbase) ||
(!lbase && rbase) ||
((lbase && rbase) && (*lbase != *rbase))) {
return false;
}


// Check the rest of the SimpleSelectors
// Use string representations. We can't create a set of Simple_Selector pointers because std::set == std::set is going to call ==
// on the pointers to determine equality. I don't know of a way to pass in a comparison object. The one you can specify as part of
// the template type is used for ordering, but not equality. We also can't just put in non-pointer Simple_Selectors because the
// class is intended to be subclassed, and we'd get splicing.

set<string> lset, rset;

for (size_t i = 0, L = length(); i < L; ++i)
{ lset.insert((*this)[i]->perform(&to_string)); }
for (size_t i = 0, L = rhs.length(); i < L; ++i)
{ rset.insert(rhs[i]->perform(&to_string)); }

return lset == rset;
}

bool Complex_Selector_Pointer_Compare::operator() (const Complex_Selector* const pLeft, const Complex_Selector* const pRight) const {
return *pLeft < *pRight;
}
Expand Down Expand Up @@ -361,7 +361,7 @@ namespace Sass {
if (!found)
{ return false; }

/*
/*
Hmm, I hope I have the logic right:
if lhs has a combinator:
Expand Down Expand Up @@ -413,7 +413,7 @@ namespace Sass {
{
if (!tail()) return 0;
if (!head()) return tail()->context(ctx);
return new (ctx.mem) Complex_Selector(path(), position(), combinator(), head(), tail()->context(ctx));
return new (ctx.mem) Complex_Selector(pstate(), combinator(), head(), tail()->context(ctx));
}

Complex_Selector* Complex_Selector::innermost()
Expand Down Expand Up @@ -446,7 +446,7 @@ namespace Sass {
if (tail()) cpy->tail(tail()->clone(ctx));
return cpy;
}

Complex_Selector* Complex_Selector::cloneFully(Context& ctx) const
{
Complex_Selector* cpy = new (ctx.mem) Complex_Selector(*this);
Expand All @@ -461,20 +461,20 @@ namespace Sass {

return cpy;
}

Compound_Selector* Compound_Selector::clone(Context& ctx) const
{
Compound_Selector* cpy = new (ctx.mem) Compound_Selector(*this);
return cpy;
}



Selector_Placeholder* Selector::find_placeholder()
{
return 0;
}

void Selector_List::adjust_after_pushing(Complex_Selector* c)
{
if (c->has_reference()) has_reference(true);
Expand Down Expand Up @@ -534,7 +534,7 @@ namespace Sass {
Compound_Selector* Compound_Selector::minus(Compound_Selector* rhs, Context& ctx)
{
To_String to_string;
Compound_Selector* result = new (ctx.mem) Compound_Selector(path(), position());
Compound_Selector* result = new (ctx.mem) Compound_Selector(pstate());

// not very efficient because it needs to preserve order
for (size_t i = 0, L = length(); i < L; ++i)
Expand All @@ -554,7 +554,7 @@ namespace Sass {

return result;
}

void Compound_Selector::mergeSources(SourcesSet& sources, Context& ctx)
{
for (SourcesSet::iterator iterator = sources.begin(), endIterator = sources.end(); iterator != endIterator; ++iterator) {
Expand Down
Loading

0 comments on commit 33a9e45

Please sign in to comment.