Files
TheRock/compiler/amd-llvm/clang-tools-extra/clang-include-fixer/find-all-symbols/SymbolInfo.cpp
T
derek.holloway 7502bf64a4
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
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

134 lines
4.4 KiB
C++

//===-- SymbolInfo.cpp - Symbol Info ----------------------------*- 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 "SymbolInfo.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/YAMLTraits.h"
#include "llvm/Support/raw_ostream.h"
using ContextType = clang::find_all_symbols::SymbolInfo::ContextType;
using clang::find_all_symbols::SymbolInfo;
using clang::find_all_symbols::SymbolAndSignals;
using SymbolKind = clang::find_all_symbols::SymbolInfo::SymbolKind;
LLVM_YAML_IS_DOCUMENT_LIST_VECTOR(SymbolAndSignals)
LLVM_YAML_IS_SEQUENCE_VECTOR(SymbolInfo::Context)
namespace llvm {
namespace yaml {
template <> struct MappingTraits<SymbolAndSignals> {
static void mapping(IO &io, SymbolAndSignals &Symbol) {
io.mapRequired("Name", Symbol.Symbol.Name);
io.mapRequired("Contexts", Symbol.Symbol.Contexts);
io.mapRequired("FilePath", Symbol.Symbol.FilePath);
io.mapRequired("Type", Symbol.Symbol.Type);
io.mapRequired("Seen", Symbol.Signals.Seen);
io.mapRequired("Used", Symbol.Signals.Used);
}
};
template <> struct ScalarEnumerationTraits<ContextType> {
static void enumeration(IO &io, ContextType &value) {
io.enumCase(value, "Record", ContextType::Record);
io.enumCase(value, "Namespace", ContextType::Namespace);
io.enumCase(value, "EnumDecl", ContextType::EnumDecl);
}
};
template <> struct ScalarEnumerationTraits<SymbolKind> {
static void enumeration(IO &io, SymbolKind &value) {
io.enumCase(value, "Variable", SymbolKind::Variable);
io.enumCase(value, "Function", SymbolKind::Function);
io.enumCase(value, "Class", SymbolKind::Class);
io.enumCase(value, "TypedefName", SymbolKind::TypedefName);
io.enumCase(value, "EnumDecl", SymbolKind::EnumDecl);
io.enumCase(value, "EnumConstantDecl", SymbolKind::EnumConstantDecl);
io.enumCase(value, "Macro", SymbolKind::Macro);
io.enumCase(value, "Unknown", SymbolKind::Unknown);
}
};
template <> struct MappingTraits<SymbolInfo::Context> {
static void mapping(IO &io, SymbolInfo::Context &Context) {
io.mapRequired("ContextType", Context.first);
io.mapRequired("ContextName", Context.second);
}
};
} // namespace yaml
} // namespace llvm
namespace clang {
namespace find_all_symbols {
SymbolInfo::SymbolInfo(llvm::StringRef Name, SymbolKind Type,
llvm::StringRef FilePath,
const std::vector<Context> &Contexts)
: Name(Name), Type(Type), FilePath(FilePath), Contexts(Contexts) {}
bool SymbolInfo::operator==(const SymbolInfo &Symbol) const {
return std::tie(Name, Type, FilePath, Contexts) ==
std::tie(Symbol.Name, Symbol.Type, Symbol.FilePath, Symbol.Contexts);
}
bool SymbolInfo::operator<(const SymbolInfo &Symbol) const {
return std::tie(Name, Type, FilePath, Contexts) <
std::tie(Symbol.Name, Symbol.Type, Symbol.FilePath, Symbol.Contexts);
}
std::string SymbolInfo::getQualifiedName() const {
std::string QualifiedName = Name;
for (const auto &Context : Contexts) {
if (Context.first == ContextType::EnumDecl)
continue;
QualifiedName = Context.second + "::" + QualifiedName;
}
return QualifiedName;
}
SymbolInfo::Signals &SymbolInfo::Signals::operator+=(const Signals &RHS) {
Seen += RHS.Seen;
Used += RHS.Used;
return *this;
}
SymbolInfo::Signals SymbolInfo::Signals::operator+(const Signals &RHS) const {
Signals Result = *this;
Result += RHS;
return Result;
}
bool SymbolInfo::Signals::operator==(const Signals &RHS) const {
return std::tie(Seen, Used) == std::tie(RHS.Seen, RHS.Used);
}
bool SymbolAndSignals::operator==(const SymbolAndSignals& RHS) const {
return std::tie(Symbol, Signals) == std::tie(RHS.Symbol, RHS.Signals);
}
bool WriteSymbolInfosToStream(llvm::raw_ostream &OS,
const SymbolInfo::SignalMap &Symbols) {
llvm::yaml::Output yout(OS);
for (const auto &Symbol : Symbols) {
SymbolAndSignals S{Symbol.first, Symbol.second};
yout << S;
}
return true;
}
std::vector<SymbolAndSignals> ReadSymbolInfosFromYAML(llvm::StringRef Yaml) {
std::vector<SymbolAndSignals> Symbols;
llvm::yaml::Input yin(Yaml);
yin >> Symbols;
return Symbols;
}
} // namespace find_all_symbols
} // namespace clang