wpiformat/wpiformat/cpplint.py
def CheckForIncludeWhatYouUse(filename, clean_lines, include_state, error,
                              io=codecs):
  """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.
    io: The IO factory to use to read the header file. Provided for unittest
        injection.
  """
  required = {}  # A map of header name to linenumber and the template entity.
                 # Example of required: { '<functional>': (1219, 'less<>') }

  for linenum in range(clean_lines.NumLines()):
    line = clean_lines.elided[linenum]
    if not line or line[0] == '#':
      continue

    # String is special -- it is a non-templatized type in STL.
    matched = _RE_PATTERN_STRING.search(line)
    if matched:
      # Don't warn about strings in non-STL namespaces:
      # (We check only the first match per line; good enough.)
      prefix = line[:matched.start()]
      if prefix.endswith('std::') or not prefix.endswith('::'):
        required['<string>'] = (linenum, 'string')

    for pattern, template, header in _re_pattern_headers_maybe_templates:
      if pattern.search(line):
        required[header] = (linenum, 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:
      matched = pattern.search(line)
      if matched:
        # Don't warn about IWYU in non-STL namespaces:
        # (We check only the first match per line; good enough.)
        prefix = line[:matched.start()]
        if prefix.endswith('std::') or not prefix.endswith('::'):
          required[header] = (linenum, template)

  # The policy is that if you #include something in foo.h you don't need to
  # include it again in foo.cc. Here, we will look at possible includes.
  # Let's flatten the include_state include_list and copy it into a dictionary.
  include_dict = dict([item for sublist in include_state.include_list
                       for item in sublist])

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

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

  # include_dict is modified during iteration, so we iterate over a copy of
  # the keys.
  header_keys = list(include_dict.keys())
  for header in header_keys:
    (same_module, common_path) = FilesBelongToSameModule(abs_filename, header)
    fullpath = common_path + header
    if same_module and UpdateIncludeState(fullpath, include_dict, io):
      header_found = True

  # If we can't find the header file for a .cc, 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.
  # TODO(unknown): Do a better job of finding .h files so we are confident that
  # not having the .h file means there isn't one.
  if not header_found:
    if IsSourceFile(filename):
      return

  # All the lines have been processed, report the errors found.
  for required_header_unstripped in sorted(required, key=required.__getitem__):
    template = required[required_header_unstripped][1]
    if required_header_unstripped.strip('<>"') not in include_dict:
      error(filename, 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.
    io: The IO factory to use to read the header file. Provided for unittest
        injection.
  
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 CheckForIncludeWhatYouUse(filename, clean_lines, include_state, error,
                              io=codecs):
  required = {}  
  for linenum in range(clean_lines.NumLines()):
    line = clean_lines.elided[linenum]
    if not line or line[0] == '#':
      continue
    matched = _RE_PATTERN_STRING.search(line)
    if matched:
      prefix = line[:matched.start()]
      if prefix.endswith('std::') or not prefix.endswith('::'):
        required['<string>'] = (linenum, 'string')
    for pattern, template, header in _re_pattern_headers_maybe_templates:
      if pattern.search(line):
        required[header] = (linenum, template)
    if not '<' in line:  
      continue
    for pattern, template, header in _re_pattern_templates:
      matched = pattern.search(line)
      if matched:
        prefix = line[:matched.start()]
        if prefix.endswith('std::') or not prefix.endswith('::'):
          required[header] = (linenum, template)
  include_dict = dict([item for sublist in include_state.include_list
                       for item in sublist])
  header_found = False
  abs_filename = FileInfo(filename).FullName()
  header_keys = list(include_dict.keys())
  for header in header_keys:
    (same_module, common_path) = FilesBelongToSameModule(abs_filename, header)
    fullpath = common_path + header
    if same_module and UpdateIncludeState(fullpath, include_dict, io):
      header_found = True
  if not header_found:
    if IsSourceFile(filename):
      return
  for required_header_unstripped in sorted(required, key=required.__getitem__):
    template = required[required_header_unstripped][1]
    if required_header_unstripped.strip('<>"') not in include_dict:
      error(filename, required[required_header_unstripped][0],
            'build/include_what_you_use', 4,
            'Add #include ' + required_header_unstripped + ' for ' + template)
def CheckForIncludeWhatYouUse ( filename , clean_lines , include_state , error , io = codecs ) : required = { } for linenum in range ( clean_lines . NumLines ( ) ) : line = clean_lines . elided [ linenum ] if not line or line [ 0 ] == '#' : continue matched = _RE_PATTERN_STRING . search ( line ) if matched : prefix = line [ : matched . start ( ) ] if prefix . endswith ( 'std::' ) or not prefix . endswith ( '::' ) : required [ '<string>' ] = ( linenum , 'string' ) for pattern , template , header in _re_pattern_headers_maybe_templates : if pattern . search ( line ) : required [ header ] = ( linenum , template ) if not '<' in line : continue for pattern , template , header in _re_pattern_templates : matched = pattern . search ( line ) if matched : prefix = line [ : matched . start ( ) ] if prefix . endswith ( 'std::' ) or not prefix . endswith ( '::' ) : required [ header ] = ( linenum , template ) include_dict = dict ( [ item for sublist in include_state . include_list for item in sublist ] ) header_found = False abs_filename = FileInfo ( filename ) . FullName ( ) header_keys = list ( include_dict . keys ( ) ) for header in header_keys : ( same_module , common_path ) = FilesBelongToSameModule ( abs_filename , header ) fullpath = common_path + header if same_module and UpdateIncludeState ( fullpath , include_dict , io ) : header_found = True if not header_found : if IsSourceFile ( filename ) : return for required_header_unstripped in sorted ( required , key = required . __getitem__ ) : template = required [ required_header_unstripped ] [ 1 ] if required_header_unstripped . strip ( '<>"' ) not in include_dict : error ( filename , 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.
    io: The IO factory to use to read the header file. Provided for unittest
        injection.
  """ # A map of header name to linenumber and the template entity. # Example of required: { '<functional>': (1219, 'less<>') } # String is special -- it is a non-templatized type in STL. # Don't warn about strings in non-STL namespaces: # (We check only the first match per line; good enough.) # The following function is just a speed up, no semantics are changed. # Reduces the cpu time usage by skipping lines. # Don't warn about IWYU in non-STL namespaces: # (We check only the first match per line; good enough.) # The policy is that if you #include something in foo.h you don't need to # include it again in foo.cc. Here, we will look at possible includes. # Let's flatten the include_state include_list and copy it into a dictionary. # Did we find the header for this file (if any) and successfully load it? # Use the absolute path so that matching works properly. # include_dict is modified during iteration, so we iterate over a copy of # the keys. # If we can't find the header file for a .cc, 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. # TODO(unknown): 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 .
io
The IO factory to use to read the header file. Provided for unittest
injection.
The IO factory to use to read the header file . Provided for unittest injection .