MCPcopy Create free account
hub / github.com/BoomingTech/Piccolo / _ClassifyInclude

Function _ClassifyInclude

engine/3rdparty/tinyobjloader/deps/cpplint.py:4545–4601  ·  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

4543
4544
4545def _ClassifyInclude(fileinfo, include, is_system):
4546 """Figures out what kind of header 'include' is.
4547
4548 Args:
4549 fileinfo: The current file cpplint is running over. A FileInfo instance.
4550 include: The path to a #included file.
4551 is_system: True if the #include used <> rather than "".
4552
4553 Returns:
4554 One of the _XXX_HEADER constants.
4555
4556 For example:
4557 >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'stdio.h', True)
4558 _C_SYS_HEADER
4559 >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'string', True)
4560 _CPP_SYS_HEADER
4561 >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/foo.h', False)
4562 _LIKELY_MY_HEADER
4563 >>> _ClassifyInclude(FileInfo('foo/foo_unknown_extension.cc'),
4564 ... 'bar/foo_other_ext.h', False)
4565 _POSSIBLE_MY_HEADER
4566 >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/bar.h', False)
4567 _OTHER_HEADER
4568 """
4569 # This is a list of all standard c++ header files, except
4570 # those already checked for above.
4571 is_cpp_h = include in _CPP_HEADERS
4572
4573 if is_system:
4574 if is_cpp_h:
4575 return _CPP_SYS_HEADER
4576 else:
4577 return _C_SYS_HEADER
4578
4579 # If the target file and the include we're checking share a
4580 # basename when we drop common extensions, and the include
4581 # lives in . , then it's likely to be owned by the target file.
4582 target_dir, target_base = (
4583 os.path.split(_DropCommonSuffixes(fileinfo.RepositoryName())))
4584 include_dir, include_base = os.path.split(_DropCommonSuffixes(include))
4585 if target_base == include_base and (
4586 include_dir == target_dir or
4587 include_dir == os.path.normpath(target_dir + '/../public')):
4588 return _LIKELY_MY_HEADER
4589
4590 # If the target and include share some initial basename
4591 # component, it's possible the target is implementing the
4592 # include, so it's allowed to be first, but we'll never
4593 # complain if it's not there.
4594 target_first_component = _RE_FIRST_COMPONENT.match(target_base)
4595 include_first_component = _RE_FIRST_COMPONENT.match(include_base)
4596 if (target_first_component and include_first_component and
4597 target_first_component.group(0) ==
4598 include_first_component.group(0)):
4599 return _POSSIBLE_MY_HEADER
4600
4601 return _OTHER_HEADER
4602

Callers 1

CheckIncludeLineFunction · 0.85

Calls 4

_DropCommonSuffixesFunction · 0.85
splitMethod · 0.80
RepositoryNameMethod · 0.80
matchMethod · 0.45

Tested by

no test coverage detected