MCPcopy Index your code
hub / github.com/cpplint/cpplint / CheckForNonConstReference

Function CheckForNonConstReference

cpplint.py:6312–6454  ·  view source on GitHub ↗

Check for non-const references. Separate from CheckLanguage since it scans backwards from current line, instead of scanning forward. Args: filename: The name of the current file. clean_lines: A CleansedLines instance containing the file. linenum: The number of the lin

(filename, clean_lines, linenum, nesting_state, error)

Source from the content-addressed store, hash-verified

6310
6311
6312def CheckForNonConstReference(filename, clean_lines, linenum, nesting_state, error):
6313 """Check for non-const references.
6314
6315 Separate from CheckLanguage since it scans backwards from current
6316 line, instead of scanning forward.
6317
6318 Args:
6319 filename: The name of the current file.
6320 clean_lines: A CleansedLines instance containing the file.
6321 linenum: The number of the line to check.
6322 nesting_state: A NestingState instance which maintains information about
6323 the current stack of nested blocks being parsed.
6324 error: The function to call with any errors found.
6325 """
6326 # Do nothing if there is no '&' on current line.
6327 line = clean_lines.elided[linenum]
6328 if "&" not in line:
6329 return
6330
6331 # If a function is inherited, current function doesn't have much of
6332 # a choice, so any non-const references should not be blamed on
6333 # derived function.
6334 if IsDerivedFunction(clean_lines, linenum):
6335 return
6336
6337 # Don't warn on out-of-line method definitions, as we would warn on the
6338 # in-line declaration, if it isn't marked with 'override'.
6339 if IsOutOfLineMethodDefinition(clean_lines, linenum):
6340 return
6341
6342 # Long type names may be broken across multiple lines, usually in one
6343 # of these forms:
6344 # LongType
6345 # ::LongTypeContinued &identifier
6346 # LongType::
6347 # LongTypeContinued &identifier
6348 # LongType<
6349 # ...>::LongTypeContinued &identifier
6350 #
6351 # If we detected a type split across two lines, join the previous
6352 # line to current line so that we can match const references
6353 # accordingly.
6354 #
6355 # Note that this only scans back one line, since scanning back
6356 # arbitrary number of lines would be expensive. If you have a type
6357 # that spans more than 2 lines, please use a typedef.
6358 if linenum > 1:
6359 previous = None
6360 if re.match(r"\s*::(?:[\w<>]|::)+\s*&\s*\S", line):
6361 # previous_line\n + ::current_line
6362 previous = re.search(
6363 r"\b((?:const\s*)?(?:[\w<>]|::)+[\w<>])\s*$", clean_lines.elided[linenum - 1]
6364 )
6365 elif re.match(r"\s*[a-zA-Z_]([\w<>]|::)+\s*&\s*\S", line):
6366 # previous_line::\n + current_line
6367 previous = re.search(
6368 r"\b((?:const\s*)?(?:[\w<>]|::)+::)\s*$", clean_lines.elided[linenum - 1]
6369 )

Callers 1

ProcessLineFunction · 0.85

Calls 4

IsDerivedFunctionFunction · 0.85
ReverseCloseExpressionFunction · 0.85
IsInitializerListFunction · 0.85

Tested by

no test coverage detected