Skip to content

Commit 0e6538a

Browse files
authored
Merge pull request #3929 from tautschnig/deprecation-nil_typet
Replace use of deprecated nil_typet in java_type_from_string [blocks: #3800]
2 parents 012e544 + 8f71a23 commit 0e6538a

File tree

12 files changed

+101
-112
lines changed

12 files changed

+101
-112
lines changed
Binary file not shown.

jbmc/regression/jbmc/stack_var12/stack_typecast.j

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66

77
.method public <init>()V
88
aload_0
9-
invokevirtual java/lang/Object/<init>()V
9+
invokespecial java/lang/Object/<init>()V
1010
return
1111
.end method
1212

1313
.method public f()I
1414
.limit stack 6
1515
.limit locals 1
16-
.var 0 is this stack_typecast from begin to end
16+
.var 0 is this Lstack_typecast; from begin to end
1717
.line 0
1818
begin:
1919

jbmc/src/java_bytecode/java_bytecode_convert_class.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -637,10 +637,8 @@ void java_bytecode_convert_classt::convert(
637637
typet field_type;
638638
if(f.signature.has_value())
639639
{
640-
field_type=java_type_from_string_with_exception(
641-
f.descriptor,
642-
f.signature,
643-
id2string(class_symbol.name));
640+
field_type = *java_type_from_string_with_exception(
641+
f.descriptor, f.signature, id2string(class_symbol.name));
644642

645643
/// this is for a free type variable, e.g., a field of the form `T f;`
646644
if(is_java_generic_parameter(field_type))
@@ -670,7 +668,7 @@ void java_bytecode_convert_classt::convert(
670668
}
671669
}
672670
else
673-
field_type=java_type_from_string(f.descriptor);
671+
field_type = *java_type_from_string(f.descriptor);
674672

675673
// is this a static field?
676674
if(f.is_static)

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -259,21 +259,26 @@ java_method_typet member_type_lazy(
259259

260260
messaget message(message_handler);
261261

262-
typet member_type_from_descriptor=java_type_from_string(descriptor);
263-
INVARIANT(member_type_from_descriptor.id()==ID_code, "Must be code type");
262+
auto member_type_from_descriptor = java_type_from_string(descriptor);
263+
INVARIANT(
264+
member_type_from_descriptor.has_value() &&
265+
member_type_from_descriptor->id() == ID_code,
266+
"Must be code type");
264267
if(signature.has_value())
265268
{
266269
try
267270
{
268-
typet member_type_from_signature=java_type_from_string(
269-
signature.value(),
270-
class_name);
271-
INVARIANT(member_type_from_signature.id()==ID_code, "Must be code type");
271+
auto member_type_from_signature =
272+
java_type_from_string(signature.value(), class_name);
273+
INVARIANT(
274+
member_type_from_signature.has_value() &&
275+
member_type_from_signature->id() == ID_code,
276+
"Must be code type");
272277
if(
273-
to_java_method_type(member_type_from_signature).parameters().size() ==
274-
to_java_method_type(member_type_from_descriptor).parameters().size())
278+
to_java_method_type(*member_type_from_signature).parameters().size() ==
279+
to_java_method_type(*member_type_from_descriptor).parameters().size())
275280
{
276-
return to_java_method_type(member_type_from_signature);
281+
return to_java_method_type(*member_type_from_signature);
277282
}
278283
else
279284
{
@@ -294,7 +299,7 @@ java_method_typet member_type_lazy(
294299
<< message.eom;
295300
}
296301
}
297-
return to_java_method_type(member_type_from_descriptor);
302+
return to_java_method_type(*member_type_from_descriptor);
298303
}
299304

300305
/// Retrieves the symbol of the lambda method associated with the given
@@ -460,24 +465,10 @@ void java_bytecode_convert_methodt::convert(
460465
if(!is_parameter(v))
461466
continue;
462467

463-
// Construct a fully qualified name for the parameter v,
464-
// e.g. my.package.ClassName.myMethodName:(II)I::anIntParam, and then a
465-
// symbol_exprt with the parameter and its type
466-
typet t;
467-
if(v.signature.has_value())
468-
{
469-
t=java_type_from_string_with_exception(
470-
v.descriptor,
471-
v.signature,
472-
id2string(class_symbol.name));
473-
}
474-
else
475-
t=java_type_from_string(v.descriptor);
476-
477468
std::ostringstream id_oss;
478469
id_oss << method_id << "::" << v.name;
479470
irep_idt identifier(id_oss.str());
480-
symbol_exprt result(identifier, t);
471+
symbol_exprt result = symbol_exprt::typeless(identifier);
481472
result.set(ID_C_base_name, v.name);
482473

483474
// Create a new variablet in the variables vector; in fact this entry will

jbmc/src/java_bytecode/java_bytecode_parser.cpp

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class java_bytecode_parsert:public parsert
100100

101101
const typet type_entry(u2 index)
102102
{
103-
return java_type_from_string(id2string(pool_entry(index).s));
103+
return *java_type_from_string(id2string(pool_entry(index).s));
104104
}
105105

106106
void populate_bytecode_mnemonics_table()
@@ -547,10 +547,8 @@ void java_bytecode_parsert::get_class_refs()
547547
break;
548548

549549
case CONSTANT_NameAndType:
550-
{
551-
typet t=java_type_from_string(id2string(pool_entry(c.ref2).s));
552-
get_class_refs_rec(t);
553-
}
550+
get_class_refs_rec(
551+
*java_type_from_string(id2string(pool_entry(c.ref2).s)));
554552
break;
555553

556554
default: {}
@@ -562,59 +560,63 @@ void java_bytecode_parsert::get_class_refs()
562560
for(const auto &field : parse_tree.parsed_class.fields)
563561
{
564562
get_annotation_class_refs(field.annotations);
565-
typet field_type;
563+
566564
if(field.signature.has_value())
567565
{
568-
field_type=java_type_from_string_with_exception(
566+
typet field_type = *java_type_from_string_with_exception(
569567
field.descriptor,
570568
field.signature,
571-
"java::"+id2string(parse_tree.parsed_class.name));
569+
"java::" + id2string(parse_tree.parsed_class.name));
572570

573571
// add generic type args to class refs as dependencies, same below for
574572
// method types and entries from the local variable type table
575573
get_dependencies_from_generic_parameters(
576574
field_type, parse_tree.class_refs);
575+
get_class_refs_rec(field_type);
577576
}
578577
else
579-
field_type=java_type_from_string(field.descriptor);
580-
581-
get_class_refs_rec(field_type);
578+
{
579+
get_class_refs_rec(*java_type_from_string(field.descriptor));
580+
}
582581
}
583582

584583
for(const auto &method : parse_tree.parsed_class.methods)
585584
{
586585
get_annotation_class_refs(method.annotations);
587586
for(const auto &parameter_annotations : method.parameter_annotations)
588587
get_annotation_class_refs(parameter_annotations);
589-
typet method_type;
588+
590589
if(method.signature.has_value())
591590
{
592-
method_type=java_type_from_string_with_exception(
591+
typet method_type = *java_type_from_string_with_exception(
593592
method.descriptor,
594593
method.signature,
595-
"java::"+id2string(parse_tree.parsed_class.name));
594+
"java::" + id2string(parse_tree.parsed_class.name));
596595
get_dependencies_from_generic_parameters(
597596
method_type, parse_tree.class_refs);
597+
get_class_refs_rec(method_type);
598598
}
599599
else
600-
method_type=java_type_from_string(method.descriptor);
600+
{
601+
get_class_refs_rec(*java_type_from_string(method.descriptor));
602+
}
601603

602-
get_class_refs_rec(method_type);
603604
for(const auto &var : method.local_variable_table)
604605
{
605-
typet var_type;
606606
if(var.signature.has_value())
607607
{
608-
var_type=java_type_from_string_with_exception(
608+
typet var_type = *java_type_from_string_with_exception(
609609
var.descriptor,
610610
var.signature,
611-
"java::"+id2string(parse_tree.parsed_class.name));
611+
"java::" + id2string(parse_tree.parsed_class.name));
612612
get_dependencies_from_generic_parameters(
613613
var_type, parse_tree.class_refs);
614+
get_class_refs_rec(var_type);
614615
}
615616
else
616-
var_type=java_type_from_string(var.descriptor);
617-
get_class_refs_rec(var_type);
617+
{
618+
get_class_refs_rec(*java_type_from_string(var.descriptor));
619+
}
618620
}
619621
}
620622
}
@@ -672,8 +674,7 @@ void java_bytecode_parsert::get_annotation_value_class_refs(const exprt &value)
672674
if(const auto &symbol_expr = expr_try_dynamic_cast<symbol_exprt>(value))
673675
{
674676
const irep_idt &value_id = symbol_expr->get_identifier();
675-
const typet value_type = java_type_from_string(id2string(value_id));
676-
get_class_refs_rec(value_type);
677+
get_class_refs_rec(*java_type_from_string(id2string(value_id)));
677678
}
678679
else if(const auto &array_expr = expr_try_dynamic_cast<array_exprt>(value))
679680
{

jbmc/src/java_bytecode/java_entry_point.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,14 +267,14 @@ bool is_java_main(const symbolt &function)
267267
{
268268
bool named_main = has_suffix(id2string(function.name), JAVA_MAIN_METHOD);
269269
const java_method_typet &function_type = to_java_method_type(function.type);
270-
const typet &string_array_type = java_type_from_string("[Ljava/lang/String;");
270+
const auto string_array_type = java_type_from_string("[Ljava/lang/String;");
271271
// checks whether the function is static and has a single String[] parameter
272272
bool is_static = !function_type.has_this();
273273
// this should be implied by the signature
274274
const java_method_typet::parameterst &parameters = function_type.parameters();
275275
bool has_correct_type = function_type.return_type().id() == ID_empty &&
276276
parameters.size() == 1 &&
277-
parameters[0].type().full_eq(string_array_type);
277+
parameters[0].type().full_eq(*string_array_type);
278278
bool public_access = function_type.get(ID_access) == ID_public;
279279
return named_main && is_static && has_correct_type && public_access;
280280
}

jbmc/src/java_bytecode/java_local_variable_table.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -794,9 +794,9 @@ void java_bytecode_convert_methodt::setup_local_variables(
794794
const std::string class_name = method_name.substr(0, class_name_end);
795795

796796
const typet t = v.var.signature.has_value()
797-
? java_type_from_string_with_exception(
797+
? *java_type_from_string_with_exception(
798798
v.var.descriptor, v.var.signature, class_name)
799-
: java_type_from_string(v.var.descriptor);
799+
: *java_type_from_string(v.var.descriptor);
800800

801801
std::ostringstream id_oss;
802802
id_oss << method_id << "::" << v.var.start_pc << "::" << v.var.name;

0 commit comments

Comments
 (0)