|
@@ -65,7 +65,7 @@ pub fn expression(
|
|
|
} => add(
|
|
} => add(
|
|
|
loc,
|
|
loc,
|
|
|
ty,
|
|
ty,
|
|
|
- unchecked,
|
|
|
|
|
|
|
+ *unchecked,
|
|
|
left,
|
|
left,
|
|
|
cfg,
|
|
cfg,
|
|
|
contract_no,
|
|
contract_no,
|
|
@@ -84,7 +84,7 @@ pub fn expression(
|
|
|
} => subtract(
|
|
} => subtract(
|
|
|
loc,
|
|
loc,
|
|
|
ty,
|
|
ty,
|
|
|
- unchecked,
|
|
|
|
|
|
|
+ *unchecked,
|
|
|
left,
|
|
left,
|
|
|
cfg,
|
|
cfg,
|
|
|
contract_no,
|
|
contract_no,
|
|
@@ -353,7 +353,7 @@ pub fn expression(
|
|
|
} = &**left
|
|
} = &**left
|
|
|
{
|
|
{
|
|
|
// If cfg_right is an AllocDynamicArray(_,_,size,_), update it such that it becomes AllocDynamicArray(_,_,temp_var,_) to avoid repetitive expressions in the cfg.
|
|
// If cfg_right is an AllocDynamicArray(_,_,size,_), update it such that it becomes AllocDynamicArray(_,_,temp_var,_) to avoid repetitive expressions in the cfg.
|
|
|
- cfg_right = handle_array_assign(cfg_right, cfg, vartab, var_no);
|
|
|
|
|
|
|
+ cfg_right = handle_array_assign(cfg_right, cfg, vartab, *var_no);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
assign_single(left, cfg_right, cfg, contract_no, func, ns, vartab, opt)
|
|
assign_single(left, cfg_right, cfg, contract_no, func, ns, vartab, opt)
|
|
@@ -379,7 +379,7 @@ pub fn expression(
|
|
|
ns,
|
|
ns,
|
|
|
loc,
|
|
loc,
|
|
|
expr,
|
|
expr,
|
|
|
- unchecked,
|
|
|
|
|
|
|
+ *unchecked,
|
|
|
opt,
|
|
opt,
|
|
|
),
|
|
),
|
|
|
ast::Expression::PostDecrement {
|
|
ast::Expression::PostDecrement {
|
|
@@ -403,7 +403,7 @@ pub fn expression(
|
|
|
ns,
|
|
ns,
|
|
|
loc,
|
|
loc,
|
|
|
expr,
|
|
expr,
|
|
|
- unchecked,
|
|
|
|
|
|
|
+ *unchecked,
|
|
|
opt,
|
|
opt,
|
|
|
),
|
|
),
|
|
|
ast::Expression::Constructor {
|
|
ast::Expression::Constructor {
|
|
@@ -417,7 +417,7 @@ pub fn expression(
|
|
|
|
|
|
|
|
call_constructor(
|
|
call_constructor(
|
|
|
loc,
|
|
loc,
|
|
|
- constructor_contract,
|
|
|
|
|
|
|
+ *constructor_contract,
|
|
|
contract_no,
|
|
contract_no,
|
|
|
constructor_no,
|
|
constructor_no,
|
|
|
args,
|
|
args,
|
|
@@ -903,7 +903,7 @@ pub fn expression(
|
|
|
ast::Expression::Builtin {
|
|
ast::Expression::Builtin {
|
|
|
loc,
|
|
loc,
|
|
|
tys,
|
|
tys,
|
|
|
- kind: builtin,
|
|
|
|
|
|
|
+ kind,
|
|
|
args,
|
|
args,
|
|
|
} => expr_builtin(
|
|
} => expr_builtin(
|
|
|
args,
|
|
args,
|
|
@@ -914,7 +914,7 @@ pub fn expression(
|
|
|
vartab,
|
|
vartab,
|
|
|
loc,
|
|
loc,
|
|
|
tys,
|
|
tys,
|
|
|
- builtin,
|
|
|
|
|
|
|
+ *kind,
|
|
|
opt,
|
|
opt,
|
|
|
),
|
|
),
|
|
|
ast::Expression::FormatString { loc, format: args } => {
|
|
ast::Expression::FormatString { loc, format: args } => {
|
|
@@ -945,7 +945,7 @@ pub fn expression(
|
|
|
right,
|
|
right,
|
|
|
opt,
|
|
opt,
|
|
|
),
|
|
),
|
|
|
- ast::Expression::InterfaceId { loc, contract_no } => interfaceid(ns, contract_no, loc),
|
|
|
|
|
|
|
+ ast::Expression::InterfaceId { loc, contract_no } => interfaceid(ns, *contract_no, loc),
|
|
|
ast::Expression::BoolLiteral { loc, value } => Expression::BoolLiteral(*loc, *value),
|
|
ast::Expression::BoolLiteral { loc, value } => Expression::BoolLiteral(*loc, *value),
|
|
|
ast::Expression::BytesLiteral { loc, ty, value } => {
|
|
ast::Expression::BytesLiteral { loc, ty, value } => {
|
|
|
Expression::BytesLiteral(*loc, ty.clone(), value.clone())
|
|
Expression::BytesLiteral(*loc, ty.clone(), value.clone())
|
|
@@ -1050,7 +1050,7 @@ fn post_incdec(
|
|
|
ns: &Namespace,
|
|
ns: &Namespace,
|
|
|
loc: &pt::Loc,
|
|
loc: &pt::Loc,
|
|
|
expr: &ast::Expression,
|
|
expr: &ast::Expression,
|
|
|
- unchecked: &bool,
|
|
|
|
|
|
|
+ unchecked: bool,
|
|
|
opt: &Options,
|
|
opt: &Options,
|
|
|
) -> Expression {
|
|
) -> Expression {
|
|
|
let res = vartab.temp_anonymous(ty);
|
|
let res = vartab.temp_anonymous(ty);
|
|
@@ -1073,14 +1073,14 @@ fn post_incdec(
|
|
|
ast::Expression::PostDecrement { .. } => Expression::Subtract(
|
|
ast::Expression::PostDecrement { .. } => Expression::Subtract(
|
|
|
*loc,
|
|
*loc,
|
|
|
ty.clone(),
|
|
ty.clone(),
|
|
|
- *unchecked,
|
|
|
|
|
|
|
+ unchecked,
|
|
|
Box::new(Expression::Variable(*loc, ty.clone(), res)),
|
|
Box::new(Expression::Variable(*loc, ty.clone(), res)),
|
|
|
one,
|
|
one,
|
|
|
),
|
|
),
|
|
|
ast::Expression::PostIncrement { .. } => Expression::Add(
|
|
ast::Expression::PostIncrement { .. } => Expression::Add(
|
|
|
*loc,
|
|
*loc,
|
|
|
ty.clone(),
|
|
ty.clone(),
|
|
|
- *unchecked,
|
|
|
|
|
|
|
+ unchecked,
|
|
|
Box::new(Expression::Variable(*loc, ty.clone(), res)),
|
|
Box::new(Expression::Variable(*loc, ty.clone(), res)),
|
|
|
one,
|
|
one,
|
|
|
),
|
|
),
|
|
@@ -1146,7 +1146,7 @@ fn pre_incdec(
|
|
|
ns: &Namespace,
|
|
ns: &Namespace,
|
|
|
loc: &pt::Loc,
|
|
loc: &pt::Loc,
|
|
|
expr: &ast::Expression,
|
|
expr: &ast::Expression,
|
|
|
- unchecked: &bool,
|
|
|
|
|
|
|
+ unchecked: bool,
|
|
|
opt: &Options,
|
|
opt: &Options,
|
|
|
) -> Expression {
|
|
) -> Expression {
|
|
|
let res = vartab.temp_anonymous(ty);
|
|
let res = vartab.temp_anonymous(ty);
|
|
@@ -1159,10 +1159,10 @@ fn pre_incdec(
|
|
|
let one = Box::new(Expression::NumberLiteral(*loc, ty.clone(), BigInt::one()));
|
|
let one = Box::new(Expression::NumberLiteral(*loc, ty.clone(), BigInt::one()));
|
|
|
let expr = match expr {
|
|
let expr = match expr {
|
|
|
ast::Expression::PreDecrement { .. } => {
|
|
ast::Expression::PreDecrement { .. } => {
|
|
|
- Expression::Subtract(*loc, ty.clone(), *unchecked, Box::new(v), one)
|
|
|
|
|
|
|
+ Expression::Subtract(*loc, ty.clone(), unchecked, Box::new(v), one)
|
|
|
}
|
|
}
|
|
|
ast::Expression::PreIncrement { .. } => {
|
|
ast::Expression::PreIncrement { .. } => {
|
|
|
- Expression::Add(*loc, ty.clone(), *unchecked, Box::new(v), one)
|
|
|
|
|
|
|
+ Expression::Add(*loc, ty.clone(), unchecked, Box::new(v), one)
|
|
|
}
|
|
}
|
|
|
_ => unreachable!(),
|
|
_ => unreachable!(),
|
|
|
};
|
|
};
|
|
@@ -1779,7 +1779,7 @@ fn expr_builtin(
|
|
|
vartab: &mut Vartable,
|
|
vartab: &mut Vartable,
|
|
|
loc: &pt::Loc,
|
|
loc: &pt::Loc,
|
|
|
tys: &[Type],
|
|
tys: &[Type],
|
|
|
- builtin: &ast::Builtin,
|
|
|
|
|
|
|
+ builtin: ast::Builtin,
|
|
|
opt: &Options,
|
|
opt: &Options,
|
|
|
) -> Expression {
|
|
) -> Expression {
|
|
|
match builtin {
|
|
match builtin {
|
|
@@ -1983,7 +1983,7 @@ fn expr_builtin(
|
|
|
|
|
|
|
|
cfg.set_basic_block(in_bounds);
|
|
cfg.set_basic_block(in_bounds);
|
|
|
|
|
|
|
|
- Expression::Builtin(*loc, tys.to_vec(), builtin.into(), vec![buf, offset])
|
|
|
|
|
|
|
+ Expression::Builtin(*loc, tys.to_vec(), (&builtin).into(), vec![buf, offset])
|
|
|
}
|
|
}
|
|
|
ast::Builtin::AddMod | ast::Builtin::MulMod => {
|
|
ast::Builtin::AddMod | ast::Builtin::MulMod => {
|
|
|
let arguments: Vec<Expression> = args
|
|
let arguments: Vec<Expression> = args
|
|
@@ -2017,7 +2017,7 @@ fn expr_builtin(
|
|
|
Instr::Set {
|
|
Instr::Set {
|
|
|
loc: *loc,
|
|
loc: *loc,
|
|
|
res: temp,
|
|
res: temp,
|
|
|
- expr: Expression::Builtin(*loc, tys.to_vec(), builtin.into(), arguments),
|
|
|
|
|
|
|
+ expr: Expression::Builtin(*loc, tys.to_vec(), (&builtin).into(), arguments),
|
|
|
},
|
|
},
|
|
|
);
|
|
);
|
|
|
cfg.add(vartab, Instr::Branch { block: end_if });
|
|
cfg.add(vartab, Instr::Branch { block: end_if });
|
|
@@ -2043,7 +2043,7 @@ fn expr_builtin(
|
|
|
.map(|v| expression(v, cfg, contract_no, func, ns, vartab, opt))
|
|
.map(|v| expression(v, cfg, contract_no, func, ns, vartab, opt))
|
|
|
.collect();
|
|
.collect();
|
|
|
|
|
|
|
|
- if !arguments.is_empty() && builtin == &ast::Builtin::ArrayLength {
|
|
|
|
|
|
|
+ if !arguments.is_empty() && builtin == ast::Builtin::ArrayLength {
|
|
|
// If an array length instruction is called
|
|
// If an array length instruction is called
|
|
|
// Get the variable it is assigned with
|
|
// Get the variable it is assigned with
|
|
|
if let Expression::Variable(_, _, num) = &arguments[0] {
|
|
if let Expression::Variable(_, _, num) = &arguments[0] {
|
|
@@ -2054,7 +2054,7 @@ fn expr_builtin(
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- Expression::Builtin(*loc, tys.to_vec(), builtin.into(), arguments)
|
|
|
|
|
|
|
+ Expression::Builtin(*loc, tys.to_vec(), (&builtin).into(), arguments)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -2078,7 +2078,7 @@ fn alloc_dynamic_array(
|
|
|
fn add(
|
|
fn add(
|
|
|
loc: &pt::Loc,
|
|
loc: &pt::Loc,
|
|
|
ty: &Type,
|
|
ty: &Type,
|
|
|
- unchecked: &bool,
|
|
|
|
|
|
|
+ unchecked: bool,
|
|
|
left: &ast::Expression,
|
|
left: &ast::Expression,
|
|
|
cfg: &mut ControlFlowGraph,
|
|
cfg: &mut ControlFlowGraph,
|
|
|
contract_no: usize,
|
|
contract_no: usize,
|
|
@@ -2091,7 +2091,7 @@ fn add(
|
|
|
Expression::Add(
|
|
Expression::Add(
|
|
|
*loc,
|
|
*loc,
|
|
|
ty.clone(),
|
|
ty.clone(),
|
|
|
- *unchecked,
|
|
|
|
|
|
|
+ unchecked,
|
|
|
Box::new(expression(left, cfg, contract_no, func, ns, vartab, opt)),
|
|
Box::new(expression(left, cfg, contract_no, func, ns, vartab, opt)),
|
|
|
Box::new(expression(right, cfg, contract_no, func, ns, vartab, opt)),
|
|
Box::new(expression(right, cfg, contract_no, func, ns, vartab, opt)),
|
|
|
)
|
|
)
|
|
@@ -2100,7 +2100,7 @@ fn add(
|
|
|
fn subtract(
|
|
fn subtract(
|
|
|
loc: &pt::Loc,
|
|
loc: &pt::Loc,
|
|
|
ty: &Type,
|
|
ty: &Type,
|
|
|
- unchecked: &bool,
|
|
|
|
|
|
|
+ unchecked: bool,
|
|
|
left: &ast::Expression,
|
|
left: &ast::Expression,
|
|
|
cfg: &mut ControlFlowGraph,
|
|
cfg: &mut ControlFlowGraph,
|
|
|
contract_no: usize,
|
|
contract_no: usize,
|
|
@@ -2113,7 +2113,7 @@ fn subtract(
|
|
|
Expression::Subtract(
|
|
Expression::Subtract(
|
|
|
*loc,
|
|
*loc,
|
|
|
ty.clone(),
|
|
ty.clone(),
|
|
|
- *unchecked,
|
|
|
|
|
|
|
+ unchecked,
|
|
|
Box::new(expression(left, cfg, contract_no, func, ns, vartab, opt)),
|
|
Box::new(expression(left, cfg, contract_no, func, ns, vartab, opt)),
|
|
|
Box::new(expression(right, cfg, contract_no, func, ns, vartab, opt)),
|
|
Box::new(expression(right, cfg, contract_no, func, ns, vartab, opt)),
|
|
|
)
|
|
)
|
|
@@ -2293,14 +2293,14 @@ fn conditional_operator(
|
|
|
Expression::Variable(*loc, ty.clone(), pos)
|
|
Expression::Variable(*loc, ty.clone(), pos)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-fn interfaceid(ns: &Namespace, contract_no: &usize, loc: &pt::Loc) -> Expression {
|
|
|
|
|
|
|
+fn interfaceid(ns: &Namespace, contract_no: usize, loc: &pt::Loc) -> Expression {
|
|
|
let selector_len = ns.target.selector_length();
|
|
let selector_len = ns.target.selector_length();
|
|
|
let mut id = vec![0u8; selector_len as usize];
|
|
let mut id = vec![0u8; selector_len as usize];
|
|
|
- for func_no in &ns.contracts[*contract_no].functions {
|
|
|
|
|
|
|
+ for func_no in &ns.contracts[contract_no].functions {
|
|
|
let func = &ns.functions[*func_no];
|
|
let func = &ns.functions[*func_no];
|
|
|
|
|
|
|
|
if func.ty == pt::FunctionTy::Function {
|
|
if func.ty == pt::FunctionTy::Function {
|
|
|
- let selector = func.selector(ns, contract_no);
|
|
|
|
|
|
|
+ let selector = func.selector(ns, &contract_no);
|
|
|
debug_assert_eq!(id.len(), selector.len());
|
|
debug_assert_eq!(id.len(), selector.len());
|
|
|
|
|
|
|
|
for (i, e) in id.iter_mut().enumerate() {
|
|
for (i, e) in id.iter_mut().enumerate() {
|