Skip to content

[TG-4099] Parse and capture outer class information for an inner class #2571

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

Merged
Merged
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
1 change: 1 addition & 0 deletions jbmc/src/java_bytecode/java_bytecode_convert_class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ void java_bytecode_convert_classt::convert(
class_type.set_is_inner_class(c.is_inner_class);
class_type.set_is_static_class(c.is_static_class);
class_type.set_is_anonymous_class(c.is_anonymous_class);
class_type.set_outer_class(c.outer_class);
if(c.is_enum)
{
if(max_array_length != 0 && c.enum_elements > max_array_length)
Expand Down
1 change: 1 addition & 0 deletions jbmc/src/java_bytecode/java_bytecode_parse_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ class java_bytecode_parse_treet
bool is_static_class = false;
bool is_anonymous_class = false;
bool attribute_bootstrapmethods_read = false;
irep_idt outer_class; // when no outer class is set, there is no outer class
size_t enum_elements=0;

enum class method_handle_typet
Expand Down
5 changes: 5 additions & 0 deletions jbmc/src/java_bytecode/java_bytecode_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1643,6 +1643,11 @@ void java_bytecode_parsert::rinner_classes_attribute(
}
else
{
std::string outer_class_info_name =
class_infot(pool_entry(outer_class_info_index))
.get_name(pool_entry_lambda);
parsed_class.outer_class =
constant(outer_class_info_index).type().get(ID_C_base_name);
parsed_class.is_private = is_private;
parsed_class.is_protected = is_protected;
parsed_class.is_public = is_public;
Expand Down
10 changes: 10 additions & 0 deletions jbmc/src/java_bytecode/java_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ class java_class_typet:public class_typet
return set(ID_is_inner_class, is_inner_class);
}

const irep_idt get_outer_class() const
{
return get(ID_outer_class);
}

void set_outer_class(irep_idt outer_class)
{
return set(ID_outer_class, outer_class);
}

const bool get_is_static_class() const
{
return get_bool(ID_is_static);
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
66 changes: 66 additions & 0 deletions jbmc/unit/java_bytecode/java_bytecode_parser/InnerClasses.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,72 @@ private PrivateDoublyNestedInnerClass(int i) {
}
}

class InnerPrivateClassesDeeplyNested {
private class SinglyNestedPrivateClass {
int i;
SinglyNestedPrivateClass(int i) {
this.i = i;
}
public class PublicDoublyNestedInnerClass {
public int i;
public PublicDoublyNestedInnerClass(int i) {
this.i = i;
}
}
class DefaultDoublyNestedInnerClass {
int i;
DefaultDoublyNestedInnerClass(int i) {
this.i = i;
}
}
protected class ProtectedDoublyNestedInnerClass {
protected int i;
protected ProtectedDoublyNestedInnerClass(int i) {
this.i = i;
}
}
private class PrivateDoublyNestedInnerClass {
private int i;
private PrivateDoublyNestedInnerClass(int i) {
this.i = i;
}
}
}
}

class OuterClassMostRestrictiveDeeplyNested {
public class SinglyNestedPublicClass {
int i;
SinglyNestedPublicClass(int i) {
this.i = i;
}
public class PublicDoublyNestedInnerClass {
public int i;
public PublicDoublyNestedInnerClass(int i) {
this.i = i;
}
}
class DefaultDoublyNestedInnerClass {
int i;
DefaultDoublyNestedInnerClass(int i) {
this.i = i;
}
}
protected class ProtectedDoublyNestedInnerClass {
protected int i;
protected ProtectedDoublyNestedInnerClass(int i) {
this.i = i;
}
}
private class PrivateDoublyNestedInnerClass {
private int i;
private PrivateDoublyNestedInnerClass(int i) {
this.i = i;
}
}
}
}

class ContainsAnonymousClass {
interface InnerInterface {
int i = 0;
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading