Skip to content

Commit a166a4d

Browse files
author
Dave Bartolomeo
committed
C++: A few IR QLDoc comments
1 parent 4ce896b commit a166a4d

File tree

9 files changed

+124
-0
lines changed

9 files changed

+124
-0
lines changed

cpp/ql/src/semmle/code/cpp/ir/implementation/EdgeKind.qll

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ private newtype TEdgeKind =
1717
* `EdgeKind`.
1818
*/
1919
abstract class EdgeKind extends TEdgeKind {
20+
/** Gets a textual representation of this edge kind. */
2021
abstract string toString();
2122
}
2223

@@ -28,6 +29,10 @@ class GotoEdge extends EdgeKind, TGotoEdge {
2829
final override string toString() { result = "Goto" }
2930
}
3031

32+
/**
33+
* Gets the single instance of `GotoEdge`, representing the unconditional successor of an
34+
* `Instruction`
35+
*/
3136
GotoEdge gotoEdge() { result = TGotoEdge() }
3237

3338
/**
@@ -38,6 +43,10 @@ class TrueEdge extends EdgeKind, TTrueEdge {
3843
final override string toString() { result = "True" }
3944
}
4045

46+
/**
47+
* Gets the single instance of `TrueEdge`, representing the successor of a conditional branch when
48+
* the condition is non-zero.
49+
*/
4150
TrueEdge trueEdge() { result = TTrueEdge() }
4251

4352
/**
@@ -48,6 +57,10 @@ class FalseEdge extends EdgeKind, TFalseEdge {
4857
final override string toString() { result = "False" }
4958
}
5059

60+
/**
61+
* Gets the single instance of `FalseEdge`, representing the successor of a conditional branch when
62+
* the condition is zero.
63+
*/
5164
FalseEdge falseEdge() { result = TFalseEdge() }
5265

5366
/**
@@ -58,6 +71,10 @@ class ExceptionEdge extends EdgeKind, TExceptionEdge {
5871
final override string toString() { result = "Exception" }
5972
}
6073

74+
/**
75+
* Gets the single instance of `ExceptionEdge`, representing the successor of an instruction when
76+
* that instruction's evaluation throws an exception.
77+
*/
6178
ExceptionEdge exceptionEdge() { result = TExceptionEdge() }
6279

6380
/**
@@ -68,6 +85,10 @@ class DefaultEdge extends EdgeKind, TDefaultEdge {
6885
final override string toString() { result = "Default" }
6986
}
7087

88+
/**
89+
* Gets the single instance of `DefaultEdge`, representing the successor of a `Switch` instruction
90+
* when none of the case values matches the condition value.
91+
*/
7192
DefaultEdge defaultEdge() { result = TDefaultEdge() }
7293

7394
/**
@@ -91,4 +112,8 @@ class CaseEdge extends EdgeKind, TCaseEdge {
91112
string getMaxValue() { result = maxValue }
92113
}
93114

115+
/**
116+
* Gets the `CaseEdge` representing the successor of a `Switch` instruction corresponding to the
117+
* `case` label with the specified lower and upper bounds.
118+
*/
94119
CaseEdge caseEdge(string minValue, string maxValue) { result = TCaseEdge(minValue, maxValue) }
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1+
/**
2+
* Defines the public interface to temporary variable tags, which describe the reason a particular
3+
* `IRTempVariable` was generated.
4+
*/
15
private import internal.TempVariableTagInternal
26
private import Imports::TempVariableTag
37

8+
/**
9+
* Describes the reason that a particular IR temporary variable was generated. For example, it could
10+
* be generated to hold the return value of a function, or to hold the result of a `?:` operator
11+
* computed on each branch. The set of possible `TempVariableTag`s is language-dependent.
12+
*/
413
class TempVariableTag extends TTempVariableTag {
514
string toString() { result = getTempVariableTagId(this) }
615
}

cpp/ql/src/semmle/code/cpp/ir/implementation/internal/OperandTag.qll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* Defines the set of possible `OperandTag`s, which are used to identify the role each `Operand`
3+
* plays in the evaluation of its `Instruction`.
4+
*/
15
private import OperandTagInternal
26

37
private newtype TOperandTag =
@@ -24,10 +28,18 @@ private newtype TOperandTag =
2428
* an `Instruction` is determined by the instruction's opcode.
2529
*/
2630
abstract class OperandTag extends TOperandTag {
31+
/** Gets a textual representation of this operand tag */
2732
abstract string toString();
2833

34+
/**
35+
* Gets an integer representing the order in which this operand should appear in the operand list
36+
* of an instruction when printing the IR.
37+
*/
2938
abstract int getSortOrder();
3039

40+
/**
41+
* Gets a label that will appear before the operand when printing the IR.
42+
*/
3143
string getLabel() { result = "" }
3244
}
3345

cpp/ql/src/semmle/code/cpp/ir/internal/CppType.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ private newtype TCppType =
203203
* of a `VariableAddress` where the variable is of reference type)
204204
*/
205205
class CppType extends TCppType {
206+
/** Gets a textual representation of this type. */
206207
string toString() { none() }
207208

208209
/** Gets a string used in IR dumps */
@@ -224,6 +225,10 @@ class CppType extends TCppType {
224225
*/
225226
predicate hasType(Type type, boolean isGLValue) { none() }
226227

228+
/**
229+
* Holds if this type represents the C++ type `type`. If `isGLValue` is `true`, then this type
230+
* represents a glvalue of type `type`. Otherwise, it represents a prvalue of type `type`.
231+
*/
227232
final predicate hasUnspecifiedType(Type type, boolean isGLValue) {
228233
exists(Type specifiedType |
229234
hasType(specifiedType, isGLValue) and
@@ -540,6 +545,9 @@ string getOpaqueTagIdentityString(Type tag) {
540545
}
541546

542547
module LanguageTypeSanity {
548+
/**
549+
* Sanity query to detect C++ `Type` objects which have no corresponding `CppType` object.
550+
*/
543551
query predicate missingCppType(Type type, string message) {
544552
not exists(getTypeForPRValue(type)) and
545553
exists(type.getSize()) and

cpp/ql/src/semmle/code/cpp/ir/internal/IntegerConstant.qll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
/**
2+
* Provides predicates for manipulating integer constants tracked by constant folding and similar
3+
* analyses.
4+
*/
5+
6+
/**
7+
* An alias used to represent the constant value of an integer, if one can be determined. If no
8+
* single constant value can be determined, or if the constant value is out of the representable
9+
* range, it will be represented as the special value `unknown()`. This allows `IntValue` to be used
10+
* in contexts where there must always be a value for the `IntValue`, even if no constant value is
11+
* known.
12+
*/
113
class IntValue = int;
214

315
/**

csharp/ql/src/semmle/code/csharp/ir/implementation/EdgeKind.qll

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ private newtype TEdgeKind =
1717
* `EdgeKind`.
1818
*/
1919
abstract class EdgeKind extends TEdgeKind {
20+
/** Gets a textual representation of this edge kind. */
2021
abstract string toString();
2122
}
2223

@@ -28,6 +29,10 @@ class GotoEdge extends EdgeKind, TGotoEdge {
2829
final override string toString() { result = "Goto" }
2930
}
3031

32+
/**
33+
* Gets the single instance of `GotoEdge`, representing the unconditional successor of an
34+
* `Instruction`
35+
*/
3136
GotoEdge gotoEdge() { result = TGotoEdge() }
3237

3338
/**
@@ -38,6 +43,10 @@ class TrueEdge extends EdgeKind, TTrueEdge {
3843
final override string toString() { result = "True" }
3944
}
4045

46+
/**
47+
* Gets the single instance of `TrueEdge`, representing the successor of a conditional branch when
48+
* the condition is non-zero.
49+
*/
4150
TrueEdge trueEdge() { result = TTrueEdge() }
4251

4352
/**
@@ -48,6 +57,10 @@ class FalseEdge extends EdgeKind, TFalseEdge {
4857
final override string toString() { result = "False" }
4958
}
5059

60+
/**
61+
* Gets the single instance of `FalseEdge`, representing the successor of a conditional branch when
62+
* the condition is zero.
63+
*/
5164
FalseEdge falseEdge() { result = TFalseEdge() }
5265

5366
/**
@@ -58,6 +71,10 @@ class ExceptionEdge extends EdgeKind, TExceptionEdge {
5871
final override string toString() { result = "Exception" }
5972
}
6073

74+
/**
75+
* Gets the single instance of `ExceptionEdge`, representing the successor of an instruction when
76+
* that instruction's evaluation throws an exception.
77+
*/
6178
ExceptionEdge exceptionEdge() { result = TExceptionEdge() }
6279

6380
/**
@@ -68,6 +85,10 @@ class DefaultEdge extends EdgeKind, TDefaultEdge {
6885
final override string toString() { result = "Default" }
6986
}
7087

88+
/**
89+
* Gets the single instance of `DefaultEdge`, representing the successor of a `Switch` instruction
90+
* when none of the case values matches the condition value.
91+
*/
7192
DefaultEdge defaultEdge() { result = TDefaultEdge() }
7293

7394
/**
@@ -91,4 +112,8 @@ class CaseEdge extends EdgeKind, TCaseEdge {
91112
string getMaxValue() { result = maxValue }
92113
}
93114

115+
/**
116+
* Gets the `CaseEdge` representing the successor of a `Switch` instruction corresponding to the
117+
* `case` label with the specified lower and upper bounds.
118+
*/
94119
CaseEdge caseEdge(string minValue, string maxValue) { result = TCaseEdge(minValue, maxValue) }
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1+
/**
2+
* Defines the public interface to temporary variable tags, which describe the reason a particular
3+
* `IRTempVariable` was generated.
4+
*/
15
private import internal.TempVariableTagInternal
26
private import Imports::TempVariableTag
37

8+
/**
9+
* Describes the reason that a particular IR temporary variable was generated. For example, it could
10+
* be generated to hold the return value of a function, or to hold the result of a `?:` operator
11+
* computed on each branch. The set of possible `TempVariableTag`s is language-dependent.
12+
*/
413
class TempVariableTag extends TTempVariableTag {
514
string toString() { result = getTempVariableTagId(this) }
615
}

csharp/ql/src/semmle/code/csharp/ir/implementation/internal/OperandTag.qll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* Defines the set of possible `OperandTag`s, which are used to identify the role each `Operand`
3+
* plays in the evaluation of its `Instruction`.
4+
*/
15
private import OperandTagInternal
26

37
private newtype TOperandTag =
@@ -24,10 +28,18 @@ private newtype TOperandTag =
2428
* an `Instruction` is determined by the instruction's opcode.
2529
*/
2630
abstract class OperandTag extends TOperandTag {
31+
/** Gets a textual representation of this operand tag */
2732
abstract string toString();
2833

34+
/**
35+
* Gets an integer representing the order in which this operand should appear in the operand list
36+
* of an instruction when printing the IR.
37+
*/
2938
abstract int getSortOrder();
3039

40+
/**
41+
* Gets a label that will appear before the operand when printing the IR.
42+
*/
3143
string getLabel() { result = "" }
3244
}
3345

csharp/ql/src/semmle/code/csharp/ir/internal/IntegerConstant.qll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
/**
2+
* Provides predicates for manipulating integer constants tracked by constant folding and similar
3+
* analyses.
4+
*/
5+
6+
/**
7+
* An alias used to represent the constant value of an integer, if one can be determined. If no
8+
* single constant value can be determined, or if the constant value is out of the representable
9+
* range, it will be represented as the special value `unknown()`. This allows `IntValue` to be used
10+
* in contexts where there must always be a value for the `IntValue`, even if no constant value is
11+
* known.
12+
*/
113
class IntValue = int;
214

315
/**

0 commit comments

Comments
 (0)