59
59
# if empty, use defaults
60
60
_valid_extensions = set ([])
61
61
62
- __VERSION__ = '1.4.6 '
62
+ __VERSION__ = '1.5.0 '
63
63
64
64
try :
65
65
xrange # Python 2
280
280
'build/include' ,
281
281
'build/include_subdir' ,
282
282
'build/include_alpha' ,
283
- 'build/include_inline' ,
284
283
'build/include_order' ,
285
284
'build/include_what_you_use' ,
286
285
'build/namespaces_literals' ,
295
294
'readability/constructors' ,
296
295
'readability/fn_size' ,
297
296
'readability/inheritance' ,
298
- 'readability/pointer_notation' ,
299
297
'readability/multiline_comment' ,
300
298
'readability/multiline_string' ,
301
299
'readability/namespace' ,
302
300
'readability/nolint' ,
303
301
'readability/nul' ,
304
- 'readability/null_usage' ,
305
302
'readability/strings' ,
306
303
'readability/todo' ,
307
304
'readability/utf8' ,
321
318
'runtime/string' ,
322
319
'runtime/threadsafe_fn' ,
323
320
'runtime/vlog' ,
324
- 'runtime/v8_persistent' ,
325
321
'whitespace/blank_line' ,
326
322
'whitespace/braces' ,
327
323
'whitespace/comma' ,
518
514
'cwctype' ,
519
515
])
520
516
517
+ # C headers
518
+ _C_HEADERS = frozenset ([
519
+ # System C headers
520
+ 'assert.h' ,
521
+ 'complex.h' ,
522
+ 'ctype.h' ,
523
+ 'errno.h' ,
524
+ 'fenv.h' ,
525
+ 'float.h' ,
526
+ 'inttypes.h' ,
527
+ 'iso646.h' ,
528
+ 'limits.h' ,
529
+ 'locale.h' ,
530
+ 'math.h' ,
531
+ 'setjmp.h' ,
532
+ 'signal.h' ,
533
+ 'stdalign.h' ,
534
+ 'stdarg.h' ,
535
+ 'stdatomic.h' ,
536
+ 'stdbool.h' ,
537
+ 'stddef.h' ,
538
+ 'stdint.h' ,
539
+ 'stdio.h' ,
540
+ 'stdlib.h' ,
541
+ 'stdnoreturn.h' ,
542
+ 'string.h' ,
543
+ 'tgmath.h' ,
544
+ 'threads.h' ,
545
+ 'time.h' ,
546
+ 'uchar.h' ,
547
+ 'wchar.h' ,
548
+ 'wctype.h' ,
549
+ # POSIX C headers
550
+ 'aio.h' ,
551
+ 'arpa/inet.h' ,
552
+ 'cpio.h' ,
553
+ 'dirent.h' ,
554
+ 'dlfcn.h' ,
555
+ 'fcntl.h' ,
556
+ 'fmtmsg.h' ,
557
+ 'fnmatch.h' ,
558
+ 'ftw.h' ,
559
+ 'glob.h' ,
560
+ 'grp.h' ,
561
+ 'iconv.h' ,
562
+ 'langinfo.h' ,
563
+ 'libgen.h' ,
564
+ 'monetary.h' ,
565
+ 'mqueue.h' ,
566
+ 'ndbm.h' ,
567
+ 'net/if.h' ,
568
+ 'netdb.h' ,
569
+ 'netinet/in.h' ,
570
+ 'netinet/tcp.h' ,
571
+ 'nl_types.h' ,
572
+ 'poll.h' ,
573
+ 'pthread.h' ,
574
+ 'pwd.h' ,
575
+ 'regex.h' ,
576
+ 'sched.h' ,
577
+ 'search.h' ,
578
+ 'semaphore.h' ,
579
+ 'setjmp.h' ,
580
+ 'signal.h' ,
581
+ 'spawn.h' ,
582
+ 'strings.h' ,
583
+ 'stropts.h' ,
584
+ 'syslog.h' ,
585
+ 'tar.h' ,
586
+ 'termios.h' ,
587
+ 'trace.h' ,
588
+ 'ulimit.h' ,
589
+ 'unistd.h' ,
590
+ 'utime.h' ,
591
+ 'utmpx.h' ,
592
+ 'wordexp.h' ,
593
+ # GNUlib headers
594
+ 'a.out.h' ,
595
+ 'aliases.h' ,
596
+ 'alloca.h' ,
597
+ 'ar.h' ,
598
+ 'argp.h' ,
599
+ 'argz.h' ,
600
+ 'byteswap.h' ,
601
+ 'crypt.h' ,
602
+ 'endian.h' ,
603
+ 'envz.h' ,
604
+ 'err.h' ,
605
+ 'error.h' ,
606
+ 'execinfo.h' ,
607
+ 'fpu_control.h' ,
608
+ 'fstab.h' ,
609
+ 'fts.h' ,
610
+ 'getopt.h' ,
611
+ 'gshadow.h' ,
612
+ 'ieee754.h' ,
613
+ 'ifaddrs.h' ,
614
+ 'libintl.h' ,
615
+ 'mcheck.h' ,
616
+ 'mntent.h' ,
617
+ 'obstack.h' ,
618
+ 'paths.h' ,
619
+ 'printf.h' ,
620
+ 'pty.h' ,
621
+ 'resolv.h' ,
622
+ 'shadow.h' ,
623
+ 'sysexits.h' ,
624
+ 'ttyent.h' ,
625
+ # Hardware specific headers
626
+ 'arm_neon.h' ,
627
+ 'emmintrin.h' ,
628
+ 'xmmintin.h' ,
629
+ ])
630
+
521
631
# Type names
522
632
_TYPES = re .compile (
523
633
r'^(?:'
604
714
# _IncludeState.CheckNextIncludeOrder().
605
715
_C_SYS_HEADER = 1
606
716
_CPP_SYS_HEADER = 2
607
- _LIKELY_MY_HEADER = 3
608
- _POSSIBLE_MY_HEADER = 4
609
- _OTHER_HEADER = 5
717
+ _OTHER_SYS_HEADER = 3
718
+ _LIKELY_MY_HEADER = 4
719
+ _POSSIBLE_MY_HEADER = 5
720
+ _OTHER_HEADER = 6
610
721
611
722
# These constants define the current inline assembly state
612
723
_NO_ASM = 0 # Outside of inline assembly block
626
737
# Match string that indicates we're working on a Linux Kernel file.
627
738
_SEARCH_KERNEL_FILE = re .compile (r'\b(?:LINT_KERNEL_FILE)' )
628
739
629
- _NULL_TOKEN_PATTERN = re .compile (r'\bNULL\b' )
630
-
631
- _V8_PERSISTENT_PATTERN = re .compile (r'\bv8::Persistent\b' )
632
-
633
- _RIGHT_LEANING_POINTER_PATTERN = re .compile (r'[^=|(,\s><);&?:}]'
634
- r'(?<!(sizeof|return))'
635
- r'\s\*[a-zA-Z_][0-9a-zA-Z_]*' )
636
-
637
740
_regexp_compile_cache = {}
638
741
639
742
# {str, set(int)}: a map from error categories to sets of linenumbers
653
756
# Files to exclude from linting. This is set by the --exclude flag.
654
757
_excludes = None
655
758
656
- # Whether to suppress PrintInfo messages
759
+ # Whether to supress PrintInfo messages
657
760
_quiet = False
658
761
659
762
# The allowed line length of files.
@@ -862,23 +965,26 @@ class _IncludeState(object):
862
965
# needs to move backwards, CheckNextIncludeOrder will raise an error.
863
966
_INITIAL_SECTION = 0
864
967
_MY_H_SECTION = 1
865
- _OTHER_H_SECTION = 2
866
- _C_SECTION = 3
867
- _CPP_SECTION = 4
968
+ _C_SECTION = 2
969
+ _CPP_SECTION = 3
970
+ _OTHER_SYS_SECTION = 4
971
+ _OTHER_H_SECTION = 5
868
972
869
973
_TYPE_NAMES = {
870
974
_C_SYS_HEADER : 'C system header' ,
871
975
_CPP_SYS_HEADER : 'C++ system header' ,
976
+ _OTHER_SYS_HEADER : 'other system header' ,
872
977
_LIKELY_MY_HEADER : 'header this file implements' ,
873
978
_POSSIBLE_MY_HEADER : 'header this file may implement' ,
874
979
_OTHER_HEADER : 'other header' ,
875
980
}
876
981
_SECTION_NAMES = {
877
982
_INITIAL_SECTION : "... nothing. (This can't be an error.)" ,
878
983
_MY_H_SECTION : 'a header this file implements' ,
879
- _OTHER_H_SECTION : 'other header' ,
880
984
_C_SECTION : 'C system header' ,
881
985
_CPP_SECTION : 'C++ system header' ,
986
+ _OTHER_SYS_SECTION : 'other system header' ,
987
+ _OTHER_H_SECTION : 'other header' ,
882
988
}
883
989
884
990
def __init__ (self ):
@@ -991,6 +1097,12 @@ def CheckNextIncludeOrder(self, header_type):
991
1097
else :
992
1098
self ._last_header = ''
993
1099
return error_message
1100
+ elif header_type == _OTHER_SYS_HEADER :
1101
+ if self ._section <= self ._OTHER_SYS_SECTION :
1102
+ self ._section = self ._OTHER_SYS_SECTION
1103
+ else :
1104
+ self ._last_header = ''
1105
+ return error_message
994
1106
elif header_type == _LIKELY_MY_HEADER :
995
1107
if self ._section <= self ._MY_H_SECTION :
996
1108
self ._section = self ._MY_H_SECTION
@@ -2274,21 +2386,6 @@ def CheckForBadCharacters(filename, lines, error):
2274
2386
error (filename , linenum , 'readability/nul' , 5 , 'Line contains NUL byte.' )
2275
2387
2276
2388
2277
- def CheckInlineHeader (filename , include_state , error ):
2278
- """Logs an error if both a header and its inline variant are included."""
2279
-
2280
- all_headers = dict (item for sublist in include_state .include_list
2281
- for item in sublist )
2282
- bad_headers = set ('%s.h' % name [:- 6 ] for name in all_headers .keys ()
2283
- if name .endswith ('-inl.h' ))
2284
- bad_headers &= set (all_headers .keys ())
2285
-
2286
- for name in bad_headers :
2287
- err = '%s includes both %s and %s-inl.h' % (filename , name , name )
2288
- linenum = all_headers [name ]
2289
- error (filename , linenum , 'build/include_inline' , 5 , err )
2290
-
2291
-
2292
2389
def CheckForNewlineAtEOF (filename , lines , error ):
2293
2390
"""Logs an error if there is no newline char at the end of the file.
2294
2391
@@ -3312,7 +3409,7 @@ def CheckForFunctionLengths(filename, clean_lines, linenum,
3312
3409
"""Reports for long function bodies.
3313
3410
3314
3411
For an overview why this is done, see:
3315
- https://google.github.io/styleguide/ cppguide.html #Write_Short_Functions
3412
+ https://google-styleguide.googlecode.com/svn/trunk/ cppguide.xml #Write_Short_Functions
3316
3413
3317
3414
Uses a simplistic algorithm assuming other style guidelines
3318
3415
(especially spacing) are followed.
@@ -4538,71 +4635,6 @@ def CheckAltTokens(filename, clean_lines, linenum, error):
4538
4635
'Use operator %s instead of %s' % (
4539
4636
_ALT_TOKEN_REPLACEMENT [match .group (1 )], match .group (1 )))
4540
4637
4541
- def CheckNullTokens (filename , clean_lines , linenum , error ):
4542
- """Check NULL usage.
4543
-
4544
- Args:
4545
- filename: The name of the current file.
4546
- clean_lines: A CleansedLines instance containing the file.
4547
- linenum: The number of the line to check.
4548
- error: The function to call with any errors found.
4549
- """
4550
- line = clean_lines .elided [linenum ]
4551
-
4552
- # Avoid preprocessor lines
4553
- if Match (r'^\s*#' , line ):
4554
- return
4555
-
4556
- if line .find ('/*' ) >= 0 or line .find ('*/' ) >= 0 :
4557
- return
4558
-
4559
- for match in _NULL_TOKEN_PATTERN .finditer (line ):
4560
- error (filename , linenum , 'readability/null_usage' , 2 ,
4561
- 'Use nullptr instead of NULL' )
4562
-
4563
- def CheckV8PersistentTokens (filename , clean_lines , linenum , error ):
4564
- """Check v8::Persistent usage.
4565
-
4566
- Args:
4567
- filename: The name of the current file.
4568
- clean_lines: A CleansedLines instance containing the file.
4569
- linenum: The number of the line to check.
4570
- error: The function to call with any errors found.
4571
- """
4572
- line = clean_lines .elided [linenum ]
4573
-
4574
- # Avoid preprocessor lines
4575
- if Match (r'^\s*#' , line ):
4576
- return
4577
-
4578
- if line .find ('/*' ) >= 0 or line .find ('*/' ) >= 0 :
4579
- return
4580
-
4581
- for match in _V8_PERSISTENT_PATTERN .finditer (line ):
4582
- error (filename , linenum , 'runtime/v8_persistent' , 2 ,
4583
- 'Use v8::Global instead of v8::Persistent' )
4584
-
4585
- def CheckLeftLeaningPointer (filename , clean_lines , linenum , error ):
4586
- """Check for left-leaning pointer placement.
4587
-
4588
- Args:
4589
- filename: The name of the current file.
4590
- clean_lines: A CleansedLines instance containing the file.
4591
- linenum: The number of the line to check.
4592
- error: The function to call with any errors found.
4593
- """
4594
- line = clean_lines .elided [linenum ]
4595
-
4596
- # Avoid preprocessor lines
4597
- if Match (r'^\s*#' , line ):
4598
- return
4599
-
4600
- if '/*' in line or '*/' in line :
4601
- return
4602
-
4603
- for match in _RIGHT_LEANING_POINTER_PATTERN .finditer (line ):
4604
- error (filename , linenum , 'readability/pointer_notation' , 2 ,
4605
- 'Use left leaning pointer instead of right leaning' )
4606
4638
4607
4639
def GetLineWidth (line ):
4608
4640
"""Determines the width of the line in column positions.
@@ -4757,9 +4789,6 @@ def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state,
4757
4789
CheckSpacingForFunctionCall (filename , clean_lines , linenum , error )
4758
4790
CheckCheck (filename , clean_lines , linenum , error )
4759
4791
CheckAltTokens (filename , clean_lines , linenum , error )
4760
- CheckNullTokens (filename , clean_lines , linenum , error )
4761
- CheckV8PersistentTokens (filename , clean_lines , linenum , error )
4762
- CheckLeftLeaningPointer (filename , clean_lines , linenum , error )
4763
4792
classinfo = nesting_state .InnermostClass ()
4764
4793
if classinfo :
4765
4794
CheckSectionSpacing (filename , clean_lines , classinfo , linenum , error )
@@ -4820,6 +4849,8 @@ def _ClassifyInclude(fileinfo, include, is_system):
4820
4849
_C_SYS_HEADER
4821
4850
>>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'string', True)
4822
4851
_CPP_SYS_HEADER
4852
+ >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/foo.h', True)
4853
+ _OTHER_SYS_HEADER
4823
4854
>>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/foo.h', False)
4824
4855
_LIKELY_MY_HEADER
4825
4856
>>> _ClassifyInclude(FileInfo('foo/foo_unknown_extension.cc'),
@@ -4832,15 +4863,20 @@ def _ClassifyInclude(fileinfo, include, is_system):
4832
4863
# those already checked for above.
4833
4864
is_cpp_h = include in _CPP_HEADERS
4834
4865
4866
+ # Mark include as C header if in list or of type 'sys/*.h'.
4867
+ is_c_h = include in _C_HEADERS or Search (r'sys\/.*\.h' , include )
4868
+
4835
4869
# Headers with C++ extensions shouldn't be considered C system headers
4836
4870
if is_system and os .path .splitext (include )[1 ] in ['.hpp' , '.hxx' , '.h++' ]:
4837
4871
is_system = False
4838
4872
4839
4873
if is_system :
4840
4874
if is_cpp_h :
4841
4875
return _CPP_SYS_HEADER
4842
- else :
4876
+ if is_c_h :
4843
4877
return _C_SYS_HEADER
4878
+ else :
4879
+ return _OTHER_SYS_HEADER
4844
4880
4845
4881
# If the target file and the include we're checking share a
4846
4882
# basename when we drop common extensions, and the include
@@ -4936,10 +4972,11 @@ def CheckIncludeLine(filename, clean_lines, linenum, include_state, error):
4936
4972
include_state .include_list [- 1 ].append ((include , linenum ))
4937
4973
4938
4974
# We want to ensure that headers appear in the right order:
4939
- # 1) for foo.cc, foo.h
4940
- # 2) other project headers
4941
- # 3) c system files
4942
- # 4) cpp system files
4975
+ # 1) for foo.cc, foo.h (preferred location)
4976
+ # 2) c system files
4977
+ # 3) cpp system files
4978
+ # 4) for foo.cc, foo.h (deprecated location)
4979
+ # 5) other google headers
4943
4980
#
4944
4981
# We classify each include statement as one of those 5 types
4945
4982
# using a number of techniques. The include_state object keeps
@@ -5202,7 +5239,7 @@ def CheckLanguage(filename, clean_lines, linenum, file_extension,
5202
5239
and line [- 1 ] != '\\ ' ):
5203
5240
error (filename , linenum , 'build/namespaces' , 4 ,
5204
5241
'Do not use unnamed namespaces in header files. See '
5205
- 'https://google.github.io/styleguide/ cppguide.html #Namespaces'
5242
+ 'https://google-styleguide.googlecode.com/svn/trunk/ cppguide.xml #Namespaces'
5206
5243
' for more information.' )
5207
5244
5208
5245
@@ -6324,8 +6361,6 @@ def ProcessFileData(filename, file_extension, lines, error,
6324
6361
6325
6362
CheckForNewlineAtEOF (filename , lines , error )
6326
6363
6327
- CheckInlineHeader (filename , include_state , error )
6328
-
6329
6364
def ProcessConfigOverrides (filename ):
6330
6365
""" Loads the configuration files and processes the config overrides.
6331
6366
@@ -6344,7 +6379,7 @@ def ProcessConfigOverrides(filename):
6344
6379
if not base_name :
6345
6380
break # Reached the root directory.
6346
6381
6347
- cfg_file = os .path .join (abs_path , ".cpplint " )
6382
+ cfg_file = os .path .join (abs_path , "CPPLINT.cfg " )
6348
6383
abs_filename = abs_path
6349
6384
if not os .path .isfile (cfg_file ):
6350
6385
continue
0 commit comments