CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
xml_interface.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: XML Interface
4
5Author: Daniel Kroening, kroening@kroening.com
6
7\*******************************************************************/
8
11
12#include "xml_interface.h"
13
14#include <iostream>
15
16#include <util/cmdline.h>
18#include <util/message.h>
19
20#include <xmllang/xml_parser.h>
21
23static void get_xml_options(const xmlt &xml, cmdlinet &cmdline)
24{
25 for(const auto &e : xml.elements)
26 {
27 // recursive call
28 get_xml_options(e, cmdline);
29 }
30
31 if(xml.name == "valueOption")
32 {
33 std::string name = xml.get_attribute("name");
34 std::string value = xml.get_attribute("actual");
35
36 if(name.empty())
37 cmdline.args.push_back(value);
38 else
39 cmdline.set(name, value);
40 }
41 else if(xml.name == "flagOption")
42 {
43 cmdline.set(xml.get_attribute("name"), xml.get_attribute("actual") == "on");
44 }
45}
46
47void xml_interface(cmdlinet &cmdline, message_handlert &message_handler)
48{
49 if(cmdline.isset("xml-interface"))
50 {
51 xmlt xml;
52
53 parse_xml(std::cin, "", message_handler, xml);
54
55 // We have to catch here because command line options are
56 // parsed in the constructor of parse_optionst and not in main()
57 try
58 {
59 get_xml_options(xml, cmdline);
60
61 // Add this so that it gets propagated into optionst;
62 // the ui_message_handlert::uit has already been set on the basis
63 // of the xml-interface flag.
64 cmdline.set("xml-ui");
65 }
67 {
68 messaget log(message_handler);
69 log.error() << e.what() << messaget::eom;
70
71 // make sure we fail with a usage error
72 cmdline.clear();
73 }
74 }
75}
virtual bool isset(char option) const
Definition cmdline.cpp:30
argst args
Definition cmdline.h:154
virtual void set(const std::string &option, bool value=true)
Set option option to value, or true if the value is omitted.
Definition cmdline.cpp:63
virtual void clear()
Definition cmdline.cpp:24
Thrown when users pass incorrect command line arguments, for example passing no files to analysis or ...
std::string what() const override
A human readable description of what went wrong.
Class that provides messages with a built-in verbosity 'level'.
Definition message.h:154
static eomt eom
Definition message.h:289
Definition xml.h:21
std::string get_attribute(const std::string &attribute) const
Definition xml.h:63
elementst elements
Definition xml.h:42
std::string name
Definition xml.h:39
double log(double x)
Definition math.c:2449
xmlt xml(const irep_idt &property_id, const property_infot &property_info)
void xml_interface(cmdlinet &cmdline, message_handlert &message_handler)
Parse XML-formatted commandline options from stdin.
static void get_xml_options(const xmlt &xml, cmdlinet &cmdline)
Parse commandline options from xml into cmdline.
XML Interface.
bool parse_xml(std::istream &in, const std::string &filename, message_handlert &message_handler, xmlt &dest)