Skip to content

Commit 0e1ff97

Browse files
author
Daniel Kroening
committed
add signature to method pretty names
1 parent 2854fd9 commit 0e1ff97

File tree

3 files changed

+76
-16
lines changed

3 files changed

+76
-16
lines changed

src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -363,20 +363,6 @@ void java_bytecode_convert_method_lazy(
363363
else
364364
member_type.set_access(ID_default);
365365

366-
if(is_constructor(method_symbol.base_name))
367-
{
368-
// we use full.class_name.class_name(...) as pretty name
369-
// for constructors
370-
method_symbol.pretty_name=
371-
id2string(class_symbol.pretty_name)+"."+
372-
id2string(class_symbol.base_name)+"()";
373-
member_type.set_is_constructor();
374-
}
375-
else
376-
method_symbol.pretty_name=
377-
id2string(class_symbol.pretty_name)+"."+
378-
id2string(m.base_name)+"()";
379-
380366
// do we need to add 'this' as a parameter?
381367
if(!m.is_static)
382368
{
@@ -389,6 +375,23 @@ void java_bytecode_convert_method_lazy(
389375
parameters.insert(parameters.begin(), this_p);
390376
}
391377

378+
const std::string signature_string=
379+
pretty_signature(member_type);
380+
381+
if(is_constructor(method_symbol.base_name))
382+
{
383+
// we use full.class_name.class_name(...) as pretty name
384+
// for constructors
385+
method_symbol.pretty_name=
386+
id2string(class_symbol.pretty_name)+"."+
387+
id2string(class_symbol.base_name)+signature_string;
388+
member_type.set_is_constructor();
389+
}
390+
else
391+
method_symbol.pretty_name=
392+
id2string(class_symbol.pretty_name)+"."+
393+
id2string(m.base_name)+signature_string;
394+
392395
// Load annotations
393396
if(!m.annotations.empty())
394397
{

src/java_bytecode/java_types.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,3 +884,54 @@ optionalt<size_t> java_generic_symbol_typet::generic_type_index(
884884
}
885885
return {};
886886
}
887+
888+
std::string pretty_java_type(const typet &type)
889+
{
890+
if(type==java_int_type())
891+
return "int";
892+
else if(type==java_long_type())
893+
return "long";
894+
else if(type==java_short_type())
895+
return "short";
896+
else if(type==java_byte_type())
897+
return "byte";
898+
else if(type==java_char_type())
899+
return "char";
900+
else if(type==java_float_type())
901+
return "float";
902+
else if(type==java_double_type())
903+
return "double";
904+
else if(type==java_boolean_type())
905+
return "boolean";
906+
else if(type==java_byte_type())
907+
return "byte";
908+
else if(type.id()==ID_symbol)
909+
return id2string(strip_java_namespace_prefix(
910+
to_symbol_type(type).get_identifier()));
911+
else
912+
return "?";
913+
}
914+
915+
std::string pretty_signature(
916+
const code_typet &code_type)
917+
{
918+
std::ostringstream result;
919+
result << '(';
920+
921+
bool first=true;
922+
for(const auto p : code_type.parameters())
923+
{
924+
if(p.get_this())
925+
continue;
926+
927+
if(first)
928+
first=false;
929+
else
930+
result << ", ";
931+
932+
result << pretty_java_type(p.type());
933+
}
934+
935+
result << ')';
936+
return result.str();
937+
}

src/java_bytecode/java_types.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,12 +626,18 @@ inline java_generic_symbol_typet &to_java_generic_symbol_type(typet &type)
626626
/// the type to be parsed normally, for example
627627
/// `java.util.HashSet<java.lang.Integer>` will be turned into
628628
/// `java.util.HashSet`
629-
std::string erase_type_arguments(const std::string &src);
629+
std::string erase_type_arguments(const std::string &);
630630
/// Returns the full class name, skipping over the generics. This turns any of
631631
/// these:
632632
/// 1. Signature: Lcom/package/OuterClass<TT;>.Inner;
633633
/// 2. Descriptor: Lcom.pacakge.OuterClass$Inner;
634634
/// into `com.package.OuterClass.Inner`
635-
std::string gather_full_class_name(const std::string &src);
635+
std::string gather_full_class_name(const std::string &);
636+
637+
// turn java type into string
638+
std::string pretty_java_type(const typet &);
639+
640+
// pretty signature for methods
641+
std::string pretty_signature(const code_typet &);
636642

637643
#endif // CPROVER_JAVA_BYTECODE_JAVA_TYPES_H

0 commit comments

Comments
 (0)