Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
Move AST supports into own compile units
Browse files Browse the repository at this point in the history
  • Loading branch information
mgreter committed Nov 29, 2018
1 parent 058e763 commit 98aede5
Show file tree
Hide file tree
Showing 7 changed files with 261 additions and 177 deletions.
1 change: 1 addition & 0 deletions Makefile.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
SOURCES = \
ast.cpp \
ast_values.cpp \
ast_supports.cpp \
ast_sel_cmp.cpp \
ast_sel_unify.cpp \
ast_selectors.cpp \
Expand Down
94 changes: 7 additions & 87 deletions src/ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Supports_Operator>(cond)) {
return op->operand() != operand();
}
return Cast<Supports_Negation>(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<Supports_Negation>(cond) ||
Cast<Supports_Operator>(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)
{ }
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -1023,4 +939,8 @@ namespace Sass {
IMPLEMENT_AST_OPERATORS(Bubble);
IMPLEMENT_AST_OPERATORS(Definition);
IMPLEMENT_AST_OPERATORS(Declaration);

/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////

}
91 changes: 1 addition & 90 deletions src/ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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).
/////////////////////////////////////////////////
Expand Down Expand Up @@ -1067,6 +977,7 @@ namespace Sass {
}

#include "ast_values.hpp"
#include "ast_supports.hpp"
#include "ast_selectors.hpp"

#ifdef __clang__
Expand Down
116 changes: 116 additions & 0 deletions src/ast_supports.cpp
Original file line number Diff line number Diff line change
@@ -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 <set>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
#include <cctype>
#include <locale>

#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<Supports_Operator>(cond)) {
return op->operand() != operand();
}
return Cast<Supports_Negation>(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<Supports_Negation>(cond) ||
Cast<Supports_Operator>(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);

/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////

}
Loading

0 comments on commit 98aede5

Please sign in to comment.