• 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_TYPEREFERENCE
9 #define SKSL_TYPEREFERENCE
10 
11 #include "src/sksl/SkSLContext.h"
12 #include "src/sksl/ir/SkSLExpression.h"
13 
14 namespace SkSL {
15 
16 /**
17  * Represents an identifier referring to a type. This is an intermediate value: TypeReferences are
18  * always eventually replaced by Constructors in valid programs.
19  */
20 class TypeReference final : public Expression {
21 public:
22     inline static constexpr Kind kExpressionKind = Kind::kTypeReference;
23 
TypeReference(const Context & context,int line,const Type * value)24     TypeReference(const Context& context, int line, const Type* value)
25         : TypeReference(line, value, context.fTypes.fInvalid.get()) {}
26 
27     // Creates a reference to an SkSL type; uses the ErrorReporter to report errors.
28     static std::unique_ptr<TypeReference> Convert(const Context& context,
29                                                   int line,
30                                                   const Type* type);
31 
32     // Creates a reference to an SkSL type; reports errors via ASSERT.
33     static std::unique_ptr<TypeReference> Make(const Context& context, int line, const Type* type);
34 
value()35     const Type& value() const {
36         return fValue;
37     }
38 
hasProperty(Property property)39     bool hasProperty(Property property) const override {
40         return false;
41     }
42 
description()43     std::string description() const override {
44         return std::string(this->value().name());
45     }
46 
clone()47     std::unique_ptr<Expression> clone() const override {
48         return std::unique_ptr<Expression>(new TypeReference(fLine, &this->value(), &this->type()));
49     }
50 
51 private:
TypeReference(int line,const Type * value,const Type * type)52     TypeReference(int line, const Type* value, const Type* type)
53         : INHERITED(line, kExpressionKind, type)
54         , fValue(*value) {}
55 
56     const Type& fValue;
57 
58     using INHERITED = Expression;
59 };
60 
61 }  // namespace SkSL
62 
63 #endif
64