@@ -22,32 +22,53 @@ instrumentation_props data structure.
22
22
\*******************************************************************/
23
23
24
24
#include < taint-slicer/instrumentation_props.h>
25
+ #include < goto-programs/remove_returns.h>
26
+ #include < util/msgstream.h>
25
27
#include < util/msgstream.h>
26
28
#include < deque>
27
29
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)
30
31
{
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)
39
53
{
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." ;
50
66
}
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 ());
51
72
}
52
73
53
74
bool is_primitive_type_name (const std::string &datatype)
@@ -85,52 +106,16 @@ bool does_instrumentation_of_type_require_subclass(const std::string &datatype)
85
106
|| datatype==" java::java.lang.Object" ;
86
107
}
87
108
88
-
89
- static std::string parse_param_type_name ( const typet ¶m_type )
109
+ static std::string get_return_type_name_from_function_name (
110
+ const std::string &fname, const symbol_tablet &symbol_table )
90
111
{
91
- const typet * restype = ¶m_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);
131
117
}
132
118
133
-
134
119
/* ******************************************************************\
135
120
136
121
Function: perform_BFS
@@ -261,10 +246,11 @@ void taint_instrumentation_propst::build_map_from_typenames_to_tokennames(
261
246
taint_tokens_propagation_grapht::get_void_loc ());
262
247
std::string datatype;
263
248
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 ());
265
251
else
266
252
{
267
- datatype=parse_param_type_name (
253
+ datatype=parse_type_name (
268
254
fn_type.parameters ().at (arg_token.get_argidx ()).type ());
269
255
}
270
256
assert (datatype.find (" ERROR:" )==std::string::npos);
0 commit comments