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 static constexpr Kind kExpressionKind = Kind::kTypeReference; 23 TypeReference(const Context & context,int offset,const Type * value)24 TypeReference(const Context& context, int offset, const Type* value) 25 : INHERITED(offset, kExpressionKind, context.fInvalid_Type.get()) 26 , fValue(*value) {} 27 value()28 const Type& value() const { 29 return fValue; 30 } 31 hasProperty(Property property)32 bool hasProperty(Property property) const override { 33 return false; 34 } 35 description()36 String description() const override { 37 return String(this->value().name()); 38 } 39 clone()40 std::unique_ptr<Expression> clone() const override { 41 return std::unique_ptr<Expression>(new TypeReference(fOffset, &this->value(), 42 &this->type())); 43 } 44 45 private: TypeReference(int offset,const Type * value,const Type * type)46 TypeReference(int offset, const Type* value, const Type* type) 47 : INHERITED(offset, kExpressionKind, type) 48 , fValue(*value) {} 49 50 const Type& fValue; 51 52 using INHERITED = Expression; 53 }; 54 55 } // namespace SkSL 56 57 #endif 58