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

Class _ClassInfo

rtpose_wrapper/scripts/cpp_lint.py:1792–1845  ·  view source on GitHub ↗

Stores information about a class.

Source from the content-addressed store, hash-verified

1790
1791
1792class _ClassInfo(_BlockInfo):
1793 """Stores information about a class."""
1794
1795 def __init__(self, name, class_or_struct, clean_lines, linenum):
1796 _BlockInfo.__init__(self, False)
1797 self.name = name
1798 self.starting_linenum = linenum
1799 self.is_derived = False
1800 if class_or_struct == 'struct':
1801 self.access = 'public'
1802 self.is_struct = True
1803 else:
1804 self.access = 'private'
1805 self.is_struct = False
1806
1807 # Remember initial indentation level for this class. Using raw_lines here
1808 # instead of elided to account for leading comments.
1809 initial_indent = Match(r'^( *)\S', clean_lines.raw_lines[linenum])
1810 if initial_indent:
1811 self.class_indent = len(initial_indent.group(1))
1812 else:
1813 self.class_indent = 0
1814
1815 # Try to find the end of the class. This will be confused by things like:
1816 # class A {
1817 # } *x = { ...
1818 #
1819 # But it's still good enough for CheckSectionSpacing.
1820 self.last_line = 0
1821 depth = 0
1822 for i in range(linenum, clean_lines.NumLines()):
1823 line = clean_lines.elided[i]
1824 depth += line.count('{') - line.count('}')
1825 if not depth:
1826 self.last_line = i
1827 break
1828
1829 def CheckBegin(self, filename, clean_lines, linenum, error):
1830 # Look for a bare ':'
1831 if Search('(^|[^:]):($|[^:])', clean_lines.elided[linenum]):
1832 self.is_derived = True
1833
1834 def CheckEnd(self, filename, clean_lines, linenum, error):
1835 # Check that closing brace is aligned with beginning of the class.
1836 # Only do this if the closing brace is indented by only whitespaces.
1837 # This means we will not check single-line class definitions.
1838 indent = Match(r'^( *)\}', clean_lines.elided[linenum])
1839 if indent and len(indent.group(1)) != self.class_indent:
1840 if self.is_struct:
1841 parent = 'struct ' + self.name
1842 else:
1843 parent = 'class ' + self.name
1844 error(filename, linenum, 'whitespace/indent', 3,
1845 'Closing brace should be aligned with beginning of %s' % parent)
1846
1847
1848class _NamespaceInfo(_BlockInfo):

Callers 1

UpdateMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected