Skip to content

Commit

Permalink
Moved SymbolOrigin into its own header and implementation file
Browse files Browse the repository at this point in the history
Reviewers: ioeric

Subscribers: mgorny, jkorous, arphaman, kadircet, jdoerfert, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D58773

llvm-svn: 355086
  • Loading branch information
gribozavr committed Feb 28, 2019
1 parent bd5429e commit dba22a3
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 36 deletions.
5 changes: 3 additions & 2 deletions clang-tools-extra/clangd/CMakeLists.txt
Expand Up @@ -62,10 +62,11 @@ add_clang_library(clangDaemon
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
Expand Down
1 change: 1 addition & 0 deletions clang-tools-extra/clangd/CodeComplete.h
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions clang-tools-extra/clangd/index/FileIndex.cpp
Expand Up @@ -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"
Expand Down
10 changes: 0 additions & 10 deletions clang-tools-extra/clangd/index/Index.cpp
Expand Up @@ -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<uint8_t>(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";
Expand Down
25 changes: 1 addition & 24 deletions clang-tools-extra/clangd/index/Index.h
Expand Up @@ -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"
Expand All @@ -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<SymbolOrigin>(static_cast<uint8_t>(A) |
static_cast<uint8_t>(B));
}
inline SymbolOrigin &operator|=(SymbolOrigin &A, SymbolOrigin B) {
return A = A | B;
}
inline SymbolOrigin operator&(SymbolOrigin A, SymbolOrigin B) {
return static_cast<SymbolOrigin>(static_cast<uint8_t>(A) &
static_cast<uint8_t>(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
Expand Down
2 changes: 2 additions & 0 deletions clang-tools-extra/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"
Expand Down
1 change: 1 addition & 0 deletions clang-tools-extra/clangd/index/Merge.cpp
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions clang-tools-extra/clangd/index/Serialization.cpp
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions clang-tools-extra/clangd/index/SymbolCollector.h
Expand Up @@ -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"
Expand Down Expand Up @@ -143,4 +144,5 @@ class SymbolCollector : public index::IndexDataConsumer {

} // namespace clangd
} // namespace clang

#endif
25 changes: 25 additions & 0 deletions clang-tools-extra/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<uint8_t>(O) & 1u << I)
OS << Sigils[I];
return OS;
}

} // namespace clangd
} // namespace clang
47 changes: 47 additions & 0 deletions clang-tools-extra/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 <cstdint>

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<SymbolOrigin>(static_cast<uint8_t>(A) |
static_cast<uint8_t>(B));
}
inline SymbolOrigin &operator|=(SymbolOrigin &A, SymbolOrigin B) {
return A = A | B;
}
inline SymbolOrigin operator&(SymbolOrigin A, SymbolOrigin B) {
return static_cast<SymbolOrigin>(static_cast<uint8_t>(A) &
static_cast<uint8_t>(B));
}

llvm::raw_ostream &operator<<(llvm::raw_ostream &, SymbolOrigin);

} // namespace clangd
} // namespace clang

#endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_SYMBOL_ORIGIN_H
1 change: 1 addition & 0 deletions clang-tools-extra/clangd/index/YAMLSerialization.cpp
Expand Up @@ -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"
Expand Down

0 comments on commit dba22a3

Please sign in to comment.