Skip to content

Refactoring of the parsing of the --object-bits command line argument #5447

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

Conversation

thomasspriggs
Copy link
Contributor

As I was working on #5440, I found the entry point code less than straight forward to follow. I carried out this refactorings locally in order to make it easier for me to understand. I am raising this separate PR containing the refactoring work only as it was not required in order to implement the feature in the original PR, but should still improve maintainability.

  • Each commit message has a non-empty body, explaining why the change was made.
  • Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • N/A - No user visible changes The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • N/A - non claimed - My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • White-space or formatting changes outside the feature-related changed lines are in commits of their own.

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks OK to me

@@ -776,8 +776,8 @@ configt::bv_encodingt parse_object_bits_encoding(
const std::string &argument,
const std::size_t pointer_width)
{
const unsigned int object_bits = unsafe_string2unsigned(argument);
if(object_bits <= 0 || object_bits >= pointer_width)

Choose a reason for hiding this comment

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

⛏️ Would be better if the case where parsing fails and the object_bits are out of range were separated, also it would be helpful for debugging to put argument in the error message (this makes it easier to find if for example you've messed up a command line when copy&pasting, e.g. --object-bits --function hello world 8)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks OK to me

Copy link
Contributor

@smowton smowton left a comment

Choose a reason for hiding this comment

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

Couple of simple fixes otherwise lgtm

^EXIT=1$
^SIGNAL=0$
--
Test parsing of an invalid non numeric object-bits setting.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a must-not-match, not a comment (similarly others)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

const std::size_t pointer_width)
{
const auto object_bits = string2optional<unsigned int>(argument);
if(!object_bits || *object_bits <= 0 || *object_bits >= pointer_width)
Copy link
Contributor

Choose a reason for hiding this comment

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

Note <= 0 on an unsigned type

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have swapped this to use == 0, as this should be less misleading.

In order to ensure that this functionality is not broken by subsequent
refactorings.
So that `bv_encodingt` can be more used without the need to explicitly
initialise its members.
So the length of `configt::set` can be marginally reduced. So that this
functionality can be documented. This would also support unit testing
of this parsing if unit tests are added later.
So that direct usage of this function can be more succinct.
The previous use of `unsafe_string2unsigned` handled non numeric input
based on the behaviour of 0 being returned by `unsafe_string2unsigned`,
which is then caught by the subsequent range check. It was well defined
behaviour of `std::strtoul`. However this was only discoverable, based
on looking at the implementation of `unsafe_string2unsigned` and reading
the documentation of `std::strtoul` or by using a debugger. The explict
check in the refactored version makes the handling of this case clear
from reading `parse_object_bits_encoding` only, without reference to
other code or documentation.
It is easier to debug your invocation of a command line tool if the
specific invalid argument and the reason why it is invalid is given.
`object_bits <= 0` suggests that `object_bits` could be below zero. This
is not possible because `object_bits` is unsigned. Checking for equal to
zero makes it explicit that we are checking for one specific value.
@thomasspriggs thomasspriggs force-pushed the tas/object_bits_parsing_refactor branch from dd4dac9 to 8efa7cc Compare August 11, 2020 13:07
@codecov
Copy link

codecov bot commented Aug 11, 2020

Codecov Report

Merging #5447 into develop will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #5447   +/-   ##
========================================
  Coverage    68.22%   68.22%           
========================================
  Files         1178     1178           
  Lines        97580    97579    -1     
========================================
+ Hits         66573    66575    +2     
+ Misses       31007    31004    -3     
Flag Coverage Δ
#cproversmt2 42.80% <100.00%> (+<0.01%) ⬆️
#regression 65.39% <100.00%> (+<0.01%) ⬆️
#unit 32.26% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/util/config.h 75.00% <ø> (+2.27%) ⬆️
src/util/string2int.h 100.00% <ø> (ø)
src/util/config.cpp 57.19% <100.00%> (+0.37%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update af5bc99...8efa7cc. Read the comment docs.

@thomasspriggs thomasspriggs merged commit 7d8a6f7 into diffblue:develop Aug 11, 2020
@thomasspriggs thomasspriggs deleted the tas/object_bits_parsing_refactor branch August 11, 2020 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants