Skip to content

Commit bdf6a77

Browse files
authored
Merge pull request diffblue#29 from diffblue/smowton/feature/pretty_print_evs
External value set pretty-printer
2 parents ba7d482 + 3e0d04b commit bdf6a77

File tree

4 files changed

+80
-1
lines changed

4 files changed

+80
-1
lines changed

src/driver/sec_driver_parse_options.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ Author: Chris Smowton, [email protected]
5858

5959
#include <taint-analysis/taint_security_scanner.h>
6060

61+
#include <pointer-analysis/evs_pretty_printer.h>
62+
6163
#include "sec_driver_parse_options.h"
6264

6365
#include <fstream>
@@ -193,6 +195,7 @@ int sec_driver_parse_optionst::doit()
193195
<< config.this_operating_system() << eom;
194196

195197
register_languages();
198+
register_evs_pretty_printer();
196199

197200
goto_model.set_message_handler(get_message_handler());
198201

src/pointer-analysis/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
SRC = local_value_set_analysis.cpp local_value_set.cpp
2+
SRC = local_value_set_analysis.cpp local_value_set.cpp evs_pretty_printer.cpp
33

44
INCLUDES= -I .. -I ../../cbmc/src
55

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
2+
#include "evs_pretty_printer.h"
3+
#include <pointer-analysis/external_value_set_expr.h>
4+
#include <langapi/language_util.h>
5+
6+
#include <sstream>
7+
8+
std::string evs_pretty_printert::convert(const exprt &src)
9+
{
10+
if(src.id()==ID_external_value_set)
11+
{
12+
std::ostringstream result;
13+
result << "EXT_VAL_SET(";
14+
bool first=true;
15+
forall_operands(it, src)
16+
{
17+
if(!first)
18+
result << ", ";
19+
else
20+
first=false;
21+
result << top_pretty_printer->convert(*it);
22+
}
23+
result << ")";
24+
if(src.get_bool("modified"))
25+
result << "<maybe-modified>";
26+
result << " ["
27+
<< top_pretty_printer->convert(src.type())
28+
<< ']';
29+
return result.str();
30+
}
31+
else if(src.id()==ID_access_path_entry)
32+
{
33+
std::ostringstream result;
34+
result << "{ " << src.get(ID_access_path_label) << ", " <<
35+
src.get(ID_access_path_function) << ", " <<
36+
src.get(ID_access_path_loc);
37+
const auto &decl_type=to_access_path_entry(src).declared_on_type();
38+
if(decl_type.id()==ID_struct)
39+
result << " (decl-on-type " << to_struct_type(decl_type).get_tag() << ") }";
40+
return result.str();
41+
}
42+
43+
return baset::convert(src);
44+
}
45+
46+
void register_evs_pretty_printer()
47+
{
48+
register_global_pretty_printer(
49+
[](const namespacet &ns)
50+
{
51+
return std::unique_ptr<pretty_printert>(new evs_pretty_printert(ns));
52+
}
53+
);
54+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef SECURITY_SCANNER_POINTER_ANALYSIS_EVS_PRETTY_PRINTER
2+
#define SECURITY_SCANNER_POINTER_ANALYSIS_EVS_PRETTY_PRINTER
3+
4+
#include <langapi/pretty_printer.h>
5+
#include <util/namespace.h>
6+
7+
class evs_pretty_printert:public pretty_printert
8+
{
9+
public:
10+
evs_pretty_printert(const namespacet &ns):
11+
ns(ns)
12+
{}
13+
14+
std::string convert(const exprt &) override;
15+
protected:
16+
typedef pretty_printert baset;
17+
const namespacet &ns;
18+
};
19+
20+
void register_evs_pretty_printer();
21+
22+
#endif

0 commit comments

Comments
 (0)