@@ -146,6 +146,11 @@ class Config:
146146 if have_error :
147147 sys .exit (1 )
148148
149+ # pylint: disable-next=no-member - TODO: fix this
150+ if config .include_guard :
151+ # pylint: disable-next=no-member - TODO: fix this
152+ config .include_guard_header_re = config .include_guard .get ('RE_HEADERFILE' ,"[^/].*\\ .h\\ Z" )
153+
149154 return config
150155
151156
@@ -200,14 +205,15 @@ def check_include_guards(conf,cfg,unguarded_include_files):
200205 # - test whether include guards are in place
201206 max_linenr = conf .include_guard .get ('max_linenr' , 5 )
202207
203- def report (directive ,msg ,errorId ,column = 0 ):
204- reportNamingError (directive ,msg ,errorId ,column = column )
208+ def report (directive ,msg ,errorId ,severity = 'style' , column = 0 ):
209+ reportNamingError (directive ,msg ,errorId ,severity = severity , column = column )
205210
206211 def report_pending_ifndef (directive ,column ):
207212 report (directive ,'include guard #ifndef is not followed by #define' ,'includeGuardIncomplete' ,column = column )
208213
209214 last_fn = None
210215 pending_ifndef = None
216+ guard_column = None
211217 phase = 0
212218 for directive in cfg .directives :
213219 if last_fn != directive .file :
@@ -219,7 +225,7 @@ def report_pending_ifndef(directive,column):
219225 if phase == - 1 :
220226 # ignore (the remainder of) this file
221227 continue
222- if not re .match (include_guard_header_re ,directive .file ):
228+ if not re .match (conf . include_guard_header_re ,directive .file ):
223229 phase = - 1
224230 continue
225231
@@ -263,20 +269,16 @@ def report_pending_ifndef(directive,column):
263269 if pending_ifndef :
264270 report_pending_ifndef (pending_ifndef ,guard_column )
265271
266- def process (dumpfiles , configfile ):
272+ def process (dumpfiles , configfile , cli , debugprint ):
267273 conf = loadConfig (configfile )
268274
269- if conf .include_guard :
270- global include_guard_header_re
271- include_guard_header_re = conf .include_guard .get ('RE_HEADERFILE' ,"[^/].*\\ .h\\ Z" )
272-
273275 for afile in dumpfiles :
274276 if not afile [- 5 :] == '.dump' :
275277 continue
276- if not args . cli :
278+ if not cli :
277279 print ('Checking ' + afile + '...' )
278280 data = cppcheckdata .CppcheckData (afile )
279- process_data (conf ,data )
281+ process_data (conf ,data , cli , debugprint )
280282
281283def check_file_naming (conf ,data ):
282284 for source_file in data .files :
@@ -297,7 +299,7 @@ def check_namespace_naming(conf,data):
297299 for exp in conf .namespace :
298300 evalExpr (conf .namespace , exp , mockToken , 'Namespace' )
299301
300- def check_variable_naming (conf ,cfg ):
302+ def check_variable_naming (conf ,cfg , debugprint ):
301303 for var in cfg .variables :
302304 if not var .nameToken :
303305 continue
@@ -309,7 +311,7 @@ def check_variable_naming(conf,cfg):
309311 prev = prev .previous
310312 varType = prev .str + varType
311313
312- if args . debugprint :
314+ if debugprint :
313315 print ("Variable Name: " + str (var .nameToken .str ))
314316 print ("original Type Name: " + str (var .nameToken .valueType .originalTypeName ))
315317 print ("Type Name: " + var .nameToken .valueType .type )
@@ -342,7 +344,7 @@ def check_gpp_naming(conf_list,cfg,access,message):
342344 for exp in conf_list :
343345 evalExpr (conf_list , exp , mockToken , message )
344346
345- def check_function_naming (conf ,cfg ):
347+ def check_function_naming (conf ,cfg , debugprint ):
346348 for token in cfg .tokenlist :
347349 if not token .function :
348350 continue
@@ -353,7 +355,7 @@ def check_function_naming(conf,cfg):
353355 while "*" in retval and len (retval .replace ("*" , "" )) == 0 :
354356 prev = prev .previous
355357 retval = prev .str + retval
356- if args . debugprint :
358+ if debugprint :
357359 print ("\t :: {} {}" .format (retval , token .function .name ))
358360
359361 if retval and retval in conf .function_prefixes :
@@ -373,7 +375,7 @@ def check_class_naming(conf,cfg):
373375 for exp in conf .class_name :
374376 evalExpr (conf .class_name , exp , mockToken , msgType )
375377
376- def process_data (conf ,data ):
378+ def process_data (conf ,data , cli , debugprint ):
377379 if conf .file :
378380 check_file_naming (conf ,data )
379381
@@ -382,21 +384,21 @@ def process_data(conf,data):
382384
383385 unguarded_include_files = []
384386 if conf .include_guard and conf .include_guard .get ('required' ,1 ):
385- unguarded_include_files = [fn for fn in data .files if re .match (include_guard_header_re ,fn )]
387+ unguarded_include_files = [fn for fn in data .files if re .match (conf . include_guard_header_re ,fn )]
386388
387389 for cfg in data .configurations :
388- if not args . cli :
390+ if not cli :
389391 print ('Checking config %s...' % cfg .name )
390392 if conf .variable :
391- check_variable_naming (conf ,cfg )
393+ check_variable_naming (conf ,cfg , debugprint )
392394 if conf .private_member :
393395 check_gpp_naming (conf .private_member ,cfg ,'Private' ,'Private member variable' )
394396 if conf .public_member :
395397 check_gpp_naming (conf .public_member ,cfg ,'Public' ,'Public member variable' )
396398 if conf .global_variable :
397399 check_gpp_naming (conf .global_variable ,cfg ,'Global' ,'Global variable' )
398400 if conf .function_name :
399- check_function_naming (conf ,cfg )
401+ check_function_naming (conf ,cfg , debugprint )
400402 if conf .class_name :
401403 check_class_naming (conf ,cfg )
402404 if conf .include_guard :
@@ -414,6 +416,6 @@ def process_data(conf,data):
414416 help = "Naming check config file" )
415417
416418 args = parser .parse_args ()
417- process (args .dumpfile , args .configfile )
419+ process (args .dumpfile , args .configfile , args . cli , args . debugprint )
418420
419421 sys .exit (0 )
0 commit comments