Skip to content

Commit 98aede5

Browse files
committed
Move AST supports into own compile units
1 parent 058e763 commit 98aede5

File tree

7 files changed

+261
-177
lines changed

7 files changed

+261
-177
lines changed

Makefile.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
SOURCES = \
99
ast.cpp \
1010
ast_values.cpp \
11+
ast_supports.cpp \
1112
ast_sel_cmp.cpp \
1213
ast_sel_unify.cpp \
1314
ast_selectors.cpp \

src/ast.cpp

Lines changed: 7 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -679,87 +679,6 @@ namespace Sass {
679679
/////////////////////////////////////////////////////////////////////////
680680
/////////////////////////////////////////////////////////////////////////
681681

682-
Supports_Block::Supports_Block(ParserState pstate, Supports_Condition_Obj condition, Block_Obj block)
683-
: Has_Block(pstate, block), condition_(condition)
684-
{ statement_type(SUPPORTS); }
685-
Supports_Block::Supports_Block(const Supports_Block* ptr)
686-
: Has_Block(ptr), condition_(ptr->condition_)
687-
{ statement_type(SUPPORTS); }
688-
bool Supports_Block::bubbles() { return true; }
689-
690-
/////////////////////////////////////////////////////////////////////////
691-
/////////////////////////////////////////////////////////////////////////
692-
693-
Supports_Operator::Supports_Operator(ParserState pstate, Supports_Condition_Obj l, Supports_Condition_Obj r, Operand o)
694-
: Supports_Condition(pstate), left_(l), right_(r), operand_(o)
695-
{ }
696-
Supports_Operator::Supports_Operator(const Supports_Operator* ptr)
697-
: Supports_Condition(ptr),
698-
left_(ptr->left_),
699-
right_(ptr->right_),
700-
operand_(ptr->operand_)
701-
{ }
702-
703-
bool Supports_Operator::needs_parens(Supports_Condition_Obj cond) const
704-
{
705-
if (Supports_Operator_Obj op = Cast<Supports_Operator>(cond)) {
706-
return op->operand() != operand();
707-
}
708-
return Cast<Supports_Negation>(cond) != NULL;
709-
}
710-
711-
/////////////////////////////////////////////////////////////////////////
712-
/////////////////////////////////////////////////////////////////////////
713-
714-
Supports_Negation::Supports_Negation(ParserState pstate, Supports_Condition_Obj c)
715-
: Supports_Condition(pstate), condition_(c)
716-
{ }
717-
Supports_Negation::Supports_Negation(const Supports_Negation* ptr)
718-
: Supports_Condition(ptr), condition_(ptr->condition_)
719-
{ }
720-
721-
bool Supports_Negation::needs_parens(Supports_Condition_Obj cond) const
722-
{
723-
return Cast<Supports_Negation>(cond) ||
724-
Cast<Supports_Operator>(cond);
725-
}
726-
727-
/////////////////////////////////////////////////////////////////////////
728-
/////////////////////////////////////////////////////////////////////////
729-
730-
Supports_Declaration::Supports_Declaration(ParserState pstate, Expression_Obj f, Expression_Obj v)
731-
: Supports_Condition(pstate), feature_(f), value_(v)
732-
{ }
733-
Supports_Declaration::Supports_Declaration(const Supports_Declaration* ptr)
734-
: Supports_Condition(ptr),
735-
feature_(ptr->feature_),
736-
value_(ptr->value_)
737-
{ }
738-
739-
bool Supports_Declaration::needs_parens(Supports_Condition_Obj cond) const
740-
{
741-
return false;
742-
}
743-
744-
/////////////////////////////////////////////////////////////////////////
745-
/////////////////////////////////////////////////////////////////////////
746-
747-
Supports_Interpolation::Supports_Interpolation(ParserState pstate, Expression_Obj v)
748-
: Supports_Condition(pstate), value_(v)
749-
{ }
750-
Supports_Interpolation::Supports_Interpolation(const Supports_Interpolation* ptr)
751-
: Supports_Condition(ptr),
752-
value_(ptr->value_)
753-
{ }
754-
755-
bool Supports_Interpolation::needs_parens(Supports_Condition_Obj cond) const
756-
{
757-
return false;
758-
}
759-
760-
/////////////////////////////////////////////////////////////////////////
761-
/////////////////////////////////////////////////////////////////////////
762-
763682
At_Root_Query::At_Root_Query(ParserState pstate, Expression_Obj f, Expression_Obj v, bool i)
764683
: Expression(pstate), feature_(f), value_(v)
765684
{ }
@@ -984,15 +903,15 @@ namespace Sass {
984903
}
985904
}
986905

987-
IMPLEMENT_AST_OPERATORS(Supports_Operator);
988-
IMPLEMENT_AST_OPERATORS(Supports_Negation);
906+
/////////////////////////////////////////////////////////////////////////
907+
/////////////////////////////////////////////////////////////////////////
908+
989909
IMPLEMENT_AST_OPERATORS(Ruleset);
990910
IMPLEMENT_AST_OPERATORS(Media_Block);
991911
IMPLEMENT_AST_OPERATORS(Import);
992912
IMPLEMENT_AST_OPERATORS(Import_Stub);
993913
IMPLEMENT_AST_OPERATORS(Directive);
994914
IMPLEMENT_AST_OPERATORS(At_Root_Block);
995-
IMPLEMENT_AST_OPERATORS(Supports_Block);
996915
IMPLEMENT_AST_OPERATORS(While);
997916
IMPLEMENT_AST_OPERATORS(Each);
998917
IMPLEMENT_AST_OPERATORS(For);
@@ -1008,9 +927,6 @@ namespace Sass {
1008927
IMPLEMENT_AST_OPERATORS(Return);
1009928
IMPLEMENT_AST_OPERATORS(At_Root_Query);
1010929
IMPLEMENT_AST_OPERATORS(Comment);
1011-
IMPLEMENT_AST_OPERATORS(Supports_Interpolation);
1012-
IMPLEMENT_AST_OPERATORS(Supports_Declaration);
1013-
IMPLEMENT_AST_OPERATORS(Supports_Condition);
1014930
IMPLEMENT_AST_OPERATORS(Parameters);
1015931
IMPLEMENT_AST_OPERATORS(Parameter);
1016932
IMPLEMENT_AST_OPERATORS(Arguments);
@@ -1023,4 +939,8 @@ namespace Sass {
1023939
IMPLEMENT_AST_OPERATORS(Bubble);
1024940
IMPLEMENT_AST_OPERATORS(Definition);
1025941
IMPLEMENT_AST_OPERATORS(Declaration);
942+
943+
/////////////////////////////////////////////////////////////////////////
944+
/////////////////////////////////////////////////////////////////////////
945+
1026946
}

src/ast.hpp

Lines changed: 1 addition & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -903,96 +903,6 @@ namespace Sass {
903903
ATTACH_CRTP_PERFORM_METHODS()
904904
};
905905

906-
////////////////////
907-
// `@supports` rule.
908-
////////////////////
909-
class Supports_Block final : public Has_Block {
910-
ADD_PROPERTY(Supports_Condition_Obj, condition)
911-
public:
912-
Supports_Block(ParserState pstate, Supports_Condition_Obj condition, Block_Obj block = {});
913-
Supports_Block(const Supports_Block* ptr);
914-
bool bubbles();
915-
ATTACH_AST_OPERATIONS(Supports_Block)
916-
ATTACH_CRTP_PERFORM_METHODS()
917-
};
918-
919-
//////////////////////////////////////////////////////
920-
// The abstract superclass of all Supports conditions.
921-
//////////////////////////////////////////////////////
922-
class Supports_Condition : public Expression {
923-
public:
924-
Supports_Condition(ParserState pstate)
925-
: Expression(pstate)
926-
{ }
927-
Supports_Condition(const Supports_Condition* ptr)
928-
: Expression(ptr)
929-
{ }
930-
virtual bool needs_parens(Supports_Condition_Obj cond) const { return false; }
931-
ATTACH_AST_OPERATIONS(Supports_Condition)
932-
ATTACH_CRTP_PERFORM_METHODS()
933-
};
934-
935-
////////////////////////////////////////////////////////////
936-
// An operator condition (e.g. `CONDITION1 and CONDITION2`).
937-
////////////////////////////////////////////////////////////
938-
class Supports_Operator final : public Supports_Condition {
939-
public:
940-
enum Operand { AND, OR };
941-
private:
942-
ADD_PROPERTY(Supports_Condition_Obj, left);
943-
ADD_PROPERTY(Supports_Condition_Obj, right);
944-
ADD_PROPERTY(Operand, operand);
945-
public:
946-
Supports_Operator(ParserState pstate, Supports_Condition_Obj l, Supports_Condition_Obj r, Operand o);
947-
Supports_Operator(const Supports_Operator* ptr);
948-
bool needs_parens(Supports_Condition_Obj cond) const override;
949-
ATTACH_AST_OPERATIONS(Supports_Operator)
950-
ATTACH_CRTP_PERFORM_METHODS()
951-
};
952-
953-
//////////////////////////////////////////
954-
// A negation condition (`not CONDITION`).
955-
//////////////////////////////////////////
956-
class Supports_Negation final : public Supports_Condition {
957-
private:
958-
ADD_PROPERTY(Supports_Condition_Obj, condition);
959-
public:
960-
Supports_Negation(ParserState pstate, Supports_Condition_Obj c);
961-
Supports_Negation(const Supports_Negation* ptr);
962-
bool needs_parens(Supports_Condition_Obj cond) const override;
963-
ATTACH_AST_OPERATIONS(Supports_Negation)
964-
ATTACH_CRTP_PERFORM_METHODS()
965-
};
966-
967-
/////////////////////////////////////////////////////
968-
// A declaration condition (e.g. `(feature: value)`).
969-
/////////////////////////////////////////////////////
970-
class Supports_Declaration final : public Supports_Condition {
971-
private:
972-
ADD_PROPERTY(Expression_Obj, feature);
973-
ADD_PROPERTY(Expression_Obj, value);
974-
public:
975-
Supports_Declaration(ParserState pstate, Expression_Obj f, Expression_Obj v);
976-
Supports_Declaration(const Supports_Declaration* ptr);
977-
virtual bool needs_parens(Supports_Condition_Obj cond) const;
978-
ATTACH_AST_OPERATIONS(Supports_Declaration)
979-
ATTACH_CRTP_PERFORM_METHODS()
980-
};
981-
982-
///////////////////////////////////////////////
983-
// An interpolation condition (e.g. `#{$var}`).
984-
///////////////////////////////////////////////
985-
class Supports_Interpolation final : public Supports_Condition {
986-
private:
987-
ADD_PROPERTY(Expression_Obj, value);
988-
public:
989-
Supports_Interpolation(ParserState pstate, Expression_Obj v);
990-
Supports_Interpolation(const Supports_Interpolation* ptr);
991-
virtual bool needs_parens(Supports_Condition_Obj cond) const;
992-
ATTACH_AST_OPERATIONS(Supports_Interpolation)
993-
ATTACH_CRTP_PERFORM_METHODS()
994-
};
995-
996906
/////////////////////////////////////////////////
997907
// At root expressions (for use inside @at-root).
998908
/////////////////////////////////////////////////
@@ -1067,6 +977,7 @@ namespace Sass {
1067977
}
1068978

1069979
#include "ast_values.hpp"
980+
#include "ast_supports.hpp"
1070981
#include "ast_selectors.hpp"
1071982

1072983
#ifdef __clang__

src/ast_supports.cpp

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
#include "sass.hpp"
2+
#include "ast.hpp"
3+
#include "context.hpp"
4+
#include "node.hpp"
5+
#include "eval.hpp"
6+
#include "extend.hpp"
7+
#include "emitter.hpp"
8+
#include "color_maps.hpp"
9+
#include "ast_fwd_decl.hpp"
10+
#include <set>
11+
#include <iomanip>
12+
#include <iostream>
13+
#include <algorithm>
14+
#include <functional>
15+
#include <cctype>
16+
#include <locale>
17+
18+
#include "ast_values.hpp"
19+
20+
namespace Sass {
21+
22+
/////////////////////////////////////////////////////////////////////////
23+
/////////////////////////////////////////////////////////////////////////
24+
25+
Supports_Block::Supports_Block(ParserState pstate, Supports_Condition_Obj condition, Block_Obj block)
26+
: Has_Block(pstate, block), condition_(condition)
27+
{ statement_type(SUPPORTS); }
28+
Supports_Block::Supports_Block(const Supports_Block* ptr)
29+
: Has_Block(ptr), condition_(ptr->condition_)
30+
{ statement_type(SUPPORTS); }
31+
bool Supports_Block::bubbles() { return true; }
32+
33+
/////////////////////////////////////////////////////////////////////////
34+
/////////////////////////////////////////////////////////////////////////
35+
36+
Supports_Operator::Supports_Operator(ParserState pstate, Supports_Condition_Obj l, Supports_Condition_Obj r, Operand o)
37+
: Supports_Condition(pstate), left_(l), right_(r), operand_(o)
38+
{ }
39+
Supports_Operator::Supports_Operator(const Supports_Operator* ptr)
40+
: Supports_Condition(ptr),
41+
left_(ptr->left_),
42+
right_(ptr->right_),
43+
operand_(ptr->operand_)
44+
{ }
45+
46+
bool Supports_Operator::needs_parens(Supports_Condition_Obj cond) const
47+
{
48+
if (Supports_Operator_Obj op = Cast<Supports_Operator>(cond)) {
49+
return op->operand() != operand();
50+
}
51+
return Cast<Supports_Negation>(cond) != NULL;
52+
}
53+
54+
/////////////////////////////////////////////////////////////////////////
55+
/////////////////////////////////////////////////////////////////////////
56+
57+
Supports_Negation::Supports_Negation(ParserState pstate, Supports_Condition_Obj c)
58+
: Supports_Condition(pstate), condition_(c)
59+
{ }
60+
Supports_Negation::Supports_Negation(const Supports_Negation* ptr)
61+
: Supports_Condition(ptr), condition_(ptr->condition_)
62+
{ }
63+
64+
bool Supports_Negation::needs_parens(Supports_Condition_Obj cond) const
65+
{
66+
return Cast<Supports_Negation>(cond) ||
67+
Cast<Supports_Operator>(cond);
68+
}
69+
70+
/////////////////////////////////////////////////////////////////////////
71+
/////////////////////////////////////////////////////////////////////////
72+
73+
Supports_Declaration::Supports_Declaration(ParserState pstate, Expression_Obj f, Expression_Obj v)
74+
: Supports_Condition(pstate), feature_(f), value_(v)
75+
{ }
76+
Supports_Declaration::Supports_Declaration(const Supports_Declaration* ptr)
77+
: Supports_Condition(ptr),
78+
feature_(ptr->feature_),
79+
value_(ptr->value_)
80+
{ }
81+
82+
bool Supports_Declaration::needs_parens(Supports_Condition_Obj cond) const
83+
{
84+
return false;
85+
}
86+
87+
/////////////////////////////////////////////////////////////////////////
88+
/////////////////////////////////////////////////////////////////////////
89+
90+
Supports_Interpolation::Supports_Interpolation(ParserState pstate, Expression_Obj v)
91+
: Supports_Condition(pstate), value_(v)
92+
{ }
93+
Supports_Interpolation::Supports_Interpolation(const Supports_Interpolation* ptr)
94+
: Supports_Condition(ptr),
95+
value_(ptr->value_)
96+
{ }
97+
98+
bool Supports_Interpolation::needs_parens(Supports_Condition_Obj cond) const
99+
{
100+
return false;
101+
}
102+
103+
/////////////////////////////////////////////////////////////////////////
104+
/////////////////////////////////////////////////////////////////////////
105+
106+
IMPLEMENT_AST_OPERATORS(Supports_Block);
107+
IMPLEMENT_AST_OPERATORS(Supports_Condition);
108+
IMPLEMENT_AST_OPERATORS(Supports_Operator);
109+
IMPLEMENT_AST_OPERATORS(Supports_Negation);
110+
IMPLEMENT_AST_OPERATORS(Supports_Declaration);
111+
IMPLEMENT_AST_OPERATORS(Supports_Interpolation);
112+
113+
/////////////////////////////////////////////////////////////////////////
114+
/////////////////////////////////////////////////////////////////////////
115+
116+
}

0 commit comments

Comments
 (0)