OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SKSL_ASTINDEXSUFFIX | 8 #ifndef SKSL_ASTINDEXSUFFIX |
9 #define SKSL_ASTINDEXSUFFIX | 9 #define SKSL_ASTINDEXSUFFIX |
10 | 10 |
11 #include "SkSLASTExpression.h" | 11 #include "SkSLASTExpression.h" |
12 #include "SkSLASTSuffix.h" | 12 #include "SkSLASTSuffix.h" |
13 | 13 |
14 namespace SkSL { | 14 namespace SkSL { |
15 | 15 |
16 /** | 16 /** |
17 * A bracketed expression, as in '[0]', indicating an array access. Empty bracke
ts (as occur in | 17 * A bracketed expression, as in '[0]', indicating an array access. |
18 * 'float[](5, 6)' are represented with a null fExpression. | |
19 */ | 18 */ |
20 struct ASTIndexSuffix : public ASTSuffix { | 19 struct ASTIndexSuffix : public ASTSuffix { |
21 ASTIndexSuffix(Position position) | |
22 : INHERITED(position, ASTSuffix::kIndex_Kind) | |
23 , fExpression(nullptr) {} | |
24 | |
25 ASTIndexSuffix(std::unique_ptr<ASTExpression> expression) | 20 ASTIndexSuffix(std::unique_ptr<ASTExpression> expression) |
26 : INHERITED(expression ? expression->fPosition : Position(), ASTSuffix::kInd
ex_Kind) | 21 : INHERITED(expression->fPosition, ASTSuffix::kIndex_Kind) |
27 , fExpression(std::move(expression)) {} | 22 , fExpression(std::move(expression)) {} |
28 | 23 |
29 std::string description() const override { | 24 std::string description() const override { |
30 if (fExpression) { | 25 return "[" + fExpression->description() + "]"; |
31 return "[" + fExpression->description() + "]"; | |
32 } else { | |
33 return "[]"; | |
34 } | |
35 } | 26 } |
36 | 27 |
37 // may be null | |
38 std::unique_ptr<ASTExpression> fExpression; | 28 std::unique_ptr<ASTExpression> fExpression; |
39 | 29 |
40 typedef ASTSuffix INHERITED; | 30 typedef ASTSuffix INHERITED; |
41 }; | 31 }; |
42 | 32 |
43 } // namespace | 33 } // namespace |
44 | 34 |
45 #endif | 35 #endif |
OLD | NEW |