r348198 - [AST] Generate unique identifiers for CXXCtorInitializer objects.

Artem Dergachev via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 3 14:15:34 PST 2018


Author: dergachev
Date: Mon Dec  3 14:15:34 2018
New Revision: 348198

URL: http://llvm.org/viewvc/llvm-project?rev=348198&view=rev
Log:
[AST] Generate unique identifiers for CXXCtorInitializer objects.

This continues the work started in r342309 and r342315 to provide identifiers
to AST objects that are shorter and easier to read and remember than pointers.

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

Modified:
    cfe/trunk/include/clang/AST/DeclCXX.h
    cfe/trunk/lib/AST/DeclCXX.cpp

Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=348198&r1=348197&r2=348198&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Mon Dec  3 14:15:34 2018
@@ -2315,6 +2315,9 @@ public:
   CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo,
                      SourceLocation L, Expr *Init, SourceLocation R);
 
+  /// \return Unique reproducible object identifier.
+  int64_t getID(const ASTContext &Context) const;
+
   /// Determine whether this initializer is initializing a base class.
   bool isBaseInitializer() const {
     return Initializee.is<TypeSourceInfo*>() && !IsDelegating;

Modified: cfe/trunk/lib/AST/DeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclCXX.cpp?rev=348198&r1=348197&r2=348198&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclCXX.cpp (original)
+++ cfe/trunk/lib/AST/DeclCXX.cpp Mon Dec  3 14:15:34 2018
@@ -2246,6 +2246,14 @@ CXXCtorInitializer::CXXCtorInitializer(A
     : Initializee(TInfo), Init(Init), LParenLoc(L), RParenLoc(R),
       IsDelegating(true), IsVirtual(false), IsWritten(false), SourceOrder(0) {}
 
+int64_t CXXCtorInitializer::getID(const ASTContext &Context) const {
+  Optional<int64_t> Out = Context.getAllocator().identifyObject(this);
+  assert(Out && "Wrong allocator used");
+  assert(*Out % alignof(CXXCtorInitializer) == 0 &&
+         "Wrong alignment information");
+  return *Out / alignof(CXXCtorInitializer);
+}
+
 TypeLoc CXXCtorInitializer::getBaseClassLoc() const {
   if (isBaseInitializer())
     return Initializee.get<TypeSourceInfo*>()->getTypeLoc();




More information about the cfe-commits mailing list