third_party/blink/tools/blinkpy/style/checkers/cpp.py
def check_for_toFoo_definition(filename, pattern, error):
    """Reports for using static_cast instead of toFoo convenience function.

    This function will output warnings to make sure you are actually using
    the added toFoo conversion functions rather than directly hard coding
    the static_cast<Classname*> call. For example, you should toHTMLELement(Node*)
    to convert Node* to HTMLElement*, instead of static_cast<HTMLElement*>(Node*)

    Args:
      filename: The name of the header file in which to check for toFoo definition.
      pattern: The conversion function pattern to grep for.
      error: The function to call with any errors found.
    """

    def get_abs_filepath(filename):
        fileSystem = FileSystem()
        base_dir = fileSystem.path_to_module(FileSystem.__module__).split(
            'WebKit', 1)[0]
        base_dir = ''.join((base_dir, 'WebKit/Source'))
        for root, _, names in os.walk(base_dir):
            if filename in names:
                return os.path.join(root, filename)
        return None

    def grep(lines, pattern, error):
        matches = []
        function_state = None
        for line_number in xrange(lines.num_lines()):
            line = (lines.elided[line_number]).rstrip()
            try:
                if pattern in line:
                    if not function_state:
                        function_state = _FunctionState(1)
                    detect_functions(lines, line_number, function_state, error)
                    # Exclude the match of dummy conversion function. Dummy function is just to
                    # catch invalid conversions and shouldn't be part of possible alternatives.
                    result = re.search(r'%s(\s+)%s' % ('void', pattern), line)
                    if not result:
                        matches.append([
                            line, function_state.body_start_position.row,
                            function_state.end_position.row + 1
                        ])
                        function_state = None
            except UnicodeDecodeError:
                # There would be no non-ascii characters in the codebase ever. The only exception
                # would be comments/copyright text which might have non-ascii characters. Hence,
                # it is perfectly safe to catch the UnicodeDecodeError and just pass the line.
                pass

        return matches

    def check_in_mock_header(filename, matches=None):
        if not filename == 'Foo.h':
            return False

        header_file = None
        try:
            header_file = CppChecker.fs.read_text_file(filename)
        except IOError:
            return False
        line_number = 0
        for line in header_file:
            line_number += 1
            matched = re.search(r'\btoFoo\b', line)
            if matched:
                matches.append(['toFoo', line_number, line_number + 3])
        return True

    # For unit testing only, avoid header search and lookup locally.
    matches = []
    mock_def_found = check_in_mock_header(filename, matches)
    if mock_def_found:
        return matches

    # Regular style check flow. Search for actual header file & defs.
    file_path = get_abs_filepath(filename)
    if not file_path:
        return None
    try:
        f = open(file_path)
        clean_lines = CleansedLines(f.readlines())
    finally:
        f.close()

    # Make a list of all genuine alternatives to static_cast.
    matches = grep(clean_lines, pattern, error)
    return matches
Reports for using static_cast instead of toFoo convenience function.

    This function will output warnings to make sure you are actually using
    the added toFoo conversion functions rather than directly hard coding
    the static_cast<Classname*> call. For example, you should toHTMLELement(Node*)
    to convert Node* to HTMLElement*, instead of static_cast<HTMLElement*>(Node*)

    Args:
      filename: The name of the header file in which to check for toFoo definition.
      pattern: The conversion function pattern to grep for.
      error: The function to call with any errors found.
    
Reports for using static_cast instead of toFoo convenience function.
This function will output warnings to make sure you are actually using
the added toFoo conversion functions rather than directly hard coding
the static_cast call. For example, you should toHTMLELement(Node*)
to convert Node* to HTMLElement*, instead of static_cast(Node*)
Reports for using static_cast instead of toFoo convenience function . This function will output warnings to make sure you are actually using the added toFoo conversion functions rather than directly hard coding the static_cast call . For example you should toHTMLELement ( Node * ) to convert Node * to HTMLElement * instead of static_cast ( Node * )
def check_for_toFoo_definition(filename, pattern, error):
    def get_abs_filepath(filename):
        fileSystem = FileSystem()
        base_dir = fileSystem.path_to_module(FileSystem.__module__).split(
            'WebKit', 1)[0]
        base_dir = ''.join((base_dir, 'WebKit/Source'))
        for root, _, names in os.walk(base_dir):
            if filename in names:
                return os.path.join(root, filename)
        return None
    def grep(lines, pattern, error):
        matches = []
        function_state = None
        for line_number in xrange(lines.num_lines()):
            line = (lines.elided[line_number]).rstrip()
            try:
                if pattern in line:
                    if not function_state:
                        function_state = _FunctionState(1)
                    detect_functions(lines, line_number, function_state, error)
                    result = re.search(r'%s(\s+)%s' % ('void', pattern), line)
                    if not result:
                        matches.append([
                            line, function_state.body_start_position.row,
                            function_state.end_position.row + 1
                        ])
                        function_state = None
            except UnicodeDecodeError:
                pass
        return matches
    def check_in_mock_header(filename, matches=None):
        if not filename == 'Foo.h':
            return False
        header_file = None
        try:
            header_file = CppChecker.fs.read_text_file(filename)
        except IOError:
            return False
        line_number = 0
        for line in header_file:
            line_number += 1
            matched = re.search(r'\btoFoo\b', line)
            if matched:
                matches.append(['toFoo', line_number, line_number + 3])
        return True
    matches = []
    mock_def_found = check_in_mock_header(filename, matches)
    if mock_def_found:
        return matches
    file_path = get_abs_filepath(filename)
    if not file_path:
        return None
    try:
        f = open(file_path)
        clean_lines = CleansedLines(f.readlines())
    finally:
        f.close()
    matches = grep(clean_lines, pattern, error)
    return matches
def check_for_toFoo_definition ( filename , pattern , error ) : def get_abs_filepath ( filename ) : fileSystem = FileSystem ( ) base_dir = fileSystem . path_to_module ( FileSystem . __module__ ) . split ( 'WebKit' , 1 ) [ 0 ] base_dir = '' . join ( ( base_dir , 'WebKit/Source' ) ) for root , _ , names in os . walk ( base_dir ) : if filename in names : return os . path . join ( root , filename ) return None def grep ( lines , pattern , error ) : matches = [ ] function_state = None for line_number in xrange ( lines . num_lines ( ) ) : line = ( lines . elided [ line_number ] ) . rstrip ( ) try : if pattern in line : if not function_state : function_state = _FunctionState ( 1 ) detect_functions ( lines , line_number , function_state , error ) result = re . search ( r'%s(\s+)%s' % ( 'void' , pattern ) , line ) if not result : matches . append ( [ line , function_state . body_start_position . row , function_state . end_position . row + 1 ] ) function_state = None except UnicodeDecodeError : pass return matches def check_in_mock_header ( filename , matches = None ) : if not filename == 'Foo.h' : return False header_file = None try : header_file = CppChecker . fs . read_text_file ( filename ) except IOError : return False line_number = 0 for line in header_file : line_number += 1 matched = re . search ( r'\btoFoo\b' , line ) if matched : matches . append ( [ 'toFoo' , line_number , line_number + 3 ] ) return True matches = [ ] mock_def_found = check_in_mock_header ( filename , matches ) if mock_def_found : return matches file_path = get_abs_filepath ( filename ) if not file_path : return None try : f = open ( file_path ) clean_lines = CleansedLines ( f . readlines ( ) ) finally : f . close ( ) matches = grep ( clean_lines , pattern , error ) return matches
Reports for using static_cast instead of toFoo convenience function.
Reports for using static_cast instead of toFoo convenience function .
"""Reports for using static_cast instead of toFoo convenience function.

    This function will output warnings to make sure you are actually using
    the added toFoo conversion functions rather than directly hard coding
    the static_cast<Classname*> call. For example, you should toHTMLELement(Node*)
    to convert Node* to HTMLElement*, instead of static_cast<HTMLElement*>(Node*)

    Args:
      filename: The name of the header file in which to check for toFoo definition.
      pattern: The conversion function pattern to grep for.
      error: The function to call with any errors found.
    """ # Exclude the match of dummy conversion function. Dummy function is just to # catch invalid conversions and shouldn't be part of possible alternatives. # There would be no non-ascii characters in the codebase ever. The only exception # would be comments/copyright text which might have non-ascii characters. Hence, # it is perfectly safe to catch the UnicodeDecodeError and just pass the line. # For unit testing only, avoid header search and lookup locally. # Regular style check flow. Search for actual header file & defs. # Make a list of all genuine alternatives to static_cast.
filename
The name of the header file in which to check for toFoo definition.
The name of the header file in which to check for toFoo definition .
pattern
The conversion function pattern to grep for.
The conversion function pattern to grep for .
error
The function to call with any errors found.
The function to call with any errors found .