MCPcopy Create free account
hub / github.com/BVLC/caffe / CheckForNonConstReference

Function CheckForNonConstReference

scripts/cpp_lint.py:4138–4248  ·  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

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

Callers 1

ProcessLineFunction · 0.85

Calls 4

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

Tested by

no test coverage detected