Skip to content

Clean member of #3901

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 4 commits into from
Jan 29, 2019
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
37 changes: 22 additions & 15 deletions jbmc/src/java_bytecode/java_bytecode_convert_method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -647,39 +647,46 @@ static irep_idt get_if_cmp_operator(const irep_idt &stmt)
throw "unhandled java comparison instruction";
}

static member_exprt
to_member(const exprt &pointer, const exprt &fieldref, const namespacet &ns)
/// Build a member exprt for accessing a specific field that may come from a
/// base class.
/// \param pointer: The expression to access the field on.
/// \param field_reference: A getfield/setfield instruction produced by the
/// bytecode parser.
/// \param ns: Global namespace
/// \return A member expression accessing the field, through base class
/// components if necessary.
static member_exprt to_member(
const exprt &pointer,
const exprt &field_reference,
const namespacet &ns)
{
struct_tag_typet class_type(fieldref.get(ID_class));
struct_tag_typet class_type(field_reference.get(ID_class));

const exprt typed_pointer =
typecast_exprt::conditional_cast(pointer, java_reference_type(class_type));

const irep_idt &component_name = fieldref.get(ID_component_name);
const irep_idt &component_name = field_reference.get(ID_component_name);

exprt accessed_object = checked_dereference(typed_pointer, class_type);
const auto type_of = [&ns](const exprt &object) {
return to_struct_type(ns.follow(object.type()));
};

// The field access is described as being against a particular type, but it
// may in fact belong to any ancestor type.
while(1)
while(type_of(accessed_object).get_component(component_name).is_nil())
{
struct_typet object_type =
to_struct_type(ns.follow(accessed_object.type()));
auto component = object_type.get_component(component_name);

if(component.is_not_nil())
return member_exprt(accessed_object, component);

// Component not present: check the immediate parent type.

const auto &components = object_type.components();
const auto components = type_of(accessed_object).components();
INVARIANT(
components.size() != 0,
"infer_opaque_type_fields should guarantee that a member access has a "
"corresponding field");

// Base class access is always done through the first component
accessed_object = member_exprt(accessed_object, components.front());
}
return member_exprt(
accessed_object, type_of(accessed_object).get_component(component_name));
}

/// Find all goto statements in 'repl' that target 'old_label' and redirect them
Expand Down
2 changes: 1 addition & 1 deletion src/goto-programs/remove_virtual_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ static void create_static_function_call(
call_args[i].type().id() == ID_pointer,
"where overriding function argument types differ, "
"those arguments must be pointer-typed");
call_args[i].make_typecast(need_type);
call_args[i] = typecast_exprt(call_args[i], need_type);
}
}
}
Expand Down