MCPcopy Create free account
hub / github.com/OpenMS/OpenMS / CloseExpression

Function CloseExpression

src/tests/coding/cpplint.py:2074–2115  ·  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

2072
2073
2074def CloseExpression(clean_lines, linenum, pos):
2075 """If input points to ( or { or [ or <, finds the position that closes it.
2076
2077 If lines[linenum][pos] points to a '(' or '{' or '[' or '<', finds the
2078 linenum/pos that correspond to the closing of the expression.
2079
2080 TODO(unknown): cpplint spends a fair bit of time matching parentheses.
2081 Ideally we would want to index all opening and closing parentheses once
2082 and have CloseExpression be just a simple lookup, but due to preprocessor
2083 tricks, this is not so easy.
2084
2085 Args:
2086 clean_lines: A CleansedLines instance containing the file.
2087 linenum: The number of the line to check.
2088 pos: A position on the line.
2089
2090 Returns:
2091 A tuple (line, linenum, pos) pointer *past* the closing brace, or
2092 (line, len(lines), -1) if we never find a close. Note we ignore
2093 strings and comments when matching; and the line we return is the
2094 'cleansed' line at linenum.
2095 """
2096
2097 line = clean_lines.elided[linenum]
2098 if (line[pos] not in '({[<') or Match(r'<[<=]', line[pos:]):
2099 return (line, clean_lines.NumLines(), -1)
2100
2101 # Check first line
2102 (end_pos, stack) = FindEndOfExpressionInLine(line, pos, [])
2103 if end_pos > -1:
2104 return (line, linenum, end_pos)
2105
2106 # Continue scanning forward
2107 while stack and linenum < clean_lines.NumLines() - 1:
2108 linenum += 1
2109 line = clean_lines.elided[linenum]
2110 (end_pos, stack) = FindEndOfExpressionInLine(line, 0, stack)
2111 if end_pos > -1:
2112 return (line, linenum, end_pos)
2113
2114 # Did not find end of expression before end of file, give up
2115 return (line, clean_lines.NumLines(), -1)
2116
2117
2118def 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
MatchFunction · 0.70

Tested by

no test coverage detected