Skip to content

Commit 6a1a9ed

Browse files
committed
[WIP] [DNM] Backport dart sass parser 13
1 parent b6bb421 commit 6a1a9ed

34 files changed

+672
-798
lines changed

src/ast.cpp

Lines changed: 42 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ namespace Sass {
154154
{ }
155155
Block::Block(const Block* ptr)
156156
: Statement(ptr),
157-
Vectorized<Statement_Obj>(*ptr),
157+
Vectorized<Statement_Obj>(ptr),
158158
is_root_(ptr->is_root_)
159159
{ }
160160

@@ -166,7 +166,7 @@ namespace Sass {
166166

167167
bool Block::isInvisible() const
168168
{
169-
for (auto& item : elements()) {
169+
for (auto& item : this->elements()) {
170170
if (!item->is_invisible()) return false;
171171
}
172172
return true;
@@ -198,22 +198,16 @@ namespace Sass {
198198
/////////////////////////////////////////////////////////////////////////
199199
/////////////////////////////////////////////////////////////////////////
200200

201-
Ruleset::Ruleset(ParserState pstate, SelectorListObj s, Block_Obj b)
202-
: Has_Block(pstate, b), selector_(s), interpolation_(), is_root_(false)
201+
StyleRule::StyleRule(ParserState pstate, Interpolation* s, Block_Obj b)
202+
: Has_Block(pstate, b), interpolation_(s)
203203
{ statement_type(RULESET); }
204204

205-
Ruleset::Ruleset(ParserState pstate, Interpolation* s, Block_Obj b)
206-
: Has_Block(pstate, b), selector_(), interpolation_(s), is_root_(false)
207-
{ statement_type(RULESET); }
208-
209-
Ruleset::Ruleset(const Ruleset* ptr)
205+
StyleRule::StyleRule(const StyleRule* ptr)
210206
: Has_Block(ptr),
211-
selector_(ptr->selector_),
212-
interpolation_(ptr->interpolation_),
213-
is_root_(ptr->is_root_)
207+
interpolation_(ptr->interpolation_)
214208
{ statement_type(RULESET); }
215209

216-
bool Ruleset::is_invisible() const {
210+
bool CssStyleRule::is_invisible() const {
217211
bool sel_invisible = true;
218212
bool els_invisible = true;
219213
if (const SelectorList * sl = Cast<SelectorList>(selector())) {
@@ -692,17 +686,11 @@ namespace Sass {
692686

693687
Expression::Expression(ParserState pstate, bool d, bool e, bool i, Type ct)
694688
: AST_Node(pstate),
695-
is_delayed_(d),
696-
is_expanded_(e),
697-
is_interpolant_(i),
698689
concrete_type_(ct)
699690
{ }
700691

701692
Expression::Expression(const Expression* ptr)
702693
: AST_Node(ptr),
703-
is_delayed_(ptr->is_delayed_),
704-
is_expanded_(ptr->is_expanded_),
705-
is_interpolant_(ptr->is_interpolant_),
706694
concrete_type_(ptr->concrete_type_)
707695
{ }
708696

@@ -722,34 +710,17 @@ namespace Sass {
722710
expression_(ptr->expression())
723711
{}
724712

725-
size_t ParenthesizedExpression::hash() const
726-
{
727-
if (expression()) {
728-
return expression()->hash();
729-
}
730-
return 0;
731-
}
732-
733713
/////////////////////////////////////////////////////////////////////////
734714
/////////////////////////////////////////////////////////////////////////
735715

736716
Unary_Expression::Unary_Expression(ParserState pstate, Type t, Expression_Obj o)
737-
: Expression(pstate), optype_(t), operand_(o), hash_(0)
717+
: Expression(pstate), optype_(t), operand_(o)
738718
{ }
739719
Unary_Expression::Unary_Expression(const Unary_Expression* ptr)
740720
: Expression(ptr),
741721
optype_(ptr->optype_),
742-
operand_(ptr->operand_),
743-
hash_(ptr->hash_)
722+
operand_(ptr->operand_)
744723
{ }
745-
size_t Unary_Expression::hash() const
746-
{
747-
if (hash_ == 0) {
748-
hash_ = std::hash<size_t>()(optype_);
749-
hash_combine(hash_, operand()->hash());
750-
};
751-
return hash_;
752-
}
753724

754725
/////////////////////////////////////////////////////////////////////////
755726
/////////////////////////////////////////////////////////////////////////
@@ -768,12 +739,6 @@ namespace Sass {
768739
{
769740
}
770741

771-
void Argument::set_delayed(bool delayed)
772-
{
773-
if (value_) value_->set_delayed(delayed);
774-
is_delayed(delayed);
775-
}
776-
777742
size_t Argument::hash() const
778743
{
779744
if (hash_ == 0) {
@@ -788,62 +753,58 @@ namespace Sass {
788753

789754
Arguments::Arguments(ParserState pstate)
790755
: Expression(pstate),
791-
Vectorized<Argument_Obj>(),
792-
has_named_arguments_(false),
793-
has_rest_argument_(false),
794-
has_keyword_argument_(false)
756+
Vectorized<Argument_Obj>()
795757
{ }
796758
Arguments::Arguments(const Arguments* ptr)
797759
: Expression(ptr),
798-
Vectorized<Argument_Obj>(*ptr),
799-
has_named_arguments_(ptr->has_named_arguments_),
800-
has_rest_argument_(ptr->has_rest_argument_),
801-
has_keyword_argument_(ptr->has_keyword_argument_)
760+
Vectorized<Argument_Obj>(*ptr)
802761
{ }
803762

804-
void Arguments::set_delayed(bool delayed)
763+
ArgumentObj Arguments::get_rest_argument()
805764
{
806-
for (Argument_Obj arg : elements()) {
807-
if (arg) arg->set_delayed(delayed);
765+
for (Argument* arg : elements()) {
766+
if (arg->is_rest_argument()) {
767+
return arg;
768+
}
808769
}
809-
is_delayed(delayed);
770+
return ArgumentObj();
810771
}
811772

812-
Argument_Obj Arguments::get_rest_argument()
773+
ArgumentObj Arguments::get_keyword_argument()
813774
{
814-
if (this->has_rest_argument()) {
815-
for (Argument_Obj arg : this->elements()) {
816-
if (arg->is_rest_argument()) {
817-
return arg;
818-
}
775+
for (Argument* arg : elements()) {
776+
if (arg->is_keyword_argument()) {
777+
return arg;
819778
}
820779
}
821-
return {};
780+
return ArgumentObj();
822781
}
823782

824-
Argument_Obj Arguments::get_keyword_argument()
825-
{
826-
if (this->has_keyword_argument()) {
827-
for (Argument_Obj arg : this->elements()) {
828-
if (arg->is_keyword_argument()) {
829-
return arg;
830-
}
783+
bool Arguments::hasRestArgument() const {
784+
for (const Argument* arg : elements()) {
785+
if (arg->is_rest_argument()) {
786+
return true;
831787
}
832788
}
833-
return {};
789+
return false;
834790
}
835791

836-
void Arguments::adjust_after_pushing(Argument_Obj a)
837-
{
838-
if (!a->name().empty()) {
839-
has_named_arguments(true);
840-
}
841-
else if (a->is_rest_argument()) {
842-
has_rest_argument(true);
792+
bool Arguments::hasNamedArgument() const {
793+
for (const Argument* arg : elements()) {
794+
if (!arg->name().empty()) {
795+
return true;
796+
}
843797
}
844-
else if (a->is_keyword_argument()) {
845-
has_keyword_argument(true);
798+
return false;
799+
}
800+
801+
bool Arguments::hasKeywordArgument() const {
802+
for (const Argument* arg : elements()) {
803+
if (arg->is_keyword_argument()) {
804+
return true;
805+
}
846806
}
807+
return false;
847808
}
848809

849810
/////////////////////////////////////////////////////////////////////////
@@ -965,23 +926,13 @@ namespace Sass {
965926
has_rest_parameter_(ptr->has_rest_parameter_)
966927
{ }
967928

968-
void Parameters::adjust_after_pushing(Parameter_Obj p)
969-
{
970-
if (p->default_value()) {
971-
has_optional_parameters(true);
972-
}
973-
else if (p->is_rest_parameter()) {
974-
has_rest_parameter(true);
975-
}
976-
}
977-
978929
/////////////////////////////////////////////////////////////////////////
979930
/////////////////////////////////////////////////////////////////////////
980931

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

984-
IMPLEMENT_AST_OPERATORS(Ruleset);
935+
IMPLEMENT_AST_OPERATORS(StyleRule);
985936
IMPLEMENT_AST_OPERATORS(MediaRule);
986937
IMPLEMENT_AST_OPERATORS(Import);
987938
IMPLEMENT_AST_OPERATORS(Import_Stub);

0 commit comments

Comments
 (0)