MCPcopy Create free account
hub / github.com/alibaba/GraphScope / _ClassInfo

Class _ClassInfo

analytical_engine/misc/cpplint.py:2756–2822  ·  view source on GitHub ↗

Stores information about a class.

Source from the content-addressed store, hash-verified

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