#pragma once #include #include "IncludeGraph.h" #include "AST/RelationKind.h" #include "AST/SourceCode.h" #include "AST/SymbolKind.h" #include "Support/Bitmap.h" namespace clice::index { using Range = LocalSourceRange; using SymbolHash = std::uint64_t; struct Relation { RelationKind kind; std::uint32_t padding = 0; LocalSourceRange range; SymbolHash target_symbol; constexpr void set_definition_range(LocalSourceRange range) { target_symbol = std::bit_cast(range); } constexpr auto definition_range() { return std::bit_cast(target_symbol); } }; struct Occurrence { /// range of this occurrence. Range range; /// SymbolHash target; friend bool operator==(const Occurrence&, const Occurrence&) = default; }; struct FileIndex { llvm::DenseMap> relations; std::vector occurrences; std::array hash(); }; struct Symbol { std::string name; SymbolKind kind; /// All files that referenced this symbol. Bitmap reference_files; friend bool operator==(const Symbol&, const Symbol&) = default; }; using SymbolTable = llvm::DenseMap; struct TUIndex { /// The building timestamp of this file. std::chrono::milliseconds built_at; /// The include information of this file. IncludeGraph graph; SymbolTable symbols; llvm::DenseMap file_indices; FileIndex main_file_index; static TUIndex build(CompilationUnitRef unit); }; } // namespace clice::index