MCPcopy Create free account
hub / github.com/alibaba/graph-learn / Update

Method Update

dynamic_graph_service/ci/cpplint.py:2805–2967  ·  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

2803
2804 # TODO(unknown): Update() is too long, but we will refactor later.
2805 def Update(self, filename, clean_lines, linenum, error):
2806 """Update nesting state with current line.
2807
2808 Args:
2809 filename: The name of the current file.
2810 clean_lines: A CleansedLines instance containing the file.
2811 linenum: The number of the line to check.
2812 error: The function to call with any errors found.
2813 """
2814 line = clean_lines.elided[linenum]
2815
2816 # Remember top of the previous nesting stack.
2817 #
2818 # The stack is always pushed/popped and not modified in place, so
2819 # we can just do a shallow copy instead of copy.deepcopy. Using
2820 # deepcopy would slow down cpplint by ~28%.
2821 if self.stack:
2822 self.previous_stack_top = self.stack[-1]
2823 else:
2824 self.previous_stack_top = None
2825
2826 # Update pp_stack
2827 self.UpdatePreprocessor(line)
2828
2829 # Count parentheses. This is to avoid adding struct arguments to
2830 # the nesting stack.
2831 if self.stack:
2832 inner_block = self.stack[-1]
2833 depth_change = line.count('(') - line.count(')')
2834 inner_block.open_parentheses += depth_change
2835
2836 # Also check if we are starting or ending an inline assembly block.
2837 if inner_block.inline_asm in (_NO_ASM, _END_ASM):
2838 if (depth_change != 0 and
2839 inner_block.open_parentheses == 1 and
2840 _MATCH_ASM.match(line)):
2841 # Enter assembly block
2842 inner_block.inline_asm = _INSIDE_ASM
2843 else:
2844 # Not entering assembly block. If previous line was _END_ASM,
2845 # we will now shift to _NO_ASM state.
2846 inner_block.inline_asm = _NO_ASM
2847 elif (inner_block.inline_asm == _INSIDE_ASM and
2848 inner_block.open_parentheses == 0):
2849 # Exit assembly block
2850 inner_block.inline_asm = _END_ASM
2851
2852 # Consume namespace declaration at the beginning of the line. Do
2853 # this in a loop so that we catch same line declarations like this:
2854 # namespace proto2 { namespace bridge { class MessageSet; } }
2855 while True:
2856 # Match start of namespace. The "\b\s*" below catches namespace
2857 # declarations even if it weren't followed by a whitespace, this
2858 # is so that we don't confuse our namespace checker. The
2859 # missing spaces will be flagged by CheckSpacing.
2860 namespace_decl_match = Match(r'^\s*namespace\b\s*([:\w]+)?(.*)$', line)
2861 if not namespace_decl_match:
2862 break

Callers 1

ProcessLineFunction · 0.45

Calls 14

UpdatePreprocessorMethod · 0.95
SeenOpenBraceMethod · 0.95
MatchFunction · 0.85
_NamespaceInfoClass · 0.85
_ClassInfoClass · 0.85
_ExternCInfoClass · 0.85
_BlockInfoClass · 0.85
countMethod · 0.80
findMethod · 0.80
popMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected