MCPcopy Index your code
hub / github.com/nodejs/node / CloseExpression

Function CloseExpression

tools/cpplint.py:2318–2359  ·  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. TODO(google): cpplint spends a fair bit of time matching parentheses. Ideally

(clean_lines, linenum, pos)

Source from the content-addressed store, hash-verified

2316
2317
2318def CloseExpression(clean_lines, linenum, pos):
2319 """If input points to ( or { or [ or <, finds the position that closes it.
2320
2321 If lines[linenum][pos] points to a '(' or '{' or '[' or '<', finds the
2322 linenum/pos that correspond to the closing of the expression.
2323
2324 TODO(google): cpplint spends a fair bit of time matching parentheses.
2325 Ideally we would want to index all opening and closing parentheses once
2326 and have CloseExpression be just a simple lookup, but due to preprocessor
2327 tricks, this is not so easy.
2328
2329 Args:
2330 clean_lines: A CleansedLines instance containing the file.
2331 linenum: The number of the line to check.
2332 pos: A position on the line.
2333
2334 Returns:
2335 A tuple (line, linenum, pos) pointer *past* the closing brace, or
2336 (line, len(lines), -1) if we never find a close. Note we ignore
2337 strings and comments when matching; and the line we return is the
2338 'cleansed' line at linenum.
2339 """
2340
2341 line = clean_lines.elided[linenum]
2342 if (line[pos] not in "({[<") or re.match(r"<[<=]", line[pos:]):
2343 return (line, clean_lines.NumLines(), -1)
2344
2345 # Check first line
2346 (end_pos, stack) = FindEndOfExpressionInLine(line, pos, [])
2347 if end_pos > -1:
2348 return (line, linenum, end_pos)
2349
2350 # Continue scanning forward
2351 while stack and linenum < clean_lines.NumLines() - 1:
2352 linenum += 1
2353 line = clean_lines.elided[linenum]
2354 (end_pos, stack) = FindEndOfExpressionInLine(line, 0, stack)
2355 if end_pos > -1:
2356 return (line, linenum, end_pos)
2357
2358 # Did not find end of expression before end of file, give up
2359 return (line, clean_lines.NumLines(), -1)
2360
2361
2362def FindStartOfExpressionInLine(line, endpos, stack):

Callers 10

CheckOperatorSpacingFunction · 0.85
CheckBracesSpacingFunction · 0.85
CheckBracesFunction · 0.85
CheckTrailingSemicolonFunction · 0.85
CheckEmptyBlockBodyFunction · 0.85
CheckCheckFunction · 0.85
IsDerivedFunctionFunction · 0.85
CheckCastsFunction · 0.85
CheckRedundantVirtualFunction · 0.85

Calls 3

NumLinesMethod · 0.80
matchMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…