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