MCPcopy Create free account
hub / github.com/BVLC/caffe / Update

Method Update

scripts/cpp_lint.py:2008–2162  ·  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

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

Callers 1

ProcessLineFunction · 0.45

Calls 10

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

Tested by

no test coverage detected