MCPcopy Create free account
hub / github.com/alibaba/GraphScope / CheckLanguage

Function CheckLanguage

analytical_engine/misc/cpplint.py:5226–5384  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 1

ProcessLineFunction · 0.85

Calls 12

CheckIncludeLineFunction · 0.85
CheckCastsFunction · 0.85
CheckGlobalStaticFunction · 0.85
CheckPrintfFunction · 0.85
IsHeaderExtensionFunction · 0.85
SearchFunction · 0.85
_GetTextInsideFunction · 0.85
ResetSectionMethod · 0.80
findMethod · 0.80
splitMethod · 0.80
MatchFunction · 0.70
groupMethod · 0.45

Tested by

no test coverage detected