MCPcopy Create free account
hub / github.com/BVLC/caffe / CheckForIncludeWhatYouUse

Function CheckForIncludeWhatYouUse

scripts/cpp_lint.py:4487–4577  ·  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

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

Callers 1

ProcessFileDataFunction · 0.85

Calls 6

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

Tested by

no test coverage detected