MCPcopy Create free account
hub / github.com/4paradigm/OpenMLDB / _ClassInfo

Class _ClassInfo

steps/cpplint.py:2767–2833  ·  view source on GitHub ↗

Stores information about a class.

Source from the content-addressed store, hash-verified

2765
2766
2767class _ClassInfo(_BlockInfo):
2768 """Stores information about a class."""
2769
2770 def __init__(self, name, class_or_struct, clean_lines, linenum):
2771 _BlockInfo.__init__(self, linenum, False)
2772 self.name = name
2773 self.is_derived = False
2774 self.check_namespace_indentation = True
2775 if class_or_struct == 'struct':
2776 self.access = 'public'
2777 self.is_struct = True
2778 else:
2779 self.access = 'private'
2780 self.is_struct = False
2781
2782 # Remember initial indentation level for this class. Using raw_lines here
2783 # instead of elided to account for leading comments.
2784 self.class_indent = GetIndentLevel(clean_lines.raw_lines[linenum])
2785
2786 # Try to find the end of the class. This will be confused by things like:
2787 # class A {
2788 # } *x = { ...
2789 #
2790 # But it's still good enough for CheckSectionSpacing.
2791 self.last_line = 0
2792 depth = 0
2793 for i in range(linenum, clean_lines.NumLines()):
2794 line = clean_lines.elided[i]
2795 depth += line.count('{') - line.count('}')
2796 if not depth:
2797 self.last_line = i
2798 break
2799
2800 def CheckBegin(self, filename, clean_lines, linenum, error):
2801 # Look for a bare ':'
2802 if Search('(^|[^:]):($|[^:])', clean_lines.elided[linenum]):
2803 self.is_derived = True
2804
2805 def CheckEnd(self, filename, clean_lines, linenum, error):
2806 # If there is a DISALLOW macro, it should appear near the end of
2807 # the class.
2808 seen_last_thing_in_class = False
2809 for i in xrange(linenum - 1, self.starting_linenum, -1):
2810 match = Search(
2811 r'\b(DISALLOW_COPY_AND_ASSIGN|DISALLOW_IMPLICIT_CONSTRUCTORS)\(' +
2812 self.name + r'\)',
2813 clean_lines.elided[i])
2814 if match:
2815 if seen_last_thing_in_class:
2816 error(filename, i, 'readability/constructors', 3,
2817 match.group(1) + ' should be the last thing in the class')
2818 break
2819
2820 if not Match(r'^\s*$', clean_lines.elided[i]):
2821 seen_last_thing_in_class = True
2822
2823 # Check that closing brace is aligned with beginning of the class.
2824 # Only do this if the closing brace is indented by only whitespaces.

Callers 1

UpdateMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected