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. | 17 * A bracketed expression, as in '[0]', indicating an array access. Empty bracke
ts (as occur in |
| 18 * 'float[](5, 6)' are represented with a null fExpression. |
18 */ | 19 */ |
19 struct ASTIndexSuffix : public ASTSuffix { | 20 struct ASTIndexSuffix : public ASTSuffix { |
| 21 ASTIndexSuffix(Position position) |
| 22 : INHERITED(position, ASTSuffix::kIndex_Kind) |
| 23 , fExpression(nullptr) {} |
| 24 |
20 ASTIndexSuffix(std::unique_ptr<ASTExpression> expression) | 25 ASTIndexSuffix(std::unique_ptr<ASTExpression> expression) |
21 : INHERITED(expression->fPosition, ASTSuffix::kIndex_Kind) | 26 : INHERITED(expression ? expression->fPosition : Position(), ASTSuffix::kInd
ex_Kind) |
22 , fExpression(std::move(expression)) {} | 27 , fExpression(std::move(expression)) {} |
23 | 28 |
24 std::string description() const override { | 29 std::string description() const override { |
25 return "[" + fExpression->description() + "]"; | 30 if (fExpression) { |
| 31 return "[" + fExpression->description() + "]"; |
| 32 } else { |
| 33 return "[]"; |
| 34 } |
26 } | 35 } |
27 | 36 |
| 37 // may be null |
28 std::unique_ptr<ASTExpression> fExpression; | 38 std::unique_ptr<ASTExpression> fExpression; |
29 | 39 |
30 typedef ASTSuffix INHERITED; | 40 typedef ASTSuffix INHERITED; |
31 }; | 41 }; |
32 | 42 |
33 } // namespace | 43 } // namespace |
34 | 44 |
35 #endif | 45 #endif |
OLD | NEW |