Skip to content

Commit 0c1e0f4

Browse files
authored
Merge pull request #4584 from peterschrammel/move-xml-interface
Fix, refactor, move xml_interface
2 parents f63c394 + 66cea8e commit 0c1e0f4

File tree

12 files changed

+110
-78
lines changed

12 files changed

+110
-78
lines changed

regression/cbmc/xml-interface1/main.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <assert.h>
2+
3+
void foo(int x)
4+
{
5+
for(int i = 0; i < 5; ++i)
6+
{
7+
if(x)
8+
assert(0);
9+
assert(0);
10+
}
11+
assert(0);
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
--xml-interface
3+
< test.xml
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
Not unwinding loop foo\.0 iteration 3 file main\.c line 5 function foo thread 0
7+
<result property="foo\.assertion\.3" status="SUCCESS"/>
8+
<result property="foo\.assertion\.1" status="FAILURE">
9+
<goto_trace>
10+
VERIFICATION FAILED
11+
--
12+
<result property="foo\.assertion\.2" status=
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<options>
2+
<valueOption actual="main.c"/>
3+
<valueOption name="function" actual="foo"/>
4+
<valueOption name="unwind" actual="3"/>
5+
<valueOption name="property" actual="foo.assertion.1"/>
6+
<valueOption name="property" actual="foo.assertion.3"/>
7+
<flagOption name="trace" actual="on"/>
8+
<flagOption name="show-properties" actual="off"/>
9+
</options>

src/cbmc/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ SRC = c_test_input_generator.cpp \
22
cbmc_languages.cpp \
33
cbmc_main.cpp \
44
cbmc_parse_options.cpp \
5-
xml_interface.cpp \
65
# Empty last line
76

87
OBJ += ../ansi-c/ansi-c$(LIBEXT) \

src/cbmc/cbmc_parse_options.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,18 @@ Author: Daniel Kroening, [email protected]
7979

8080
#include <langapi/mode.h>
8181

82+
#include <xmllang/xml_interface.h>
83+
8284
#include "c_test_input_generator.h"
83-
#include "xml_interface.h"
8485

8586
cbmc_parse_optionst::cbmc_parse_optionst(int argc, const char **argv)
8687
: parse_options_baset(
8788
CBMC_OPTIONS,
8889
argc,
8990
argv,
90-
std::string("CBMC ") + CBMC_VERSION),
91-
xml_interfacet(cmdline)
91+
std::string("CBMC ") + CBMC_VERSION)
9292
{
93+
xml_interface(cmdline, ui_message_handler);
9394
}
9495

9596
::cbmc_parse_optionst::cbmc_parse_optionst(
@@ -100,9 +101,9 @@ ::cbmc_parse_optionst::cbmc_parse_optionst(
100101
CBMC_OPTIONS + extra_options,
101102
argc,
102103
argv,
103-
std::string("CBMC ") + CBMC_VERSION),
104-
xml_interfacet(cmdline)
104+
std::string("CBMC ") + CBMC_VERSION)
105105
{
106+
xml_interface(cmdline, ui_message_handler);
106107
}
107108

108109
void cbmc_parse_optionst::set_default_options(optionst &options)

src/cbmc/cbmc_parse_options.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ Author: Daniel Kroening, [email protected]
3131

3232
#include <solvers/strings/string_refinement.h>
3333

34-
#include "xml_interface.h"
35-
3634
class goto_functionst;
3735
class optionst;
3836

@@ -82,7 +80,7 @@ class optionst;
8280
"(claim):(show-claims)(floatbv)(all-claims)(all-properties)" // legacy, and will eventually disappear // NOLINT(whitespace/line_length)
8381
// clang-format on
8482

85-
class cbmc_parse_optionst : public parse_options_baset, public xml_interfacet
83+
class cbmc_parse_optionst : public parse_options_baset
8684
{
8785
public:
8886
virtual int doit() override;

src/cbmc/xml_interface.h

Lines changed: 0 additions & 32 deletions
This file was deleted.

src/util/ui_message.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,17 @@ ui_message_handlert::ui_message_handlert(
6565
const std::string &program)
6666
: ui_message_handlert(
6767
nullptr,
68-
cmdline.isset("xml-ui") ? uit::XML_UI : cmdline.isset("json-ui")
69-
? uit::JSON_UI
70-
: uit::PLAIN,
68+
cmdline.isset("xml-ui") || cmdline.isset("xml-interface")
69+
? uit::XML_UI
70+
: cmdline.isset("json-ui") ? uit::JSON_UI : uit::PLAIN,
7171
program,
7272
cmdline.isset("flush"),
73-
cmdline.isset("timestamp")
74-
? cmdline.get_value("timestamp") == "monotonic"
75-
? timestampert::clockt::MONOTONIC
76-
: cmdline.get_value("timestamp") == "wall"
77-
? timestampert::clockt::WALL_CLOCK
78-
: timestampert::clockt::NONE
79-
: timestampert::clockt::NONE)
73+
cmdline.isset("timestamp") ? cmdline.get_value("timestamp") == "monotonic"
74+
? timestampert::clockt::MONOTONIC
75+
: cmdline.get_value("timestamp") == "wall"
76+
? timestampert::clockt::WALL_CLOCK
77+
: timestampert::clockt::NONE
78+
: timestampert::clockt::NONE)
8079
{
8180
if(get_ui() == uit::PLAIN)
8281
{

src/xmllang/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
SRC = graphml.cpp \
2+
xml_interface.cpp \
23
xml_lex.yy.cpp \
34
xml_parse_tree.cpp \
45
xml_parser.cpp \

src/cbmc/xml_interface.cpp renamed to src/xmllang/xml_interface.cpp

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,52 +13,52 @@ 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
{
4326
// recursive call
4427
get_xml_options(e, cmdline);
4528
}
4629

47-
if(xml.name=="valueOption")
30+
if(xml.name == "valueOption")
4831
{
49-
std::string name=xml.get_attribute("name");
50-
std::string value=xml.get_attribute("actual");
32+
std::string name = xml.get_attribute("name");
33+
std::string value = xml.get_attribute("actual");
5134

52-
if(name=="")
35+
if(name == "")
5336
cmdline.args.push_back(value);
5437
else
5538
cmdline.set(name, value);
5639
}
57-
else if(xml.name=="flagOption")
40+
else if(xml.name == "flagOption")
5841
{
59-
if(xml.get_attribute("actual")=="on")
42+
if(xml.get_attribute("actual") == "on")
6043
{
6144
cmdline.set(xml.get_attribute("name"));
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: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*******************************************************************\
2+
3+
Module: XML Interface
4+
5+
Author: Daniel Kroening, [email protected]
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// XML Interface
11+
12+
#ifndef CPROVER_XMLLANG_XML_INTERFACE_H
13+
#define CPROVER_XMLLANG_XML_INTERFACE_H
14+
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 &);
33+
34+
#endif // CPROVER_XMLLANG_XML_INTERFACE_H

unit/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ testing-utils-clean:
102102
BMC_DEPS =../src/cbmc/c_test_input_generator$(OBJEXT) \
103103
../src/cbmc/cbmc_languages$(OBJEXT) \
104104
../src/cbmc/cbmc_parse_options$(OBJEXT) \
105-
../src/cbmc/xml_interface$(OBJEXT) \
106105
../src/goto-instrument/source_lines$(OBJEXT) \
107106
../src/goto-instrument/cover$(OBJEXT) \
108107
../src/goto-instrument/cover_basic_blocks$(OBJEXT) \

0 commit comments

Comments
 (0)