Skip to content

Commit 2b9c169

Browse files
committed
Updates requested in the PR diffblue#133.
1 parent 8c9f5a9 commit 2b9c169

File tree

1 file changed

+51
-65
lines changed

1 file changed

+51
-65
lines changed

src/taint-slicer/instrumentation_props.cpp

Lines changed: 51 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,53 @@ instrumentation_props data structure.
2222
\*******************************************************************/
2323

2424
#include <taint-slicer/instrumentation_props.h>
25+
#include <goto-programs/remove_returns.h>
26+
#include <util/msgstream.h>
2527
#include <util/msgstream.h>
2628
#include <deque>
2729

28-
static std::string parse_return_type_from_function_name(
29-
const std::string &fname)
30+
static std::string parse_type_name(const typet &type)
3031
{
31-
const std::string::size_type idx=fname.rfind(")");
32-
if(idx==std::string::npos)
33-
return "ERROR: cannot find the start of the return type.";
34-
const std::string raw_type=fname.substr(idx+1UL);
35-
if(raw_type.empty())
36-
return "ERROR: the return type is missing.";
37-
std::string result;
38-
switch(raw_type[0])
32+
const typet * restype = &type;
33+
if(type.id()==ID_pointer)
34+
restype=&to_pointer_type(type).subtype();
35+
else if(type.id()==ID_array)
36+
restype=&to_array_type(type).subtype();
37+
if(restype->id()==ID_signedbv)
38+
{
39+
const signedbv_typet &sbv=to_signedbv_type(*restype);
40+
if(sbv.get_width()==8UL)
41+
return as_string(ID_char);
42+
if(sbv.get_width()==16UL)
43+
return as_string(ID_short);
44+
if(sbv.get_width()==32UL)
45+
return as_string(ID_int);
46+
if(sbv.get_width()==64UL)
47+
return as_string(ID_long);
48+
return msgstream() << "ERROR: unexpected bit-width '"
49+
<< sbv.get_width() << "' of signedbv type. Valid sizes "
50+
<< "are 8, 16, 32, and 64.";
51+
}
52+
if(restype->id()==ID_unsignedbv)
3953
{
40-
case 'L':
41-
result="java::"+raw_type.substr(1UL, raw_type.size()-2UL);
42-
std::replace(result.begin(), result.end(), '/', '.');
43-
return result;
44-
case 'C':
45-
return "char";
46-
case 'I':
47-
return "int";
48-
default:
49-
return msgstream() << "ERROR: unknown return type type: " << raw_type;
54+
const unsignedbv_typet &ubv=to_unsignedbv_type(*restype);
55+
if(ubv.get_width()==8UL)
56+
return as_string(ID_byte);
57+
if(ubv.get_width()==16UL)
58+
return as_string(ID_unsigned_short_int);
59+
if(ubv.get_width()==32UL)
60+
return as_string(ID_unsigned_int);
61+
if(ubv.get_width()==64UL)
62+
return as_string(ID_unsigned_long_int);
63+
return msgstream() << "ERROR: unexpected bit-width '"
64+
<< ubv.get_width() << "' of unsignedbv type. Valid "
65+
<< "sizes are 8, 16, 32 and 64.";
5066
}
67+
if(restype->id()!=ID_symbol)
68+
return msgstream() << "ERROR: expecting the '"
69+
<< as_string(ID_symbol) << "' type id, but received '"
70+
<< as_string(restype->id()) << "'.";
71+
return as_string(to_symbol_type(*restype).get_identifier());
5172
}
5273

5374
bool is_primitive_type_name(const std::string &datatype)
@@ -85,52 +106,16 @@ bool does_instrumentation_of_type_require_subclass(const std::string &datatype)
85106
|| datatype=="java::java.lang.Object";
86107
}
87108

88-
89-
static std::string parse_param_type_name(const typet &param_type)
109+
static std::string get_return_type_name_from_function_name(
110+
const std::string &fname, const symbol_tablet &symbol_table)
90111
{
91-
const typet * restype = &param_type;
92-
if(param_type.id()==ID_pointer)
93-
restype=&to_pointer_type(param_type).subtype();
94-
else if(param_type.id()==ID_array)
95-
restype=&to_array_type(param_type).subtype();
96-
if(restype->id()==ID_signedbv)
97-
{
98-
const signedbv_typet &sbv=to_signedbv_type(*restype);
99-
if(sbv.get_width()==8UL)
100-
return as_string(ID_char);
101-
if(sbv.get_width()==16UL)
102-
return as_string(ID_short);
103-
if(sbv.get_width()==32UL)
104-
return as_string(ID_int);
105-
if(sbv.get_width()==64UL)
106-
return as_string(ID_long);
107-
return msgstream() << "ERROR: unexpected bit-width '"
108-
<< sbv.get_width() << "' of signedbv type. Valid sizes "
109-
<< "are 8, 16, 32, and 64.";
110-
}
111-
if(restype->id()==ID_unsignedbv)
112-
{
113-
const unsignedbv_typet &ubv=to_unsignedbv_type(*restype);
114-
if(ubv.get_width()==8UL)
115-
return as_string(ID_byte);
116-
if(ubv.get_width()==16UL)
117-
return as_string(ID_unsigned_short_int);
118-
if(ubv.get_width()==32UL)
119-
return as_string(ID_unsigned_int);
120-
if(ubv.get_width()==64UL)
121-
return as_string(ID_unsigned_long_int);
122-
return msgstream() << "ERROR: unexpected bit-width '"
123-
<< ubv.get_width() << "' of unsignedbv type. Valid "
124-
<< "sizes are 8, 16, 32 and 64.";
125-
}
126-
if(restype->id()!=ID_symbol)
127-
return msgstream() << "ERROR: expecting the '"
128-
<< as_string(ID_symbol) << "' type id, but received '"
129-
<< as_string(restype->id()) << "'.";
130-
return as_string(to_symbol_type(*restype).get_identifier());
112+
assert(symbol_table.has_symbol(fname+RETURN_VALUE_SUFFIX));
113+
typet t=symbol_table.lookup(fname+RETURN_VALUE_SUFFIX).type;
114+
if(t.id()==ID_pointer)
115+
t=to_pointer_type(t).subtype();
116+
return parse_type_name(t);
131117
}
132118

133-
134119
/*******************************************************************\
135120
136121
Function: perform_BFS
@@ -261,10 +246,11 @@ void taint_instrumentation_propst::build_map_from_typenames_to_tokennames(
261246
taint_tokens_propagation_grapht::get_void_loc());
262247
std::string datatype;
263248
if(arg_token.get_argidx()==-1) // Return value
264-
datatype=parse_return_type_from_function_name(callee_ident);
249+
datatype=get_return_type_name_from_function_name(
250+
callee_ident, program.get_symbol_table());
265251
else
266252
{
267-
datatype=parse_param_type_name(
253+
datatype=parse_type_name(
268254
fn_type.parameters().at(arg_token.get_argidx()).type());
269255
}
270256
assert(datatype.find("ERROR:")==std::string::npos);

0 commit comments

Comments
 (0)