32
32
33
33
import cpp
34
34
import Deviations
35
+ import codingstandards.cpp.Locations
35
36
36
37
string supportedStandard ( ) { result = [ "misra" , "autosar" , "cert" ] }
37
38
@@ -226,15 +227,20 @@ class DeviationAttribute extends StdAttribute {
226
227
227
228
DeviationRecord getADeviationRecord ( ) { result = record }
228
229
229
- pragma [ nomagic ]
230
- Element getASuppressedElement ( ) {
230
+ /** Gets the element to which this attribute was applied. */
231
+ Element getPrimarySuppressedElement ( ) {
231
232
result .( Type ) .getAnAttribute ( ) = this
232
233
or
233
234
result .( Stmt ) .getAnAttribute ( ) = this
234
235
or
235
236
result .( Variable ) .getAnAttribute ( ) = this
236
237
or
237
238
result .( Function ) .getAnAttribute ( ) = this
239
+ }
240
+
241
+ pragma [ nomagic]
242
+ Element getASuppressedElement ( ) {
243
+ result = this .getPrimarySuppressedElement ( )
238
244
or
239
245
result .( Expr ) .getEnclosingStmt ( ) = this .getASuppressedElement ( )
240
246
or
@@ -289,11 +295,14 @@ newtype TCodeIndentifierDeviation =
289
295
} or
290
296
TMultiLineDeviation (
291
297
DeviationRecord record , DeviationBegin beginComment , DeviationEnd endComment , string filepath ,
292
- int suppressedStartLine , int suppressedEndLine
298
+ int suppressedStartLine , int suppressedStartColumn , int suppressedEndLine ,
299
+ int suppressedEndColumn
293
300
) {
294
301
isDeviationRangePaired ( record , beginComment , endComment ) and
295
- beginComment .getLocation ( ) .hasLocationInfo ( filepath , suppressedStartLine , _, _, _) and
296
- endComment .getLocation ( ) .hasLocationInfo ( filepath , suppressedEndLine , _, _, _)
302
+ beginComment
303
+ .getLocation ( )
304
+ .hasLocationInfo ( filepath , suppressedStartLine , suppressedStartColumn , _, _) and
305
+ endComment .getLocation ( ) .hasLocationInfo ( filepath , _, _, suppressedEndLine , suppressedEndColumn )
297
306
} or
298
307
TCodeIdentifierDeviation ( DeviationRecord record , DeviationAttribute attribute ) {
299
308
attribute .getADeviationRecord ( ) = record
@@ -304,7 +313,7 @@ class CodeIdentifierDeviation extends TCodeIndentifierDeviation {
304
313
DeviationRecord getADeviationRecord ( ) {
305
314
this = TSingleLineDeviation ( result , _, _, _)
306
315
or
307
- this = TMultiLineDeviation ( result , _, _, _, _, _)
316
+ this = TMultiLineDeviation ( result , _, _, _, _, _, _ , _ )
308
317
or
309
318
this = TCodeIdentifierDeviation ( result , _)
310
319
}
@@ -315,18 +324,38 @@ class CodeIdentifierDeviation extends TCodeIndentifierDeviation {
315
324
bindingset [ e]
316
325
pragma [ inline_late]
317
326
predicate isElementMatching ( Element e ) {
318
- exists ( string filepath , int elementLocationStart |
319
- e .getLocation ( ) .hasLocationInfo ( filepath , elementLocationStart , _, _, _)
327
+ exists ( string filepath , int elementLocationStart , int elementLocationColumnStart |
328
+ e .getLocation ( )
329
+ .hasLocationInfo ( filepath , elementLocationStart , elementLocationColumnStart , _, _)
320
330
|
321
331
exists ( int suppressedLine |
322
332
this = TSingleLineDeviation ( _, _, filepath , suppressedLine ) and
323
333
suppressedLine = elementLocationStart
324
334
)
325
335
or
326
- exists ( int suppressedStartLine , int suppressedEndLine |
327
- this = TMultiLineDeviation ( _, _, _, filepath , suppressedStartLine , suppressedEndLine ) and
328
- suppressedStartLine < elementLocationStart and
329
- suppressedEndLine > elementLocationStart
336
+ exists (
337
+ int suppressedStartLine , int suppressedStartColumn , int suppressedEndLine ,
338
+ int suppressedEndColumn
339
+ |
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
+ )
330
359
)
331
360
)
332
361
or
@@ -336,26 +365,64 @@ class CodeIdentifierDeviation extends TCodeIndentifierDeviation {
336
365
)
337
366
}
338
367
368
+ /**
369
+ * Holds for the region matched by this code identifier deviation.
370
+ *
371
+ * Note: this is not the location of the marker itself.
372
+ */
373
+ predicate hasLocationInfo (
374
+ string filepath , int suppressedLine , int suppressedColumn , int endline , int endcolumn
375
+ ) {
376
+ exists ( Comment commentMarker |
377
+ this = TSingleLineDeviation ( _, commentMarker , filepath , suppressedLine ) and
378
+ suppressedColumn = 1 and
379
+ endline = suppressedLine
380
+ |
381
+ if commentMarker instanceof DeviationEndOfLineMarker
382
+ then endcolumn = commentMarker .( DeviationEndOfLineMarker ) .getLocation ( ) .getEndColumn ( )
383
+ else
384
+ // Find the last column for a location on the next line
385
+ endcolumn = getLastColumnNumber ( filepath , suppressedLine )
386
+ )
387
+ or
388
+ this =
389
+ TMultiLineDeviation ( _, _, _, filepath , suppressedLine , suppressedColumn , endline , endcolumn )
390
+ or
391
+ exists ( DeviationAttribute attribute |
392
+ this = TCodeIdentifierDeviation ( _, attribute ) and
393
+ attribute
394
+ .getPrimarySuppressedElement ( )
395
+ .getLocation ( )
396
+ .hasLocationInfo ( filepath , suppressedLine , suppressedColumn , endline , endcolumn )
397
+ )
398
+ }
399
+
339
400
string toString ( ) {
340
401
exists ( string filepath |
341
402
exists ( int suppressedLine |
342
403
this = TSingleLineDeviation ( _, _, filepath , suppressedLine ) and
343
404
result =
344
- "Deviation record " + getADeviationRecord ( ) + " applied to " + filepath + " Line " +
405
+ "Deviation of " + getADeviationRecord ( ) . getQuery ( ) + " applied to " + filepath + " Line " +
345
406
suppressedLine
346
407
)
347
408
or
348
- exists ( int suppressedStartLine , int suppressedEndLine |
349
- this = TMultiLineDeviation ( _, _, _, filepath , suppressedStartLine , suppressedEndLine ) and
409
+ exists (
410
+ int suppressedStartLine , int suppressedStartColumn , int suppressedEndLine ,
411
+ int suppressedEndColumn
412
+ |
413
+ this =
414
+ TMultiLineDeviation ( _, _, _, filepath , suppressedStartLine , suppressedStartColumn ,
415
+ suppressedEndLine , suppressedEndColumn ) and
350
416
result =
351
- "Deviation record " + getADeviationRecord ( ) + " applied to " + filepath + " Line" +
352
- suppressedStartLine + ":" + suppressedEndLine
417
+ "Deviation of " + getADeviationRecord ( ) .getQuery ( ) + " applied to " + filepath + " Line " +
418
+ suppressedStartLine + ":" + suppressedStartColumn + ":" + suppressedEndLine + ":" +
419
+ suppressedEndColumn
353
420
)
354
421
)
355
422
or
356
423
exists ( DeviationAttribute attribute |
357
424
this = TCodeIdentifierDeviation ( _, attribute ) and
358
- result = "Deviation record " + getADeviationRecord ( ) + " applied to " + attribute
425
+ result = "Deviation of " + getADeviationRecord ( ) . getQuery ( ) + " applied to " + attribute
359
426
)
360
427
}
361
428
}
0 commit comments