Find the position just after the end of current parenthesized expression. Args: line: a CleansedLines line. startpos: start searching at this position. stack: nesting stack at startpos. Returns: On finding matching end: (index just after matching end, None) On finding an un
(line, startpos, stack)
| 1517 | |
| 1518 | |
| 1519 | def FindEndOfExpressionInLine(line, startpos, stack): |
| 1520 | """Find the position just after the end of current parenthesized expression. |
| 1521 | |
| 1522 | Args: |
| 1523 | line: a CleansedLines line. |
| 1524 | startpos: start searching at this position. |
| 1525 | stack: nesting stack at startpos. |
| 1526 | |
| 1527 | Returns: |
| 1528 | On finding matching end: (index just after matching end, None) |
| 1529 | On finding an unclosed expression: (-1, None) |
| 1530 | Otherwise: (-1, new stack at end of this line) |
| 1531 | """ |
| 1532 | for i in xrange(startpos, len(line)): |
| 1533 | char = line[i] |
| 1534 | if char in '([{': |
| 1535 | # Found start of parenthesized expression, push to expression stack |
| 1536 | stack.append(char) |
| 1537 | elif char == '<': |
| 1538 | # Found potential start of template argument list |
| 1539 | if i > 0 and line[i - 1] == '<': |
| 1540 | # Left shift operator |
| 1541 | if stack and stack[-1] == '<': |
| 1542 | stack.pop() |
| 1543 | if not stack: |
| 1544 | return (-1, None) |
| 1545 | elif i > 0 and Search(r'\boperator\s*$', line[0:i]): |
| 1546 | # operator<, don't add to stack |
| 1547 | continue |
| 1548 | else: |
| 1549 | # Tentative start of template argument list |
| 1550 | stack.append('<') |
| 1551 | elif char in ')]}': |
| 1552 | # Found end of parenthesized expression. |
| 1553 | # |
| 1554 | # If we are currently expecting a matching '>', the pending '<' |
| 1555 | # must have been an operator. Remove them from expression stack. |
| 1556 | while stack and stack[-1] == '<': |
| 1557 | stack.pop() |
| 1558 | if not stack: |
| 1559 | return (-1, None) |
| 1560 | if ((stack[-1] == '(' and char == ')') or |
| 1561 | (stack[-1] == '[' and char == ']') or |
| 1562 | (stack[-1] == '{' and char == '}')): |
| 1563 | stack.pop() |
| 1564 | if not stack: |
| 1565 | return (i + 1, None) |
| 1566 | else: |
| 1567 | # Mismatched parentheses |
| 1568 | return (-1, None) |
| 1569 | elif char == '>': |
| 1570 | # Found potential end of template argument list. |
| 1571 | |
| 1572 | # Ignore "->" and operator functions |
| 1573 | if (i > 0 and |
| 1574 | (line[i - 1] == '-' or Search(r'\boperator\s*$', line[0:i - 1]))): |
| 1575 | continue |
| 1576 |
no test coverage detected
searching dependent graphs…