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