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

Function FindPreviousMatchingAngleBracket

scripts/cpp_lint.py:2590–2644  ·  view source on GitHub ↗

Find the corresponding < that started a template. Args: clean_lines: A CleansedLines instance containing the file. linenum: Current line number. init_prefix: Part of the current line before the initial >. Returns: True if a matching bracket exists.

(clean_lines, linenum, init_prefix)

Source from the content-addressed store, hash-verified

2588
2589
2590def FindPreviousMatchingAngleBracket(clean_lines, linenum, init_prefix):
2591 """Find the corresponding < that started a template.
2592
2593 Args:
2594 clean_lines: A CleansedLines instance containing the file.
2595 linenum: Current line number.
2596 init_prefix: Part of the current line before the initial >.
2597
2598 Returns:
2599 True if a matching bracket exists.
2600 """
2601 line = init_prefix
2602 nesting_stack = ['>']
2603 while True:
2604 # Find the previous operator
2605 match = Search(r'^(.*)([<>(),;\[\]])[^<>(),;\[\]]*$', line)
2606 if match:
2607 # Found an operator, update nesting stack
2608 operator = match.group(2)
2609 line = match.group(1)
2610
2611 if nesting_stack[-1] == '>':
2612 # Expecting opening angle bracket
2613 if operator in ('>', ')', ']'):
2614 nesting_stack.append(operator)
2615 elif operator == '<':
2616 nesting_stack.pop()
2617 if not nesting_stack:
2618 # Found matching angle bracket
2619 return True
2620 elif operator == ',':
2621 # Got a comma before a bracket, this is most likely a
2622 # template argument. The opening angle bracket is probably
2623 # there if we look for it, so just return early here.
2624 return True
2625 else:
2626 # Got some other operator.
2627 return False
2628
2629 else:
2630 # Expecting opening parenthesis or opening bracket
2631 if operator in ('>', ')', ']'):
2632 nesting_stack.append(operator)
2633 elif operator in ('(', '['):
2634 nesting_stack.pop()
2635
2636 else:
2637 # Scan the previous line
2638 linenum -= 1
2639 if linenum < 0:
2640 break
2641 line = clean_lines.elided[linenum]
2642
2643 # Exhausted all earlier lines and still no matching angle bracket.
2644 return False
2645
2646
2647def CheckSpacing(filename, clean_lines, linenum, nesting_state, error):

Callers 1

CheckSpacingFunction · 0.85

Calls 2

SearchFunction · 0.85
popMethod · 0.80

Tested by

no test coverage detected