[PATCH] D58773: Moved SymbolOrigin into its own header and implementation file

2019-02-28 Thread Dmitri Gribenko via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE355086: Moved SymbolOrigin into its own header and 
implementation file (authored by gribozavr, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D58773?vs=188703&id=188709#toc

Repository:
  rCTE Clang Tools Extra

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58773/new/

https://reviews.llvm.org/D58773

Files:
  clangd/CMakeLists.txt
  clangd/CodeComplete.h
  clangd/index/FileIndex.cpp
  clangd/index/Index.cpp
  clangd/index/Index.h
  clangd/index/IndexAction.cpp
  clangd/index/Merge.cpp
  clangd/index/Serialization.cpp
  clangd/index/SymbolCollector.h
  clangd/index/SymbolOrigin.cpp
  clangd/index/SymbolOrigin.h
  clangd/index/YAMLSerialization.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/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/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.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/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/inde

[PATCH] D58773: Moved SymbolOrigin into its own header and implementation file

2019-02-28 Thread Eric Liu via Phabricator via cfe-commits
ioeric accepted this revision.
ioeric added a comment.
This revision is now accepted and ready to land.

In D58773#1413486 , @gribozavr wrote:

> SymbolOrigin is used by itself, for example, in CodeComplete.h to define 
> `struct CodeCompletion`.


Fair enough. lgtm


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58773/new/

https://reviews.llvm.org/D58773



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D58773: Moved SymbolOrigin into its own header and implementation file

2019-02-28 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr added a comment.

SymbolOrigin is used by itself, for example, in CodeComplete.h to define 
`struct CodeCompletion`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58773/new/

https://reviews.llvm.org/D58773



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D58773: Moved SymbolOrigin into its own header and implementation file

2019-02-28 Thread Eric Liu via Phabricator via cfe-commits
ioeric added a comment.

I'm not sure if SymbolOrigin is interesting enough to be its own library. It's 
usually only used along with Symbol. Maybe we could pull a library Symbol.h 
instead and put SymbolOrigin by Symbol?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58773/new/

https://reviews.llvm.org/D58773



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D58773: Moved SymbolOrigin into its own header and implementation file

2019-02-28 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr created this revision.
gribozavr added a reviewer: ioeric.
Herald added subscribers: cfe-commits, jdoerfert, kadircet, arphaman, jkorous, 
mgorny.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D58773

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/CodeComplete.h
  clang-tools-extra/clangd/index/FileIndex.cpp
  clang-tools-extra/clangd/index/Index.cpp
  clang-tools-extra/clangd/index/Index.h
  clang-tools-extra/clangd/index/IndexAction.cpp
  clang-tools-extra/clangd/index/Merge.cpp
  clang-tools-extra/clangd/index/Serialization.cpp
  clang-tools-extra/clangd/index/SymbolCollector.h
  clang-tools-extra/clangd/index/SymbolOrigin.cpp
  clang-tools-extra/clangd/index/SymbolOrigin.h
  clang-tools-extra/clangd/index/YAMLSerialization.cpp

Index: clang-tools-extra/clangd/index/YAMLSerialization.cpp
===
--- clang-tools-extra/clangd/index/YAMLSerialization.cpp
+++ clang-tools-extra/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"
Index: clang-tools-extra/clangd/index/SymbolOrigin.h
===
--- /dev/null
+++ 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 
+
+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: clang-tools-extra/clangd/index/SymbolOrigin.cpp
===
--- /dev/null
+++ 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(O) & 1u << I)
+  OS << Sigils[I];
+  return OS;
+}
+
+} // namespace clangd
+} // namespace clang
Index: clang-tools-extra/clangd/index/SymbolCollector.h
===
--- clang-tools-extra/clangd/index/SymbolCollector.h
+++ clang-tools-extra/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: clang-tools-extra/clangd/index/Serialization.cpp
===
--- clang-tools-extra/clangd/index/Serialization.cpp
+++ clang-tools-extra/clangd/index/Serializati