MCPcopy Create free account
hub / github.com/alibaba/GraphScope / GetHeaderGuardCPPVariable

Function GetHeaderGuardCPPVariable

analytical_engine/misc/cpplint.py:2290–2363  ·  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

2288 return lst
2289
2290def GetHeaderGuardCPPVariable(filename):
2291 """Returns the CPP variable that should be used as a header guard.
2292
2293 Args:
2294 filename: The name of a C++ header file.
2295
2296 Returns:
2297 The CPP variable that should be used as a header guard in the
2298 named file.
2299
2300 """
2301
2302 # Restores original filename in case that cpplint is invoked from Emacs's
2303 # flymake.
2304 filename = re.sub(r'_flymake\.h$', '.h', filename)
2305 filename = re.sub(r'/\.flymake/([^/]*)$', r'/\1', filename)
2306 # Replace 'c++' with 'cpp'.
2307 filename = filename.replace('C++', 'cpp').replace('c++', 'cpp')
2308
2309 fileinfo = FileInfo(filename)
2310 file_path_from_root = fileinfo.RepositoryName()
2311
2312 def FixupPathFromRoot():
2313 if _root_debug:
2314 sys.stderr.write("\n_root fixup, _root = '%s', repository name = '%s'\n"
2315 % (_root, fileinfo.RepositoryName()))
2316
2317 # Process the file path with the --root flag if it was set.
2318 if not _root:
2319 if _root_debug:
2320 sys.stderr.write("_root unspecified\n")
2321 return file_path_from_root
2322
2323 def StripListPrefix(lst, prefix):
2324 # f(['x', 'y'], ['w, z']) -> None (not a valid prefix)
2325 if lst[:len(prefix)] != prefix:
2326 return None
2327 # f(['a, 'b', 'c', 'd'], ['a', 'b']) -> ['c', 'd']
2328 return lst[(len(prefix)):]
2329
2330 # root behavior:
2331 # --root=subdir , lstrips subdir from the header guard
2332 maybe_path = StripListPrefix(PathSplitToList(file_path_from_root),
2333 PathSplitToList(_root))
2334
2335 if _root_debug:
2336 sys.stderr.write(("_root lstrip (maybe_path=%s, file_path_from_root=%s," +
2337 " _root=%s)\n") % (maybe_path, file_path_from_root, _root))
2338
2339 if maybe_path:
2340 return os.path.join(*maybe_path)
2341
2342 # --root=.. , will prepend the outer directory to the header guard
2343 full_path = fileinfo.FullName()
2344 root_abspath = os.path.abspath(_root)
2345
2346 maybe_path = StripListPrefix(PathSplitToList(full_path),
2347 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