@@ 3629-3689 (lines=61) @@ | ||
3626 | 'Missing space after ;') |
|
3627 | ||
3628 | ||
3629 | def _IsType(clean_lines, nesting_state, expr): |
|
3630 | """Check if expression looks like a type name, returns true if so. |
|
3631 | ||
3632 | Args: |
|
3633 | clean_lines: A CleansedLines instance containing the file. |
|
3634 | nesting_state: A NestingState instance which maintains information about |
|
3635 | the current stack of nested blocks being parsed. |
|
3636 | expr: The expression to check. |
|
3637 | Returns: |
|
3638 | True, if token looks like a type. |
|
3639 | """ |
|
3640 | # Keep only the last token in the expression |
|
3641 | last_word = Match(r'^.*(\b\S+)$', expr) |
|
3642 | if last_word: |
|
3643 | token = last_word.group(1) |
|
3644 | else: |
|
3645 | token = expr |
|
3646 | ||
3647 | # Match native types and stdint types |
|
3648 | if _TYPES.match(token): |
|
3649 | return True |
|
3650 | ||
3651 | # Try a bit harder to match templated types. Walk up the nesting |
|
3652 | # stack until we find something that resembles a typename |
|
3653 | # declaration for what we are looking for. |
|
3654 | typename_pattern = (r'\b(?:typename|class|struct)\s+' + re.escape(token) + |
|
3655 | r'\b') |
|
3656 | block_index = len(nesting_state.stack) - 1 |
|
3657 | while block_index >= 0: |
|
3658 | if isinstance(nesting_state.stack[block_index], _NamespaceInfo): |
|
3659 | return False |
|
3660 | ||
3661 | # Found where the opening brace is. We want to scan from this |
|
3662 | # line up to the beginning of the function, minus a few lines. |
|
3663 | # template <typename Type1, // stop scanning here |
|
3664 | # ...> |
|
3665 | # class C |
|
3666 | # : public ... { // start scanning here |
|
3667 | last_line = nesting_state.stack[block_index].starting_linenum |
|
3668 | ||
3669 | next_block_start = 0 |
|
3670 | if block_index > 0: |
|
3671 | next_block_start = nesting_state.stack[block_index - 1].starting_linenum |
|
3672 | first_line = last_line |
|
3673 | while first_line >= next_block_start: |
|
3674 | if clean_lines.elided[first_line].find('template') >= 0: |
|
3675 | break |
|
3676 | first_line -= 1 |
|
3677 | if first_line < next_block_start: |
|
3678 | # Didn't find any "template" keyword before reaching the next block, |
|
3679 | # there are probably no template things to check for this block |
|
3680 | block_index -= 1 |
|
3681 | continue |
|
3682 | ||
3683 | # Look for typename in the specified range |
|
3684 | for i in xrange(first_line, last_line + 1, 1): |
|
3685 | if Search(typename_pattern, clean_lines.elided[i]): |
|
3686 | return True |
|
3687 | block_index -= 1 |
|
3688 | ||
3689 | return False |
|
3690 | ||
3691 | ||
3692 | def CheckBracesSpacing(filename, clean_lines, linenum, nesting_state, error): |
@@ 3629-3689 (lines=61) @@ | ||
3626 | 'Missing space after ;') |
|
3627 | ||
3628 | ||
3629 | def _IsType(clean_lines, nesting_state, expr): |
|
3630 | """Check if expression looks like a type name, returns true if so. |
|
3631 | ||
3632 | Args: |
|
3633 | clean_lines: A CleansedLines instance containing the file. |
|
3634 | nesting_state: A NestingState instance which maintains information about |
|
3635 | the current stack of nested blocks being parsed. |
|
3636 | expr: The expression to check. |
|
3637 | Returns: |
|
3638 | True, if token looks like a type. |
|
3639 | """ |
|
3640 | # Keep only the last token in the expression |
|
3641 | last_word = Match(r'^.*(\b\S+)$', expr) |
|
3642 | if last_word: |
|
3643 | token = last_word.group(1) |
|
3644 | else: |
|
3645 | token = expr |
|
3646 | ||
3647 | # Match native types and stdint types |
|
3648 | if _TYPES.match(token): |
|
3649 | return True |
|
3650 | ||
3651 | # Try a bit harder to match templated types. Walk up the nesting |
|
3652 | # stack until we find something that resembles a typename |
|
3653 | # declaration for what we are looking for. |
|
3654 | typename_pattern = (r'\b(?:typename|class|struct)\s+' + re.escape(token) + |
|
3655 | r'\b') |
|
3656 | block_index = len(nesting_state.stack) - 1 |
|
3657 | while block_index >= 0: |
|
3658 | if isinstance(nesting_state.stack[block_index], _NamespaceInfo): |
|
3659 | return False |
|
3660 | ||
3661 | # Found where the opening brace is. We want to scan from this |
|
3662 | # line up to the beginning of the function, minus a few lines. |
|
3663 | # template <typename Type1, // stop scanning here |
|
3664 | # ...> |
|
3665 | # class C |
|
3666 | # : public ... { // start scanning here |
|
3667 | last_line = nesting_state.stack[block_index].starting_linenum |
|
3668 | ||
3669 | next_block_start = 0 |
|
3670 | if block_index > 0: |
|
3671 | next_block_start = nesting_state.stack[block_index - 1].starting_linenum |
|
3672 | first_line = last_line |
|
3673 | while first_line >= next_block_start: |
|
3674 | if clean_lines.elided[first_line].find('template') >= 0: |
|
3675 | break |
|
3676 | first_line -= 1 |
|
3677 | if first_line < next_block_start: |
|
3678 | # Didn't find any "template" keyword before reaching the next block, |
|
3679 | # there are probably no template things to check for this block |
|
3680 | block_index -= 1 |
|
3681 | continue |
|
3682 | ||
3683 | # Look for typename in the specified range |
|
3684 | for i in xrange(first_line, last_line + 1, 1): |
|
3685 | if Search(typename_pattern, clean_lines.elided[i]): |
|
3686 | return True |
|
3687 | block_index -= 1 |
|
3688 | ||
3689 | return False |
|
3690 | ||
3691 | ||
3692 | def CheckBracesSpacing(filename, clean_lines, linenum, nesting_state, error): |