Skip to content

Commit 93cfe02

Browse files
Refactors interface for exceptions to not use irepts.
1 parent e93eaae commit 93cfe02

File tree

6 files changed

+28
-28
lines changed

6 files changed

+28
-28
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -587,9 +587,8 @@ void java_bytecode_convert_methodt::convert(
587587
method_symbol.location=m.source_location;
588588
method_symbol.location.set_function(method_identifier);
589589

590-
std::vector<irept> &exceptions_list = method_type.throws_exceptions();
591590
for(const auto &exception_name : m.throws_exception_table)
592-
exceptions_list.push_back(irept(exception_name));
591+
method_type.add_throws_exceptions(exception_name);
593592

594593
const std::string signature_string = pretty_signature(method_type);
595594

jbmc/src/java_bytecode/java_types.h

+7-4
Original file line numberDiff line numberDiff line change
@@ -245,14 +245,17 @@ inline bool can_cast_type<java_class_typet>(const typet &type)
245245
class java_method_typet : public code_typet
246246
{
247247
public:
248-
const std::vector<irept> &throws_exceptions() const
248+
const std::vector<irep_idt> throws_exceptions() const
249249
{
250-
return find(ID_exceptions_thrown_list).get_sub();
250+
std::vector<irep_idt> exceptions;
251+
for(const auto &e : find(ID_exceptions_thrown_list).get_sub())
252+
exceptions.push_back(e.id());
253+
return exceptions;
251254
}
252255

253-
std::vector<irept> &throws_exceptions()
256+
void add_throws_exceptions(irep_idt exception)
254257
{
255-
return add(ID_exceptions_thrown_list).get_sub();
258+
add(ID_exceptions_thrown_list).get_sub().push_back(irept(exception));
256259
}
257260
};
258261

Binary file not shown.
Binary file not shown.

jbmc/unit/java_bytecode/java_bytecode_parser/ThrowsExceptions.java

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ public static void test() throws CustomException, IOException {
88
throw new CustomException();
99
}
1010

11+
public static void testNoExceptions() {
12+
StringReader sr = new StringReader("");
13+
}
14+
1115
}
1216

1317
class CustomException extends Exception {

jbmc/unit/java_bytecode/java_bytecode_parser/parse_java_attributes.cpp

+16-22
Original file line numberDiff line numberDiff line change
@@ -606,42 +606,36 @@ SCENARIO(
606606
{
607607
THEN("We should be able to get the list of exceptions it throws")
608608
{
609-
const symbolt &class_symbol =
610-
new_symbol_table.lookup_ref("java::ThrowsExceptions");
611609
const symbolt &method_symbol =
612610
new_symbol_table.lookup_ref("java::ThrowsExceptions.test:()V");
613611
const java_method_typet method =
614612
to_java_method_type(method_symbol.type);
615-
const std::vector<irept> exceptions = method.throws_exceptions();
613+
const std::vector<irep_idt> exceptions = method.throws_exceptions();
616614
REQUIRE(exceptions.size() == 2);
617615
REQUIRE(
618616
std::find(
619-
exceptions.begin(), exceptions.end(), irept("CustomException")) !=
620-
exceptions.end());
617+
exceptions.begin(),
618+
exceptions.end(),
619+
irept("CustomException").id()) != exceptions.end());
621620
REQUIRE(
622621
std::find(
623622
exceptions.begin(),
624623
exceptions.end(),
625-
irept("java.io.IOException")) != exceptions.end());
624+
irept("java.io.IOException").id()) != exceptions.end());
626625
}
627626
}
628-
}
629-
630-
const symbol_tablet &new_symbol_table2 = load_java_class(
631-
"ThrowsExceptions", "./java_bytecode/java_bytecode_parser");
632-
WHEN(
633-
"Parsing the exceptions attribute for a method that throws no exceptions")
634-
{
635-
THEN("We should be able to get the list of exceptions it throws")
627+
WHEN(
628+
"Parsing the exceptions attribute for a method that throws no exceptions")
636629
{
637-
const symbolt &class_symbol =
638-
new_symbol_table2.lookup_ref("java::ThrowsExceptions");
639-
const symbolt &method_symbol =
640-
new_symbol_table2.lookup_ref("java::ThrowsExceptions.test:()V");
641-
const java_method_typet method = to_java_method_type(method_symbol.type);
642-
const std::vector<irept> exceptions = method.throws_exceptions();
643-
REQUIRE(exceptions.size() == 0);
644-
}
630+
THEN("We should be able to get the list of exceptions it throws")
631+
{
632+
const symbolt &method_symbol = new_symbol_table.lookup_ref(
633+
"java::ThrowsExceptions.testNoExceptions:()V");
634+
const java_method_typet method =
635+
to_java_method_type(method_symbol.type);
636+
const std::vector<irep_idt> exceptions = method.throws_exceptions();
637+
REQUIRE(exceptions.size() == 0);
638+
}
645639
}
646640
}
647641
}

0 commit comments

Comments
 (0)