Update nesting state with current line. Args: filename: The name of the current file. clean_lines: A CleansedLines instance containing the file. linenum: The number of the line to check. error: The function to call with any errors found.
(self, filename, clean_lines, linenum, error)
| 2580 | |
| 2581 | # TODO(unknown): Update() is too long, but we will refactor later. |
| 2582 | def Update(self, filename, clean_lines, linenum, error): |
| 2583 | """Update nesting state with current line. |
| 2584 | |
| 2585 | Args: |
| 2586 | filename: The name of the current file. |
| 2587 | clean_lines: A CleansedLines instance containing the file. |
| 2588 | linenum: The number of the line to check. |
| 2589 | error: The function to call with any errors found. |
| 2590 | """ |
| 2591 | line = clean_lines.elided[linenum] |
| 2592 | |
| 2593 | # Remember top of the previous nesting stack. |
| 2594 | # |
| 2595 | # The stack is always pushed/popped and not modified in place, so |
| 2596 | # we can just do a shallow copy instead of copy.deepcopy. Using |
| 2597 | # deepcopy would slow down cpplint by ~28%. |
| 2598 | if self.stack: |
| 2599 | self.previous_stack_top = self.stack[-1] |
| 2600 | else: |
| 2601 | self.previous_stack_top = None |
| 2602 | |
| 2603 | # Update pp_stack |
| 2604 | self.UpdatePreprocessor(line) |
| 2605 | |
| 2606 | # Count parentheses. This is to avoid adding struct arguments to |
| 2607 | # the nesting stack. |
| 2608 | if self.stack: |
| 2609 | inner_block = self.stack[-1] |
| 2610 | depth_change = line.count('(') - line.count(')') |
| 2611 | inner_block.open_parentheses += depth_change |
| 2612 | |
| 2613 | # Also check if we are starting or ending an inline assembly block. |
| 2614 | if inner_block.inline_asm in (_NO_ASM, _END_ASM): |
| 2615 | if (depth_change != 0 and |
| 2616 | inner_block.open_parentheses == 1 and |
| 2617 | _MATCH_ASM.match(line)): |
| 2618 | # Enter assembly block |
| 2619 | inner_block.inline_asm = _INSIDE_ASM |
| 2620 | else: |
| 2621 | # Not entering assembly block. If previous line was _END_ASM, |
| 2622 | # we will now shift to _NO_ASM state. |
| 2623 | inner_block.inline_asm = _NO_ASM |
| 2624 | elif (inner_block.inline_asm == _INSIDE_ASM and |
| 2625 | inner_block.open_parentheses == 0): |
| 2626 | # Exit assembly block |
| 2627 | inner_block.inline_asm = _END_ASM |
| 2628 | |
| 2629 | # Consume namespace declaration at the beginning of the line. Do |
| 2630 | # this in a loop so that we catch same line declarations like this: |
| 2631 | # namespace proto2 { namespace bridge { class MessageSet; } } |
| 2632 | while True: |
| 2633 | # Match start of namespace. The "\b\s*" below catches namespace |
| 2634 | # declarations even if it weren't followed by a whitespace, this |
| 2635 | # is so that we don't confuse our namespace checker. The |
| 2636 | # missing spaces will be flagged by CheckSpacing. |
| 2637 | namespace_decl_match = Match(r'^\s*namespace\b\s*([:\w]+)?(.*)$', line) |
| 2638 | if not namespace_decl_match: |
| 2639 | break |
no test coverage detected