mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-12-25 11:12:48 +03:00
Cleanup
This commit is contained in:
parent
a4a912f677
commit
7059fb5ffa
@ -17,7 +17,7 @@
|
||||
use crate::StaticSingleAssigner;
|
||||
|
||||
use leo_ast::{
|
||||
BinaryExpression, CallExpression, CircuitExpression, CircuitVariableInitializer, Expression,
|
||||
CallExpression, CircuitExpression, CircuitVariableInitializer, Expression,
|
||||
ExpressionReconstructor, Identifier,
|
||||
};
|
||||
use leo_span::Symbol;
|
||||
|
@ -31,8 +31,8 @@ impl<'a> StatementReconstructor for StaticSingleAssigner<'a> {
|
||||
self.is_lhs = true;
|
||||
// TODO: Change to support a vector of identifiers.
|
||||
let identifier = match self.reconstruct_identifier(definition.variable_name).0 {
|
||||
Expression::Identifier(identifier) => identifier,
|
||||
_ => unreachable!("`reconstruct_identifier` will always return an `Identifier`."),
|
||||
Expression::Identifier(identifier) => identifier,
|
||||
_ => unreachable!("`reconstruct_identifier` will always return an `Identifier`."),
|
||||
};
|
||||
self.is_lhs = false;
|
||||
|
||||
@ -124,45 +124,42 @@ impl<'a> StatementReconstructor for StaticSingleAssigner<'a> {
|
||||
|
||||
// TODO: Better error handling.
|
||||
for symbol in write_set {
|
||||
match self.rename_table.lookup(symbol) {
|
||||
Some(..) => {
|
||||
let if_name = if_table
|
||||
.lookup(symbol)
|
||||
.unwrap_or_else(|| panic!("Symbol {} should exist in the program.", symbol));
|
||||
let else_name = else_table
|
||||
.lookup(symbol)
|
||||
.unwrap_or_else(|| panic!("Symbol {} should exist in the program.", symbol));
|
||||
if self.rename_table.lookup(symbol).is_some() {
|
||||
let if_name = if_table
|
||||
.lookup(symbol)
|
||||
.unwrap_or_else(|| panic!("Symbol {} should exist in the program.", symbol));
|
||||
let else_name = else_table
|
||||
.lookup(symbol)
|
||||
.unwrap_or_else(|| panic!("Symbol {} should exist in the program.", symbol));
|
||||
|
||||
let ternary = Expression::Ternary(TernaryExpression {
|
||||
condition: Box::new(condition.clone()),
|
||||
if_true: Box::new(Expression::Identifier(Identifier {
|
||||
name: *if_name,
|
||||
span: Default::default(),
|
||||
})),
|
||||
if_false: Box::new(Expression::Identifier(Identifier {
|
||||
name: *else_name,
|
||||
span: Default::default(),
|
||||
})),
|
||||
let ternary = Expression::Ternary(TernaryExpression {
|
||||
condition: Box::new(condition.clone()),
|
||||
if_true: Box::new(Expression::Identifier(Identifier {
|
||||
name: *if_name,
|
||||
span: Default::default(),
|
||||
});
|
||||
|
||||
// Create a new name for the variable written to in the `ConditionalStatement`.
|
||||
let new_name = Symbol::intern(&format!("{}${}", symbol, self.get_unique_id()));
|
||||
self.rename_table.update(*(*symbol), new_name);
|
||||
|
||||
// Create a new `AssignStatement` for the phi function.
|
||||
let assignment = Statement::Assign(Box::from(AssignStatement {
|
||||
operation: AssignOperation::Assign,
|
||||
place: Expression::Identifier(Identifier {
|
||||
name: new_name,
|
||||
span: Default::default(),
|
||||
}),
|
||||
value: ternary,
|
||||
})),
|
||||
if_false: Box::new(Expression::Identifier(Identifier {
|
||||
name: *else_name,
|
||||
span: Default::default(),
|
||||
}));
|
||||
self.phi_functions.push(assignment);
|
||||
}
|
||||
None => (),
|
||||
})),
|
||||
span: Default::default(),
|
||||
});
|
||||
|
||||
// Create a new name for the variable written to in the `ConditionalStatement`.
|
||||
let new_name = Symbol::intern(&format!("{}${}", symbol, self.get_unique_id()));
|
||||
self.rename_table.update(*(*symbol), new_name);
|
||||
|
||||
// Create a new `AssignStatement` for the phi function.
|
||||
let assignment = Statement::Assign(Box::from(AssignStatement {
|
||||
operation: AssignOperation::Assign,
|
||||
place: Expression::Identifier(Identifier {
|
||||
name: new_name,
|
||||
span: Default::default(),
|
||||
}),
|
||||
value: ternary,
|
||||
span: Default::default(),
|
||||
}));
|
||||
self.phi_functions.push(assignment);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user