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.
This commit is contained in:
Dan Klishch 2023-10-01 22:26:25 -04:00 committed by Andrew Kaster
parent 12072dbac5
commit 23164bc570
Notes: sideshowbarker 2024-07-17 17:49:11 +09:00
2 changed files with 22 additions and 20 deletions

View file

@ -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))

View file

@ -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