Skip to content

Java frontend: factor out root class initialisation #1507

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
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
11 changes: 2 additions & 9 deletions src/java_bytecode/java_bytecode_typecheck_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Author: Daniel Kroening, [email protected]
#include "java_pointer_casts.h"
#include "java_types.h"
#include "java_utils.h"
#include "java_root_class.h"

void java_bytecode_typecheckt::typecheck_expr(exprt &expr)
{
Expand Down Expand Up @@ -134,15 +135,7 @@ void java_bytecode_typecheckt::typecheck_expr_java_string_literal(exprt &expr)
const auto &jlo_struct=to_struct_type(ns.follow(jlo_symbol));
struct_exprt jlo_init(jlo_symbol);
const auto &jls_struct=to_struct_type(ns.follow(string_type));

jlo_init.copy_to_operands(
constant_exprt(
"java::java.lang.String",
jlo_struct.components()[0].type()));
jlo_init.copy_to_operands(
from_integer(
0,
jlo_struct.components()[1].type()));
java_root_class_init(jlo_init, jlo_struct, false, "java::java.lang.String");

// If string refinement *is* around, populate the actual
// contents as well:
Expand Down
25 changes: 24 additions & 1 deletion src/java_bytecode/java_root_class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ Author: Daniel Kroening, [email protected]

#include "java_root_class.h"

#include <util/arith_tools.h>
#include <util/symbol.h>
#include <util/std_types.h>

#include "java_types.h"

Expand Down Expand Up @@ -52,3 +52,26 @@ void java_root_class(symbolt &class_symbol)
components.insert(components.begin(), component);
}
}

/// Adds members for an object of the root class (usually java.lang.Object).
/// \param jlo [out] : object to initialize
/// \param root_type: type of the root class
/// \param lock: lock field
/// \param class_identifier: class identifier field
void java_root_class_init(
struct_exprt &jlo,
const struct_typet &root_type,
const bool lock,
const irep_idt &class_identifier)
{
jlo.operands().resize(root_type.components().size());

const std::size_t clsid_nb=root_type.component_number("@class_identifier");
const typet &clsid_type=root_type.components()[clsid_nb].type();
constant_exprt clsid(class_identifier, clsid_type);
jlo.operands()[clsid_nb]=clsid;

const std::size_t lock_nb=root_type.component_number("@lock");
const typet &lock_type=root_type.components()[lock_nb].type();
jlo.operands()[lock_nb]=from_integer(lock, lock_type);
}
6 changes: 6 additions & 0 deletions src/java_bytecode/java_root_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@ Author: Daniel Kroening, [email protected]
void java_root_class(
class symbolt &class_symbol);

void java_root_class_init(
struct_exprt &jlo,
const struct_typet &root_type,
bool lock,
const irep_idt &class_identifier);

#endif // CPROVER_JAVA_BYTECODE_JAVA_ROOT_CLASS_H