MCPcopy Create free account
hub / github.com/OpenPTrack/open_ptrack_v2 / CheckForIncludeWhatYouUse

Function CheckForIncludeWhatYouUse

rtpose_wrapper/scripts/cpp_lint.py:4483–4573  ·  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

4481
4482
4483def CheckForIncludeWhatYouUse(filename, clean_lines, include_state, error,
4484 io=codecs):
4485 """Reports for missing stl includes.
4486
4487 This function will output warnings to make sure you are including the headers
4488 necessary for the stl containers and functions that you use. We only give one
4489 reason to include a header. For example, if you use both equal_to<> and
4490 less<> in a .h file, only one (the latter in the file) of these will be
4491 reported as a reason to include the <functional>.
4492
4493 Args:
4494 filename: The name of the current file.
4495 clean_lines: A CleansedLines instance containing the file.
4496 include_state: An _IncludeState instance.
4497 error: The function to call with any errors found.
4498 io: The IO factory to use to read the header file. Provided for unittest
4499 injection.
4500 """
4501 required = {} # A map of header name to linenumber and the template entity.
4502 # Example of required: { '<functional>': (1219, 'less<>') }
4503
4504 for linenum in xrange(clean_lines.NumLines()):
4505 line = clean_lines.elided[linenum]
4506 if not line or line[0] == '#':
4507 continue
4508
4509 # String is special -- it is a non-templatized type in STL.
4510 matched = _RE_PATTERN_STRING.search(line)
4511 if matched:
4512 # Don't warn about strings in non-STL namespaces:
4513 # (We check only the first match per line; good enough.)
4514 prefix = line[:matched.start()]
4515 if prefix.endswith('std::') or not prefix.endswith('::'):
4516 required['<string>'] = (linenum, 'string')
4517
4518 for pattern, template, header in _re_pattern_algorithm_header:
4519 if pattern.search(line):
4520 required[header] = (linenum, template)
4521
4522 # The following function is just a speed up, no semantics are changed.
4523 if not '<' in line: # Reduces the cpu time usage by skipping lines.
4524 continue
4525
4526 for pattern, template, header in _re_pattern_templates:
4527 if pattern.search(line):
4528 required[header] = (linenum, template)
4529
4530 # The policy is that if you #include something in foo.h you don't need to
4531 # include it again in foo.cc. Here, we will look at possible includes.
4532 # Let's copy the include_state so it is only messed up within this function.
4533 include_state = include_state.copy()
4534
4535 # Did we find the header for this file (if any) and succesfully load it?
4536 header_found = False
4537
4538 # Use the absolute path so that matching works properly.
4539 abs_filename = FileInfo(filename).FullName()
4540

Callers 1

ProcessFileDataFunction · 0.85

Calls 7

FileInfoClass · 0.85
FilesBelongToSameModuleFunction · 0.85
UpdateIncludeStateFunction · 0.85
errorFunction · 0.85
NumLinesMethod · 0.80
copyMethod · 0.80
FullNameMethod · 0.80

Tested by

no test coverage detected