Skip to content

Commit 4e6d256

Browse files
committed
Replace use of deprecated nil_typet in java_type_from_string
Use optionalt<typet> as recommended in the deprecation note.
1 parent 4eb7d04 commit 4e6d256

File tree

10 files changed

+87
-85
lines changed

10 files changed

+87
-85
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_class.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ void java_bytecode_convert_classt::convert(
670670
}
671671
}
672672
else
673-
field_type=java_type_from_string(f.descriptor);
673+
field_type = *java_type_from_string(f.descriptor);
674674

675675
// is this a static field?
676676
if(f.is_static)

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 16 additions & 11 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
@@ -472,7 +477,7 @@ void java_bytecode_convert_methodt::convert(
472477
id2string(class_symbol.name));
473478
}
474479
else
475-
t=java_type_from_string(v.descriptor);
480+
t = *java_type_from_string(v.descriptor);
476481

477482
std::ostringstream id_oss;
478483
id_oss << method_id << "::" << v.name;

jbmc/src/java_bytecode/java_bytecode_parser.cpp

Lines changed: 14 additions & 16 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()
@@ -548,8 +548,8 @@ void java_bytecode_parsert::get_class_refs()
548548

549549
case CONSTANT_NameAndType:
550550
{
551-
typet t=java_type_from_string(id2string(pool_entry(c.ref2).s));
552-
get_class_refs_rec(t);
551+
const auto t = java_type_from_string(id2string(pool_entry(c.ref2).s));
552+
get_class_refs_rec(*t);
553553
}
554554
break;
555555

@@ -576,7 +576,7 @@ void java_bytecode_parsert::get_class_refs()
576576
field_type, parse_tree.class_refs);
577577
}
578578
else
579-
field_type=java_type_from_string(field.descriptor);
579+
field_type = *java_type_from_string(field.descriptor);
580580

581581
get_class_refs_rec(field_type);
582582
}
@@ -586,35 +586,34 @@ void java_bytecode_parsert::get_class_refs()
586586
get_annotation_class_refs(method.annotations);
587587
for(const auto &parameter_annotations : method.parameter_annotations)
588588
get_annotation_class_refs(parameter_annotations);
589-
typet method_type;
589+
590590
if(method.signature.has_value())
591591
{
592-
method_type=java_type_from_string_with_exception(
592+
typet method_type = java_type_from_string_with_exception(
593593
method.descriptor,
594594
method.signature,
595-
"java::"+id2string(parse_tree.parsed_class.name));
595+
"java::" + id2string(parse_tree.parsed_class.name));
596596
get_dependencies_from_generic_parameters(
597597
method_type, parse_tree.class_refs);
598+
get_class_refs_rec(method_type);
598599
}
599600
else
600-
method_type=java_type_from_string(method.descriptor);
601+
get_class_refs_rec(*java_type_from_string(method.descriptor));
601602

602-
get_class_refs_rec(method_type);
603603
for(const auto &var : method.local_variable_table)
604604
{
605-
typet var_type;
606605
if(var.signature.has_value())
607606
{
608-
var_type=java_type_from_string_with_exception(
607+
typet var_type = java_type_from_string_with_exception(
609608
var.descriptor,
610609
var.signature,
611-
"java::"+id2string(parse_tree.parsed_class.name));
610+
"java::" + id2string(parse_tree.parsed_class.name));
612611
get_dependencies_from_generic_parameters(
613612
var_type, parse_tree.class_refs);
613+
get_class_refs_rec(var_type);
614614
}
615615
else
616-
var_type=java_type_from_string(var.descriptor);
617-
get_class_refs_rec(var_type);
616+
get_class_refs_rec(*java_type_from_string(var.descriptor));
618617
}
619618
}
620619
}
@@ -672,8 +671,7 @@ void java_bytecode_parsert::get_annotation_value_class_refs(const exprt &value)
672671
if(const auto &symbol_expr = expr_try_dynamic_cast<symbol_exprt>(value))
673672
{
674673
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);
674+
get_class_refs_rec(*java_type_from_string(id2string(value_id)));
677675
}
678676
else if(const auto &array_expr = expr_try_dynamic_cast<array_exprt>(value))
679677
{

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ void java_bytecode_convert_methodt::setup_local_variables(
796796
const typet t = v.var.signature.has_value()
797797
? 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;

jbmc/src/java_bytecode/java_types.cpp

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,9 @@ std::vector<typet> parse_list_types(
339339
for(const std::string &raw_type :
340340
parse_raw_list_types(src, opening_bracket, closing_bracket))
341341
{
342-
const typet new_type = java_type_from_string(raw_type, class_name_prefix);
343-
INVARIANT(new_type != nil_typet(), "Failed to parse type");
344-
type_list.push_back(new_type);
342+
auto new_type = java_type_from_string(raw_type, class_name_prefix);
343+
INVARIANT(new_type.has_value(), "Failed to parse type");
344+
type_list.push_back(std::move(*new_type));
345345
}
346346
return type_list;
347347
}
@@ -489,12 +489,12 @@ size_t find_closing_semi_colon_for_reference_type(
489489
/// \param class_name_prefix: name of class to append to generic type
490490
/// variables/parameters
491491
/// \return internal type representation for GOTO programs
492-
typet java_type_from_string(
492+
optionalt<typet> java_type_from_string(
493493
const std::string &src,
494494
const std::string &class_name_prefix)
495495
{
496496
if(src.empty())
497-
return nil_typet();
497+
return {};
498498

499499
// a java type is encoded in different ways
500500
// - a method type is encoded as '(...)R' where the parenthesis include the
@@ -538,15 +538,15 @@ typet java_type_from_string(
538538
"Cannot currently parse bounds on generic types");
539539
}
540540

541-
const typet &method_type=java_type_from_string(
542-
src.substr(closing_generic+1, std::string::npos), class_name_prefix);
541+
auto method_type = java_type_from_string(
542+
src.substr(closing_generic + 1, std::string::npos), class_name_prefix);
543543

544544
// This invariant being violated means that tkiley has not understood
545545
// part of the signature spec.
546546
// Only class and method signatures can start with a '<' and classes are
547547
// handled separately.
548548
INVARIANT(
549-
method_type.id()==ID_code,
549+
method_type.has_value() && method_type->id() == ID_code,
550550
"This should correspond to method signatures only");
551551

552552
return method_type;
@@ -555,9 +555,9 @@ typet java_type_from_string(
555555
{
556556
std::size_t e_pos=src.rfind(')');
557557
if(e_pos==std::string::npos)
558-
return nil_typet();
558+
return {};
559559

560-
typet return_type = java_type_from_string(
560+
auto return_type = java_type_from_string(
561561
std::string(src, e_pos + 1, std::string::npos), class_name_prefix);
562562

563563
std::vector<typet> param_types =
@@ -571,26 +571,25 @@ typet java_type_from_string(
571571
std::back_inserter(parameters),
572572
[](const typet &type) { return java_method_typet::parametert(type); });
573573

574-
return java_method_typet(std::move(parameters), std::move(return_type));
574+
return java_method_typet(std::move(parameters), std::move(*return_type));
575575
}
576576

577577
case '[': // array type
578578
{
579579
// If this is a reference array, we generate a plain array[reference]
580580
// with void* members, but note the real type in ID_element_type.
581581
if(src.size()<=1)
582-
return nil_typet();
582+
return {};
583583
char subtype_letter=src[1];
584-
const typet subtype=
585-
java_type_from_string(src.substr(1, std::string::npos),
586-
class_name_prefix);
584+
auto subtype = java_type_from_string(
585+
src.substr(1, std::string::npos), class_name_prefix);
587586
if(subtype_letter=='L' || // [L denotes a reference array of some sort.
588587
subtype_letter=='[' || // Array-of-arrays
589588
subtype_letter=='T') // Array of generic types
590589
subtype_letter='A';
591590
typet tmp=java_array_type(std::tolower(subtype_letter));
592-
tmp.subtype().set(ID_element_type, subtype);
593-
return tmp;
591+
tmp.subtype().set(ID_element_type, std::move(*subtype));
592+
return std::move(tmp);
594593
}
595594

596595
case 'B': return java_byte_type();
@@ -611,7 +610,7 @@ typet java_type_from_string(
611610
return java_generic_parametert(
612611
type_var_name,
613612
to_struct_tag_type(
614-
java_type_from_string("Ljava/lang/Object;").subtype()));
613+
java_type_from_string("Ljava/lang/Object;")->subtype()));
615614
}
616615
case 'L':
617616
{
@@ -627,7 +626,7 @@ typet java_type_from_string(
627626
throw unsupported_java_class_signature_exceptiont("wild card generic");
628627
}
629628
default:
630-
return nil_typet();
629+
return {};
631630
}
632631
}
633632

@@ -712,7 +711,7 @@ std::vector<typet> java_generic_type_from_string(
712711
java_generic_parametert type_var_type(
713712
type_var_name,
714713
to_struct_tag_type(
715-
java_type_from_string(bound_type, class_name).subtype()));
714+
java_type_from_string(bound_type, class_name)->subtype()));
716715

717716
types.push_back(type_var_type);
718717
signature=signature.substr(var_sep+1, std::string::npos);
@@ -734,7 +733,7 @@ static std::string slash_to_dot(const std::string &src)
734733
struct_tag_typet java_classname(const std::string &id)
735734
{
736735
if(!id.empty() && id[0]=='[')
737-
return to_struct_tag_type(java_type_from_string(id).subtype());
736+
return to_struct_tag_type(java_type_from_string(id)->subtype());
738737

739738
std::string class_name=id;
740739

@@ -888,9 +887,9 @@ void get_dependencies_from_generic_parameters(
888887
// class signature without bounds and without wildcards
889888
else if(signature.find('*') == std::string::npos)
890889
{
891-
get_dependencies_from_generic_parameters_rec(
892-
java_type_from_string(signature, erase_type_arguments(signature)),
893-
refs);
890+
auto type_from_string =
891+
java_type_from_string(signature, erase_type_arguments(signature));
892+
get_dependencies_from_generic_parameters_rec(*type_from_string, refs);
894893
}
895894
}
896895
catch(unsupported_java_class_signature_exceptiont &)
@@ -928,9 +927,9 @@ java_generic_struct_tag_typet::java_generic_struct_tag_typet(
928927
: struct_tag_typet(type)
929928
{
930929
set(ID_C_java_generic_symbol, true);
931-
const typet &base_type = java_type_from_string(base_ref, class_name_prefix);
932-
PRECONDITION(is_java_generic_type(base_type));
933-
const java_generic_typet &gen_base_type = to_java_generic_type(base_type);
930+
const auto base_type = java_type_from_string(base_ref, class_name_prefix);
931+
PRECONDITION(is_java_generic_type(*base_type));
932+
const java_generic_typet &gen_base_type = to_java_generic_type(*base_type);
934933
INVARIANT(
935934
type.get_identifier() ==
936935
to_struct_tag_type(gen_base_type.subtype()).get_identifier(),

jbmc/src/java_bytecode/java_types.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,9 +380,9 @@ bool is_java_array_type(const typet &type);
380380
bool is_multidim_java_array_type(const typet &type);
381381

382382
typet java_type_from_char(char t);
383-
typet java_type_from_string(
383+
optionalt<typet> java_type_from_string(
384384
const std::string &,
385-
const std::string &class_name_prefix="");
385+
const std::string &class_name_prefix = "");
386386
char java_char_from_type(const typet &type);
387387
std::vector<typet> java_generic_type_from_string(
388388
const std::string &,
@@ -722,11 +722,11 @@ inline typet java_type_from_string_with_exception(
722722
{
723723
try
724724
{
725-
return java_type_from_string(signature.value(), class_name);
725+
return *java_type_from_string(signature.value(), class_name);
726726
}
727727
catch(unsupported_java_class_signature_exceptiont &)
728728
{
729-
return java_type_from_string(descriptor, class_name);
729+
return *java_type_from_string(descriptor, class_name);
730730
}
731731
}
732732

0 commit comments

Comments
 (0)