MCPcopy Create free account
hub / github.com/OpenMS/OpenMS / CheckForNonConstReference

Function CheckForNonConstReference

src/tests/coding/cpplint.py:5554–5690  ·  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

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