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

Function _ClassifyInclude

rtpose_wrapper/scripts/cpp_lint.py:3620–3676  ·  view source on GitHub ↗

Figures out what kind of header 'include' is. Args: fileinfo: The current file cpplint is running over. A FileInfo instance. include: The path to a #included file. is_system: True if the #include used <> rather than "". Returns: One of the _XXX_HEADER constants. For example:

(fileinfo, include, is_system)

Source from the content-addressed store, hash-verified

3618
3619
3620def _ClassifyInclude(fileinfo, include, is_system):
3621 """Figures out what kind of header 'include' is.
3622
3623 Args:
3624 fileinfo: The current file cpplint is running over. A FileInfo instance.
3625 include: The path to a #included file.
3626 is_system: True if the #include used <> rather than "".
3627
3628 Returns:
3629 One of the _XXX_HEADER constants.
3630
3631 For example:
3632 >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'stdio.h', True)
3633 _C_SYS_HEADER
3634 >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'string', True)
3635 _CPP_SYS_HEADER
3636 >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/foo.h', False)
3637 _LIKELY_MY_HEADER
3638 >>> _ClassifyInclude(FileInfo('foo/foo_unknown_extension.cc'),
3639 ... 'bar/foo_other_ext.h', False)
3640 _POSSIBLE_MY_HEADER
3641 >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/bar.h', False)
3642 _OTHER_HEADER
3643 """
3644 # This is a list of all standard c++ header files, except
3645 # those already checked for above.
3646 is_cpp_h = include in _CPP_HEADERS
3647
3648 if is_system:
3649 if is_cpp_h:
3650 return _CPP_SYS_HEADER
3651 else:
3652 return _C_SYS_HEADER
3653
3654 # If the target file and the include we're checking share a
3655 # basename when we drop common extensions, and the include
3656 # lives in . , then it's likely to be owned by the target file.
3657 target_dir, target_base = (
3658 os.path.split(_DropCommonSuffixes(fileinfo.RepositoryName())))
3659 include_dir, include_base = os.path.split(_DropCommonSuffixes(include))
3660 if target_base == include_base and (
3661 include_dir == target_dir or
3662 include_dir == os.path.normpath(target_dir + '/../public')):
3663 return _LIKELY_MY_HEADER
3664
3665 # If the target and include share some initial basename
3666 # component, it's possible the target is implementing the
3667 # include, so it's allowed to be first, but we'll never
3668 # complain if it's not there.
3669 target_first_component = _RE_FIRST_COMPONENT.match(target_base)
3670 include_first_component = _RE_FIRST_COMPONENT.match(include_base)
3671 if (target_first_component and include_first_component and
3672 target_first_component.group(0) ==
3673 include_first_component.group(0)):
3674 return _POSSIBLE_MY_HEADER
3675
3676 return _OTHER_HEADER
3677

Callers 1

CheckIncludeLineFunction · 0.85

Calls 3

_DropCommonSuffixesFunction · 0.85
splitMethod · 0.80
RepositoryNameMethod · 0.80

Tested by

no test coverage detected