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

Method Update

support/cpplint.py:2587–2747  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 1

ProcessLineFunction · 0.80

Calls 15

UpdatePreprocessorMethod · 0.95
SeenOpenBraceMethod · 0.95
MatchFunction · 0.85
_NamespaceInfoClass · 0.85
_ClassInfoClass · 0.85
errorFunction · 0.85
_ExternCInfoClass · 0.85
_BlockInfoClass · 0.85
matchMethod · 0.80
countMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected