Flutter Engine
The Flutter Engine
SkSLPostfixExpression.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2021 Google LLC
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
9
17
18namespace SkSL {
19
20std::unique_ptr<Expression> PostfixExpression::Convert(const Context& context,
22 std::unique_ptr<Expression> base,
23 Operator op) {
24 if (base->type().isArray() || !base->type().componentType().isNumber()) {
25 context.fErrors->error(pos, "'" + std::string(op.tightOperatorName()) +
26 "' cannot operate on '" + base->type().displayName() + "'");
27 return nullptr;
28 }
30 context.fErrors)) {
31 return nullptr;
32 }
33 return PostfixExpression::Make(context, pos, std::move(base), op);
34}
35
36std::unique_ptr<Expression> PostfixExpression::Make(const Context& context,
38 std::unique_ptr<Expression> base,
39 Operator op) {
40 SkASSERT(!base->type().isArray() && base->type().componentType().isNumber());
42 return std::make_unique<PostfixExpression>(pos, std::move(base), op);
43}
44
45std::string PostfixExpression::description(OperatorPrecedence parentPrecedence) const {
46 bool needsParens = (OperatorPrecedence::kPostfix >= parentPrecedence);
47 return std::string(needsParens ? "(" : "") +
48 this->operand()->description(OperatorPrecedence::kPostfix) +
49 std::string(this->getOperator().tightOperatorName()) +
50 std::string(needsParens ? ")" : "");
51}
52
53} // namespace SkSL
SkPoint pos
#define SkASSERT(cond)
Definition: SkAssert.h:116
ErrorReporter * fErrors
Definition: SkSLContext.h:36
void error(Position position, std::string_view msg)
std::string description() const final
std::string_view tightOperatorName() const
static std::unique_ptr< Expression > Make(const Context &context, Position pos, std::unique_ptr< Expression > base, Operator op)
static std::unique_ptr< Expression > Convert(const Context &context, Position pos, std::unique_ptr< Expression > base, Operator op)
std::unique_ptr< Expression > & operand()
bool UpdateVariableRefKind(Expression *expr, VariableRefKind kind, ErrorReporter *errors=nullptr)
bool IsAssignable(Expression &expr, AssignmentInfo *info=nullptr, ErrorReporter *errors=nullptr)
OperatorPrecedence
Definition: SkSLOperator.h:57