@@ -6040,34 +6040,6 @@ def FilesBelongToSameModule(filename_cc, filename_h):
60406040 return files_belong_to_same_module , common_path
60416041
60426042
6043- def UpdateIncludeState (filename , include_dict , io = codecs ):
6044- """Fill up the include_dict with new includes found from the file.
6045-
6046- Args:
6047- filename: the name of the header to read.
6048- include_dict: a dictionary in which the headers are inserted.
6049- io: The io factory to use to read the file. Provided for testability.
6050-
6051- Returns:
6052- True if a header was successfully added. False otherwise.
6053- """
6054- headerfile = None
6055- try :
6056- with io .open (filename , 'r' , 'utf8' , 'replace' ) as headerfile :
6057- linenum = 0
6058- for line in headerfile :
6059- linenum += 1
6060- clean_line = CleanseComments (line )
6061- match = _RE_PATTERN_INCLUDE .search (clean_line )
6062- if match :
6063- include = match .group (2 )
6064- include_dict .setdefault (include , linenum )
6065- return True
6066- except IOError :
6067- return False
6068-
6069-
6070-
60716043def CheckForIncludeWhatYouUse (filename , clean_lines , include_state , error ,
60726044 io = codecs ):
60736045 """Reports for missing stl includes.
@@ -6123,36 +6095,10 @@ def CheckForIncludeWhatYouUse(filename, clean_lines, include_state, error,
61236095 if prefix .endswith ('std::' ) or not prefix .endswith ('::' ):
61246096 required [header ] = (linenum , template )
61256097
6126- # The policy is that if you #include something in foo.h you don't need to
6127- # include it again in foo.cc. Here, we will look at possible includes.
61286098 # Let's flatten the include_state include_list and copy it into a dictionary.
61296099 include_dict = dict ([item for sublist in include_state .include_list
61306100 for item in sublist ])
61316101
6132- # Did we find the header for this file (if any) and successfully load it?
6133- header_found = False
6134-
6135- # Use the absolute path so that matching works properly.
6136- abs_filename = FileInfo (filename ).FullName ()
6137-
6138- # For Emacs's flymake.
6139- # If cpplint is invoked from Emacs's flymake, a temporary file is generated
6140- # by flymake and that file name might end with '_flymake.cc'. In that case,
6141- # restore original file name here so that the corresponding header file can be
6142- # found.
6143- # e.g. If the file name is 'foo_flymake.cc', we should search for 'foo.h'
6144- # instead of 'foo_flymake.h'
6145- abs_filename = re .sub (r'_flymake\.cc$' , '.cc' , abs_filename )
6146-
6147- # include_dict is modified during iteration, so we iterate over a copy of
6148- # the keys.
6149- header_keys = list (include_dict .keys ())
6150- for header in header_keys :
6151- (same_module , common_path ) = FilesBelongToSameModule (abs_filename , header )
6152- fullpath = common_path + header
6153- if same_module and UpdateIncludeState (fullpath , include_dict , io ):
6154- header_found = True
6155-
61566102 # All the lines have been processed, report the errors found.
61576103 for required_header_unstripped in sorted (required , key = required .__getitem__ ):
61586104 template = required [required_header_unstripped ][1 ]
0 commit comments