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