Skip to content

Commit

Permalink
Give up parsing generic method signature with bound
Browse files Browse the repository at this point in the history
When the bound is in the class signature then we do the
wrong thing still
  • Loading branch information
Owen Jones committed May 24, 2018
1 parent f55bd96 commit 4551084
Show file tree
Hide file tree
Showing 9 changed files with 422 additions and 346 deletions.
12 changes: 12 additions & 0 deletions jbmc/src/java_bytecode/java_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,18 @@ typet java_type_from_string(
throw unsupported_java_class_signature_exceptiont(
"Failed to find generic signature closing delimiter");
}

// If there are any bounds between '<' and '>' then we cannot currently
// parse them, so we give up. This only happens when parsing the
// signature, so we'll fall back to the result of parsing the
// descriptor, which will respect the bounds correctly.
const size_t colon_pos = src.find(':');
if(colon_pos != std::string::npos && colon_pos < closing_generic)
{
throw unsupported_java_class_signature_exceptiont(
"Cannot currently parse bounds on generic types");
}

const typet &method_type=java_type_from_string(
src.substr(closing_generic+1, std::string::npos), class_name_prefix);

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ class Inner<E>
class BoundedInner<NUM extends java.lang.Number>
{
NUM elem;

public void f(NUM x) {
}
}

BoundedInner<Integer> belem;
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public static <T extends Interface_Implementation> void processUpperBoundClass(G

}

public static <T extends java.lang.Number> void processUpperBoundClass2(T x)
{

}

public static <T extends Interface_Implementation & Interface> void processDoubleUpperBoundClass(Generic<T> x)
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,25 @@ SCENARIO(
to_struct_type(class_symbol.type), "elem");
require_type::require_java_generic_parameter(
elem.type(), boundedinner_name + "::NUM");

std::string method_name =
boundedinner_name + ".f:(Ljava/lang/Number;)V";
REQUIRE(new_symbol_table.has_symbol(method_name));
THEN("The method parameter type should respect its bound")
{
const symbolt &method_symbol =
new_symbol_table.lookup_ref(method_name);
const code_typet &method_type =
require_type::require_code(method_symbol.type);
const code_typet::parametert &param =
require_type::require_parameter(method_type, "x");
const typet &param_type = param.type();
REQUIRE(param_type.id() == ID_pointer);
REQUIRE(param_type.subtype().id() == ID_symbol);
// REQUIRE(
// id2string(to_symbol_type(param_type.subtype()).get_identifier()) ==
// "java::java.lang.Number");
}
}
}
}
Expand Down
Loading

0 comments on commit 4551084

Please sign in to comment.