MCPcopy Index your code
hub / github.com/tensorflow/tfjs / GetHeaderGuardCPPVariable

Function GetHeaderGuardCPPVariable

tfjs-backend-wasm/tools/cpplint.py:1809–1882  ·  view source on GitHub ↗

Returns the CPP variable that should be used as a header guard. Args: filename: The name of a C++ header file. Returns: The CPP variable that should be used as a header guard in the named file.

(filename)

Source from the content-addressed store, hash-verified

1807 return lst
1808
1809def GetHeaderGuardCPPVariable(filename):
1810 """Returns the CPP variable that should be used as a header guard.
1811
1812 Args:
1813 filename: The name of a C++ header file.
1814
1815 Returns:
1816 The CPP variable that should be used as a header guard in the
1817 named file.
1818
1819 """
1820
1821 # Restores original filename in case that cpplint is invoked from Emacs's
1822 # flymake.
1823 filename = re.sub(r'_flymake\.h$', '.h', filename)
1824 filename = re.sub(r'/\.flymake/([^/]*)$', r'/\1', filename)
1825 # Replace 'c++' with 'cpp'.
1826 filename = filename.replace('C++', 'cpp').replace('c++', 'cpp')
1827
1828 fileinfo = FileInfo(filename)
1829 file_path_from_root = fileinfo.RepositoryName()
1830
1831 def FixupPathFromRoot():
1832 if _root_debug:
1833 sys.stderr.write("\n_root fixup, _root = '%s', repository name = '%s'\n"
1834 %(_root, fileinfo.RepositoryName()))
1835
1836 # Process the file path with the --root flag if it was set.
1837 if not _root:
1838 if _root_debug:
1839 sys.stderr.write("_root unspecified\n")
1840 return file_path_from_root
1841
1842 def StripListPrefix(lst, prefix):
1843 # f(['x', 'y'], ['w, z']) -> None (not a valid prefix)
1844 if lst[:len(prefix)] != prefix:
1845 return None
1846 # f(['a, 'b', 'c', 'd'], ['a', 'b']) -> ['c', 'd']
1847 return lst[(len(prefix)):]
1848
1849 # root behavior:
1850 # --root=subdir , lstrips subdir from the header guard
1851 maybe_path = StripListPrefix(PathSplitToList(file_path_from_root),
1852 PathSplitToList(_root))
1853
1854 if _root_debug:
1855 sys.stderr.write(("_root lstrip (maybe_path=%s, file_path_from_root=%s," +
1856 " _root=%s)\n") %(maybe_path, file_path_from_root, _root))
1857
1858 if maybe_path:
1859 return os.path.join(*maybe_path)
1860
1861 # --root=.. , will prepend the outer directory to the header guard
1862 full_path = fileinfo.FullName()
1863 root_abspath = os.path.abspath(_root)
1864
1865 maybe_path = StripListPrefix(PathSplitToList(full_path),
1866 PathSplitToList(root_abspath))

Callers 2

CheckForHeaderGuardFunction · 0.85
CheckStyleFunction · 0.85

Calls 4

RepositoryNameMethod · 0.95
FileInfoClass · 0.85
FixupPathFromRootFunction · 0.85
subMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…