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

Function CloseExpression

support/cpplint.py:1602–1643  ·  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(unknown): cpplint spends a fair bit of time matching parentheses. Ideally we wou

(clean_lines, linenum, pos)

Source from the content-addressed store, hash-verified

1600
1601
1602def CloseExpression(clean_lines, linenum, pos):
1603 """If input points to ( or { or [ or <, finds the position that closes it.
1604
1605 If lines[linenum][pos] points to a '(' or '{' or '[' or '<', finds the
1606 linenum/pos that correspond to the closing of the expression.
1607
1608 TODO(unknown): cpplint spends a fair bit of time matching parentheses.
1609 Ideally we would want to index all opening and closing parentheses once
1610 and have CloseExpression be just a simple lookup, but due to preprocessor
1611 tricks, this is not so easy.
1612
1613 Args:
1614 clean_lines: A CleansedLines instance containing the file.
1615 linenum: The number of the line to check.
1616 pos: A position on the line.
1617
1618 Returns:
1619 A tuple (line, linenum, pos) pointer *past* the closing brace, or
1620 (line, len(lines), -1) if we never find a close. Note we ignore
1621 strings and comments when matching; and the line we return is the
1622 'cleansed' line at linenum.
1623 """
1624
1625 line = clean_lines.elided[linenum]
1626 if (line[pos] not in '({[<') or Match(r'<[<=]', line[pos:]):
1627 return (line, clean_lines.NumLines(), -1)
1628
1629 # Check first line
1630 (end_pos, stack) = FindEndOfExpressionInLine(line, pos, [])
1631 if end_pos > -1:
1632 return (line, linenum, end_pos)
1633
1634 # Continue scanning forward
1635 while stack and linenum < clean_lines.NumLines() - 1:
1636 linenum += 1
1637 line = clean_lines.elided[linenum]
1638 (end_pos, stack) = FindEndOfExpressionInLine(line, 0, stack)
1639 if end_pos > -1:
1640 return (line, linenum, end_pos)
1641
1642 # Did not find end of expression before end of file, give up
1643 return (line, clean_lines.NumLines(), -1)
1644
1645
1646def 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

MatchFunction · 0.85
NumLinesMethod · 0.80

Tested by

no test coverage detected