third_party/blink/tools/blinkpy/style/checkers/cpp.py
def check_identifier_name_in_declaration(filename, line_number, line,
                                         file_state, error):
    """Checks if identifier names contain any underscores.

    As identifiers in libraries we are using have a bunch of
    underscores, we only warn about the declarations of identifiers
    and don't check use of identifiers.

    Args:
      filename: The name of the current file.
      line_number: The number of the line to check.
      line: The line of code to check.
      file_state: A _FileState instance which maintains information about
                  the state of things in the file.
      error: The function to call with any errors found.
    """
    # We don't check return and delete statements and conversion operator declarations.
    if match(r'\s*(return|delete|operator)\b', line):
        return

    # Basically, a declaration is a type name followed by whitespaces
    # followed by an identifier. The type name can be complicated
    # due to type adjectives and templates. We remove them first to
    # simplify the process to find declarations of identifiers.

    # Convert "long long", "long double", and "long long int" to
    # simple types, but don't remove simple "long".
    line = sub(r'long (long )?(?=long|double|int)', '', line)
    # Convert unsigned/signed types to simple types, too.
    line = sub(r'(unsigned|signed) (?=char|short|int|long)', '', line)
    line = sub(
        r'\b(inline|using|static|const|volatile|auto|register|extern|typedef|restrict|struct|class|virtual)(?=\W)',
        '', line)

    # Remove "new" and "new (expr)" to simplify, too.
    line = sub(r'new\s*(\([^)]*\))?', '', line)

    # Remove all template parameters by removing matching < and >.
    # Loop until no templates are removed to remove nested templates.
    while True:
        line, number_of_replacements = subn(r'<([\w\s:]|::)+\s*[*&]*\s*>', '',
                                            line)
        if not number_of_replacements:
            break

    # Declarations of local variables can be in condition expressions
    # of control flow statements (e.g., "if (LayoutObject* p = o->parent())").
    # We remove the keywords and the first parenthesis.
    #
    # Declarations in "while", "if", and "switch" are different from
    # other declarations in two aspects:
    #
    # - There can be only one declaration between the parentheses.
    #   (i.e., you cannot write "if (int i = 0, j = 1) {}")
    # - The variable must be initialized.
    #   (i.e., you cannot write "if (int i) {}")
    #
    # and we will need different treatments for them.
    line = sub(r'^\s*for\s*\(', '', line)
    line, control_statement = subn(r'^\s*(while|else if|if|switch)\s*\(', '',
                                   line)

    # Detect variable and functions.
    type_regexp = r'\w([\w]|\s*[*&]\s*|::)+'
    identifier_regexp = r'(?P<identifier>[\w:]+)'
    maybe_bitfield_regexp = r'(:\s*\d+\s*)?'
    character_after_identifier_regexp = r'(?P<character_after_identifier>[[;()=,])(?!=)'
    declaration_without_type_regexp = r'\s*' + identifier_regexp + \
        r'\s*' + maybe_bitfield_regexp + character_after_identifier_regexp
    declaration_with_type_regexp = r'\s*' + type_regexp + r'\s' + declaration_without_type_regexp
    is_function_arguments = False
    number_of_identifiers = 0
    while True:
        # If we are seeing the first identifier or arguments of a
        # function, there should be a type name before an identifier.
        if not number_of_identifiers or is_function_arguments:
            declaration_regexp = declaration_with_type_regexp
        else:
            declaration_regexp = declaration_without_type_regexp

        matched = match(declaration_regexp, line)
        if not matched:
            return
        identifier = matched.group('identifier')
        character_after_identifier = matched.group(
            'character_after_identifier')

        # If we removed a non-for-control statement, the character after
        # the identifier should be '='. With this rule, we can avoid
        # warning for cases like "if (val & INT_MAX) {".
        if control_statement and character_after_identifier != '=':
            return

        is_function_arguments = is_function_arguments or character_after_identifier == '('

        # There can be only one declaration in non-for-control statements.
        if control_statement:
            return
        # We should continue checking if this is a function
        # declaration because we need to check its arguments.
        # Also, we need to check multiple declarations.
        if character_after_identifier != '(' and character_after_identifier != ',':
            return

        number_of_identifiers += 1
        line = line[matched.end():]
Checks if identifier names contain any underscores.

    As identifiers in libraries we are using have a bunch of
    underscores, we only warn about the declarations of identifiers
    and don't check use of identifiers.

    Args:
      filename: The name of the current file.
      line_number: The number of the line to check.
      line: The line of code to check.
      file_state: A _FileState instance which maintains information about
                  the state of things in the file.
      error: The function to call with any errors found.
    
Checks if identifier names contain any underscores.
As identifiers in libraries we are using have a bunch of
underscores, we only warn about the declarations of identifiers
and don't check use of identifiers.
Checks if identifier names contain any underscores . As identifiers in libraries we are using have a bunch of underscores we only warn about the declarations of identifiers and don ' t check use of identifiers .
def check_identifier_name_in_declaration(filename, line_number, line,
                                         file_state, error):
    if match(r'\s*(return|delete|operator)\b', line):
        return
    line = sub(r'long (long )?(?=long|double|int)', '', line)
    line = sub(r'(unsigned|signed) (?=char|short|int|long)', '', line)
    line = sub(
        r'\b(inline|using|static|const|volatile|auto|register|extern|typedef|restrict|struct|class|virtual)(?=\W)',
        '', line)
    line = sub(r'new\s*(\([^)]*\))?', '', line)
    while True:
        line, number_of_replacements = subn(r'<([\w\s:]|::)+\s*[*&]*\s*>', '',
                                            line)
        if not number_of_replacements:
            break
     Declarations in "while", "if", and "switch" are different from
     other declarations in two aspects:
     - There can be only one declaration between the parentheses.
       (i.e., you cannot write "if (int i = 0, j = 1) {}")
     - The variable must be initialized.
       (i.e., you cannot write "if (int i) {}")
     and we will need different treatments for them.
    line = sub(r'^\s*for\s*\(', '', line)
    line, control_statement = subn(r'^\s*(while|else if|if|switch)\s*\(', '',
                                   line)
     Detect variable and functions.
    type_regexp = r'\w([\w]|\s*[*&]\s*|::)+'
    identifier_regexp = r'(?P<identifier>[\w:]+)'
    maybe_bitfield_regexp = r'(:\s*\d+\s*)?'
    character_after_identifier_regexp = r'(?P<character_after_identifier>[[;()=,])(?!=)'
    declaration_without_type_regexp = r'\s*' + identifier_regexp + \
        r'\s*' + maybe_bitfield_regexp + character_after_identifier_regexp
    declaration_with_type_regexp = r'\s*' + type_regexp + r'\s' + declaration_without_type_regexp
    is_function_arguments = False
    number_of_identifiers = 0
    while True:
         If we are seeing the first identifier or arguments of a
         function, there should be a type name before an identifier.
        if not number_of_identifiers or is_function_arguments:
            declaration_regexp = declaration_with_type_regexp
        else:
            declaration_regexp = declaration_without_type_regexp
        matched = match(declaration_regexp, line)
        if not matched:
            return
        identifier = matched.group('identifier')
        character_after_identifier = matched.group(
            'character_after_identifier')
         If we removed a non-for-control statement, the character after
         the identifier should be '='. With this rule, we can avoid
         warning for cases like "if (val & INT_MAX) {".
        if control_statement and character_after_identifier != '=':
            return
        is_function_arguments = is_function_arguments or character_after_identifier == '('
         There can be only one declaration in non-for-control statements.
        if control_statement:
            return
         We should continue checking if this is a function
         declaration because we need to check its arguments.
         Also, we need to check multiple declarations.
        if character_after_identifier != '(' and character_after_identifier != ',':
            return
        number_of_identifiers += 1
        line = line[matched.end():]
def check_identifier_name_in_declaration ( filename , line_number , line , file_state , error ) : if match ( r'\s*(return|delete|operator)\b' , line ) : return line = sub ( r'long (long )?(?=long|double|int)' , '' , line ) line = sub ( r'(unsigned|signed) (?=char|short|int|long)' , '' , line ) line = sub ( r'\b(inline|using|static|const|volatile|auto|register|extern|typedef|restrict|struct|class|virtual)(?=\W)' , '' , line ) line = sub ( r'new\s*(\([^)]*\))?' , '' , line ) while True : line , number_of_replacements = subn ( r'<([\w\s:]|::)+\s*[*&]*\s*>' , '' , line ) if not number_of_replacements : break line = sub ( r'^\s*for\s*\(' , '' , line ) line , control_statement = subn ( r'^\s*(while|else if|if|switch)\s*\(' , '' , line ) type_regexp = r'\w([\w]|\s*[*&]\s*|::)+' identifier_regexp = r'(?P<identifier>[\w:]+)' maybe_bitfield_regexp = r'(:\s*\d+\s*)?' character_after_identifier_regexp = r'(?P<character_after_identifier>[[;()=,])(?!=)' declaration_without_type_regexp = r'\s*' + identifier_regexp + r'\s*' + maybe_bitfield_regexp + character_after_identifier_regexp declaration_with_type_regexp = r'\s*' + type_regexp + r'\s' + declaration_without_type_regexp is_function_arguments = False number_of_identifiers = 0 while True : if not number_of_identifiers or is_function_arguments : declaration_regexp = declaration_with_type_regexp else : declaration_regexp = declaration_without_type_regexp matched = match ( declaration_regexp , line ) if not matched : return identifier = matched . group ( 'identifier' ) character_after_identifier = matched . group ( 'character_after_identifier' ) if control_statement and character_after_identifier != '=' : return is_function_arguments = is_function_arguments or character_after_identifier == '(' if control_statement : return if character_after_identifier != '(' and character_after_identifier != ',' : return number_of_identifiers += 1 line = line [ matched . end ( ) : ]
Checks if identifier names contain any underscores.
Checks if identifier names contain any underscores .
"""Checks if identifier names contain any underscores.

    As identifiers in libraries we are using have a bunch of
    underscores, we only warn about the declarations of identifiers
    and don't check use of identifiers.

    Args:
      filename: The name of the current file.
      line_number: The number of the line to check.
      line: The line of code to check.
      file_state: A _FileState instance which maintains information about
                  the state of things in the file.
      error: The function to call with any errors found.
    """ # We don't check return and delete statements and conversion operator declarations. # Basically, a declaration is a type name followed by whitespaces # followed by an identifier. The type name can be complicated # due to type adjectives and templates. We remove them first to # simplify the process to find declarations of identifiers. # Convert "long long", "long double", and "long long int" to # simple types, but don't remove simple "long". # Convert unsigned/signed types to simple types, too. # Remove "new" and "new (expr)" to simplify, too. # Remove all template parameters by removing matching < and >. # Loop until no templates are removed to remove nested templates. # Declarations of local variables can be in condition expressions # of control flow statements (e.g., "if (LayoutObject* p = o->parent())"). # We remove the keywords and the first parenthesis. # # Declarations in "while", "if", and "switch" are different from # other declarations in two aspects: # # - There can be only one declaration between the parentheses. #   (i.e., you cannot write "if (int i = 0, j = 1) {}") # - The variable must be initialized. #   (i.e., you cannot write "if (int i) {}") # # and we will need different treatments for them. # Detect variable and functions. # If we are seeing the first identifier or arguments of a # function, there should be a type name before an identifier. # If we removed a non-for-control statement, the character after # the identifier should be '='. With this rule, we can avoid # warning for cases like "if (val & INT_MAX) {". # There can be only one declaration in non-for-control statements. # We should continue checking if this is a function # declaration because we need to check its arguments. # Also, we need to check multiple declarations.
filename
The name of the current file.
The name of the current file .
line_number
The number of the line to check.
The number of the line to check .
line
The line of code to check.
The line of code to check .
file_state
A _FileState instance which maintains information about
the state of things in the file.
A _FileState instance which maintains information about the state of things in the file .
error
The function to call with any errors found.
The function to call with any errors found .