Skip to content

Commit 1ccffc7

Browse files
lgulichtkruse
authored andcommitted
add list of c headers
1 parent d312259 commit 1ccffc7

File tree

8 files changed

+292
-141
lines changed

8 files changed

+292
-141
lines changed

cpplint.py

Lines changed: 136 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,120 @@
514514
'cwctype',
515515
])
516516

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+
517631
# Type names
518632
_TYPES = re.compile(
519633
r'^(?:'
@@ -600,9 +714,10 @@
600714
# _IncludeState.CheckNextIncludeOrder().
601715
_C_SYS_HEADER = 1
602716
_CPP_SYS_HEADER = 2
603-
_LIKELY_MY_HEADER = 3
604-
_POSSIBLE_MY_HEADER = 4
605-
_OTHER_HEADER = 5
717+
_OTHER_SYS_HEADER = 3
718+
_LIKELY_MY_HEADER = 4
719+
_POSSIBLE_MY_HEADER = 5
720+
_OTHER_HEADER = 6
606721

607722
# These constants define the current inline assembly state
608723
_NO_ASM = 0 # Outside of inline assembly block
@@ -852,11 +967,13 @@ class _IncludeState(object):
852967
_MY_H_SECTION = 1
853968
_C_SECTION = 2
854969
_CPP_SECTION = 3
855-
_OTHER_H_SECTION = 4
970+
_OTHER_SYS_SECTION = 4
971+
_OTHER_H_SECTION = 5
856972

857973
_TYPE_NAMES = {
858974
_C_SYS_HEADER: 'C system header',
859975
_CPP_SYS_HEADER: 'C++ system header',
976+
_OTHER_SYS_HEADER: 'other system header',
860977
_LIKELY_MY_HEADER: 'header this file implements',
861978
_POSSIBLE_MY_HEADER: 'header this file may implement',
862979
_OTHER_HEADER: 'other header',
@@ -866,6 +983,7 @@ class _IncludeState(object):
866983
_MY_H_SECTION: 'a header this file implements',
867984
_C_SECTION: 'C system header',
868985
_CPP_SECTION: 'C++ system header',
986+
_OTHER_SYS_SECTION: 'other system header',
869987
_OTHER_H_SECTION: 'other header',
870988
}
871989

@@ -979,6 +1097,12 @@ def CheckNextIncludeOrder(self, header_type):
9791097
else:
9801098
self._last_header = ''
9811099
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
9821106
elif header_type == _LIKELY_MY_HEADER:
9831107
if self._section <= self._MY_H_SECTION:
9841108
self._section = self._MY_H_SECTION
@@ -4725,6 +4849,8 @@ def _ClassifyInclude(fileinfo, include, is_system):
47254849
_C_SYS_HEADER
47264850
>>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'string', True)
47274851
_CPP_SYS_HEADER
4852+
>>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/foo.h', True)
4853+
_OTHER_SYS_HEADER
47284854
>>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/foo.h', False)
47294855
_LIKELY_MY_HEADER
47304856
>>> _ClassifyInclude(FileInfo('foo/foo_unknown_extension.cc'),
@@ -4737,15 +4863,20 @@ def _ClassifyInclude(fileinfo, include, is_system):
47374863
# those already checked for above.
47384864
is_cpp_h = include in _CPP_HEADERS
47394865

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+
47404869
# Headers with C++ extensions shouldn't be considered C system headers
47414870
if is_system and os.path.splitext(include)[1] in ['.hpp', '.hxx', '.h++']:
47424871
is_system = False
47434872

47444873
if is_system:
47454874
if is_cpp_h:
47464875
return _CPP_SYS_HEADER
4747-
else:
4876+
if is_c_h:
47484877
return _C_SYS_HEADER
4878+
else:
4879+
return _OTHER_SYS_HEADER
47494880

47504881
# If the target file and the include we're checking share a
47514882
# basename when we drop common extensions, and the include

cpplint_unittest.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5288,6 +5288,20 @@ def testCheckNextIncludeOrder_CppThenC(self):
52885288
self.include_state.CheckNextIncludeOrder(
52895289
cpplint._C_SYS_HEADER))
52905290

5291+
def testCheckNextIncludeOrder_OtherSysThenC(self):
5292+
self.assertEqual('', self.include_state.CheckNextIncludeOrder(
5293+
cpplint._OTHER_SYS_HEADER))
5294+
self.assertEqual('Found C system header after other system header',
5295+
self.include_state.CheckNextIncludeOrder(
5296+
cpplint._C_SYS_HEADER))
5297+
5298+
def testCheckNextIncludeOrder_OtherSysThenCpp(self):
5299+
self.assertEqual('', self.include_state.CheckNextIncludeOrder(
5300+
cpplint._OTHER_SYS_HEADER))
5301+
self.assertEqual('Found C++ system header after other system header',
5302+
self.include_state.CheckNextIncludeOrder(
5303+
cpplint._CPP_SYS_HEADER))
5304+
52915305
def testCheckNextIncludeOrder_LikelyThenCpp(self):
52925306
self.assertEqual('', self.include_state.CheckNextIncludeOrder(
52935307
cpplint._LIKELY_MY_HEADER))
@@ -5313,13 +5327,30 @@ def testCheckNextIncludeOrder_CppThenPossible(self):
53135327
self.assertEqual('', self.include_state.CheckNextIncludeOrder(
53145328
cpplint._POSSIBLE_MY_HEADER))
53155329

5330+
def testCheckNextIncludeOrder_CppThenOtherSys(self):
5331+
self.assertEqual('', self.include_state.CheckNextIncludeOrder(
5332+
cpplint._CPP_SYS_HEADER))
5333+
self.assertEqual('', self.include_state.CheckNextIncludeOrder(
5334+
cpplint._OTHER_SYS_HEADER))
5335+
5336+
def testCheckNextIncludeOrder_OtherSysThenPossible(self):
5337+
self.assertEqual('', self.include_state.CheckNextIncludeOrder(
5338+
cpplint._OTHER_SYS_HEADER))
5339+
self.assertEqual('', self.include_state.CheckNextIncludeOrder(
5340+
cpplint._POSSIBLE_MY_HEADER))
5341+
5342+
53165343
def testClassifyInclude(self):
53175344
file_info = cpplint.FileInfo
53185345
classify_include = cpplint._ClassifyInclude
53195346
self.assertEqual(cpplint._C_SYS_HEADER,
53205347
classify_include(file_info('foo/foo.cc'),
53215348
'stdio.h',
53225349
True))
5350+
self.assertEqual(cpplint._C_SYS_HEADER,
5351+
classify_include(file_info('foo/foo.cc'),
5352+
'sys/time.h',
5353+
True))
53235354
self.assertEqual(cpplint._CPP_SYS_HEADER,
53245355
classify_include(file_info('foo/foo.cc'),
53255356
'string',
@@ -5328,6 +5359,10 @@ def testClassifyInclude(self):
53285359
classify_include(file_info('foo/foo.cc'),
53295360
'typeinfo',
53305361
True))
5362+
self.assertEqual(cpplint._OTHER_SYS_HEADER,
5363+
classify_include(file_info('foo/foo.cc'),
5364+
'foo/foo.h',
5365+
True))
53315366
self.assertEqual(cpplint._OTHER_HEADER,
53325367
classify_include(file_info('foo/foo.cc'),
53335368
'string',
@@ -5344,7 +5379,6 @@ def testClassifyInclude(self):
53445379
classify_include(file_info('foo/foo.h++'),
53455380
'boost/any.hpp',
53465381
True))
5347-
53485382
self.assertEqual(cpplint._LIKELY_MY_HEADER,
53495383
classify_include(file_info('foo/foo.cc'),
53505384
'foo/foo-inl.h',

samples/codelite-sample/simple.def

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ src/*
33
4
44
Done processing src/pptable.cpp
55
Done processing src/pptable.h
6-
Total errors found: 680
6+
Total errors found: 685
77

88
src/pptable.cpp:0: No copyright message found. You should have a line: "Copyright [year] <Copyright Owner>" [legal/copyright] [5]
99
src/pptable.cpp:1: Include the directory when naming .h files [build/include_subdir] [4]
10+
src/pptable.cpp:3: Found C++ system header after other system header. Should be: pptable.h, c system, c++ system, other. [build/include_order] [4]
1011
src/pptable.cpp:6: { should almost always be at the end of the previous line [whitespace/braces] [4]
1112
src/pptable.cpp:7: Tab found; better to use spaces [whitespace/tab] [1]
1213
src/pptable.cpp:8: Tab found; better to use spaces [whitespace/tab] [1]
@@ -607,7 +608,11 @@ src/pptable.cpp:663: Tab found; better to use spaces [whitespace/tab] [1]
607608
src/pptable.h:0: No copyright message found. You should have a line: "Copyright [year] <Copyright Owner>" [legal/copyright] [5]
608609
src/pptable.h:1: #ifndef header guard has wrong style, please use: SAMPLES_CODELITE_SAMPLE_SRC_PPTABLE_H_ [build/header_guard] [5]
609610
src/pptable.h:131: #endif line should be "#endif // SAMPLES_CODELITE_SAMPLE_SRC_PPTABLE_H_" [build/header_guard] [5]
610-
src/pptable.h:6: Found C system header after C++ system header. Should be: pptable.h, c system, c++ system, other. [build/include_order] [4]
611+
src/pptable.h:5: Found C++ system header after other system header. Should be: pptable.h, c system, c++ system, other. [build/include_order] [4]
612+
src/pptable.h:7: Found C++ system header after other system header. Should be: pptable.h, c system, c++ system, other. [build/include_order] [4]
613+
src/pptable.h:8: Found C++ system header after other system header. Should be: pptable.h, c system, c++ system, other. [build/include_order] [4]
614+
src/pptable.h:9: Found C++ system header after other system header. Should be: pptable.h, c system, c++ system, other. [build/include_order] [4]
615+
src/pptable.h:10: Found C++ system header after other system header. Should be: pptable.h, c system, c++ system, other. [build/include_order] [4]
611616
src/pptable.h:19: At least two spaces is best between code and comments [whitespace/comments] [2]
612617
src/pptable.h:27: Tab found; better to use spaces [whitespace/tab] [1]
613618
src/pptable.h:28: Tab found; better to use spaces [whitespace/tab] [1]

samples/protobuf-sample/simple.def

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,10 @@ src/*
44
Done processing src/descriptor.pb.cc
55
Done processing src/descriptor.pb.h
66
Done processing src/descriptor_unittest.cc
7-
Total errors found: 2643
7+
Total errors found: 2618
88

99
src/descriptor.pb.cc:0: No copyright message found. You should have a line: "Copyright [year] <Copyright Owner>" [legal/copyright] [5]
10-
src/descriptor.pb.cc:9: Found C system header after C++ system header. Should be: descriptor.pb.h, c system, c++ system, other. [build/include_order] [4]
11-
src/descriptor.pb.cc:10: Found C system header after C++ system header. Should be: descriptor.pb.h, c system, c++ system, other. [build/include_order] [4]
12-
src/descriptor.pb.cc:11: Found C system header after C++ system header. Should be: descriptor.pb.h, c system, c++ system, other. [build/include_order] [4]
13-
src/descriptor.pb.cc:12: Found C system header after C++ system header. Should be: descriptor.pb.h, c system, c++ system, other. [build/include_order] [4]
14-
src/descriptor.pb.cc:13: Found C system header after C++ system header. Should be: descriptor.pb.h, c system, c++ system, other. [build/include_order] [4]
15-
src/descriptor.pb.cc:14: Found C system header after C++ system header. Should be: descriptor.pb.h, c system, c++ system, other. [build/include_order] [4]
16-
src/descriptor.pb.cc:15: Found C system header after C++ system header. Should be: descriptor.pb.h, c system, c++ system, other. [build/include_order] [4]
17-
src/descriptor.pb.cc:16: Found C system header after C++ system header. Should be: descriptor.pb.h, c system, c++ system, other. [build/include_order] [4]
18-
src/descriptor.pb.cc:17: Found C system header after C++ system header. Should be: descriptor.pb.h, c system, c++ system, other. [build/include_order] [4]
10+
src/descriptor.pb.cc:7: Found C++ system header after other system header. Should be: descriptor.pb.h, c system, c++ system, other. [build/include_order] [4]
1911
src/descriptor.pb.cc:34: Lines should be <= 80 characters long [whitespace/line_length] [2]
2012
src/descriptor.pb.cc:37: Lines should be <= 80 characters long [whitespace/line_length] [2]
2113
src/descriptor.pb.cc:43: Lines should be <= 80 characters long [whitespace/line_length] [2]
@@ -1630,7 +1622,6 @@ src/descriptor.pb.cc:5: samples/protobuf-sample/src/descriptor.pb.cc should inc
16301622
src/descriptor.pb.h:0: No copyright message found. You should have a line: "Copyright [year] <Copyright Owner>" [legal/copyright] [5]
16311623
src/descriptor.pb.h:4: #ifndef header guard has wrong style, please use: SAMPLES_PROTOBUF_SAMPLE_SRC_DESCRIPTOR_PB_H_ [build/header_guard] [5]
16321624
src/descriptor.pb.h:7714: #endif line should be "#endif // SAMPLES_PROTOBUF_SAMPLE_SRC_DESCRIPTOR_PB_H_" [build/header_guard] [5]
1633-
src/descriptor.pb.h:9: Found C system header after C++ system header. Should be: descriptor.pb.h, c system, c++ system, other. [build/include_order] [4]
16341625
src/descriptor.pb.h:37: Lines should be <= 80 characters long [whitespace/line_length] [2]
16351626
src/descriptor.pb.h:87: Lines should be <= 80 characters long [whitespace/line_length] [2]
16361627
src/descriptor.pb.h:88: Lines should be <= 80 characters long [whitespace/line_length] [2]
@@ -2456,23 +2447,7 @@ src/descriptor.pb.h:7697: Lines should be <= 80 characters long [whitespace/li
24562447
src/descriptor.pb.h:7699: Lines should be <= 80 characters long [whitespace/line_length] [2]
24572448
src/descriptor.pb.h:7702: Lines should be <= 80 characters long [whitespace/line_length] [2]
24582449
src/descriptor.pb.h:7704: Lines should be <= 80 characters long [whitespace/line_length] [2]
2459-
src/descriptor_unittest.cc:43: Found C system header after C++ system header. Should be: descriptor_unittest.h, c system, c++ system, other. [build/include_order] [4]
2460-
src/descriptor_unittest.cc:44: Found C system header after C++ system header. Should be: descriptor_unittest.h, c system, c++ system, other. [build/include_order] [4]
2461-
src/descriptor_unittest.cc:45: Found C system header after C++ system header. Should be: descriptor_unittest.h, c system, c++ system, other. [build/include_order] [4]
2462-
src/descriptor_unittest.cc:46: Found C system header after C++ system header. Should be: descriptor_unittest.h, c system, c++ system, other. [build/include_order] [4]
2463-
src/descriptor_unittest.cc:47: Found C system header after C++ system header. Should be: descriptor_unittest.h, c system, c++ system, other. [build/include_order] [4]
2464-
src/descriptor_unittest.cc:48: Found C system header after C++ system header. Should be: descriptor_unittest.h, c system, c++ system, other. [build/include_order] [4]
2465-
src/descriptor_unittest.cc:49: Found C system header after C++ system header. Should be: descriptor_unittest.h, c system, c++ system, other. [build/include_order] [4]
2466-
src/descriptor_unittest.cc:50: Found C system header after C++ system header. Should be: descriptor_unittest.h, c system, c++ system, other. [build/include_order] [4]
2467-
src/descriptor_unittest.cc:51: Found C system header after C++ system header. Should be: descriptor_unittest.h, c system, c++ system, other. [build/include_order] [4]
2468-
src/descriptor_unittest.cc:52: Found C system header after C++ system header. Should be: descriptor_unittest.h, c system, c++ system, other. [build/include_order] [4]
2469-
src/descriptor_unittest.cc:53: Found C system header after C++ system header. Should be: descriptor_unittest.h, c system, c++ system, other. [build/include_order] [4]
2470-
src/descriptor_unittest.cc:55: Found C system header after C++ system header. Should be: descriptor_unittest.h, c system, c++ system, other. [build/include_order] [4]
2471-
src/descriptor_unittest.cc:56: Found C system header after C++ system header. Should be: descriptor_unittest.h, c system, c++ system, other. [build/include_order] [4]
24722450
src/descriptor_unittest.cc:57: "google/protobuf/stubs/logging.h" already included at src/descriptor_unittest.cc:56 [build/include] [4]
2473-
src/descriptor_unittest.cc:58: Found C system header after C++ system header. Should be: descriptor_unittest.h, c system, c++ system, other. [build/include_order] [4]
2474-
src/descriptor_unittest.cc:59: Found C system header after C++ system header. Should be: descriptor_unittest.h, c system, c++ system, other. [build/include_order] [4]
2475-
src/descriptor_unittest.cc:60: Found C system header after C++ system header. Should be: descriptor_unittest.h, c system, c++ system, other. [build/include_order] [4]
24762451
src/descriptor_unittest.cc:734: Extra space before ) [whitespace/parens] [2]
24772452
src/descriptor_unittest.cc:735: Extra space before ) [whitespace/parens] [2]
24782453
src/descriptor_unittest.cc:822: Extra space after ( in function call [whitespace/parens] [4]

0 commit comments

Comments
 (0)