[PATCH] D51822: Support generating unique identifiers for Stmt objects

George Karpenkov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 14 19:03:07 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rC342309: Support generating unique identifiers for Stmt objects (authored by george.karpenkov, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D51822?vs=164547&id=165625#toc

Repository:
  rC Clang

https://reviews.llvm.org/D51822

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


Index: include/clang/AST/Stmt.h
===================================================================
--- include/clang/AST/Stmt.h
+++ include/clang/AST/Stmt.h
@@ -413,6 +413,9 @@
   void dump(raw_ostream &OS, SourceManager &SM) const;
   void dump(raw_ostream &OS) const;
 
+  /// \return Unique reproducible object identifier
+  int64_t getID(const ASTContext &Context) const;
+
   /// dumpColor - same as dump(), but forces color highlighting.
   void dumpColor() const;
 
Index: lib/AST/Stmt.cpp
===================================================================
--- lib/AST/Stmt.cpp
+++ lib/AST/Stmt.cpp
@@ -302,6 +302,14 @@
   llvm_unreachable("unknown statement kind");
 }
 
+int64_t Stmt::getID(const ASTContext &Context) const {
+  Optional<int64_t> Out = Context.getAllocator().identifyObject(this);
+  assert(Out && "Wrong allocator used");
+  assert(*Out % alignof(Stmt) == 0 && "Wrong alignment information");
+  return *Out / alignof(Stmt);
+
+}
+
 CompoundStmt::CompoundStmt(ArrayRef<Stmt *> Stmts, SourceLocation LB,
                            SourceLocation RB)
     : Stmt(CompoundStmtClass), LBraceLoc(LB), RBraceLoc(RB) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51822.165625.patch
Type: text/x-patch
Size: 1142 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180915/c1d228e4/attachment.bin>


More information about the cfe-commits mailing list