MCPcopy Create free account
hub / github.com/OpenPTrack/open_ptrack_v2 / CheckForNonConstReference

Function CheckForNonConstReference

rtpose_wrapper/scripts/cpp_lint.py:4134–4244  ·  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

4132 ' for more information.')
4133
4134def CheckForNonConstReference(filename, clean_lines, linenum,
4135 nesting_state, error):
4136 """Check for non-const references.
4137
4138 Separate from CheckLanguage since it scans backwards from current
4139 line, instead of scanning forward.
4140
4141 Args:
4142 filename: The name of the current file.
4143 clean_lines: A CleansedLines instance containing the file.
4144 linenum: The number of the line to check.
4145 nesting_state: A _NestingState instance which maintains information about
4146 the current stack of nested blocks being parsed.
4147 error: The function to call with any errors found.
4148 """
4149 # Do nothing if there is no '&' on current line.
4150 line = clean_lines.elided[linenum]
4151 if '&' not in line:
4152 return
4153
4154 # Long type names may be broken across multiple lines, usually in one
4155 # of these forms:
4156 # LongType
4157 # ::LongTypeContinued &identifier
4158 # LongType::
4159 # LongTypeContinued &identifier
4160 # LongType<
4161 # ...>::LongTypeContinued &identifier
4162 #
4163 # If we detected a type split across two lines, join the previous
4164 # line to current line so that we can match const references
4165 # accordingly.
4166 #
4167 # Note that this only scans back one line, since scanning back
4168 # arbitrary number of lines would be expensive. If you have a type
4169 # that spans more than 2 lines, please use a typedef.
4170 if linenum > 1:
4171 previous = None
4172 if Match(r'\s*::(?:[\w<>]|::)+\s*&\s*\S', line):
4173 # previous_line\n + ::current_line
4174 previous = Search(r'\b((?:const\s*)?(?:[\w<>]|::)+[\w<>])\s*$',
4175 clean_lines.elided[linenum - 1])
4176 elif Match(r'\s*[a-zA-Z_]([\w<>]|::)+\s*&\s*\S', line):
4177 # previous_line::\n + current_line
4178 previous = Search(r'\b((?:const\s*)?(?:[\w<>]|::)+::)\s*$',
4179 clean_lines.elided[linenum - 1])
4180 if previous:
4181 line = previous.group(1) + line.lstrip()
4182 else:
4183 # Check for templated parameter that is split across multiple lines
4184 endpos = line.rfind('>')
4185 if endpos > -1:
4186 (_, startline, startpos) = ReverseCloseExpression(
4187 clean_lines, linenum, endpos)
4188 if startpos > -1 and startline < linenum:
4189 # Found the matching < on an earlier line, collect all
4190 # pieces up to current line.
4191 line = ''

Callers 1

ProcessLineFunction · 0.85

Calls 5

MatchFunction · 0.85
SearchFunction · 0.85
ReverseCloseExpressionFunction · 0.85
ReplaceAllFunction · 0.85
errorFunction · 0.85

Tested by

no test coverage detected