Skip to content

Commit fe9de19

Browse files
Captures information for static inner classes.
1 parent 6ce7b13 commit fe9de19

File tree

5 files changed

+76
-0
lines changed

5 files changed

+76
-0
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_class.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ void java_bytecode_convert_classt::convert(
269269
class_type.set(ID_synthetic, c.is_synthetic);
270270
class_type.set_final(c.is_final);
271271
class_type.set_is_inner_class(c.is_inner_class);
272+
class_type.set_is_static_class(c.is_static_class);
272273
if(c.is_enum)
273274
{
274275
if(max_array_length != 0 && c.enum_elements > max_array_length)

jbmc/src/java_bytecode/java_bytecode_parse_tree.h

+1
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ class java_bytecode_parse_treet
213213
bool is_synthetic = false;
214214
bool is_annotation = false;
215215
bool is_inner_class = false;
216+
bool is_static_class = false;
216217
bool attribute_bootstrapmethods_read = false;
217218
size_t enum_elements=0;
218219

jbmc/src/java_bytecode/java_bytecode_parser.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -1625,6 +1625,7 @@ void java_bytecode_parsert::rinner_classes_attribute(
16251625
bool is_private = inner_class_access_flags & ACC_PRIVATE;
16261626
bool is_public = inner_class_access_flags & ACC_PUBLIC;
16271627
bool is_protected = inner_class_access_flags & ACC_PROTECTED;
1628+
bool is_static = (inner_class_access_flags & ACC_STATIC) != 0;
16281629

16291630
// If the original parsed class name matches the inner class name,
16301631
// the parsed class is an inner class, so overwrite the parsed class'
@@ -1643,12 +1644,14 @@ void java_bytecode_parsert::rinner_classes_attribute(
16431644
parsed_class.is_private = true;
16441645
parsed_class.is_protected = false;
16451646
parsed_class.is_public = false;
1647+
parsed_class.is_static_class = is_static;
16461648
}
16471649
else
16481650
{
16491651
parsed_class.is_private = is_private;
16501652
parsed_class.is_protected = is_protected;
16511653
parsed_class.is_public = is_public;
1654+
parsed_class.is_static_class = is_static;
16521655
}
16531656
}
16541657
}

jbmc/src/java_bytecode/java_types.h

+11
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,17 @@ class java_class_typet:public class_typet
121121
return set(ID_is_inner_class, is_inner_class);
122122
}
123123

124+
const bool get_is_static_class() const
125+
{
126+
return get_bool(ID_is_static);
127+
}
128+
129+
void set_is_static_class(const bool &is_static_class)
130+
{
131+
return set(ID_is_static, is_static_class);
132+
}
133+
134+
124135
bool get_final()
125136
{
126137
return get_bool(ID_final);

jbmc/unit/java_bytecode/java_bytecode_parser/parse_java_attributes.cpp

+60
Original file line numberDiff line numberDiff line change
@@ -266,4 +266,64 @@ SCENARIO(
266266
}
267267
}
268268
}
269+
270+
GIVEN("Some class with a static inner class")
271+
{
272+
const symbol_tablet &new_symbol_table = load_java_class(
273+
"StaticInnerClass", "./java_bytecode/java_bytecode_parser");
274+
WHEN("Parsing the InnerClasses attribute for a static inner class ")
275+
{
276+
THEN("The class should be marked as static")
277+
{
278+
const symbolt &class_symbol = new_symbol_table.lookup_ref(
279+
"java::StaticInnerClass$PublicStaticInnerClass");
280+
const java_class_typet java_class =
281+
to_java_class_type(class_symbol.type);
282+
REQUIRE(java_class.get_is_inner_class());
283+
REQUIRE(java_class.get_is_static_class());
284+
}
285+
}
286+
WHEN("Parsing the InnerClasses attribute for a non-static inner class ")
287+
{
288+
THEN("The class should not be marked as static")
289+
{
290+
const symbolt &class_symbol = new_symbol_table.lookup_ref(
291+
"java::StaticInnerClass$PublicNonStaticInnerClass");
292+
const java_class_typet java_class =
293+
to_java_class_type(class_symbol.type);
294+
REQUIRE(java_class.get_is_inner_class());
295+
REQUIRE_FALSE(java_class.get_is_static_class());
296+
}
297+
}
298+
}
299+
300+
GIVEN("Some class with a static anonymous class")
301+
{
302+
const symbol_tablet &new_symbol_table = load_java_class(
303+
"StaticInnerClass", "./java_bytecode/java_bytecode_parser");
304+
WHEN("Parsing the InnerClasses attribute for a static anonymous class ")
305+
{
306+
THEN("The class should be marked as static")
307+
{
308+
const symbolt &class_symbol =
309+
new_symbol_table.lookup_ref("java::StaticInnerClass$1");
310+
const java_class_typet java_class =
311+
to_java_class_type(class_symbol.type);
312+
REQUIRE_FALSE(java_class.get_is_inner_class());
313+
REQUIRE(java_class.get_is_static_class());
314+
}
315+
}
316+
WHEN("Parsing the InnerClasses attribute for a non-static anonymous class ")
317+
{
318+
THEN("The class should not be marked as static")
319+
{
320+
const symbolt &class_symbol =
321+
new_symbol_table.lookup_ref("java::StaticInnerClass$2");
322+
const java_class_typet java_class =
323+
to_java_class_type(class_symbol.type);
324+
REQUIRE_FALSE(java_class.get_is_inner_class());
325+
REQUIRE_FALSE(java_class.get_is_static_class());
326+
}
327+
}
328+
}
269329
}

0 commit comments

Comments
 (0)