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 | 11d5397 | 2016-11-28 11:23:23 -0500 | [diff] [blame] | 7 | |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 8 | #ifndef SKSL_ASTPARAMETER |
| 9 | #define SKSL_ASTPARAMETER |
| 10 | |
Hal Canary | 6b20a55 | 2017-02-07 14:09:38 -0500 | [diff] [blame] | 11 | #include "SkSLASTPositionNode.h" |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 12 | #include "SkSLASTType.h" |
Ethan Nicholas | 11d5397 | 2016-11-28 11:23:23 -0500 | [diff] [blame] | 13 | #include "../ir/SkSLModifiers.h" |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 14 | |
| 15 | namespace SkSL { |
| 16 | |
| 17 | /** |
| 18 | * A declaration of a parameter, as part of a function declaration. |
| 19 | */ |
| 20 | struct ASTParameter : public ASTPositionNode { |
Ethan Nicholas | 11d5397 | 2016-11-28 11:23:23 -0500 | [diff] [blame] | 21 | // 'sizes' is a list of the array sizes appearing on a parameter, in source order. |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 22 | // e.g. int x[3][1] would have sizes [3, 1]. |
Ethan Nicholas | 5b5f096 | 2017-09-11 13:50:14 -0700 | [diff] [blame] | 23 | ASTParameter(int offset, Modifiers modifiers, std::unique_ptr<ASTType> type, |
| 24 | StringFragment name, std::vector<int> sizes) |
| 25 | : INHERITED(offset) |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 26 | , fModifiers(modifiers) |
| 27 | , fType(std::move(type)) |
Ethan Nicholas | 5b5f096 | 2017-09-11 13:50:14 -0700 | [diff] [blame] | 28 | , fName(name) |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 29 | , fSizes(std::move(sizes)) {} |
| 30 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 31 | String description() const override { |
| 32 | String result = fModifiers.description() + fType->description() + " " + fName; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 33 | for (int size : fSizes) { |
| 34 | result += "[" + to_string(size) + "]"; |
| 35 | } |
| 36 | return result; |
| 37 | } |
| 38 | |
Ethan Nicholas | 11d5397 | 2016-11-28 11:23:23 -0500 | [diff] [blame] | 39 | const Modifiers fModifiers; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 40 | const std::unique_ptr<ASTType> fType; |
Ethan Nicholas | 5b5f096 | 2017-09-11 13:50:14 -0700 | [diff] [blame] | 41 | const StringFragment fName; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 42 | const std::vector<int> fSizes; |
| 43 | |
| 44 | typedef ASTPositionNode INHERITED; |
| 45 | }; |
| 46 | |
| 47 | } // namespace |
| 48 | |
| 49 | #endif |