MCPcopy Create free account
hub / github.com/OpenPTrack/open_ptrack_v2 / Update

Method Update

rtpose_wrapper/scripts/cpp_lint.py:2004–2158  ·  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

2002 pass
2003
2004 def Update(self, filename, clean_lines, linenum, error):
2005 """Update nesting state with current line.
2006
2007 Args:
2008 filename: The name of the current file.
2009 clean_lines: A CleansedLines instance containing the file.
2010 linenum: The number of the line to check.
2011 error: The function to call with any errors found.
2012 """
2013 line = clean_lines.elided[linenum]
2014
2015 # Update pp_stack first
2016 self.UpdatePreprocessor(line)
2017
2018 # Count parentheses. This is to avoid adding struct arguments to
2019 # the nesting stack.
2020 if self.stack:
2021 inner_block = self.stack[-1]
2022 depth_change = line.count('(') - line.count(')')
2023 inner_block.open_parentheses += depth_change
2024
2025 # Also check if we are starting or ending an inline assembly block.
2026 if inner_block.inline_asm in (_NO_ASM, _END_ASM):
2027 if (depth_change != 0 and
2028 inner_block.open_parentheses == 1 and
2029 _MATCH_ASM.match(line)):
2030 # Enter assembly block
2031 inner_block.inline_asm = _INSIDE_ASM
2032 else:
2033 # Not entering assembly block. If previous line was _END_ASM,
2034 # we will now shift to _NO_ASM state.
2035 inner_block.inline_asm = _NO_ASM
2036 elif (inner_block.inline_asm == _INSIDE_ASM and
2037 inner_block.open_parentheses == 0):
2038 # Exit assembly block
2039 inner_block.inline_asm = _END_ASM
2040
2041 # Consume namespace declaration at the beginning of the line. Do
2042 # this in a loop so that we catch same line declarations like this:
2043 # namespace proto2 { namespace bridge { class MessageSet; } }
2044 while True:
2045 # Match start of namespace. The "\b\s*" below catches namespace
2046 # declarations even if it weren't followed by a whitespace, this
2047 # is so that we don't confuse our namespace checker. The
2048 # missing spaces will be flagged by CheckSpacing.
2049 namespace_decl_match = Match(r'^\s*namespace\b\s*([:\w]+)?(.*)$', line)
2050 if not namespace_decl_match:
2051 break
2052
2053 new_namespace = _NamespaceInfo(namespace_decl_match.group(1), linenum)
2054 self.stack.append(new_namespace)
2055
2056 line = namespace_decl_match.group(2)
2057 if line.find('{') != -1:
2058 new_namespace.seen_open_brace = True
2059 line = line[line.find('{') + 1:]
2060
2061 # Look for a class declaration in whatever is left of the line

Callers 1

ProcessLineFunction · 0.45

Calls 11

UpdatePreprocessorMethod · 0.95
SeenOpenBraceMethod · 0.95
MatchFunction · 0.85
_NamespaceInfoClass · 0.85
_ClassInfoClass · 0.85
errorFunction · 0.85
_BlockInfoClass · 0.85
countMethod · 0.80
popMethod · 0.80
CheckBeginMethod · 0.45
CheckEndMethod · 0.45

Tested by

no test coverage detected