MCPcopy Index your code
hub / github.com/cpplint/cpplint / IsInitializerList

Function IsInitializerList

cpplint.py:6270–6309  ·  view source on GitHub ↗

Check if current line is inside constructor initializer list. Args: clean_lines: A CleansedLines instance containing the file. linenum: The number of the line to check. Returns: True if current line appears to be inside constructor initializer list, False otherwise.

(clean_lines, linenum)

Source from the content-addressed store, hash-verified

6268
6269
6270def IsInitializerList(clean_lines, linenum):
6271 """Check if current line is inside constructor initializer list.
6272
6273 Args:
6274 clean_lines: A CleansedLines instance containing the file.
6275 linenum: The number of the line to check.
6276 Returns:
6277 True if current line appears to be inside constructor initializer
6278 list, False otherwise.
6279 """
6280 for i in range(linenum, 1, -1):
6281 line = clean_lines.elided[i]
6282 if i == linenum:
6283 remove_function_body = re.match(r"^(.*)\{\s*$", line)
6284 if remove_function_body:
6285 line = remove_function_body.group(1)
6286
6287 if re.search(r"\s:\s*\w+[({]", line):
6288 # A lone colon tend to indicate the start of a constructor
6289 # initializer list. It could also be a ternary operator, which
6290 # also tend to appear in constructor initializer lists as
6291 # opposed to parameter lists.
6292 return True
6293 if re.search(r"\}\s*,\s*$", line):
6294 # A closing brace followed by a comma is probably the end of a
6295 # brace-initialized member in constructor initializer list.
6296 return True
6297 if re.search(r"[{};]\s*$", line):
6298 # Found one of the following:
6299 # - A closing brace or semicolon, probably the end of the previous
6300 # function.
6301 # - An opening brace, probably the start of current class or namespace.
6302 #
6303 # Current line is probably not inside an initializer list since
6304 # we saw one of those things without seeing the starting colon.
6305 return False
6306
6307 # Got to the beginning of the file without seeing the start of
6308 # constructor initializer list.
6309 return False
6310
6311
6312def CheckForNonConstReference(filename, clean_lines, linenum, nesting_state, error):

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected