Skip to content

Commit 6d5f793

Browse files
committed
Add and use symbolt constructors
To the extent possible, apply resource-acquisition-is-initialisation. The constructors ensure that at least the most essential fields (name, type, mode) are set.
1 parent 5cfbeb8 commit 6d5f793

File tree

80 files changed

+339
-763
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+339
-763
lines changed

jbmc/src/java_bytecode/java_bytecode_concurrency_instrumentation.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,14 @@ static symbolt add_or_get_symbol(
4646
ns.lookup(name, psymbol);
4747
if(psymbol != nullptr)
4848
return *psymbol;
49-
symbolt new_symbol;
50-
new_symbol.name = name;
49+
symbolt new_symbol{name, type, ID_java};
5150
new_symbol.pretty_name = name;
5251
new_symbol.base_name = base_name;
53-
new_symbol.type = type;
5452
new_symbol.value = value;
5553
new_symbol.is_lvalue = true;
5654
new_symbol.is_state_var = true;
5755
new_symbol.is_static_lifetime = is_static_lifetime;
5856
new_symbol.is_thread_local = is_thread_local;
59-
new_symbol.mode = ID_java;
6057
symbol_table.add(new_symbol);
6158
return new_symbol;
6259
}

jbmc/src/java_bytecode/java_bytecode_convert_class.cpp

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -446,14 +446,10 @@ void java_bytecode_convert_classt::convert(
446446
}(id2string(c.name));
447447

448448
// produce class symbol
449-
symbolt new_symbol;
449+
class_type.set_name(qualified_classname);
450+
type_symbolt new_symbol{qualified_classname, class_type, ID_java};
450451
new_symbol.base_name = base_name;
451452
new_symbol.pretty_name=c.name;
452-
new_symbol.name=qualified_classname;
453-
class_type.set_name(new_symbol.name);
454-
new_symbol.type=class_type;
455-
new_symbol.mode=ID_java;
456-
new_symbol.is_type=true;
457453

458454
symbolt *class_symbol;
459455

@@ -711,23 +707,21 @@ void java_bytecode_convert_classt::convert(
711707
component.type() = field_type;
712708

713709
// Create the symbol
714-
symbolt new_symbol;
710+
symbolt new_symbol{id2string(class_symbol.name) + "." + id2string(f.name),
711+
field_type,
712+
ID_java};
715713

716714
new_symbol.is_static_lifetime=true;
717715
new_symbol.is_lvalue=true;
718716
new_symbol.is_state_var=true;
719-
new_symbol.name=id2string(class_symbol.name)+"."+id2string(f.name);
720717
new_symbol.base_name=f.name;
721-
new_symbol.type=field_type;
722718
// Provide a static field -> class link, like
723719
// java_bytecode_convert_method::convert does for method -> class.
724720
set_declaring_class(new_symbol, class_symbol.name);
725721
new_symbol.type.set(ID_C_field, f.name);
726722
new_symbol.type.set(ID_C_constant, f.is_final);
727723
new_symbol.pretty_name=id2string(class_symbol.pretty_name)+
728724
"."+id2string(f.name);
729-
new_symbol.mode=ID_java;
730-
new_symbol.is_type=false;
731725

732726
// These annotations use `ID_C_access` instead of `ID_access` like methods
733727
// to avoid type clashes in expressions like `some_static_field = 0`, where
@@ -859,12 +853,8 @@ void add_java_array_types(symbol_tablet &symbol_table)
859853
"Constructed a new type representing a Java Array "
860854
"object that doesn't match expectations");
861855

862-
symbolt symbol;
863-
symbol.name = struct_tag_type_identifier;
856+
type_symbolt symbol{struct_tag_type_identifier, class_type, ID_java};
864857
symbol.base_name = struct_tag_type.get(ID_C_base_name);
865-
symbol.is_type=true;
866-
symbol.type = class_type;
867-
symbol.mode = ID_java;
868858
symbol_table.add(symbol);
869859

870860
// Also provide a clone method:
@@ -987,14 +977,11 @@ void add_java_array_types(symbol_tablet &symbol_table)
987977
copy_loop,
988978
return_inst});
989979

990-
symbolt clone_symbol;
991-
clone_symbol.name=clone_name;
980+
symbolt clone_symbol{clone_name, clone_type, ID_java};
992981
clone_symbol.pretty_name =
993982
id2string(struct_tag_type_identifier) + ".clone:()";
994983
clone_symbol.base_name="clone";
995-
clone_symbol.type=clone_type;
996984
clone_symbol.value=clone_body;
997-
clone_symbol.mode=ID_java;
998985
symbol_table.add(clone_symbol);
999986
}
1000987
}

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,11 @@ void create_method_stub_symbol(
100100
{
101101
messaget log(message_handler);
102102

103-
symbolt symbol;
104-
symbol.name = identifier;
103+
symbolt symbol{identifier, type, ID_java};
105104
symbol.base_name = base_name;
106105
symbol.pretty_name = pretty_name;
107-
symbol.type = type;
108106
symbol.type.set(ID_access, ID_private);
109107
to_java_method_type(symbol.type).set_is_final(true);
110-
symbol.value.make_nil();
111-
symbol.mode = ID_java;
112108
assign_parameter_names(
113109
to_java_method_type(symbol.type), symbol.name, symbol_table);
114110
set_declaring_class(symbol, declaring_class);
@@ -305,18 +301,15 @@ void java_bytecode_convert_method_lazy(
305301
symbol_tablet &symbol_table,
306302
message_handlert &message_handler)
307303
{
308-
symbolt method_symbol;
309-
310304
java_method_typet member_type = member_type_lazy(
311305
m.descriptor,
312306
m.signature,
313307
id2string(class_symbol.name),
314308
id2string(m.base_name),
315309
message_handler);
316310

317-
method_symbol.name=method_identifier;
311+
symbolt method_symbol{method_identifier, typet{}, ID_java};
318312
method_symbol.base_name=m.base_name;
319-
method_symbol.mode=ID_java;
320313
method_symbol.location=m.source_location;
321314
method_symbol.location.set_function(method_identifier);
322315

@@ -1898,13 +1891,9 @@ java_bytecode_convert_methodt::convert_instructions(const methodt &method)
18981891
// Add anonymous locals to the symtab:
18991892
for(const auto &var : used_local_names)
19001893
{
1901-
symbolt new_symbol;
1902-
new_symbol.name=var.get_identifier();
1903-
new_symbol.type=var.type();
1894+
symbolt new_symbol{var.get_identifier(), var.type(), ID_java};
19041895
new_symbol.base_name=var.get(ID_C_base_name);
19051896
new_symbol.pretty_name=strip_java_namespace_prefix(var.get_identifier());
1906-
new_symbol.mode=ID_java;
1907-
new_symbol.is_type=false;
19081897
new_symbol.is_file_local=true;
19091898
new_symbol.is_thread_local=true;
19101899
new_symbol.is_lvalue=true;

jbmc/src/java_bytecode/java_bytecode_internal_additions.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,21 @@ void java_internal_additions(symbol_table_baset &dest)
2525
// add __CPROVER_rounding_mode
2626

2727
{
28-
symbolt symbol;
29-
symbol.name = rounding_mode_identifier();
28+
symbolt symbol{rounding_mode_identifier(), signed_int_type(), ID_C};
3029
symbol.base_name = symbol.name;
31-
symbol.type=signed_int_type();
32-
symbol.mode=ID_C;
3330
symbol.is_lvalue=true;
3431
symbol.is_state_var=true;
3532
symbol.is_thread_local=true;
3633
dest.add(symbol);
3734
}
3835

3936
{
40-
auxiliary_symbolt symbol;
37+
auxiliary_symbolt symbol{INFLIGHT_EXCEPTION_VARIABLE_NAME,
38+
pointer_type(java_void_type()),
39+
ID_java};
4140
symbol.base_name = INFLIGHT_EXCEPTION_VARIABLE_BASENAME;
42-
symbol.name = INFLIGHT_EXCEPTION_VARIABLE_NAME;
43-
symbol.mode = ID_java;
44-
symbol.type = pointer_type(java_void_type());
4541
symbol.type.set(ID_C_no_nondet_initialization, true);
4642
symbol.value = null_pointer_exprt(to_pointer_type(symbol.type));
47-
symbol.is_file_local = false;
4843
symbol.is_static_lifetime = true;
4944
dest.add(symbol);
5045
}

jbmc/src/java_bytecode/java_bytecode_language.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -527,15 +527,13 @@ static symbol_exprt get_or_create_class_literal_symbol(
527527
java_lang_Class);
528528
if(!symbol_table.has_symbol(symbol_expr.get_identifier()))
529529
{
530-
symbolt new_class_symbol;
531-
new_class_symbol.name = symbol_expr.get_identifier();
532-
new_class_symbol.type = symbol_expr.type();
530+
symbolt new_class_symbol{
531+
symbol_expr.get_identifier(), symbol_expr.type(), ID_java};
533532
INVARIANT(
534533
has_prefix(id2string(new_class_symbol.name), "java::"),
535534
"class identifier should have 'java::' prefix");
536535
new_class_symbol.base_name =
537536
id2string(new_class_symbol.name).substr(6);
538-
new_class_symbol.mode = ID_java;
539537
new_class_symbol.is_lvalue = true;
540538
new_class_symbol.is_state_var = true;
541539
new_class_symbol.is_static_lifetime = true;
@@ -650,13 +648,11 @@ static void create_stub_global_symbol(
650648
const irep_idt &class_id,
651649
bool force_nondet_init)
652650
{
653-
symbolt new_symbol;
651+
symbolt new_symbol{symbol_id, symbol_type, ID_java};
654652
new_symbol.is_static_lifetime = true;
655653
new_symbol.is_lvalue = true;
656654
new_symbol.is_state_var = true;
657-
new_symbol.name = symbol_id;
658655
new_symbol.base_name = symbol_basename;
659-
new_symbol.type = symbol_type;
660656
set_declaring_class(new_symbol, class_id);
661657
// Public access is a guess; it encourages merging like-typed static fields,
662658
// whereas a more restricted visbility would encourage separating them.
@@ -665,8 +661,6 @@ static void create_stub_global_symbol(
665661
// We set the field as final to avoid assuming they can be overridden.
666662
new_symbol.type.set(ID_C_constant, true);
667663
new_symbol.pretty_name = new_symbol.name;
668-
new_symbol.mode = ID_java;
669-
new_symbol.is_type = false;
670664
// If pointer-typed, initialise to null and a static initialiser will be
671665
// created to initialise on first reference. If primitive-typed, specify
672666
// nondeterministic initialisation by setting a nil value.

jbmc/src/java_bytecode/java_bytecode_typecheck_expr.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,9 @@ void java_bytecode_typecheckt::typecheck_expr_symbol(symbol_exprt &expr)
8282
has_prefix(id2string(identifier), CPROVER_PREFIX));
8383

8484
// no, create the symbol
85-
symbolt new_symbol;
86-
new_symbol.name=identifier;
87-
new_symbol.type=expr.type();
85+
symbolt new_symbol{identifier, expr.type(), ID_java};
8886
new_symbol.base_name=expr.get(ID_C_base_name);
8987
new_symbol.pretty_name=id2string(identifier).substr(6, std::string::npos);
90-
new_symbol.mode=ID_java;
91-
new_symbol.is_type=false;
9288

9389
if(new_symbol.type.id()==ID_code)
9490
{

jbmc/src/java_bytecode/java_entry_point.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,10 @@ void create_java_initialize(symbol_table_baset &symbol_table)
5050
// if a GOTO binary provided it. This behaviour mirrors the ANSI-C frontend.
5151
symbol_table.remove(INITIALIZE_FUNCTION);
5252

53-
symbolt initialize;
54-
initialize.name=INITIALIZE_FUNCTION;
53+
symbolt initialize{
54+
INITIALIZE_FUNCTION, java_method_typet({}, java_void_type()), ID_java};
5555
initialize.base_name=INITIALIZE_FUNCTION;
56-
initialize.mode=ID_java;
5756

58-
initialize.type = java_method_typet({}, java_void_type());
5957
symbol_table.add(initialize);
6058
}
6159

@@ -764,12 +762,10 @@ bool generate_java_start_function(
764762

765763
// create a symbol for the __CPROVER__start function, associate the code that
766764
// we just built and register it in the symbol table
767-
symbolt new_symbol;
768-
769-
new_symbol.name=goto_functionst::entry_point();
770-
new_symbol.type = java_method_typet({}, java_void_type());
765+
symbolt new_symbol{goto_functionst::entry_point(),
766+
java_method_typet({}, java_void_type()),
767+
ID_java};
771768
new_symbol.value.swap(init_code);
772-
new_symbol.mode=ID_java;
773769

774770
if(!symbol_table.insert(std::move(new_symbol)).second)
775771
{

jbmc/src/java_bytecode/java_local_variable_table.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -832,13 +832,9 @@ void java_bytecode_convert_methodt::setup_local_variables(
832832
result, v.var.start_pc, v.var.length, false, std::move(v.holes));
833833

834834
// Register the local variable in the symbol table
835-
symbolt new_symbol;
836-
new_symbol.name=identifier;
837-
new_symbol.type=t;
835+
symbolt new_symbol{identifier, t, ID_java};
838836
new_symbol.base_name=v.var.name;
839837
new_symbol.pretty_name=id2string(identifier).substr(6, std::string::npos);
840-
new_symbol.mode=ID_java;
841-
new_symbol.is_type=false;
842838
new_symbol.is_file_local=true;
843839
new_symbol.is_thread_local=true;
844840
new_symbol.is_lvalue=true;

jbmc/src/java_bytecode/java_static_initializers.cpp

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -119,18 +119,15 @@ static symbolt add_new_variable_symbol(
119119
const bool is_thread_local,
120120
const bool is_static_lifetime)
121121
{
122-
symbolt new_symbol;
123-
new_symbol.name = name;
122+
symbolt new_symbol{name, type, ID_java};
124123
new_symbol.pretty_name = name;
125124
new_symbol.base_name = name;
126-
new_symbol.type = type;
127125
new_symbol.type.set(ID_C_no_nondet_initialization, true);
128126
new_symbol.value = value;
129127
new_symbol.is_lvalue = true;
130128
new_symbol.is_state_var = true;
131129
new_symbol.is_static_lifetime = is_static_lifetime;
132130
new_symbol.is_thread_local = is_thread_local;
133-
new_symbol.mode = ID_java;
134131
symbol_table.add(new_symbol);
135132
return new_symbol;
136133
}
@@ -334,16 +331,14 @@ static void create_function_symbol(
334331
symbol_tablet &symbol_table,
335332
synthetic_methods_mapt &synthetic_methods)
336333
{
337-
symbolt function_symbol;
338-
const java_method_typet function_type({}, java_void_type());
334+
symbolt function_symbol{
335+
function_name, java_method_typet({}, java_void_type()), ID_java};
339336
function_symbol.name = function_name;
340337
function_symbol.pretty_name = function_symbol.name;
341338
function_symbol.base_name = function_base_name;
342-
function_symbol.type = function_type;
343339
// This provides a back-link from a method to its associated class, as is done
344340
// for java_bytecode_convert_methodt::convert.
345341
set_declaring_class(function_symbol, class_name);
346-
function_symbol.mode = ID_java;
347342
bool failed = symbol_table.add(function_symbol);
348343
INVARIANT(!failed, id2string(function_base_name) + " symbol should be fresh");
349344

@@ -967,14 +962,10 @@ void stub_global_initializer_factoryt::create_stub_global_initializer_symbols(
967962
"a class cannot be both incomplete, and so have stub static fields, and "
968963
"also define a static initializer");
969964

970-
const java_method_typet thunk_type({}, java_void_type());
971-
972-
symbolt static_init_symbol;
973-
static_init_symbol.name = static_init_name;
965+
symbolt static_init_symbol{
966+
static_init_name, java_method_typet({}, java_void_type()), ID_java};
974967
static_init_symbol.pretty_name = static_init_name;
975968
static_init_symbol.base_name = "clinit():V";
976-
static_init_symbol.mode = ID_java;
977-
static_init_symbol.type = thunk_type;
978969
// This provides a back-link from a method to its associated class, as is
979970
// done for java_bytecode_convert_methodt::convert.
980971
set_declaring_class(static_init_symbol, it->first);

jbmc/src/java_bytecode/java_string_library_preprocess.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,7 @@ void java_string_library_preprocesst::add_string_type(
218218
const irep_idt &class_name, symbol_tablet &symbol_table)
219219
{
220220
irep_idt class_symbol_name = "java::" + id2string(class_name);
221-
symbolt tmp_string_symbol;
222-
tmp_string_symbol.name = class_symbol_name;
221+
type_symbolt tmp_string_symbol{class_symbol_name, typet{}, ID_java};
223222
symbolt *string_symbol = nullptr;
224223
bool already_exists = symbol_table.move(tmp_string_symbol, string_symbol);
225224

@@ -247,8 +246,6 @@ void java_string_library_preprocesst::add_string_type(
247246
string_symbol->base_name = id2string(class_name);
248247
string_symbol->pretty_name = id2string(class_name);
249248
string_symbol->type = new_string_type;
250-
string_symbol->is_type = true;
251-
string_symbol->mode = ID_java;
252249
}
253250

254251
auto &string_type = to_java_class_type(string_symbol->type);

0 commit comments

Comments
 (0)