Forráskód Böngészése

JSSpecCompiler: Replace all declarations with assignments

We assume that variable shadowing is impossible, so then there is no
reason to keep distinct Declaration and Assignment operators after
ReferenceResolvingPass.
Dan Klishch 1 éve
szülő
commit
23164bc570

+ 2 - 0
Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Compiler/Passes/ReferenceResolvingPass.cpp

@@ -18,6 +18,8 @@ RecursionDecision ReferenceResolvingPass::on_entry(Tree tree)
         if (binary_operation->m_operation != BinaryOperator::Declaration)
             return RecursionDecision::Recurse;
 
+        binary_operation->m_operation = BinaryOperator::Assignment;
+
         if (auto variable_name = as<UnresolvedReference>(binary_operation->m_left); variable_name) {
             auto name = variable_name->m_name;
             if (!m_function->m_local_variables.contains(name))

+ 20 - 20
Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Tests/simple.cpp.expectation

@@ -86,21 +86,21 @@ TreeList
   IfElseIfChain
     UnresolvedReference cond1
     TreeList
-      BinaryOperation Declaration
+      BinaryOperation Assignment
         Var a
         MathematicalConstant 1
       IfElseIfChain
         UnresolvedReference cond2
         TreeList
-          BinaryOperation Declaration
+          BinaryOperation Assignment
             Var b
             Var a
         TreeList
-          BinaryOperation Declaration
+          BinaryOperation Assignment
             Var b
             MathematicalConstant 3
     TreeList
-      BinaryOperation Declaration
+      BinaryOperation Assignment
         Var b
         MathematicalConstant 4
   ReturnNode
@@ -112,21 +112,21 @@ TreeList
   IfElseIfChain
     UnresolvedReference cond1
     TreeList
-      BinaryOperation Declaration
+      BinaryOperation Assignment
         Var a
         MathematicalConstant 1
       IfElseIfChain
         UnresolvedReference cond2
         TreeList
-          BinaryOperation Declaration
+          BinaryOperation Assignment
             Var b
             Var a
         TreeList
-          BinaryOperation Declaration
+          BinaryOperation Assignment
             Var b
             MathematicalConstant 3
     TreeList
-      BinaryOperation Declaration
+      BinaryOperation Assignment
         Var b
         MathematicalConstant 4
   ReturnNode
@@ -149,7 +149,7 @@ BinaryOperation Assignment
 ControlFlowJump jump=1
 
 3:
-BinaryOperation Declaration
+BinaryOperation Assignment
   Var a
   MathematicalConstant 1
 ControlFlowBranch true=5 false=6
@@ -159,19 +159,19 @@ ControlFlowBranch true=5 false=6
 ControlFlowJump jump=2
 
 5:
-BinaryOperation Declaration
+BinaryOperation Assignment
   Var b
   Var a
 ControlFlowJump jump=4
 
 6:
-BinaryOperation Declaration
+BinaryOperation Assignment
   Var b
   MathematicalConstant 3
 ControlFlowJump jump=4
 
 7:
-BinaryOperation Declaration
+BinaryOperation Assignment
   Var b
   MathematicalConstant 4
 ControlFlowJump jump=2
@@ -188,21 +188,21 @@ TreeList
   IfElseIfChain
     UnresolvedReference cond1
     TreeList
-      BinaryOperation Declaration
+      BinaryOperation Assignment
         Var a
         MathematicalConstant 1
       IfElseIfChain
         UnresolvedReference cond2
         TreeList
-          BinaryOperation Declaration
+          BinaryOperation Assignment
             Var b
             Var a
         TreeList
-          BinaryOperation Declaration
+          BinaryOperation Assignment
             Var b
             MathematicalConstant 3
     TreeList
-      BinaryOperation Declaration
+      BinaryOperation Assignment
         Var b
         MathematicalConstant 4
   ReturnNode
@@ -225,26 +225,26 @@ BinaryOperation Assignment
 ControlFlowJump jump=1
 
 3:
-BinaryOperation Declaration
+BinaryOperation Assignment
   Var a
   MathematicalConstant 1
 ControlFlowBranch true=4 false=5
   UnresolvedReference cond2
 
 4:
-BinaryOperation Declaration
+BinaryOperation Assignment
   Var b
   Var a
 ControlFlowJump jump=2
 
 5:
-BinaryOperation Declaration
+BinaryOperation Assignment
   Var b
   MathematicalConstant 3
 ControlFlowJump jump=2
 
 6:
-BinaryOperation Declaration
+BinaryOperation Assignment
   Var b
   MathematicalConstant 4
 ControlFlowJump jump=2