MCPcopy Create free account
hub / github.com/4paradigm/OpenMLDB / _ClassifyInclude

Function _ClassifyInclude

steps/cpplint.py:4985–5056  ·  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

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

Callers 1

CheckIncludeLineFunction · 0.85

Calls 3

SearchFunction · 0.85
_DropCommonSuffixesFunction · 0.85
RepositoryNameMethod · 0.80

Tested by

no test coverage detected