ext/libsass/src/node.cpp in sassc-1.11.1 vs ext/libsass/src/node.cpp in sassc-1.11.2

- old
+ new

@@ -6,62 +6,62 @@ #include "parser.hpp" namespace Sass { - Node Node::createCombinator(const Sequence_Selector::Combinator& combinator) { + Node Node::createCombinator(const Complex_Selector::Combinator& combinator) { NodeDequePtr null; return Node(COMBINATOR, combinator, NULL /*pSelector*/, null /*pCollection*/); } - Node Node::createSelector(Sequence_Selector* pSelector, Context& ctx) { + Node Node::createSelector(Complex_Selector_Ptr pSelector, Context& ctx) { NodeDequePtr null; - Sequence_Selector* pStripped = pSelector->clone(ctx); + Complex_Selector_Ptr pStripped = SASS_MEMORY_COPY(pSelector); pStripped->tail(NULL); - pStripped->combinator(Sequence_Selector::ANCESTOR_OF); + pStripped->combinator(Complex_Selector::ANCESTOR_OF); - Node n(SELECTOR, Sequence_Selector::ANCESTOR_OF, pStripped, null /*pCollection*/); + Node n(SELECTOR, Complex_Selector::ANCESTOR_OF, pStripped, null /*pCollection*/); if (pSelector) n.got_line_feed = pSelector->has_line_feed(); return n; } Node Node::createCollection() { NodeDequePtr pEmptyCollection = std::make_shared<NodeDeque>(); - return Node(COLLECTION, Sequence_Selector::ANCESTOR_OF, NULL /*pSelector*/, pEmptyCollection); + return Node(COLLECTION, Complex_Selector::ANCESTOR_OF, NULL /*pSelector*/, pEmptyCollection); } Node Node::createCollection(const NodeDeque& values) { NodeDequePtr pShallowCopiedCollection = std::make_shared<NodeDeque>(values); - return Node(COLLECTION, Sequence_Selector::ANCESTOR_OF, NULL /*pSelector*/, pShallowCopiedCollection); + return Node(COLLECTION, Complex_Selector::ANCESTOR_OF, NULL /*pSelector*/, pShallowCopiedCollection); } Node Node::createNil() { NodeDequePtr null; - return Node(NIL, Sequence_Selector::ANCESTOR_OF, NULL /*pSelector*/, null /*pCollection*/); + return Node(NIL, Complex_Selector::ANCESTOR_OF, NULL /*pSelector*/, null /*pCollection*/); } - Node::Node(const TYPE& type, Sequence_Selector::Combinator combinator, Sequence_Selector* pSelector, NodeDequePtr& pCollection) + Node::Node(const TYPE& type, Complex_Selector::Combinator combinator, Complex_Selector_Ptr pSelector, NodeDequePtr& pCollection) : got_line_feed(false), mType(type), mCombinator(combinator), mpSelector(pSelector), mpCollection(pCollection) { if (pSelector) got_line_feed = pSelector->has_line_feed(); } - Node Node::clone(Context& ctx) const { + Node Node::klone(Context& ctx) const { NodeDequePtr pNewCollection = std::make_shared<NodeDeque>(); if (mpCollection) { for (NodeDeque::iterator iter = mpCollection->begin(), iterEnd = mpCollection->end(); iter != iterEnd; iter++) { Node& toClone = *iter; - pNewCollection->push_back(toClone.clone(ctx)); + pNewCollection->push_back(toClone.klone(ctx)); } } - Node n(mType, mCombinator, mpSelector ? mpSelector->clone(ctx) : NULL, pNewCollection); + Node n(mType, mCombinator, mpSelector ? SASS_MEMORY_COPY(mpSelector) : NULL, pNewCollection); n.got_line_feed = got_line_feed; return n; } @@ -99,11 +99,11 @@ return true; // no state to check } else if (lhs.isSelector()){ - return selectors_equal(*lhs.selector(), *rhs.selector(), simpleSelectorOrderDependent); + return selectors_equal(*&lhs.selector(), *&rhs.selector(), simpleSelectorOrderDependent); } else if (lhs.isCollection()) { if (lhs.collection()->size() != rhs.collection()->size()) { return false; @@ -138,15 +138,15 @@ std::ostream& operator<<(std::ostream& os, const Node& node) { if (node.isCombinator()) { switch (node.combinator()) { - case Sequence_Selector::ANCESTOR_OF: os << "\" \""; break; - case Sequence_Selector::PARENT_OF: os << "\">\""; break; - case Sequence_Selector::PRECEDES: os << "\"~\""; break; - case Sequence_Selector::ADJACENT_TO: os << "\"+\""; break; - case Sequence_Selector::REFERENCE: os << "\"/\""; break; + case Complex_Selector::ANCESTOR_OF: os << "\" \""; break; + case Complex_Selector::PARENT_OF: os << "\">\""; break; + case Complex_Selector::PRECEDES: os << "\"~\""; break; + case Complex_Selector::ADJACENT_TO: os << "\"+\""; break; + case Complex_Selector::REFERENCE: os << "\"/\""; break; } } else if (node.isNil()) { os << "nil"; @@ -175,129 +175,131 @@ } #endif - Node complexSelectorToNode(Sequence_Selector* pToConvert, Context& ctx) { + Node complexSelectorToNode(Complex_Selector_Ptr pToConvert, Context& ctx) { if (pToConvert == NULL) { return Node::createNil(); } Node node = Node::createCollection(); node.got_line_feed = pToConvert->has_line_feed(); bool has_lf = pToConvert->has_line_feed(); // unwrap the selector from parent ref if (pToConvert->head() && pToConvert->head()->has_parent_ref()) { - Sequence_Selector* tail = pToConvert->tail(); + Complex_Selector_Obj tail = pToConvert->tail(); if (tail) tail->has_line_feed(pToConvert->has_line_feed()); - pToConvert = tail; + pToConvert = &tail; } while (pToConvert) { bool empty_parent_ref = pToConvert->head() && pToConvert->head()->is_empty_reference(); - if (pToConvert->head() == NULL || empty_parent_ref) { + if (pToConvert->head() || empty_parent_ref) { } - // the first Sequence_Selector may contain a dummy head pointer, skip it. - if (pToConvert->head() != NULL && !empty_parent_ref) { + // the first Complex_Selector may contain a dummy head pointer, skip it. + if (pToConvert->head() && !empty_parent_ref) { node.collection()->push_back(Node::createSelector(pToConvert, ctx)); if (has_lf) node.collection()->back().got_line_feed = has_lf; has_lf = false; } - if (pToConvert->combinator() != Sequence_Selector::ANCESTOR_OF) { + if (pToConvert->combinator() != Complex_Selector::ANCESTOR_OF) { node.collection()->push_back(Node::createCombinator(pToConvert->combinator())); if (has_lf) node.collection()->back().got_line_feed = has_lf; has_lf = false; } if (pToConvert && empty_parent_ref && pToConvert->tail()) { // pToConvert->tail()->has_line_feed(pToConvert->has_line_feed()); } - pToConvert = pToConvert->tail(); + pToConvert = &pToConvert->tail(); } return node; } - Sequence_Selector* nodeToComplexSelector(const Node& toConvert, Context& ctx) { + Complex_Selector_Ptr nodeToComplexSelector(const Node& toConvert, Context& ctx) { if (toConvert.isNil()) { return NULL; } if (!toConvert.isCollection()) { - throw "The node to convert to a Sequence_Selector* must be a collection type or nil."; + throw "The node to convert to a Complex_Selector_Ptr must be a collection type or nil."; } NodeDeque& childNodes = *toConvert.collection(); std::string noPath(""); Position noPosition(-1, -1, -1); - Sequence_Selector* pFirst = SASS_MEMORY_NEW(ctx.mem, Sequence_Selector, ParserState("[NODE]"), Sequence_Selector::ANCESTOR_OF, NULL, NULL); + Complex_Selector_Obj pFirst = SASS_MEMORY_NEW(Complex_Selector, ParserState("[NODE]"), Complex_Selector::ANCESTOR_OF, NULL, NULL); - Sequence_Selector* pCurrent = pFirst; + Complex_Selector_Obj pCurrent = pFirst; if (toConvert.isSelector()) pFirst->has_line_feed(toConvert.got_line_feed); if (toConvert.isCombinator()) pFirst->has_line_feed(toConvert.got_line_feed); for (NodeDeque::iterator childIter = childNodes.begin(), childIterEnd = childNodes.end(); childIter != childIterEnd; childIter++) { Node& child = *childIter; if (child.isSelector()) { - pCurrent->tail(child.selector()->clone(ctx)); // JMA - need to clone the selector, because they can end up getting shared across Node collections, and can result in an infinite loop during the call to parentSuperselector() + // JMA - need to clone the selector, because they can end up getting shared across Node + // collections, and can result in an infinite loop during the call to parentSuperselector() + pCurrent->tail(SASS_MEMORY_COPY(child.selector())); // if (child.got_line_feed) pCurrent->has_line_feed(child.got_line_feed); - pCurrent = pCurrent->tail(); + pCurrent = &pCurrent->tail(); } else if (child.isCombinator()) { pCurrent->combinator(child.combinator()); if (child.got_line_feed) pCurrent->has_line_feed(child.got_line_feed); - // if the next node is also a combinator, create another Sequence_Selector to hold it so it doesn't replace the current combinator + // if the next node is also a combinator, create another Complex_Selector to hold it so it doesn't replace the current combinator if (childIter+1 != childIterEnd) { Node& nextNode = *(childIter+1); if (nextNode.isCombinator()) { - pCurrent->tail(SASS_MEMORY_NEW(ctx.mem, Sequence_Selector, ParserState("[NODE]"), Sequence_Selector::ANCESTOR_OF, NULL, NULL)); + pCurrent->tail(SASS_MEMORY_NEW(Complex_Selector, ParserState("[NODE]"), Complex_Selector::ANCESTOR_OF, NULL, NULL)); if (nextNode.got_line_feed) pCurrent->tail()->has_line_feed(nextNode.got_line_feed); - pCurrent = pCurrent->tail(); + pCurrent = &pCurrent->tail(); } } } else { throw "The node to convert's children must be only combinators or selectors."; } } - // Put the dummy SimpleSequence_Selector in the first position, for consistency with the rest of libsass - SimpleSequence_Selector* fakeHead = SASS_MEMORY_NEW(ctx.mem, SimpleSequence_Selector, ParserState("[NODE]"), 1); - Parent_Selector* selectorRef = SASS_MEMORY_NEW(ctx.mem, Parent_Selector, ParserState("[NODE]")); + // Put the dummy Compound_Selector in the first position, for consistency with the rest of libsass + Compound_Selector_Ptr fakeHead = SASS_MEMORY_NEW(Compound_Selector, ParserState("[NODE]"), 1); + Parent_Selector_Ptr selectorRef = SASS_MEMORY_NEW(Parent_Selector, ParserState("[NODE]")); fakeHead->elements().push_back(selectorRef); if (toConvert.got_line_feed) pFirst->has_line_feed(toConvert.got_line_feed); // pFirst->has_line_feed(pFirst->has_line_feed() || pFirst->tail()->has_line_feed() || toConvert.got_line_feed); pFirst->head(fakeHead); - return pFirst; + return SASS_MEMORY_COPY(pFirst); } // A very naive trim function, which removes duplicates in a node - // This is only used in Sequence_Selector::unify_with for now, may need modifications to fit other needs + // This is only used in Complex_Selector::unify_with for now, may need modifications to fit other needs Node Node::naiveTrim(Node& seqses, Context& ctx) { std::vector<Node*> res; - std::vector<Sequence_Selector*> known; + std::vector<Complex_Selector_Obj> known; NodeDeque::reverse_iterator seqsesIter = seqses.collection()->rbegin(), seqsesIterEnd = seqses.collection()->rend(); for (; seqsesIter != seqsesIterEnd; ++seqsesIter) { Node& seqs1 = *seqsesIter; if( seqs1.isSelector() ) { - Sequence_Selector* sel = seqs1.selector(); - std::vector<Sequence_Selector*>::iterator it; + Complex_Selector_Obj sel = seqs1.selector(); + std::vector<Complex_Selector_Obj>::iterator it; bool found = false; for (it = known.begin(); it != known.end(); ++it) { if (**it == *sel) { found = true; break; } } if( !found ) {