Checks rules from the 'C++ language rules' section of cppguide.html. Some of these rules are hard to test (function overloading, using uint32 inappropriately), but we do the best we can. Args: filename: The name of the current file. clean_lines: A CleansedLines instance containing th
(filename, clean_lines, linenum, file_extension,
include_state, nesting_state, error)
| 5234 | |
| 5235 | |
| 5236 | def CheckLanguage(filename, clean_lines, linenum, file_extension, |
| 5237 | include_state, nesting_state, error): |
| 5238 | """Checks rules from the 'C++ language rules' section of cppguide.html. |
| 5239 | |
| 5240 | Some of these rules are hard to test (function overloading, using |
| 5241 | uint32 inappropriately), but we do the best we can. |
| 5242 | |
| 5243 | Args: |
| 5244 | filename: The name of the current file. |
| 5245 | clean_lines: A CleansedLines instance containing the file. |
| 5246 | linenum: The number of the line to check. |
| 5247 | file_extension: The extension (without the dot) of the filename. |
| 5248 | include_state: An _IncludeState instance in which the headers are inserted. |
| 5249 | nesting_state: A NestingState instance which maintains information about |
| 5250 | the current stack of nested blocks being parsed. |
| 5251 | error: The function to call with any errors found. |
| 5252 | """ |
| 5253 | # If the line is empty or consists of entirely a comment, no need to |
| 5254 | # check it. |
| 5255 | line = clean_lines.elided[linenum] |
| 5256 | if not line: |
| 5257 | return |
| 5258 | |
| 5259 | match = _RE_PATTERN_INCLUDE.search(line) |
| 5260 | if match: |
| 5261 | CheckIncludeLine(filename, clean_lines, linenum, include_state, error) |
| 5262 | return |
| 5263 | |
| 5264 | # Reset include state across preprocessor directives. This is meant |
| 5265 | # to silence warnings for conditional includes. |
| 5266 | match = Match(r'^\s*#\s*(if|ifdef|ifndef|elif|else|endif)\b', line) |
| 5267 | if match: |
| 5268 | include_state.ResetSection(match.group(1)) |
| 5269 | |
| 5270 | |
| 5271 | # Perform other checks now that we are sure that this is not an include line |
| 5272 | CheckCasts(filename, clean_lines, linenum, error) |
| 5273 | CheckGlobalStatic(filename, clean_lines, linenum, error) |
| 5274 | CheckPrintf(filename, clean_lines, linenum, error) |
| 5275 | |
| 5276 | if IsHeaderExtension(file_extension): |
| 5277 | # TODO(unknown): check that 1-arg constructors are explicit. |
| 5278 | # How to tell it's a constructor? |
| 5279 | # (handled in CheckForNonStandardConstructs for now) |
| 5280 | # TODO(unknown): check that classes declare or disable copy/assign |
| 5281 | # (level 1 error) |
| 5282 | pass |
| 5283 | |
| 5284 | # Check if people are using the verboten C basic types. The only exception |
| 5285 | # we regularly allow is "unsigned short port" for port. |
| 5286 | if Search(r'\bshort port\b', line): |
| 5287 | if not Search(r'\bunsigned short port\b', line): |
| 5288 | error(filename, linenum, 'runtime/int', 4, |
| 5289 | 'Use "unsigned short" for ports, not "short"') |
| 5290 | else: |
| 5291 | match = Search(r'\b(short|long(?! +double)|long long)\b', line) |
| 5292 | if match: |
| 5293 | error(filename, linenum, 'runtime/int', 4, |
no test coverage detected