| 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_FUNCTIONDEFINITION |
| 9 | #define SKSL_FUNCTIONDEFINITION |
| 10 | |
| 11 | #include "src/sksl/ir/SkSLBlock.h" |
| 12 | #include "src/sksl/ir/SkSLFunctionDeclaration.h" |
| 13 | #include "src/sksl/ir/SkSLProgramElement.h" |
| 14 | |
| 15 | namespace SkSL { |
| 16 | |
| 17 | struct ASTNode; |
| 18 | |
| 19 | /** |
| 20 | * A function definition (a declaration plus an associated block of code). |
| 21 | */ |
| 22 | struct FunctionDefinition : public ProgramElement { |
| 23 | FunctionDefinition(int offset, const FunctionDeclaration& declaration, |
| 24 | std::unique_ptr<Statement> body) |
| 25 | : INHERITED(offset, kFunction_Kind) |
| 26 | , fDeclaration(declaration) |
| 27 | , fBody(std::move(body)) {} |
| 28 | |
| 29 | std::unique_ptr<ProgramElement> clone() const override { |
| 30 | return std::unique_ptr<ProgramElement>(new FunctionDefinition(fOffset, fDeclaration, |
| 31 | fBody->clone())); |
| 32 | } |
| 33 | |
| 34 | #ifdef SK_DEBUG |
| 35 | String description() const override { |
| 36 | return fDeclaration.description() + " "+ fBody->description(); |
| 37 | } |
| 38 | #endif |
| 39 | |
| 40 | const FunctionDeclaration& fDeclaration; |
| 41 | std::unique_ptr<Statement> fBody; |
| 42 | // This pointer may be null, and even when non-null is not guaranteed to remain valid for the |
| 43 | // entire lifespan of this object. The parse tree's lifespan is normally controlled by |
| 44 | // IRGenerator, so the IRGenerator being destroyed or being used to compile another file will |
| 45 | // invalidate this pointer. |
| 46 | const ASTNode* fSource = nullptr; |
| 47 | |
| 48 | typedef ProgramElement INHERITED; |
| 49 | }; |
| 50 | |
| 51 | } // namespace |
| 52 | |
| 53 | #endif |
| 54 |