MCPcopy Create free account
hub / github.com/tensorflow/tfjs / _ClassifyInclude

Function _ClassifyInclude

tfjs-backend-wasm/tools/cpplint.py:4466–4522  ·  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

4464
4465
4466def _ClassifyInclude(fileinfo, include, is_system):
4467 """Figures out what kind of header 'include' is.
4468
4469 Args:
4470 fileinfo: The current file cpplint is running over. A FileInfo instance.
4471 include: The path to a #included file.
4472 is_system: True if the #include used <> rather than "".
4473
4474 Returns:
4475 One of the _XXX_HEADER constants.
4476
4477 For example:
4478 >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'stdio.h', True)
4479 _C_SYS_HEADER
4480 >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'string', True)
4481 _CPP_SYS_HEADER
4482 >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/foo.h', False)
4483 _LIKELY_MY_HEADER
4484 >>> _ClassifyInclude(FileInfo('foo/foo_unknown_extension.cc'),
4485 ... 'bar/foo_other_ext.h', False)
4486 _POSSIBLE_MY_HEADER
4487 >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/bar.h', False)
4488 _OTHER_HEADER
4489 """
4490 # This is a list of all standard c++ header files, except
4491 # those already checked for above.
4492 is_cpp_h = include in _CPP_HEADERS
4493
4494 if is_system:
4495 if is_cpp_h:
4496 return _CPP_SYS_HEADER
4497 else:
4498 return _C_SYS_HEADER
4499
4500 # If the target file and the include we're checking share a
4501 # basename when we drop common extensions, and the include
4502 # lives in . , then it's likely to be owned by the target file.
4503 target_dir, target_base = (
4504 os.path.split(_DropCommonSuffixes(fileinfo.RepositoryName())))
4505 include_dir, include_base = os.path.split(_DropCommonSuffixes(include))
4506 if target_base == include_base and (
4507 include_dir == target_dir or
4508 include_dir == os.path.normpath(target_dir + '/../public')):
4509 return _LIKELY_MY_HEADER
4510
4511 # If the target and include share some initial basename
4512 # component, it's possible the target is implementing the
4513 # include, so it's allowed to be first, but we'll never
4514 # complain if it's not there.
4515 target_first_component = _RE_FIRST_COMPONENT.match(target_base)
4516 include_first_component = _RE_FIRST_COMPONENT.match(include_base)
4517 if (target_first_component and include_first_component and
4518 target_first_component.group(0) ==
4519 include_first_component.group(0)):
4520 return _POSSIBLE_MY_HEADER
4521
4522 return _OTHER_HEADER
4523

Callers 1

CheckIncludeLineFunction · 0.85

Calls 3

_DropCommonSuffixesFunction · 0.85
RepositoryNameMethod · 0.80
splitMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…