Skip to content

Split up the two parts of cmdlinet::parse into separate functions #5462

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

Conversation

hannes-steffenhagen-diffblue
Copy link
Contributor

cmdlinet::parse first parses the command line specification, and then the command line arguments themselves. This PR splits those two bits up into their own functions (this just moves code around, the only reason the functions look slightly different is because of clang-format).

  • 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.
  • 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).
  • 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.

@codecov
Copy link

codecov bot commented Aug 14, 2020

Codecov Report

Merging #5462 (86baa33) into develop (0f57d77) will increase coverage by 0.00%.
The diff coverage is 97.14%.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #5462   +/-   ##
========================================
  Coverage    69.65%   69.65%           
========================================
  Files         1243     1243           
  Lines       100843   100847    +4     
========================================
+ Hits         70243    70247    +4     
  Misses       30600    30600           
Flag Coverage Δ
cproversmt2 43.39% <88.57%> (+<0.01%) ⬆️
regression 66.56% <97.14%> (+<0.01%) ⬆️
unit 32.21% <82.85%> (+<0.01%) ⬆️

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

Impacted Files Coverage Δ
src/util/cmdline.h 66.66% <ø> (ø)
src/util/cmdline.cpp 93.15% <97.14%> (+0.19%) ⬆️

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 0f57d77...86baa33. Read the comment docs.

@thomasspriggs
Copy link
Contributor

Your commits have empty message bodies. They should really have a rationale for the changes are being made.

Copy link
Contributor

@NlightNFotis NlightNFotis left a comment

Choose a reason for hiding this comment

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

Cool, nice maintenance work 👍

Would also like if we could get docstrings for the functions introduced, but it's a nitpick for me as well - just the cherry on top, really.

@hannes-steffenhagen-diffblue
Copy link
Contributor Author

@thomasspriggs @NlightNFotis I have added a bit of documentation, if you would check if that works for you?

@hannes-steffenhagen-diffblue hannes-steffenhagen-diffblue force-pushed the refactor/split-up-cmdline-parse branch from ba9c516 to 8e9c61b Compare August 18, 2020 09:48
/// string at index argc being a terminating null pointer.
/// This parameter is parsed based on optstring.
/// \param optstring A specification of allowed command line options.
/// This is a C string container any number of single
Copy link
Contributor

Choose a reason for hiding this comment

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

⛏️ container -> containing

Copy link
Collaborator

@tautschnig tautschnig left a comment

Choose a reason for hiding this comment

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

Thank you for cleaning this up and adding extensive documentation. Just a bunch of minor notes.

Comment on lines 212 to 166
}
void cmdlinet::parse_optstring(const char *optstring)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit pick: a blank line would be nice to have.

@@ -20,6 +20,58 @@ Author: Daniel Kroening, [email protected]
class cmdlinet
{
public:
/// Parses a commandline according to a specification given in optstring.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd suggest \p optstring to clarify to an extent what this is referring to.

/// it was invoked (e.g. /usr/bin/cmake) and is ignored. It is
/// further assumed the array holds argc+1 elements with the C
/// string at index argc being a terminating null pointer.
/// This parameter is parsed based on optstring.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Again, \p optstring, and s/parameter/argument/ ("argv" is a parameter, but what gets parsed is the actual argument).

/// \param argv An array of C strings.
/// The 0th element is assumed to be the name of the command as
/// it was invoked (e.g. /usr/bin/cmake) and is ignored. It is
/// further assumed the array holds argc+1 elements with the C
Copy link
Collaborator

Choose a reason for hiding this comment

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

\p argc+1

/// and ')', both of which can be optionally followed by a
/// single ':' indicating that the option takes a parameter,
/// if not present it does not. Parameters must be in the
/// next array element, except for short options whose
Copy link
Collaborator

Choose a reason for hiding this comment

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

next array element in argv

/// surrounded by a matching pair of '(' and ')' signifying a
/// "long" option with the name being the string between '('
/// and ')', both of which can be optionally followed by a
/// single ':' indicating that the option takes a parameter,
Copy link
Collaborator

Choose a reason for hiding this comment

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

In my opinion, all further uses of "parameter" should be replaced by "argument" here.

@tautschnig tautschnig merged commit f4edb72 into diffblue:develop Jan 18, 2021
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