MCPcopy Create free account
hub / github.com/4paradigm/OpenMLDB / Update

Method Update

steps/cpplint.py:3087–3249  ·  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

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

Callers 1

ProcessLineFunction · 0.45

Calls 11

UpdatePreprocessorMethod · 0.95
SeenOpenBraceMethod · 0.95
MatchFunction · 0.85
_NamespaceInfoClass · 0.85
_ClassInfoClass · 0.85
_ExternCInfoClass · 0.85
_BlockInfoClass · 0.85
appendMethod · 0.80
CheckBeginMethod · 0.45
CheckEndMethod · 0.45

Tested by

no test coverage detected