From eaba0f4c5bb560094e9e4e7a10b78ef80a284f93 Mon Sep 17 00:00:00 2001 From: ykiko Date: Tue, 22 Oct 2024 20:42:16 +0800 Subject: [PATCH] Refactor the definition of `Index`. --- include/Index/Index.def | 67 ++++++++++++++ include/Index/Index.h | 163 ++++++++++++++++++++--------------- include/Index/Indexer.h | 10 ++- include/Index/Loader.h | 8 +- include/Index/Pack.h | 32 ------- include/Support/Reflection.h | 30 +------ include/Support/TypeTraits.h | 52 +++++++++++ src/Index/Index.cpp | 27 +++--- src/Index/Indexer.cpp | 28 +++--- src/Index/Pack.cpp | 148 ------------------------------- unittests/Index/Index.cpp | 8 +- unittests/Index/Pack.cpp | 27 ------ 12 files changed, 256 insertions(+), 344 deletions(-) create mode 100644 include/Index/Index.def delete mode 100644 include/Index/Pack.h create mode 100644 include/Support/TypeTraits.h delete mode 100644 src/Index/Pack.cpp delete mode 100644 unittests/Index/Pack.cpp diff --git a/include/Index/Index.def b/include/Index/Index.def new file mode 100644 index 00000000..27d3b6ec --- /dev/null +++ b/include/Index/Index.def @@ -0,0 +1,67 @@ +#ifndef MAKE_CLANGD_HAPPY + +#include + +template +using Ref = T; + +using llvm::ArrayRef; +using llvm::StringRef; + +struct Position {}; + +enum RelationKind : std::uint32_t {}; + +#endif + +/// If USR is not empty, value is the hash of USR. +/// Otherwise, value is used to represent the kind of builtin symbols. +struct SymbolID { + std::uint64_t value; + StringRef USR; +}; + +struct Location { + Position begin; + Position end; + StringRef file; +}; + +struct Relation { + RelationKind kind; + Ref location; +}; + +struct Symbol { + Ref ID; + /// The name of this symbol. + StringRef name; + /// The document of this symbol. + StringRef document; + ArrayRef relations; +}; + +/// Represents a symbol occurrence in the source code. +struct Occurrence { + Ref symbol; + Ref location; +}; + +struct Index { + /// The version of the index format. + StringRef version; + /// The language of the indexed code, currently only supports "C" and "C++". + StringRef language; + /// The URI of the source file. + StringRef URI; + /// The context of the source file. + StringRef context; + /// The commands used to compile the source file. + ArrayRef commands; + /// All the symbols in the source file. + ArrayRef symbols; + /// All the occurrences in the source file. + ArrayRef occurrences; +}; + +#undef MAKE_CLANGD_HAPPY diff --git a/include/Index/Index.h b/include/Index/Index.h index d1b97468..1f5a1a88 100644 --- a/include/Index/Index.h +++ b/include/Index/Index.h @@ -3,49 +3,18 @@ #include #include -#include +// #include -namespace clice { +namespace clice::index { -struct Symbol; -struct Occurrence; +/// Note that we have two kinds of `Index` definitions. One for collecting data from AST, +/// and the other is used to serialize data to the binary format. The key difference is that +/// one uses pointers and the other uses offsets to store data. All structures that uses ArrayRef +/// or StringRef are defined in `Index.def` so that they could have different definitions in +/// context. -// struct Diagnostic {}; -// struct InlayHint {}; - -/// CSIF stands for "C/C++ Semantic Index Format". -/// It is an efficient binary format for storing the semantic information of C/C++ source code. -/// The main references are [SCIP](https://sourcegraph.com/blog/announcing-scip) and -/// [SemanticDB](https://scalameta.org/docs/semanticdb/specification.html). -struct CSIF { - /// The version of the CSIF format. - llvm::StringRef version; - /// The language of the source code, currently only supports "c" and "c++". - llvm::StringRef language; - /// The URI of the source file. - llvm::StringRef uri; - /// The context of the source file, used to check whether need to re-index the source file. - llvm::StringRef content; - /// The commands used to compile the source file. - llvm::ArrayRef commands; - - /// The symbols in the source file. - llvm::ArrayRef symbols; - /// The occurrences in the source file. - llvm::ArrayRef occurrences; - - ///// The semantic tokens in the source file. - // llvm::ArrayRef semanticTokens; - - // FIXME: - /// The diagnostics in the source file. - // llvm::ArrayRef diagnostics; - /// The inlay hints in the source file. - // llvm::ArrayRef inlayHints; -}; - -/// Note that it's possible to have multiple roles at the same time. -enum class Role { +/// Used to discribe the kind of relation between two symbols. +enum RelationKind : std::uint32_t { Invalid, Declaration, Definition, @@ -81,48 +50,100 @@ enum class Role { Callee, }; -struct Location { - proto::DocumentUri uri; - proto::Range range; +/// Represent a position in the source code, the line and column are 1-based. +struct Position { + std::uint32_t line; + std::uint32_t column; - friend std::strong_ordering operator<=> (const Location& lhs, const Location& rhs) = default; + friend std::strong_ordering operator<=> (const Position&, const Position&) = default; }; -/// If symbol A has a relation to symbol B with role R. -/// For example, `Caller`. Then we say B is a caller of A. -struct Relation { - /// The role of the relation. - Role role; - /// The location of the related symbol. - Location location; +} // namespace clice::index - friend std::strong_ordering operator<=> (const Relation& lhs, const Relation& rhs) = default; +namespace clice::index::in { + +template +using Ref = T; + +using llvm::ArrayRef; +using llvm::StringRef; + +#define MAKE_CLANGD_HAPPY +#include "Index.def" + +inline SymbolID kindToSymbolID(std::uint64_t kind) { + return SymbolID{kind, ""}; +} + +inline SymbolID USRToSymbolID(llvm::StringRef USR) { + return SymbolID{llvm::hash_value(USR), USR}; +} + +inline std::strong_ordering operator<=> (const SymbolID& lhs, const SymbolID& rhs) { + auto cmp = lhs.value <=> rhs.value; + if(cmp != std::strong_ordering::equal) { + return cmp; + } + return lhs.USR.compare(rhs.USR) <=> 0; +} + +inline std::strong_ordering operator<=> (const Location& lhs, const Location& rhs) { + auto cmp = lhs.file.compare(rhs.file); + if(cmp != 0) { + return cmp <=> 0; + } + return std::tuple{lhs.begin, lhs.end} <=> std::tuple{rhs.begin, rhs.end}; }; -struct Symbol { - /// The ID of the symbol. - SymbolID ID; - /// display when hover. - llvm::StringRef document; +} // namespace clice::index::in - // TODO: append more useful information. +namespace llvm { - /// The relations of the symbol. - llvm::ArrayRef relations; +using clice::index::in::kindToSymbolID; +using SymbolID = clice::index::in::SymbolID; + +template <> +struct DenseMapInfo { + inline static SymbolID getEmptyKey() { + static SymbolID EMPTY_KEY = kindToSymbolID(std::numeric_limits::max()); + return EMPTY_KEY; + } + + inline static SymbolID getTombstoneKey() { + static SymbolID TOMBSTONE_KEY = kindToSymbolID(std::numeric_limits::max() - 1); + return TOMBSTONE_KEY; + } + + inline static llvm::hash_code getHashValue(const SymbolID& ID) { + return ID.value; + } + + inline static bool isEqual(const SymbolID& LHS, const SymbolID& RHS) { + return LHS.value == RHS.value && LHS.USR == RHS.USR; + } }; -struct Occurrence { - /// The ID of the symbol. - SymbolID symbol; - /// The range of the occurrence. - Location location; +} // namespace llvm + +namespace clice::index::out { + +/// Because `SymbolID` and `Location` are duplicate referenced by `Relation`, `Symbol` and `Occurrence`, +/// To save space, we use offsets to index them. +template +struct Ref { + std::uint32_t offset; }; -enum BuiltinSymbolKind { - -#define SYMBOL(name, description) name, -#include -#undef SYMBOL +template +struct ArrayRef { + std::uint32_t offset; + std::uint32_t length; }; -} // namespace clice +using StringRef = ArrayRef; + +#define MAKE_CLANGD_HAPPY +#include "Index.def" + +} // namespace clice::index::out + diff --git a/include/Index/Indexer.h b/include/Index/Indexer.h index f7a90ece..1e892bf0 100644 --- a/include/Index/Indexer.h +++ b/include/Index/Indexer.h @@ -3,13 +3,13 @@ #include #include -namespace clice { +namespace clice::index::in { class Indexer { public: Indexer(clang::Sema& sema, clang::syntax::TokenBuffer& tokBuf) : sema(sema), tokBuf(tokBuf) {} - CSIF index(); + Index index(); std::size_t lookup(const clang::NamedDecl* decl); @@ -19,7 +19,9 @@ public: Indexer& addOccurrence(const clang::NamedDecl* decl, clang::SourceRange range); - Indexer& addRelation(const clang::NamedDecl* from, clang::SourceRange range, std::initializer_list roles); + Indexer& addRelation(const clang::NamedDecl* from, + clang::SourceRange range, + std::initializer_list roles); private: clang::Sema& sema; @@ -36,5 +38,5 @@ private: llvm::DenseMap cache; }; -} // namespace clice +} // namespace clice::index::in diff --git a/include/Index/Loader.h b/include/Index/Loader.h index 51b7667c..3ae46dbc 100644 --- a/include/Index/Loader.h +++ b/include/Index/Loader.h @@ -2,11 +2,11 @@ #include -namespace clice { +namespace clice::index::in { class Loader { public: - Loader(CSIF csif, char* data) : csif(csif), data(data) {} + Loader(Index csif, char* data) : csif(csif), data(data) {} const Symbol& locate(Location loc) const { auto iter = std::partition_point(csif.occurrences.begin(), csif.occurrences.end(), [&](const auto& occurrence) { @@ -30,8 +30,8 @@ public: } private: - CSIF csif; + Index csif; char* data; }; -} // namespace clice +} // namespace clice::index::in diff --git a/include/Index/Pack.h b/include/Index/Pack.h deleted file mode 100644 index b079255f..00000000 --- a/include/Index/Pack.h +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include "Index.h" - -namespace clice { - -// We use an efficient way to pack the CSIF structure into a binary format. -// -// The serialization process follows these steps: -// 1. Write the `CSIF` structure directly into the binary buffer. -// 2. For each reference member (e.g., arrays and strings): -// a. Write the referenced data (array elements or string characters) into the buffer. -// b. Replace the pointer in the `CSIF` structure with the offset pointing to the actual data. -// -// Data Layout in the binary buffer: -// | CSIF structure | array offsets | string offsets | array data | string data | -// -// - `CSIF structure`: The first `sizeof(CSIF)` bytes store the `CSIF` structure itself. -// - `array offsets`: Offsets pointing to the actual array data stored later in the buffer. -// - `string offsets`: Offsets pointing to the actual string data stored later in the buffer. -// - `array data`: Contains all array elements, stored with 8-byte alignment to improve access efficiency. -// - `string data`: Contains all string characters, stored sequentially. - -/// Pack the CSIF into a binary buffer. -std::unique_ptr pack(CSIF csif); - -/// Unpack the binary buffer into a CSIF. -/// NOTE: the data should be mutable. when the first load it, -/// We need to replace all offset to actual pointer. -CSIF unpack(char* data); - -} // namespace clice diff --git a/include/Support/Reflection.h b/include/Support/Reflection.h index 62bb5251..0aff8869 100644 --- a/include/Support/Reflection.h +++ b/include/Support/Reflection.h @@ -6,6 +6,8 @@ #include #include +#include + namespace clice::impl { struct Any { @@ -190,32 +192,6 @@ consteval auto enum_max() { return N; } -template -struct replace_cv_ref; - -template -struct replace_cv_ref { - using type = Target&; -}; - -template -struct replace_cv_ref { - using type = Target&&; -}; - -template -struct replace_cv_ref { - using type = const Target&; -}; - -template -struct replace_cv_ref { - using type = const Target&&; -}; - -template -using replace_cv_ref_t = typename replace_cv_ref::type; - } // namespace clice::impl namespace clice::refl { @@ -257,7 +233,7 @@ template struct Record : Ts... { template static void foreach(Object&& object, const Callback& callback) { - (clice::refl::foreach(static_cast>(object), callback), ...); + (clice::refl::foreach(static_cast>(object), callback), ...); } }; diff --git a/include/Support/TypeTraits.h b/include/Support/TypeTraits.h new file mode 100644 index 00000000..b134770d --- /dev/null +++ b/include/Support/TypeTraits.h @@ -0,0 +1,52 @@ +#pragma once + +#include + +namespace clice { + +template +struct replace_cv_ref; + +template +struct replace_cv_ref { + using type = Target&; +}; + +template +struct replace_cv_ref { + using type = Target&&; +}; + +template +struct replace_cv_ref { + using type = const Target&; +}; + +template +struct replace_cv_ref { + using type = const Target&&; +}; + +/// Replace the cv-qualifiers and reference of Source with Target. +/// For example, `replace_cv_ref_t` is `const double&`. +template +using replace_cv_ref_t = typename replace_cv_ref::type; + +template typename Map> +struct tuple_map; + +template typename Map> +struct tuple_map, Map> { + using type = std::tuple::type...>; +}; + +/// Map the types in the tuple to another type with the given template template argument. +template typename Map> +using tuple_map_t = typename tuple_map::type; + +template +struct identity { + using type = T; +}; + +} // namespace clice diff --git a/src/Index/Index.cpp b/src/Index/Index.cpp index 27345ce4..26b85d75 100644 --- a/src/Index/Index.cpp +++ b/src/Index/Index.cpp @@ -1,6 +1,6 @@ #include -namespace clice { +namespace clice::index::in { namespace { @@ -109,7 +109,7 @@ public: bool VisitTagTypeLoc(clang ::TagTypeLoc loc) { auto decl = loc.getTypePtr()->getDecl(); auto location = loc.getNameLoc(); - slab.addOccurrence(decl, location).addRelation(decl, location, {Role::Reference}); + slab.addOccurrence(decl, location).addRelation(decl, location, {RelationKind::Reference}); return true; } @@ -121,7 +121,7 @@ public: case clang::ElaboratedTypeKeyword::Class: case clang::ElaboratedTypeKeyword::Union: case clang::ElaboratedTypeKeyword::Enum: { - slab.addOccurrence(BuiltinSymbolKind::elaborated_type_specifier, keywordLoc); + // slab.addOccurrence(BuiltinSymbolKind::elaborated_type_specifier, keywordLoc); } case clang::ElaboratedTypeKeyword::Typename: { @@ -137,14 +137,14 @@ public: bool VisitTypedefTypeLoc(clang::TypedefTypeLoc loc) { auto decl = loc.getTypePtr()->getDecl(); auto location = loc.getNameLoc(); - slab.addOccurrence(decl, location).addRelation(decl, location, {Role::Reference}); + slab.addOccurrence(decl, location).addRelation(decl, location, {RelationKind::Reference}); return true; } bool VisitUsingTypeLoc(clang::UsingTypeLoc loc) { auto decl = loc.getTypePtr()->getFoundDecl(); auto location = loc.getNameLoc(); - slab.addOccurrence(decl, location).addRelation(decl, location, {Role::Reference}); + slab.addOccurrence(decl, location).addRelation(decl, location, {RelationKind::Reference}); return true; } @@ -178,24 +178,24 @@ public: auto specialized = spec->getSpecializedTemplateOrPartial(); if(specialized.is()) { slab.addOccurrence(CTD, nameLoc) - .addRelation(CTD, nameLoc, {Role::Reference, Role::ImplicitInstantiation}); + .addRelation(CTD, nameLoc, {RelationKind::Reference, RelationKind::ImplicitInstantiation}); } else { auto PSD = specialized.get(); slab.addOccurrence(PSD, nameLoc) - .addRelation(PSD, nameLoc, {Role::Reference, Role::ImplicitInstantiation}) - .addRelation(CTD, nameLoc, {Role::Reference}); + .addRelation(PSD, nameLoc, {RelationKind::Reference, RelationKind::ImplicitInstantiation}) + .addRelation(CTD, nameLoc, {RelationKind::Reference}); } } else { // full specialization slab.addOccurrence(spec, nameLoc) - .addRelation(spec, nameLoc, {Role::Reference, Role::FullSpecialization}); + .addRelation(spec, nameLoc, {RelationKind::Reference, RelationKind::FullSpecialization}); } } } else if(auto TATD = llvm::dyn_cast(decl)) { // Beacuse type alias template is not allowed to have partial and full specialization, // So we do notin slab.addOccurrence(TATD, nameLoc) - .addRelation(TATD, nameLoc, {Role::Reference, Role::ImplicitInstantiation}); + .addRelation(TATD, nameLoc, {RelationKind::Reference, RelationKind::ImplicitInstantiation}); } return true; } @@ -211,8 +211,8 @@ private: } // namespace -CSIF Indexer::index() { - CSIF csif; +Index Indexer::index() { + Index csif; SymbolCollector collector(*this, sema.getASTContext()); collector.TraverseAST(sema.getASTContext()); @@ -227,6 +227,7 @@ CSIF Indexer::index() { llvm::sort(symbols, [](const Symbol& lhs, const Symbol& rhs) { return lhs.ID < rhs.ID; }); + llvm::sort(occurrences, [](const Occurrence& lhs, const Occurrence& rhs) { return lhs.location < rhs.location; }); @@ -239,4 +240,4 @@ CSIF Indexer::index() { return csif; }; -} // namespace clice +} // namespace clice::index::in diff --git a/src/Index/Indexer.cpp b/src/Index/Indexer.cpp index 0568a815..e8873868 100644 --- a/src/Index/Indexer.cpp +++ b/src/Index/Indexer.cpp @@ -1,16 +1,16 @@ #include #include -namespace clice { +namespace clice::index::in { namespace { Location toRange(clang::SourceRange range, clang::syntax::TokenBuffer& tokBuf) { auto& srcMgr = tokBuf.sourceManager(); Location location{}; - location.uri = srcMgr.getFilename(range.getBegin()); + location.file = srcMgr.getFilename(range.getBegin()); /// It's impossible that a range has crossed multiple files. - assert(location.uri == srcMgr.getFilename(range.getEnd())); + assert(location.file == srcMgr.getFilename(range.getEnd())); if(range.getBegin().isMacroID() || range.getEnd().isMacroID()) { range.dump(srcMgr); @@ -25,11 +25,11 @@ Location toRange(clang::SourceRange range, clang::syntax::TokenBuffer& tokBuf) { std::terminate(); } - location.range.start.line = srcMgr.getPresumedLineNumber(begin->location()); - location.range.start.character = srcMgr.getPresumedColumnNumber(begin->location()); + location.begin.line = srcMgr.getPresumedLineNumber(begin->location()); + location.begin.column = srcMgr.getPresumedColumnNumber(begin->location()); - location.range.end.line = srcMgr.getPresumedLineNumber(end->endLocation()); - location.range.end.character = srcMgr.getPresumedColumnNumber(end->endLocation()); + location.end.line = srcMgr.getPresumedLineNumber(end->endLocation()); + location.end.column = srcMgr.getPresumedColumnNumber(end->endLocation()); return location; } @@ -51,16 +51,16 @@ Indexer& Indexer::addSymbol(const clang::NamedDecl* decl) { llvm::SmallString<128> USR; clang::index::generateUSRForDecl(decl, USR); - if(!symbolIndex.contains(SymbolID::fromUSR(USR))) { - auto ID = SymbolID::fromUSR(saver.save(USR.str())); + if(!symbolIndex.contains(USRToSymbolID(USR))) { + auto ID = USRToSymbolID(saver.save(USR.str())); symbols.emplace_back(ID); + Symbol symbol; symbols.back().document = saver.save(decl->getNameAsString()); - cache.try_emplace(decl, symbols.size() - 1); symbolIndex.try_emplace(ID, symbols.size() - 1); relations.emplace_back(); } else { - cache.try_emplace(decl, symbolIndex[SymbolID::fromUSR(USR)]); + cache.try_emplace(decl, symbolIndex[USRToSymbolID(USR)]); } return *this; @@ -82,14 +82,14 @@ Indexer& Indexer::addOccurrence(int Kind, clang::SourceLocation loc) { return *this; } - auto ID = SymbolID::fromKind(Kind); + auto ID = kindToSymbolID(Kind); occurrences.emplace_back(Occurrence{ID, toRange(loc, tokBuf)}); return *this; } Indexer& Indexer::addRelation(const clang::NamedDecl* from, clang::SourceRange range, - std::initializer_list roles) { + std::initializer_list roles) { if(range.isInvalid()) { return *this; } @@ -102,4 +102,4 @@ Indexer& Indexer::addRelation(const clang::NamedDecl* from, return *this; } -} // namespace clice +} // namespace clice::index::in diff --git a/src/Index/Pack.cpp b/src/Index/Pack.cpp deleted file mode 100644 index 7f34f747..00000000 --- a/src/Index/Pack.cpp +++ /dev/null @@ -1,148 +0,0 @@ -#include -#include - -namespace clice { - -namespace { - -// FIXME: figure out the influence of alignment, padding and endianness. -// Add some tests to verify the correctness of the implementation. - -template -constexpr bool is_array_ref_v = false; - -template -constexpr bool is_array_ref_v> = true; - -static_assert(std::is_trivially_copyable_v, "CSIF must be trivially copyable"); -static_assert(sizeof(std::uint64_t) == sizeof(void*), "std::uint64_t must be the same size as void*"); - -struct Metadata { - CSIF csif; - std::uint64_t arrayOffset; - std::uint64_t stringOffset; -}; - -class Encoder { -public: - void encode(llvm::StringRef& string) { - std::size_t offset = stringData.size(); - stringData.insert(stringData.end(), string.begin(), string.end()); - stringData.push_back('\0'); - // modify pointer to offset - string = llvm::StringRef(reinterpret_cast(offset), string.size()); - } - - template - void encode(llvm::ArrayRef& array) { - std::size_t offset = arrayData.size(); - arrayData.reserve(arrayData.size() + array.size() * sizeof(T)); - for(auto elem: array) { - // write the element of the array - encodeMemberRef(elem); - char* begin = reinterpret_cast(&elem); - arrayData.insert(arrayData.end(), begin, begin + sizeof(T)); - } - // modify pointer to offset - array = llvm::ArrayRef(reinterpret_cast(offset), array.size()); - } - - template - void encodeMemberRef(T& data) { - static_assert(!std::is_const_v); - if constexpr(clice::refl::Reflectable) { - refl::foreach(data, [&](std::string_view, Field& field) { - if constexpr(is_array_ref_v) { - encode(field); - } - }); - } else if constexpr(is_array_ref_v) { - encode(data); - } - } - - std::unique_ptr pack(CSIF csif) { - // calculate size - std::size_t size = sizeof(Metadata) + arrayData.size() + stringData.size(); - std::unique_ptr data(new char[size]); - - // fill metadata - Metadata metadata{csif}; - encodeMemberRef(metadata.csif); - metadata.arrayOffset = sizeof(Metadata); - metadata.stringOffset = sizeof(Metadata) + arrayData.size(); - - // write metadata - std::memcpy(data.get(), &metadata, sizeof(Metadata)); - - // write arrayData and stringData - std::size_t offset = sizeof(Metadata); - std::memcpy(data.get() + offset, arrayData.data(), arrayData.size()); - offset += arrayData.size(); - std::memcpy(data.get() + offset, stringData.data(), stringData.size()); - - return data; - } - -private: - std::vector arrayData; - std::vector stringData; -}; - -class Decoder { -public: - void decode(llvm::StringRef& string) { - string = llvm::StringRef(data + stringOffset, string.size()); - } - - template - void decode(llvm::ArrayRef& array) { - array = llvm::ArrayRef(reinterpret_cast(data + arrayOffset), array.size()); - for(auto& elem: array) { - decodeMemberRef(const_cast(elem)); - } - } - - template - void decodeMemberRef(T& data) { - static_assert(!std::is_const_v); - if constexpr(clice::refl::Reflectable) { - refl::foreach(data, [&](std::string_view, Field& field) { - if constexpr(is_array_ref_v) { - decode(field); - } - }); - } else if constexpr(is_array_ref_v) { - decode(data); - } - } - - CSIF unpack(char* data) { - Metadata metadata; - std::memcpy(&metadata, data, sizeof(Metadata)); - this->data = data; - this->arrayOffset = metadata.arrayOffset; - this->stringOffset = metadata.stringOffset; - decodeMemberRef(metadata.csif); - return metadata.csif; - } - -private: - char* data; - std::size_t arrayOffset; - std::size_t stringOffset; -}; - -} // namespace - -std::unique_ptr pack(CSIF csif) { - Encoder encoder; - return encoder.pack(csif); -} - -CSIF unpack(char* data) { - Decoder decoder; - return decoder.unpack(data); -} - -} // namespace clice diff --git a/unittests/Index/Index.cpp b/unittests/Index/Index.cpp index 7b40fafb..d58ecb12 100644 --- a/unittests/Index/Index.cpp +++ b/unittests/Index/Index.cpp @@ -19,7 +19,7 @@ TEST(clice, Index) { foreachFile("Index", [](llvm::StringRef filepath, llvm::StringRef content) { Compiler compiler("main.cpp", content, compileArgs); compiler.buildAST(); - Indexer slab(compiler.sema(), compiler.tokBuf()); + index::in::Indexer slab(compiler.sema(), compiler.tokBuf()); auto csif = slab.index(); auto value = json::serialize(csif); std::error_code EC; @@ -30,9 +30,9 @@ TEST(clice, Index) { // llvm::outs() << value << "\n"; if(filepath.ends_with("ClassTemplate.cpp")) { - Loader loader(csif, nullptr); - Location location; - location.range = {14, 1, 14, 2}; + index::in::Loader loader(csif, nullptr); + index::in::Location location; + location = {14, 1, 14, 2}; auto& sym = loader.locate(location); llvm::outs() << sym.document << "\n"; } diff --git a/unittests/Index/Pack.cpp b/unittests/Index/Pack.cpp deleted file mode 100644 index 94d1541d..00000000 --- a/unittests/Index/Pack.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include -#include - -namespace { - -using namespace clice; - -TEST(clice, pack) { - CSIF csif; - csif.version = "0.0.1"; - auto data = pack(csif); - - auto result = unpack(data.get()); - EXPECT_EQ(csif.version, result.version); - - std::vector x; - x.emplace_back(1); -} - -consteval void f(){ - auto p = &f; - p(); -} - - - -} // namespace