#pragma once #include "ArrayView.h" #include "Basic/RelationKind.h" #include "Basic/SymbolKind.h" #include "Compiler/Compiler.h" #include "Support/JSON.h" namespace clice::index { struct LocalSourceRange { /// The begin position offset to the source file. uint32_t begin; /// The end position offset to the source file. uint32_t end; }; class SymbolIndex { public: SymbolIndex(void* base, std::size_t size) : base(base), size(size) {} SymbolIndex(SymbolIndex&& other) : base(other.base), size(other.size) { other.base = nullptr; other.size = 0; } ~SymbolIndex() { std::free(base); } struct Symbol; struct Relation : Relative { /// Relation kind. RelationKind kind() const; /// Occurrence range. std::optional range() const; /// Whole symbol range. std::optional symbolRange() const; std::optional symbol() const; }; struct SymbolID : Relative { /// Symbol id. uint64_t id() const; /// Symbol name. llvm::StringRef name() const; }; struct Symbol : SymbolID { /// Symbol kind. SymbolKind kind() const; /// All relations of this symbol. ArrayView relations() const; }; struct Occurrence : Relative { /// Occurrence range. LocalSourceRange range() const; /// Occurrence symbol. Symbol symbol() const; }; /// All symbols in the index. ArrayView symbols() const; /// All occurrences in the index. ArrayView occurrences() const; /// Locate symbols at the given position. void locateSymbols(uint32_t position, llvm::SmallVectorImpl& symbols) const; /// Locate symbol with the given id(usually from another index). Symbol locateSymbol(SymbolID ID) const; json::Value toJSON() const; public: void* base; std::size_t size; }; llvm::DenseMap test(ASTInfo& info); } // namespace clice::index