@@ -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
@@ -208,6 +213,7 @@ def report_pending_ifndef(directive,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,22 +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- # pylint: disable-next=no-member - TODO: fix this
270- if conf .include_guard :
271- global include_guard_header_re
272- # pylint: disable-next=no-member - TODO: fix this
273- include_guard_header_re = conf .include_guard .get ('RE_HEADERFILE' ,"[^/].*\\ .h\\ Z" )
274-
275275 for afile in dumpfiles :
276276 if not afile [- 5 :] == '.dump' :
277277 continue
278- if not args . cli :
278+ if not cli :
279279 print ('Checking ' + afile + '...' )
280280 data = cppcheckdata .CppcheckData (afile )
281- process_data (conf ,data )
281+ process_data (conf ,data , debugprint )
282282
283283def check_file_naming (conf ,data ):
284284 for source_file in data .files :
@@ -299,7 +299,7 @@ def check_namespace_naming(conf,data):
299299 for exp in conf .namespace :
300300 evalExpr (conf .namespace , exp , mockToken , 'Namespace' )
301301
302- def check_variable_naming (conf ,cfg ):
302+ def check_variable_naming (conf ,cfg , debugprint ):
303303 for var in cfg .variables :
304304 if not var .nameToken :
305305 continue
@@ -311,7 +311,7 @@ def check_variable_naming(conf,cfg):
311311 prev = prev .previous
312312 varType = prev .str + varType
313313
314- if args . debugprint :
314+ if debugprint :
315315 print ("Variable Name: " + str (var .nameToken .str ))
316316 print ("original Type Name: " + str (var .nameToken .valueType .originalTypeName ))
317317 print ("Type Name: " + var .nameToken .valueType .type )
@@ -344,7 +344,7 @@ def check_gpp_naming(conf_list,cfg,access,message):
344344 for exp in conf_list :
345345 evalExpr (conf_list , exp , mockToken , message )
346346
347- def check_function_naming (conf ,cfg ):
347+ def check_function_naming (conf ,cfg , debugprint ):
348348 for token in cfg .tokenlist :
349349 if not token .function :
350350 continue
@@ -355,7 +355,7 @@ def check_function_naming(conf,cfg):
355355 while "*" in retval and len (retval .replace ("*" , "" )) == 0 :
356356 prev = prev .previous
357357 retval = prev .str + retval
358- if args . debugprint :
358+ if debugprint :
359359 print ("\t :: {} {}" .format (retval , token .function .name ))
360360
361361 if retval and retval in conf .function_prefixes :
@@ -375,7 +375,7 @@ def check_class_naming(conf,cfg):
375375 for exp in conf .class_name :
376376 evalExpr (conf .class_name , exp , mockToken , msgType )
377377
378- def process_data (conf ,data ):
378+ def process_data (conf ,data , debugprint ):
379379 if conf .file :
380380 check_file_naming (conf ,data )
381381
@@ -384,21 +384,21 @@ def process_data(conf,data):
384384
385385 unguarded_include_files = []
386386 if conf .include_guard and conf .include_guard .get ('required' ,1 ):
387- 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 )]
388388
389389 for cfg in data .configurations :
390390 if not args .cli :
391391 print ('Checking config %s...' % cfg .name )
392392 if conf .variable :
393- check_variable_naming (conf ,cfg )
393+ check_variable_naming (conf ,cfg , debugprint )
394394 if conf .private_member :
395395 check_gpp_naming (conf .private_member ,cfg ,'Private' ,'Private member variable' )
396396 if conf .public_member :
397397 check_gpp_naming (conf .public_member ,cfg ,'Public' ,'Public member variable' )
398398 if conf .global_variable :
399399 check_gpp_naming (conf .global_variable ,cfg ,'Global' ,'Global variable' )
400400 if conf .function_name :
401- check_function_naming (conf ,cfg )
401+ check_function_naming (conf ,cfg , debugprint )
402402 if conf .class_name :
403403 check_class_naming (conf ,cfg )
404404 if conf .include_guard :
@@ -416,6 +416,6 @@ def process_data(conf,data):
416416 help = "Naming check config file" )
417417
418418 args = parser .parse_args ()
419- process (args .dumpfile , args .configfile )
419+ process (args .dumpfile , args .configfile , args . cli , args . debugprint )
420420
421421 sys .exit (0 )
0 commit comments