MCPcopy Create free account
hub / github.com/dmtcp/dmtcp / CheckForIncludeWhatYouUse

Function CheckForIncludeWhatYouUse

util/cpplint.py:5420–5516  ·  view source on GitHub ↗

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

(filename, clean_lines, include_state, error,
                              io=codecs)

Source from the content-addressed store, hash-verified

5418
5419
5420def CheckForIncludeWhatYouUse(filename, clean_lines, include_state, error,
5421 io=codecs):
5422 """Reports for missing stl includes.
5423
5424 This function will output warnings to make sure you are including the headers
5425 necessary for the stl containers and functions that you use. We only give one
5426 reason to include a header. For example, if you use both equal_to<> and
5427 less<> in a .h file, only one (the latter in the file) of these will be
5428 reported as a reason to include the <functional>.
5429
5430 Args:
5431 filename: The name of the current file.
5432 clean_lines: A CleansedLines instance containing the file.
5433 include_state: An _IncludeState instance.
5434 error: The function to call with any errors found.
5435 io: The IO factory to use to read the header file. Provided for unittest
5436 injection.
5437 """
5438 required = {} # A map of header name to linenumber and the template entity.
5439 # Example of required: { '<functional>': (1219, 'less<>') }
5440
5441 for linenum in range(clean_lines.NumLines()):
5442 line = clean_lines.elided[linenum]
5443 if not line or line[0] == '#':
5444 continue
5445
5446 # String is special -- it is a non-templatized type in STL.
5447 matched = _RE_PATTERN_STRING.search(line)
5448 if matched:
5449 # Don't warn about strings in non-STL namespaces:
5450 # (We check only the first match per line; good enough.)
5451 prefix = line[:matched.start()]
5452 if prefix.endswith('std::') or not prefix.endswith('::'):
5453 required['<string>'] = (linenum, 'string')
5454
5455 for pattern, template, header in _re_pattern_headers_maybe_templates:
5456 if pattern.search(line):
5457 required[header] = (linenum, template)
5458
5459 # The following function is just a speed up, no semantics are changed.
5460 if not '<' in line: # Reduces the cpu time usage by skipping lines.
5461 continue
5462
5463 for pattern, template, header in _re_pattern_templates:
5464 matched = pattern.search(line)
5465 if matched:
5466 # Don't warn about IWYU in non-STL namespaces:
5467 # (We check only the first match per line; good enough.)
5468 prefix = line[:matched.start()]
5469 if prefix.endswith('std::') or not prefix.endswith('::'):
5470 required[header] = (linenum, template)
5471
5472 # The policy is that if you #include something in foo.h you don't need to
5473 # include it again in foo.cc. Here, we will look at possible includes.
5474 # Let's flatten the include_state include_list and copy it into a dictionary.
5475 include_dict = dict([item for sublist in include_state.include_list
5476 for item in sublist])
5477

Callers 1

ProcessFileDataFunction · 0.85

Calls 8

FileInfoClass · 0.85
listClass · 0.85
FilesBelongToSameModuleFunction · 0.85
UpdateIncludeStateFunction · 0.85
errorFunction · 0.85
NumLinesMethod · 0.80
startMethod · 0.80
FullNameMethod · 0.80

Tested by

no test coverage detected