blob: 2b7cd484175c450d0ef799fee5144da547a826d5 [file] [log] [blame]
ethannicholasb3058bd2016-07-01 08:22:01 -07001/*
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
14namespace SkSL {
15
16/**
ethannicholas5961bc92016-10-12 06:39:56 -070017 * 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.
ethannicholasb3058bd2016-07-01 08:22:01 -070019 */
20struct ASTIndexSuffix : public ASTSuffix {
ethannicholas5961bc92016-10-12 06:39:56 -070021 ASTIndexSuffix(Position position)
22 : INHERITED(position, ASTSuffix::kIndex_Kind)
23 , fExpression(nullptr) {}
24
ethannicholasb3058bd2016-07-01 08:22:01 -070025 ASTIndexSuffix(std::unique_ptr<ASTExpression> expression)
ethannicholas5961bc92016-10-12 06:39:56 -070026 : INHERITED(expression ? expression->fPosition : Position(), ASTSuffix::kIndex_Kind)
ethannicholasb3058bd2016-07-01 08:22:01 -070027 , fExpression(std::move(expression)) {}
28
Ethan Nicholas9e1138d2016-11-21 10:39:35 -050029 SkString description() const override {
ethannicholas5961bc92016-10-12 06:39:56 -070030 if (fExpression) {
31 return "[" + fExpression->description() + "]";
32 } else {
Ethan Nicholas9e1138d2016-11-21 10:39:35 -050033 return SkString("[]");
ethannicholas5961bc92016-10-12 06:39:56 -070034 }
ethannicholasb3058bd2016-07-01 08:22:01 -070035 }
36
ethannicholas5961bc92016-10-12 06:39:56 -070037 // may be null
ethannicholasb3058bd2016-07-01 08:22:01 -070038 std::unique_ptr<ASTExpression> fExpression;
39
40 typedef ASTSuffix INHERITED;
41};
42
43} // namespace
44
45#endif