Skip to content

Do not use optionalt::value() [blocks: #6749] #6765

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 25 additions & 32 deletions jbmc/src/java_bytecode/java_bytecode_convert_class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,16 +190,15 @@ extract_generic_superclass_reference(const optionalt<std::string> &signature)
{
// skip the (potential) list of generic parameters at the beginning of the
// signature
const size_t start =
signature.value().front() == '<'
? find_closing_delimiter(signature.value(), 0, '<', '>') + 1
: 0;
const size_t start = signature->front() == '<'
? find_closing_delimiter(*signature, 0, '<', '>') + 1
: 0;

// extract the superclass reference
const size_t end =
find_closing_semi_colon_for_reference_type(signature.value(), start);
find_closing_semi_colon_for_reference_type(*signature, start);
const std::string superclass_ref =
signature.value().substr(start, (end - start) + 1);
signature->substr(start, (end - start) + 1);

// if the superclass is generic then the reference is of form
// `Lsuperclass-name<generic-types;>;` if it is implicitly generic, then the
Expand Down Expand Up @@ -231,15 +230,13 @@ static optionalt<std::string> extract_generic_interface_reference(
{
// skip the (potential) list of generic parameters at the beginning of the
// signature
size_t start =
signature.value().front() == '<'
? find_closing_delimiter(signature.value(), 0, '<', '>') + 1
: 0;
size_t start = signature->front() == '<'
? find_closing_delimiter(*signature, 0, '<', '>') + 1
: 0;

// skip the superclass reference (if there is at least one interface
// reference in the signature, then there is a superclass reference)
start =
find_closing_semi_colon_for_reference_type(signature.value(), start) + 1;
start = find_closing_semi_colon_for_reference_type(*signature, start) + 1;

// if the interface name includes package name, convert dots to slashes
std::string interface_name_slash_to_dot = interface_name;
Expand All @@ -249,13 +246,12 @@ static optionalt<std::string> extract_generic_interface_reference(
'.',
'/');

start =
signature.value().find("L" + interface_name_slash_to_dot + "<", start);
start = signature->find("L" + interface_name_slash_to_dot + "<", start);
if(start != std::string::npos)
{
const size_t &end =
find_closing_semi_colon_for_reference_type(signature.value(), start);
return signature.value().substr(start, (end - start) + 1);
find_closing_semi_colon_for_reference_type(*signature, start);
return signature->substr(start, (end - start) + 1);
}
}
return {};
Expand All @@ -277,20 +273,17 @@ void java_bytecode_convert_classt::convert(
}

java_class_typet class_type;
if(c.signature.has_value() && c.signature.value()[0]=='<')
if(c.signature.has_value() && (*c.signature)[0] == '<')
{
java_generic_class_typet generic_class_type;
#ifdef DEBUG
std::cout << "INFO: found generic class signature "
<< c.signature.value()
<< " in parsed class "
<< c.name << "\n";
std::cout << "INFO: found generic class signature " << *c.signature
<< " in parsed class " << c.name << "\n";
#endif
try
{
const std::vector<typet> &generic_types=java_generic_type_from_string(
id2string(c.name),
c.signature.value());
const std::vector<typet> &generic_types =
java_generic_type_from_string(id2string(c.name), *c.signature);
for(const typet &t : generic_types)
{
generic_class_type.generic_types()
Expand All @@ -301,9 +294,9 @@ void java_bytecode_convert_classt::convert(
catch(const unsupported_java_class_signature_exceptiont &e)
{
log.debug() << "Class: " << c.name
<< "\n could not parse signature: " << c.signature.value()
<< "\n " << e.what()
<< "\n ignoring that the class is generic" << messaget::eom;
<< "\n could not parse signature: " << *c.signature << "\n "
<< e.what() << "\n ignoring that the class is generic"
<< messaget::eom;
}
}

Expand Down Expand Up @@ -359,15 +352,15 @@ void java_bytecode_convert_classt::convert(
try
{
const java_generic_struct_tag_typet generic_base(
base, superclass_ref.value(), qualified_classname);
base, *superclass_ref, qualified_classname);
class_type.add_base(generic_base);
}
catch(const unsupported_java_class_signature_exceptiont &e)
{
log.debug() << "Superclass: " << c.super_class
<< " of class: " << c.name
<< "\n could not parse signature: "
<< superclass_ref.value() << "\n " << e.what()
<< "\n could not parse signature: " << *superclass_ref
<< "\n " << e.what()
<< "\n ignoring that the superclass is generic"
<< messaget::eom;
class_type.add_base(base);
Expand Down Expand Up @@ -401,13 +394,13 @@ void java_bytecode_convert_classt::convert(
try
{
const java_generic_struct_tag_typet generic_base(
base, interface_ref.value(), qualified_classname);
base, *interface_ref, qualified_classname);
class_type.add_base(generic_base);
}
catch(const unsupported_java_class_signature_exceptiont &e)
{
log.debug() << "Interface: " << interface << " of class: " << c.name
<< "\n could not parse signature: " << interface_ref.value()
<< "\n could not parse signature: " << *interface_ref
<< "\n " << e.what()
<< "\n ignoring that the interface is generic"
<< messaget::eom;
Expand Down
8 changes: 4 additions & 4 deletions jbmc/src/java_bytecode/java_bytecode_convert_method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ java_method_typet member_type_lazy(
try
{
auto member_type_from_signature =
java_type_from_string(signature.value(), class_name);
java_type_from_string(*signature, class_name);
INVARIANT(
member_type_from_signature.has_value() &&
member_type_from_signature->id() == ID_code,
Expand All @@ -269,7 +269,7 @@ java_method_typet member_type_lazy(
else
{
message.debug() << "Method: " << class_name << "." << method_name
<< "\n signature: " << signature.value()
<< "\n signature: " << *signature
<< "\n descriptor: " << descriptor
<< "\n different number of parameters, reverting to "
"descriptor"
Expand All @@ -279,8 +279,8 @@ java_method_typet member_type_lazy(
catch(const unsupported_java_class_signature_exceptiont &e)
{
message.debug() << "Method: " << class_name << "." << method_name
<< "\n could not parse signature: " << signature.value()
<< "\n " << e.what() << "\n"
<< "\n could not parse signature: " << *signature << "\n "
<< e.what() << "\n"
<< " reverting to descriptor: " << descriptor
<< message.eom;
}
Expand Down
8 changes: 4 additions & 4 deletions jbmc/src/java_bytecode/java_bytecode_language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,18 +338,18 @@ void java_bytecode_languaget::parse_from_main_class()
throwMainClassLoadingError(id2string(main_class));
return;
}
status() << "Trying to load Java main class: " << maybe_class_name.value()
status() << "Trying to load Java main class: " << *maybe_class_name
<< eom;
if(!java_class_loader.can_load_class(
maybe_class_name.value(), get_message_handler()))
*maybe_class_name, get_message_handler()))
{
throwMainClassLoadingError(id2string(main_class));
return;
}
// Everything went well. We have a loadable main class.
// The entry point ('main') will be checked later.
config.main = id2string(main_class);
main_class = maybe_class_name.value();
main_class = *maybe_class_name;
}
status() << "Found Java main class: " << main_class << eom;
// Now really load it.
Expand Down Expand Up @@ -403,7 +403,7 @@ bool java_bytecode_languaget::parse(
// If we have an entry method, we can derive a main class.
if(config.main.has_value())
{
const std::string &entry_method = config.main.value();
const std::string &entry_method = *config.main;
const auto last_dot_position = entry_method.find_last_of('.');
main_class = entry_method.substr(0, last_dot_position);
}
Expand Down
4 changes: 2 additions & 2 deletions jbmc/src/java_bytecode/java_entry_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,8 +557,8 @@ main_function_resultt get_main_symbol(
if(config.main.has_value())
{
std::string error_message;
irep_idt main_symbol_id = resolve_friendly_method_name(
config.main.value(), symbol_table, error_message);
irep_idt main_symbol_id =
resolve_friendly_method_name(*config.main, symbol_table, error_message);

if(main_symbol_id.empty())
{
Expand Down
2 changes: 1 addition & 1 deletion jbmc/src/java_bytecode/java_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@ inline optionalt<typet> java_type_from_string_with_exception(
{
try
{
return java_type_from_string(signature.value(), class_name);
return java_type_from_string(*signature, class_name);
}
catch(unsupported_java_class_signature_exceptiont &)
{
Expand Down
2 changes: 1 addition & 1 deletion jbmc/unit/java-testing-utils/require_goto_statements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ require_goto_statements::find_struct_component_assignments(
const member_exprt &superclass_expr =
to_member_expr(member_expr.compound());
const irep_idt supercomponent_name =
"@" + id2string(superclass_name.value());
"@" + id2string(*superclass_name);

object_descriptor_exprt ode;
const namespacet ns(symbol_table);
Expand Down
4 changes: 2 additions & 2 deletions jbmc/unit/java-testing-utils/require_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pointer_typet require_type::require_pointer(
const pointer_typet &pointer = to_pointer_type(type);

if(subtype)
REQUIRE(pointer.subtype() == subtype.value());
REQUIRE(pointer.subtype() == *subtype);

return pointer;
}
Expand Down Expand Up @@ -248,7 +248,7 @@ const typet &require_type::require_java_non_generic_type(
REQUIRE(!is_java_generic_parameter(type));
REQUIRE(!is_java_generic_type(type));
if(expect_subtype)
REQUIRE(type.subtype() == expect_subtype.value());
REQUIRE(type.subtype() == *expect_subtype);
return type;
}

Expand Down
8 changes: 4 additions & 4 deletions jbmc/unit/java_bytecode/java_types/generic_type_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ SCENARIO("generic_type_index", "[core][java_types]")
THEN("X has index 0, Y index 1 and Z is not found")
{
REQUIRE(indexX.has_value());
REQUIRE(indexX.value() == 0);
REQUIRE(*indexX == 0);
REQUIRE(index_value.has_value());
REQUIRE(index_value.value() == 1);
REQUIRE(*index_value == 1);
REQUIRE_FALSE(indexZ.has_value());
}
}
Expand Down Expand Up @@ -66,9 +66,9 @@ SCENARIO("generic_type_index", "[core][java_types]")
THEN("K has index 0, V index 1 and T is not found")
{
REQUIRE(index_param0.has_value());
REQUIRE(index_param0.value() == 0);
REQUIRE(*index_param0 == 0);
REQUIRE(index_param1.has_value());
REQUIRE(index_param1.value() == 1);
REQUIRE(*index_param1 == 1);
REQUIRE_FALSE(index_param2.has_value());
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/analyses/variable-sensitivity/abstract_environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ abstract_object_pointert abstract_environmentt::resolve_symbol(
const auto symbol_entry = map.find(symbol.get_identifier());

if(symbol_entry.has_value())
return symbol_entry.value();
return *symbol_entry;
return abstract_object_factory(expr.type(), ns, true, false);
}

Expand Down Expand Up @@ -490,7 +490,7 @@ abstract_environmentt::modified_symbols(
const auto &second_entry = second.map.find(entry.first);
if(second_entry.has_value())
{
if(second_entry.value().get()->has_been_modified(entry.second))
if(second_entry->get()->has_been_modified(entry.second))
{
CHECK_RETURN(!entry.first.empty());
symbols_diff.push_back(entry.first);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,7 @@ abstract_object_pointert full_array_abstract_objectt::write_leaf_element(
{
result->map.replace(
index.value,
abstract_objectt::merge(old_value.value(), value, widen_modet::no)
.object);
abstract_objectt::merge(*old_value, value, widen_modet::no).object);
}

DATA_INVARIANT(result->verify(), "Structural invariants maintained");
Expand Down Expand Up @@ -371,8 +370,7 @@ void full_array_abstract_objectt::map_put(
// if we're over the max_index, merge with existing value
auto replacement_value =
overrun
? abstract_objectt::merge(old_value.value(), value, widen_modet::no)
.object
? abstract_objectt::merge(*old_value, value, widen_modet::no).object
: value;

map.replace(index_value, replacement_value);
Expand All @@ -386,7 +384,7 @@ abstract_object_pointert full_array_abstract_objectt::map_find_or_top(
{
auto value = map.find(index_value);
if(value.has_value())
return value.value();
return *value;
return get_top_entry(env, ns);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ abstract_object_pointert full_struct_abstract_objectt::read_component(

if(value.has_value())
{
return value.value();
return *value;
}
else
{
Expand Down Expand Up @@ -144,8 +144,7 @@ abstract_object_pointert full_struct_abstract_objectt::write_component(
else
{
result->map.replace(
c,
environment.write(old_value.value(), value, stack, ns, merging_write));
c, environment.write(*old_value, value, stack, ns, merging_write));
}

result->set_not_top();
Expand Down Expand Up @@ -178,9 +177,7 @@ abstract_object_pointert full_struct_abstract_objectt::write_component(
}

result->map.replace(
c,
abstract_objectt::merge(old_value.value(), value, widen_modet::no)
.object);
c, abstract_objectt::merge(*old_value, value, widen_modet::no).object);
}
else
{
Expand Down Expand Up @@ -225,8 +222,8 @@ void full_struct_abstract_objectt::output(
out << ", ";
}
out << '.' << field.get_name() << '=';
static_cast<const abstract_object_pointert &>(value.value())
->output(out, ai, ns);
static_cast<const abstract_object_pointert &>(*value)->output(
out, ai, ns);
first = false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ static inline mp_integer force_value_from_expr(const exprt &value)
PRECONDITION(constant_interval_exprt::is_int(value.type()));
optionalt<mp_integer> maybe_integer_value = numeric_cast<mp_integer>(value);
INVARIANT(maybe_integer_value.has_value(), "Input has to have a value");
return maybe_integer_value.value();
return *maybe_integer_value;
}

static inline constant_interval_exprt
Expand Down
2 changes: 1 addition & 1 deletion src/analyses/variable-sensitivity/liveness_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ bool liveness_contextt::has_location() const

abstract_objectt::locationt liveness_contextt::get_location() const
{
return assign_location.value();
return *assign_location;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/ansi-c/ansi_c_entry_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ bool ansi_c_entry_point(
std::list<irep_idt> matches;

for(const auto &symbol_name_entry :
equal_range(symbol_table.symbol_base_map, config.main.value()))
equal_range(symbol_table.symbol_base_map, *config.main))
{
// look it up
symbol_tablet::symbolst::const_iterator s_it =
Expand All @@ -137,16 +137,16 @@ bool ansi_c_entry_point(
if(matches.empty())
{
messaget message(message_handler);
message.error() << "main symbol '" << config.main.value() << "' not found"
message.error() << "main symbol '" << *config.main << "' not found"
<< messaget::eom;
return true; // give up
}

if(matches.size()>=2)
{
messaget message(message_handler);
message.error() << "main symbol '" << config.main.value()
<< "' is ambiguous" << messaget::eom;
message.error() << "main symbol '" << *config.main << "' is ambiguous"
<< messaget::eom;
return true;
}

Expand Down
Loading