• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_FUNCTIONREFERENCE
9 #define SKSL_FUNCTIONREFERENCE
10 
11 #include "src/sksl/SkSLContext.h"
12 #include "src/sksl/ir/SkSLExpression.h"
13 #include "src/sksl/ir/SkSLFunctionDeclaration.h"
14 
15 namespace SkSL {
16 
17 /**
18  * An identifier referring to a function name. This is an intermediate value: FunctionReferences are
19  * always eventually replaced by FunctionCalls in valid programs.
20  */
21 class FunctionReference final : public Expression {
22 public:
23     inline static constexpr Kind kExpressionKind = Kind::kFunctionReference;
24 
FunctionReference(const Context & context,int line,std::vector<const FunctionDeclaration * > functions)25     FunctionReference(const Context& context, int line,
26                       std::vector<const FunctionDeclaration*> functions)
27         : INHERITED(line, kExpressionKind, context.fTypes.fInvalid.get())
28         , fFunctions(std::move(functions)) {}
29 
functions()30     const std::vector<const FunctionDeclaration*>& functions() const {
31         return fFunctions;
32     }
33 
hasProperty(Property property)34     bool hasProperty(Property property) const override {
35         return false;
36     }
37 
clone()38     std::unique_ptr<Expression> clone() const override {
39         return std::unique_ptr<Expression>(new FunctionReference(fLine, this->functions(),
40                                                                  &this->type()));
41     }
42 
description()43     String description() const override {
44         return String("<function>");
45     }
46 
47 private:
FunctionReference(int line,std::vector<const FunctionDeclaration * > functions,const Type * type)48     FunctionReference(int line, std::vector<const FunctionDeclaration*> functions,
49                       const Type* type)
50         : INHERITED(line, kExpressionKind, type)
51         , fFunctions(std::move(functions)) {}
52 
53     std::vector<const FunctionDeclaration*> fFunctions;
54 
55     using INHERITED = Expression;
56 };
57 
58 }  // namespace SkSL
59 
60 #endif
61