MCPcopy Create free account
hub / github.com/SIPp/sipp / _ClassifyInclude

Function _ClassifyInclude

cpplint.py:2957–3014  ·  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

2955
2956
2957def _ClassifyInclude(fileinfo, include, is_system):
2958 """Figures out what kind of header 'include' is.
2959
2960 Args:
2961 fileinfo: The current file cpplint is running over. A FileInfo instance.
2962 include: The path to a #included file.
2963 is_system: True if the #include used <> rather than "".
2964
2965 Returns:
2966 One of the _XXX_HEADER constants.
2967
2968 For example:
2969 >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'stdio.h', True)
2970 _C_SYS_HEADER
2971 >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'string', True)
2972 _CPP_SYS_HEADER
2973 >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/foo.h', False)
2974 _LIKELY_MY_HEADER
2975 >>> _ClassifyInclude(FileInfo('foo/foo_unknown_extension.cc'),
2976 ... 'bar/foo_other_ext.h', False)
2977 _POSSIBLE_MY_HEADER
2978 >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/bar.h', False)
2979 _OTHER_HEADER
2980 """
2981 # This is a list of all standard c++ header files, except
2982 # those already checked for above.
2983 is_stl_h = include in _STL_HEADERS
2984 is_cpp_h = is_stl_h or include in _CPP_HEADERS
2985
2986 if is_system:
2987 if is_cpp_h:
2988 return _CPP_SYS_HEADER
2989 else:
2990 return _C_SYS_HEADER
2991
2992 # If the target file and the include we're checking share a
2993 # basename when we drop common extensions, and the include
2994 # lives in . , then it's likely to be owned by the target file.
2995 target_dir, target_base = (
2996 os.path.split(_DropCommonSuffixes(fileinfo.RepositoryName())))
2997 include_dir, include_base = os.path.split(_DropCommonSuffixes(include))
2998 if target_base == include_base and (
2999 include_dir == target_dir or
3000 include_dir == os.path.normpath(target_dir + '/../public')):
3001 return _LIKELY_MY_HEADER
3002
3003 # If the target and include share some initial basename
3004 # component, it's possible the target is implementing the
3005 # include, so it's allowed to be first, but we'll never
3006 # complain if it's not there.
3007 target_first_component = _RE_FIRST_COMPONENT.match(target_base)
3008 include_first_component = _RE_FIRST_COMPONENT.match(include_base)
3009 if (target_first_component and include_first_component and
3010 target_first_component.group(0) ==
3011 include_first_component.group(0)):
3012 return _POSSIBLE_MY_HEADER
3013
3014 return _OTHER_HEADER

Callers 1

CheckIncludeLineFunction · 0.85

Calls 2

_DropCommonSuffixesFunction · 0.85
RepositoryNameMethod · 0.80

Tested by

no test coverage detected