3
3
*/
4
4
5
5
import 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
8
8
9
9
// Internal representation of call contexts
10
10
cached
11
11
private newtype TCallContext =
12
12
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
15
15
TDelegateToLibraryCallableArgCallContext ( DelegateArgumentToLibraryCallable arg , int i ) {
16
16
exists ( arg .getDelegateType ( ) .getParameter ( i ) )
17
17
}
@@ -32,6 +32,8 @@ class CallContext extends TCallContext {
32
32
/** An empty call context. */
33
33
class EmptyCallContext extends CallContext , TEmptyCallContext {
34
34
override string toString ( ) { result = "<empty>" }
35
+
36
+ override EmptyLocation getLocation ( ) { any ( ) }
35
37
}
36
38
37
39
/**
@@ -43,43 +45,40 @@ abstract class ArgumentCallContext extends CallContext {
43
45
* Holds if this call context represents the argument at position `i` of the
44
46
* call expression `call`.
45
47
*/
46
- abstract predicate isArgument ( DotNet :: Expr call , int i ) ;
48
+ abstract predicate isArgument ( Expr call , int i ) ;
47
49
}
48
50
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 ;
54
54
55
- CallArgumentCallContext ( ) { this = TArgCallContext ( c , arg ) }
55
+ NonDelegateCallArgumentCallContext ( ) { this = TArgNonDelegateCallContext ( arg ) }
56
56
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 ( ) )
60
59
}
61
60
62
- override string toString ( ) { result = c . getArgument ( arg ) .toString ( ) }
61
+ override string toString ( ) { result = arg .toString ( ) }
63
62
64
- override Location getLocation ( ) { result = c . getArgument ( arg ) .getLocation ( ) }
63
+ override Location getLocation ( ) { result = arg .getLocation ( ) }
65
64
}
66
65
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 ;
70
69
71
70
int arg ;
72
71
73
- DynamicAccessorArgumentCallContext ( ) { this = TDynamicAccessorArgCallContext ( dac , arg ) }
72
+ DelegateCallArgumentCallContext ( ) { this = TArgDelegateCallContext ( dc , arg ) }
74
73
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
77
76
i = arg
78
77
}
79
78
80
- override string toString ( ) { result = dac .getArgument ( arg ) .toString ( ) }
79
+ override string toString ( ) { result = dc .getArgument ( arg ) .toString ( ) }
81
80
82
- override Location getLocation ( ) { result = dac .getArgument ( arg ) .getLocation ( ) }
81
+ override Location getLocation ( ) { result = dc .getArgument ( arg ) .getLocation ( ) }
83
82
}
84
83
85
84
/**
@@ -93,15 +92,15 @@ class DynamicAccessorArgumentCallContext extends ArgumentCallContext, TDynamicAc
93
92
*/
94
93
class DelegateArgumentToLibraryCallableArgumentContext extends ArgumentCallContext ,
95
94
TDelegateToLibraryCallableArgCallContext {
96
- DotNet :: Expr delegate ;
95
+ Expr delegate ;
97
96
98
97
int arg ;
99
98
100
99
DelegateArgumentToLibraryCallableArgumentContext ( ) {
101
100
this = TDelegateToLibraryCallableArgCallContext ( delegate , arg )
102
101
}
103
102
104
- override predicate isArgument ( DotNet :: Expr call , int i ) {
103
+ override predicate isArgument ( Expr call , int i ) {
105
104
call = delegate and
106
105
i = arg
107
106
}
0 commit comments