[clangd] Make SymbolOrigin an enum class, rather than a plain enum.

I never intended to define namespace pollution like clangd::AST, clangd::Unknown
etc. Oops!

llvm-svn: 336431
This commit is contained in:
Sam McCall 2018-07-06 11:50:49 +00:00
parent 492cdfc5fb
commit 4e5742a479
5 changed files with 24 additions and 16 deletions

View File

@ -268,8 +268,7 @@ struct CodeCompletionBuilder {
: ASTCtx(ASTCtx), ExtractDocumentation(Opts.IncludeComments) {
add(C, SemaCCS);
if (C.SemaResult) {
Completion.Origin =
static_cast<SymbolOrigin>(Completion.Origin | SymbolOrigin::AST);
Completion.Origin |= SymbolOrigin::AST;
Completion.Name = llvm::StringRef(SemaCCS->getTypedText());
if (Completion.Scope.empty())
if (C.SemaResult->Kind == CodeCompletionResult::RK_Declaration)
@ -281,8 +280,7 @@ struct CodeCompletionBuilder {
toCompletionItemKind(C.SemaResult->Kind, C.SemaResult->Declaration);
}
if (C.IndexResult) {
Completion.Origin =
static_cast<SymbolOrigin>(Completion.Origin | C.IndexResult->Origin);
Completion.Origin |= C.IndexResult->Origin;
if (Completion.Scope.empty())
Completion.Scope = C.IndexResult->Scope;
if (Completion.Kind == CompletionItemKind::Missing)
@ -1156,17 +1154,18 @@ private:
else
return;
SymbolOrigin Origin = SymbolOrigin::Unknown;
bool FromIndex = false;
for (const auto &Candidate : Bundle) {
if (Candidate.IndexResult) {
Quality.merge(*Candidate.IndexResult);
Relevance.merge(*Candidate.IndexResult);
Origin =
static_cast<SymbolOrigin>(Origin | Candidate.IndexResult->Origin);
Origin |= Candidate.IndexResult->Origin;
FromIndex = true;
}
if (Candidate.SemaResult) {
Quality.merge(*Candidate.SemaResult);
Relevance.merge(*Candidate.SemaResult);
Origin = static_cast<SymbolOrigin>(Origin | SymbolOrigin::AST);
Origin |= SymbolOrigin::AST;
}
}
@ -1184,8 +1183,8 @@ private:
<< Quality << Relevance << "\n");
NSema += bool(Origin & SymbolOrigin::AST);
NIndex += bool(Origin & ~SymbolOrigin::AST);
NBoth += (Origin & SymbolOrigin::AST) && (Origin & ~SymbolOrigin::AST);
NIndex += FromIndex;
NBoth += bool(Origin & SymbolOrigin::AST) && FromIndex;
if (Candidates.push({std::move(Bundle), Scores}))
Incomplete = true;
}

View File

@ -49,7 +49,7 @@ raw_ostream &operator<<(raw_ostream &OS, SymbolOrigin O) {
return OS << "unknown";
constexpr static char Sigils[] = "ADSM4567";
for (unsigned I = 0; I < sizeof(Sigils); ++I)
if (O & static_cast<SymbolOrigin>(1 << I))
if (static_cast<uint8_t>(O) & 1u << I)
OS << Sigils[I];
return OS;
}

View File

@ -120,7 +120,7 @@ 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 SymbolOrigin : uint8_t {
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.
@ -128,6 +128,17 @@ enum SymbolOrigin : uint8_t {
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.
@ -171,7 +182,7 @@ struct Symbol {
/// See also isIndexedForCodeCompletion().
bool IsIndexedForCodeCompletion = false;
/// Where this symbol came from. Usually an index provides a constant value.
SymbolOrigin Origin = Unknown;
SymbolOrigin Origin = SymbolOrigin::Unknown;
/// A brief description of the symbol that can be appended in the completion
/// candidate list. For example, "(X x, Y y) const" is a function signature.
llvm::StringRef Signature;

View File

@ -116,8 +116,7 @@ mergeSymbol(const Symbol &L, const Symbol &R, Symbol::Details *Scratch) {
S.Detail = O.Detail;
}
S.Origin =
static_cast<SymbolOrigin>(S.Origin | O.Origin | SymbolOrigin::Merge);
S.Origin |= O.Origin | SymbolOrigin::Merge;
return S;
}

View File

@ -1257,8 +1257,7 @@ TEST(CompletionTest, Render) {
C.Header = "\"foo.h\"";
C.Kind = CompletionItemKind::Method;
C.Score.Total = 1.0;
C.Origin =
static_cast<SymbolOrigin>(SymbolOrigin::AST | SymbolOrigin::Static);
C.Origin = SymbolOrigin::AST | SymbolOrigin::Static;
CodeCompleteOptions Opts;
Opts.IncludeIndicator.Insert = "^";