MCPcopy Create free account
hub / github.com/apache/mesos / CheckForNonConstReference

Function CheckForNonConstReference

support/cpplint.py:5013–5149  ·  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

5011
5012
5013def CheckForNonConstReference(filename, clean_lines, linenum,
5014 nesting_state, error):
5015 """Check for non-const references.
5016
5017 Separate from CheckLanguage since it scans backwards from current
5018 line, instead of scanning forward.
5019
5020 Args:
5021 filename: The name of the current file.
5022 clean_lines: A CleansedLines instance containing the file.
5023 linenum: The number of the line to check.
5024 nesting_state: A NestingState instance which maintains information about
5025 the current stack of nested blocks being parsed.
5026 error: The function to call with any errors found.
5027 """
5028 # Do nothing if there is no '&' on current line.
5029 line = clean_lines.elided[linenum]
5030 if '&' not in line:
5031 return
5032
5033 # If a function is inherited, current function doesn't have much of
5034 # a choice, so any non-const references should not be blamed on
5035 # derived function.
5036 if IsDerivedFunction(clean_lines, linenum):
5037 return
5038
5039 # Don't warn on out-of-line method definitions, as we would warn on the
5040 # in-line declaration, if it isn't marked with 'override'.
5041 if IsOutOfLineMethodDefinition(clean_lines, linenum):
5042 return
5043
5044 # Long type names may be broken across multiple lines, usually in one
5045 # of these forms:
5046 # LongType
5047 # ::LongTypeContinued &identifier
5048 # LongType::
5049 # LongTypeContinued &identifier
5050 # LongType<
5051 # ...>::LongTypeContinued &identifier
5052 #
5053 # If we detected a type split across two lines, join the previous
5054 # line to current line so that we can match const references
5055 # accordingly.
5056 #
5057 # Note that this only scans back one line, since scanning back
5058 # arbitrary number of lines would be expensive. If you have a type
5059 # that spans more than 2 lines, please use a typedef.
5060 if linenum > 1:
5061 previous = None
5062 if Match(r'\s*::(?:[\w<>]|::)+\s*&\s*\S', line):
5063 # previous_line\n + ::current_line
5064 previous = Search(r'\b((?:const\s*)?(?:[\w<>]|::)+[\w<>])\s*$',
5065 clean_lines.elided[linenum - 1])
5066 elif Match(r'\s*[a-zA-Z_]([\w<>]|::)+\s*&\s*\S', line):
5067 # previous_line::\n + current_line
5068 previous = Search(r'\b((?:const\s*)?(?:[\w<>]|::)+::)\s*$',
5069 clean_lines.elided[linenum - 1])
5070 if previous:

Callers 1

ProcessLineFunction · 0.85

Calls 9

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

Tested by

no test coverage detected