From: George Karpenkov Date: Sat, 15 Sep 2018 02:01:47 +0000 (+0000) Subject: Support generating unique identifiers for Stmt objects X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=03164d3e0eb9a5dcbf4b2b6e2051bd3e8d18af1a;p=clang Support generating unique identifiers for Stmt objects The generated identifiers are stable across multiple runs, and can be a great debug or visualization aid. Differential Revision: https://reviews.llvm.org/D51822 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@342309 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Stmt.h b/include/clang/AST/Stmt.h index b9cfda7c6b..33d4e70e02 100644 --- a/include/clang/AST/Stmt.h +++ b/include/clang/AST/Stmt.h @@ -413,6 +413,9 @@ public: 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; diff --git a/lib/AST/Stmt.cpp b/lib/AST/Stmt.cpp index 6ed71fd673..687b9c24b0 100644 --- a/lib/AST/Stmt.cpp +++ b/lib/AST/Stmt.cpp @@ -302,6 +302,14 @@ SourceLocation Stmt::getEndLoc() const { llvm_unreachable("unknown statement kind"); } +int64_t Stmt::getID(const ASTContext &Context) const { + Optional 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 Stmts, SourceLocation LB, SourceLocation RB) : Stmt(CompoundStmtClass), LBraceLoc(LB), RBraceLoc(RB) {