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

Function CloseExpression

scripts/cpp_lint.py:1258–1301  ·  view source on GitHub ↗

If input points to ( or { or [ or <, finds the position that closes it. If lines[linenum][pos] points to a '(' or '{' or '[' or '<', finds the linenum/pos that correspond to the closing of the expression. Args: clean_lines: A CleansedLines instance containing the file. linenum: The n

(clean_lines, linenum, pos)

Source from the content-addressed store, hash-verified

1256
1257
1258def CloseExpression(clean_lines, linenum, pos):
1259 """If input points to ( or { or [ or <, finds the position that closes it.
1260
1261 If lines[linenum][pos] points to a '(' or '{' or '[' or '<', finds the
1262 linenum/pos that correspond to the closing of the expression.
1263
1264 Args:
1265 clean_lines: A CleansedLines instance containing the file.
1266 linenum: The number of the line to check.
1267 pos: A position on the line.
1268
1269 Returns:
1270 A tuple (line, linenum, pos) pointer *past* the closing brace, or
1271 (line, len(lines), -1) if we never find a close. Note we ignore
1272 strings and comments when matching; and the line we return is the
1273 'cleansed' line at linenum.
1274 """
1275
1276 line = clean_lines.elided[linenum]
1277 startchar = line[pos]
1278 if startchar not in '({[<':
1279 return (line, clean_lines.NumLines(), -1)
1280 if startchar == '(': endchar = ')'
1281 if startchar == '[': endchar = ']'
1282 if startchar == '{': endchar = '}'
1283 if startchar == '<': endchar = '>'
1284
1285 # Check first line
1286 (end_pos, num_open) = FindEndOfExpressionInLine(
1287 line, pos, 0, startchar, endchar)
1288 if end_pos > -1:
1289 return (line, linenum, end_pos)
1290
1291 # Continue scanning forward
1292 while linenum < clean_lines.NumLines() - 1:
1293 linenum += 1
1294 line = clean_lines.elided[linenum]
1295 (end_pos, num_open) = FindEndOfExpressionInLine(
1296 line, 0, num_open, startchar, endchar)
1297 if end_pos > -1:
1298 return (line, linenum, end_pos)
1299
1300 # Did not find endchar before end of file, give up
1301 return (line, clean_lines.NumLines(), -1)
1302
1303
1304def FindStartOfExpressionInLine(line, endpos, depth, startchar, endchar):

Callers 4

CheckSpacingFunction · 0.85
CheckBracesFunction · 0.85
CheckEmptyBlockBodyFunction · 0.85
CheckCheckFunction · 0.85

Calls 2

NumLinesMethod · 0.80

Tested by

no test coverage detected