Flutter Engine
The Flutter Engine
SkSLPrefixExpression.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_PREFIXEXPRESSION
9#define SKSL_PREFIXEXPRESSION
10
15
16#include <memory>
17#include <string>
18#include <utility>
19
20namespace SkSL {
21
22class Context;
23
24/**
25 * An expression modified by a unary operator appearing before it, such as '!flag'.
26 */
27class PrefixExpression final : public Expression {
28public:
29 inline static constexpr Kind kIRNodeKind = Kind::kPrefix;
30
31 // Use PrefixExpression::Make to automatically simplify various prefix expression types.
32 PrefixExpression(Position pos, Operator op, std::unique_ptr<Expression> operand)
34 , fOperator(op)
35 , fOperand(std::move(operand)) {}
36
37 // Creates an SkSL prefix expression; uses the ErrorReporter to report errors.
38 static std::unique_ptr<Expression> Convert(const Context& context, Position pos, Operator op,
39 std::unique_ptr<Expression> base);
40
41 // Creates an SkSL prefix expression; reports errors via ASSERT.
42 static std::unique_ptr<Expression> Make(const Context& context, Position pos, Operator op,
43 std::unique_ptr<Expression> base);
44
46 return fOperator;
47 }
48
49 std::unique_ptr<Expression>& operand() {
50 return fOperand;
51 }
52
53 const std::unique_ptr<Expression>& operand() const {
54 return fOperand;
55 }
56
57 std::unique_ptr<Expression> clone(Position pos) const override {
58 return std::make_unique<PrefixExpression>(pos, this->getOperator(),
59 this->operand()->clone());
60 }
61
62 std::string description(OperatorPrecedence parentPrecedence) const override;
63
64private:
65 Operator fOperator;
66 std::unique_ptr<Expression> fOperand;
67
68 using INHERITED = Expression;
69};
70
71} // namespace SkSL
72
73#endif
SkPoint pos
std::unique_ptr< Expression > clone() const
Expression(Position pos, Kind kind, const Type *type)
const Type & type() const
std::string description() const final
PrefixExpression(Position pos, Operator op, std::unique_ptr< Expression > operand)
static std::unique_ptr< Expression > Make(const Context &context, Position pos, Operator op, std::unique_ptr< Expression > base)
Operator getOperator() const
static std::unique_ptr< Expression > Convert(const Context &context, Position pos, Operator op, std::unique_ptr< Expression > base)
const std::unique_ptr< Expression > & operand() const
std::unique_ptr< Expression > clone(Position pos) const override
std::unique_ptr< Expression > & operand()
static constexpr Kind kIRNodeKind
OperatorPrecedence
Definition: SkSLOperator.h:57
ExpressionKind
Definition: SkSLIRNode.h:62
Definition: ref_ptr.h:256