Skip to content

Commit dea7be0

Browse files
authored
Merge pull request github#3557 from jbj/qldoc-external
C++: QLDoc for legacy libraries in `external` dir
2 parents 5deeda0 + 357e14b commit dea7be0

File tree

3 files changed

+78
-7
lines changed

3 files changed

+78
-7
lines changed

cpp/ql/src/external/DefectFilter.qll

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,52 @@
1+
/** Provides a class for working with defect query results stored in dashboard databases. */
2+
13
import cpp
24

5+
/**
6+
* Holds if `id` in the opaque identifier of a result reported by query `queryPath`,
7+
* such that `message` is the associated message and the location of the result spans
8+
* column `startcolumn` of line `startline` to column `endcolumn` of line `endline`
9+
* in file `filepath`.
10+
*
11+
* For more information, see [Locations](https://help.semmle.com/QL/learn-ql/ql/locations.html).
12+
*/
313
external predicate defectResults(
414
int id, string queryPath, string file, int startline, int startcol, int endline, int endcol,
515
string message
616
);
717

18+
/**
19+
* A defect query result stored in a dashboard database.
20+
*/
821
class DefectResult extends int {
922
DefectResult() { defectResults(this, _, _, _, _, _, _, _) }
1023

24+
/** Gets the path of the query that reported the result. */
1125
string getQueryPath() { defectResults(this, result, _, _, _, _, _, _) }
1226

27+
/** Gets the file in which this query result was reported. */
1328
File getFile() {
1429
exists(string path |
1530
defectResults(this, _, path, _, _, _, _, _) and result.getAbsolutePath() = path
1631
)
1732
}
1833

34+
/** Gets the line on which the location of this query result starts. */
1935
int getStartLine() { defectResults(this, _, _, result, _, _, _, _) }
2036

37+
/** Gets the column on which the location of this query result starts. */
2138
int getStartColumn() { defectResults(this, _, _, _, result, _, _, _) }
2239

40+
/** Gets the line on which the location of this query result ends. */
2341
int getEndLine() { defectResults(this, _, _, _, _, result, _, _) }
2442

43+
/** Gets the column on which the location of this query result ends. */
2544
int getEndColumn() { defectResults(this, _, _, _, _, _, result, _) }
2645

46+
/** Gets the message associated with this query result. */
2747
string getMessage() { defectResults(this, _, _, _, _, _, _, result) }
2848

49+
/** Gets the URL corresponding to the location of this query result. */
2950
string getURL() {
3051
result =
3152
"file://" + getFile().getAbsolutePath() + ":" + getStartLine() + ":" + getStartColumn() + ":" +
Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,45 @@
1+
/**
2+
* Provides classes for working with external data.
3+
*/
4+
15
import cpp
26

7+
/**
8+
* An external data item.
9+
*/
310
class ExternalData extends @externalDataElement {
11+
/** Gets the path of the file this data was loaded from. */
412
string getDataPath() { externalData(this, result, _, _) }
513

14+
/**
15+
* Gets the path of the file this data was loaded from, with its
16+
* extension replaced by `.ql`.
17+
*/
618
string getQueryPath() { result = getDataPath().regexpReplaceAll("\\.[^.]*$", ".ql") }
719

20+
/** Gets the number of fields in this data item. */
821
int getNumFields() { result = 1 + max(int i | externalData(this, _, i, _) | i) }
922

10-
string getField(int index) { externalData(this, _, index, result) }
23+
/** Gets the value of the `i`th field of this data item. */
24+
string getField(int i) { externalData(this, _, i, result) }
1125

12-
int getFieldAsInt(int index) { result = getField(index).toInt() }
26+
/** Gets the integer value of the `i`th field of this data item. */
27+
int getFieldAsInt(int i) { result = getField(i).toInt() }
1328

14-
float getFieldAsFloat(int index) { result = getField(index).toFloat() }
29+
/** Gets the floating-point value of the `i`th field of this data item. */
30+
float getFieldAsFloat(int i) { result = getField(i).toFloat() }
1531

16-
date getFieldAsDate(int index) { result = getField(index).toDate() }
32+
/** Gets the value of the `i`th field of this data item, interpreted as a date. */
33+
date getFieldAsDate(int i) { result = getField(i).toDate() }
1734

35+
/** Gets a textual representation of this data item. */
1836
string toString() { result = getQueryPath() + ": " + buildTupleString(0) }
1937

20-
private string buildTupleString(int start) {
21-
start = getNumFields() - 1 and result = getField(start)
38+
/** Gets a textual representation of this data item, starting with the `n`th field. */
39+
private string buildTupleString(int n) {
40+
n = getNumFields() - 1 and result = getField(n)
2241
or
23-
start < getNumFields() - 1 and result = getField(start) + "," + buildTupleString(start + 1)
42+
n < getNumFields() - 1 and result = getField(n) + "," + buildTupleString(n + 1)
2443
}
2544
}
2645

@@ -33,7 +52,9 @@ class DefectExternalData extends ExternalData {
3352
this.getNumFields() = 2
3453
}
3554

55+
/** Gets the URL associated with this data item. */
3656
string getURL() { result = getField(0) }
3757

58+
/** Gets the message associated with this data item. */
3859
string getMessage() { result = getField(1) }
3960
}

cpp/ql/src/external/MetricFilter.qll

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,58 @@
1+
/** Provides a class for working with metric query results stored in dashboard databases. */
2+
13
import cpp
24

5+
/**
6+
* Holds if `id` in the opaque identifier of a result reported by query `queryPath`,
7+
* such that `value` is the reported metric value and the location of the result spans
8+
* column `startcolumn` of line `startline` to column `endcolumn` of line `endline`
9+
* in file `filepath`.
10+
*
11+
* For more information, see [Locations](https://help.semmle.com/QL/learn-ql/ql/locations.html).
12+
*/
313
external predicate metricResults(
414
int id, string queryPath, string file, int startline, int startcol, int endline, int endcol,
515
float value
616
);
717

18+
/**
19+
* A metric query result stored in a dashboard database.
20+
*/
821
class MetricResult extends int {
922
MetricResult() { metricResults(this, _, _, _, _, _, _, _) }
1023

24+
/** Gets the path of the query that reported the result. */
1125
string getQueryPath() { metricResults(this, result, _, _, _, _, _, _) }
1226

27+
/** Gets the file in which this query result was reported. */
1328
File getFile() {
1429
exists(string path |
1530
metricResults(this, _, path, _, _, _, _, _) and result.getAbsolutePath() = path
1631
)
1732
}
1833

34+
/** Gets the line on which the location of this query result starts. */
1935
int getStartLine() { metricResults(this, _, _, result, _, _, _, _) }
2036

37+
/** Gets the column on which the location of this query result starts. */
2138
int getStartColumn() { metricResults(this, _, _, _, result, _, _, _) }
2239

40+
/** Gets the line on which the location of this query result ends. */
2341
int getEndLine() { metricResults(this, _, _, _, _, result, _, _) }
2442

43+
/** Gets the column on which the location of this query result ends. */
2544
int getEndColumn() { metricResults(this, _, _, _, _, _, result, _) }
2645

46+
/**
47+
* Holds if there is a `Location` entity whose location is the same as
48+
* the location of this query result.
49+
*/
2750
predicate hasMatchingLocation() { exists(this.getMatchingLocation()) }
2851

52+
/**
53+
* Gets the `Location` entity whose location is the same as the location
54+
* of this query result.
55+
*/
2956
Location getMatchingLocation() {
3057
result.getFile() = this.getFile() and
3158
result.getStartLine() = this.getStartLine() and
@@ -34,8 +61,10 @@ class MetricResult extends int {
3461
result.getEndColumn() = this.getEndColumn()
3562
}
3663

64+
/** Gets the value associated with this query result. */
3765
float getValue() { metricResults(this, _, _, _, _, _, _, result) }
3866

67+
/** Gets the URL corresponding to the location of this query result. */
3968
string getURL() {
4069
result =
4170
"file://" + getFile().getAbsolutePath() + ":" + getStartLine() + ":" + getStartColumn() + ":" +

0 commit comments

Comments
 (0)