Skip to content

Commit b759856

Browse files
authored
Merge pull request github#3792 from calumgrant/cs/qldoc-coverage1
C#: Improve qldoc coverage
2 parents c4d43ba + 6e36096 commit b759856

File tree

5 files changed

+257
-33
lines changed

5 files changed

+257
-33
lines changed

csharp/ql/src/Concurrency/Concurrency.qll

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
// Various utilities for writing concurrency queries.
1+
/** Classes for concurrency queries. */
2+
23
import 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. */
1315
class 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. */
4955
abstract 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. */
8290
class 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() {

csharp/ql/src/Documentation/Documentation.qll

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
/** Classes representing documentation comments. */
2+
13
import csharp
24

3-
class SourceDeclaration extends Declaration {
5+
private class SourceDeclaration extends Declaration {
46
SourceDeclaration() { this.isSourceDeclaration() }
57
}
68

@@ -59,48 +61,60 @@ predicate isDocumentationNeeded(Modifiable decl) {
5961
class ReturnsXmlComment extends XmlComment {
6062
ReturnsXmlComment() { getOpenTag(_) = "returns" }
6163

64+
/** Holds if the element in this comment has a body at offset `offset`. */
6265
predicate hasBody(int offset) { hasBody("returns", offset) }
6366

67+
/** Holds if the element in this comment is an opening tag at offset `offset`. */
6468
predicate isOpenTag(int offset) { "returns" = getOpenTag(offset) }
6569

70+
/** Holds if the element in this comment is an empty tag at offset `offset`. */
6671
predicate isEmptyTag(int offset) { "returns" = getEmptyTag(offset) }
6772
}
6873

6974
/** An XML comment containing an `<exception>` tag. */
7075
class ExceptionXmlComment extends XmlComment {
7176
ExceptionXmlComment() { getOpenTag(_) = "exception" }
7277

78+
/** Gets a `cref` attribute at offset `offset`, if any. */
7379
string getCref(int offset) { result = getAttribute("exception", "cref", offset) }
7480

81+
/** Holds if the element in this comment has a body at offset `offset`. */
7582
predicate hasBody(int offset) { hasBody("exception", offset) }
7683
}
7784

7885
/** An XML comment containing a `<param>` tag. */
7986
class ParamXmlComment extends XmlComment {
8087
ParamXmlComment() { getOpenTag(_) = "param" }
8188

89+
/** Gets the name of this parameter at offset `offset`. */
8290
string getName(int offset) { getAttribute("param", "name", offset) = result }
8391

92+
/** Holds if the element in this comment has a body at offset `offset`. */
8493
predicate hasBody(int offset) { hasBody("param", offset) }
8594
}
8695

8796
/** An XML comment containing a `<typeparam>` tag. */
8897
class TypeparamXmlComment extends XmlComment {
8998
TypeparamXmlComment() { getOpenTag(_) = "typeparam" }
9099

100+
/** Gets the `name` attribute of this element at offset `offset`. */
91101
string getName(int offset) { getAttribute("typeparam", "name", offset) = result }
92102

103+
/** Holds if the element in this comment has a body at offset `offset`. */
93104
predicate hasBody(int offset) { hasBody("typeparam", offset) }
94105
}
95106

96107
/** An XML comment containing a `<summary>` tag. */
97108
class SummaryXmlComment extends XmlComment {
98109
SummaryXmlComment() { getOpenTag(_) = "summary" }
99110

111+
/** Holds if the element in this comment has a body at offset `offset`. */
100112
predicate hasBody(int offset) { hasBody("summary", offset) }
101113

114+
/** Holds if the element in this comment has an open tag at offset `offset`. */
102115
predicate isOpenTag(int offset) { "summary" = getOpenTag(offset) }
103116

117+
/** Holds if the element in this comment is empty at offset `offset`. */
104118
predicate isEmptyTag(int offset) { "summary" = getEmptyTag(offset) }
105119
}
106120

csharp/ql/src/cil.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1+
/**
2+
* The default QL library for modeling the Common Intermediate Language (CIL).
3+
*/
4+
15
import semmle.code.cil.CIL as CIL

csharp/ql/src/dotnet.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1+
/**
2+
* The default QL library for modeling .NET definitions for both C# and CIL code.
3+
*/
4+
15
import semmle.code.dotnet.DotNet as DotNet

0 commit comments

Comments
 (0)