aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/DebugInfo/LogicalView/Core/LVSupport.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/DebugInfo/LogicalView/Core/LVSupport.cpp')
-rw-r--r--llvm/lib/DebugInfo/LogicalView/Core/LVSupport.cpp109
1 files changed, 109 insertions, 0 deletions
diff --git a/llvm/lib/DebugInfo/LogicalView/Core/LVSupport.cpp b/llvm/lib/DebugInfo/LogicalView/Core/LVSupport.cpp
index 9fa1f28eb089..42fb1142eb44 100644
--- a/llvm/lib/DebugInfo/LogicalView/Core/LVSupport.cpp
+++ b/llvm/lib/DebugInfo/LogicalView/Core/LVSupport.cpp
@@ -20,6 +20,12 @@ using namespace llvm::logicalview;
#define DEBUG_TYPE "Support"
+namespace {
+// Unique string pool instance used by all logical readers.
+LVStringPool StringPool;
+} // namespace
+LVStringPool &llvm::logicalview::getStringPool() { return StringPool; }
+
// Perform the following transformations to the given 'Path':
// - all characters to lowercase.
// - '\\' into '/' (Platform independent).
@@ -54,3 +60,106 @@ std::string llvm::logicalview::flattenedFilePath(StringRef Path) {
};
return Name;
}
+
+using LexicalEntry = std::pair<size_t, size_t>;
+using LexicalIndexes = SmallVector<LexicalEntry, 10>;
+
+static LexicalIndexes getAllLexicalIndexes(StringRef Name) {
+ if (Name.empty())
+ return {};
+
+ size_t AngleCount = 0;
+ size_t ColonSeen = 0;
+ size_t Current = 0;
+
+ LexicalIndexes Indexes;
+
+#ifndef NDEBUG
+ auto PrintLexicalEntry = [&]() {
+ LexicalEntry Entry = Indexes.back();
+ llvm::dbgs() << formatv(
+ "'{0}:{1}', '{2}'\n", Entry.first, Entry.second,
+ Name.substr(Entry.first, Entry.second - Entry.first + 1));
+ };
+#endif
+
+ size_t Length = Name.size();
+ for (size_t Index = 0; Index < Length; ++Index) {
+ LLVM_DEBUG({
+ llvm::dbgs() << formatv("Index: '{0}', Char: '{1}'\n", Index,
+ Name[Index]);
+ });
+ switch (Name[Index]) {
+ case '<':
+ ++AngleCount;
+ break;
+ case '>':
+ --AngleCount;
+ break;
+ case ':':
+ ++ColonSeen;
+ break;
+ }
+ if (ColonSeen == 2) {
+ if (!AngleCount) {
+ Indexes.push_back(LexicalEntry(Current, Index - 2));
+ Current = Index + 1;
+ LLVM_DEBUG({ PrintLexicalEntry(); });
+ }
+ ColonSeen = 0;
+ continue;
+ }
+ }
+
+ // Store last component.
+ Indexes.push_back(LexicalEntry(Current, Length - 1));
+ LLVM_DEBUG({ PrintLexicalEntry(); });
+ return Indexes;
+}
+
+LVLexicalComponent llvm::logicalview::getInnerComponent(StringRef Name) {
+ if (Name.empty())
+ return {};
+
+ LexicalIndexes Indexes = getAllLexicalIndexes(Name);
+ if (Indexes.size() == 1)
+ return std::make_tuple(StringRef(), Name);
+
+ LexicalEntry BeginEntry = Indexes.front();
+ LexicalEntry EndEntry = Indexes[Indexes.size() - 2];
+ StringRef Outer =
+ Name.substr(BeginEntry.first, EndEntry.second - BeginEntry.first + 1);
+
+ LexicalEntry LastEntry = Indexes.back();
+ StringRef Inner =
+ Name.substr(LastEntry.first, LastEntry.second - LastEntry.first + 1);
+
+ return std::make_tuple(Outer, Inner);
+}
+
+LVStringRefs llvm::logicalview::getAllLexicalComponents(StringRef Name) {
+ if (Name.empty())
+ return {};
+
+ LexicalIndexes Indexes = getAllLexicalIndexes(Name);
+ LVStringRefs Components;
+ for (const LexicalEntry &Entry : Indexes)
+ Components.push_back(
+ Name.substr(Entry.first, Entry.second - Entry.first + 1));
+
+ return Components;
+}
+
+std::string llvm::logicalview::getScopedName(const LVStringRefs &Components,
+ StringRef BaseName) {
+ if (Components.empty())
+ return {};
+ std::string Name(BaseName);
+ raw_string_ostream Stream(Name);
+ if (BaseName.size())
+ Stream << "::";
+ Stream << Components[0];
+ for (LVStringRefs::size_type Index = 1; Index < Components.size(); ++Index)
+ Stream << "::" << Components[Index];
+ return Name;
+}