MCPcopy Create free account
hub / github.com/OpenMS/OpenMS / Update

Method Update

src/tests/coding/cpplint.py:3073–3235  ·  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

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

Callers 1

ProcessLineFunction · 0.80

Calls 14

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

Tested by

no test coverage detected