Skip to content

Commit 773bba7

Browse files
authored
Merge pull request #2908 from mgreter/feature/selectors-backport
Refactoring / back-porting selectors and extend
2 parents 4d229af + 7c40b00 commit 773bba7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+7583
-7758
lines changed

Makefile.conf

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ SOURCES = \
1111
ast_supports.cpp \
1212
ast_sel_cmp.cpp \
1313
ast_sel_unify.cpp \
14+
ast_sel_super.cpp \
15+
ast_sel_weave.cpp \
1416
ast_selectors.cpp \
15-
node.cpp \
1617
context.cpp \
1718
constants.cpp \
1819
fn_utils.cpp \
@@ -37,19 +38,22 @@ SOURCES = \
3738
position.cpp \
3839
lexer.cpp \
3940
parser.cpp \
41+
parser_selectors.cpp \
4042
prelexer.cpp \
4143
eval.cpp \
44+
eval_selectors.cpp \
4245
expand.cpp \
4346
listize.cpp \
4447
cssize.cpp \
45-
extend.cpp \
48+
extender.cpp \
49+
extension.cpp \
50+
stylesheet.cpp \
4651
output.cpp \
4752
inspect.cpp \
4853
emitter.cpp \
4954
check_nesting.cpp \
5055
remove_placeholders.cpp \
5156
sass.cpp \
52-
sass_util.cpp \
5357
sass_values.cpp \
5458
sass_context.cpp \
5559
sass_functions.cpp \
@@ -60,7 +64,6 @@ SOURCES = \
6064
c2ast.cpp \
6165
to_value.cpp \
6266
source_map.cpp \
63-
subset_map.cpp \
6467
error_handling.cpp \
6568
memory/SharedPtr.cpp \
6669
utf8_string.cpp \

appveyor.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ cache:
2323
- C:\Ruby%ruby_version%\lib\ruby\gems
2424
- C:\mingw64
2525

26+
# Uncomment to debug hanging builds via RDP, password can ve found/set under Environment-Variables in appveyor settings!
27+
#
28+
# init:
29+
# - ps: iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
30+
#
31+
# on_finish:
32+
# - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
33+
2634
install:
2735
- git clone https://github.com/sass/sassc.git
2836
- git clone https://github.com/sass/sass-spec.git

include/sass/base.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ enum Sass_Output_Style {
6868
SASS_STYLE_COMPRESSED,
6969
// only used internaly
7070
SASS_STYLE_INSPECT,
71-
SASS_STYLE_TO_SASS
71+
SASS_STYLE_TO_SASS,
72+
SASS_STYLE_TO_CSS
7273
};
7374

7475
// to allocate buffer to be filled

src/ast.cpp

Lines changed: 49 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
1+
// sass.hpp must go before all system headers to get the
2+
// __EXTENSIONS__ fix on Solaris.
13
#include "sass.hpp"
4+
25
#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>
156
#include <cctype>
167
#include <locale>
178

@@ -69,7 +60,7 @@ namespace Sass {
6960
pstate_.offset += pstate - pstate_ + pstate.offset;
7061
}
7162

72-
const std::string AST_Node::to_string(Sass_Inspect_Options opt) const
63+
std::string AST_Node::to_string(Sass_Inspect_Options opt) const
7364
{
7465
Sass_Output_Options out(opt);
7566
Emitter emitter(out);
@@ -80,19 +71,21 @@ namespace Sass {
8071
return i.get_buffer();
8172
}
8273

83-
const std::string AST_Node::to_string() const
74+
std::string AST_Node::to_css(Sass_Inspect_Options opt) const
8475
{
85-
return to_string({ NESTED, 5 });
76+
opt.output_style = TO_CSS;
77+
Sass_Output_Options out(opt);
78+
Emitter emitter(out);
79+
Inspect i(emitter);
80+
i.in_declaration = true;
81+
// ToDo: inspect should be const
82+
const_cast<AST_Node*>(this)->perform(&i);
83+
return i.get_buffer();
8684
}
8785

88-
/////////////////////////////////////////////////////////////////////////
89-
/////////////////////////////////////////////////////////////////////////
90-
91-
Expression_Obj Hashed::at(Expression_Obj k) const
86+
std::string AST_Node::to_string() const
9287
{
93-
if (elements_.count(k))
94-
{ return elements_.at(k); }
95-
else { return {}; }
88+
return to_string({ NESTED, 5 });
9689
}
9790

9891
/////////////////////////////////////////////////////////////////////////
@@ -137,6 +130,14 @@ namespace Sass {
137130
is_root_(ptr->is_root_)
138131
{ }
139132

133+
bool Block::isInvisible() const
134+
{
135+
for (auto& item : elements()) {
136+
if (!item->is_invisible()) return false;
137+
}
138+
return true;
139+
}
140+
140141
bool Block::has_content()
141142
{
142143
for (size_t i = 0, L = elements().size(); i < L; ++i) {
@@ -163,19 +164,20 @@ namespace Sass {
163164
/////////////////////////////////////////////////////////////////////////
164165
/////////////////////////////////////////////////////////////////////////
165166

166-
Ruleset::Ruleset(ParserState pstate, Selector_List_Obj s, Block_Obj b)
167-
: Has_Block(pstate, b), selector_(s), is_root_(false)
167+
Ruleset::Ruleset(ParserState pstate, SelectorListObj s, Block_Obj b)
168+
: Has_Block(pstate, b), selector_(s), schema_(), is_root_(false)
168169
{ statement_type(RULESET); }
169170
Ruleset::Ruleset(const Ruleset* ptr)
170171
: Has_Block(ptr),
171172
selector_(ptr->selector_),
173+
schema_(ptr->schema_),
172174
is_root_(ptr->is_root_)
173175
{ statement_type(RULESET); }
174176

175177
bool Ruleset::is_invisible() const {
176-
if (Selector_List* sl = Cast<Selector_List>(selector())) {
177-
for (size_t i = 0, L = sl->length(); i < L; ++i)
178-
if (!(*sl)[i]->has_placeholder()) return false;
178+
if (const SelectorList * sl = Cast<SelectorList>(selector())) {
179+
for (size_t i = 0, L = sl->length(); i < L; i += 1)
180+
if (!(*sl)[i]->isInvisible()) return false;
179181
}
180182
return true;
181183
}
@@ -212,30 +214,7 @@ namespace Sass {
212214
/////////////////////////////////////////////////////////////////////////
213215
/////////////////////////////////////////////////////////////////////////
214216

215-
Media_Block::Media_Block(ParserState pstate, List_Obj mqs, Block_Obj b)
216-
: Has_Block(pstate, b), media_queries_(mqs)
217-
{ statement_type(MEDIA); }
218-
Media_Block::Media_Block(const Media_Block* ptr)
219-
: Has_Block(ptr), media_queries_(ptr->media_queries_)
220-
{ statement_type(MEDIA); }
221-
222-
bool Media_Block::is_invisible() const {
223-
for (size_t i = 0, L = block()->length(); i < L; ++i) {
224-
Statement_Obj stm = block()->at(i);
225-
if (!stm->is_invisible()) return false;
226-
}
227-
return true;
228-
}
229-
230-
bool Media_Block::bubbles()
231-
{
232-
return true;
233-
}
234-
235-
/////////////////////////////////////////////////////////////////////////
236-
/////////////////////////////////////////////////////////////////////////
237-
238-
Directive::Directive(ParserState pstate, std::string kwd, Selector_List_Obj sel, Block_Obj b, Expression_Obj val)
217+
Directive::Directive(ParserState pstate, std::string kwd, SelectorListObj sel, Block_Obj b, Expression_Obj val)
239218
: Has_Block(pstate, b), keyword_(kwd), selector_(sel), value_(val) // set value manually if needed
240219
{ statement_type(DIRECTIVE); }
241220
Directive::Directive(const Directive* ptr)
@@ -450,11 +429,19 @@ namespace Sass {
450429
/////////////////////////////////////////////////////////////////////////
451430
/////////////////////////////////////////////////////////////////////////
452431

453-
Extension::Extension(ParserState pstate, Selector_List_Obj s)
454-
: Statement(pstate), selector_(s)
432+
ExtendRule::ExtendRule(ParserState pstate, SelectorListObj s)
433+
: Statement(pstate), isOptional_(false), selector_(s), schema_()
455434
{ statement_type(EXTEND); }
456-
Extension::Extension(const Extension* ptr)
457-
: Statement(ptr), selector_(ptr->selector_)
435+
ExtendRule::ExtendRule(ParserState pstate, Selector_Schema_Obj s)
436+
: Statement(pstate), isOptional_(false), selector_(), schema_(s)
437+
{
438+
statement_type(EXTEND);
439+
}
440+
ExtendRule::ExtendRule(const ExtendRule* ptr)
441+
: Statement(ptr),
442+
isOptional_(ptr->isOptional_),
443+
selector_(ptr->selector_),
444+
schema_(ptr->schema_)
458445
{ statement_type(EXTEND); }
459446

460447
/////////////////////////////////////////////////////////////////////////
@@ -923,8 +910,13 @@ namespace Sass {
923910
/////////////////////////////////////////////////////////////////////////
924911
/////////////////////////////////////////////////////////////////////////
925912

913+
// If you forget to add a class here you will get
914+
// undefined reference to `vtable for Sass::Class'
915+
926916
IMPLEMENT_AST_OPERATORS(Ruleset);
927-
IMPLEMENT_AST_OPERATORS(Media_Block);
917+
IMPLEMENT_AST_OPERATORS(MediaRule);
918+
IMPLEMENT_AST_OPERATORS(CssMediaRule);
919+
IMPLEMENT_AST_OPERATORS(CssMediaQuery);
928920
IMPLEMENT_AST_OPERATORS(Import);
929921
IMPLEMENT_AST_OPERATORS(Import_Stub);
930922
IMPLEMENT_AST_OPERATORS(Directive);
@@ -934,7 +926,7 @@ namespace Sass {
934926
IMPLEMENT_AST_OPERATORS(For);
935927
IMPLEMENT_AST_OPERATORS(If);
936928
IMPLEMENT_AST_OPERATORS(Mixin_Call);
937-
IMPLEMENT_AST_OPERATORS(Extension);
929+
IMPLEMENT_AST_OPERATORS(ExtendRule);
938930
IMPLEMENT_AST_OPERATORS(Media_Query);
939931
IMPLEMENT_AST_OPERATORS(Media_Query_Expression);
940932
IMPLEMENT_AST_OPERATORS(Debug);

0 commit comments

Comments
 (0)