[PATCH] D52113: Generate unique identifiers for Decl objects

George Karpenkov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 14 11:59:51 PDT 2018


george.karpenkov created this revision.
george.karpenkov added reviewers: NoQ, rsmith, aprantl.

https://reviews.llvm.org/D52113

Files:
  clang/include/clang/AST/DeclBase.h
  clang/lib/AST/DeclBase.cpp


Index: clang/lib/AST/DeclBase.cpp
===================================================================
--- clang/lib/AST/DeclBase.cpp
+++ clang/lib/AST/DeclBase.cpp
@@ -930,6 +930,13 @@
 static Decl::Kind getKind(const Decl *D) { return D->getKind(); }
 static Decl::Kind getKind(const DeclContext *DC) { return DC->getDeclKind(); }
 
+int64_t Decl::getID() const {
+  Optional<int64_t> Out = getASTContext().getAllocator().identifyObject(this);
+  assert(Out && "Wrong allocator used");
+  assert(*Out % alignof(Decl) == 0 && "Wrong alignment information");
+  return *Out / alignof(Decl);
+}
+
 const FunctionType *Decl::getFunctionType(bool BlocksToo) const {
   QualType Ty;
   if (const auto *D = dyn_cast<ValueDecl>(this))
Index: clang/include/clang/AST/DeclBase.h
===================================================================
--- clang/include/clang/AST/DeclBase.h
+++ clang/include/clang/AST/DeclBase.h
@@ -1141,6 +1141,9 @@
 
   void dump(raw_ostream &Out, bool Deserialize = false) const;
 
+  /// \return Unique reproducible object identifier
+  int64_t getID() const;
+
   /// Looks through the Decl's underlying type to extract a FunctionType
   /// when possible. Will return null if the type underlying the Decl does not
   /// have a FunctionType.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52113.165564.patch
Type: text/x-patch
Size: 1269 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180914/d8331f1d/attachment.bin>


More information about the cfe-commits mailing list