Convert IRGenerator::convertPostfixExpr to PostfixExpr::Make.

We have no optimizations on postfix-expressions at all so this is a very
straightforward cut-and-paste.

Change-Id: I73b3bc73ad833e668306301e6d6859e44230393a
Bug: skia:11342
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/376846
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
diff --git a/gn/sksl.gni b/gn/sksl.gni
index 99b3743..72fcd7c 100644
--- a/gn/sksl.gni
+++ b/gn/sksl.gni
@@ -120,6 +120,7 @@
   "$_src/sksl/ir/SkSLModifiers.h",
   "$_src/sksl/ir/SkSLModifiersDeclaration.h",
   "$_src/sksl/ir/SkSLNop.h",
+  "$_src/sksl/ir/SkSLPostfixExpression.cpp",
   "$_src/sksl/ir/SkSLPostfixExpression.h",
   "$_src/sksl/ir/SkSLPrefixExpression.cpp",
   "$_src/sksl/ir/SkSLPrefixExpression.h",
diff --git a/src/sksl/SkSLIRGenerator.cpp b/src/sksl/SkSLIRGenerator.cpp
index 2b12e43..b764687 100644
--- a/src/sksl/SkSLIRGenerator.cpp
+++ b/src/sksl/SkSLIRGenerator.cpp
@@ -769,7 +769,8 @@
             Token::Kind::TK_LT,
             std::make_unique<IntLiteral>(fContext, /*offset=*/-1, fInvocations),
             fContext.fTypes.fBool.get());
-    auto next = std::make_unique<PostfixExpression>(
+    auto next = PostfixExpression::Make(
+            fContext,
             std::make_unique<VariableReference>(/*offset=*/-1, loopIdx,
                                                 VariableReference::RefKind::kReadWrite),
             Token::Kind::TK_PLUSPLUS);
@@ -2408,23 +2409,7 @@
     if (!base) {
         return nullptr;
     }
-    return this->convertPostfixExpression(std::move(base), expression.getOperator());
-}
-
-std::unique_ptr<Expression> IRGenerator::convertPostfixExpression(std::unique_ptr<Expression> base,
-                                                                  Operator op) {
-    const Type& baseType = base->type();
-    if (!baseType.isNumber()) {
-        this->errorReporter().error(base->fOffset,
-                                    "'" + String(op.operatorName()) +
-                                    "' cannot operate on '" + baseType.displayName() + "'");
-        return nullptr;
-    }
-    if (!Analysis::MakeAssignmentExpr(base.get(), VariableReference::RefKind::kReadWrite,
-                                      &fContext.fErrors)) {
-        return nullptr;
-    }
-    return std::make_unique<PostfixExpression>(std::move(base), op);
+    return PostfixExpression::Make(fContext, std::move(base), expression.getOperator());
 }
 
 void IRGenerator::checkValid(const Expression& expr) {
diff --git a/src/sksl/SkSLIRGenerator.h b/src/sksl/SkSLIRGenerator.h
index 00ff1e4..6efbb7a 100644
--- a/src/sksl/SkSLIRGenerator.h
+++ b/src/sksl/SkSLIRGenerator.h
@@ -221,8 +221,6 @@
     std::unique_ptr<Expression> convertIndexExpression(const ASTNode& expression);
     std::unique_ptr<Expression> convertIndex(std::unique_ptr<Expression> base,
                                              std::unique_ptr<Expression> index);
-    std::unique_ptr<Expression> convertPostfixExpression(std::unique_ptr<Expression> base,
-                                                         Operator op);
     std::unique_ptr<Expression> convertPostfixExpression(const ASTNode& expression);
     std::unique_ptr<Expression> convertScopeExpression(const ASTNode& expression);
     std::unique_ptr<StructDefinition> convertStructDefinition(const ASTNode& expression);
diff --git a/src/sksl/SkSLInliner.cpp b/src/sksl/SkSLInliner.cpp
index 4ba9157..07f2991 100644
--- a/src/sksl/SkSLInliner.cpp
+++ b/src/sksl/SkSLInliner.cpp
@@ -367,7 +367,7 @@
         }
         case Expression::Kind::kPostfix: {
             const PostfixExpression& p = expression.as<PostfixExpression>();
-            return std::make_unique<PostfixExpression>(expr(p.operand()), p.getOperator());
+            return PostfixExpression::Make(*fContext, expr(p.operand()), p.getOperator());
         }
         case Expression::Kind::kSetting:
             return expression.clone();
@@ -716,7 +716,8 @@
                 fContext->fTypes.fBool.get());
 
         // _1_loop++
-        std::unique_ptr<Expression> increment = std::make_unique<PostfixExpression>(
+        std::unique_ptr<Expression> increment = PostfixExpression::Make(
+                *fContext,
                 std::make_unique<VariableReference>(/*offset=*/-1, loopVar.fVarSymbol,
                                                     VariableReference::RefKind::kReadWrite),
                 Token::Kind::TK_PLUSPLUS);
diff --git a/src/sksl/SkSLRehydrator.cpp b/src/sksl/SkSLRehydrator.cpp
index 225ecee..9877476 100644
--- a/src/sksl/SkSLRehydrator.cpp
+++ b/src/sksl/SkSLRehydrator.cpp
@@ -503,7 +503,7 @@
         case Rehydrator::kPostfix_Command: {
             Token::Kind op = (Token::Kind) this->readU8();
             std::unique_ptr<Expression> operand = this->expression();
-            return std::make_unique<PostfixExpression>(std::move(operand), op);
+            return PostfixExpression::Make(fContext, std::move(operand), op);
         }
         case Rehydrator::kPrefix_Command: {
             Token::Kind op = (Token::Kind) this->readU8();
diff --git a/src/sksl/dsl/priv/DSLWriter.cpp b/src/sksl/dsl/priv/DSLWriter.cpp
index f94e941..237fa6e 100644
--- a/src/sksl/dsl/priv/DSLWriter.cpp
+++ b/src/sksl/dsl/priv/DSLWriter.cpp
@@ -16,6 +16,7 @@
 #include "src/sksl/dsl/DSLCore.h"
 #include "src/sksl/dsl/DSLErrorHandling.h"
 #include "src/sksl/ir/SkSLConstructor.h"
+#include "src/sksl/ir/SkSLPostfixExpression.h"
 #include "src/sksl/ir/SkSLPrefixExpression.h"
 #include "src/sksl/ir/SkSLSwitchStatement.h"
 
@@ -132,7 +133,7 @@
 
 std::unique_ptr<SkSL::Expression> DSLWriter::ConvertPostfix(std::unique_ptr<Expression> expr,
                                                             Operator op) {
-    return IRGenerator().convertPostfixExpression(std::move(expr), op);
+    return PostfixExpression::Make(Context(), std::move(expr), op);
 }
 
 std::unique_ptr<SkSL::Expression> DSLWriter::ConvertPrefix(Operator op,
diff --git a/src/sksl/ir/SkSLPostfixExpression.cpp b/src/sksl/ir/SkSLPostfixExpression.cpp
new file mode 100644
index 0000000..6950434
--- /dev/null
+++ b/src/sksl/ir/SkSLPostfixExpression.cpp
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2021 Google LLC
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "src/sksl/SkSLAnalysis.h"
+#include "src/sksl/SkSLContext.h"
+#include "src/sksl/ir/SkSLPostfixExpression.h"
+#include "src/sksl/ir/SkSLVariableReference.h"
+
+namespace SkSL {
+
+std::unique_ptr<Expression> PostfixExpression::Make(const Context& context,
+                                                    std::unique_ptr<Expression> base,
+                                                    Operator op) {
+    const Type& baseType = base->type();
+    if (!baseType.isNumber()) {
+        context.fErrors.error(base->fOffset,
+                              "'" + String(op.operatorName()) + "' cannot operate on '" +
+                              baseType.displayName() + "'");
+        return nullptr;
+    }
+    if (!Analysis::MakeAssignmentExpr(base.get(), VariableRefKind::kReadWrite, &context.fErrors)) {
+        return nullptr;
+    }
+    return std::make_unique<PostfixExpression>(std::move(base), op);
+}
+
+}  // namespace SkSL
diff --git a/src/sksl/ir/SkSLPostfixExpression.h b/src/sksl/ir/SkSLPostfixExpression.h
index 92b0caf..df5e797 100644
--- a/src/sksl/ir/SkSLPostfixExpression.h
+++ b/src/sksl/ir/SkSLPostfixExpression.h
@@ -26,6 +26,9 @@
         , fOperand(std::move(operand))
         , fOperator(op) {}
 
+    static std::unique_ptr<Expression> Make(const Context& context,
+                                            std::unique_ptr<Expression> base,
+                                            Operator op);
     Operator getOperator() const {
         return fOperator;
     }
@@ -39,15 +42,12 @@
     }
 
     bool hasProperty(Property property) const override {
-        if (property == Property::kSideEffects) {
-            return true;
-        }
-        return this->operand()->hasProperty(property);
+        return (property == Property::kSideEffects) ||
+               this->operand()->hasProperty(property);
     }
 
     std::unique_ptr<Expression> clone() const override {
-        return std::unique_ptr<Expression>(new PostfixExpression(this->operand()->clone(),
-                                                                 this->getOperator()));
+        return std::make_unique<PostfixExpression>(this->operand()->clone(), this->getOperator());
     }
 
     String description() const override {