33 */
44
55import csharp
6- private import semmle.code.csharp.dataflow.DelegateDataFlow
7- private import dotnet
6+ private import semmle.code.csharp.dataflow.internal. DelegateDataFlow
7+ private import semmle.code.csharp.dispatch.Dispatch
88
99// Internal representation of call contexts
1010cached
1111private newtype TCallContext =
1212 TEmptyCallContext ( ) or
13- TArgCallContext ( DotNet :: Call c , int i ) { exists ( c .getArgument ( i ) ) } or
14- TDynamicAccessorArgCallContext ( DynamicAccessorCall dac , int i ) { exists ( dac .getArgument ( i ) ) } or
13+ TArgNonDelegateCallContext ( Expr arg ) { exists ( DispatchCall dc | arg = dc .getArgument ( _ ) ) } or
14+ TArgDelegateCallContext ( DelegateCall dc , int i ) { exists ( dc .getArgument ( i ) ) } or
1515 TDelegateToLibraryCallableArgCallContext ( DelegateArgumentToLibraryCallable arg , int i ) {
1616 exists ( arg .getDelegateType ( ) .getParameter ( i ) )
1717 }
@@ -32,6 +32,8 @@ class CallContext extends TCallContext {
3232/** An empty call context. */
3333class EmptyCallContext extends CallContext , TEmptyCallContext {
3434 override string toString ( ) { result = "<empty>" }
35+
36+ override EmptyLocation getLocation ( ) { any ( ) }
3537}
3638
3739/**
@@ -43,43 +45,40 @@ abstract class ArgumentCallContext extends CallContext {
4345 * Holds if this call context represents the argument at position `i` of the
4446 * call expression `call`.
4547 */
46- abstract predicate isArgument ( DotNet :: Expr call , int i ) ;
48+ abstract predicate isArgument ( Expr call , int i ) ;
4749}
4850
49- /** An argument of an ordinary call. */
50- class CallArgumentCallContext extends ArgumentCallContext , TArgCallContext {
51- DotNet:: Call c ;
52-
53- int arg ;
51+ /** An argument of a non-delegate call. */
52+ class NonDelegateCallArgumentCallContext extends ArgumentCallContext , TArgNonDelegateCallContext {
53+ Expr arg ;
5454
55- CallArgumentCallContext ( ) { this = TArgCallContext ( c , arg ) }
55+ NonDelegateCallArgumentCallContext ( ) { this = TArgNonDelegateCallContext ( arg ) }
5656
57- override predicate isArgument ( DotNet:: Expr call , int i ) {
58- call = c and
59- i = arg
57+ override predicate isArgument ( Expr call , int i ) {
58+ exists ( DispatchCall dc | arg = dc .getArgument ( i ) | call = dc .getCall ( ) )
6059 }
6160
62- override string toString ( ) { result = c . getArgument ( arg ) .toString ( ) }
61+ override string toString ( ) { result = arg .toString ( ) }
6362
64- override Location getLocation ( ) { result = c . getArgument ( arg ) .getLocation ( ) }
63+ override Location getLocation ( ) { result = arg .getLocation ( ) }
6564}
6665
67- /** An argument of a dynamic accessor call. */
68- class DynamicAccessorArgumentCallContext extends ArgumentCallContext , TDynamicAccessorArgCallContext {
69- DynamicAccessorCall dac ;
66+ /** An argument of a delegate call. */
67+ class DelegateCallArgumentCallContext extends ArgumentCallContext , TArgDelegateCallContext {
68+ DelegateCall dc ;
7069
7170 int arg ;
7271
73- DynamicAccessorArgumentCallContext ( ) { this = TDynamicAccessorArgCallContext ( dac , arg ) }
72+ DelegateCallArgumentCallContext ( ) { this = TArgDelegateCallContext ( dc , arg ) }
7473
75- override predicate isArgument ( DotNet :: Expr call , int i ) {
76- call = dac and
74+ override predicate isArgument ( Expr call , int i ) {
75+ call = dc and
7776 i = arg
7877 }
7978
80- override string toString ( ) { result = dac .getArgument ( arg ) .toString ( ) }
79+ override string toString ( ) { result = dc .getArgument ( arg ) .toString ( ) }
8180
82- override Location getLocation ( ) { result = dac .getArgument ( arg ) .getLocation ( ) }
81+ override Location getLocation ( ) { result = dc .getArgument ( arg ) .getLocation ( ) }
8382}
8483
8584/**
@@ -93,15 +92,15 @@ class DynamicAccessorArgumentCallContext extends ArgumentCallContext, TDynamicAc
9392 */
9493class DelegateArgumentToLibraryCallableArgumentContext extends ArgumentCallContext ,
9594 TDelegateToLibraryCallableArgCallContext {
96- DotNet :: Expr delegate ;
95+ Expr delegate ;
9796
9897 int arg ;
9998
10099 DelegateArgumentToLibraryCallableArgumentContext ( ) {
101100 this = TDelegateToLibraryCallableArgCallContext ( delegate , arg )
102101 }
103102
104- override predicate isArgument ( DotNet :: Expr call , int i ) {
103+ override predicate isArgument ( Expr call , int i ) {
105104 call = delegate and
106105 i = arg
107106 }
0 commit comments