Skip to content

Commit e9b184f

Browse files
committed
C#: Avoid multiple explicit casts in stub generator.
1 parent eb90579 commit e9b184f

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

csharp/ql/src/Stubs/Stubs.qll

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -502,21 +502,28 @@ private string stubClassName(Type t) {
502502
else
503503
if t instanceof TupleType
504504
then
505-
if t.(TupleType).getArity() < 2
506-
then result = stubClassName(t.(TupleType).getUnderlyingType())
507-
else
508-
result =
509-
"(" +
510-
concat(int i, Type element |
511-
element = t.(TupleType).getElementType(i)
512-
|
513-
stubClassName(element), "," order by i
514-
) + ")"
505+
exists(TupleType tt | tt = t |
506+
if tt.getArity() < 2
507+
then result = stubClassName(tt.getUnderlyingType())
508+
else
509+
result =
510+
"(" +
511+
concat(int i, Type element |
512+
element = tt.getElementType(i)
513+
|
514+
stubClassName(element), "," order by i
515+
) + ")"
516+
)
515517
else
516518
if t instanceof FunctionPointerType
517519
then
518-
exists(CallingConvention callconvention, string calltext |
519-
callconvention = t.(FunctionPointerType).getCallingConvention() and
520+
exists(
521+
FunctionPointerType fpt, CallingConvention callconvention,
522+
string calltext
523+
|
524+
fpt = t
525+
|
526+
callconvention = fpt.getCallingConvention() and
520527
(
521528
if callconvention instanceof UnmanagedCallingConvention
522529
then calltext = "unmanaged"
@@ -525,10 +532,10 @@ private string stubClassName(Type t) {
525532
result =
526533
"delegate* " + calltext + "<" +
527534
concat(int i, Parameter p |
528-
p = t.(FunctionPointerType).getParameter(i)
535+
p = fpt.getParameter(i)
529536
|
530537
stubClassName(p.getType()) + "," order by i
531-
) + stubClassName(t.(FunctionPointerType).getReturnType()) + ">"
538+
) + stubClassName(fpt.getReturnType()) + ">"
532539
)
533540
else
534541
if t instanceof ValueOrRefType

0 commit comments

Comments
 (0)