SkSLFunctionDefinition.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. #ifndef SKSL_FUNCTIONDEFINITION
  8. #define SKSL_FUNCTIONDEFINITION
  9. #include "src/sksl/ir/SkSLBlock.h"
  10. #include "src/sksl/ir/SkSLFunctionDeclaration.h"
  11. #include "src/sksl/ir/SkSLProgramElement.h"
  12. namespace SkSL {
  13. /**
  14. * A function definition (a declaration plus an associated block of code).
  15. */
  16. struct FunctionDefinition : public ProgramElement {
  17. FunctionDefinition(int offset, const FunctionDeclaration& declaration,
  18. std::unique_ptr<Statement> body)
  19. : INHERITED(offset, kFunction_Kind)
  20. , fDeclaration(declaration)
  21. , fBody(std::move(body)) {}
  22. std::unique_ptr<ProgramElement> clone() const override {
  23. return std::unique_ptr<ProgramElement>(new FunctionDefinition(fOffset, fDeclaration,
  24. fBody->clone()));
  25. }
  26. String description() const override {
  27. return fDeclaration.description() + " " + fBody->description();
  28. }
  29. const FunctionDeclaration& fDeclaration;
  30. std::unique_ptr<Statement> fBody;
  31. typedef ProgramElement INHERITED;
  32. };
  33. } // namespace
  34. #endif