Skip to content

Commit

Permalink
(Support) Moved some command-line parsing functions
Browse files Browse the repository at this point in the history
API-Breaking change

* The high-level command-line parsing functions intended for ROSE
  tools have been moved out of ::CommandlineProcessing and into
  ::Rose::CommandLine.

* This moves those functions out of libroseutil and into librose.

* This allows those functions to call other functions in librose
  in order validate command-lines, provide suggestions, and
  generate documentation.

To fix your code:

1) #include <CommandLine.h> // a ROSE header file

2) Change "CommandlineProcessing" to "Rose::CommandLine", but
   only for those few things that have been moved. They are:

    createEmptyParser
    createEmptyParserStage
    genericSwitches
    genericSwitchArgs
    insertBooleanSwitch
  • Loading branch information
matzke1 committed Jan 12, 2018
1 parent 3896564 commit 0f6f409
Show file tree
Hide file tree
Showing 58 changed files with 421 additions and 336 deletions.
3 changes: 2 additions & 1 deletion projects/BinFuncDetect/compareResults.C
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <AsmUnparser.h>
#include <cstring>
#include <CommandLine.h>
#include <Diagnostics.h>
#include <FileSystem.h>
#include <iostream>
Expand Down Expand Up @@ -38,7 +39,7 @@ parseCommandLine(int argc, char *argv[], Settings &settings) {
.purpose("compares disassembler results")
.version(std::string(ROSE_SCM_VERSION_ID).substr(0, 8), ROSE_CONFIGURE_DATE)
.chapter(1, "ROSE Command-line Tools")
.with(CommandlineProcessing::genericSwitches())
.with(Rose::CommandLine::genericSwitches())
.doc("synopsis",
"@prop{programName} [@v{switches}] @v{csv1} @v{csv2}")
.doc("description",
Expand Down
3 changes: 2 additions & 1 deletion projects/BinaryAnalysisTools/PathFinder/findPath.C
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <boost/thread/locks.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>
#include <CommandLine.h>
#include <Diagnostics.h>
#include <DwarfLineMapper.h>
#include <Partitioner2/CfgPath.h>
Expand Down Expand Up @@ -598,7 +599,7 @@ buildVirtualCpu(const P2::Partitioner &partitioner) {
}
}

SmtSolver *solver = SmtSolver::instance(CommandlineProcessing::genericSwitchArgs.smtSolver);
SmtSolver *solver = SmtSolver::instance(Rose::CommandLine::genericSwitchArgs.smtSolver);
RiscOperatorsPtr ops = RiscOperators::instance(&partitioner, myRegs, solver);

return partitioner.instructionProvider().dispatcher()->create(ops);
Expand Down
3 changes: 2 additions & 1 deletion projects/BinaryAnalysisTools/bROwSE/Application.C
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <bROwSE/WSplash.h>
#include <bROwSE/WStatus.h>
#include <bROwSE/WStrings.h>
#include <CommandLine.h> // ROSE
#include <Disassembler.h> // ROSE
#include <Partitioner2/Engine.h> // ROSE
#include <Partitioner2/Modules.h> // ROSE
Expand Down Expand Up @@ -52,7 +53,7 @@ Application::parseCommandLine(int argc, char *argv[], Settings &settings)
using namespace Sawyer::CommandLine;

// Generic switches
SwitchGroup gen = CommandlineProcessing::genericSwitches();
SwitchGroup gen = Rose::CommandLine::genericSwitches();
gen.insert(Switch("config")
.argument("names", listParser(anyParser(settings.configurationNames), ":"))
.whichValue(SAVE_ALL)
Expand Down
3 changes: 2 additions & 1 deletion projects/BinaryAnalysisTools/debugSemantics.C
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <BinaryNoOperation.h>
#include <BinaryYicesSolver.h>
#include <BinaryZ3Solver.h>
#include <CommandLine.h>
#include <ConcreteSemantics2.h>
#include <Diagnostics.h>
#include <Disassembler.h>
Expand Down Expand Up @@ -249,7 +250,7 @@ parseCommandLine(int argc, char *argv[], P2::Engine &engine, Settings &settings)

static SmtSolver *
makeSolver(const Settings &settings) {
return SmtSolver::instance(CommandlineProcessing::genericSwitchArgs.smtSolver);
return SmtSolver::instance(Rose::CommandLine::genericSwitchArgs.smtSolver);
}

static BaseSemantics::SValuePtr
Expand Down
5 changes: 3 additions & 2 deletions projects/BinaryAnalysisTools/findSimilarFunctions.C
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <rose.h>

#include <CommandLine.h>
#include <Disassembler.h>
#include <EditDistance/TreeEditDistance.h>
#include <EditDistance/LinearEditDistance.h>
Expand Down Expand Up @@ -418,9 +419,9 @@ main(int argc, char *argv[]) {
// Parse command-line
P2::Engine engine;
Settings settings;
CommandlineProcessing::genericSwitchArgs.threads = 0; // we want multi-threading by default
Rose::CommandLine::genericSwitchArgs.threads = 0; // we want multi-threading by default
std::vector<std::string> positionalArgs = parseCommandLine(argc, argv, engine, settings);
size_t nThreads = CommandlineProcessing::genericSwitchArgs.threads;
size_t nThreads = Rose::CommandLine::genericSwitchArgs.threads;
if (0 == nThreads)
nThreads = boost::thread::hardware_concurrency();

Expand Down
3 changes: 2 additions & 1 deletion projects/BinaryAnalysisTools/generatePaths.C
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <rose.h>

#include <CommandLine.h> // ROSE
#include "integerOps.h"

#include <iostream>
Expand Down Expand Up @@ -28,7 +29,7 @@ parseCommandLine(int argc, char *argv[], Settings &settings) {
"Generates a program, written in C, on standard output, that has a certain structure specified by the "
"command-line switches described here.");

SwitchGroup gen = CommandlineProcessing::genericSwitches();
SwitchGroup gen = Rose::CommandLine::genericSwitches();
gen.insert(Switch("tree-depth", 't')
.argument("n", nonNegativeIntegerParser(settings.binaryTreeDepth))
.doc("Width in bits of the 'if' tree."));
Expand Down
3 changes: 2 additions & 1 deletion projects/BinaryAnalysisTools/maxBijection.C
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "rose.h"
#include "rose_getline.h"
#include "rose_strtoull.h"
#include <CommandLine.h> // ROSE
#include "Diagnostics.h"
#include "integerOps.h"
#include <Sawyer/CommandLine.h>
Expand All @@ -21,7 +22,7 @@ struct Settings {
static Sawyer::CommandLine::ParserResult
parseCommandLine(int argc, char *argv[], Settings &settings) {
using namespace Sawyer::CommandLine;
SwitchGroup generic = CommandlineProcessing::genericSwitches();
SwitchGroup generic = Rose::CommandLine::genericSwitches();

SwitchGroup tool("Tool-specific switches");
tool.insert(Switch("width")
Expand Down
3 changes: 2 additions & 1 deletion projects/BinaryAnalysisTools/symbolicSimplifier.C
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <rose.h>
#include <rosePublicConfig.h>
#include <CommandLine.h>
#include <Sawyer/CommandLine.h>
#include <BinarySymbolicExprParser.h>

Expand Down Expand Up @@ -52,7 +53,7 @@ parseCommandLine(int argc, char *argv[], bool &testSerialization /*in,out*/) {
"Parses symbolic expressions from standard input and prints the resulting expression trees. These trees "
"undergo basic simplifications in ROSE before they're printed.")
.doc("Symbolic expression syntax", symbolicParser().docString())
.with(CommandlineProcessing::genericSwitches())
.with(Rose::CommandLine::genericSwitches())
.with(tool);

if (!parser.parse(argc, argv).apply().unreachedArgs().empty())
Expand Down
7 changes: 4 additions & 3 deletions projects/BinaryAnalysisTools/xml2json.C
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ static const char *description =
"by the ROSE binary analysis state serialization.";

#include <rose.h> // Must be first ROSE include file
#include <CommandLine.h>
#include <Diagnostics.h> // ROSE

#include <boost/algorithm/string/classification.hpp>
Expand Down Expand Up @@ -39,15 +40,15 @@ parseCommandLine(int argc, char *argv[]) {
using namespace Sawyer::CommandLine;
Settings retval;

Parser p = /*Rose*/::CommandlineProcessing::createEmptyParser(purpose, description);
p.with(/*Rose*/::CommandlineProcessing::genericSwitches());
Parser p = Rose::CommandLine::createEmptyParser(purpose, description);
p.with(Rose::CommandLine::genericSwitches());
p.doc("Synopsis", "@prop{programName} [@v{switches}] @v{xml_input_file} @v{json_output_file}");
p.errorStream(mlog[FATAL]);
SwitchGroup tool("Tool-specific switches");
tool.name("tool");

#ifdef XML2JSON_SUPPORT_CHECK
/*Rose*/::CommandlineProcessing::insertBooleanSwitch(tool, "check", retval.check, "Perform extra input checking.");
Rose::CommandLine::insertBooleanSwitch(tool, "check", retval.check, "Perform extra input checking.");
#endif

tool.insert(Switch("delete")
Expand Down
3 changes: 2 additions & 1 deletion projects/BinaryCloneDetection/semantic/runRandom.C
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <BinaryDebugger.h>
#include <Combinatorics.h>
#include <CommandLine.h>
#include <Partitioner2/Engine.h>
#include <rose_strtoull.h>

Expand Down Expand Up @@ -51,7 +52,7 @@ parseCommandLine(int argc, char *argv[], Settings &settings)
using namespace Sawyer::CommandLine;

// Generic switches
SwitchGroup gen = CommandlineProcessing::genericSwitches();
SwitchGroup gen = Rose::CommandLine::genericSwitches();

// Switches for this tool
SwitchGroup tool("Tool-specific switches");
Expand Down
3 changes: 2 additions & 1 deletion projects/EditDistanceMetric/astDiff.C
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// the integer order of visit).

#include <rose.h>
#include <CommandLine.h>
#include <EditDistance/TreeEditDistance.h>
#include <Sawyer/CommandLine.h>
#include <Sawyer/Stopwatch.h>
Expand All @@ -29,7 +30,7 @@ using namespace Rose;
Sawyer::CommandLine::ParserResult
parseCommandLine(int argc, char *argv[], Settings &settings) {
using namespace Sawyer::CommandLine;
SwitchGroup gen = CommandlineProcessing::genericSwitches();
SwitchGroup gen = Rose::CommandLine::genericSwitches();
SwitchGroup tool = toolCommandLineSwitches(settings);

Parser parser;
Expand Down
3 changes: 2 additions & 1 deletion projects/MatrixTesting/matrixAttachments.C
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <rose.h>

#include <boost/foreach.hpp>
#include <CommandLine.h> // from ROSE
#include <FileSystem.h> // from ROSE
#include <Sawyer/CommandLine.h>
#include <Sawyer/Message.h>
Expand Down Expand Up @@ -74,7 +75,7 @@ parseCommandLine(int argc, char *argv[], Settings &settings) {
"like normal, but the final COMMIT is skipped, causing the database to roll back to its initial "
"state."));

return parser.with(CommandlineProcessing::genericSwitches()).with(sg).parse(argc, argv).apply().unreachedArgs();
return parser.with(Rose::CommandLine::genericSwitches()).with(sg).parse(argc, argv).apply().unreachedArgs();
}

static bool
Expand Down
3 changes: 2 additions & 1 deletion projects/MatrixTesting/matrixDeleteTest.C
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <boost/foreach.hpp>
#include <boost/lexical_cast.hpp>
#include <CommandLine.h>
#include <Sawyer/CommandLine.h>
#include <Sawyer/Message.h>
#include <SqlDatabase.h>
Expand Down Expand Up @@ -46,7 +47,7 @@ parseCommandLine(int argc, char *argv[], Settings &settings) {
.argument("uri", anyParser(settings.databaseUri))
.doc("Uniform resource locator for the database." + SqlDatabase::uriDocumentation()));

return parser.with(CommandlineProcessing::genericSwitches()).with(sg).parse(argc, argv).apply().unreachedArgs();
return parser.with(Rose::CommandLine::genericSwitches()).with(sg).parse(argc, argv).apply().unreachedArgs();
}

int
Expand Down
3 changes: 2 additions & 1 deletion projects/MatrixTesting/matrixErrors.C
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/trim.hpp>
#include <boost/foreach.hpp>
#include <CommandLine.h>
#include <Sawyer/CommandLine.h>
#include <Sawyer/Message.h>
#include <SqlDatabase.h>
Expand Down Expand Up @@ -77,7 +78,7 @@ parseCommandLine(int argc, char *argv[], Settings &settings) {
.intrinsicValue(true, settings.latestTests)
.doc("Operate on only the latest version of ROSE in the database."));

return parser.with(CommandlineProcessing::genericSwitches()).with(sg).parse(argc, argv).apply().unreachedArgs();
return parser.with(Rose::CommandLine::genericSwitches()).with(sg).parse(argc, argv).apply().unreachedArgs();
}

// Render Unix time as a string when printing a database table
Expand Down
3 changes: 2 additions & 1 deletion projects/MatrixTesting/matrixNextTest.C
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <boost/algorithm/string/join.hpp>
#include <boost/foreach.hpp>
#include <boost/regex.hpp>
#include <CommandLine.h>
#include <cstring>
#include <LinearCongruentialGenerator.h>
#include <Sawyer/CommandLine.h>
Expand Down Expand Up @@ -64,7 +65,7 @@ parseCommandLine(int argc, char *argv[], Settings &settings) {
" @named{shell}{Output one line of space-separated key=value pairs.}"
" @named{overrides}{Output entire configuration space as shell OVERRIDE variables.}"));

if (!parser.with(CommandlineProcessing::genericSwitches()).with(sg).parse(argc, argv).apply().unreachedArgs().empty()) {
if (!parser.with(Rose::CommandLine::genericSwitches()).with(sg).parse(argc, argv).apply().unreachedArgs().empty()) {
mlog[FATAL] <<"invalid usage; see --help\n";
exit(1);
}
Expand Down
3 changes: 2 additions & 1 deletion projects/MatrixTesting/matrixQueryTable.C
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <boost/algorithm/string/trim.hpp>
#include <boost/foreach.hpp>
#include <CommandLine.h>
#include <Sawyer/CommandLine.h>
#include <Sawyer/Map.h>
#include <Sawyer/Message.h>
Expand Down Expand Up @@ -49,7 +50,7 @@ parseCommandLine(int argc, char *argv[], Settings &settings) {
.argument("uri", anyParser(settings.databaseUri))
.doc("URI specifying which database to use." + SqlDatabase::uriDocumentation()));

return parser.with(CommandlineProcessing::genericSwitches()).with(sg).parse(argc, argv).apply().unreachedArgs();
return parser.with(Rose::CommandLine::genericSwitches()).with(sg).parse(argc, argv).apply().unreachedArgs();
}

typedef Sawyer::Container::Map<std::string /*key*/, std::string /*colname*/> DependencyNames;
Expand Down
3 changes: 2 additions & 1 deletion projects/MatrixTesting/matrixTestResult.C
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <boost/algorithm/string/trim.hpp>
#include <boost/foreach.hpp>
#include <CommandLine.h>
#include <cstdio>
#include <cstring>
#include <LinearCongruentialGenerator.h>
Expand Down Expand Up @@ -70,7 +71,7 @@ parseCommandLine(int argc, char *argv[], Settings &settings) {
"like normal, but the final COMMIT is skipped, causing the database to roll back to its initial "
"state."));

return parser.with(CommandlineProcessing::genericSwitches()).with(sg).parse(argc, argv).apply().unreachedArgs();
return parser.with(Rose::CommandLine::genericSwitches()).with(sg).parse(argc, argv).apply().unreachedArgs();
}

typedef Sawyer::Container::Map<std::string /*key*/, std::string /*colname*/> DependencyNames;
Expand Down
3 changes: 2 additions & 1 deletion projects/SnippetTools/roseDiff.C
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <rose.h>
#include <CommandLine.h>
#include <FileSystem.h>

#include <Sawyer/CommandLine.h>
Expand Down Expand Up @@ -26,7 +27,7 @@ parseCommandLine(int argc, char *argv[], Settings &settings /*in,out*/) {
.doc("description",
"Scans the two specified directories and creates a recursive, unified diff of the ROSE-generated files "
"in those directories.")
.with(CommandlineProcessing::genericSwitches());
.with(Rose::CommandLine::genericSwitches());

return parser.parse(argc, argv).apply();
}
Expand Down
3 changes: 2 additions & 1 deletion projects/SnippetTools/rosePatch.C
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <rose.h>

#include <CommandLine.h>
#include <FileSystem.h>
#include <Sawyer/CommandLine.h>
#include <Sawyer/Message.h>
Expand All @@ -25,7 +26,7 @@ parseCommandLine(int argc, char *argv[], Settings &settings /*in,out*/) {
.purpose("applies ROSE patches on the fly")
.version(std::string(ROSE_SCM_VERSION_ID).substr(0, 8), ROSE_CONFIGURE_DATE)
.chapter(1, "ROSE Command-line Tools")
.with(CommandlineProcessing::genericSwitches())
.with(Rose::CommandLine::genericSwitches())
.doc("Synopsis",
"@prop{programName} --identity=@v{directory} --translated=@v{directory} --top=@v{directory} "
"-- @v{compiler_arguments}")
Expand Down
4 changes: 2 additions & 2 deletions projects/autoParallelization/autoPar.C
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,12 @@ Sawyer::CommandLine::SwitchGroup commandLineSwitches() {
static std::vector<std::string> commandline_processing(std::vector< std::string > & argvList)
{
using namespace Sawyer::CommandLine;
Parser p = CommandlineProcessing::createEmptyParserStage(purpose, description);
Parser p = Rose::CommandLine::createEmptyParserStage(purpose, description);
p.doc("Synopsis", "@prop{programName} @v{switches} @v{files}...");
p.longPrefix("-");

// initialize generic Sawyer switches: assertion, logging, threads, etc.
p.with(CommandlineProcessing::genericSwitches());
p.with(Rose::CommandLine::genericSwitches());

// initialize this tool's switches
p.with(commandLineSwitches());
Expand Down
3 changes: 2 additions & 1 deletion projects/simulator2/demos/ports_opened.C
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// The following stuff is mostly cut-n-pasted from x86sim.C with minor modifications to the documentation.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#include <CommandLine.h> // ROSE command-line
#include <Diagnostics.h> // ROSE diagnostics
#include <RSIM_Debugger.h> // Simulator interactive debugger
#include <RSIM_Linux32.h> // Simulator architecture: Linux-x86
Expand Down Expand Up @@ -148,7 +149,7 @@ parseCommandLine(int argc, char *argv[], Settings &settings) {

return parser
.errorStream(::mlog[FATAL])
.with(CommandlineProcessing::genericSwitches())
.with(Rose::CommandLine::genericSwitches())
.with(sg) // tool-specific
.with(RSIM_Simulator::commandLineSwitches(settings.simSettings))
.parse(argc, argv).apply().unreachedArgs();
Expand Down
3 changes: 2 additions & 1 deletion projects/simulator2/x86sim.C
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <RSIM_Private.h>
#ifdef ROSE_ENABLE_SIMULATOR /* protects this whole file */

#include <CommandLine.h> // ROSE command-line
#include <RSIM_Debugger.h> // Interactive debugger for the simulator
#include <RSIM_ColdFire.h> // FreeScale ColdFire/m68k naked hardware simulator
#include <RSIM_Linux32.h> // Operating system simulation for Linux-x86
Expand Down Expand Up @@ -151,7 +152,7 @@ parseCommandLine(int argc, char *argv[], Settings &settings) {

return parser
.errorStream(::mlog[FATAL])
.with(CommandlineProcessing::genericSwitches())
.with(Rose::CommandLine::genericSwitches())
.with(sg) // tool-specific
.with(RSIM_Simulator::commandLineSwitches(settings.simSettings))
.parse(argc, argv).apply().unreachedArgs();
Expand Down
1 change: 1 addition & 0 deletions src/ROSETTA/Grammar/Node.code
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ HEADER_NODE_PREDECLARATION_START
#include <boost/serialization/vector.hpp>
#include <boost/unordered_map.hpp>
#include <boost/unordered_set.hpp>
#include <Sawyer/CommandLine.h>
#include <Sawyer/Interval.h>
#include <Sawyer/IntervalSet.h>

Expand Down
Loading

0 comments on commit 0f6f409

Please sign in to comment.