-
Notifications
You must be signed in to change notification settings - Fork 273
Resolving signature/descriptor missmatch #1489
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,7 @@ void java_bytecode_convert_method_lazy( | |
const symbolt &class_symbol, | ||
const irep_idt &method_identifier, | ||
const java_bytecode_parse_treet::methodt &, | ||
symbol_tablet &symbol_table); | ||
symbol_tablet &symbol_table, | ||
message_handlert &); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Even though it's not strictly necessary, I tend to prefer naming the parameters in the declaration - e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I asked about the general guidelines for this recently and I was told that the names can be left out unless it's not clear from the type what the parameter represents. For example, from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fine by me then :-) |
||
|
||
#endif // CPROVER_JAVA_BYTECODE_JAVA_BYTECODE_CONVERT_METHOD_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
public abstract class AbstractGenericClass<T> | ||
{ | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
public class Outer<T> | ||
{ | ||
private class Inner | ||
{ | ||
private final AbstractGenericClass<T> u; | ||
|
||
Inner (AbstractGenericClass<T> t) | ||
{ | ||
this.u = t; | ||
} | ||
} | ||
|
||
private enum InnerEnum | ||
{ | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -174,57 +174,52 @@ SCENARIO( | |
.has_symbol("java::generics$bound_element.f:()Ljava/lang/Number;")); | ||
|
||
// TODO: methods should have generic return type (the tests needs to be | ||
// extended), reintroduce when the issue of signature/descriptor for methods is | ||
// resolved | ||
// THEN("The method should have generic return type") | ||
// { | ||
// const symbolt &method_symbol= | ||
// new_symbol_table | ||
// .lookup("java::generics$bound_element.f:()Ljava/lang/Number;") | ||
// .value().get(); | ||
// const typet &symbol_type=method_symbol.type; | ||
// | ||
// REQUIRE(symbol_type.id()==ID_code); | ||
// | ||
// const code_typet &code=to_code_type(symbol_type); | ||
// } | ||
// extended) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Above comment can be removed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Incorrect - comment relates to a different issue |
||
THEN("The method should have generic return type") | ||
{ | ||
const symbolt &method_symbol= | ||
new_symbol_table | ||
.lookup_ref("java::generics$bound_element.f:()Ljava/lang/Number;"); | ||
const typet &symbol_type=method_symbol.type; | ||
|
||
REQUIRE(symbol_type.id()==ID_code); | ||
|
||
const code_typet &code=to_code_type(symbol_type); | ||
} | ||
|
||
REQUIRE( | ||
new_symbol_table | ||
.has_symbol("java::generics$bound_element.g:(Ljava/lang/Number;)V")); | ||
THEN("The method should have a generic parameter.") | ||
{ | ||
const symbolt &method_symbol= | ||
new_symbol_table | ||
.lookup_ref("java::generics$bound_element.g:(Ljava/lang/Number;)V"); | ||
const typet &symbol_type=method_symbol.type; | ||
|
||
// TODO: methods are not recognized as generic, reintroduce when | ||
// the issue of signature/descriptor for methods is resolved | ||
// THEN("The method should have a generic parameter.") | ||
// { | ||
// const symbolt &method_symbol= | ||
// new_symbol_table | ||
// .lookup("java::generics$bound_element.g:(Ljava/lang/Number;)V"); | ||
// const typet &symbol_type=method_symbol.type; | ||
// | ||
// REQUIRE(symbol_type.id()==ID_code); | ||
// | ||
// const code_typet &code=to_code_type(symbol_type); | ||
// | ||
// bool found=false; | ||
// for(const auto &p : code.parameters()) | ||
// { | ||
// if(p.get_identifier()== | ||
// "java::generics$bound_element.g:(Ljava/lang/Number;)V::e") | ||
// { | ||
// found=true; | ||
// const typet &t=p.type(); | ||
// REQUIRE(is_java_generic_parameter(p.type())); | ||
// const java_generic_parametert &gen_type= | ||
// to_java_generic_parameter(p.type()); | ||
// const symbol_typet &type_var=gen_type.type_variable(); | ||
// REQUIRE(type_var.get_identifier()== | ||
// "java::generics$bound_element::NUM"); | ||
// break; | ||
// } | ||
// } | ||
// REQUIRE(found); | ||
// } | ||
REQUIRE(symbol_type.id()==ID_code); | ||
|
||
const code_typet &code=to_code_type(symbol_type); | ||
|
||
bool found=false; | ||
for(const auto &p : code.parameters()) | ||
{ | ||
if(p.get_identifier()== | ||
"java::generics$bound_element.g:(Ljava/lang/Number;)V::e") | ||
{ | ||
found=true; | ||
const typet &t=p.type(); | ||
REQUIRE(is_java_generic_parameter(p.type())); | ||
const java_generic_parametert &gen_type= | ||
to_java_generic_parameter(p.type()); | ||
const symbol_typet &type_var=gen_type.type_variable(); | ||
REQUIRE(type_var.get_identifier()== | ||
"java::generics$bound_element::NUM"); | ||
break; | ||
} | ||
} | ||
REQUIRE(found); | ||
} | ||
} | ||
} | ||
GIVEN("A class with multiple bounds") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/*******************************************************************\ | ||
|
||
Module: Unit tests for parsing generic classes | ||
|
||
Author: DiffBlue Limited. All rights reserved. | ||
|
||
\*******************************************************************/ | ||
|
||
#include <testing-utils/catch.hpp> | ||
|
||
#include <memory> | ||
|
||
#include <util/config.h> | ||
#include <util/language.h> | ||
#include <java_bytecode/java_bytecode_language.h> | ||
#include <iostream> | ||
#include <testing-utils/load_java_class.h> | ||
#include <testing-utils/require_symbol.h> | ||
|
||
SCENARIO( | ||
"java_bytecode_parse_signature_descriptor_mismatch", | ||
"[core][java_bytecode][java_bytecode_parse_generics]") | ||
{ | ||
const symbol_tablet &new_symbol_table= | ||
load_java_class( | ||
"Outer", | ||
"./java_bytecode/java_bytecode_parse_generics"); | ||
|
||
const std::string class_prefix="java::Outer"; | ||
REQUIRE(new_symbol_table.has_symbol(class_prefix)); | ||
|
||
const std::string inner_prefix=class_prefix+"$Inner"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice :-) I should copy that pattern for my unit tests... |
||
THEN("There is a (complete) symbol for the inner class Inner") | ||
{ | ||
REQUIRE(new_symbol_table.has_symbol(inner_prefix)); | ||
|
||
const symbolt &inner_symbol=new_symbol_table.lookup_ref(inner_prefix); | ||
const class_typet &inner_class_type= | ||
require_symbol::require_complete_class(inner_symbol); | ||
} | ||
|
||
THEN("There is a symbol for the constructor of the inner class with correct" | ||
" descriptor") | ||
{ | ||
const std::string func_name=".<init>"; | ||
const std::string func_descriptor=":(LOuter;LAbstractGenericClass;)V"; | ||
const std::string process_func_name= | ||
inner_prefix+func_name+func_descriptor; | ||
REQUIRE(new_symbol_table.has_symbol(process_func_name)); | ||
|
||
const code_typet func_code= | ||
to_code_type(new_symbol_table.lookup_ref(process_func_name).type); | ||
REQUIRE(func_code.parameters().size()==3); | ||
} | ||
|
||
const std::string inner_enum_prefix=class_prefix+"$InnerEnum"; | ||
THEN("There is a (complete) symbol for the inner enum InnerEnum") | ||
{ | ||
REQUIRE(new_symbol_table.has_symbol(inner_enum_prefix)); | ||
|
||
const symbolt &inner_enum_symbol= | ||
new_symbol_table.lookup_ref(inner_enum_prefix); | ||
const class_typet &inner_enum_class_type= | ||
require_symbol::require_complete_class(inner_enum_symbol); | ||
} | ||
|
||
THEN("There is a symbol for the constructor of the inner enum with correct" | ||
" number of parameters") | ||
{ | ||
const std::string func_name=".<init>"; | ||
const std::string func_descriptor=":(Ljava/lang/String;I)V"; | ||
const std::string process_func_name= | ||
inner_enum_prefix+func_name+func_descriptor; | ||
REQUIRE(new_symbol_table.has_symbol(process_func_name)); | ||
|
||
const code_typet func_code= | ||
to_code_type(new_symbol_table.lookup_ref(process_func_name).type); | ||
REQUIRE(func_code.parameters().size()==3); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/*******************************************************************\ | ||
|
||
Module: Unit test utilities | ||
|
||
Author: DiffBlue Limited. All rights reserved. | ||
|
||
\*******************************************************************/ | ||
|
||
/// \file | ||
/// Helper functions for requiring properties of symbols | ||
|
||
#include "require_symbol.h" | ||
|
||
#include <testing-utils/catch.hpp> | ||
|
||
const class_typet &require_symbol::require_complete_class( | ||
const symbolt &class_symbol) | ||
{ | ||
REQUIRE(class_symbol.is_type); | ||
|
||
const typet &class_symbol_type=class_symbol.type; | ||
REQUIRE(class_symbol_type.id()==ID_struct); | ||
|
||
const class_typet &class_class_type=to_class_type(class_symbol_type); | ||
REQUIRE(class_class_type.is_class()); | ||
REQUIRE_FALSE(class_class_type.get_bool(ID_incomplete_class)); | ||
|
||
return class_class_type; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/*******************************************************************\ | ||
|
||
Module: Unit test utilities | ||
|
||
Author: DiffBlue Limited. All rights reserved. | ||
|
||
\*******************************************************************/ | ||
|
||
/// \file | ||
/// Helper functions for requiring properties of symbols | ||
|
||
#include <util/symbol.h> | ||
#include <util/std_types.h> | ||
|
||
#ifndef CPROVER_TESTING_UTILS_REQUIRE_SYMBOL_H | ||
#define CPROVER_TESTING_UTILS_REQUIRE_SYMBOL_H | ||
|
||
// NOLINTNEXTLINE(readability/namespace) | ||
namespace require_symbol | ||
{ | ||
const class_typet &require_complete_class( | ||
const symbolt &class_symbol); | ||
} | ||
|
||
#endif // CPROVER_TESTING_UTILS_REQUIRE_SYMBOL_H |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update the Doxygen comments for this function to reflect the extra parameter.