-
Notifications
You must be signed in to change notification settings - Fork 274
use code_blockt::add and ::move for adding a statement #3067
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -873,7 +873,7 @@ code_blockt &java_bytecode_convert_methodt::get_or_create_block_for_pcrange( | |
for(auto blockidx=child_offset, blocklim=child_offset+nblocks; | ||
blockidx!=blocklim; | ||
++blockidx) | ||
newblock.move_to_operands(this_block_children[blockidx]); | ||
newblock.add(this_block_children[blockidx]); | ||
|
||
// Relabel the inner header: | ||
to_code_label(newblock.statements()[0]).set_label(new_label_irep); | ||
|
@@ -1727,7 +1727,7 @@ codet java_bytecode_convert_methodt::convert_instructions( | |
{ | ||
symbol_exprt lhs=tmp_variable("$stack", s_it->type()); | ||
code_assignt a(lhs, *s_it); | ||
more_code.copy_to_operands(a); | ||
more_code.add(a); | ||
|
||
s_it->swap(lhs); | ||
} | ||
|
@@ -1743,7 +1743,7 @@ codet java_bytecode_convert_methodt::convert_instructions( | |
assert(has_prefix(os_it->get_string(ID_C_base_name), "$stack")); | ||
symbol_exprt lhs=to_symbol_expr(*os_it); | ||
code_assignt a(lhs, expr); | ||
more_code.copy_to_operands(a); | ||
more_code.add(a); | ||
|
||
expr.swap(lhs); | ||
++os_it; | ||
|
@@ -1752,7 +1752,7 @@ codet java_bytecode_convert_methodt::convert_instructions( | |
|
||
if(results.empty()) | ||
{ | ||
more_code.copy_to_operands(c); | ||
more_code.add(c); | ||
c.swap(more_code); | ||
} | ||
else | ||
|
@@ -1834,7 +1834,7 @@ codet java_bytecode_convert_methodt::convert_instructions( | |
if(start_new_block) | ||
{ | ||
code_labelt newlabel(label(std::to_string(address)), code_blockt()); | ||
root_block.move_to_operands(newlabel); | ||
root_block.add(newlabel); | ||
root.branch.push_back(block_tree_nodet::get_leaf()); | ||
assert((root.branch_addresses.empty() || | ||
root.branch_addresses.back()<address) && | ||
|
@@ -1912,7 +1912,7 @@ codet java_bytecode_convert_methodt::convert_instructions( | |
} | ||
|
||
for(auto &block : root_block.statements()) | ||
code.move_to_operands(block); | ||
code.add(block); | ||
|
||
return code; | ||
} | ||
|
@@ -2252,12 +2252,7 @@ void java_bytecode_convert_methodt::convert_invoke( | |
{ | ||
codet clinit_call = get_clinit_call(arg0.get(ID_C_class)); | ||
if(clinit_call.get_statement() != ID_skip) | ||
{ | ||
code_blockt ret_block; | ||
ret_block.move_to_operands(clinit_call); | ||
ret_block.move_to_operands(c); | ||
c = std::move(ret_block); | ||
} | ||
c = code_blockt({clinit_call, c}); | ||
} | ||
} | ||
|
||
|
@@ -2320,10 +2315,7 @@ void java_bytecode_convert_methodt::convert_athrow( | |
assume_location.set("user-provided", true); | ||
assume_code.add_source_location() = assume_location; | ||
|
||
code_blockt ret_block; | ||
ret_block.move_to_operands(assert_code); | ||
ret_block.move_to_operands(assume_code); | ||
c = ret_block; | ||
c = code_blockt({assert_code, assume_code}); | ||
} | ||
else | ||
{ | ||
|
@@ -2394,10 +2386,7 @@ codet &java_bytecode_convert_methodt::do_exception_handling( | |
exception_ids[i], handler_labels[i])); | ||
} | ||
|
||
code_blockt try_block; | ||
try_block.move_to_operands(catch_push); | ||
try_block.move_to_operands(c); | ||
c = try_block; | ||
c = code_blockt({catch_push, c}); | ||
} | ||
else | ||
{ | ||
|
@@ -2435,10 +2424,7 @@ codet &java_bytecode_convert_methodt::do_exception_handling( | |
start_pc = exception_row.start_pc; | ||
// add CATCH_POP instruction | ||
code_pop_catcht catch_pop; | ||
code_blockt end_try_block; | ||
end_try_block.move_to_operands(c); | ||
end_try_block.move_to_operands(catch_pop); | ||
c = end_try_block; | ||
c = code_blockt({c, catch_pop}); | ||
} | ||
} | ||
} | ||
|
@@ -2464,11 +2450,11 @@ void java_bytecode_convert_methodt::convert_multianewarray( | |
constant_exprt size_limit = from_integer(max_array_length, java_int_type()); | ||
binary_relation_exprt le_max_size(op[0], ID_le, size_limit); | ||
code_assumet assume_le_max_size(le_max_size); | ||
create.move_to_operands(assume_le_max_size); | ||
create.add(assume_le_max_size); | ||
} | ||
|
||
const exprt tmp = tmp_variable("newarray", ref_type); | ||
create.copy_to_operands(code_assignt(tmp, java_new_array)); | ||
create.add(code_assignt(tmp, java_new_array)); | ||
c = std::move(create); | ||
results[0] = tmp; | ||
} | ||
|
@@ -2521,10 +2507,10 @@ void java_bytecode_convert_methodt::convert_newarray( | |
constant_exprt size_limit = from_integer(max_array_length, java_int_type()); | ||
binary_relation_exprt le_max_size(op[0], ID_le, size_limit); | ||
code_assumet assume_le_max_size(le_max_size); | ||
c.move_to_operands(assume_le_max_size); | ||
to_code_block(c).add(assume_le_max_size); | ||
} | ||
const exprt tmp = tmp_variable("newarray", ref_type); | ||
c.copy_to_operands(code_assignt(tmp, java_new_array)); | ||
to_code_block(c).add(code_assignt(tmp, java_new_array)); | ||
results[0] = tmp; | ||
} | ||
|
||
|
@@ -2547,10 +2533,7 @@ void java_bytecode_convert_methodt::convert_new( | |
get_clinit_call(to_symbol_type(arg0.type()).get_identifier()); | ||
if(clinit_call.get_statement() != ID_skip) | ||
{ | ||
code_blockt ret_block; | ||
ret_block.move_to_operands(clinit_call); | ||
ret_block.move_to_operands(c); | ||
c = std::move(ret_block); | ||
c = code_blockt({clinit_call, c}); | ||
} | ||
results[0] = tmp; | ||
} | ||
|
@@ -2575,15 +2558,15 @@ codet java_bytecode_convert_methodt::convert_putstatic( | |
// the field. | ||
codet clinit_call = get_clinit_call(arg0.get_string(ID_class)); | ||
if(clinit_call.get_statement() != ID_skip) | ||
block.move_to_operands(clinit_call); | ||
block.add(clinit_call); | ||
|
||
save_stack_entries( | ||
"stack_static_field", | ||
symbol_expr.type(), | ||
block, | ||
bytecode_write_typet::STATIC_FIELD, | ||
symbol_expr.get_identifier()); | ||
block.copy_to_operands(code_assignt(symbol_expr, op[0])); | ||
block.add(code_assignt(symbol_expr, op[0])); | ||
return block; | ||
} | ||
|
||
|
@@ -2598,7 +2581,7 @@ codet java_bytecode_convert_methodt::convert_putfield( | |
block, | ||
bytecode_write_typet::FIELD, | ||
arg0.get(ID_component_name)); | ||
block.copy_to_operands(code_assignt(to_member(op[0], arg0), op[1])); | ||
block.add(code_assignt(to_member(op[0], arg0), op[1])); | ||
return block; | ||
} | ||
|
||
|
@@ -2738,7 +2721,8 @@ codet java_bytecode_convert_methodt::convert_iinc( | |
const code_assignt code_assign( | ||
variable(arg0, 'i', address, NO_CAST), | ||
plus_exprt(variable(arg0, 'i', address, CAST_AS_NEEDED), arg1_int_type)); | ||
block.copy_to_operands(code_assign); | ||
block.add(code_assign); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move? |
||
|
||
return block; | ||
} | ||
|
||
|
@@ -2843,7 +2827,7 @@ code_blockt java_bytecode_convert_methodt::convert_ret( | |
code_gotot g(label(number)); | ||
g.add_source_location() = location; | ||
if(idx == idxlim - 1) | ||
c.move_to_operands(g); | ||
c.add(g); | ||
else | ||
{ | ||
code_ifthenelset branch; | ||
|
@@ -2854,7 +2838,7 @@ code_blockt java_bytecode_convert_methodt::convert_ret( | |
branch.cond().add_source_location() = location; | ||
branch.then_case() = g; | ||
branch.add_source_location() = location; | ||
c.move_to_operands(branch); | ||
c.add(branch); | ||
} | ||
} | ||
return c; | ||
|
@@ -2905,7 +2889,7 @@ codet java_bytecode_convert_methodt::convert_store( | |
var_name); | ||
code_assignt assign(var, toassign); | ||
assign.add_source_location() = location; | ||
block.move(assign); | ||
block.add(assign); | ||
return block; | ||
} | ||
|
||
|
@@ -2937,7 +2921,7 @@ codet java_bytecode_convert_methodt::convert_astore( | |
|
||
code_assignt array_put(element, op[2]); | ||
array_put.add_source_location() = location; | ||
block.move(array_put); | ||
block.add(array_put); | ||
return block; | ||
} | ||
|
||
|
@@ -3268,6 +3252,6 @@ void java_bytecode_convert_methodt::create_stack_tmp_var( | |
{ | ||
const exprt tmp_var= | ||
tmp_variable(tmp_var_prefix, tmp_var_type); | ||
block.copy_to_operands(code_assignt(tmp_var, stack_entry)); | ||
block.add(code_assignt(tmp_var, stack_entry)); | ||
stack_entry=tmp_var; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're going for this style, could I recommend replacing the constructor for
code_blockt
that takes astd::list<const codet &>
with one taking astd::initializer_list
? The former means a bunch of heap allocates and deallocates, whereas the latter is basically a type-safe layer atop varargs.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(It could also take universal references, permitting
{monitorexit, std::move(code)}
)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Correction, it's not a wrapper on
<stdarg>
style varargs as I'd thought, but it is a fixed-size array, probably stack-allocated, which still avoids much of the pointless back-and-forth of a temporary linked list)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(You could also use a variadic template... but that's probably more fuss than it's worth when the initializers are monovariant)
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, there is unnecessary copying going on in the constructor. How about these:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not
std::initializer_list<codet>
? Should be just like vector, except without the heap alloc; plus it's (one of the) new standard ways to do varargsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does that add anything over offering the vector interface? Note that the vector offers a constructor from std::initializer_list, and that the vector needs to exist eventually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think marginally, but the difference is small so let's go with this. It's definitely much better than
std::list
for this purpose.