MCPcopy Create free account
hub / github.com/4paradigm/OpenMLDB / CheckForNonConstReference

Function CheckForNonConstReference

steps/cpplint.py:5567–5703  ·  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

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

Callers 1

ProcessLineFunction · 0.85

Calls 7

IsDerivedFunctionFunction · 0.85
MatchFunction · 0.85
SearchFunction · 0.85
ReverseCloseExpressionFunction · 0.85
IsInitializerListFunction · 0.85
ReplaceAllFunction · 0.85

Tested by

no test coverage detected