• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2020 Google LLC
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_INLINEMARKER
9 #define SKSL_INLINEMARKER
10 
11 #include "include/private/SkSLStatement.h"
12 #include "src/sksl/ir/SkSLFunctionDeclaration.h"
13 #include "src/sksl/ir/SkSLSymbolTable.h"
14 
15 namespace SkSL {
16 
17 /**
18  * A no-op statement that indicates that a function was inlined here. This is necessary to detect
19  * and prevent runaway infinite recursion. This node doesn't directly generate code.
20  */
21 class InlineMarker final : public Statement {
22 public:
23     inline static constexpr Kind kStatementKind = Kind::kInlineMarker;
24 
InlineMarker(const FunctionDeclaration * function)25     InlineMarker(const FunctionDeclaration* function)
26             : INHERITED(/*line=*/-1, kStatementKind)
27             , fFunction(*function) {}
28 
Make(const FunctionDeclaration * function)29     static std::unique_ptr<Statement> Make(const FunctionDeclaration* function) {
30         return std::make_unique<InlineMarker>(function);
31     }
32 
function()33     const FunctionDeclaration& function() const {
34         return fFunction;
35     }
36 
isEmpty()37     bool isEmpty() const override {
38         return true;
39     }
40 
description()41     String description() const override {
42         return String("/* inlined: ") + this->function().name() + String(" */");
43     }
44 
clone()45     std::unique_ptr<Statement> clone() const override {
46         return std::make_unique<InlineMarker>(&this->function());
47     }
48 
49 private:
50     const FunctionDeclaration& fFunction;
51 
52     using INHERITED = Statement;
53 };
54 
55 }  // namespace SkSL
56 
57 #endif
58