Index: clangd/CMakeLists.txt =================================================================== --- clangd/CMakeLists.txt +++ clangd/CMakeLists.txt @@ -62,10 +62,11 @@ index/IndexAction.cpp index/MemIndex.cpp index/Merge.cpp - index/SymbolID.cpp - index/SymbolLocation.cpp index/Serialization.cpp index/SymbolCollector.cpp + index/SymbolID.cpp + index/SymbolLocation.cpp + index/SymbolOrigin.cpp index/YAMLSerialization.cpp index/dex/Dex.cpp Index: clangd/CodeComplete.h =================================================================== --- clangd/CodeComplete.h +++ clangd/CodeComplete.h @@ -21,6 +21,7 @@ #include "Path.h" #include "Protocol.h" #include "index/Index.h" +#include "index/SymbolOrigin.h" #include "clang/Frontend/PrecompiledPreamble.h" #include "clang/Sema/CodeCompleteConsumer.h" #include "clang/Sema/CodeCompleteOptions.h" Index: clangd/index/FileIndex.cpp =================================================================== --- clangd/index/FileIndex.cpp +++ clangd/index/FileIndex.cpp @@ -14,6 +14,7 @@ #include "index/Index.h" #include "index/MemIndex.h" #include "index/Merge.h" +#include "index/SymbolOrigin.h" #include "index/dex/Dex.h" #include "clang/Index/IndexingAction.h" #include "clang/Lex/MacroInfo.h" Index: clangd/index/Index.h =================================================================== --- clangd/index/Index.h +++ clangd/index/Index.h @@ -12,6 +12,7 @@ #include "ExpectedTypes.h" #include "SymbolID.h" #include "SymbolLocation.h" +#include "SymbolOrigin.h" #include "clang/Index/IndexSymbol.h" #include "clang/Lex/Lexer.h" #include "llvm/ADT/DenseMap.h" @@ -31,30 +32,6 @@ namespace clang { namespace clangd { -// Describes the source of information about a symbol. -// Mainly useful for debugging, e.g. understanding code completion reuslts. -// This is a bitfield as information can be combined from several sources. -enum class SymbolOrigin : uint8_t { - Unknown = 0, - AST = 1 << 0, // Directly from the AST (indexes should not set this). - Dynamic = 1 << 1, // From the dynamic index of opened files. - Static = 1 << 2, // From the static, externally-built index. - Merge = 1 << 3, // A non-trivial index merge was performed. - // Remaining bits reserved for index implementations. -}; -inline SymbolOrigin operator|(SymbolOrigin A, SymbolOrigin B) { - return static_cast(static_cast(A) | - static_cast(B)); -} -inline SymbolOrigin &operator|=(SymbolOrigin &A, SymbolOrigin B) { - return A = A | B; -} -inline SymbolOrigin operator&(SymbolOrigin A, SymbolOrigin B) { - return static_cast(static_cast(A) & - static_cast(B)); -} -raw_ostream &operator<<(raw_ostream &, SymbolOrigin); - // The class presents a C++ symbol, e.g. class, function. // // WARNING: Symbols do not own much of their underlying data - typically strings Index: clangd/index/Index.cpp =================================================================== --- clangd/index/Index.cpp +++ clangd/index/Index.cpp @@ -16,16 +16,6 @@ namespace clang { namespace clangd { -llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, SymbolOrigin O) { - if (O == SymbolOrigin::Unknown) - return OS << "unknown"; - constexpr static char Sigils[] = "ADSM4567"; - for (unsigned I = 0; I < sizeof(Sigils); ++I) - if (static_cast(O) & 1u << I) - OS << Sigils[I]; - return OS; -} - llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, Symbol::SymbolFlag F) { if (F == Symbol::None) return OS << "None"; Index: clangd/index/IndexAction.cpp =================================================================== --- clangd/index/IndexAction.cpp +++ clangd/index/IndexAction.cpp @@ -1,4 +1,6 @@ #include "IndexAction.h" + +#include "index/SymbolOrigin.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Index/IndexDataConsumer.h" #include "clang/Index/IndexingAction.h" Index: clangd/index/Merge.cpp =================================================================== --- clangd/index/Merge.cpp +++ clangd/index/Merge.cpp @@ -10,6 +10,7 @@ #include "Logger.h" #include "Trace.h" #include "index/SymbolLocation.h" +#include "index/SymbolOrigin.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSet.h" Index: clangd/index/Serialization.cpp =================================================================== --- clangd/index/Serialization.cpp +++ clangd/index/Serialization.cpp @@ -10,6 +10,7 @@ #include "Logger.h" #include "RIFF.h" #include "SymbolLocation.h" +#include "SymbolOrigin.h" #include "Trace.h" #include "dex/Dex.h" #include "llvm/Support/Compression.h" Index: clangd/index/SymbolCollector.h =================================================================== --- clangd/index/SymbolCollector.h +++ clangd/index/SymbolCollector.h @@ -10,6 +10,7 @@ #include "CanonicalIncludes.h" #include "Index.h" +#include "SymbolOrigin.h" #include "clang/AST/ASTContext.h" #include "clang/AST/Decl.h" #include "clang/Basic/SourceLocation.h" @@ -143,4 +144,5 @@ } // namespace clangd } // namespace clang + #endif Index: clangd/index/SymbolOrigin.h =================================================================== --- clangd/index/SymbolOrigin.h +++ clangd/index/SymbolOrigin.h @@ -0,0 +1,47 @@ +//===--- SymbolOrigin.h ------------------------------------------*- C++-*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_SYMBOL_ORIGIN_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_SYMBOL_ORIGIN_H + +#include "llvm/Support/raw_ostream.h" +#include + +namespace clang { +namespace clangd { + +// Describes the source of information about a symbol. +// Mainly useful for debugging, e.g. understanding code completion reuslts. +// This is a bitfield as information can be combined from several sources. +enum class SymbolOrigin : uint8_t { + Unknown = 0, + AST = 1 << 0, // Directly from the AST (indexes should not set this). + Dynamic = 1 << 1, // From the dynamic index of opened files. + Static = 1 << 2, // From the static, externally-built index. + Merge = 1 << 3, // A non-trivial index merge was performed. + // Remaining bits reserved for index implementations. +}; + +inline SymbolOrigin operator|(SymbolOrigin A, SymbolOrigin B) { + return static_cast(static_cast(A) | + static_cast(B)); +} +inline SymbolOrigin &operator|=(SymbolOrigin &A, SymbolOrigin B) { + return A = A | B; +} +inline SymbolOrigin operator&(SymbolOrigin A, SymbolOrigin B) { + return static_cast(static_cast(A) & + static_cast(B)); +} + +llvm::raw_ostream &operator<<(llvm::raw_ostream &, SymbolOrigin); + +} // namespace clangd +} // namespace clang + +#endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_SYMBOL_ORIGIN_H Index: clangd/index/SymbolOrigin.cpp =================================================================== --- clangd/index/SymbolOrigin.cpp +++ clangd/index/SymbolOrigin.cpp @@ -0,0 +1,25 @@ +//===--- SymbolOrigin.cpp ----------------------------------------*- C++-*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "SymbolOrigin.h" + +namespace clang { +namespace clangd { + +llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, SymbolOrigin O) { + if (O == SymbolOrigin::Unknown) + return OS << "unknown"; + constexpr static char Sigils[] = "ADSM4567"; + for (unsigned I = 0; I < sizeof(Sigils); ++I) + if (static_cast(O) & 1u << I) + OS << Sigils[I]; + return OS; +} + +} // namespace clangd +} // namespace clang Index: clangd/index/YAMLSerialization.cpp =================================================================== --- clangd/index/YAMLSerialization.cpp +++ clangd/index/YAMLSerialization.cpp @@ -15,6 +15,7 @@ #include "Index.h" #include "Serialization.h" #include "SymbolLocation.h" +#include "SymbolOrigin.h" #include "Trace.h" #include "dex/Dex.h" #include "llvm/ADT/Optional.h"