ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 7 | |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 8 | #ifndef SKSL_ASTINDEXSUFFIX |
| 9 | #define SKSL_ASTINDEXSUFFIX |
| 10 | |
| 11 | #include "SkSLASTExpression.h" |
| 12 | #include "SkSLASTSuffix.h" |
| 13 | |
| 14 | namespace SkSL { |
| 15 | |
| 16 | /** |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 17 | * A bracketed expression, as in '[0]', indicating an array access. Empty brackets (as occur in |
| 18 | * 'float[](5, 6)' are represented with a null fExpression. |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 19 | */ |
| 20 | struct ASTIndexSuffix : public ASTSuffix { |
Ethan Nicholas | 5b5f096 | 2017-09-11 13:50:14 -0700 | [diff] [blame] | 21 | ASTIndexSuffix(int offset) |
| 22 | : INHERITED(offset, ASTSuffix::kIndex_Kind) |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 23 | , fExpression(nullptr) {} |
| 24 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 25 | ASTIndexSuffix(std::unique_ptr<ASTExpression> expression) |
Ethan Nicholas | 5b5f096 | 2017-09-11 13:50:14 -0700 | [diff] [blame] | 26 | : INHERITED(expression ? expression->fOffset : -1, ASTSuffix::kIndex_Kind) |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 27 | , fExpression(std::move(expression)) {} |
| 28 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 29 | String description() const override { |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 30 | if (fExpression) { |
| 31 | return "[" + fExpression->description() + "]"; |
| 32 | } else { |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 33 | return String("[]"); |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 34 | } |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 35 | } |
| 36 | |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 37 | // may be null |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 38 | std::unique_ptr<ASTExpression> fExpression; |
| 39 | |
| 40 | typedef ASTSuffix INHERITED; |
| 41 | }; |
| 42 | |
| 43 | } // namespace |
| 44 | |
| 45 | #endif |