third_party/blink/tools/blinkpy/style/checkers/cpp.py
def detect_functions(clean_lines, line_number, function_state, error):
    """Finds where functions start and end.

    Uses a simplistic algorithm assuming other style guidelines
    (especially spacing) are followed.
    Trivial bodies are unchecked, so constructors with huge initializer lists
    may be missed.

    Args:
      clean_lines: A CleansedLines instance containing the file.
      line_number: The number of the line to check.
      function_state: Current function name and lines in body so far.
      error: The function to call with any errors found.
    """
    # Are we now past the end of a function?
    if function_state.end_position.row + 1 == line_number:
        function_state.end()

    # If we're in a function, don't try to detect a new one.
    if function_state.in_a_function:
        return

    lines = clean_lines.lines
    line = lines[line_number]
    raw = clean_lines.raw_lines
    raw_line = raw[line_number]

    # Lines ending with a \ indicate a macro. Don't try to check them.
    if raw_line.endswith('\\'):
        return

    regexp = r'\s*(\w(\w|::|\*|\&|\s|<|>|,|~|(operator\s*(/|-|=|!|\+)+))*)\('  # decls * & space::name( ...
    match_result = match(regexp, line)
    if not match_result:
        return

    # If the name is all caps and underscores, figure it's a macro and
    # ignore it, unless it's TEST or TEST_F.
    function_name = match_result.group(1).split()[-1]
    if (function_name != 'TEST' and function_name != 'TEST_F'
            and match(r'[A-Z_]+$', function_name)):
        return

    joined_line = ''
    for start_line_number in xrange(line_number, clean_lines.num_lines()):
        start_line = clean_lines.elided[start_line_number]
        joined_line += ' ' + start_line.lstrip()
        body_match = search(r'{|;', start_line)
        if body_match:
            body_start_position = Position(start_line_number,
                                           body_match.start(0))

            # Replace template constructs with _ so that no spaces remain in the function name,
            # while keeping the column numbers of other characters the same as "line".
            line_with_no_templates = iteratively_replace_matches_with_char(
                r'<[^<>]*>', '_', line)
            match_function = search(
                r'((\w|:|<|>|,|~|(operator\s*(/|-|=|!|\+)+))*)\(',
                line_with_no_templates)
            if not match_function:
                return  # The '(' must have been inside of a template.

            # Use the column numbers from the modified line to find the
            # function name in the original line.
            function = line[match_function.start(1):match_function.end(1)]
            function_name_start_position = Position(line_number,
                                                    match_function.start(1))

            if match(r'TEST', function):  # Handle TEST... macros
                parameter_regexp = search(r'(\(.*\))', joined_line)
                if parameter_regexp:  # Ignore bad syntax
                    function += parameter_regexp.group(1)
            else:
                function += '()'

            parameter_start_position = Position(line_number,
                                                match_function.end(1))
            parameter_end_position = close_expression(
                clean_lines.elided, parameter_start_position)
            if parameter_end_position.row == len(clean_lines.elided):
                # No end was found.
                return

            if start_line[body_start_position.column] == ';':
                end_position = Position(body_start_position.row,
                                        body_start_position.column + 1)
            else:
                end_position = close_expression(clean_lines.elided,
                                                body_start_position)

            # Check for nonsensical positions. (This happens in test cases which check code snippets.)
            if parameter_end_position > body_start_position:
                return

            function_state.begin(function, function_name_start_position,
                                 body_start_position, end_position,
                                 parameter_start_position,
                                 parameter_end_position, clean_lines)
            return

    # No body for the function (or evidence of a non-function) was found.
    error(line_number, 'readability/fn_size', 5,
          'Lint failed to find start of function body.')
Finds where functions start and end.

    Uses a simplistic algorithm assuming other style guidelines
    (especially spacing) are followed.
    Trivial bodies are unchecked, so constructors with huge initializer lists
    may be missed.

    Args:
      clean_lines: A CleansedLines instance containing the file.
      line_number: The number of the line to check.
      function_state: Current function name and lines in body so far.
      error: The function to call with any errors found.
    
Finds where functions start and end.
Uses a simplistic algorithm assuming other style guidelines
(especially spacing) are followed.
Trivial bodies are unchecked, so constructors with huge initializer lists
may be missed.
Finds where functions start and end . Uses a simplistic algorithm assuming other style guidelines ( especially spacing ) are followed . Trivial bodies are unchecked so constructors with huge initializer lists may be missed .
def detect_functions(clean_lines, line_number, function_state, error):
    if function_state.end_position.row + 1 == line_number:
        function_state.end()
    if function_state.in_a_function:
        return
    lines = clean_lines.lines
    line = lines[line_number]
    raw = clean_lines.raw_lines
    raw_line = raw[line_number]
    if raw_line.endswith('\\'):
        return
    regexp = r'\s*(\w(\w|::|\*|\&|\s|<|>|,|~|(operator\s*(/|-|=|!|\+)+))*)\('  
    match_result = match(regexp, line)
    if not match_result:
        return
    function_name = match_result.group(1).split()[-1]
    if (function_name != 'TEST' and function_name != 'TEST_F'
            and match(r'[A-Z_]+$', function_name)):
        return
    joined_line = ''
    for start_line_number in xrange(line_number, clean_lines.num_lines()):
        start_line = clean_lines.elided[start_line_number]
        joined_line += ' ' + start_line.lstrip()
        body_match = search(r'{|;', start_line)
        if body_match:
            body_start_position = Position(start_line_number,
                                           body_match.start(0))
            line_with_no_templates = iteratively_replace_matches_with_char(
                r'<[^<>]*>', '_', line)
            match_function = search(
                r'((\w|:|<|>|,|~|(operator\s*(/|-|=|!|\+)+))*)\(',
                line_with_no_templates)
            if not match_function:
                return  
            function = line[match_function.start(1):match_function.end(1)]
            function_name_start_position = Position(line_number,
                                                    match_function.start(1))
            if match(r'TEST', function):  
                parameter_regexp = search(r'(\(.*\))', joined_line)
                if parameter_regexp:  
                    function += parameter_regexp.group(1)
            else:
                function += '()'
            parameter_start_position = Position(line_number,
                                                match_function.end(1))
            parameter_end_position = close_expression(
                clean_lines.elided, parameter_start_position)
            if parameter_end_position.row == len(clean_lines.elided):
                return
            if start_line[body_start_position.column] == ';':
                end_position = Position(body_start_position.row,
                                        body_start_position.column + 1)
            else:
                end_position = close_expression(clean_lines.elided,
                                                body_start_position)
            if parameter_end_position > body_start_position:
                return
            function_state.begin(function, function_name_start_position,
                                 body_start_position, end_position,
                                 parameter_start_position,
                                 parameter_end_position, clean_lines)
            return
    error(line_number, 'readability/fn_size', 5,
          'Lint failed to find start of function body.')
def detect_functions ( clean_lines , line_number , function_state , error ) : if function_state . end_position . row + 1 == line_number : function_state . end ( ) if function_state . in_a_function : return lines = clean_lines . lines line = lines [ line_number ] raw = clean_lines . raw_lines raw_line = raw [ line_number ] if raw_line . endswith ( '\\' ) : return regexp = r'\s*(\w(\w|::|\*|\&|\s|<|>|,|~|(operator\s*(/|-|=|!|\+)+))*)\(' match_result = match ( regexp , line ) if not match_result : return function_name = match_result . group ( 1 ) . split ( ) [ - 1 ] if ( function_name != 'TEST' and function_name != 'TEST_F' and match ( r'[A-Z_]+$' , function_name ) ) : return joined_line = '' for start_line_number in xrange ( line_number , clean_lines . num_lines ( ) ) : start_line = clean_lines . elided [ start_line_number ] joined_line += ' ' + start_line . lstrip ( ) body_match = search ( r'{|;' , start_line ) if body_match : body_start_position = Position ( start_line_number , body_match . start ( 0 ) ) line_with_no_templates = iteratively_replace_matches_with_char ( r'<[^<>]*>' , '_' , line ) match_function = search ( r'((\w|:|<|>|,|~|(operator\s*(/|-|=|!|\+)+))*)\(' , line_with_no_templates ) if not match_function : return function = line [ match_function . start ( 1 ) : match_function . end ( 1 ) ] function_name_start_position = Position ( line_number , match_function . start ( 1 ) ) if match ( r'TEST' , function ) : parameter_regexp = search ( r'(\(.*\))' , joined_line ) if parameter_regexp : function += parameter_regexp . group ( 1 ) else : function += '()' parameter_start_position = Position ( line_number , match_function . end ( 1 ) ) parameter_end_position = close_expression ( clean_lines . elided , parameter_start_position ) if parameter_end_position . row == len ( clean_lines . elided ) : return if start_line [ body_start_position . column ] == ';' : end_position = Position ( body_start_position . row , body_start_position . column + 1 ) else : end_position = close_expression ( clean_lines . elided , body_start_position ) if parameter_end_position > body_start_position : return function_state . begin ( function , function_name_start_position , body_start_position , end_position , parameter_start_position , parameter_end_position , clean_lines ) return error ( line_number , 'readability/fn_size' , 5 , 'Lint failed to find start of function body.' )
Finds where functions start and end.
Finds where functions start and end .
"""Finds where functions start and end.

    Uses a simplistic algorithm assuming other style guidelines
    (especially spacing) are followed.
    Trivial bodies are unchecked, so constructors with huge initializer lists
    may be missed.

    Args:
      clean_lines: A CleansedLines instance containing the file.
      line_number: The number of the line to check.
      function_state: Current function name and lines in body so far.
      error: The function to call with any errors found.
    """ # Are we now past the end of a function? # If we're in a function, don't try to detect a new one. # Lines ending with a \ indicate a macro. Don't try to check them. # decls * & space::name( ... # If the name is all caps and underscores, figure it's a macro and # ignore it, unless it's TEST or TEST_F. # Replace template constructs with _ so that no spaces remain in the function name, # while keeping the column numbers of other characters the same as "line". # The '(' must have been inside of a template. # Use the column numbers from the modified line to find the # function name in the original line. # Handle TEST... macros # Ignore bad syntax # No end was found. # Check for nonsensical positions. (This happens in test cases which check code snippets.) # No body for the function (or evidence of a non-function) was found.
clean_lines
A CleansedLines instance containing the file.
A CleansedLines instance containing the file .
line_number
The number of the line to check.
The number of the line to check .
function_state
Current function name and lines in body so far.
Current function name and lines in body so far .
error
The function to call with any errors found.
The function to call with any errors found .