Skip to content

Commit

Permalink
[WIP] Selector and extend refactoring (BIG and WIP!)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgreter committed Jun 12, 2019
1 parent 5ebc5d5 commit de42ad1
Show file tree
Hide file tree
Showing 81 changed files with 7,595 additions and 6,795 deletions.
11 changes: 7 additions & 4 deletions Makefile.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ SOURCES = \
ast_supports.cpp \
ast_sel_cmp.cpp \
ast_sel_unify.cpp \
ast_sel_super.cpp \
ast_sel_weave.cpp \
ast_selectors.cpp \
node.cpp \
context.cpp \
constants.cpp \
fn_utils.cpp \
Expand All @@ -37,19 +38,22 @@ SOURCES = \
position.cpp \
lexer.cpp \
parser.cpp \
parser_selectors.cpp \
prelexer.cpp \
eval.cpp \
eval_selectors.cpp \
expand.cpp \
listize.cpp \
cssize.cpp \
extend.cpp \
extender.cpp \
extension.cpp \
stylesheet.cpp \
output.cpp \
inspect.cpp \
emitter.cpp \
check_nesting.cpp \
remove_placeholders.cpp \
sass.cpp \
sass_util.cpp \
sass_values.cpp \
sass_context.cpp \
sass_functions.cpp \
Expand All @@ -60,7 +64,6 @@ SOURCES = \
c2ast.cpp \
to_value.cpp \
source_map.cpp \
subset_map.cpp \
error_handling.cpp \
memory/SharedPtr.cpp \
utf8_string.cpp \
Expand Down
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ install:
- git clone https://github.com/sass/sass-spec.git
- set PATH=C:\Ruby%ruby_version%\bin;%PATH%
- ps: |
if(!(gem which minitest 2>$nul)) { gem install minitest --no-ri --no-rdoc }
if(!(gem which hrx 2>$nul)) { gem install hrx --no-ri --no-rdoc }
gem install minitest --no-ri --no-rdoc
gem install hrx --no-ri --no-rdoc
if ($env:Compiler -eq "mingw" -AND -Not (Test-Path "C:\mingw64")) {
# Install MinGW.
$file = "x86_64-4.9.2-release-win32-seh-rt_v4-rev3.7z"
Expand Down
3 changes: 2 additions & 1 deletion include/sass/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ enum Sass_Output_Style {
SASS_STYLE_COMPRESSED,
// only used internaly
SASS_STYLE_INSPECT,
SASS_STYLE_TO_SASS
SASS_STYLE_TO_SASS,
SASS_STYLE_TO_CSS
};

// to allocate buffer to be filled
Expand Down
105 changes: 60 additions & 45 deletions src/ast.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#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"
Expand All @@ -17,6 +15,8 @@

namespace Sass {

bool doDebug = false;

static Null sass_null(ParserState("null"));

const char* sass_op_to_name(enum Sass_OP op) {
Expand Down Expand Up @@ -80,6 +80,18 @@ namespace Sass {
return i.get_buffer();
}

const std::string AST_Node::to_css(Sass_Inspect_Options opt) const
{
opt.output_style = TO_CSS;
Sass_Output_Options out(opt);
Emitter emitter(out);
Inspect i(emitter);
i.in_declaration = true;
// ToDo: inspect should be const
const_cast<AST_Node*>(this)->perform(&i);
return i.get_buffer();
}

const std::string AST_Node::to_string() const
{
return to_string({ NESTED, 5 });
Expand Down Expand Up @@ -128,15 +140,23 @@ namespace Sass {

Block::Block(ParserState pstate, size_t s, bool r)
: Statement(pstate),
Vectorized<Statement_Obj>(s),
Vectorized<Statement_Obj, Block>(s),
is_root_(r)
{ }
Block::Block(const Block* ptr)
: Statement(ptr),
Vectorized<Statement_Obj>(*ptr),
Vectorized<Statement_Obj, Block>(*ptr),
is_root_(ptr->is_root_)
{ }

bool Block::isInvisible() const
{
for (auto item : elements()) {
if (!item->is_invisible()) return false;
}
return true;
}

bool Block::has_content()
{
for (size_t i = 0, L = elements().size(); i < L; ++i) {
Expand All @@ -163,21 +183,23 @@ namespace Sass {
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////

Ruleset::Ruleset(ParserState pstate, Selector_List_Obj s, Block_Obj b)
: Has_Block(pstate, b), selector_(s), is_root_(false)
Ruleset::Ruleset(ParserState pstate, SelectorList_Obj s, Block_Obj b)
: Has_Block(pstate, b), selector_(s), schema_(), is_root_(false)
{ statement_type(RULESET); }
Ruleset::Ruleset(const Ruleset* ptr)
: Has_Block(ptr),
selector_(ptr->selector_),
// selector_(ptr->selector_),
schema_(ptr->schema_),
is_root_(ptr->is_root_)
{ statement_type(RULESET); }

bool Ruleset::is_invisible() const {
if (Selector_List* sl = Cast<Selector_List>(selector())) {
if (SelectorList * sl = Cast<SelectorList>(selector())) {
for (size_t i = 0, L = sl->length(); i < L; ++i)
if (!(*sl)[i]->has_placeholder()) return false;
if (!(*sl)[i]->isInvisible()) return false;
}
return true;
return true; // ToDo: hide real invisible ones
}

/////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -212,30 +234,7 @@ namespace Sass {
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////

Media_Block::Media_Block(ParserState pstate, List_Obj mqs, Block_Obj b)
: Has_Block(pstate, b), media_queries_(mqs)
{ statement_type(MEDIA); }
Media_Block::Media_Block(const Media_Block* ptr)
: Has_Block(ptr), media_queries_(ptr->media_queries_)
{ statement_type(MEDIA); }

bool Media_Block::is_invisible() const {
for (size_t i = 0, L = block()->length(); i < L; ++i) {
Statement_Obj stm = block()->at(i);
if (!stm->is_invisible()) return false;
}
return true;
}

bool Media_Block::bubbles()
{
return true;
}

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

Directive::Directive(ParserState pstate, std::string kwd, Selector_List_Obj sel, Block_Obj b, Expression_Obj val)
Directive::Directive(ParserState pstate, std::string kwd, SelectorList_Obj sel, Block_Obj b, Expression_Obj val)
: Has_Block(pstate, b), keyword_(kwd), selector_(sel), value_(val) // set value manually if needed
{ statement_type(DIRECTIVE); }
Directive::Directive(const Directive* ptr)
Expand Down Expand Up @@ -450,11 +449,19 @@ namespace Sass {
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////

Extension::Extension(ParserState pstate, Selector_List_Obj s)
: Statement(pstate), selector_(s)
ExtendRule::ExtendRule(ParserState pstate, SelectorList_Obj s)
: Statement(pstate), isOptional_(false), selector_(s), schema_()
{ statement_type(EXTEND); }
Extension::Extension(const Extension* ptr)
: Statement(ptr), selector_(ptr->selector_)
ExtendRule::ExtendRule(ParserState pstate, Selector_Schema_Obj s)
: Statement(pstate), isOptional_(false), selector_(), schema_(s)
{
statement_type(EXTEND);
}
ExtendRule::ExtendRule(const ExtendRule* ptr)
: Statement(ptr),
isOptional_(ptr->isOptional_),
selector_(ptr->selector_),
schema_(ptr->schema_)
{ statement_type(EXTEND); }

/////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -672,14 +679,14 @@ namespace Sass {

Arguments::Arguments(ParserState pstate)
: Expression(pstate),
Vectorized<Argument_Obj>(),
Vectorized<Argument_Obj, Arguments>(),
has_named_arguments_(false),
has_rest_argument_(false),
has_keyword_argument_(false)
{ }
Arguments::Arguments(const Arguments* ptr)
: Expression(ptr),
Vectorized<Argument_Obj>(*ptr),
Vectorized<Argument_Obj, Arguments>(*ptr),
has_named_arguments_(ptr->has_named_arguments_),
has_rest_argument_(ptr->has_rest_argument_),
has_keyword_argument_(ptr->has_keyword_argument_)
Expand Down Expand Up @@ -754,12 +761,12 @@ namespace Sass {
/////////////////////////////////////////////////////////////////////////

Media_Query::Media_Query(ParserState pstate, String_Obj t, size_t s, bool n, bool r)
: Expression(pstate), Vectorized<Media_Query_Expression_Obj>(s),
: Expression(pstate), Vectorized<Media_Query_Expression_Obj, Media_Query>(s),
media_type_(t), is_negated_(n), is_restricted_(r)
{ }
Media_Query::Media_Query(const Media_Query* ptr)
: Expression(ptr),
Vectorized<Media_Query_Expression_Obj>(*ptr),
Vectorized<Media_Query_Expression_Obj, Media_Query>(*ptr),
media_type_(ptr->media_type_),
is_negated_(ptr->is_negated_),
is_restricted_(ptr->is_restricted_)
Expand Down Expand Up @@ -885,13 +892,13 @@ namespace Sass {

Parameters::Parameters(ParserState pstate)
: AST_Node(pstate),
Vectorized<Parameter_Obj>(),
Vectorized<Parameter_Obj, Parameters>(),
has_optional_parameters_(false),
has_rest_parameter_(false)
{ }
Parameters::Parameters(const Parameters* ptr)
: AST_Node(ptr),
Vectorized<Parameter_Obj>(*ptr),
Vectorized<Parameter_Obj, Parameters>(*ptr),
has_optional_parameters_(ptr->has_optional_parameters_),
has_rest_parameter_(ptr->has_rest_parameter_)
{ }
Expand Down Expand Up @@ -923,8 +930,16 @@ namespace Sass {
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////

// If you forget to add a class here you will get
// undefined reference to `vtable for Sass::Class'

IMPLEMENT_AST_OPERATORS(Ruleset);
IMPLEMENT_AST_OPERATORS(Media_Block);

IMPLEMENT_AST_OPERATORS(MediaRule);
IMPLEMENT_AST_OPERATORS(CssMediaRule);
IMPLEMENT_AST_OPERATORS(CssMediaQuery);


IMPLEMENT_AST_OPERATORS(Import);
IMPLEMENT_AST_OPERATORS(Import_Stub);
IMPLEMENT_AST_OPERATORS(Directive);
Expand All @@ -934,7 +949,7 @@ namespace Sass {
IMPLEMENT_AST_OPERATORS(For);
IMPLEMENT_AST_OPERATORS(If);
IMPLEMENT_AST_OPERATORS(Mixin_Call);
IMPLEMENT_AST_OPERATORS(Extension);
IMPLEMENT_AST_OPERATORS(ExtendRule);
IMPLEMENT_AST_OPERATORS(Media_Query);
IMPLEMENT_AST_OPERATORS(Media_Query_Expression);
IMPLEMENT_AST_OPERATORS(Debug);
Expand Down
Loading

0 comments on commit de42ad1

Please sign in to comment.