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)
| 5510 | |
| 5511 | |
| 5512 | def IsInitializerList(clean_lines, linenum): |
| 5513 | """Check if current line is inside constructor initializer list. |
| 5514 | |
| 5515 | Args: |
| 5516 | clean_lines: A CleansedLines instance containing the file. |
| 5517 | linenum: The number of the line to check. |
| 5518 | Returns: |
| 5519 | True if current line appears to be inside constructor initializer |
| 5520 | list, False otherwise. |
| 5521 | """ |
| 5522 | for i in xrange(linenum, 1, -1): |
| 5523 | line = clean_lines.elided[i] |
| 5524 | if i == linenum: |
| 5525 | remove_function_body = Match(r'^(.*)\{\s*$', line) |
| 5526 | if remove_function_body: |
| 5527 | line = remove_function_body.group(1) |
| 5528 | |
| 5529 | if Search(r'\s:\s*\w+[({]', line): |
| 5530 | # A lone colon tend to indicate the start of a constructor |
| 5531 | # initializer list. It could also be a ternary operator, which |
| 5532 | # also tend to appear in constructor initializer lists as |
| 5533 | # opposed to parameter lists. |
| 5534 | return True |
| 5535 | if Search(r'\}\s*,\s*$', line): |
| 5536 | # A closing brace followed by a comma is probably the end of a |
| 5537 | # brace-initialized member in constructor initializer list. |
| 5538 | return True |
| 5539 | if Search(r'[{};]\s*$', line): |
| 5540 | # Found one of the following: |
| 5541 | # - A closing brace or semicolon, probably the end of the previous |
| 5542 | # function. |
| 5543 | # - An opening brace, probably the start of current class or namespace. |
| 5544 | # |
| 5545 | # Current line is probably not inside an initializer list since |
| 5546 | # we saw one of those things without seeing the starting colon. |
| 5547 | return False |
| 5548 | |
| 5549 | # Got to the beginning of the file without seeing the start of |
| 5550 | # constructor initializer list. |
| 5551 | return False |
| 5552 | |
| 5553 | |
| 5554 | def CheckForNonConstReference(filename, clean_lines, linenum, |
no test coverage detected