1- // Various utilities for writing concurrency queries.
1+ /** Classes for concurrency queries. */
2+
23import csharp
34
4- class WaitCall extends MethodCall {
5+ private class WaitCall extends MethodCall {
56 WaitCall ( ) {
67 getTarget ( ) .hasName ( "Wait" ) and
78 getTarget ( ) .getDeclaringType ( ) .hasQualifiedName ( "System.Threading.Monitor" )
@@ -10,22 +11,24 @@ class WaitCall extends MethodCall {
1011 Expr getExpr ( ) { result = getArgument ( 0 ) }
1112}
1213
14+ /** An expression statement containing a `Wait` call. */
1315class WaitStmt extends ExprStmt {
1416 WaitStmt ( ) { getExpr ( ) instanceof WaitCall }
1517
18+ /** Gets the expression that this wait call is waiting on. */
1619 Expr getLock ( ) { result = getExpr ( ) .( WaitCall ) .getExpr ( ) }
1720
18- // If we are waiting on a variable
21+ /** Gets the variable that this wait call is waiting on, if any. */
1922 Variable getWaitVariable ( ) { result .getAnAccess ( ) = getLock ( ) }
2023
21- // If we are waiting on ' this'
24+ /** Holds if this wait call waits on ` this`. */
2225 predicate isWaitThis ( ) { getLock ( ) instanceof ThisAccess }
2326
24- // If we are waiting on a typeof()
27+ /** Gets the type that this wait call waits on, if any. */
2528 Type getWaitTypeObject ( ) { result = getLock ( ) .( TypeofExpr ) .getTypeAccess ( ) .getTarget ( ) }
2629}
2730
28- class SynchronizedMethodAttribute extends Attribute {
31+ private class SynchronizedMethodAttribute extends Attribute {
2932 SynchronizedMethodAttribute ( ) {
3033 getType ( ) .hasQualifiedName ( "System.Runtime.CompilerServices.MethodImplAttribute" ) and
3134 exists ( MemberConstantAccess a , MemberConstant mc |
@@ -37,22 +40,29 @@ class SynchronizedMethodAttribute extends Attribute {
3740 }
3841}
3942
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 {
4245 SynchronizedMethod ( ) { getAnAttribute ( ) instanceof SynchronizedMethodAttribute }
4346
47+ /** Holds if this method locks `this`. */
4448 predicate isLockThis ( ) { not isStatic ( ) }
4549
50+ /** Gets the type that is locked by this method, if any. */
4651 Type getLockTypeObject ( ) { isStatic ( ) and result = getDeclaringType ( ) }
4752}
4853
54+ /** A block that is locked by a `lock` statement. */
4955abstract class LockedBlock extends BlockStmt {
56+ /** Holds if the `lock` statement locks `this`. */
5057 abstract predicate isLockThis ( ) ;
5158
59+ /** Gets the lock variable of the `lock` statement, if any. */
5260 abstract Variable getLockVariable ( ) ;
5361
62+ /** Gets the locked type of the `lock` statement, if any. */
5463 abstract Type getLockTypeObject ( ) ;
5564
65+ /** Gets a statement in the scope of this locked block. */
5666 Stmt getALockedStmt ( ) {
5767 // Do this instead of getParent+, because we don't want to escape
5868 // delegates and lambdas
@@ -62,7 +72,7 @@ abstract class LockedBlock extends BlockStmt {
6272 }
6373}
6474
65- class LockStmtBlock extends LockedBlock {
75+ private class LockStmtBlock extends LockedBlock {
6676 LockStmtBlock ( ) { exists ( LockStmt s | this = s .getBlock ( ) ) }
6777
6878 override predicate isLockThis ( ) { exists ( LockStmt s | this = s .getBlock ( ) and s .isLockThis ( ) ) }
@@ -76,9 +86,7 @@ class LockStmtBlock extends LockedBlock {
7686 }
7787}
7888
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. */
8290class LockingCall extends MethodCall {
8391 LockingCall ( ) {
8492 this .getTarget ( ) =
@@ -91,7 +99,7 @@ class LockingCall extends MethodCall {
9199 }
92100}
93101
94- class SynchronizedMethodBlock extends LockedBlock {
102+ private class SynchronizedMethodBlock extends LockedBlock {
95103 SynchronizedMethodBlock ( ) { exists ( SynchronizedMethod m | this = m .getStatementBody ( ) ) }
96104
97105 override predicate isLockThis ( ) {
0 commit comments