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

Function CheckForNonConstReference

analytical_engine/misc/cpplint.py:5557–5693  ·  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 line to check.

(filename, clean_lines, linenum,
                              nesting_state, error)

Source from the content-addressed store, hash-verified

5555
5556
5557def CheckForNonConstReference(filename, clean_lines, linenum,
5558 nesting_state, error):
5559 """Check for non-const references.
5560
5561 Separate from CheckLanguage since it scans backwards from current
5562 line, instead of scanning forward.
5563
5564 Args:
5565 filename: The name of the current file.
5566 clean_lines: A CleansedLines instance containing the file.
5567 linenum: The number of the line to check.
5568 nesting_state: A NestingState instance which maintains information about
5569 the current stack of nested blocks being parsed.
5570 error: The function to call with any errors found.
5571 """
5572 # Do nothing if there is no '&' on current line.
5573 line = clean_lines.elided[linenum]
5574 if '&' not in line:
5575 return
5576
5577 # If a function is inherited, current function doesn't have much of
5578 # a choice, so any non-const references should not be blamed on
5579 # derived function.
5580 if IsDerivedFunction(clean_lines, linenum):
5581 return
5582
5583 # Don't warn on out-of-line method definitions, as we would warn on the
5584 # in-line declaration, if it isn't marked with 'override'.
5585 if IsOutOfLineMethodDefinition(clean_lines, linenum):
5586 return
5587
5588 # Long type names may be broken across multiple lines, usually in one
5589 # of these forms:
5590 # LongType
5591 # ::LongTypeContinued &identifier
5592 # LongType::
5593 # LongTypeContinued &identifier
5594 # LongType<
5595 # ...>::LongTypeContinued &identifier
5596 #
5597 # If we detected a type split across two lines, join the previous
5598 # line to current line so that we can match const references
5599 # accordingly.
5600 #
5601 # Note that this only scans back one line, since scanning back
5602 # arbitrary number of lines would be expensive. If you have a type
5603 # that spans more than 2 lines, please use a typedef.
5604 if linenum > 1:
5605 previous = None
5606 if Match(r'\s*::(?:[\w<>]|::)+\s*&\s*\S', line):
5607 # previous_line\n + ::current_line
5608 previous = Search(r'\b((?:const\s*)?(?:[\w<>]|::)+[\w<>])\s*$',
5609 clean_lines.elided[linenum - 1])
5610 elif Match(r'\s*[a-zA-Z_]([\w<>]|::)+\s*&\s*\S', line):
5611 # previous_line::\n + current_line
5612 previous = Search(r'\b((?:const\s*)?(?:[\w<>]|::)+::)\s*$',
5613 clean_lines.elided[linenum - 1])
5614 if previous:

Callers 1

ProcessLineFunction · 0.85

Calls 8

IsDerivedFunctionFunction · 0.85
SearchFunction · 0.85
ReverseCloseExpressionFunction · 0.85
IsInitializerListFunction · 0.85
ReplaceAllFunction · 0.85
MatchFunction · 0.70
groupMethod · 0.45

Tested by

no test coverage detected