Skip to content

add visibility information for fields and methods #847

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 1 commit into from
Apr 27, 2017
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
2 changes: 2 additions & 0 deletions src/java_bytecode/java_bytecode_convert_class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ void java_bytecode_convert_classt::convert(
component.set_access(ID_protected);
else if(f.is_public)
component.set_access(ID_public);
else
component.set_access(ID_default);
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/java_bytecode/java_bytecode_convert_method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,14 @@ void java_bytecode_convert_method_lazy(
method_symbol.mode=ID_java;
method_symbol.location=m.source_location;
method_symbol.location.set_function(method_identifier);
if(m.is_public)
member_type.set(ID_access, ID_public);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be using the same set_access API? (member_type will thus need to be converted to a more specific type than typet.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the problem is that set_access is defined for struct_union_typet and therefore is only really usable for fields here. I had thought about using a special java_typet derived from typet which could have the set_access, too. Would you prefer that?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I would like to avoid is having typet objects floating around that have ID_access set without anything ever making use of that. Notably, would equality comparison succeed on two typet with ID_access set to different values -- likely not. Thus such information should either be communicated via "#access" ("ID_C_access") or with objects of proper type and API. Maybe it takes introducing java_typet, but then this needs to propagate to, e.g., base_type_eq.

else if(m.is_protected)
member_type.set(ID_access, ID_protected);
else if(m.is_private)
member_type.set(ID_access, ID_private);
else
member_type.set(ID_access, ID_default);

if(method_symbol.base_name=="<init>")
{
Expand Down
11 changes: 11 additions & 0 deletions src/java_bytecode/java_bytecode_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,13 @@ void java_bytecode_parsert::rfields(classt &parsed_class)
field.is_final=(access_flags&ACC_FINAL)!=0;
field.is_enum=(access_flags&ACC_ENUM)!=0;
field.signature=id2string(pool_entry(descriptor_index).s);
field.is_public=(access_flags&ACC_PUBLIC)!=0;
field.is_protected=(access_flags&ACC_PROTECTED)!=0;
field.is_private=(access_flags&ACC_PRIVATE)!=0;
size_t flags=(field.is_public?1:0)+
(field.is_protected?1:0)+
(field.is_private?1:0);
assert(flags<=1);

for(std::size_t j=0; j<attributes_count; j++)
rfield_attribute(field);
Expand Down Expand Up @@ -1561,6 +1568,10 @@ void java_bytecode_parsert::rmethod(classt &parsed_class)
method.base_name=pool_entry(name_index).s;
method.signature=id2string(pool_entry(descriptor_index).s);

size_t flags=(method.is_public?1:0)+
(method.is_protected?1:0)+
(method.is_private?1:0);
assert(flags<=1);
u2 attributes_count=read_u2();

for(std::size_t j=0; j<attributes_count; j++)
Expand Down