OLD | NEW |
1 #!/usr/bin/python2.4 | 1 #!/usr/bin/python2.4 |
2 # | 2 # |
3 # Copyright (c) 2009 Google Inc. All rights reserved. | 3 # Copyright (c) 2009 Google Inc. All rights reserved. |
4 # | 4 # |
5 # Redistribution and use in source and binary forms, with or without | 5 # Redistribution and use in source and binary forms, with or without |
6 # modification, are permitted provided that the following conditions are | 6 # modification, are permitted provided that the following conditions are |
7 # met: | 7 # met: |
8 # | 8 # |
9 # * Redistributions of source code must retain the above copyright | 9 # * Redistributions of source code must retain the above copyright |
10 # notice, this list of conditions and the following disclaimer. | 10 # notice, this list of conditions and the following disclaimer. |
(...skipping 1053 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1064 # set ifndef to the header guard presented on the #ifndef line. | 1064 # set ifndef to the header guard presented on the #ifndef line. |
1065 ifndef = linesplit[1] | 1065 ifndef = linesplit[1] |
1066 ifndef_linenum = linenum | 1066 ifndef_linenum = linenum |
1067 if not define and linesplit[0] == '#define': | 1067 if not define and linesplit[0] == '#define': |
1068 define = linesplit[1] | 1068 define = linesplit[1] |
1069 # find the last occurrence of #endif, save entire line | 1069 # find the last occurrence of #endif, save entire line |
1070 if line.startswith('#endif'): | 1070 if line.startswith('#endif'): |
1071 endif = line | 1071 endif = line |
1072 endif_linenum = linenum | 1072 endif_linenum = linenum |
1073 | 1073 |
1074 if not ifndef or not define or ifndef != define: | 1074 if not ifndef: |
1075 error(filename, 0, 'build/header_guard', 5, | 1075 error(filename, 0, 'build/header_guard', 5, |
1076 'No #ifndef header guard found, suggested CPP variable is: %s' % | 1076 'No #ifndef header guard found, suggested CPP variable is: %s' % |
1077 cppvar) | 1077 cppvar) |
1078 return | 1078 return |
1079 | 1079 |
| 1080 if not define: |
| 1081 error(filename, 0, 'build/header_guard', 5, |
| 1082 'No #define header guard found, suggested CPP variable is: %s' % |
| 1083 cppvar) |
| 1084 return |
| 1085 |
1080 # The guard should be PATH_FILE_H_, but we also allow PATH_FILE_H__ | 1086 # The guard should be PATH_FILE_H_, but we also allow PATH_FILE_H__ |
1081 # for backward compatibility. | 1087 # for backward compatibility. |
1082 if ifndef != cppvar: | 1088 if ifndef != cppvar: |
1083 error_level = 0 | 1089 error_level = 0 |
1084 if ifndef != cppvar + '_': | 1090 if ifndef != cppvar + '_': |
1085 error_level = 5 | 1091 error_level = 5 |
1086 | 1092 |
1087 ParseNolintSuppressions(filename, lines[ifndef_linenum], ifndef_linenum, | 1093 ParseNolintSuppressions(filename, lines[ifndef_linenum], ifndef_linenum, |
1088 error) | 1094 error) |
1089 error(filename, ifndef_linenum, 'build/header_guard', error_level, | 1095 error(filename, ifndef_linenum, 'build/header_guard', error_level, |
1090 '#ifndef header guard has wrong style, please use: %s' % cppvar) | 1096 '#ifndef header guard has wrong style, please use: %s' % cppvar) |
1091 | 1097 |
| 1098 if define != ifndef: |
| 1099 error(filename, 0, 'build/header_guard', 5, |
| 1100 '#ifndef and #define don\'t match, suggested CPP variable is: %s' % |
| 1101 cppvar) |
| 1102 return |
| 1103 |
1092 if endif != ('#endif // %s' % cppvar): | 1104 if endif != ('#endif // %s' % cppvar): |
1093 error_level = 0 | 1105 error_level = 0 |
1094 if endif != ('#endif // %s' % (cppvar + '_')): | 1106 if endif != ('#endif // %s' % (cppvar + '_')): |
1095 error_level = 5 | 1107 error_level = 5 |
1096 | 1108 |
1097 ParseNolintSuppressions(filename, lines[endif_linenum], endif_linenum, | 1109 ParseNolintSuppressions(filename, lines[endif_linenum], endif_linenum, |
1098 error) | 1110 error) |
1099 error(filename, endif_linenum, 'build/header_guard', error_level, | 1111 error(filename, endif_linenum, 'build/header_guard', error_level, |
1100 '#endif line should be "#endif // %s"' % cppvar) | 1112 '#endif line should be "#endif // %s"' % cppvar) |
1101 | 1113 |
(...skipping 2238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3340 _cpplint_state.ResetErrorCounts() | 3352 _cpplint_state.ResetErrorCounts() |
3341 for filename in filenames: | 3353 for filename in filenames: |
3342 ProcessFile(filename, _cpplint_state.verbose_level) | 3354 ProcessFile(filename, _cpplint_state.verbose_level) |
3343 _cpplint_state.PrintErrorCounts() | 3355 _cpplint_state.PrintErrorCounts() |
3344 | 3356 |
3345 sys.exit(_cpplint_state.error_count > 0) | 3357 sys.exit(_cpplint_state.error_count > 0) |
3346 | 3358 |
3347 | 3359 |
3348 if __name__ == '__main__': | 3360 if __name__ == '__main__': |
3349 main() | 3361 main() |
OLD | NEW |