Skip to content

Cleanup of operands() accesses #23

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 2 commits into from
Jan 23, 2017

Conversation

tautschnig
Copy link
Collaborator

Although USE_LIST is gone as of r3530, there are a number of cases where iterators are preferable over indexed access to elements.
This is a duplicate of #9 after restoring all links to the SVN.

@tautschnig tautschnig force-pushed the operandst-list-support branch from 9c5a1ae to f907248 Compare March 21, 2016 19:21
@tautschnig tautschnig force-pushed the operandst-list-support branch from f907248 to bad02a1 Compare April 3, 2016 09:51
@kroening kroening self-assigned this Apr 18, 2016
@tautschnig tautschnig force-pushed the operandst-list-support branch from bad02a1 to bd098eb Compare May 18, 2016 17:13
@tautschnig tautschnig force-pushed the operandst-list-support branch from bd098eb to a4145aa Compare May 30, 2016 11:44
@tautschnig tautschnig force-pushed the operandst-list-support branch from a4145aa to b4e83a7 Compare June 12, 2016 13:13
@tautschnig tautschnig force-pushed the operandst-list-support branch from b4e83a7 to 5498001 Compare June 21, 2016 07:12
@tautschnig tautschnig force-pushed the operandst-list-support branch from 5498001 to a01e3a1 Compare November 5, 2016 22:25
Copy link
Contributor

@thk123 thk123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an old PR so may be too distant for you to remember it's purpose!I've had a look through and changes all look like they don't change behaviour just improve type correctness and better for loops.

Main changes are consistency with prefix vs. post fix increamentors and a couple of places that can use range based for.

This also needs to be rebased - which may be more effort than it is worth.

@@ -2578,25 +2578,26 @@ void cpp_typecheckt::typecheck_function_call_arguments(
}
}

for(std::size_t i=0; i<parameters.size(); i++)
exprt::operandst::iterator arg_it=expr.arguments().begin();
for(std::size_t i=0; i<parameters.size(); i++, ++arg_it)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use either prefix or postfix to increment these.

@@ -2634,10 +2635,12 @@ void cpp_typecheck_resolvet::resolve_with_arguments(
const cpp_typecheck_fargst &fargs)
{
// not clear what this is good for
for(std::size_t i=0; i<fargs.operands.size(); i++)
for(exprt::operandst::const_iterator it=fargs.operands.begin();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can use a ranged for here


for(std::size_t i=1; i<operands.size(); i++)
for(exprt::operandst::const_iterator
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Range based for.

@@ -282,7 +282,7 @@ class code_assumet:public codet
inline code_assumet():codet(ID_assume)
{
// will change to resize(1) in the future
operands().reserve(1);
reserve_operands(1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the comment above still relevant/correct? Is reserve_operands what resize ended up being called?

@tautschnig tautschnig force-pushed the operandst-list-support branch from a01e3a1 to e1b120b Compare December 23, 2016 15:56
@tautschnig
Copy link
Collaborator Author

I have now refreshed/rebased this pull request, and have taken into account all the comments as far as applicable.

@peterschrammel
Copy link
Member

@thk123, can you please check whether your comments have been taken into account?

@thk123
Copy link
Contributor

thk123 commented Jan 12, 2017

@peterschrammel I think these (1, 3) comments are still outstanding. Are there reasons for not addressing them @tautschnig?

@tautschnig tautschnig force-pushed the operandst-list-support branch from e1b120b to e76a3a3 Compare January 18, 2017 15:47
@tautschnig
Copy link
Collaborator Author

I have addressed the remaining comments, which induced some further cleanup.

@tautschnig tautschnig force-pushed the operandst-list-support branch from e76a3a3 to 383a9de Compare January 18, 2017 15:51
Copy link
Contributor

@thk123 thk123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last few changes - apologies about wrongly saying should use op0() rather than front(), should have checked was an exprt not an operandst - I have removed this comment.


exprt temporary;
new_temporary(expr.arguments()[i].source_location(),
parameters[i].type().subtype(),
new_temporary(arg_it->source_location(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter should be on the next line. It might be worth rebasing again so you get the lint output from just modified lines.

@@ -109,7 +109,8 @@ bool cpp_typecheck_fargst::match(
return false;
}

for(std::size_t i=0; i<ops.size(); i++)
exprt::operandst::iterator it=ops.begin();
for(std::size_t i=0; i<ops.size(); i++, ++it)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still mixing post fix and prefix incrementing. Maybe this isn't really a problem (I think it looks weird but it isn't in the coding guidelines) but I thought I'd see this being picked up in other PR reviews.

return op0();
}

inline bool has_return_value() const
{
return operands().size()==1;
if(operands().empty()) return false; // backwards compatibility
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

False on the new line.

if(operands().empty()) 
  return false; // backwards compatibility

Use iterators instead of indexed access. This may re-enable std::list
support (for exprt::operandst) if taken further.
@tautschnig tautschnig force-pushed the operandst-list-support branch from 383a9de to e527f64 Compare January 20, 2017 15:09
@tautschnig
Copy link
Collaborator Author

Thanks a lot for the careful scrutiny! I believe I have addressed the issues, but looking at the cpplint run yields some rather unrelated problems. @thk123 Could you please take a look at the travis output?

@thk123
Copy link
Contributor

thk123 commented Jan 23, 2017

@tautschnig You seem to be based off a commit that is before the script that just checks the modified lines, if you rebase I imagine they will go away (or at least the only ones left should be legitimate errors). It should also fix the python crash at the end.

@kroening kroening merged commit 97e038f into diffblue:master Jan 23, 2017
@tautschnig tautschnig deleted the operandst-list-support branch January 25, 2017 13:29
smowton added a commit to smowton/cbmc that referenced this pull request May 9, 2018
zlfben pushed a commit to zlfben/cbmc that referenced this pull request May 13, 2021
abstraction: put all functions into one namespace/class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants