Skip to content

Commit 367c070

Browse files
committed
Make some AST methods pure virtual
1 parent 5196b3b commit 367c070

File tree

2 files changed

+59
-8
lines changed

2 files changed

+59
-8
lines changed

src/ast.cpp

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -307,18 +307,63 @@ namespace Sass {
307307
return unified.detach();
308308
}
309309

310-
bool Selector::operator== (const Selector& rhs) const
310+
bool Complex_Selector::operator== (const Selector& rhs) const
311311
{
312-
if (const Selector_List* sl = Cast<Selector_List>(this)) return *sl == rhs;
313-
if (Simple_Selector_Ptr_Const sp = Cast<Simple_Selector>(this)) return *sp == rhs;
312+
if (const Selector_List* sl = Cast<Selector_List>(&rhs)) return *this == *sl;
313+
if (const Simple_Selector* sp = Cast<Simple_Selector>(&rhs)) return *this == *sp;
314+
if (const Complex_Selector* cs = Cast<Complex_Selector>(&rhs)) return *this == *cs;
315+
if (const Compound_Selector* ch = Cast<Compound_Selector>(&rhs)) return *this == *ch;
314316
throw std::runtime_error("invalid selector base classes to compare");
315317
return false;
316318
}
317319

318-
bool Selector::operator< (const Selector& rhs) const
320+
321+
bool Complex_Selector::operator< (const Selector& rhs) const
322+
{
323+
if (const Selector_List* sl = Cast<Selector_List>(&rhs)) return *this < *sl;
324+
if (const Simple_Selector* sp = Cast<Simple_Selector>(&rhs)) return *this < *sp;
325+
if (const Complex_Selector* cs = Cast<Complex_Selector>(&rhs)) return *this < *cs;
326+
if (const Compound_Selector* ch = Cast<Compound_Selector>(&rhs)) return *this < *ch;
327+
throw std::runtime_error("invalid selector base classes to compare");
328+
return false;
329+
}
330+
331+
bool Compound_Selector::operator== (const Selector& rhs) const
332+
{
333+
if (const Selector_List* sl = Cast<Selector_List>(&rhs)) return *this == *sl;
334+
if (const Simple_Selector* sp = Cast<Simple_Selector>(&rhs)) return *this == *sp;
335+
if (const Complex_Selector* cs = Cast<Complex_Selector>(&rhs)) return *this == *cs;
336+
if (const Compound_Selector* ch = Cast<Compound_Selector>(&rhs)) return *this == *ch;
337+
throw std::runtime_error("invalid selector base classes to compare");
338+
return false;
339+
}
340+
341+
bool Compound_Selector::operator< (const Selector& rhs) const
342+
{
343+
if (const Selector_List* sl = Cast<Selector_List>(&rhs)) return *this < *sl;
344+
if (const Simple_Selector* sp = Cast<Simple_Selector>(&rhs)) return *this < *sp;
345+
if (const Complex_Selector* cs = Cast<Complex_Selector>(&rhs)) return *this < *cs;
346+
if (const Compound_Selector* ch = Cast<Compound_Selector>(&rhs)) return *this < *ch;
347+
throw std::runtime_error("invalid selector base classes to compare");
348+
return false;
349+
}
350+
351+
bool Selector_Schema::operator== (const Selector& rhs) const
352+
{
353+
if (const Selector_List* sl = Cast<Selector_List>(&rhs)) return *this == *sl;
354+
if (const Simple_Selector* sp = Cast<Simple_Selector>(&rhs)) return *this == *sp;
355+
if (const Complex_Selector* cs = Cast<Complex_Selector>(&rhs)) return *this == *cs;
356+
if (const Compound_Selector* ch = Cast<Compound_Selector>(&rhs)) return *this == *ch;
357+
throw std::runtime_error("invalid selector base classes to compare");
358+
return false;
359+
}
360+
361+
bool Selector_Schema::operator< (const Selector& rhs) const
319362
{
320-
if (Selector_List_Ptr_Const sl = Cast<Selector_List>(this)) return *sl < rhs;
321-
if (Simple_Selector_Ptr_Const sp = Cast<Simple_Selector>(this)) return *sp < rhs;
363+
if (const Selector_List* sl = Cast<Selector_List>(&rhs)) return *this < *sl;
364+
if (const Simple_Selector* sp = Cast<Simple_Selector>(&rhs)) return *this < *sp;
365+
if (const Complex_Selector* cs = Cast<Complex_Selector>(&rhs)) return *this < *cs;
366+
if (const Compound_Selector* ch = Cast<Compound_Selector>(&rhs)) return *this < *ch;
322367
throw std::runtime_error("invalid selector base classes to compare");
323368
return false;
324369
}

src/ast.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2307,8 +2307,8 @@ namespace Sass {
23072307
return false;
23082308
}
23092309
// dispatch to correct handlers
2310-
virtual bool operator<(const Selector& rhs) const;
2311-
virtual bool operator==(const Selector& rhs) const;
2310+
virtual bool operator<(const Selector& rhs) const = 0;
2311+
virtual bool operator==(const Selector& rhs) const = 0;
23122312
ATTACH_VIRTUAL_AST_OPERATIONS(Selector);
23132313
};
23142314
inline Selector::~Selector() { }
@@ -2333,6 +2333,8 @@ namespace Sass {
23332333
{ }
23342334
virtual bool has_parent_ref();
23352335
virtual bool has_real_parent_ref();
2336+
virtual bool operator<(const Selector& rhs) const;
2337+
virtual bool operator==(const Selector& rhs) const;
23362338
// selector schema is not yet a final selector, so we do not
23372339
// have a specificity for it yet. We need to
23382340
virtual unsigned long specificity() const { return 0; }
@@ -2789,6 +2791,8 @@ namespace Sass {
27892791
Cast<Parent_Selector>((*this)[0]);
27902792
}
27912793

2794+
virtual bool operator<(const Selector& rhs) const;
2795+
virtual bool operator==(const Selector& rhs) const;
27922796
virtual bool operator<(const Compound_Selector& rhs) const;
27932797
virtual bool operator==(const Compound_Selector& rhs) const;
27942798
inline bool operator!=(const Compound_Selector& rhs) const { return !(*this == rhs); }
@@ -2908,6 +2912,8 @@ namespace Sass {
29082912
if (tail_ && tail_->has_placeholder()) return true;
29092913
return false;
29102914
}
2915+
virtual bool operator<(const Selector& rhs) const;
2916+
virtual bool operator==(const Selector& rhs) const;
29112917
virtual bool operator<(const Complex_Selector& rhs) const;
29122918
virtual bool operator==(const Complex_Selector& rhs) const;
29132919
inline bool operator!=(const Complex_Selector& rhs) const { return !(*this == rhs); }

0 commit comments

Comments
 (0)