Skip to content

Commit 5c7dcac

Browse files
Parses the exception attribute
4.7.5. The Exceptions Attribute
1 parent 7fcc42d commit 5c7dcac

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

jbmc/src/java_bytecode/java_bytecode_parse_tree.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ struct java_bytecode_parse_treet
114114
typedef std::vector<exceptiont> exception_tablet;
115115
exception_tablet exception_table;
116116

117+
std::vector<irep_idt> throws_exception_table;
118+
117119
struct local_variablet
118120
{
119121
irep_idt name;

jbmc/src/java_bytecode/java_bytecode_parser.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ class java_bytecode_parsert:public parsert
121121
void rmethod(classt &parsed_class);
122122
void
123123
rinner_classes_attribute(classt &parsed_class, const u4 &attribute_length);
124+
std::vector<irep_idt> rexceptions_attribute();
124125
void rclass_attribute(classt &parsed_class);
125126
void rRuntimeAnnotation_attribute(annotationst &);
126127
void rRuntimeAnnotation(annotationt &);
@@ -1242,6 +1243,10 @@ void java_bytecode_parsert::rmethod_attribute(methodt &method)
12421243
{
12431244
rRuntimeAnnotation_attribute(method.annotations);
12441245
}
1246+
else if(attribute_name == "Exceptions")
1247+
{
1248+
method.throws_exception_table = rexceptions_attribute();
1249+
}
12451250
else
12461251
skip_bytes(attribute_length);
12471252
}
@@ -1654,6 +1659,26 @@ void java_bytecode_parsert::rinner_classes_attribute(
16541659
}
16551660
}
16561661

1662+
/// Corresponds to the element_value structure
1663+
/// Described in Java 8 specification 4.7.5
1664+
/// https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.7.5
1665+
/// Parses the Exceptions attribute for the current method,
1666+
/// and returns a vector of exceptions.
1667+
std::vector<irep_idt> java_bytecode_parsert::rexceptions_attribute()
1668+
{
1669+
u2 number_of_exceptions = read_u2();
1670+
1671+
std::vector<irep_idt> exceptions;
1672+
for(size_t i = 0; i < number_of_exceptions; i++)
1673+
{
1674+
u2 exception_index_table = read_u2();
1675+
const irep_idt exception_name =
1676+
constant(exception_index_table).type().get(ID_C_base_name);
1677+
exceptions.push_back(exception_name);
1678+
}
1679+
return exceptions;
1680+
}
1681+
16571682
void java_bytecode_parsert::rclass_attribute(classt &parsed_class)
16581683
{
16591684
u2 attribute_name_index=read_u2();

src/util/irep_ids.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@ IREP_ID_TWO(C_array_ini, #array_ini)
694694
IREP_ID_ONE(r_ok)
695695
IREP_ID_ONE(w_ok)
696696
IREP_ID_ONE(super_class)
697+
IREP_ID_ONE(exceptions_thrown_list)
697698

698699
// Projects depending on this code base that wish to extend the list of
699700
// available ids should provide a file local_irep_ids.def in their source tree

src/util/std_types.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,16 @@ class code_typet:public typet
912912
return (parameterst &)add(ID_parameters).get_sub();
913913
}
914914

915+
const std::vector<irept> &throws_exceptions() const
916+
{
917+
return find(ID_exceptions_thrown_list).get_sub();
918+
}
919+
920+
std::vector<irept> &throws_exceptions()
921+
{
922+
return add(ID_exceptions_thrown_list).get_sub();
923+
}
924+
915925
bool get_inlined() const
916926
{
917927
return get_bool(ID_C_inlined);

0 commit comments

Comments
 (0)