@@ -23,90 +23,52 @@ instrumentation_props data structure.
23
23
24
24
#include < taint-slicer/instrumentation_props.h>
25
25
#include < goto-programs/remove_returns.h>
26
+ #include < java_bytecode/java_types.h>
27
+ #include < java_bytecode/expr2java.h>
26
28
#include < util/prefix.h>
27
29
#include < util/msgstream.h>
28
30
#include < deque>
29
31
30
- static std::string parse_type_name ( const typet &type )
32
+ bool is_primitive_type_name ( const std::string &datatype, const namespacet &ns )
31
33
{
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
- throw std::logic_error (
49
- msgstream () << " ERROR: unexpected bit-width '"
50
- << sbv.get_width () << " ' of signedbv type. Valid sizes "
51
- << " are 8, 16, 32, and 64." );
52
- }
53
- if (restype->id ()==ID_unsignedbv)
54
- {
55
- const unsignedbv_typet &ubv=to_unsignedbv_type (*restype);
56
- if (ubv.get_width ()==8UL )
57
- return as_string (ID_byte);
58
- if (ubv.get_width ()==16UL )
59
- return as_string (ID_unsigned_short_int);
60
- if (ubv.get_width ()==32UL )
61
- return as_string (ID_unsigned_int);
62
- if (ubv.get_width ()==64UL )
63
- return as_string (ID_unsigned_long_int);
64
- throw std::logic_error (
65
- msgstream () << " ERROR: unexpected bit-width '"
66
- << ubv.get_width () << " ' of unsignedbv type. Valid "
67
- << " sizes are 8, 16, 32 and 64." );
68
- }
69
- if (restype->id ()!=ID_symbol)
70
- throw std::logic_error (
71
- msgstream () << " ERROR: expecting the '"
72
- << as_string (ID_symbol) << " ' type id, but received '"
73
- << as_string (restype->id ()) << " '." );
74
- return as_string (to_symbol_type (*restype).get_identifier ());
34
+ return datatype==type2java (java_boolean_type (), ns) ||
35
+ datatype==type2java (java_boolean_type (), ns) ||
36
+ datatype==type2java (java_byte_type (), ns) ||
37
+ datatype==type2java (java_char_type (), ns) ||
38
+ datatype==type2java (java_short_type (), ns) ||
39
+ datatype==type2java (java_int_type (), ns) ||
40
+ datatype==type2java (java_long_type (), ns) ||
41
+ datatype==type2java (java_float_type (), ns) ||
42
+ datatype==type2java (java_double_type (), ns) ;
75
43
}
76
44
77
- bool is_primitive_type_name ( const std::string &datatype )
45
+ static std::string parse_type_name ( const typet &type, const namespacet &ns )
78
46
{
79
- static const std::set<std::string> names=
80
- {
81
- as_string (ID_bool),
82
- as_string (ID_byte),
83
- as_string (ID_char),
84
- as_string (ID_unsigned_char),
85
- as_string (ID_short),
86
- as_string (ID_unsigned_short_int),
87
- as_string (ID_int),
88
- as_string (ID_unsigned_int),
89
- as_string (ID_long),
90
- as_string (ID_unsigned_long_int),
91
- as_string (ID_unsigned_long_long_int),
92
- as_string (ID_unsigned_int128),
93
- as_string (ID_float),
94
- as_string (ID_double),
95
- as_string (ID_long_double)
96
- };
97
- return names.count (datatype)==1UL ;
47
+ if (type.id ()==ID_pointer)
48
+ return parse_type_name (to_pointer_type (type).subtype (), ns);
49
+ if (type.id ()==ID_array)
50
+ return parse_type_name (to_array_type (type).subtype (), ns);
51
+ if (type.id ()==ID_symbol)
52
+ return as_string (to_symbol_type (type).get_identifier ());
53
+ const std::string result=type2java (type, ns);
54
+ if (!is_primitive_type_name (result, ns))
55
+ throw std::logic_error (
56
+ msgstream () << " ERROR: expecting a primitive data type, "
57
+ " but received '" << result << " '." );
58
+ return result;
98
59
}
99
60
100
61
bool is_java_array_type_name (const std::string &datatype)
101
62
{
102
63
return has_prefix (datatype, " java::array[" ) && *datatype.rbegin ()==' ]' ;
103
64
}
104
65
105
- bool does_instrumentation_of_type_require_subclass (const std::string &datatype)
66
+ bool does_instrumentation_of_type_require_subclass (
67
+ const std::string &datatype, const namespacet &ns)
106
68
{
107
- return is_primitive_type_name (datatype) ||
108
- is_java_array_type_name (datatype)
109
- || datatype==" java::java.lang.Object" ;
69
+ return is_primitive_type_name (datatype, ns ) ||
70
+ is_java_array_type_name (datatype) ||
71
+ datatype==" java::java.lang.Object" ;
110
72
}
111
73
112
74
static std::string get_return_type_name_from_function_name (
@@ -116,7 +78,7 @@ static std::string get_return_type_name_from_function_name(
116
78
typet t=symbol_table.lookup (fname+RETURN_VALUE_SUFFIX).type ;
117
79
if (t.id ()==ID_pointer)
118
80
t=to_pointer_type (t).subtype ();
119
- return parse_type_name (t);
81
+ return parse_type_name (t, namespacet (symbol_table) );
120
82
}
121
83
122
84
/* ******************************************************************\
@@ -254,9 +216,10 @@ void taint_instrumentation_propst::build_map_from_typenames_to_tokennames(
254
216
else
255
217
{
256
218
datatype=parse_type_name (
257
- fn_type.parameters ().at (arg_token.get_argidx ()).type ());
219
+ fn_type.parameters ().at (arg_token.get_argidx ()).type (),
220
+ program.get_namespace ());
258
221
}
259
- assert (is_primitive_type_name (datatype)
222
+ assert (is_primitive_type_name (datatype, program. get_namespace () )
260
223
|| program.get_symbol_table ().has_symbol (datatype));
261
224
datatypes[datatype].insert (arg_token.get_token_name ());
262
225
}
@@ -374,7 +337,10 @@ void taint_build_instrumentation_props(
374
337
}
375
338
}
376
339
377
- void dump_as_json (const taint_instrumentation_propst &props, json_objectt &out)
340
+ void dump_as_json (
341
+ const taint_instrumentation_propst &props,
342
+ json_objectt &out,
343
+ const namespacet &ns)
378
344
{
379
345
{
380
346
json_arrayt out_types;
@@ -386,7 +352,7 @@ void dump_as_json(const taint_instrumentation_propst &props, json_objectt &out)
386
352
json_objectt out_type_props;
387
353
out_type_props[" type_name" ]=json_stringt (elem.first );
388
354
out_type_props[" shadow_vars" ]=out_tokens;
389
- if (does_instrumentation_of_type_require_subclass (elem.first ))
355
+ if (does_instrumentation_of_type_require_subclass (elem.first , ns ))
390
356
out_type_props[" make_subclass" ]=json_truet ();
391
357
else
392
358
out_type_props[" make_subclass" ]=json_falset ();
0 commit comments