Skip to content

Commit af40105

Browse files
committed
Replace all uses of deprecated nil_typet
Use typet or optionalt<typet>.
1 parent dc4ffae commit af40105

28 files changed

+181
-157
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: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -259,21 +259,21 @@ 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(member_type_from_descriptor.has_value() && member_type_from_descriptor->id()==ID_code, "Must be code type");
264264
if(signature.has_value())
265265
{
266266
try
267267
{
268-
typet member_type_from_signature=java_type_from_string(
268+
auto member_type_from_signature=java_type_from_string(
269269
signature.value(),
270270
class_name);
271-
INVARIANT(member_type_from_signature.id()==ID_code, "Must be code type");
271+
INVARIANT(member_type_from_signature.has_value() && member_type_from_signature->id()==ID_code, "Must be code type");
272272
if(
273-
to_java_method_type(member_type_from_signature).parameters().size() ==
274-
to_java_method_type(member_type_from_descriptor).parameters().size())
273+
to_java_method_type(*member_type_from_signature).parameters().size() ==
274+
to_java_method_type(*member_type_from_descriptor).parameters().size())
275275
{
276-
return to_java_method_type(member_type_from_signature);
276+
return to_java_method_type(*member_type_from_signature);
277277
}
278278
else
279279
{
@@ -294,7 +294,7 @@ java_method_typet member_type_lazy(
294294
<< message.eom;
295295
}
296296
}
297-
return to_java_method_type(member_type_from_descriptor);
297+
return to_java_method_type(*member_type_from_descriptor);
298298
}
299299

300300
/// Retrieves the symbol of the lambda method associated with the given
@@ -472,7 +472,7 @@ void java_bytecode_convert_methodt::convert(
472472
id2string(class_symbol.name));
473473
}
474474
else
475-
t=java_type_from_string(v.descriptor);
475+
t=*java_type_from_string(v.descriptor);
476476

477477
std::ostringstream id_oss;
478478
id_oss << method_id << "::" << v.name;

jbmc/src/java_bytecode/java_bytecode_parser.cpp

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ 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+
auto type_from_string = java_type_from_string(id2string(pool_entry(index).s));
104+
CHECK_RETURN(type_from_string.has_value());
105+
return std::move(*type_from_string);
104106
}
105107

106108
void populate_bytecode_mnemonics_table()
@@ -548,8 +550,9 @@ void java_bytecode_parsert::get_class_refs()
548550

549551
case CONSTANT_NameAndType:
550552
{
551-
typet t=java_type_from_string(id2string(pool_entry(c.ref2).s));
552-
get_class_refs_rec(t);
553+
const auto t=java_type_from_string(id2string(pool_entry(c.ref2).s));
554+
CHECK_RETURN(t.has_value());
555+
get_class_refs_rec(*t);
553556
}
554557
break;
555558

@@ -576,7 +579,11 @@ void java_bytecode_parsert::get_class_refs()
576579
field_type, parse_tree.class_refs);
577580
}
578581
else
579-
field_type=java_type_from_string(field.descriptor);
582+
{
583+
auto type_from_string = java_type_from_string(field.descriptor);
584+
CHECK_RETURN(type_from_string.has_value());
585+
field_type=std::move(*type_from_string);
586+
}
580587

581588
get_class_refs_rec(field_type);
582589
}
@@ -597,7 +604,11 @@ void java_bytecode_parsert::get_class_refs()
597604
method_type, parse_tree.class_refs);
598605
}
599606
else
600-
method_type=java_type_from_string(method.descriptor);
607+
{
608+
auto type_from_string = java_type_from_string(method.descriptor);
609+
CHECK_RETURN(type_from_string.has_value());
610+
method_type=std::move(*type_from_string);
611+
}
601612

602613
get_class_refs_rec(method_type);
603614
for(const auto &var : method.local_variable_table)
@@ -613,7 +624,11 @@ void java_bytecode_parsert::get_class_refs()
613624
var_type, parse_tree.class_refs);
614625
}
615626
else
616-
var_type=java_type_from_string(var.descriptor);
627+
{
628+
auto type_from_string = java_type_from_string(var.descriptor);
629+
CHECK_RETURN(type_from_string.has_value());
630+
var_type=std::move(*type_from_string);
631+
}
617632
get_class_refs_rec(var_type);
618633
}
619634
}
@@ -672,8 +687,9 @@ void java_bytecode_parsert::get_annotation_value_class_refs(const exprt &value)
672687
if(const auto &symbol_expr = expr_try_dynamic_cast<symbol_exprt>(value))
673688
{
674689
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);
690+
const auto value_type = java_type_from_string(id2string(value_id));
691+
CHECK_RETURN(value_type.has_value());
692+
get_class_refs_rec(*value_type);
677693
}
678694
else if(const auto &array_expr = expr_try_dynamic_cast<array_exprt>(value))
679695
{

jbmc/src/java_bytecode/java_entry_point.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,14 +267,15 @@ 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;");
271+
CHECK_RETURN(string_array_type.has_value());
271272
// checks whether the function is static and has a single String[] parameter
272273
bool is_static = !function_type.has_this();
273274
// this should be implied by the signature
274275
const java_method_typet::parameterst &parameters = function_type.parameters();
275276
bool has_correct_type = function_type.return_type().id() == ID_empty &&
276277
parameters.size() == 1 &&
277-
parameters[0].type().full_eq(string_array_type);
278+
parameters[0].type().full_eq(*string_array_type);
278279
bool public_access = function_type.get(ID_access) == ID_public;
279280
return named_main && is_static && has_correct_type && public_access;
280281
}

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: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ typet java_type_from_char(char t)
199199
case 'd': return java_double_type();
200200
case 'z': return java_boolean_type();
201201
case 'a': return java_reference_type(void_typet());
202-
default: UNREACHABLE; return nil_typet();
202+
default: UNREACHABLE;
203203
}
204204
}
205205

@@ -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(
541+
auto method_type=java_type_from_string(
542542
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,10 +555,11 @@ 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);
562+
CHECK_RETURN(return_type.has_value());
562563

563564
std::vector<typet> param_types =
564565
parse_list_types(src.substr(0, e_pos + 1), class_name_prefix, '(', ')');
@@ -571,26 +572,27 @@ typet java_type_from_string(
571572
std::back_inserter(parameters),
572573
[](const typet &type) { return java_method_typet::parametert(type); });
573574

574-
return java_method_typet(std::move(parameters), std::move(return_type));
575+
return java_method_typet(std::move(parameters), std::move(*return_type));
575576
}
576577

577578
case '[': // array type
578579
{
579580
// If this is a reference array, we generate a plain array[reference]
580581
// with void* members, but note the real type in ID_element_type.
581582
if(src.size()<=1)
582-
return nil_typet();
583+
return {};
583584
char subtype_letter=src[1];
584-
const typet subtype=
585+
auto subtype=
585586
java_type_from_string(src.substr(1, std::string::npos),
586587
class_name_prefix);
588+
CHECK_RETURN(subtype.has_value());
587589
if(subtype_letter=='L' || // [L denotes a reference array of some sort.
588590
subtype_letter=='[' || // Array-of-arrays
589591
subtype_letter=='T') // Array of generic types
590592
subtype_letter='A';
591593
typet tmp=java_array_type(std::tolower(subtype_letter));
592-
tmp.subtype().set(ID_element_type, subtype);
593-
return tmp;
594+
tmp.subtype().set(ID_element_type, std::move(*subtype));
595+
return std::move(tmp);
594596
}
595597

596598
case 'B': return java_byte_type();
@@ -611,7 +613,7 @@ typet java_type_from_string(
611613
return java_generic_parametert(
612614
type_var_name,
613615
to_struct_tag_type(
614-
java_type_from_string("Ljava/lang/Object;").subtype()));
616+
java_type_from_string("Ljava/lang/Object;")->subtype()));
615617
}
616618
case 'L':
617619
{
@@ -627,7 +629,7 @@ typet java_type_from_string(
627629
throw unsupported_java_class_signature_exceptiont("wild card generic");
628630
}
629631
default:
630-
return nil_typet();
632+
return {};
631633
}
632634
}
633635

@@ -712,7 +714,7 @@ std::vector<typet> java_generic_type_from_string(
712714
java_generic_parametert type_var_type(
713715
type_var_name,
714716
to_struct_tag_type(
715-
java_type_from_string(bound_type, class_name).subtype()));
717+
java_type_from_string(bound_type, class_name)->subtype()));
716718

717719
types.push_back(type_var_type);
718720
signature=signature.substr(var_sep+1, std::string::npos);
@@ -734,7 +736,7 @@ static std::string slash_to_dot(const std::string &src)
734736
struct_tag_typet java_classname(const std::string &id)
735737
{
736738
if(!id.empty() && id[0]=='[')
737-
return to_struct_tag_type(java_type_from_string(id).subtype());
739+
return to_struct_tag_type(java_type_from_string(id)->subtype());
738740

739741
std::string class_name=id;
740742

@@ -888,8 +890,10 @@ void get_dependencies_from_generic_parameters(
888890
// class signature without bounds and without wildcards
889891
else if(signature.find('*') == std::string::npos)
890892
{
893+
auto type_from_string = java_type_from_string(signature, erase_type_arguments(signature));
894+
CHECK_RETURN(type_from_string.has_value());
891895
get_dependencies_from_generic_parameters_rec(
892-
java_type_from_string(signature, erase_type_arguments(signature)),
896+
*type_from_string,
893897
refs);
894898
}
895899
}
@@ -928,9 +932,10 @@ java_generic_struct_tag_typet::java_generic_struct_tag_typet(
928932
: struct_tag_typet(type)
929933
{
930934
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);
935+
const auto base_type = java_type_from_string(base_ref, class_name_prefix);
936+
CHECK_RETURN(base_type.has_value());
937+
PRECONDITION(is_java_generic_type(*base_type));
938+
const java_generic_typet &gen_base_type = to_java_generic_type(*base_type);
934939
INVARIANT(
935940
type.get_identifier() ==
936941
to_struct_tag_type(gen_base_type.subtype()).get_identifier(),

jbmc/src/java_bytecode/java_types.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ 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 &,
385385
const std::string &class_name_prefix="");
386386
char java_char_from_type(const typet &type);
@@ -722,11 +722,15 @@ inline typet java_type_from_string_with_exception(
722722
{
723723
try
724724
{
725-
return java_type_from_string(signature.value(), class_name);
725+
const auto type_from_string = java_type_from_string(signature.value(), class_name);
726+
CHECK_RETURN(type_from_string.has_value());
727+
return *type_from_string;
726728
}
727729
catch(unsupported_java_class_signature_exceptiont &)
728730
{
729-
return java_type_from_string(descriptor, class_name);
731+
const auto type_from_string = java_type_from_string(descriptor, class_name);
732+
CHECK_RETURN(type_from_string.has_value());
733+
return *type_from_string;
730734
}
731735
}
732736

0 commit comments

Comments
 (0)