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

Method Update

util/cpplint.py:2487–2649  ·  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

2485
2486 # TODO(unknown): Update() is too long, but we will refactor later.
2487 def Update(self, filename, clean_lines, linenum, error):
2488 """Update nesting state with current line.
2489
2490 Args:
2491 filename: The name of the current file.
2492 clean_lines: A CleansedLines instance containing the file.
2493 linenum: The number of the line to check.
2494 error: The function to call with any errors found.
2495 """
2496 line = clean_lines.elided[linenum]
2497
2498 # Remember top of the previous nesting stack.
2499 #
2500 # The stack is always pushed/popped and not modified in place, so
2501 # we can just do a shallow copy instead of copy.deepcopy. Using
2502 # deepcopy would slow down cpplint by ~28%.
2503 if self.stack:
2504 self.previous_stack_top = self.stack[-1]
2505 else:
2506 self.previous_stack_top = None
2507
2508 # Update pp_stack
2509 self.UpdatePreprocessor(line)
2510
2511 # Count parentheses. This is to avoid adding struct arguments to
2512 # the nesting stack.
2513 if self.stack:
2514 inner_block = self.stack[-1]
2515 depth_change = line.count('(') - line.count(')')
2516 inner_block.open_parentheses += depth_change
2517
2518 # Also check if we are starting or ending an inline assembly block.
2519 if inner_block.inline_asm in (_NO_ASM, _END_ASM):
2520 if (depth_change != 0 and
2521 inner_block.open_parentheses == 1 and
2522 _MATCH_ASM.match(line)):
2523 # Enter assembly block
2524 inner_block.inline_asm = _INSIDE_ASM
2525 else:
2526 # Not entering assembly block. If previous line was _END_ASM,
2527 # we will now shift to _NO_ASM state.
2528 inner_block.inline_asm = _NO_ASM
2529 elif (inner_block.inline_asm == _INSIDE_ASM and
2530 inner_block.open_parentheses == 0):
2531 # Exit assembly block
2532 inner_block.inline_asm = _END_ASM
2533
2534 # Consume namespace declaration at the beginning of the line. Do
2535 # this in a loop so that we catch same line declarations like this:
2536 # namespace proto2 { namespace bridge { class MessageSet; } }
2537 while True:
2538 # Match start of namespace. The "\b\s*" below catches namespace
2539 # declarations even if it weren't followed by a whitespace, this
2540 # is so that we don't confuse our namespace checker. The
2541 # missing spaces will be flagged by CheckSpacing.
2542 namespace_decl_match = Match(r'^\s*namespace\b\s*([:\w]+)?(.*)$', line)
2543 if not namespace_decl_match:
2544 break

Callers 1

ProcessLineFunction · 0.80

Calls 11

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

Tested by

no test coverage detected