OLD | NEW |
(Empty) | |
| 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_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 /** |
| 19 * A function declaration or definition. The fBody field will be null for declar
ations. |
| 20 */ |
| 21 struct ASTFunction : public ASTDeclaration { |
| 22 ASTFunction(Position position, std::unique_ptr<ASTType> returnType, std::str
ing name, |
| 23 std::vector<std::unique_ptr<ASTParameter>> parameters, |
| 24 std::unique_ptr<ASTBlock> body) |
| 25 : INHERITED(position, kFunction_Kind) |
| 26 , fReturnType(std::move(returnType)) |
| 27 , fName(std::move(name)) |
| 28 , fParameters(std::move(parameters)) |
| 29 , fBody(std::move(body)) {} |
| 30 |
| 31 std::string description() const override { |
| 32 std::string result = fReturnType->description() + " " + fName + "("; |
| 33 for (size_t i = 0; i < fParameters.size(); i++) { |
| 34 if (i > 0) { |
| 35 result += ", "; |
| 36 } |
| 37 result += fParameters[i]->description(); |
| 38 } |
| 39 if (fBody) { |
| 40 result += ") " + fBody->description(); |
| 41 } else { |
| 42 result += ");"; |
| 43 } |
| 44 return result; |
| 45 } |
| 46 |
| 47 const std::unique_ptr<ASTType> fReturnType; |
| 48 const std::string fName; |
| 49 const std::vector<std::unique_ptr<ASTParameter>> fParameters; |
| 50 const std::unique_ptr<ASTBlock> fBody; |
| 51 |
| 52 typedef ASTDeclaration INHERITED; |
| 53 }; |
| 54 |
| 55 } // namespace |
| 56 |
| 57 #endif |
OLD | NEW |