1
- // Various utilities for writing concurrency queries.
1
+ /** Classes for concurrency queries. */
2
+
2
3
import csharp
3
4
4
- class WaitCall extends MethodCall {
5
+ private class WaitCall extends MethodCall {
5
6
WaitCall ( ) {
6
7
getTarget ( ) .hasName ( "Wait" ) and
7
8
getTarget ( ) .getDeclaringType ( ) .hasQualifiedName ( "System.Threading.Monitor" )
@@ -10,22 +11,24 @@ class WaitCall extends MethodCall {
10
11
Expr getExpr ( ) { result = getArgument ( 0 ) }
11
12
}
12
13
14
+ /** An expression statement containing a `Wait` call. */
13
15
class WaitStmt extends ExprStmt {
14
16
WaitStmt ( ) { getExpr ( ) instanceof WaitCall }
15
17
18
+ /** Gets the expression that this wait call is waiting on. */
16
19
Expr getLock ( ) { result = getExpr ( ) .( WaitCall ) .getExpr ( ) }
17
20
18
- // If we are waiting on a variable
21
+ /** Gets the variable that this wait call is waiting on, if any. */
19
22
Variable getWaitVariable ( ) { result .getAnAccess ( ) = getLock ( ) }
20
23
21
- // If we are waiting on ' this'
24
+ /** Holds if this wait call waits on ` this`. */
22
25
predicate isWaitThis ( ) { getLock ( ) instanceof ThisAccess }
23
26
24
- // If we are waiting on a typeof()
27
+ /** Gets the type that this wait call waits on, if any. */
25
28
Type getWaitTypeObject ( ) { result = getLock ( ) .( TypeofExpr ) .getTypeAccess ( ) .getTarget ( ) }
26
29
}
27
30
28
- class SynchronizedMethodAttribute extends Attribute {
31
+ private class SynchronizedMethodAttribute extends Attribute {
29
32
SynchronizedMethodAttribute ( ) {
30
33
getType ( ) .hasQualifiedName ( "System.Runtime.CompilerServices.MethodImplAttribute" ) and
31
34
exists ( MemberConstantAccess a , MemberConstant mc |
@@ -37,22 +40,29 @@ class SynchronizedMethodAttribute extends Attribute {
37
40
}
38
41
}
39
42
40
- // A method with attribute [MethodImpl(MethodImplOptions.Synchronized)]
41
- class SynchronizedMethod extends Method {
43
+ /** A method with attribute ` [MethodImpl(MethodImplOptions.Synchronized)]`. */
44
+ private class SynchronizedMethod extends Method {
42
45
SynchronizedMethod ( ) { getAnAttribute ( ) instanceof SynchronizedMethodAttribute }
43
46
47
+ /** Holds if this method locks `this`. */
44
48
predicate isLockThis ( ) { not isStatic ( ) }
45
49
50
+ /** Gets the type that is locked by this method, if any. */
46
51
Type getLockTypeObject ( ) { isStatic ( ) and result = getDeclaringType ( ) }
47
52
}
48
53
54
+ /** A block that is locked by a `lock` statement. */
49
55
abstract class LockedBlock extends BlockStmt {
56
+ /** Holds if the `lock` statement locks `this`. */
50
57
abstract predicate isLockThis ( ) ;
51
58
59
+ /** Gets the lock variable of the `lock` statement, if any. */
52
60
abstract Variable getLockVariable ( ) ;
53
61
62
+ /** Gets the locked type of the `lock` statement, if any. */
54
63
abstract Type getLockTypeObject ( ) ;
55
64
65
+ /** Gets a statement in the scope of this locked block. */
56
66
Stmt getALockedStmt ( ) {
57
67
// Do this instead of getParent+, because we don't want to escape
58
68
// delegates and lambdas
@@ -62,7 +72,7 @@ abstract class LockedBlock extends BlockStmt {
62
72
}
63
73
}
64
74
65
- class LockStmtBlock extends LockedBlock {
75
+ private class LockStmtBlock extends LockedBlock {
66
76
LockStmtBlock ( ) { exists ( LockStmt s | this = s .getBlock ( ) ) }
67
77
68
78
override predicate isLockThis ( ) { exists ( LockStmt s | this = s .getBlock ( ) and s .isLockThis ( ) ) }
@@ -76,9 +86,7 @@ class LockStmtBlock extends LockedBlock {
76
86
}
77
87
}
78
88
79
- /**
80
- * A call which may take a lock using one of the standard library classes.
81
- */
89
+ /** A call that may take a lock using one of the standard library methods. */
82
90
class LockingCall extends MethodCall {
83
91
LockingCall ( ) {
84
92
this .getTarget ( ) =
@@ -91,7 +99,7 @@ class LockingCall extends MethodCall {
91
99
}
92
100
}
93
101
94
- class SynchronizedMethodBlock extends LockedBlock {
102
+ private class SynchronizedMethodBlock extends LockedBlock {
95
103
SynchronizedMethodBlock ( ) { exists ( SynchronizedMethod m | this = m .getStatementBody ( ) ) }
96
104
97
105
override predicate isLockThis ( ) {
0 commit comments