Line data Source code
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 : */
7 :
8 : #ifndef SKSL_ASTINDEXSUFFIX
9 : #define SKSL_ASTINDEXSUFFIX
10 :
11 : #include "SkSLASTExpression.h"
12 : #include "SkSLASTSuffix.h"
13 :
14 : namespace SkSL {
15 :
16 : /**
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.
19 : */
20 0 : struct ASTIndexSuffix : public ASTSuffix {
21 0 : ASTIndexSuffix(Position position)
22 0 : : INHERITED(position, ASTSuffix::kIndex_Kind)
23 0 : , fExpression(nullptr) {}
24 :
25 0 : ASTIndexSuffix(std::unique_ptr<ASTExpression> expression)
26 0 : : INHERITED(expression ? expression->fPosition : Position(), ASTSuffix::kIndex_Kind)
27 0 : , fExpression(std::move(expression)) {}
28 :
29 0 : String description() const override {
30 0 : if (fExpression) {
31 0 : return "[" + fExpression->description() + "]";
32 : } else {
33 0 : return String("[]");
34 : }
35 : }
36 :
37 : // may be null
38 : std::unique_ptr<ASTExpression> fExpression;
39 :
40 : typedef ASTSuffix INHERITED;
41 : };
42 :
43 : } // namespace
44 :
45 : #endif
|