Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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 const Type& baseType = base->type();
25 if (!baseType.isNumber()) {
26 context.fErrors->error(pos, "'" + std::string(op.tightOperatorName()) +
27 "' cannot operate on '" + baseType.displayName() + "'");
28 return nullptr;
29 }
31 context.fErrors)) {
32 return nullptr;
33 }
34 return PostfixExpression::Make(context, pos, std::move(base), op);
35}
36
37std::unique_ptr<Expression> PostfixExpression::Make(const Context& context,
39 std::unique_ptr<Expression> base,
40 Operator op) {
41 SkASSERT(base->type().isNumber());
43 return std::make_unique<PostfixExpression>(pos, std::move(base), op);
44}
45
46std::string PostfixExpression::description(OperatorPrecedence parentPrecedence) const {
47 bool needsParens = (OperatorPrecedence::kPostfix >= parentPrecedence);
48 return std::string(needsParens ? "(" : "") +
49 this->operand()->description(OperatorPrecedence::kPostfix) +
50 std::string(this->getOperator().tightOperatorName()) +
51 std::string(needsParens ? ")" : "");
52}
53
54} // 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 isNumber() const
Definition SkSLType.h:304
std::string displayName() const
Definition SkSLType.h:234
bool UpdateVariableRefKind(Expression *expr, VariableRefKind kind, ErrorReporter *errors=nullptr)
bool IsAssignable(Expression &expr, AssignmentInfo *info=nullptr, ErrorReporter *errors=nullptr)
OperatorPrecedence