123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- namespace llvm {
- class CompileUnit;
- struct DeclMapInfo;
- class CachedPathResolver {
- public:
-
-
- StringRef resolve(const std::string &Path,
- NonRelocatableStringpool &StringPool) {
- StringRef FileName = sys::path::filename(Path);
- StringRef ParentPath = sys::path::parent_path(Path);
-
-
- if (!ResolvedPaths.count(ParentPath)) {
- SmallString<256> RealPath;
- sys::fs::real_path(ParentPath, RealPath);
- ResolvedPaths.insert(
- {ParentPath, std::string(RealPath.c_str(), RealPath.size())});
- }
-
- SmallString<256> ResolvedPath(ResolvedPaths[ParentPath]);
- sys::path::append(ResolvedPath, FileName);
- return StringPool.internString(ResolvedPath);
- }
- private:
- StringMap<std::string> ResolvedPaths;
- };
- class DeclContext {
- public:
- using Map = DenseSet<DeclContext *, DeclMapInfo>;
- DeclContext() : DefinedInClangModule(0), Parent(*this) {}
- DeclContext(unsigned Hash, uint32_t Line, uint32_t ByteSize, uint16_t Tag,
- StringRef Name, StringRef File, const DeclContext &Parent,
- DWARFDie LastSeenDIE = DWARFDie(), unsigned CUId = 0)
- : QualifiedNameHash(Hash), Line(Line), ByteSize(ByteSize), Tag(Tag),
- DefinedInClangModule(0), Name(Name), File(File), Parent(Parent),
- LastSeenDIE(LastSeenDIE), LastSeenCompileUnitID(CUId) {}
- uint32_t getQualifiedNameHash() const { return QualifiedNameHash; }
- bool setLastSeenDIE(CompileUnit &U, const DWARFDie &Die);
- void setHasCanonicalDIE() { HasCanonicalDIE = true; }
- bool hasCanonicalDIE() const { return HasCanonicalDIE; }
- uint32_t getCanonicalDIEOffset() const { return CanonicalDIEOffset; }
- void setCanonicalDIEOffset(uint32_t Offset) { CanonicalDIEOffset = Offset; }
- bool isDefinedInClangModule() const { return DefinedInClangModule; }
- void setDefinedInClangModule(bool Val) { DefinedInClangModule = Val; }
- uint16_t getTag() const { return Tag; }
- private:
- friend DeclMapInfo;
- unsigned QualifiedNameHash = 0;
- uint32_t Line = 0;
- uint32_t ByteSize = 0;
- uint16_t Tag = dwarf::DW_TAG_compile_unit;
- unsigned DefinedInClangModule : 1;
- StringRef Name;
- StringRef File;
- const DeclContext &Parent;
- DWARFDie LastSeenDIE;
- uint32_t LastSeenCompileUnitID = 0;
- std::atomic<uint32_t> CanonicalDIEOffset = {0};
- bool HasCanonicalDIE = false;
- };
- class DeclContextTree {
- public:
-
-
-
-
-
-
-
-
-
-
-
- PointerIntPair<DeclContext *, 1> getChildDeclContext(DeclContext &Context,
- const DWARFDie &DIE,
- CompileUnit &Unit,
- bool InClangModule);
- DeclContext &getRoot() { return Root; }
- private:
- BumpPtrAllocator Allocator;
- DeclContext Root;
- DeclContext::Map Contexts;
-
-
- using ResolvedPathsMap = DenseMap<std::pair<unsigned, unsigned>, StringRef>;
- ResolvedPathsMap ResolvedPaths;
-
- CachedPathResolver PathResolver;
-
- NonRelocatableStringpool StringPool;
- StringRef getResolvedPath(CompileUnit &CU, unsigned FileNum,
- const DWARFDebugLine::LineTable &LineTable);
- };
- struct DeclMapInfo : private DenseMapInfo<DeclContext *> {
- using DenseMapInfo<DeclContext *>::getEmptyKey;
- using DenseMapInfo<DeclContext *>::getTombstoneKey;
- static unsigned getHashValue(const DeclContext *Ctxt) {
- return Ctxt->QualifiedNameHash;
- }
- static bool isEqual(const DeclContext *LHS, const DeclContext *RHS) {
- if (RHS == getEmptyKey() || RHS == getTombstoneKey())
- return RHS == LHS;
- return LHS->QualifiedNameHash == RHS->QualifiedNameHash &&
- LHS->Line == RHS->Line && LHS->ByteSize == RHS->ByteSize &&
- LHS->Name.data() == RHS->Name.data() &&
- LHS->File.data() == RHS->File.data() &&
- LHS->Parent.QualifiedNameHash == RHS->Parent.QualifiedNameHash;
- }
- };
- }
|