Skip to content

Commit 33777c2

Browse files
mmueslydanpoe
authored andcommitted
Add meaningfull names instead of id_X
1 parent 6c734f8 commit 33777c2

File tree

6 files changed

+74
-45
lines changed

6 files changed

+74
-45
lines changed

regression/memory-analyzer/arrays/test.desc

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@ arrays.exe
44
analyzing symbol: test_struct
55
GENERATED CODE:
66
\{
7-
char id_1\[7l\]="accept";
8-
char id_2\[8l\]="unique0";
9-
char id_3\[8l\]="unique1";
10-
char id_4\[8l\]="unique2";
11-
char id_5\[8l\]="unique3";
12-
struct a_typet id_0=\{ .config=\{ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 \}, .initalized=false,
13-
.values=\{ 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 171, 171, 171, 171, 171, 171, 171, 171, 171, 171 \}, .childs=\{ \{ .id=12, .options=\{ \{ .text=\(char \*\)&id_1 \}, \{ .text=\(char \*\)&id_2 \} \} \},
14-
\{ .id=13, .options=\{ \{ .text=\(char \*\)&id_1 \}, \{ .text=\(char \*\)&id_3 \} \} \},
15-
\{ .id=14, .options=\{ \{ .text=\(char \*\)&id_1 \}, \{ .text=\(char \*\)&id_4 \} \} \},
16-
\{ .id=15, .options=\{ \{ .text=\(char \*\)&id_1 \}, \{ .text=\(char \*\)&id_5 \} \} \} \} \};
17-
test_struct = &id_0;
7+
char _test_struct_childs0_options0_text_1\[7l\]="accept";
8+
char _test_struct_childs0_options1_text_2\[8l\]="unique0";
9+
char _test_struct_childs1_options1_text_3\[8l\]="unique1";
10+
char _test_struct_childs2_options1_text_4\[8l\]="unique2";
11+
char _test_struct_childs3_options1_text_5\[8l\]="unique3";
12+
struct a_typet test_struct_0=\{ .config=\{ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 \}, .initalized=0,
13+
.values=\{ 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 171, 171, 171, 171, 171, 171, 171, 171, 171, 171 \}, .childs=\{ \{ .id=12, .options=\{ \{ .text=\(char \*\)&_test_struct_childs0_options0_text_1 \},
14+
\{ .text=\(char \*\)&_test_struct_childs0_options1_text_2 \} \} \},
15+
\{ .id=13, .options=\{ \{ .text=\(char \*\)&_test_struct_childs0_options0_text_1 \},
16+
\{ .text=\(char \*\)&_test_struct_childs1_options1_text_3 \} \} \},
17+
\{ .id=14, .options=\{ \{ .text=\(char \*\)&_test_struct_childs0_options0_text_1 \},
18+
\{ .text=\(char \*\)&_test_struct_childs2_options1_text_4 \} \} \},
19+
\{ .id=15, .options=\{ \{ .text=\(char \*\)&_test_struct_childs0_options0_text_1 \},
20+
\{ .text=\(char \*\)&_test_struct_childs3_options1_text_5 \} \} \} \} \};
21+
test_struct = &test_struct_0;
1822
\}
1923
--
2024
--

regression/memory-analyzer/cycles/test.desc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ cycles.exe
44
analyzing symbol: buffer
55
GENERATED CODE:
66
\{
7-
char id_1\[5l\]="snow";
8-
char id_3\[4l\]="sun";
9-
char id_5\[5l\]="rain";
10-
char id_7\[14l\]="thunder storm";
11-
struct cycle_buffer_entry id_6=\{ .data=\(char \*\)&id_7, .next=\(\(struct cycle_buffer_entry \*\)NULL\) \};
12-
struct cycle_buffer_entry id_4=\{ .data=\(char \*\)&id_5, .next=&id_6 \};
13-
struct cycle_buffer_entry id_2=\{ .data=\(char \*\)&id_3, .next=&id_4 \};
14-
struct cycle_buffer_entry id_0=\{ .data=\(char \*\)&id_1, .next=&id_2 \};
15-
buffer.start = &id_0;
16-
buffer.end = &id_6;
17-
\(\*\(\*\(\*\(\*buffer.start\).next\).next\).next\).next = &id_0;
7+
char _buffer_start_data_1\[5l\]="snow";
8+
char __buffer_start_next_data_3\[4l\]="sun";
9+
char ___buffer_start_next_next_data_5\[5l\]="rain";
10+
char ____buffer_start_next_next_next_data_7\[14l\]="thunder storm";
11+
struct cycle_buffer_entry ___buffer_start_next_next_next_6=\{ .data=\(char \*\)&____buffer_start_next_next_next_data_7, .next=\(\(struct cycle_buffer_entry \*\)NULL\) \};
12+
struct cycle_buffer_entry __buffer_start_next_next_4=\{ .data=\(char \*\)&___buffer_start_next_next_data_5, .next=&___buffer_start_next_next_next_6 \};
13+
struct cycle_buffer_entry _buffer_start_next_2=\{ .data=\(char \*\)&__buffer_start_next_data_3, .next=&__buffer_start_next_next_4 \};
14+
struct cycle_buffer_entry buffer_start_0=\{ .data=\(char \*\)&_buffer_start_data_1, .next=&_buffer_start_next_2 \};
15+
buffer.start = &buffer_start_0;
16+
buffer.end = &___buffer_start_next_next_next_6;
17+
\(\*\(\*\(\*\(\*buffer.start\).next\).next\).next\).next = &buffer_start_0;
1818
\}
1919
--
2020
--

regression/memory-analyzer/primitive_types/test.desc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ GENERATED CODE:
1212
e = 17;
1313
f = &e;
1414
f_1 = &e;
15-
char id_0\[6l\]="test2";
15+
char d_b_0\[6l\]="test2";
1616
d.a = 4;
17-
d.b = \(char \*\)&id_0;
17+
d.b = \(char \*\)&d_b_0;
1818
d.c = -32;
19-
struct mapping_things id_1=\{ .a=0, .b=\(\(char \*\)NULL\), .c=0 \};
20-
g = &id_1;
21-
char id_2\[5l\]="test";
22-
h = \(char \*\)&id_2;
19+
struct mapping_things g_1=\{ .a=0, .b=\(\(char \*\)NULL\), .c=0 \};
20+
g = &g_1;
21+
char h_2\[5l\]="test";
22+
h = \(char \*\)&h_2;
2323
}
2424
^EXIT=0
2525
^SIGNAL=0

regression/memory-analyzer/void_pointer/test.desc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ analyzing symbol: blob
55
GENERATED CODE:
66
\{
77
a_void_pointer = NULL;
8-
char id_0\[12l\]="test_string";
9-
a_second_void_pointer = \(char \*\)&id_0;
10-
char id_1\[7ul\]=\{ -13, -13, 'H', -1, '\\\\', '\\\\', -1 \};
11-
a_third_void_pointer = \(char \*\)&id_1;
8+
char char_a_second_void_pointer_0\[12l\]="test_string";
9+
a_second_void_pointer = \(char \*\)&char_a_second_void_pointer_0;
10+
char char_a_third_void_pointer_1\[7ul\]=\{ -13, -13, 'H', -1, '\\\\', '\\\\', -1 \};
11+
a_third_void_pointer = \(char \*\)&char_a_third_void_pointer_1;
1212
blob.size = 7;
13-
blob.data = \(char \*\)&id_1;
13+
blob.data = \(char \*\)&char_a_third_void_pointer_1;
1414
\}
1515
--
1616
--

src/memory-analyzer/analyze_symbol.cpp

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "analyze_symbol.h"
55
#include "gdb_api.h"
66

7+
#include <algorithm>
78
#include <regex>
89

910
#include <ansi-c/expr2c_class.h>
@@ -181,6 +182,37 @@ array_exprt create_char_array_from_string(
181182
return result_array;
182183
}
183184

185+
code_declt
186+
symbol_analyzert::declare_instance(const std::string &prefix, const typet &type)
187+
{
188+
std::string safe_prefix = prefix;
189+
std::replace(safe_prefix.begin(), safe_prefix.end(), '.', '_');
190+
std::replace(safe_prefix.begin(), safe_prefix.end(), '-', '_');
191+
std::replace(safe_prefix.begin(), safe_prefix.end(), '>', '_');
192+
std::replace(safe_prefix.begin(), safe_prefix.end(), '&', '_');
193+
std::replace(safe_prefix.begin(), safe_prefix.end(), '*', '_');
194+
safe_prefix.erase(
195+
std::remove(safe_prefix.begin(), safe_prefix.end(), '('),
196+
safe_prefix.end());
197+
safe_prefix.erase(
198+
std::remove(safe_prefix.begin(), safe_prefix.end(), ')'),
199+
safe_prefix.end());
200+
safe_prefix.erase(
201+
std::remove(safe_prefix.begin(), safe_prefix.end(), '['),
202+
safe_prefix.end());
203+
safe_prefix.erase(
204+
std::remove(safe_prefix.begin(), safe_prefix.end(), ']'),
205+
safe_prefix.end());
206+
safe_prefix.erase(
207+
std::remove(safe_prefix.begin(), safe_prefix.end(), ' '),
208+
safe_prefix.end());
209+
210+
const std::string var_id = safe_prefix + "_" + std::to_string(id_counter);
211+
++id_counter;
212+
const code_declt declaration(symbol_exprt(var_id, type));
213+
return declaration;
214+
}
215+
184216
exprt symbol_analyzert::declare_and_initalize_char_ptr(
185217
const symbol_exprt &symbol,
186218
const std::string &memory_location,
@@ -201,7 +233,8 @@ exprt symbol_analyzert::declare_and_initalize_char_ptr(
201233
init = create_char_array_from_string(value, bv_type, location, ns);
202234
}
203235

204-
code_declt target_object = declare_instance(init.type());
236+
code_declt target_object =
237+
declare_instance(id2string(symbol.get_identifier()), init.type());
205238
target_object.operands().resize(2);
206239
target_object.op1() = init;
207240
generated_code.add(target_object);
@@ -217,14 +250,6 @@ exprt symbol_analyzert::declare_and_initalize_char_ptr(
217250
}
218251
}
219252

220-
code_declt symbol_analyzert::declare_instance(const typet &type)
221-
{
222-
const std::string var_id = "id_" + std::to_string(id_counter);
223-
++id_counter;
224-
const code_declt declaration(symbol_exprt(var_id, type));
225-
return declaration;
226-
}
227-
228253
exprt symbol_analyzert::process_any_pointer_target(
229254
const symbol_exprt &symbol,
230255
const std::string memory_location,
@@ -254,7 +279,7 @@ code_declt symbol_analyzert::get_pointer_target(
254279
const typet &type,
255280
const source_locationt &location)
256281
{
257-
code_declt declaration = declare_instance(type);
282+
code_declt declaration = declare_instance(pointer_name, type);
258283

259284
const std::string deref_pointer = "(*" + pointer_name + ")";
260285
const exprt target_expr = fill_expr_with_values(
@@ -373,7 +398,7 @@ exprt symbol_analyzert::fill_struct_with_values(
373398
}
374399
else if(is_struct(resolved_type))
375400
{
376-
code_declt declaration = declare_instance(resolved_type);
401+
code_declt declaration = declare_instance(field_access, resolved_type);
377402

378403
const exprt target_expr = fill_expr_with_values(
379404
field_access,

src/memory-analyzer/analyze_symbol.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class symbol_analyzert : public messaget
7070
const typet &type,
7171
const source_locationt &location);
7272

73-
code_declt declare_instance(const typet &type);
73+
code_declt declare_instance(const std::string &prefix, const typet &type);
7474
exprt declare_and_initalize_char_ptr(
7575
const symbol_exprt &symbol,
7676
const std::string &memory_location,

0 commit comments

Comments
 (0)