MCPcopy Index your code
hub / github.com/nodejs/node / CheckForNonConstReference

Function CheckForNonConstReference

tools/cpplint.py:6456–6598  ·  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

6454
6455
6456def CheckForNonConstReference(filename, clean_lines, linenum, nesting_state, error):
6457 """Check for non-const references.
6458
6459 Separate from CheckLanguage since it scans backwards from current
6460 line, instead of scanning forward.
6461
6462 Args:
6463 filename: The name of the current file.
6464 clean_lines: A CleansedLines instance containing the file.
6465 linenum: The number of the line to check.
6466 nesting_state: A NestingState instance which maintains information about
6467 the current stack of nested blocks being parsed.
6468 error: The function to call with any errors found.
6469 """
6470 # Do nothing if there is no '&' on current line.
6471 line = clean_lines.elided[linenum]
6472 if "&" not in line:
6473 return
6474
6475 # If a function is inherited, current function doesn't have much of
6476 # a choice, so any non-const references should not be blamed on
6477 # derived function.
6478 if IsDerivedFunction(clean_lines, linenum):
6479 return
6480
6481 # Don't warn on out-of-line method definitions, as we would warn on the
6482 # in-line declaration, if it isn't marked with 'override'.
6483 if IsOutOfLineMethodDefinition(clean_lines, linenum):
6484 return
6485
6486 # Long type names may be broken across multiple lines, usually in one
6487 # of these forms:
6488 # LongType
6489 # ::LongTypeContinued &identifier
6490 # LongType::
6491 # LongTypeContinued &identifier
6492 # LongType<
6493 # ...>::LongTypeContinued &identifier
6494 #
6495 # If we detected a type split across two lines, join the previous
6496 # line to current line so that we can match const references
6497 # accordingly.
6498 #
6499 # Note that this only scans back one line, since scanning back
6500 # arbitrary number of lines would be expensive. If you have a type
6501 # that spans more than 2 lines, please use a typedef.
6502 if linenum > 1:
6503 previous = None
6504 if re.match(r"\s*::(?:[\w<>]|::)+\s*&\s*\S", line):
6505 # previous_line\n + ::current_line
6506 previous = re.search(
6507 r"\b((?:const\s*)?(?:[\w<>]|::)+[\w<>])\s*$", clean_lines.elided[linenum - 1]
6508 )
6509 elif re.match(r"\s*[a-zA-Z_]([\w<>]|::)+\s*&\s*\S", line):
6510 # previous_line::\n + current_line
6511 previous = re.search(
6512 r"\b((?:const\s*)?(?:[\w<>]|::)+::)\s*$", clean_lines.elided[linenum - 1]
6513 )

Callers 1

ProcessLineFunction · 0.85

Calls 9

IsDerivedFunctionFunction · 0.85
ReverseCloseExpressionFunction · 0.85
IsInitializerListFunction · 0.85
matchMethod · 0.65
rangeFunction · 0.50
maxFunction · 0.50
errorFunction · 0.50
searchMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…