2 * Copyright 2016 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef SKSL_TYPEREFERENCE
9 #define SKSL_TYPEREFERENCE
11 #include "src/sksl/SkSLContext.h"
12 #include "src/sksl/ir/SkSLExpression.h"
17 * Represents an identifier referring to a type. This is an intermediate value: TypeReferences are
18 * always eventually replaced by Constructors in valid programs.
20 class TypeReference final : public Expression {
22 inline static constexpr Kind kExpressionKind = Kind::kTypeReference;
24 TypeReference(const Context& context, Position pos, const Type* value)
25 : TypeReference(pos, value, context.fTypes.fInvalid.get()) {}
27 // Creates a reference to an SkSL type; uses the ErrorReporter to report errors.
28 static std::unique_ptr<TypeReference> Convert(const Context& context,
32 // Creates a reference to an SkSL type; reports errors via ASSERT.
33 static std::unique_ptr<TypeReference> Make(const Context& context, Position pos,
36 const Type& value() const {
40 bool hasProperty(Property property) const override {
44 std::string description() const override {
45 return std::string(this->value().name());
48 std::unique_ptr<Expression> clone(Position pos) const override {
49 return std::unique_ptr<Expression>(new TypeReference(pos, &this->value(), &this->type()));
53 TypeReference(Position pos, const Type* value, const Type* type)
54 : INHERITED(pos, kExpressionKind, type)
59 using INHERITED = Expression;