MCPcopy Index your code
hub / github.com/tensorflow/tfjs / CheckForIncludeWhatYouUse

Function CheckForIncludeWhatYouUse

tfjs-backend-wasm/tools/cpplint.py:5498–5594  ·  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

5496
5497
5498def CheckForIncludeWhatYouUse(filename, clean_lines, include_state, error,
5499 io=codecs):
5500 """Reports for missing stl includes.
5501
5502 This function will output warnings to make sure you are including the headers
5503 necessary for the stl containers and functions that you use. We only give one
5504 reason to include a header. For example, if you use both equal_to<> and
5505 less<> in a .h file, only one (the latter in the file) of these will be
5506 reported as a reason to include the <functional>.
5507
5508 Args:
5509 filename: The name of the current file.
5510 clean_lines: A CleansedLines instance containing the file.
5511 include_state: An _IncludeState instance.
5512 error: The function to call with any errors found.
5513 io: The IO factory to use to read the header file. Provided for unittest
5514 injection.
5515 """
5516 required = {} # A map of header name to linenumber and the template entity.
5517 # Example of required: { '<functional>': (1219, 'less<>') }
5518
5519 for linenum in xrange(clean_lines.NumLines()):
5520 line = clean_lines.elided[linenum]
5521 if not line or line[0] == '#':
5522 continue
5523
5524 # String is special -- it is a non-templatized type in STL.
5525 matched = _RE_PATTERN_STRING.search(line)
5526 if matched:
5527 # Don't warn about strings in non-STL namespaces:
5528 # (We check only the first match per line; good enough.)
5529 prefix = line[:matched.start()]
5530 if prefix.endswith('std::') or not prefix.endswith('::'):
5531 required['<string>'] = (linenum, 'string')
5532
5533 for pattern, template, header in _re_pattern_headers_maybe_templates:
5534 if pattern.search(line):
5535 required[header] = (linenum, template)
5536
5537 # The following function is just a speed up, no semantics are changed.
5538 if not '<' in line: # Reduces the cpu time usage by skipping lines.
5539 continue
5540
5541 for pattern, template, header in _re_pattern_templates:
5542 matched = pattern.search(line)
5543 if matched:
5544 # Don't warn about IWYU in non-STL namespaces:
5545 # (We check only the first match per line; good enough.)
5546 prefix = line[:matched.start()]
5547 if prefix.endswith('std::') or not prefix.endswith('::'):
5548 required[header] = (linenum, template)
5549
5550 # The policy is that if you #include something in foo.h you don't need to
5551 # include it again in foo.cc. Here, we will look at possible includes.
5552 # Let's flatten the include_state include_list and copy it into a dictionary.
5553 include_dict = dict([item for sublist in include_state.include_list
5554 for item in sublist])
5555

Callers 1

ProcessFileDataFunction · 0.85

Calls 7

FileInfoClass · 0.85
FilesBelongToSameModuleFunction · 0.85
UpdateIncludeStateFunction · 0.85
NumLinesMethod · 0.80
FullNameMethod · 0.80
subMethod · 0.80
startMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…