diff --git a/Makefile.conf b/Makefile.conf index cb7637528..c692e6cd6 100644 --- a/Makefile.conf +++ b/Makefile.conf @@ -8,6 +8,7 @@ SOURCES = \ ast.cpp \ ast_values.cpp \ + ast_supports.cpp \ ast_sel_cmp.cpp \ ast_sel_unify.cpp \ ast_selectors.cpp \ diff --git a/src/ast.cpp b/src/ast.cpp index a60052ddf..ceb5a206c 100644 --- a/src/ast.cpp +++ b/src/ast.cpp @@ -679,87 +679,6 @@ namespace Sass { ///////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////// - Supports_Block::Supports_Block(ParserState pstate, Supports_Condition_Obj condition, Block_Obj block) - : Has_Block(pstate, block), condition_(condition) - { statement_type(SUPPORTS); } - Supports_Block::Supports_Block(const Supports_Block* ptr) - : Has_Block(ptr), condition_(ptr->condition_) - { statement_type(SUPPORTS); } - bool Supports_Block::bubbles() { return true; } - - ///////////////////////////////////////////////////////////////////////// - ///////////////////////////////////////////////////////////////////////// - - Supports_Operator::Supports_Operator(ParserState pstate, Supports_Condition_Obj l, Supports_Condition_Obj r, Operand o) - : Supports_Condition(pstate), left_(l), right_(r), operand_(o) - { } - Supports_Operator::Supports_Operator(const Supports_Operator* ptr) - : Supports_Condition(ptr), - left_(ptr->left_), - right_(ptr->right_), - operand_(ptr->operand_) - { } - - bool Supports_Operator::needs_parens(Supports_Condition_Obj cond) const - { - if (Supports_Operator_Obj op = Cast(cond)) { - return op->operand() != operand(); - } - return Cast(cond) != NULL; - } - - ///////////////////////////////////////////////////////////////////////// - ///////////////////////////////////////////////////////////////////////// - - Supports_Negation::Supports_Negation(ParserState pstate, Supports_Condition_Obj c) - : Supports_Condition(pstate), condition_(c) - { } - Supports_Negation::Supports_Negation(const Supports_Negation* ptr) - : Supports_Condition(ptr), condition_(ptr->condition_) - { } - - bool Supports_Negation::needs_parens(Supports_Condition_Obj cond) const - { - return Cast(cond) || - Cast(cond); - } - - ///////////////////////////////////////////////////////////////////////// - ///////////////////////////////////////////////////////////////////////// - - Supports_Declaration::Supports_Declaration(ParserState pstate, Expression_Obj f, Expression_Obj v) - : Supports_Condition(pstate), feature_(f), value_(v) - { } - Supports_Declaration::Supports_Declaration(const Supports_Declaration* ptr) - : Supports_Condition(ptr), - feature_(ptr->feature_), - value_(ptr->value_) - { } - - bool Supports_Declaration::needs_parens(Supports_Condition_Obj cond) const - { - return false; - } - - ///////////////////////////////////////////////////////////////////////// - ///////////////////////////////////////////////////////////////////////// - - Supports_Interpolation::Supports_Interpolation(ParserState pstate, Expression_Obj v) - : Supports_Condition(pstate), value_(v) - { } - Supports_Interpolation::Supports_Interpolation(const Supports_Interpolation* ptr) - : Supports_Condition(ptr), - value_(ptr->value_) - { } - - bool Supports_Interpolation::needs_parens(Supports_Condition_Obj cond) const - { - return false; - } - - ///////////////////////////////////////////////////////////////////////// - ///////////////////////////////////////////////////////////////////////// - At_Root_Query::At_Root_Query(ParserState pstate, Expression_Obj f, Expression_Obj v, bool i) : Expression(pstate), feature_(f), value_(v) { } @@ -984,15 +903,15 @@ namespace Sass { } } - IMPLEMENT_AST_OPERATORS(Supports_Operator); - IMPLEMENT_AST_OPERATORS(Supports_Negation); + ///////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////// + IMPLEMENT_AST_OPERATORS(Ruleset); IMPLEMENT_AST_OPERATORS(Media_Block); IMPLEMENT_AST_OPERATORS(Import); IMPLEMENT_AST_OPERATORS(Import_Stub); IMPLEMENT_AST_OPERATORS(Directive); IMPLEMENT_AST_OPERATORS(At_Root_Block); - IMPLEMENT_AST_OPERATORS(Supports_Block); IMPLEMENT_AST_OPERATORS(While); IMPLEMENT_AST_OPERATORS(Each); IMPLEMENT_AST_OPERATORS(For); @@ -1008,9 +927,6 @@ namespace Sass { IMPLEMENT_AST_OPERATORS(Return); IMPLEMENT_AST_OPERATORS(At_Root_Query); IMPLEMENT_AST_OPERATORS(Comment); - IMPLEMENT_AST_OPERATORS(Supports_Interpolation); - IMPLEMENT_AST_OPERATORS(Supports_Declaration); - IMPLEMENT_AST_OPERATORS(Supports_Condition); IMPLEMENT_AST_OPERATORS(Parameters); IMPLEMENT_AST_OPERATORS(Parameter); IMPLEMENT_AST_OPERATORS(Arguments); @@ -1023,4 +939,8 @@ namespace Sass { IMPLEMENT_AST_OPERATORS(Bubble); IMPLEMENT_AST_OPERATORS(Definition); IMPLEMENT_AST_OPERATORS(Declaration); + + ///////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////// + } diff --git a/src/ast.hpp b/src/ast.hpp index 2f924bbbe..71a5186af 100644 --- a/src/ast.hpp +++ b/src/ast.hpp @@ -903,96 +903,6 @@ namespace Sass { ATTACH_CRTP_PERFORM_METHODS() }; - //////////////////// - // `@supports` rule. - //////////////////// - class Supports_Block final : public Has_Block { - ADD_PROPERTY(Supports_Condition_Obj, condition) - public: - Supports_Block(ParserState pstate, Supports_Condition_Obj condition, Block_Obj block = {}); - Supports_Block(const Supports_Block* ptr); - bool bubbles(); - ATTACH_AST_OPERATIONS(Supports_Block) - ATTACH_CRTP_PERFORM_METHODS() - }; - - ////////////////////////////////////////////////////// - // The abstract superclass of all Supports conditions. - ////////////////////////////////////////////////////// - class Supports_Condition : public Expression { - public: - Supports_Condition(ParserState pstate) - : Expression(pstate) - { } - Supports_Condition(const Supports_Condition* ptr) - : Expression(ptr) - { } - virtual bool needs_parens(Supports_Condition_Obj cond) const { return false; } - ATTACH_AST_OPERATIONS(Supports_Condition) - ATTACH_CRTP_PERFORM_METHODS() - }; - - //////////////////////////////////////////////////////////// - // An operator condition (e.g. `CONDITION1 and CONDITION2`). - //////////////////////////////////////////////////////////// - class Supports_Operator final : public Supports_Condition { - public: - enum Operand { AND, OR }; - private: - ADD_PROPERTY(Supports_Condition_Obj, left); - ADD_PROPERTY(Supports_Condition_Obj, right); - ADD_PROPERTY(Operand, operand); - public: - Supports_Operator(ParserState pstate, Supports_Condition_Obj l, Supports_Condition_Obj r, Operand o); - Supports_Operator(const Supports_Operator* ptr); - bool needs_parens(Supports_Condition_Obj cond) const override; - ATTACH_AST_OPERATIONS(Supports_Operator) - ATTACH_CRTP_PERFORM_METHODS() - }; - - ////////////////////////////////////////// - // A negation condition (`not CONDITION`). - ////////////////////////////////////////// - class Supports_Negation final : public Supports_Condition { - private: - ADD_PROPERTY(Supports_Condition_Obj, condition); - public: - Supports_Negation(ParserState pstate, Supports_Condition_Obj c); - Supports_Negation(const Supports_Negation* ptr); - bool needs_parens(Supports_Condition_Obj cond) const override; - ATTACH_AST_OPERATIONS(Supports_Negation) - ATTACH_CRTP_PERFORM_METHODS() - }; - - ///////////////////////////////////////////////////// - // A declaration condition (e.g. `(feature: value)`). - ///////////////////////////////////////////////////// - class Supports_Declaration final : public Supports_Condition { - private: - ADD_PROPERTY(Expression_Obj, feature); - ADD_PROPERTY(Expression_Obj, value); - public: - Supports_Declaration(ParserState pstate, Expression_Obj f, Expression_Obj v); - Supports_Declaration(const Supports_Declaration* ptr); - virtual bool needs_parens(Supports_Condition_Obj cond) const; - ATTACH_AST_OPERATIONS(Supports_Declaration) - ATTACH_CRTP_PERFORM_METHODS() - }; - - /////////////////////////////////////////////// - // An interpolation condition (e.g. `#{$var}`). - /////////////////////////////////////////////// - class Supports_Interpolation final : public Supports_Condition { - private: - ADD_PROPERTY(Expression_Obj, value); - public: - Supports_Interpolation(ParserState pstate, Expression_Obj v); - Supports_Interpolation(const Supports_Interpolation* ptr); - virtual bool needs_parens(Supports_Condition_Obj cond) const; - ATTACH_AST_OPERATIONS(Supports_Interpolation) - ATTACH_CRTP_PERFORM_METHODS() - }; - ///////////////////////////////////////////////// // At root expressions (for use inside @at-root). ///////////////////////////////////////////////// @@ -1067,6 +977,7 @@ namespace Sass { } #include "ast_values.hpp" +#include "ast_supports.hpp" #include "ast_selectors.hpp" #ifdef __clang__ diff --git a/src/ast_supports.cpp b/src/ast_supports.cpp new file mode 100644 index 000000000..571a57245 --- /dev/null +++ b/src/ast_supports.cpp @@ -0,0 +1,116 @@ +#include "sass.hpp" +#include "ast.hpp" +#include "context.hpp" +#include "node.hpp" +#include "eval.hpp" +#include "extend.hpp" +#include "emitter.hpp" +#include "color_maps.hpp" +#include "ast_fwd_decl.hpp" +#include +#include +#include +#include +#include +#include +#include + +#include "ast_values.hpp" + +namespace Sass { + + ///////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////// + + Supports_Block::Supports_Block(ParserState pstate, Supports_Condition_Obj condition, Block_Obj block) + : Has_Block(pstate, block), condition_(condition) + { statement_type(SUPPORTS); } + Supports_Block::Supports_Block(const Supports_Block* ptr) + : Has_Block(ptr), condition_(ptr->condition_) + { statement_type(SUPPORTS); } + bool Supports_Block::bubbles() { return true; } + + ///////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////// + + Supports_Operator::Supports_Operator(ParserState pstate, Supports_Condition_Obj l, Supports_Condition_Obj r, Operand o) + : Supports_Condition(pstate), left_(l), right_(r), operand_(o) + { } + Supports_Operator::Supports_Operator(const Supports_Operator* ptr) + : Supports_Condition(ptr), + left_(ptr->left_), + right_(ptr->right_), + operand_(ptr->operand_) + { } + + bool Supports_Operator::needs_parens(Supports_Condition_Obj cond) const + { + if (Supports_Operator_Obj op = Cast(cond)) { + return op->operand() != operand(); + } + return Cast(cond) != NULL; + } + + ///////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////// + + Supports_Negation::Supports_Negation(ParserState pstate, Supports_Condition_Obj c) + : Supports_Condition(pstate), condition_(c) + { } + Supports_Negation::Supports_Negation(const Supports_Negation* ptr) + : Supports_Condition(ptr), condition_(ptr->condition_) + { } + + bool Supports_Negation::needs_parens(Supports_Condition_Obj cond) const + { + return Cast(cond) || + Cast(cond); + } + + ///////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////// + + Supports_Declaration::Supports_Declaration(ParserState pstate, Expression_Obj f, Expression_Obj v) + : Supports_Condition(pstate), feature_(f), value_(v) + { } + Supports_Declaration::Supports_Declaration(const Supports_Declaration* ptr) + : Supports_Condition(ptr), + feature_(ptr->feature_), + value_(ptr->value_) + { } + + bool Supports_Declaration::needs_parens(Supports_Condition_Obj cond) const + { + return false; + } + + ///////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////// + + Supports_Interpolation::Supports_Interpolation(ParserState pstate, Expression_Obj v) + : Supports_Condition(pstate), value_(v) + { } + Supports_Interpolation::Supports_Interpolation(const Supports_Interpolation* ptr) + : Supports_Condition(ptr), + value_(ptr->value_) + { } + + bool Supports_Interpolation::needs_parens(Supports_Condition_Obj cond) const + { + return false; + } + + ///////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////// + + IMPLEMENT_AST_OPERATORS(Supports_Block); + IMPLEMENT_AST_OPERATORS(Supports_Condition); + IMPLEMENT_AST_OPERATORS(Supports_Operator); + IMPLEMENT_AST_OPERATORS(Supports_Negation); + IMPLEMENT_AST_OPERATORS(Supports_Declaration); + IMPLEMENT_AST_OPERATORS(Supports_Interpolation); + + ///////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////// + +} \ No newline at end of file diff --git a/src/ast_supports.hpp b/src/ast_supports.hpp new file mode 100644 index 000000000..e112876a9 --- /dev/null +++ b/src/ast_supports.hpp @@ -0,0 +1,128 @@ +#ifndef SASS_AST_SUPPORTS_H +#define SASS_AST_SUPPORTS_H + +#include "sass.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include "sass/base.h" +#include "ast_fwd_decl.hpp" + +#include "util.hpp" +#include "units.hpp" +#include "context.hpp" +#include "position.hpp" +#include "constants.hpp" +#include "operation.hpp" +#include "position.hpp" +#include "inspect.hpp" +#include "source_map.hpp" +#include "environment.hpp" +#include "error_handling.hpp" +#include "ast_def_macros.hpp" +#include "ast_fwd_decl.hpp" +#include "source_map.hpp" +#include "fn_utils.hpp" + +#include "sass.h" + +namespace Sass { + + //////////////////// + // `@supports` rule. + //////////////////// + class Supports_Block : public Has_Block { + ADD_PROPERTY(Supports_Condition_Obj, condition) + public: + Supports_Block(ParserState pstate, Supports_Condition_Obj condition, Block_Obj block = {}); + Supports_Block(const Supports_Block* ptr); + bool bubbles(); + ATTACH_AST_OPERATIONS(Supports_Block) + ATTACH_CRTP_PERFORM_METHODS() + }; + + ////////////////////////////////////////////////////// + // The abstract superclass of all Supports conditions. + ////////////////////////////////////////////////////// + class Supports_Condition : public Expression { + public: + Supports_Condition(ParserState pstate) + : Expression(pstate) + { } + Supports_Condition(const Supports_Condition* ptr) + : Expression(ptr) + { } + virtual bool needs_parens(Supports_Condition_Obj cond) const { return false; } + ATTACH_AST_OPERATIONS(Supports_Condition) + ATTACH_CRTP_PERFORM_METHODS() + }; + + //////////////////////////////////////////////////////////// + // An operator condition (e.g. `CONDITION1 and CONDITION2`). + //////////////////////////////////////////////////////////// + class Supports_Operator : public Supports_Condition { + public: + enum Operand { AND, OR }; + private: + ADD_PROPERTY(Supports_Condition_Obj, left); + ADD_PROPERTY(Supports_Condition_Obj, right); + ADD_PROPERTY(Operand, operand); + public: + Supports_Operator(ParserState pstate, Supports_Condition_Obj l, Supports_Condition_Obj r, Operand o); + Supports_Operator(const Supports_Operator* ptr); + virtual bool needs_parens(Supports_Condition_Obj cond) const; + ATTACH_AST_OPERATIONS(Supports_Operator) + ATTACH_CRTP_PERFORM_METHODS() + }; + + ////////////////////////////////////////// + // A negation condition (`not CONDITION`). + ////////////////////////////////////////// + class Supports_Negation : public Supports_Condition { + private: + ADD_PROPERTY(Supports_Condition_Obj, condition); + public: + Supports_Negation(ParserState pstate, Supports_Condition_Obj c); + Supports_Negation(const Supports_Negation* ptr); + virtual bool needs_parens(Supports_Condition_Obj cond) const; + ATTACH_AST_OPERATIONS(Supports_Negation) + ATTACH_CRTP_PERFORM_METHODS() + }; + + ///////////////////////////////////////////////////// + // A declaration condition (e.g. `(feature: value)`). + ///////////////////////////////////////////////////// + class Supports_Declaration : public Supports_Condition { + private: + ADD_PROPERTY(Expression_Obj, feature); + ADD_PROPERTY(Expression_Obj, value); + public: + Supports_Declaration(ParserState pstate, Expression_Obj f, Expression_Obj v); + Supports_Declaration(const Supports_Declaration* ptr); + virtual bool needs_parens(Supports_Condition_Obj cond) const; + ATTACH_AST_OPERATIONS(Supports_Declaration) + ATTACH_CRTP_PERFORM_METHODS() + }; + + /////////////////////////////////////////////// + // An interpolation condition (e.g. `#{$var}`). + /////////////////////////////////////////////// + class Supports_Interpolation : public Supports_Condition { + private: + ADD_PROPERTY(Expression_Obj, value); + public: + Supports_Interpolation(ParserState pstate, Expression_Obj v); + Supports_Interpolation(const Supports_Interpolation* ptr); + virtual bool needs_parens(Supports_Condition_Obj cond) const; + ATTACH_AST_OPERATIONS(Supports_Interpolation) + ATTACH_CRTP_PERFORM_METHODS() + }; + +} + +#endif \ No newline at end of file diff --git a/win/libsass.targets b/win/libsass.targets index 5c7dda247..085577637 100644 --- a/win/libsass.targets +++ b/win/libsass.targets @@ -13,6 +13,7 @@ + @@ -80,6 +81,7 @@ + diff --git a/win/libsass.vcxproj.filters b/win/libsass.vcxproj.filters index 855ad11c2..a53aaeb8e 100644 --- a/win/libsass.vcxproj.filters +++ b/win/libsass.vcxproj.filters @@ -54,6 +54,9 @@ Headers + + Headers + Headers @@ -254,6 +257,9 @@ Sources + + Sources + Sources