Skip to content

Commit 75a72d7

Browse files
Refactor xml_interface
Turn the constructor-only class into a free function.
1 parent d323552 commit 75a72d7

File tree

3 files changed

+42
-40
lines changed

3 files changed

+42
-40
lines changed

src/cbmc/cbmc_parse_options.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ cbmc_parse_optionst::cbmc_parse_optionst(int argc, const char **argv)
8888
CBMC_OPTIONS,
8989
argc,
9090
argv,
91-
std::string("CBMC ") + CBMC_VERSION),
92-
xml_interfacet(cmdline)
91+
std::string("CBMC ") + CBMC_VERSION)
9392
{
93+
xml_interface(cmdline, ui_message_handler);
9494
}
9595

9696
::cbmc_parse_optionst::cbmc_parse_optionst(
@@ -101,9 +101,9 @@ ::cbmc_parse_optionst::cbmc_parse_optionst(
101101
CBMC_OPTIONS + extra_options,
102102
argc,
103103
argv,
104-
std::string("CBMC ") + CBMC_VERSION),
105-
xml_interfacet(cmdline)
104+
std::string("CBMC ") + CBMC_VERSION)
106105
{
106+
xml_interface(cmdline, ui_message_handler);
107107
}
108108

109109
void cbmc_parse_optionst::set_default_options(optionst &options)

src/xmllang/xml_interface.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,13 @@ Author: Daniel Kroening, [email protected]
1313

1414
#include <iostream>
1515

16+
#include <util/cmdline.h>
1617
#include <util/message.h>
1718

1819
#include <xmllang/xml_parser.h>
1920

20-
/// XML User Interface
21-
void xml_interfacet::get_xml_options(cmdlinet &cmdline)
22-
{
23-
if(cmdline.isset("xml-interface"))
24-
{
25-
null_message_handlert message_handler;
26-
xmlt xml;
27-
28-
parse_xml(std::cin, "", message_handler, xml);
29-
30-
get_xml_options(xml, cmdline);
31-
32-
cmdline.set("xml-ui");
33-
}
34-
}
35-
36-
/// XML User Interface
37-
void xml_interfacet::get_xml_options(
38-
const xmlt &xml,
39-
cmdlinet &cmdline)
21+
/// Parse commandline options from \p xml into \p cmdline
22+
static void get_xml_options(const xmlt &xml, cmdlinet &cmdline)
4023
{
4124
for(const auto &e : xml.elements)
4225
{
@@ -62,3 +45,20 @@ void xml_interfacet::get_xml_options(
6245
}
6346
}
6447
}
48+
49+
void xml_interface(cmdlinet &cmdline, message_handlert &message_handler)
50+
{
51+
if(cmdline.isset("xml-interface"))
52+
{
53+
xmlt xml;
54+
55+
parse_xml(std::cin, "", message_handler, xml);
56+
57+
get_xml_options(xml, cmdline);
58+
59+
// Add this so that it gets propagated into optionst;
60+
// the ui_message_handlert::uit has already been set on the basis
61+
// of the xml-interface flag.
62+
cmdline.set("xml-ui");
63+
}
64+
}

src/xmllang/xml_interface.h

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,23 @@ Author: Daniel Kroening, [email protected]
1212
#ifndef CPROVER_XMLLANG_XML_INTERFACE_H
1313
#define CPROVER_XMLLANG_XML_INTERFACE_H
1414

15-
#include <util/cmdline.h>
16-
17-
class xmlt;
18-
19-
class xml_interfacet
20-
{
21-
public:
22-
explicit xml_interfacet(cmdlinet &_cmdline)
23-
{
24-
get_xml_options(_cmdline);
25-
}
26-
27-
protected:
28-
void get_xml_options(cmdlinet &cmdline);
29-
void get_xml_options(const xmlt &xml, cmdlinet &cmdline);
30-
};
15+
class cmdlinet;
16+
class message_handlert;
17+
18+
/// Parse XML-formatted commandline options from stdin.
19+
///
20+
/// Example:
21+
/// \code{.xml}
22+
/// <options>
23+
/// <valueOption actual="main.c"/>
24+
/// <valueOption name="function" actual="foo"/>
25+
/// <valueOption name="unwind" actual="3"/>
26+
/// <valueOption name="property" actual="foo.assertion.1"/>
27+
/// <valueOption name="property" actual="foo.assertion.3"/>
28+
/// <flagOption name="trace" actual="on"/>
29+
/// <flagOption name="show-properties" actual="off"/>
30+
/// </options>
31+
/// \endcode
32+
void xml_interface(cmdlinet &, message_handlert &);
3133

3234
#endif // CPROVER_XMLLANG_XML_INTERFACE_H

0 commit comments

Comments
 (0)