third_party/blink/tools/blinkpy/style/checkers/cpp.py
def check_for_include_what_you_use(filename, clean_lines, include_state,
                                   error):
    """Reports for missing stl includes.

    This function will output warnings to make sure you are including the headers
    necessary for the stl containers and functions that you use. We only give one
    reason to include a header. For example, if you use both equal_to<> and
    less<> in a .h file, only one (the latter in the file) of these will be
    reported as a reason to include the <functional>.

    Args:
      filename: The name of the current file.
      clean_lines: A CleansedLines instance containing the file.
      include_state: An _IncludeState instance.
      error: The function to call with any errors found.
    """
    # A map of header name to line_number and the template entity.
    required = {}
    # Example of required: { '<functional>': (1219, 'less<>') }

    for line_number in xrange(clean_lines.num_lines()):
        line = clean_lines.elided[line_number]
        if not line or line[0] == '#':
            continue

        # String is special -- it is a non-templatized type in STL.
        if _RE_PATTERN_STRING.search(line):
            required['<string>'] = (line_number, 'string')

        for pattern, template, header in _re_pattern_algorithm_header:
            if pattern.search(line):
                required[header] = (line_number, template)

        # The following function is just a speed up, no semantics are changed.
        if not '<' in line:  # Reduces the cpu time usage by skipping lines.
            continue

        for pattern, template, header in _re_pattern_templates:
            if pattern.search(line):
                required[header] = (line_number, template)

    # The policy is that if you #include something in foo.h you don't need to
    # include it again in foo.cpp. Here, we will look at possible includes.
    # Let's copy the include_state so it is only messed up within this function.
    include_state = include_state.copy()

    # Did we find the header for this file (if any) and succesfully load it?
    header_found = False

    # Use the absolute path so that matching works properly.
    abs_filename = os.path.abspath(filename)

    # For Emacs's flymake.
    # If cpp_style is invoked from Emacs's flymake, a temporary file is generated
    # by flymake and that file name might end with '_flymake.cpp'. In that case,
    # restore original file name here so that the corresponding header file can be
    # found.
    # e.g. If the file name is 'foo_flymake.cpp', we should search for 'foo.h'
    # instead of 'foo_flymake.h'
    abs_filename = re.sub(r'_flymake\.cpp$', '.cpp', abs_filename)

    # include_state is modified during iteration, so we iterate over a copy of
    # the keys.
    for header in list(include_state):  # NOLINT
        (same_module, common_path) = files_belong_to_same_module(
            abs_filename, header)
        fullpath = common_path + header
        if same_module and update_include_state(fullpath, include_state):
            header_found = True

    # If we can't find the header file for a .cpp, assume it's because we don't
    # know where to look. In that case we'll give up as we're not sure they
    # didn't include it in the .h file.
    # FIXME: Do a better job of finding .h files so we are confident that
    #        not having the .h file means there isn't one.
    if filename.endswith('.cpp') and not header_found:
        return

    # All the lines have been processed, report the errors found.
    for required_header_unstripped in required:
        template = required[required_header_unstripped][1]
        if template in _HEADERS_ACCEPTED_BUT_NOT_PROMOTED:
            headers = _HEADERS_ACCEPTED_BUT_NOT_PROMOTED[template]
            if [True for header in headers if header in include_state]:
                continue
        if required_header_unstripped.strip('<>"') not in include_state:
            error(
                required[required_header_unstripped][0],
                'build/include_what_you_use', 4, 'Add #include ' +
                required_header_unstripped + ' for ' + template)
Reports for missing stl includes.

    This function will output warnings to make sure you are including the headers
    necessary for the stl containers and functions that you use. We only give one
    reason to include a header. For example, if you use both equal_to<> and
    less<> in a .h file, only one (the latter in the file) of these will be
    reported as a reason to include the <functional>.

    Args:
      filename: The name of the current file.
      clean_lines: A CleansedLines instance containing the file.
      include_state: An _IncludeState instance.
      error: The function to call with any errors found.
    
Reports for missing stl includes.
This function will output warnings to make sure you are including the headers
necessary for the stl containers and functions that you use. We only give one
reason to include a header. For example, if you use both equal_to<> and
less<> in a .h file, only one (the latter in the file) of these will be
reported as a reason to include the .
Reports for missing stl includes . This function will output warnings to make sure you are including the headers necessary for the stl containers and functions that you use . We only give one reason to include a header . For example if you use both equal_to< > and less< > in a . h file only one ( the latter in the file ) of these will be reported as a reason to include the .
def check_for_include_what_you_use(filename, clean_lines, include_state,
                                   error):
    required = {}
    for line_number in xrange(clean_lines.num_lines()):
        line = clean_lines.elided[line_number]
        if not line or line[0] == '#':
            continue
        if _RE_PATTERN_STRING.search(line):
            required['<string>'] = (line_number, 'string')
        for pattern, template, header in _re_pattern_algorithm_header:
            if pattern.search(line):
                required[header] = (line_number, template)
        if not '<' in line:  
            continue
        for pattern, template, header in _re_pattern_templates:
            if pattern.search(line):
                required[header] = (line_number, template)
    include_state = include_state.copy()
    header_found = False
    abs_filename = os.path.abspath(filename)
    abs_filename = re.sub(r'_flymake\.cpp$', '.cpp', abs_filename)
    for header in list(include_state):  
        (same_module, common_path) = files_belong_to_same_module(
            abs_filename, header)
        fullpath = common_path + header
        if same_module and update_include_state(fullpath, include_state):
            header_found = True
    if filename.endswith('.cpp') and not header_found:
        return
    for required_header_unstripped in required:
        template = required[required_header_unstripped][1]
        if template in _HEADERS_ACCEPTED_BUT_NOT_PROMOTED:
            headers = _HEADERS_ACCEPTED_BUT_NOT_PROMOTED[template]
            if [True for header in headers if header in include_state]:
                continue
        if required_header_unstripped.strip('<>"') not in include_state:
            error(
                required[required_header_unstripped][0],
                'build/include_what_you_use', 4, 'Add #include ' +
                required_header_unstripped + ' for ' + template)
def check_for_include_what_you_use ( filename , clean_lines , include_state , error ) : required = { } for line_number in xrange ( clean_lines . num_lines ( ) ) : line = clean_lines . elided [ line_number ] if not line or line [ 0 ] == '#' : continue if _RE_PATTERN_STRING . search ( line ) : required [ '<string>' ] = ( line_number , 'string' ) for pattern , template , header in _re_pattern_algorithm_header : if pattern . search ( line ) : required [ header ] = ( line_number , template ) if not '<' in line : continue for pattern , template , header in _re_pattern_templates : if pattern . search ( line ) : required [ header ] = ( line_number , template ) include_state = include_state . copy ( ) header_found = False abs_filename = os . path . abspath ( filename ) abs_filename = re . sub ( r'_flymake\.cpp$' , '.cpp' , abs_filename ) for header in list ( include_state ) : ( same_module , common_path ) = files_belong_to_same_module ( abs_filename , header ) fullpath = common_path + header if same_module and update_include_state ( fullpath , include_state ) : header_found = True if filename . endswith ( '.cpp' ) and not header_found : return for required_header_unstripped in required : template = required [ required_header_unstripped ] [ 1 ] if template in _HEADERS_ACCEPTED_BUT_NOT_PROMOTED : headers = _HEADERS_ACCEPTED_BUT_NOT_PROMOTED [ template ] if [ True for header in headers if header in include_state ] : continue if required_header_unstripped . strip ( '<>"' ) not in include_state : error ( required [ required_header_unstripped ] [ 0 ] , 'build/include_what_you_use' , 4 , 'Add #include ' + required_header_unstripped + ' for ' + template )
Reports for missing stl includes.
Reports for missing stl includes .
"""Reports for missing stl includes.

    This function will output warnings to make sure you are including the headers
    necessary for the stl containers and functions that you use. We only give one
    reason to include a header. For example, if you use both equal_to<> and
    less<> in a .h file, only one (the latter in the file) of these will be
    reported as a reason to include the <functional>.

    Args:
      filename: The name of the current file.
      clean_lines: A CleansedLines instance containing the file.
      include_state: An _IncludeState instance.
      error: The function to call with any errors found.
    """ # A map of header name to line_number and the template entity. # Example of required: { '<functional>': (1219, 'less<>') } # String is special -- it is a non-templatized type in STL. # The following function is just a speed up, no semantics are changed. # Reduces the cpu time usage by skipping lines. # The policy is that if you #include something in foo.h you don't need to # include it again in foo.cpp. Here, we will look at possible includes. # Let's copy the include_state so it is only messed up within this function. # Did we find the header for this file (if any) and succesfully load it? # Use the absolute path so that matching works properly. # For Emacs's flymake. # If cpp_style is invoked from Emacs's flymake, a temporary file is generated # by flymake and that file name might end with '_flymake.cpp'. In that case, # restore original file name here so that the corresponding header file can be # found. # e.g. If the file name is 'foo_flymake.cpp', we should search for 'foo.h' # instead of 'foo_flymake.h' # include_state is modified during iteration, so we iterate over a copy of # the keys. # NOLINT # If we can't find the header file for a .cpp, assume it's because we don't # know where to look. In that case we'll give up as we're not sure they # didn't include it in the .h file. # FIXME: Do a better job of finding .h files so we are confident that #        not having the .h file means there isn't one. # All the lines have been processed, report the errors found.
filename
The name of the current file.
The name of the current file .
clean_lines
A CleansedLines instance containing the file.
A CleansedLines instance containing the file .
include_state
An _IncludeState instance.
An _IncludeState instance .
error
The function to call with any errors found.
The function to call with any errors found .