Skip to content

Commit 35cd160

Browse files
thk123svorenova
thk123
authored and
svorenova
committed
Deal with generic methods
The signature of a method can start with an angle bracket if it is a generic method on a non-generic type or a static generic method. Previously this would cause us to return a nil type rather than a code type. This information is currently ignored and instead we just skip over the Formal Type parameters and proceed using normal type evaluation.
1 parent 7320c46 commit 35cd160

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ void java_bytecode_convert_method_lazy(
273273
member_type=java_type_from_string(
274274
m.signature.value(),
275275
id2string(class_symbol.name));
276+
INVARIANT(member_type.id()==ID_code, "Must be code type");
276277
}
277278
else
278279
member_type=java_type_from_string(m.descriptor);

src/java_bytecode/java_types.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,26 @@ typet java_type_from_string(
195195
// - type variables are similar to object types but have the prefix 'T'
196196
switch(src[0])
197197
{
198+
case '<':
199+
{
200+
// The method signature can optionally have a collection of formal
201+
// type parameters (e.g. on generic methods on non-generic classes
202+
// or generic static methods). For now we skip over this part of the
203+
// signature and continue parsing the rest of the signature as normal
204+
size_t closing_generic=find_closing_delimiter(src, 0, '<', '>');
205+
const typet &method_type=java_type_from_string(
206+
src.substr(closing_generic+1, std::string::npos), class_name);
207+
208+
// This invariant being violated means that tkiley has not understood
209+
// part of the signature spec.
210+
// Only class and method signatures can start with a '<' and classes are
211+
// handled separately.
212+
INVARIANT(
213+
method_type.id()==ID_code,
214+
"This should correspond to method signatures only");
215+
216+
return method_type;
217+
}
198218
case '(': // function type
199219
{
200220
std::size_t e_pos=src.rfind(')');

0 commit comments

Comments
 (0)