MCPcopy Create free account
hub / github.com/alibaba/GraphScope / Update

Method Update

analytical_engine/misc/cpplint.py:3076–3238  ·  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

3074
3075 # TODO(unknown): Update() is too long, but we will refactor later.
3076 def Update(self, filename, clean_lines, linenum, error):
3077 """Update nesting state with current line.
3078
3079 Args:
3080 filename: The name of the current file.
3081 clean_lines: A CleansedLines instance containing the file.
3082 linenum: The number of the line to check.
3083 error: The function to call with any errors found.
3084 """
3085 line = clean_lines.elided[linenum]
3086
3087 # Remember top of the previous nesting stack.
3088 #
3089 # The stack is always pushed/popped and not modified in place, so
3090 # we can just do a shallow copy instead of copy.deepcopy. Using
3091 # deepcopy would slow down cpplint by ~28%.
3092 if self.stack:
3093 self.previous_stack_top = self.stack[-1]
3094 else:
3095 self.previous_stack_top = None
3096
3097 # Update pp_stack
3098 self.UpdatePreprocessor(line)
3099
3100 # Count parentheses. This is to avoid adding struct arguments to
3101 # the nesting stack.
3102 if self.stack:
3103 inner_block = self.stack[-1]
3104 depth_change = line.count('(') - line.count(')')
3105 inner_block.open_parentheses += depth_change
3106
3107 # Also check if we are starting or ending an inline assembly block.
3108 if inner_block.inline_asm in (_NO_ASM, _END_ASM):
3109 if (depth_change != 0 and
3110 inner_block.open_parentheses == 1 and
3111 _MATCH_ASM.match(line)):
3112 # Enter assembly block
3113 inner_block.inline_asm = _INSIDE_ASM
3114 else:
3115 # Not entering assembly block. If previous line was _END_ASM,
3116 # we will now shift to _NO_ASM state.
3117 inner_block.inline_asm = _NO_ASM
3118 elif (inner_block.inline_asm == _INSIDE_ASM and
3119 inner_block.open_parentheses == 0):
3120 # Exit assembly block
3121 inner_block.inline_asm = _END_ASM
3122
3123 # Consume namespace declaration at the beginning of the line. Do
3124 # this in a loop so that we catch same line declarations like this:
3125 # namespace proto2 { namespace bridge { class MessageSet; } }
3126 while True:
3127 # Match start of namespace. The "\b\s*" below catches namespace
3128 # declarations even if it weren't followed by a whitespace, this
3129 # is so that we don't confuse our namespace checker. The
3130 # missing spaces will be flagged by CheckSpacing.
3131 namespace_decl_match = Match(r'^\s*namespace\b\s*([:\w]+)?(.*)$', line)
3132 if not namespace_decl_match:
3133 break

Callers 1

ProcessLineFunction · 0.45

Calls 15

UpdatePreprocessorMethod · 0.95
SeenOpenBraceMethod · 0.95
_NamespaceInfoClass · 0.85
_ClassInfoClass · 0.85
_ExternCInfoClass · 0.85
_BlockInfoClass · 0.85
findMethod · 0.80
MatchFunction · 0.70
countMethod · 0.65
appendMethod · 0.65
matchMethod · 0.45

Tested by

no test coverage detected