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_ASTFUNCTION |
| 9 | #define SKSL_ASTFUNCTION |
| 10 | |
| 11 | #include "SkSLASTBlock.h" |
| 12 | #include "SkSLASTDeclaration.h" |
| 13 | #include "SkSLASTParameter.h" |
| 14 | #include "SkSLASTType.h" |
| 15 | |
| 16 | namespace SkSL { |
| 17 | |
| 18 | /** |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 19 | * A function declaration or definition. The fBody field will be null for declarations. |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 20 | */ |
| 21 | struct ASTFunction : public ASTDeclaration { |
Ethan Nicholas | 5b5f096 | 2017-09-11 13:50:14 -0700 | [diff] [blame] | 22 | ASTFunction(int offset, Modifiers modifiers, std::unique_ptr<ASTType> returnType, |
| 23 | StringFragment name, std::vector<std::unique_ptr<ASTParameter>> parameters, |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 24 | std::unique_ptr<ASTBlock> body) |
Ethan Nicholas | 5b5f096 | 2017-09-11 13:50:14 -0700 | [diff] [blame] | 25 | : INHERITED(offset, kFunction_Kind) |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 26 | , fModifiers(modifiers) |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 27 | , fReturnType(std::move(returnType)) |
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 | , fParameters(std::move(parameters)) |
| 30 | , fBody(std::move(body)) {} |
| 31 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 32 | String description() const override { |
| 33 | String result = fReturnType->description() + " " + fName + "("; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 34 | for (size_t i = 0; i < fParameters.size(); i++) { |
| 35 | if (i > 0) { |
| 36 | result += ", "; |
| 37 | } |
| 38 | result += fParameters[i]->description(); |
| 39 | } |
| 40 | if (fBody) { |
| 41 | result += ") " + fBody->description(); |
| 42 | } else { |
| 43 | result += ");"; |
| 44 | } |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 45 | return result; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 46 | } |
| 47 | |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 48 | const Modifiers fModifiers; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 49 | const std::unique_ptr<ASTType> fReturnType; |
Ethan Nicholas | 5b5f096 | 2017-09-11 13:50:14 -0700 | [diff] [blame] | 50 | const StringFragment fName; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 51 | const std::vector<std::unique_ptr<ASTParameter>> fParameters; |
| 52 | const std::unique_ptr<ASTBlock> fBody; |
| 53 | |
| 54 | typedef ASTDeclaration INHERITED; |
| 55 | }; |
| 56 | |
| 57 | } // namespace |
| 58 | |
| 59 | #endif |