[clang-tools-extra] r355082 - Moved SymbolLocation into its own header and implementation file

Dmitri Gribenko via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 28 03:02:03 PST 2019


Author: gribozavr
Date: Thu Feb 28 03:02:01 2019
New Revision: 355082

URL: http://llvm.org/viewvc/llvm-project?rev=355082&view=rev
Log:
Moved SymbolLocation into its own header and implementation file

Reviewers: ioeric

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

Tags: #clang

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

Added:
    clang-tools-extra/trunk/clangd/index/SymbolLocation.cpp
    clang-tools-extra/trunk/clangd/index/SymbolLocation.h
Modified:
    clang-tools-extra/trunk/clangd/CMakeLists.txt
    clang-tools-extra/trunk/clangd/XRefs.cpp
    clang-tools-extra/trunk/clangd/index/Index.cpp
    clang-tools-extra/trunk/clangd/index/Index.h
    clang-tools-extra/trunk/clangd/index/Merge.cpp
    clang-tools-extra/trunk/clangd/index/Serialization.cpp
    clang-tools-extra/trunk/clangd/index/Serialization.h
    clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
    clang-tools-extra/trunk/clangd/index/YAMLSerialization.cpp

Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CMakeLists.txt?rev=355082&r1=355081&r2=355082&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clangd/CMakeLists.txt Thu Feb 28 03:02:01 2019
@@ -63,6 +63,7 @@ add_clang_library(clangDaemon
   index/MemIndex.cpp
   index/Merge.cpp
   index/SymbolID.cpp
+  index/SymbolLocation.cpp
   index/Serialization.cpp
   index/SymbolCollector.cpp
   index/YAMLSerialization.cpp

Modified: clang-tools-extra/trunk/clangd/XRefs.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/XRefs.cpp?rev=355082&r1=355081&r2=355082&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/XRefs.cpp (original)
+++ clang-tools-extra/trunk/clangd/XRefs.cpp Thu Feb 28 03:02:01 2019
@@ -10,8 +10,8 @@
 #include "Logger.h"
 #include "SourceCode.h"
 #include "URI.h"
-#include "index/Index.h"
 #include "index/Merge.h"
+#include "index/SymbolLocation.h"
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/Index/IndexDataConsumer.h"

Modified: clang-tools-extra/trunk/clangd/index/Index.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.cpp?rev=355082&r1=355081&r2=355082&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/index/Index.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Index.cpp Thu Feb 28 03:02:01 2019
@@ -16,30 +16,6 @@
 namespace clang {
 namespace clangd {
 
-constexpr uint32_t SymbolLocation::Position::MaxLine;
-constexpr uint32_t SymbolLocation::Position::MaxColumn;
-void SymbolLocation::Position::setLine(uint32_t L) {
-  if (L > MaxLine) {
-    Line = MaxLine;
-    return;
-  }
-  Line = L;
-}
-void SymbolLocation::Position::setColumn(uint32_t Col) {
-  if (Col > MaxColumn) {
-    Column = MaxColumn;
-    return;
-  }
-  Column = Col;
-}
-
-llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const SymbolLocation &L) {
-  if (!L)
-    return OS << "(none)";
-  return OS << L.FileURI << "[" << L.Start.line() << ":" << L.Start.column()
-            << "-" << L.End.line() << ":" << L.End.column() << ")";
-}
-
 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, SymbolOrigin O) {
   if (O == SymbolOrigin::Unknown)
     return OS << "unknown";

Modified: clang-tools-extra/trunk/clangd/index/Index.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.h?rev=355082&r1=355081&r2=355082&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/index/Index.h (original)
+++ clang-tools-extra/trunk/clangd/index/Index.h Thu Feb 28 03:02:01 2019
@@ -11,6 +11,7 @@
 
 #include "ExpectedTypes.h"
 #include "SymbolID.h"
+#include "SymbolLocation.h"
 #include "clang/Index/IndexSymbol.h"
 #include "clang/Lex/Lexer.h"
 #include "llvm/ADT/DenseMap.h"
@@ -30,70 +31,6 @@
 namespace clang {
 namespace clangd {
 
-struct SymbolLocation {
-  // Specify a position (Line, Column) of symbol. Using Line/Column allows us to
-  // build LSP responses without reading the file content.
-  //
-  // Position is encoded into 32 bits to save space.
-  // If Line/Column overflow, the value will be their maximum value.
-  struct Position {
-    Position() : Line(0), Column(0) {}
-    void setLine(uint32_t Line);
-    uint32_t line() const { return Line; }
-    void setColumn(uint32_t Column);
-    uint32_t column() const { return Column; }
-
-    bool hasOverflow() const {
-      return Line >= MaxLine || Column >= MaxColumn;
-    }
-
-    static constexpr uint32_t MaxLine = (1 << 20) - 1;
-    static constexpr uint32_t MaxColumn = (1 << 12) - 1;
-
-  private:
-    uint32_t Line : 20; // 0-based
-    // Using UTF-16 code units.
-    uint32_t Column : 12; // 0-based
-  };
-
-  /// The symbol range, using half-open range [Start, End).
-  Position Start;
-  Position End;
-
-  explicit operator bool() const { return !StringRef(FileURI).empty(); }
-
-  // The URI of the source file where a symbol occurs.
-  // The string must be null-terminated.
-  //
-  // We avoid using llvm::StringRef here to save memory.
-  // WARNING: unless you know what you are doing, it is recommended to use it
-  // via llvm::StringRef.
-  const char *FileURI = "";
-};
-inline bool operator==(const SymbolLocation::Position &L,
-                       const SymbolLocation::Position &R) {
-  return std::make_tuple(L.line(), L.column()) ==
-         std::make_tuple(R.line(), R.column());
-}
-inline bool operator<(const SymbolLocation::Position &L,
-                      const SymbolLocation::Position &R) {
-  return std::make_tuple(L.line(), L.column()) <
-         std::make_tuple(R.line(), R.column());
-}
-inline bool operator==(const SymbolLocation &L, const SymbolLocation &R) {
-  assert(L.FileURI && R.FileURI);
-  return !std::strcmp(L.FileURI, R.FileURI) &&
-         std::tie(L.Start, L.End) == std::tie(R.Start, R.End);
-}
-inline bool operator<(const SymbolLocation &L, const SymbolLocation &R) {
-  assert(L.FileURI && R.FileURI);
-  int Cmp = std::strcmp(L.FileURI, R.FileURI);
-  if (Cmp != 0)
-    return Cmp < 0;
-  return std::tie(L.Start, L.End) < std::tie(R.Start, R.End);
-}
-llvm::raw_ostream &operator<<(llvm::raw_ostream &, const SymbolLocation &);
-
 // 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.

Modified: clang-tools-extra/trunk/clangd/index/Merge.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Merge.cpp?rev=355082&r1=355081&r2=355082&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/index/Merge.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Merge.cpp Thu Feb 28 03:02:01 2019
@@ -9,7 +9,7 @@
 #include "Merge.h"
 #include "Logger.h"
 #include "Trace.h"
-#include "index/Index.h"
+#include "index/SymbolLocation.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSet.h"

Modified: clang-tools-extra/trunk/clangd/index/Serialization.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Serialization.cpp?rev=355082&r1=355081&r2=355082&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/index/Serialization.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Serialization.cpp Thu Feb 28 03:02:01 2019
@@ -7,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "Serialization.h"
-#include "Index.h"
 #include "Logger.h"
 #include "RIFF.h"
+#include "SymbolLocation.h"
 #include "Trace.h"
 #include "dex/Dex.h"
 #include "llvm/Support/Compression.h"

Modified: clang-tools-extra/trunk/clangd/index/Serialization.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Serialization.h?rev=355082&r1=355081&r2=355082&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/index/Serialization.h (original)
+++ clang-tools-extra/trunk/clangd/index/Serialization.h Thu Feb 28 03:02:01 2019
@@ -23,6 +23,7 @@
 
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_RIFF_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_RIFF_H
+
 #include "Headers.h"
 #include "Index.h"
 #include "llvm/Support/Error.h"

Modified: clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp?rev=355082&r1=355081&r2=355082&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp Thu Feb 28 03:02:01 2019
@@ -13,6 +13,7 @@
 #include "CodeCompletionStrings.h"
 #include "Logger.h"
 #include "SourceCode.h"
+#include "SymbolLocation.h"
 #include "URI.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"

Added: clang-tools-extra/trunk/clangd/index/SymbolLocation.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/SymbolLocation.cpp?rev=355082&view=auto
==============================================================================
--- clang-tools-extra/trunk/clangd/index/SymbolLocation.cpp (added)
+++ clang-tools-extra/trunk/clangd/index/SymbolLocation.cpp Thu Feb 28 03:02:01 2019
@@ -0,0 +1,40 @@
+//===--- SymbolLocation.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 "SymbolLocation.h"
+
+namespace clang {
+namespace clangd {
+
+constexpr uint32_t SymbolLocation::Position::MaxLine;
+constexpr uint32_t SymbolLocation::Position::MaxColumn;
+
+void SymbolLocation::Position::setLine(uint32_t L) {
+  if (L > MaxLine) {
+    Line = MaxLine;
+    return;
+  }
+  Line = L;
+}
+void SymbolLocation::Position::setColumn(uint32_t Col) {
+  if (Col > MaxColumn) {
+    Column = MaxColumn;
+    return;
+  }
+  Column = Col;
+}
+
+llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const SymbolLocation &L) {
+  if (!L)
+    return OS << "(none)";
+  return OS << L.FileURI << "[" << L.Start.line() << ":" << L.Start.column()
+            << "-" << L.End.line() << ":" << L.End.column() << ")";
+}
+
+} // namespace clangd
+} // namespace clang

Added: clang-tools-extra/trunk/clangd/index/SymbolLocation.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/SymbolLocation.h?rev=355082&view=auto
==============================================================================
--- clang-tools-extra/trunk/clangd/index/SymbolLocation.h (added)
+++ clang-tools-extra/trunk/clangd/index/SymbolLocation.h Thu Feb 28 03:02:01 2019
@@ -0,0 +1,88 @@
+//===--- SymbolLocation.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_LOCATION_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_SYMBOL_LOCATION_H
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/raw_ostream.h"
+#include <cstdint>
+
+namespace clang {
+namespace clangd {
+
+struct SymbolLocation {
+  // Specify a position (Line, Column) of symbol. Using Line/Column allows us to
+  // build LSP responses without reading the file content.
+  //
+  // Position is encoded into 32 bits to save space.
+  // If Line/Column overflow, the value will be their maximum value.
+  struct Position {
+    Position() : Line(0), Column(0) {}
+    void setLine(uint32_t Line);
+    uint32_t line() const { return Line; }
+    void setColumn(uint32_t Column);
+    uint32_t column() const { return Column; }
+
+    bool hasOverflow() const {
+      return Line >= MaxLine || Column >= MaxColumn;
+    }
+
+    static constexpr uint32_t MaxLine = (1 << 20) - 1;
+    static constexpr uint32_t MaxColumn = (1 << 12) - 1;
+
+  private:
+    uint32_t Line : 20; // 0-based
+    // Using UTF-16 code units.
+    uint32_t Column : 12; // 0-based
+  };
+
+  /// The symbol range, using half-open range [Start, End).
+  Position Start;
+  Position End;
+
+  explicit operator bool() const { return !llvm::StringRef(FileURI).empty(); }
+
+  // The URI of the source file where a symbol occurs.
+  // The string must be null-terminated.
+  //
+  // We avoid using llvm::StringRef here to save memory.
+  // WARNING: unless you know what you are doing, it is recommended to use it
+  // via llvm::StringRef.
+  const char *FileURI = "";
+};
+
+inline bool operator==(const SymbolLocation::Position &L,
+                       const SymbolLocation::Position &R) {
+  return std::make_tuple(L.line(), L.column()) ==
+         std::make_tuple(R.line(), R.column());
+}
+inline bool operator<(const SymbolLocation::Position &L,
+                      const SymbolLocation::Position &R) {
+  return std::make_tuple(L.line(), L.column()) <
+         std::make_tuple(R.line(), R.column());
+}
+inline bool operator==(const SymbolLocation &L, const SymbolLocation &R) {
+  assert(L.FileURI && R.FileURI);
+  return !std::strcmp(L.FileURI, R.FileURI) &&
+         std::tie(L.Start, L.End) == std::tie(R.Start, R.End);
+}
+inline bool operator<(const SymbolLocation &L, const SymbolLocation &R) {
+  assert(L.FileURI && R.FileURI);
+  int Cmp = std::strcmp(L.FileURI, R.FileURI);
+  if (Cmp != 0)
+    return Cmp < 0;
+  return std::tie(L.Start, L.End) < std::tie(R.Start, R.End);
+}
+
+llvm::raw_ostream &operator<<(llvm::raw_ostream &, const SymbolLocation &);
+
+} // namespace clangd
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_SYMBOL_LOCATION_H

Modified: clang-tools-extra/trunk/clangd/index/YAMLSerialization.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/YAMLSerialization.cpp?rev=355082&r1=355081&r2=355082&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/index/YAMLSerialization.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/YAMLSerialization.cpp Thu Feb 28 03:02:01 2019
@@ -14,6 +14,7 @@
 
 #include "Index.h"
 #include "Serialization.h"
+#include "SymbolLocation.h"
 #include "Trace.h"
 #include "dex/Dex.h"
 #include "llvm/ADT/Optional.h"




More information about the cfe-commits mailing list