Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkSLVariableReference.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_VARIABLEREFERENCE
9#define SKSL_VARIABLEREFERENCE
10
15
16#include <cstdint>
17#include <memory>
18#include <string>
19
20namespace SkSL {
21
22class Variable;
23enum class OperatorPrecedence : uint8_t;
24
25enum class VariableRefKind : int8_t {
26 kRead,
27 kWrite,
29 // taking the address of a variable - we consider this a read & write but don't complain if
30 // the variable was not previously assigned
32};
33
34/**
35 * A reference to a variable, through which it can be read or written. In the statement:
36 *
37 * x = x + 1;
38 *
39 * there is only one Variable 'x', but two VariableReferences to it.
40 */
41class VariableReference final : public Expression {
42public:
44
45 inline static constexpr Kind kIRNodeKind = Kind::kVariableReference;
46
48
49 // Creates a VariableReference. There isn't much in the way of error-checking or optimization
50 // opportunities here.
51 static std::unique_ptr<Expression> Make(Position pos,
52 const Variable* variable,
53 RefKind refKind = RefKind::kRead) {
55 return std::make_unique<VariableReference>(pos, variable, refKind);
56 }
57
60
61 const Variable* variable() const {
62 return fVariable;
63 }
64
65 RefKind refKind() const {
66 return fRefKind;
67 }
68
70 void setVariable(const Variable* variable);
71
72 std::unique_ptr<Expression> clone(Position pos) const override {
73 return std::make_unique<VariableReference>(pos, this->variable(), this->refKind());
74 }
75
76 std::string description(OperatorPrecedence) const override;
77
78private:
79 const Variable* fVariable;
80 VariableRefKind fRefKind;
81
82 using INHERITED = Expression;
83};
84
85} // namespace SkSL
86
87#endif
SkPoint pos
#define SkASSERT(cond)
Definition SkAssert.h:116
std::string description() const final
VariableReference & operator=(const VariableReference &)=delete
const Variable * variable() const
std::unique_ptr< Expression > clone(Position pos) const override
void setRefKind(RefKind refKind)
static std::unique_ptr< Expression > Make(Position pos, const Variable *variable, RefKind refKind=RefKind::kRead)
VariableReference(const VariableReference &)=delete
static constexpr Kind kIRNodeKind
void setVariable(const Variable *variable)
OperatorPrecedence
ExpressionKind
Definition SkSLIRNode.h:62