@@ -17,55 +17,88 @@ namespace SkSL {
17
17
/* *
18
18
* A 'for' statement.
19
19
*/
20
- struct ForStatement : public Statement {
20
+ class ForStatement : public Statement {
21
+ public:
21
22
static constexpr Kind kStatementKind = Kind::kFor ;
22
23
23
24
ForStatement (int offset, std::unique_ptr<Statement> initializer,
24
25
std::unique_ptr<Expression> test, std::unique_ptr<Expression> next,
25
26
std::unique_ptr<Statement> statement, std::shared_ptr<SymbolTable> symbols)
26
- : INHERITED(offset, kStatementKind )
27
- , fSymbols (symbols)
28
- , fInitializer (std::move(initializer))
29
- , fTest (std::move(test))
30
- , fNext (std::move(next))
31
- , fStatement (std::move(statement)) {}
27
+ : INHERITED(offset, kStatementKind , ForStatementData{std::move (symbols)}) {
28
+ fStatementChildren .reserve (2 );
29
+ fStatementChildren .push_back (std::move (initializer));
30
+ fStatementChildren .push_back (std::move (statement));
31
+ fExpressionChildren .reserve (2 );
32
+ fExpressionChildren .push_back (std::move (test));
33
+ fExpressionChildren .push_back (std::move (next));
34
+ }
35
+
36
+ std::unique_ptr<Statement>& initializer () {
37
+ return fStatementChildren [0 ];
38
+ }
39
+
40
+ const std::unique_ptr<Statement>& initializer () const {
41
+ return fStatementChildren [0 ];
42
+ }
43
+
44
+ std::unique_ptr<Expression>& test () {
45
+ return fExpressionChildren [0 ];
46
+ }
47
+
48
+ const std::unique_ptr<Expression>& test () const {
49
+ return fExpressionChildren [0 ];
50
+ }
51
+
52
+ std::unique_ptr<Expression>& next () {
53
+ return fExpressionChildren [1 ];
54
+ }
55
+
56
+ const std::unique_ptr<Expression>& next () const {
57
+ return fExpressionChildren [1 ];
58
+ }
59
+
60
+ std::unique_ptr<Statement>& statement () {
61
+ return fStatementChildren [1 ];
62
+ }
63
+
64
+ const std::unique_ptr<Statement>& statement () const {
65
+ return fStatementChildren [1 ];
66
+ }
67
+
68
+ std::shared_ptr<SymbolTable> symbols () const {
69
+ return this ->forStatementData ().fSymbolTable ;
70
+ }
32
71
33
72
std::unique_ptr<Statement> clone () const override {
34
- return std::unique_ptr<Statement>(new ForStatement (fOffset ,
35
- fInitializer ? fInitializer ->clone () : nullptr ,
36
- fTest ? fTest ->clone () : nullptr ,
37
- fNext ? fNext ->clone () : nullptr ,
38
- fStatement ->clone (),
39
- fSymbols ));
73
+ return std::unique_ptr<Statement>(new ForStatement (
74
+ fOffset ,
75
+ this ->initializer () ? this ->initializer ()->clone () : nullptr ,
76
+ this ->test () ? this ->test ()->clone () : nullptr ,
77
+ this ->next () ? this ->next ()->clone () : nullptr ,
78
+ this ->statement ()->clone (),
79
+ this ->symbols ()));
40
80
}
41
81
42
82
String description () const override {
43
83
String result (" for (" );
44
- if (fInitializer ) {
45
- result += fInitializer ->description ();
84
+ if (this -> initializer () ) {
85
+ result += this -> initializer () ->description ();
46
86
} else {
47
87
result += " ;" ;
48
88
}
49
89
result += " " ;
50
- if (fTest ) {
51
- result += fTest ->description ();
90
+ if (this -> test () ) {
91
+ result += this -> test () ->description ();
52
92
}
53
93
result += " ; " ;
54
- if (fNext ) {
55
- result += fNext ->description ();
94
+ if (this -> next () ) {
95
+ result += this -> next () ->description ();
56
96
}
57
- result += " ) " + fStatement ->description ();
97
+ result += " ) " + this -> statement () ->description ();
58
98
return result;
59
99
}
60
100
61
- // it's important to keep fSymbols defined first (and thus destroyed last) because destroying
62
- // the other fields can update symbol reference counts
63
- const std::shared_ptr<SymbolTable> fSymbols ;
64
- std::unique_ptr<Statement> fInitializer ;
65
- std::unique_ptr<Expression> fTest ;
66
- std::unique_ptr<Expression> fNext ;
67
- std::unique_ptr<Statement> fStatement ;
68
-
101
+ private:
69
102
using INHERITED = Statement;
70
103
};
71
104
0 commit comments