[clang-tools-extra] 4ce242a - [clangd] Find relations in Dex exploration tool.

Utkarsh Saxena via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 10 07:54:17 PST 2020


Author: Utkarsh Saxena
Date: 2020-12-10T16:54:03+01:00
New Revision: 4ce242a163c3b98385a5cb949a7e6b1e1ae7eb83

URL: https://github.com/llvm/llvm-project/commit/4ce242a163c3b98385a5cb949a7e6b1e1ae7eb83
DIFF: https://github.com/llvm/llvm-project/commit/4ce242a163c3b98385a5cb949a7e6b1e1ae7eb83.diff

LOG: [clangd] Find relations in Dex exploration tool.

Reviewed By: hokein

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

Added: 
    

Modified: 
    clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp b/clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
index d7da330e2ed0..49f16e72be92 100644
--- a/clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
+++ b/clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
@@ -11,6 +11,8 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "index/Index.h"
+#include "index/Relation.h"
 #include "index/Serialization.h"
 #include "index/dex/Dex.h"
 #include "index/remote/Client.h"
@@ -267,6 +269,43 @@ class Refs : public Command {
   }
 };
 
+class Relations : public Command {
+  llvm::cl::opt<std::string> ID{
+      "id",
+      llvm::cl::Positional,
+      llvm::cl::desc("Symbol ID of the symbol being queried (hex)."),
+  };
+  llvm::cl::opt<RelationKind> Relation{
+      "relation",
+      llvm::cl::desc("Relation kind for the predicate."),
+      values(clEnumValN(RelationKind::BaseOf, "base_of",
+                        "Find subclasses of a class."),
+             clEnumValN(RelationKind::OverriddenBy, "overridden_by",
+                        "Find methods that overrides a virtual method.")),
+  };
+
+  void run() override {
+    if (ID.getNumOccurrences() == 0 || Relation.getNumOccurrences() == 0) {
+      llvm::errs()
+          << "Missing required argument: please provide id and -relation.\n";
+      return;
+    }
+    RelationsRequest Req;
+    if (ID.getNumOccurrences()) {
+      auto SID = SymbolID::fromStr(ID);
+      if (!SID) {
+        llvm::errs() << llvm::toString(SID.takeError()) << "\n";
+        return;
+      }
+      Req.Subjects.insert(*SID);
+    }
+    Req.Predicate = Relation.getValue();
+    Index->relations(Req, [](const SymbolID &SID, const Symbol &S) {
+      llvm::outs() << toYAML(S);
+    });
+  }
+};
+
 class Export : public Command {
   llvm::cl::opt<IndexFileFormat> Format{
       "format",
@@ -326,6 +365,8 @@ struct {
     {"lookup", "Dump symbol details by ID or qualified name",
      std::make_unique<Lookup>},
     {"refs", "Find references by ID or qualified name", std::make_unique<Refs>},
+    {"relations", "Find relations by ID and relation kind",
+     std::make_unique<Relations>},
     {"export", "Export index", std::make_unique<Export>},
 };
 


        


More information about the cfe-commits mailing list