Flutter Engine
The Flutter Engine
SkSLTypeReference.h
Go to the documentation of this file.
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
17
18#include <cstdint>
19#include <memory>
20#include <string>
21
22namespace SkSL {
23
24enum class OperatorPrecedence : uint8_t;
25
26/**
27 * Represents an identifier referring to a type. This is an intermediate value: TypeReferences are
28 * always eventually replaced by Constructors in valid programs.
29 */
30class TypeReference final : public Expression {
31public:
32 inline static constexpr Kind kIRNodeKind = Kind::kTypeReference;
33
34 TypeReference(const Context& context, Position pos, const Type* value)
35 : TypeReference(pos, value, context.fTypes.fInvalid.get()) {}
36
37 // Reports an error and returns false if the type is generic or, in a strict-ES2 program, if the
38 // type is not allowed in ES2. Otherwise, returns true. (These are the same checks performed by
39 // Convert.)
40 static bool VerifyType(const Context& context, const SkSL::Type* type, Position pos);
41
42 // Creates a reference to an SkSL type; uses the ErrorReporter to report errors.
43 static std::unique_ptr<TypeReference> Convert(const Context& context,
45 const Type* type);
46
47 // Creates a reference to an SkSL type; reports errors via ASSERT.
48 static std::unique_ptr<TypeReference> Make(const Context& context, Position pos,
49 const Type* type);
50
51 const Type& value() const {
52 return fValue;
53 }
54
55 std::string description(OperatorPrecedence) const override {
56 return std::string(this->value().name());
57 }
58
59 std::unique_ptr<Expression> clone(Position pos) const override {
60 return std::unique_ptr<Expression>(new TypeReference(pos, &this->value(), &this->type()));
61 }
62
63private:
65 : INHERITED(pos, kIRNodeKind, type)
66 , fValue(*value) {}
67
68 const Type& fValue;
69
70 using INHERITED = Expression;
71};
72
73} // namespace SkSL
74
75#endif
SkPoint pos
Expression(Position pos, Kind kind, const Type *type)
const Type & type() const
std::unique_ptr< Expression > clone(Position pos) const override
std::string description(OperatorPrecedence) const override
static constexpr Kind kIRNodeKind
TypeReference(const Context &context, Position pos, const Type *value)
static bool VerifyType(const Context &context, const SkSL::Type *type, Position pos)
const Type & value() const
static std::unique_ptr< TypeReference > Convert(const Context &context, Position pos, const Type *type)
static std::unique_ptr< TypeReference > Make(const Context &context, Position pos, const Type *type)
OperatorPrecedence
Definition: SkSLOperator.h:57
ExpressionKind
Definition: SkSLIRNode.h:62
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
const myers::Point & get(const myers::Segment &)