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

llvm-svn: 342309
This commit is contained in:
George Karpenkov 2018-09-15 02:01:47 +00:00
parent 40cbde9ce2
commit 5eb4cc66eb
2 changed files with 11 additions and 0 deletions

View File

@ -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;

View File

@ -302,6 +302,14 @@ SourceLocation Stmt::getEndLoc() const {
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) {