Stores information about a class.
| 3077 | |
| 3078 | |
| 3079 | class _ClassInfo(_BlockInfo): |
| 3080 | """Stores information about a class.""" |
| 3081 | |
| 3082 | def __init__(self, name, class_or_struct, clean_lines, linenum): |
| 3083 | _BlockInfo.__init__(self, linenum, False) |
| 3084 | self.name = name |
| 3085 | self.is_derived = False |
| 3086 | self.check_namespace_indentation = True |
| 3087 | if class_or_struct == "struct": |
| 3088 | self.access = "public" |
| 3089 | self.is_struct = True |
| 3090 | else: |
| 3091 | self.access = "private" |
| 3092 | self.is_struct = False |
| 3093 | |
| 3094 | # Remember initial indentation level for this class. Using raw_lines here |
| 3095 | # instead of elided to account for leading comments. |
| 3096 | self.class_indent = GetIndentLevel(clean_lines.raw_lines[linenum]) |
| 3097 | |
| 3098 | # Try to find the end of the class. This will be confused by things like: |
| 3099 | # class A { |
| 3100 | # } *x = { ... |
| 3101 | # |
| 3102 | # But it's still good enough for CheckSectionSpacing. |
| 3103 | self.last_line = 0 |
| 3104 | depth = 0 |
| 3105 | for i in range(linenum, clean_lines.NumLines()): |
| 3106 | line = clean_lines.elided[i] |
| 3107 | depth += line.count("{") - line.count("}") |
| 3108 | if not depth: |
| 3109 | self.last_line = i |
| 3110 | break |
| 3111 | |
| 3112 | def CheckBegin(self, filename, clean_lines, linenum, error): |
| 3113 | # Look for a bare ':' |
| 3114 | if re.search("(^|[^:]):($|[^:])", clean_lines.elided[linenum]): |
| 3115 | self.is_derived = True |
| 3116 | |
| 3117 | def CheckEnd(self, filename, clean_lines, linenum, error): |
| 3118 | # If there is a DISALLOW macro, it should appear near the end of |
| 3119 | # the class. |
| 3120 | seen_last_thing_in_class = False |
| 3121 | for i in range(linenum - 1, self.starting_linenum, -1): |
| 3122 | match = re.search( |
| 3123 | r"\b(DISALLOW_COPY_AND_ASSIGN|DISALLOW_IMPLICIT_CONSTRUCTORS)\(" |
| 3124 | + self.name |
| 3125 | + r"\)", |
| 3126 | clean_lines.elided[i], |
| 3127 | ) |
| 3128 | if match: |
| 3129 | if seen_last_thing_in_class: |
| 3130 | error( |
| 3131 | filename, |
| 3132 | i, |
| 3133 | "readability/constructors", |
| 3134 | 3, |
| 3135 | match.group(1) + " should be the last thing in the class", |
| 3136 | ) |
no outgoing calls
no test coverage detected
searching dependent graphs…