CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
92 lines
3.2 KiB
C++
92 lines
3.2 KiB
C++
//===--- SerializablePathCollection.cpp -- Index of paths -------*- C++ -*-===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "clang/IndexSerialization/SerializablePathCollection.h"
|
|
#include "llvm/Support/Path.h"
|
|
|
|
using namespace llvm;
|
|
using namespace clang;
|
|
using namespace clang::index;
|
|
|
|
StringPool::StringOffsetSize StringPool::add(StringRef Str) {
|
|
const std::size_t Offset = Buffer.size();
|
|
Buffer += Str;
|
|
return StringPool::StringOffsetSize(Offset, Str.size());
|
|
}
|
|
|
|
size_t PathPool::addFilePath(RootDirKind Root,
|
|
const StringPool::StringOffsetSize &Dir,
|
|
StringRef Filename) {
|
|
FilePaths.emplace_back(DirPath(Root, Dir), Paths.add(Filename));
|
|
return FilePaths.size() - 1;
|
|
}
|
|
|
|
StringPool::StringOffsetSize PathPool::addDirPath(StringRef Dir) {
|
|
return Paths.add(Dir);
|
|
}
|
|
|
|
llvm::ArrayRef<PathPool::FilePath> PathPool::getFilePaths() const {
|
|
return FilePaths;
|
|
}
|
|
|
|
StringRef PathPool::getPaths() const { return Paths.getBuffer(); }
|
|
|
|
SerializablePathCollection::SerializablePathCollection(
|
|
StringRef CurrentWorkDir, StringRef SysRoot, llvm::StringRef OutputFile)
|
|
: WorkDir(CurrentWorkDir),
|
|
SysRoot(llvm::sys::path::parent_path(SysRoot).empty() ? StringRef()
|
|
: SysRoot),
|
|
WorkDirPath(Paths.addDirPath(WorkDir)),
|
|
SysRootPath(Paths.addDirPath(SysRoot)),
|
|
OutputFilePath(Paths.addDirPath(OutputFile)) {}
|
|
|
|
size_t SerializablePathCollection::tryStoreFilePath(FileEntryRef FE) {
|
|
auto FileIt = UniqueFiles.find(FE);
|
|
if (FileIt != UniqueFiles.end())
|
|
return FileIt->second;
|
|
|
|
const auto Dir = tryStoreDirPath(sys::path::parent_path(FE.getName()));
|
|
const auto FileIdx =
|
|
Paths.addFilePath(Dir.Root, Dir.Path, sys::path::filename(FE.getName()));
|
|
|
|
UniqueFiles.try_emplace(FE, FileIdx);
|
|
return FileIdx;
|
|
}
|
|
|
|
PathPool::DirPath SerializablePathCollection::tryStoreDirPath(StringRef Dir) {
|
|
// We don't want to strip separator if Dir is "/" - so we check size > 1.
|
|
while (Dir.size() > 1 && llvm::sys::path::is_separator(Dir.back()))
|
|
Dir = Dir.drop_back();
|
|
|
|
auto DirIt = UniqueDirs.find(Dir);
|
|
if (DirIt != UniqueDirs.end())
|
|
return DirIt->second;
|
|
|
|
const std::string OrigDir = Dir.str();
|
|
|
|
PathPool::RootDirKind Root = PathPool::RootDirKind::Regular;
|
|
if (!SysRoot.empty() && Dir.starts_with(SysRoot) &&
|
|
llvm::sys::path::is_separator(Dir[SysRoot.size()])) {
|
|
Root = PathPool::RootDirKind::SysRoot;
|
|
Dir = Dir.drop_front(SysRoot.size());
|
|
} else if (!WorkDir.empty() && Dir.starts_with(WorkDir) &&
|
|
llvm::sys::path::is_separator(Dir[WorkDir.size()])) {
|
|
Root = PathPool::RootDirKind::CurrentWorkDir;
|
|
Dir = Dir.drop_front(WorkDir.size());
|
|
}
|
|
|
|
if (Root != PathPool::RootDirKind::Regular) {
|
|
while (!Dir.empty() && llvm::sys::path::is_separator(Dir.front()))
|
|
Dir = Dir.drop_front();
|
|
}
|
|
|
|
PathPool::DirPath Result(Root, Paths.addDirPath(Dir));
|
|
UniqueDirs.try_emplace(OrigDir, Result);
|
|
return Result;
|
|
}
|