Skip to content

Commit 93c62e8

Browse files
committed
Split AST declarations and definitions
1 parent 98aede5 commit 93c62e8

13 files changed

+1557
-1249
lines changed

src/ast.cpp

Lines changed: 42 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,40 @@ namespace Sass {
2222
/////////////////////////////////////////////////////////////////////////
2323
/////////////////////////////////////////////////////////////////////////
2424

25+
void AST_Node::update_pstate(const ParserState& pstate)
26+
{
27+
pstate_.offset += pstate - pstate_ + pstate.offset;
28+
}
29+
30+
const std::string AST_Node::to_string(Sass_Inspect_Options opt) const
31+
{
32+
Sass_Output_Options out(opt);
33+
Emitter emitter(out);
34+
Inspect i(emitter);
35+
i.in_declaration = true;
36+
// ToDo: inspect should be const
37+
const_cast<AST_Node_Ptr>(this)->perform(&i);
38+
return i.get_buffer();
39+
}
40+
41+
const std::string AST_Node::to_string() const
42+
{
43+
return to_string({ NESTED, 5 });
44+
}
45+
46+
/////////////////////////////////////////////////////////////////////////
47+
/////////////////////////////////////////////////////////////////////////
48+
49+
Expression_Obj Hashed::at(Expression_Obj k) const
50+
{
51+
if (elements_.count(k))
52+
{ return elements_.at(k); }
53+
else { return {}; }
54+
}
55+
56+
/////////////////////////////////////////////////////////////////////////
57+
/////////////////////////////////////////////////////////////////////////
58+
2559
Statement::Statement(ParserState pstate, Type st, size_t t)
2660
: AST_Node(pstate), statement_type_(st), tabs_(t), group_end_(false)
2761
{ }
@@ -143,6 +177,14 @@ namespace Sass {
143177
: Has_Block(ptr), media_queries_(ptr->media_queries_)
144178
{ statement_type(MEDIA); }
145179

180+
bool Media_Block::is_invisible() const {
181+
for (size_t i = 0, L = block()->length(); i < L; ++i) {
182+
Statement_Obj stm = block()->at(i);
183+
if (!stm->is_invisible()) return false;
184+
}
185+
return true;
186+
}
187+
146188
bool Media_Block::bubbles()
147189
{
148190
return true;
@@ -767,18 +809,6 @@ namespace Sass {
767809
/////////////////////////////////////////////////////////////////////////
768810
/////////////////////////////////////////////////////////////////////////
769811

770-
Thunk::Thunk(ParserState pstate, Expression_Obj exp, Env* env)
771-
: Expression(pstate), expression_(exp), environment_(env)
772-
{ }
773-
Thunk::Thunk(const Thunk* ptr)
774-
: Expression(ptr->pstate_),
775-
expression_(ptr->expression_),
776-
environment_(ptr->environment_)
777-
{ }
778-
779-
/////////////////////////////////////////////////////////////////////////
780-
/////////////////////////////////////////////////////////////////////////
781-
782812
Parameter::Parameter(ParserState pstate, std::string n, Expression_Obj def, bool rest)
783813
: AST_Node(pstate), name_(n), default_value_(def), is_rest_parameter_(rest)
784814
{ }
@@ -832,80 +862,6 @@ namespace Sass {
832862
/////////////////////////////////////////////////////////////////////////
833863
/////////////////////////////////////////////////////////////////////////
834864

835-
/////////////////////////////////////////////////////////////////////////
836-
/////////////////////////////////////////////////////////////////////////
837-
838-
/////////////////////////////////////////////////////////////////////////
839-
/////////////////////////////////////////////////////////////////////////
840-
841-
/////////////////////////////////////////////////////////////////////////
842-
/////////////////////////////////////////////////////////////////////////
843-
844-
845-
void AST_Node::update_pstate(const ParserState& pstate)
846-
{
847-
pstate_.offset += pstate - pstate_ + pstate.offset;
848-
}
849-
850-
bool Media_Block::is_invisible() const {
851-
for (size_t i = 0, L = block()->length(); i < L; ++i) {
852-
Statement_Obj stm = block()->at(i);
853-
if (!stm->is_invisible()) return false;
854-
}
855-
return true;
856-
}
857-
858-
Expression_Obj Hashed::at(Expression_Obj k) const
859-
{
860-
if (elements_.count(k))
861-
{ return elements_.at(k); }
862-
else { return {}; }
863-
}
864-
865-
bool Binary_Expression::is_left_interpolant(void) const
866-
{
867-
return is_interpolant() || (left() && left()->is_left_interpolant());
868-
}
869-
bool Binary_Expression::is_right_interpolant(void) const
870-
{
871-
return is_interpolant() || (right() && right()->is_right_interpolant());
872-
}
873-
874-
const std::string AST_Node::to_string(Sass_Inspect_Options opt) const
875-
{
876-
Sass_Output_Options out(opt);
877-
Emitter emitter(out);
878-
Inspect i(emitter);
879-
i.in_declaration = true;
880-
// ToDo: inspect should be const
881-
const_cast<AST_Node_Ptr>(this)->perform(&i);
882-
return i.get_buffer();
883-
}
884-
885-
const std::string AST_Node::to_string() const
886-
{
887-
return to_string({ NESTED, 5 });
888-
}
889-
890-
//////////////////////////////////////////////////////////////////////////////////////////
891-
// Additional method on Lists to retrieve values directly or from an encompassed Argument.
892-
//////////////////////////////////////////////////////////////////////////////////////////
893-
Expression_Obj List::value_at_index(size_t i) {
894-
Expression_Obj obj = this->at(i);
895-
if (is_arglist_) {
896-
if (Argument_Ptr arg = Cast<Argument>(obj)) {
897-
return arg->value();
898-
} else {
899-
return obj;
900-
}
901-
} else {
902-
return obj;
903-
}
904-
}
905-
906-
/////////////////////////////////////////////////////////////////////////
907-
/////////////////////////////////////////////////////////////////////////
908-
909865
IMPLEMENT_AST_OPERATORS(Ruleset);
910866
IMPLEMENT_AST_OPERATORS(Media_Block);
911867
IMPLEMENT_AST_OPERATORS(Import);

0 commit comments

Comments
 (0)