• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
8 #include "src/sksl/ir/SkSLPostfixExpression.h"
9 
10 #include "include/sksl/SkSLErrorReporter.h"
11 #include "src/sksl/SkSLAnalysis.h"
12 #include "src/sksl/SkSLContext.h"
13 #include "src/sksl/ir/SkSLVariableReference.h"
14 
15 namespace SkSL {
16 
Convert(const Context & context,std::unique_ptr<Expression> base,Operator op)17 std::unique_ptr<Expression> PostfixExpression::Convert(const Context& context,
18                                                        std::unique_ptr<Expression> base,
19                                                        Operator op) {
20     const Type& baseType = base->type();
21     if (!baseType.isNumber()) {
22         context.fErrors->error(base->fLine, "'" + std::string(op.tightOperatorName()) +
23                                             "' cannot operate on '" + baseType.displayName() + "'");
24         return nullptr;
25     }
26     if (!Analysis::UpdateVariableRefKind(base.get(), VariableRefKind::kReadWrite,
27                                          context.fErrors)) {
28         return nullptr;
29     }
30     return PostfixExpression::Make(context, std::move(base), op);
31 }
32 
Make(const Context &,std::unique_ptr<Expression> base,Operator op)33 std::unique_ptr<Expression> PostfixExpression::Make(const Context&,
34                                                     std::unique_ptr<Expression> base,
35                                                     Operator op) {
36     SkASSERT(base->type().isNumber());
37     SkASSERT(Analysis::IsAssignable(*base));
38     return std::make_unique<PostfixExpression>(std::move(base), op);
39 }
40 
41 }  // namespace SkSL
42