Skip to content

Commit 2f47dae

Browse files
committed
Merge pull request #2087 from xzyfer/feat/implement-trace
Add the Trace AST node
2 parents 34bcd3f + d4499d3 commit 2f47dae

File tree

6 files changed

+35
-7
lines changed

6 files changed

+35
-7
lines changed

src/ast.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,18 @@ namespace Sass {
507507
ATTACH_OPERATIONS()
508508
};
509509

510+
/////////////////
511+
// Trace.
512+
/////////////////
513+
class Trace : public Has_Block {
514+
ADD_PROPERTY(std::string, name)
515+
public:
516+
Trace(ParserState pstate, std::string n, Block* b = 0)
517+
: Has_Block(pstate, b), name_(n)
518+
{ }
519+
ATTACH_OPERATIONS()
520+
};
521+
510522
/////////////////
511523
// Media queries.
512524
/////////////////

src/ast_fwd_decl.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace Sass {
1313
class Ruleset;
1414
class Propset;
1515
class Bubble;
16+
class Trace;
1617
class Media_Block;
1718
class Supports_Block;
1819
class Directive;

src/cssize.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ namespace Sass {
3939
return bb;
4040
}
4141

42+
Statement* Cssize::operator()(Trace* t)
43+
{
44+
return t->block()->perform(this);
45+
}
46+
4247
Statement* Cssize::operator()(Directive* r)
4348
{
4449
if (!r->block() || !r->block()->length()) return r;

src/cssize.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ namespace Sass {
3636
Statement* operator()(At_Root_Block*);
3737
Statement* operator()(Directive*);
3838
Statement* operator()(Keyframe_Rule*);
39+
Statement* operator()(Trace*);
3940
// Statement* operator()(Declaration*);
4041
// Statement* operator()(Assignment*);
4142
// Statement* operator()(Import*);

src/debugger.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ inline void debug_ast(AST_Node* node, std::string ind, Env* env)
6565
std::cerr << " (" << pstate_source_position(node) << ")";
6666
std::cerr << " " << bubble->tabs();
6767
std::cerr << std::endl;
68+
} else if (dynamic_cast<Trace*>(node)) {
69+
Trace* trace = dynamic_cast<Trace*>(node);
70+
std::cerr << ind << "Trace " << trace;
71+
std::cerr << " (" << pstate_source_position(node) << ")"
72+
<< " [name:" << trace->name() << "]"
73+
<< std::endl;
74+
debug_ast(trace->block(), ind + " ", env);
6875
} else if (dynamic_cast<At_Root_Block*>(node)) {
6976
At_Root_Block* root_block = dynamic_cast<At_Root_Block*>(node);
7077
std::cerr << ind << "At_Root_Block " << root_block;
@@ -426,14 +433,14 @@ inline void debug_ast(AST_Node* node, std::string ind, Env* env)
426433
std::cerr << " [native: " << block->native_function() << "] ";
427434
std::cerr << " " << block->tabs() << std::endl;
428435
debug_ast(block->parameters(), ind + " params: ", env);
429-
if (block->block()) for(auto i : block->block()->elements()) { debug_ast(i, ind + " ", env); }
436+
if (block->block()) debug_ast(block->block(), ind + " ", env);
430437
} else if (dynamic_cast<Mixin_Call*>(node)) {
431438
Mixin_Call* block = dynamic_cast<Mixin_Call*>(node);
432439
std::cerr << ind << "Mixin_Call " << block << " " << block->tabs();
433440
std::cerr << " [" << block->name() << "]";
434441
std::cerr << " [has_content: " << block->has_content() << "] " << std::endl;
435442
debug_ast(block->arguments(), ind + " args: ");
436-
if (block->block()) for(auto i : block->block()->elements()) { debug_ast(i, ind + " ", env); }
443+
if (block->block()) debug_ast(block->block(), ind + " ", env);
437444
} else if (Ruleset* ruleset = dynamic_cast<Ruleset*>(node)) {
438445
std::cerr << ind << "Ruleset " << ruleset;
439446
std::cerr << " (" << pstate_source_position(node) << ")";

src/operation.hpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ namespace Sass {
1515
virtual T operator()(Ruleset* x) = 0;
1616
virtual T operator()(Propset* x) = 0;
1717
virtual T operator()(Bubble* x) = 0;
18+
virtual T operator()(Trace* x) = 0;
1819
virtual T operator()(Supports_Block* x) = 0;
1920
virtual T operator()(Media_Block* x) = 0;
2021
virtual T operator()(At_Root_Block* x) = 0;
21-
virtual T operator()(Directive* x) = 0;
22+
virtual T operator()(Directive* x) = 0;
2223
virtual T operator()(Keyframe_Rule* x) = 0;
2324
virtual T operator()(Declaration* x) = 0;
2425
virtual T operator()(Assignment* x) = 0;
@@ -61,7 +62,7 @@ namespace Sass {
6162
virtual T operator()(Supports_Interpolation* x) = 0;
6263
virtual T operator()(Media_Query* x) = 0;
6364
virtual T operator()(Media_Query_Expression* x) = 0;
64-
virtual T operator()(At_Root_Query* x) = 0;
65+
virtual T operator()(At_Root_Query* x) = 0;
6566
virtual T operator()(Null* x) = 0;
6667
virtual T operator()(Parent_Selector* x) = 0;
6768
// parameters and arguments
@@ -96,10 +97,11 @@ namespace Sass {
9697
T operator()(Ruleset* x) { return static_cast<D*>(this)->fallback(x); }
9798
T operator()(Propset* x) { return static_cast<D*>(this)->fallback(x); }
9899
T operator()(Bubble* x) { return static_cast<D*>(this)->fallback(x); }
100+
T operator()(Trace* x) { return static_cast<D*>(this)->fallback(x); }
99101
T operator()(Supports_Block* x) { return static_cast<D*>(this)->fallback(x); }
100102
T operator()(Media_Block* x) { return static_cast<D*>(this)->fallback(x); }
101103
T operator()(At_Root_Block* x) { return static_cast<D*>(this)->fallback(x); }
102-
T operator()(Directive* x) { return static_cast<D*>(this)->fallback(x); }
104+
T operator()(Directive* x) { return static_cast<D*>(this)->fallback(x); }
103105
T operator()(Keyframe_Rule* x) { return static_cast<D*>(this)->fallback(x); }
104106
T operator()(Declaration* x) { return static_cast<D*>(this)->fallback(x); }
105107
T operator()(Assignment* x) { return static_cast<D*>(this)->fallback(x); }
@@ -142,7 +144,7 @@ namespace Sass {
142144
T operator()(Supports_Interpolation* x) { return static_cast<D*>(this)->fallback(x); }
143145
T operator()(Media_Query* x) { return static_cast<D*>(this)->fallback(x); }
144146
T operator()(Media_Query_Expression* x) { return static_cast<D*>(this)->fallback(x); }
145-
T operator()(At_Root_Query* x) { return static_cast<D*>(this)->fallback(x); }
147+
T operator()(At_Root_Query* x) { return static_cast<D*>(this)->fallback(x); }
146148
T operator()(Null* x) { return static_cast<D*>(this)->fallback(x); }
147149
T operator()(Parent_Selector* x) { return static_cast<D*>(this)->fallback(x); }
148150
// parameters and arguments
@@ -163,7 +165,7 @@ namespace Sass {
163165
T operator()(Selector_List* x) { return static_cast<D*>(this)->fallback(x); }
164166

165167
template <typename U>
166-
T fallback(U x) { return T(); }
168+
T fallback(U x) { return T(); }
167169
};
168170

169171
}

0 commit comments

Comments
 (0)