MCPcopy Create free account
hub / github.com/dmtcp/dmtcp / _ClassInfo

Class _ClassInfo

util/cpplint.py:2167–2233  ·  view source on GitHub ↗

Stores information about a class.

Source from the content-addressed store, hash-verified

2165
2166
2167class _ClassInfo(_BlockInfo):
2168 """Stores information about a class."""
2169
2170 def __init__(self, name, class_or_struct, clean_lines, linenum):
2171 _BlockInfo.__init__(self, linenum, False)
2172 self.name = name
2173 self.is_derived = False
2174 self.check_namespace_indentation = True
2175 if class_or_struct == 'struct':
2176 self.access = 'public'
2177 self.is_struct = True
2178 else:
2179 self.access = 'private'
2180 self.is_struct = False
2181
2182 # Remember initial indentation level for this class. Using raw_lines here
2183 # instead of elided to account for leading comments.
2184 self.class_indent = GetIndentLevel(clean_lines.raw_lines[linenum])
2185
2186 # Try to find the end of the class. This will be confused by things like:
2187 # class A {
2188 # } *x = { ...
2189 #
2190 # But it's still good enough for CheckSectionSpacing.
2191 self.last_line = 0
2192 depth = 0
2193 for i in range(linenum, clean_lines.NumLines()):
2194 line = clean_lines.elided[i]
2195 depth += line.count('{') - line.count('}')
2196 if not depth:
2197 self.last_line = i
2198 break
2199
2200 def CheckBegin(self, filename, clean_lines, linenum, error):
2201 # Look for a bare ':'
2202 if Search('(^|[^:]):($|[^:])', clean_lines.elided[linenum]):
2203 self.is_derived = True
2204
2205 def CheckEnd(self, filename, clean_lines, linenum, error):
2206 # If there is a DISALLOW macro, it should appear near the end of
2207 # the class.
2208 seen_last_thing_in_class = False
2209 for i in range(linenum - 1, self.starting_linenum, -1):
2210 match = Search(
2211 r'\b(DISALLOW_COPY_AND_ASSIGN|DISALLOW_IMPLICIT_CONSTRUCTORS)\(' +
2212 self.name + r'\)',
2213 clean_lines.elided[i])
2214 if match:
2215 if seen_last_thing_in_class:
2216 error(filename, i, 'readability/constructors', 3,
2217 match.group(1) + ' should be the last thing in the class')
2218 break
2219
2220 if not Match(r'^\s*$', clean_lines.elided[i]):
2221 seen_last_thing_in_class = True
2222
2223 # Check that closing brace is aligned with beginning of the class.
2224 # 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