1717
1818import cppcheckdata
1919import itertools
20+ import json
2021import sys
2122import re
2223import os
2324import argparse
2425import codecs
2526import string
2627
28+ from collections import namedtuple
29+
2730try :
2831 from itertools import izip as zip
2932except ImportError :
@@ -1336,6 +1339,15 @@ def misra_5_5(self, data):
13361339 self .reportError (scope .bodyStart , 5 , 5 )
13371340
13381341
1342+ def misra_5_6 (self , data ):
1343+ dumpfile = data [0 ]
1344+ typedefInfo = data [1 ]
1345+ summary = []
1346+ for ti in typedefInfo :
1347+ summary .append ({ 'name' : ti .name , 'file' : ti .filename , 'line' : ti .lineNumber })
1348+ if len (summary ) > 0 :
1349+ cppcheckdata .reportSummary (dumpfile , 'misra_5_6' , summary )
1350+
13391351 def misra_6_1 (self , data ):
13401352 # Bitfield type must be bool or explicitly signed/unsigned int
13411353 for token in data .tokenlist :
@@ -3250,6 +3262,7 @@ def fillVerifyExpected(verify_expected, tok):
32503262 self .executeCheck (502 , self .misra_5_2 , cfg )
32513263 self .executeCheck (504 , self .misra_5_4 , cfg )
32523264 self .executeCheck (505 , self .misra_5_5 , cfg )
3265+ self .executeCheck (506 , self .misra_5_6 , (dumpfile , cfg .typedefInfo ))
32533266 self .executeCheck (601 , self .misra_6_1 , cfg )
32543267 self .executeCheck (602 , self .misra_6_2 , cfg )
32553268 if cfgNumber == 0 :
@@ -3342,6 +3355,32 @@ def fillVerifyExpected(verify_expected, tok):
33423355 self .executeCheck (2112 , self .misra_21_12 , cfg )
33433356 # 22.4 is already covered by Cppcheck writeReadOnlyFile
33443357
3358+ def analyse_ctu_info (self , files ):
3359+ data_misra_5_6 = []
3360+
3361+ Location = namedtuple ('Location' , 'file linenr column' )
3362+
3363+ for filename in files :
3364+ if not filename .endswith ('.ctu-info' ):
3365+ continue
3366+ for line in open (filename , 'rt' ):
3367+ if line .startswith ('{' ):
3368+ s = json .loads (line )
3369+ summary_type = s ['summary' ]
3370+ summary_data = s ['data' ]
3371+
3372+ # TODO break out info some function
3373+ if summary_type == 'misra_5_6' :
3374+ for info1 in summary_data :
3375+ found = False
3376+ for info2 in data_misra_5_6 :
3377+ if info1 ['name' ] == info2 ['name' ]:
3378+ found = True
3379+ if info1 ['file' ] != info2 ['file' ] or info1 ['line' ] != info2 ['line' ]:
3380+ self .reportError (Location (info2 ['file' ], info2 ['line' ], 0 ), 5 , 6 )
3381+ self .reportError (Location (info1 ['file' ], info1 ['line' ], 0 ), 5 , 6 )
3382+ if not found :
3383+ data_misra_5_6 .append (info1 )
33453384
33463385RULE_TEXTS_HELP = '''Path to text file of MISRA rules
33473386
@@ -3434,6 +3473,9 @@ def main():
34343473 checker .setSeverity (args .severity )
34353474
34363475 for item in args .dumpfile :
3476+ if item .endswith ('.ctu-info' ):
3477+ continue
3478+
34373479 checker .parseDump (item )
34383480
34393481 if settings .verify :
@@ -3457,6 +3499,8 @@ def main():
34573499 if exitCode != 0 :
34583500 sys .exit (exitCode )
34593501
3502+ checker .analyse_ctu_info (args .dumpfile )
3503+
34603504 if settings .verify :
34613505 sys .exit (exitCode )
34623506
0 commit comments