MCPcopy Create free account
hub / github.com/alibaba/graph-learn / _ClassifyInclude

Function _ClassifyInclude

dynamic_graph_service/ci/cpplint.py:4702–4764  ·  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

4700
4701
4702def _ClassifyInclude(fileinfo, include, is_system):
4703 """Figures out what kind of header 'include' is.
4704
4705 Args:
4706 fileinfo: The current file cpplint is running over. A FileInfo instance.
4707 include: The path to a #included file.
4708 is_system: True if the #include used <> rather than "".
4709
4710 Returns:
4711 One of the _XXX_HEADER constants.
4712
4713 For example:
4714 >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'stdio.h', True)
4715 _C_SYS_HEADER
4716 >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'string', True)
4717 _CPP_SYS_HEADER
4718 >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/foo.h', False)
4719 _LIKELY_MY_HEADER
4720 >>> _ClassifyInclude(FileInfo('foo/foo_unknown_extension.cc'),
4721 ... 'bar/foo_other_ext.h', False)
4722 _POSSIBLE_MY_HEADER
4723 >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/bar.h', False)
4724 _OTHER_HEADER
4725 """
4726 # This is a list of all standard c++ header files, except
4727 # those already checked for above.
4728 is_cpp_h = include in _CPP_HEADERS
4729
4730 # Headers with C++ extensions shouldn't be considered C system headers
4731 if is_system and os.path.splitext(include)[1] in ['.hpp', '.hxx', '.h++']:
4732 is_system = False
4733
4734 if is_system:
4735 if is_cpp_h:
4736 return _CPP_SYS_HEADER
4737 else:
4738 return _C_SYS_HEADER
4739
4740 # If the target file and the include we're checking share a
4741 # basename when we drop common extensions, and the include
4742 # lives in . , then it's likely to be owned by the target file.
4743 target_dir, target_base = (
4744 os.path.split(_DropCommonSuffixes(fileinfo.RepositoryName())))
4745 include_dir, include_base = os.path.split(_DropCommonSuffixes(include))
4746 target_dir_pub = os.path.normpath(target_dir + '/../public')
4747 target_dir_pub = target_dir_pub.replace('\\', '/')
4748 if target_base == include_base and (
4749 include_dir == target_dir or
4750 include_dir == target_dir_pub):
4751 return _LIKELY_MY_HEADER
4752
4753 # If the target and include share some initial basename
4754 # component, it's possible the target is implementing the
4755 # include, so it's allowed to be first, but we'll never
4756 # complain if it's not there.
4757 target_first_component = _RE_FIRST_COMPONENT.match(target_base)
4758 include_first_component = _RE_FIRST_COMPONENT.match(include_base)
4759 if (target_first_component and include_first_component and

Callers 1

CheckIncludeLineFunction · 0.85

Calls 2

_DropCommonSuffixesFunction · 0.85
RepositoryNameMethod · 0.80

Tested by

no test coverage detected