Skip to content

Commit a47b0a9

Browse files
author
Daniel Kroening
authored
Merge pull request #115 from peterschrammel/json-output
Show goto functions
2 parents 694b8cf + 9d56d4f commit a47b0a9

File tree

3 files changed

+133
-1
lines changed

3 files changed

+133
-1
lines changed

src/cbmc/cbmc_parse_options.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Author: Daniel Kroening, [email protected]
3838
#include <goto-programs/loop_ids.h>
3939
#include <goto-programs/link_to_library.h>
4040
#include <goto-programs/remove_skip.h>
41+
#include <goto-programs/show_goto_functions.h>
4142

4243
#include <goto-instrument/full_slicer.h>
4344
#include <goto-instrument/nondet_static.h>
@@ -965,7 +966,7 @@ bool cbmc_parse_optionst::process_goto_program(
965966
if(cmdline.isset("show-goto-functions"))
966967
{
967968
namespacet ns(symbol_table);
968-
goto_functions.output(ns, std::cout);
969+
show_goto_functions(ns, get_ui(), goto_functions);
969970
return true;
970971
}
971972
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*******************************************************************\
2+
3+
Module: Show goto functions
4+
5+
Author: Peter Schrammel
6+
7+
\*******************************************************************/
8+
9+
#include <iostream>
10+
11+
#include <util/xml.h>
12+
#include <util/json.h>
13+
#include <util/i2string.h>
14+
#include <util/xml_expr.h>
15+
16+
#include <langapi/language_util.h>
17+
18+
#include "show_goto_functions.h"
19+
#include "goto_functions.h"
20+
#include "goto_model.h"
21+
22+
/*******************************************************************\
23+
24+
Function: cbmc_parseoptionst::show_goto_functions
25+
26+
Inputs:
27+
28+
Outputs:
29+
30+
Purpose:
31+
32+
\*******************************************************************/
33+
34+
void show_goto_functions(
35+
const namespacet &ns,
36+
ui_message_handlert::uit ui,
37+
const goto_functionst &goto_functions)
38+
{
39+
switch(ui)
40+
{
41+
case ui_message_handlert::XML_UI:
42+
{
43+
//This only prints the list of functions
44+
xmlt xml_functions("functions");
45+
for(goto_functionst::function_mapt::const_iterator
46+
it=goto_functions.function_map.begin();
47+
it!=goto_functions.function_map.end();
48+
it++)
49+
{
50+
xmlt &xml_function=xml_functions.new_element("function");
51+
xml_function.set_attribute("name", id2string(it->first));
52+
}
53+
54+
std::cout << xml_functions << std::endl;
55+
}
56+
break;
57+
58+
case ui_message_handlert::JSON_UI:
59+
{
60+
//This only prints the list of functions
61+
json_arrayt json_functions;
62+
for(goto_functionst::function_mapt::const_iterator
63+
it=goto_functions.function_map.begin();
64+
it!=goto_functions.function_map.end();
65+
it++)
66+
{
67+
json_objectt &json_function=
68+
json_functions.push_back(jsont()).make_object();
69+
json_function["name"]=json_stringt(id2string(it->first));
70+
}
71+
json_objectt json_result;
72+
json_result["functions"]=json_functions;
73+
std::cout << ",\n" << json_result;
74+
}
75+
break;
76+
77+
case ui_message_handlert::PLAIN:
78+
goto_functions.output(ns, std::cout);
79+
break;
80+
}
81+
}
82+
83+
/*******************************************************************\
84+
85+
Function: show_goto_functions
86+
87+
Inputs:
88+
89+
Outputs:
90+
91+
Purpose:
92+
93+
\*******************************************************************/
94+
95+
void show_goto_functions(
96+
const goto_modelt &goto_model,
97+
ui_message_handlert::uit ui)
98+
{
99+
const namespacet ns(goto_model.symbol_table);
100+
show_goto_functions(ns, ui, goto_model.goto_functions);
101+
}
102+
103+
104+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*******************************************************************\
2+
3+
Module: Show the goto functions
4+
5+
Author: Peter Schrammel
6+
7+
\*******************************************************************/
8+
9+
#ifndef CPROVER_GOTO_PROGRAMS_SHOW_GOTO_FUNCTIONS_H
10+
#define CPROVER_GOTO_PROGRAMS_SHOW_GOTO_FUNCTIONS_H
11+
12+
#include <util/ui_message.h>
13+
14+
class goto_functionst;
15+
class namespacet;
16+
class goto_modelt;
17+
18+
void show_goto_functions(
19+
const namespacet &ns,
20+
ui_message_handlert::uit ui,
21+
const goto_functionst &goto_functions);
22+
23+
void show_goto_functions(
24+
const goto_modelt &,
25+
ui_message_handlert::uit ui);
26+
27+
#endif

0 commit comments

Comments
 (0)