MCPcopy Create free account
hub / github.com/alibaba/GraphScope / _ClassifyInclude

Function _ClassifyInclude

analytical_engine/misc/cpplint.py:4975–5046  ·  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. used_angle_brackets: True if the #include used <> rather than "". include_order: "default" or other value allowed in

(fileinfo, include, used_angle_brackets, include_order="default")

Source from the content-addressed store, hash-verified

4973
4974
4975def _ClassifyInclude(fileinfo, include, used_angle_brackets, include_order="default"):
4976 """Figures out what kind of header 'include' is.
4977
4978 Args:
4979 fileinfo: The current file cpplint is running over. A FileInfo instance.
4980 include: The path to a #included file.
4981 used_angle_brackets: True if the #include used <> rather than "".
4982 include_order: "default" or other value allowed in program arguments
4983
4984 Returns:
4985 One of the _XXX_HEADER constants.
4986
4987 For example:
4988 >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'stdio.h', True)
4989 _C_SYS_HEADER
4990 >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'string', True)
4991 _CPP_SYS_HEADER
4992 >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/foo.h', True, "standardcfirst")
4993 _OTHER_SYS_HEADER
4994 >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/foo.h', False)
4995 _LIKELY_MY_HEADER
4996 >>> _ClassifyInclude(FileInfo('foo/foo_unknown_extension.cc'),
4997 ... 'bar/foo_other_ext.h', False)
4998 _POSSIBLE_MY_HEADER
4999 >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/bar.h', False)
5000 _OTHER_HEADER
5001 """
5002 # This is a list of all standard c++ header files, except
5003 # those already checked for above.
5004 is_cpp_header = include in _CPP_HEADERS
5005
5006 # Mark include as C header if in list or in a known folder for standard-ish C headers.
5007 is_std_c_header = (include_order == "default") or (include in _C_HEADERS
5008 # additional linux glibc header folders
5009 or Search(r'(?:%s)\/.*\.h' % "|".join(C_STANDARD_HEADER_FOLDERS), include))
5010
5011 # Headers with C++ extensions shouldn't be considered C system headers
5012 is_system = used_angle_brackets and not os.path.splitext(include)[1] in ['.hpp', '.hxx', '.h++']
5013
5014 if is_system:
5015 if is_cpp_header:
5016 return _CPP_SYS_HEADER
5017 if is_std_c_header:
5018 return _C_SYS_HEADER
5019 else:
5020 return _OTHER_SYS_HEADER
5021
5022 # If the target file and the include we're checking share a
5023 # basename when we drop common extensions, and the include
5024 # lives in . , then it's likely to be owned by the target file.
5025 target_dir, target_base = (
5026 os.path.split(_DropCommonSuffixes(fileinfo.RepositoryName())))
5027 include_dir, include_base = os.path.split(_DropCommonSuffixes(include))
5028 target_dir_pub = os.path.normpath(target_dir + '/../public')
5029 target_dir_pub = target_dir_pub.replace('\\', '/')
5030 if target_base == include_base and (
5031 include_dir == target_dir or
5032 include_dir == target_dir_pub):

Callers 1

CheckIncludeLineFunction · 0.85

Calls 7

SearchFunction · 0.85
_DropCommonSuffixesFunction · 0.85
splitMethod · 0.80
RepositoryNameMethod · 0.80
joinMethod · 0.45
matchMethod · 0.45
groupMethod · 0.45

Tested by

no test coverage detected