12
12
#include < test_gen/java_test_source_factory.h>
13
13
14
14
#define INDENT_SPACES " "
15
- #define ID_value_alias " value-alias "
15
+ #define JAVA_NS_PREFIX_LEN 6u
16
16
17
17
namespace
18
18
{
@@ -33,49 +33,46 @@ void add_test_class_name(std::string &result, const std::string &func_name)
33
33
result+=" () {\n " ;
34
34
}
35
35
36
- void add_decl_with_init_prefix (std::string &result, const symbol_tablet &st,
37
- const typet &type)
38
- {
39
- const namespacet ns (st);
40
- result+=type2java (type, ns);
41
- result+=' ' ;
42
- }
43
-
44
- void add_decl_with_init_prefix (std::string &result, const symbol_tablet &st,
45
- const symbolt &symbol)
46
- {
47
- add_decl_with_init_prefix (result, st, symbol.type );
48
- }
49
-
50
36
void add_symbol (std::string &result, const symbolt &s)
51
37
{
52
38
// XXX: Should be expr2java(...) once functional.
53
39
const irep_idt &n=s.pretty_name .empty () ? s.base_name : s.pretty_name ;
54
40
result+=id2string (n);
55
41
}
56
42
57
- std::string get_symbol (const symbolt &symbol)
43
+ void add_qualified_class_name (std::string &result, const namespacet &ns,
44
+ const typet &type)
58
45
{
59
- std::string result;
60
- add_symbol (result, symbol);
61
- return result;
46
+ if (ID_symbol == type.id ())
47
+ {
48
+ const std::string &id=id2string (to_symbol_type (type).get_identifier ());
49
+ assert (id.size () >= JAVA_NS_PREFIX_LEN);
50
+ result+=id.substr (JAVA_NS_PREFIX_LEN);
51
+ } else result+=id2string (to_struct_type (type).get_tag ());
62
52
}
63
53
64
- void addQualifiedClassName (std::string &result, const namespacet &ns ,
65
- const typet &type )
54
+ void add_decl_with_init_prefix (std::string &result, const symbol_tablet &st ,
55
+ const symbolt &symbol )
66
56
{
67
- result+=type2java (type, ns);
57
+ const namespacet ns (st);
58
+ if (ID_pointer != symbol.type .id ()) result+=type2java (symbol.type , ns);
59
+ else add_qualified_class_name (result, ns, symbol.type .subtype ());
60
+ result+=' ' ;
68
61
}
69
62
70
63
void add_value (std::string &result, const symbol_tablet &st,
71
- const std::string &this_name , const struct_exprt &value );
64
+ const struct_exprt &value , const std::string &this_name );
72
65
73
66
void add_value (std::string &result, const symbol_tablet &st, const exprt &value,
74
67
const std::string var_name=" " )
75
68
{
76
69
const namespacet ns (st);
77
- if (ID_struct != value.id ()) result+=expr2java (value, ns);
78
- else add_value (result, st, var_name, to_struct_expr (value));
70
+ const irep_idt &id=value.id ();
71
+ if (ID_address_of == id) add_value (result, st,
72
+ to_address_of_expr (value).object ());
73
+ else if (ID_struct == id) add_value (result, st, to_struct_expr (value),
74
+ var_name);
75
+ else result+=expr2java (value, ns);
79
76
}
80
77
81
78
class member_factoryt
@@ -97,79 +94,64 @@ class member_factoryt
97
94
void operator ()(const exprt &value)
98
95
{
99
96
assert (comp_index < comps.size ());
100
- result+=" Reflector.setInstanceField(" ;
101
- result+=this_name;
102
- const struct_typet::componentt &comp=comps[comp_index++];
103
- result+=" ,\" " ;
104
- result+=id2string (comp.get_pretty_name ());
105
- add_value (result, st, value);
106
- result+=" );\n " ;
97
+ if (ID_struct == value.id ())
98
+ {
99
+ member_factoryt mem_fac (result, st, this_name, value.type ());
100
+ const struct_exprt::operandst &ops=value.operands ();
101
+ std::for_each (ops.begin (), ops.end (), mem_fac);
102
+ if (comp_index < comps.size () - 1 ) result+=" ;\n " ;
103
+ } else
104
+ {
105
+ const struct_typet::componentt &comp=comps[comp_index];
106
+ if (ID_symbol != comp.type ().id ())
107
+ {
108
+ indent (result, 2u )+=" Reflector.setInstanceField(" ;
109
+ result+=this_name;
110
+ result+=" ,\" " ;
111
+ result+=id2string (comp.get_pretty_name ());
112
+ result+=" \" ," ;
113
+ add_value (result, st, value);
114
+ result+=" )" ;
115
+ if (comp_index < comps.size () - 1 ) result+=" ;\n " ;
116
+ }
117
+ }
118
+ ++comp_index;
107
119
}
108
120
};
109
121
110
122
void add_value (std::string &result, const symbol_tablet &st,
111
- const std::string &this_name , const struct_exprt &value )
123
+ const struct_exprt &value , const std::string &this_name )
112
124
{
113
- const std::string &alias=value.get_string (ID_value_alias);
114
- if (!alias.empty ())
115
- {
116
- result+=alias;
117
- return ;
118
- }
119
125
const namespacet ns (st);
120
126
result+=' (' ;
121
127
const typet &type=value.type ();
122
- result+= type2java (value. type () , ns);
128
+ add_qualified_class_name (result , ns, type );
123
129
result+=" ) Reflector.forceInstance(\" " ;
124
- addQualifiedClassName (result, ns, type);
130
+ add_qualified_class_name (result, ns, type);
125
131
result+=" \" );\n " ;
126
132
member_factoryt mem_fac (result, st, this_name, type);
127
133
const struct_exprt::operandst &ops=value.operands ();
128
134
std::for_each (ops.begin (), ops.end (), mem_fac);
129
135
}
130
136
131
137
void add_assign_value (std::string &result, const symbol_tablet &st,
132
- const std::string &symbol, const exprt &value)
138
+ const symbolt &symbol, const exprt &value)
133
139
{
134
- result+=symbol;
140
+ std::string symbol_name;
141
+ add_symbol (symbol_name, symbol);
142
+ result+=symbol_name;
135
143
result+=' =' ;
136
- add_value (result, st, value);
144
+ add_value (result, st, value, symbol_name );
137
145
result+=" ;\n " ;
138
146
}
139
147
140
- void add_assign_value (std::string &result, const symbol_tablet &st,
141
- const symbolt &symbol, const exprt &value)
142
- {
143
- add_assign_value (result, st, get_symbol (symbol), value);
144
- }
145
-
146
- void add_nested_objects (std::string &result, const symbol_tablet &st,
147
- const std::string &this_name, exprt &value)
148
- {
149
- if (ID_struct != value.id ()) return ;
150
- size_t i=0 ;
151
- struct_exprt::operandst &ops=value.operands ();
152
- for (struct_exprt::operandst::value_type &op : ops)
153
- {
154
- if (ID_struct != op.id ()) continue ;
155
- std::string name (this_name);
156
- name+=' _' ;
157
- name+=std::to_string (i);
158
- add_nested_objects (result, st, this_name, op);
159
- add_decl_with_init_prefix (result, st, op.type ());
160
- add_assign_value (result, st, name, op);
161
- op.set (ID_value_alias, name);
162
- }
163
- }
164
-
165
148
void add_global_state_assignments (std::string &result, const symbol_tablet &st,
166
149
inputst &inputs)
167
150
{
168
151
for (inputst::value_type &input : inputs)
169
152
{
170
153
const symbolt &symbol=st.lookup (input.first );
171
154
if (!symbol.is_static_lifetime ) continue ;
172
- add_nested_objects (result, st, get_symbol (symbol), input.second );
173
155
add_assign_value (indent (result, 2u ), st, symbol, input.second );
174
156
}
175
157
}
@@ -194,7 +176,6 @@ void add_func_call_parameters(std::string &result, const symbol_tablet &st,
194
176
const symbolt &symbol=st.lookup (param);
195
177
const inputst::iterator value=inputs.find (param);
196
178
assert (inputs.end () != value);
197
- add_nested_objects (result, st, get_symbol (symbol), value->second );
198
179
add_decl_with_init_prefix (indent (result, 2u ), st, symbol);
199
180
add_assign_value (result, st, symbol, value->second );
200
181
}
@@ -203,7 +184,7 @@ void add_func_call_parameters(std::string &result, const symbol_tablet &st,
203
184
std::string &add_func_call (std::string &result, const symbol_tablet &st,
204
185
const irep_idt &func_id)
205
186
{
206
- // XXX: Should be expr2java(...) once functional.
187
+ // XXX: Should be expr2java(...) once functional.
207
188
const symbolt &s=st.lookup (func_id);
208
189
const std::string func_name_with_brackets (id2string (s.pretty_name ));
209
190
const size_t sz=func_name_with_brackets.size ();
@@ -216,7 +197,7 @@ std::string &add_func_call(std::string &result, const symbol_tablet &st,
216
197
add_symbol (result, st.lookup (param));
217
198
result+=' ,' ;
218
199
}
219
- ( *result.rbegin () )=' )' ;
200
+ *result.rbegin ()=' )' ;
220
201
result+=" ;\n " ;
221
202
indent (result)+=" }\n " ;
222
203
return result+=" }\n " ;
0 commit comments