Skip to content

Commit 6a5f095

Browse files
committed
Deviations: Store start columns for comment ranges
1 parent 5ad61ee commit 6a5f095

File tree

3 files changed

+47
-23
lines changed

3 files changed

+47
-23
lines changed

cpp/common/src/codingstandards/cpp/deviations/CodeIdentifierDeviation.qll

+38-20
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,13 @@ newtype TCodeIndentifierDeviation =
295295
} or
296296
TMultiLineDeviation(
297297
DeviationRecord record, DeviationBegin beginComment, DeviationEnd endComment, string filepath,
298-
int suppressedStartLine, int suppressedEndLine, int suppressedEndColumn
298+
int suppressedStartLine, int suppressedStartColumn, int suppressedEndLine,
299+
int suppressedEndColumn
299300
) {
300301
isDeviationRangePaired(record, beginComment, endComment) and
301-
beginComment.getLocation().hasLocationInfo(filepath, suppressedStartLine, _, _, _) and
302+
beginComment
303+
.getLocation()
304+
.hasLocationInfo(filepath, suppressedStartLine, suppressedStartColumn, _, _) and
302305
endComment.getLocation().hasLocationInfo(filepath, _, _, suppressedEndLine, suppressedEndColumn)
303306
} or
304307
TCodeIdentifierDeviation(DeviationRecord record, DeviationAttribute attribute) {
@@ -310,7 +313,7 @@ class CodeIdentifierDeviation extends TCodeIndentifierDeviation {
310313
DeviationRecord getADeviationRecord() {
311314
this = TSingleLineDeviation(result, _, _, _)
312315
or
313-
this = TMultiLineDeviation(result, _, _, _, _, _, _)
316+
this = TMultiLineDeviation(result, _, _, _, _, _, _, _)
314317
or
315318
this = TCodeIdentifierDeviation(result, _)
316319
}
@@ -330,18 +333,29 @@ class CodeIdentifierDeviation extends TCodeIndentifierDeviation {
330333
suppressedLine = elementLocationStart
331334
)
332335
or
333-
exists(int suppressedStartLine, int suppressedEndLine, int suppressedEndColumn |
334-
this =
335-
TMultiLineDeviation(_, _, _, filepath, suppressedStartLine, suppressedEndLine,
336-
suppressedEndColumn) and
337-
suppressedStartLine < elementLocationStart
336+
exists(
337+
int suppressedStartLine, int suppressedStartColumn, int suppressedEndLine,
338+
int suppressedEndColumn
338339
|
339-
// Element starts before the end line of the suppression
340-
suppressedEndLine > elementLocationStart
341-
or
342-
// Element exists on the same line as the suppression, and occurs before it
343-
suppressedEndLine = elementLocationStart and
344-
elementLocationColumnStart < suppressedEndColumn
340+
this =
341+
TMultiLineDeviation(_, _, _, filepath, suppressedStartLine, suppressedStartColumn,
342+
suppressedEndLine, suppressedEndColumn) and
343+
(
344+
// Element starts on a line after the begin marker of the suppression
345+
suppressedStartLine < elementLocationStart
346+
or
347+
// Element exists on the same line as the begin marker, and occurs after it
348+
suppressedStartLine = elementLocationStart and
349+
suppressedStartColumn < elementLocationColumnStart
350+
) and
351+
(
352+
// Element starts on a line before the end marker of the suppression
353+
suppressedEndLine > elementLocationStart
354+
or
355+
// Element exists on the same line as the end marker of the suppression, and occurs before it
356+
suppressedEndLine = elementLocationStart and
357+
elementLocationColumnStart < suppressedEndColumn
358+
)
345359
)
346360
)
347361
or
@@ -371,8 +385,8 @@ class CodeIdentifierDeviation extends TCodeIndentifierDeviation {
371385
endcolumn = getLastColumnNumber(filepath, suppressedLine)
372386
)
373387
or
374-
this = TMultiLineDeviation(_, _, _, filepath, suppressedLine, endline, endcolumn) and
375-
suppressedColumn = 1
388+
this =
389+
TMultiLineDeviation(_, _, _, filepath, suppressedLine, suppressedColumn, endline, endcolumn)
376390
or
377391
exists(DeviationAttribute attribute |
378392
this = TCodeIdentifierDeviation(_, attribute) and
@@ -392,13 +406,17 @@ class CodeIdentifierDeviation extends TCodeIndentifierDeviation {
392406
suppressedLine
393407
)
394408
or
395-
exists(int suppressedStartLine, int suppressedEndLine, int suppressedEndColumn |
409+
exists(
410+
int suppressedStartLine, int suppressedStartColumn, int suppressedEndLine,
411+
int suppressedEndColumn
412+
|
396413
this =
397-
TMultiLineDeviation(_, _, _, filepath, suppressedStartLine, suppressedEndLine,
398-
suppressedEndColumn) and
414+
TMultiLineDeviation(_, _, _, filepath, suppressedStartLine, suppressedStartColumn,
415+
suppressedEndLine, suppressedEndColumn) and
399416
result =
400417
"Deviation of " + getADeviationRecord().getQuery() + " applied to " + filepath + " Line " +
401-
suppressedStartLine + ":" + suppressedEndLine + " (Column " + suppressedEndColumn + ")"
418+
suppressedStartLine + ":" + suppressedStartColumn + ":" + suppressedEndLine + ":" +
419+
suppressedEndColumn
402420
)
403421
)
404422
or
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
| file://:0:0:0:0 | (no string representation) | // lgtm[cpp/autosar/type-long-double-used] | lgtm[cpp/autosar/type-long-double-used] | main.cpp:12:1:12:58 | Deviation of cpp/autosar/type-long-double-used applied to main.cpp Line 12 |
22
| file://:0:0:0:0 | (no string representation) | // lgtm[cpp/autosar/type-long-double-used] | lgtm[cpp/autosar/type-long-double-used] | main.cpp:14:1:14:65 | Deviation of cpp/autosar/type-long-double-used applied to main.cpp Line 14 |
33
| file://:0:0:0:0 | (no string representation) | // lgtm[cpp/autosar/type-long-double-used] | lgtm[cpp/autosar/type-long-double-used] | main.cpp:18:1:18:40 | Deviation of cpp/autosar/type-long-double-used applied to main.cpp Line 18 |
4-
| file://:0:0:0:0 | (no string representation) | // lgtm[cpp/autosar/type-long-double-used] | lgtm[cpp/autosar/type-long-double-used] | main.cpp:21:1:27:53 | Deviation of cpp/autosar/type-long-double-used applied to main.cpp Line 21:27 (Column 53) |
5-
| file://:0:0:0:0 | (no string representation) | // lgtm[cpp/autosar/type-long-double-used] | lgtm[cpp/autosar/type-long-double-used] | main.cpp:29:1:35:53 | Deviation of cpp/autosar/type-long-double-used applied to main.cpp Line 29:35 (Column 53) |
4+
| file://:0:0:0:0 | (no string representation) | // lgtm[cpp/autosar/type-long-double-used] | lgtm[cpp/autosar/type-long-double-used] | main.cpp:21:3:27:53 | Deviation of cpp/autosar/type-long-double-used applied to main.cpp Line 21:3:27:53 |
5+
| file://:0:0:0:0 | (no string representation) | // lgtm[cpp/autosar/type-long-double-used] | lgtm[cpp/autosar/type-long-double-used] | main.cpp:29:3:35:53 | Deviation of cpp/autosar/type-long-double-used applied to main.cpp Line 29:3:35:53 |
6+
| file://:0:0:0:0 | (no string representation) | // lgtm[cpp/autosar/type-long-double-used] | lgtm[cpp/autosar/type-long-double-used] | main.cpp:40:39:41:99 | Deviation of cpp/autosar/type-long-double-used applied to main.cpp Line 40:39:41:99 |
67
| file://:0:0:0:0 | (no string representation) | // lgtm[cpp/autosar/unused-return-value] | lgtm[cpp/autosar/unused-return-value] | nested/nested2/test2.h:1:1:6:1 | Deviation of cpp/autosar/unused-return-value for nested/nested2/test2.h. |
78
| file://:0:0:0:0 | (no string representation) | // lgtm[cpp/autosar/useless-assignment] | lgtm[cpp/autosar/useless-assignment] | coding-standards.xml:1:1:17:19 | Deviation of cpp/autosar/useless-assignment for coding-standards.xml. |
8-
| file://:0:0:0:0 | (no string representation) | // lgtm[cpp/autosar/useless-assignment] | lgtm[cpp/autosar/useless-assignment] | main.cpp:1:1:39:1 | Deviation of cpp/autosar/useless-assignment for main.cpp. |
9+
| file://:0:0:0:0 | (no string representation) | // lgtm[cpp/autosar/useless-assignment] | lgtm[cpp/autosar/useless-assignment] | main.cpp:1:1:44:1 | Deviation of cpp/autosar/useless-assignment for main.cpp. |
910
| file://:0:0:0:0 | (no string representation) | // lgtm[cpp/autosar/useless-assignment] | lgtm[cpp/autosar/useless-assignment] | nested/coding-standards.xml:1:1:13:19 | Deviation of cpp/autosar/useless-assignment for nested/coding-standards.xml. |
1011
| file://:0:0:0:0 | (no string representation) | // lgtm[cpp/autosar/useless-assignment] | lgtm[cpp/autosar/useless-assignment] | nested/nested2/test2.h:1:1:6:1 | Deviation of cpp/autosar/useless-assignment for nested/nested2/test2.h. |
1112
| file://:0:0:0:0 | (no string representation) | // lgtm[cpp/autosar/useless-assignment] | lgtm[cpp/autosar/useless-assignment] | nested/test.h:1:1:6:1 | Deviation of cpp/autosar/useless-assignment for nested/test.h. |

cpp/common/test/deviations/deviations_report_deviated/main.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,10 @@ int main(int argc, char **argv) {
3535
// codeql::autosar_deviation_end(a-0-4-2-deviation)
3636
long double d14; // NON_COMPLIANT (A0-4-2)
3737
getX(); // NON_COMPLIANT (A0-1-2)
38+
39+
// clang-format off
40+
long double d15; /* NON_COMPLIANT*/ /* codeql::autosar_deviation_begin(a-0-4-2-deviation) */ long double d16; // COMPLIANT[DEVIATED]
41+
long double d17; /* COMPLIANT[DEVIATED] */ /* codeql::autosar_deviation_end(a-0-4-2-deviation) */ long double d18; // NON_COMPLIANT
42+
// clang-format on
3843
return 0;
3944
}

0 commit comments

Comments
 (0)