[cfe-commits] r146564 - in /cfe/trunk: include/clang/AST/DeclObjC.h lib/AST/ASTImporter.cpp lib/AST/DeclObjC.cpp lib/Serialization/ASTReaderDecl.cpp lib/Serialization/ASTWriterDecl.cpp tools/libclang/CIndex.cpp tools/libclang/IndexingContext.cpp

Douglas Gregor dgregor at apple.com
Wed Dec 14 09:12:04 PST 2011


Author: dgregor
Date: Wed Dec 14 11:12:03 2011
New Revision: 146564

URL: http://llvm.org/viewvc/llvm-project?rev=146564&view=rev
Log:
Eliminate the vistigial ObjCClassDecl::ObjCClassRef, and inline its
members into ObjCClassDecl, saving ourselves one pointer per forward
declaration.

Modified:
    cfe/trunk/include/clang/AST/DeclObjC.h
    cfe/trunk/lib/AST/ASTImporter.cpp
    cfe/trunk/lib/AST/DeclObjC.cpp
    cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
    cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
    cfe/trunk/tools/libclang/CIndex.cpp
    cfe/trunk/tools/libclang/IndexingContext.cpp

Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=146564&r1=146563&r2=146564&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Wed Dec 14 11:12:03 2011
@@ -1021,33 +1021,26 @@
 /// @class NSCursor, NSImage, NSPasteboard, NSWindow;
 ///
 class ObjCClassDecl : public Decl {
-public:
-  class ObjCClassRef {
-    ObjCInterfaceDecl *ID;
-    SourceLocation L;
-  public:
-    ObjCClassRef(ObjCInterfaceDecl *d, SourceLocation l) : ID(d), L(l) {}
-    SourceLocation getLocation() const { return L; }
-    ObjCInterfaceDecl *getInterface() const { return ID; }
-  };
-private:
-  ObjCClassRef *ForwardDecl;
-
+  ObjCInterfaceDecl *Interface;
+  SourceLocation InterfaceLoc;
+  
   ObjCClassDecl(DeclContext *DC, SourceLocation L,
-                ObjCInterfaceDecl *const Elt, const SourceLocation Loc,
-                ASTContext &C);
+                ObjCInterfaceDecl *Interface, SourceLocation InterfaceLoc);
+  
+  friend class ASTDeclReader;
+  friend class ASTDeclWriter;
+  
 public:
   static ObjCClassDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L,
-                               ObjCInterfaceDecl *const Elt = 0,
-                               const SourceLocation Locs = SourceLocation());
+                               ObjCInterfaceDecl *Interface = 0,
+                               SourceLocation InterfaceLoc = SourceLocation());
 
-  ObjCInterfaceDecl *getForwardInterfaceDecl() {
-    return ForwardDecl->getInterface();
+  ObjCInterfaceDecl *getForwardInterfaceDecl() const {
+    return Interface;
   }
-  ObjCClassRef *getForwardDecl() { return ForwardDecl; }
-  const ObjCClassRef *getForwardDecl() const { return ForwardDecl; }
-  void setClass(ASTContext &C, ObjCInterfaceDecl*const Cls,
-                const SourceLocation Locs);
+
+  /// \brief Retrieve the location of the class name.
+  SourceLocation getNameLoc() const { return InterfaceLoc; }
 
   virtual SourceRange getSourceRange() const;
 

Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=146564&r1=146563&r2=146564&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Wed Dec 14 11:12:03 2011
@@ -3605,13 +3605,13 @@
   
   // Import the location of this declaration.
   SourceLocation Loc = Importer.Import(D->getLocation());
-  ObjCClassDecl::ObjCClassRef *From = D->getForwardDecl();
   ObjCInterfaceDecl *ToIface
-    = cast_or_null<ObjCInterfaceDecl>(Importer.Import(From->getInterface()));
+    = cast_or_null<ObjCInterfaceDecl>(
+        Importer.Import(D->getForwardInterfaceDecl()));
   ObjCClassDecl *ToClass = ObjCClassDecl::Create(Importer.getToContext(), DC,
-                                        Loc,
-                                        ToIface,
-                                        Importer.Import(From->getLocation()));
+                             Loc,
+                             ToIface,
+                             Importer.Import(D->getNameLoc()));
     
   ToClass->setLexicalDeclContext(LexicalDC);
   LexicalDC->addDeclInternal(ToClass);

Modified: cfe/trunk/lib/AST/DeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=146564&r1=146563&r2=146564&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Wed Dec 14 11:12:03 2011
@@ -942,31 +942,21 @@
 //===----------------------------------------------------------------------===//
 
 ObjCClassDecl::ObjCClassDecl(DeclContext *DC, SourceLocation L,
-                             ObjCInterfaceDecl *const Elt,
-                             const SourceLocation Loc,
-                             ASTContext &C)
-  : Decl(ObjCClass, DC, L) {
-  setClass(C, Elt, Loc);
+                             ObjCInterfaceDecl *Interface, 
+                             SourceLocation InterfaceLoc)
+  : Decl(ObjCClass, DC, L), Interface(Interface), InterfaceLoc(InterfaceLoc)
+{
 }
 
 ObjCClassDecl *ObjCClassDecl::Create(ASTContext &C, DeclContext *DC,
                                      SourceLocation L,
-                                     ObjCInterfaceDecl *const Elt,
-                                     const SourceLocation Loc) {
-  return new (C) ObjCClassDecl(DC, L, Elt, Loc, C);
+                                     ObjCInterfaceDecl *Interface,
+                                     SourceLocation InterfaceLoc) {
+  return new (C) ObjCClassDecl(DC, L, Interface, InterfaceLoc);
 }
 
-void ObjCClassDecl::setClass(ASTContext &C, ObjCInterfaceDecl*const Cls,
-                             const SourceLocation Loc) {
-    
-  ForwardDecl = (ObjCClassRef*) C.Allocate(sizeof(ObjCClassRef),
-                                           llvm::alignOf<ObjCClassRef>());
-  new (ForwardDecl) ObjCClassRef(Cls, Loc);
-}
-    
 SourceRange ObjCClassDecl::getSourceRange() const {
-  // FIXME: We should include the semicolon
-  return SourceRange(getLocation(), ForwardDecl->getLocation());
+  return SourceRange(getLocation(), InterfaceLoc);
 }
 
 //===----------------------------------------------------------------------===//

Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=146564&r1=146563&r2=146564&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Wed Dec 14 11:12:03 2011
@@ -629,9 +629,8 @@
 
 void ASTDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
   VisitDecl(CD);
-  ObjCInterfaceDecl *ClassRef = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
-  SourceLocation SLoc = ReadSourceLocation(Record, Idx);
-  CD->setClass(Reader.getContext(), ClassRef, SLoc);
+  CD->Interface = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
+  CD->InterfaceLoc = ReadSourceLocation(Record, Idx);
 }
 
 void ASTDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {

Modified: cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterDecl.cpp?rev=146564&r1=146563&r2=146564&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriterDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriterDecl.cpp Wed Dec 14 11:12:03 2011
@@ -526,8 +526,8 @@
 
 void ASTDeclWriter::VisitObjCClassDecl(ObjCClassDecl *D) {
   VisitDecl(D);
-  Writer.AddDeclRef(D->getForwardInterfaceDecl(), Record);
-  Writer.AddSourceLocation(D->getForwardDecl()->getLocation(), Record);
+  Writer.AddDeclRef(D->Interface, Record);
+  Writer.AddSourceLocation(D->InterfaceLoc, Record);
   Code = serialization::DECL_OBJC_CLASS;
 }
 

Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=146564&r1=146563&r2=146564&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Wed Dec 14 11:12:03 2011
@@ -1065,7 +1065,7 @@
 
 bool CursorVisitor::VisitObjCClassDecl(ObjCClassDecl *D) {
   if (Visit(MakeCursorObjCClassRef(D->getForwardInterfaceDecl(), 
-                                   D->getForwardDecl()->getLocation(), TU)))
+                                   D->getNameLoc(), TU)))
       return true;
   return false;
 }

Modified: cfe/trunk/tools/libclang/IndexingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/IndexingContext.cpp?rev=146564&r1=146563&r2=146564&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/IndexingContext.cpp (original)
+++ cfe/trunk/tools/libclang/IndexingContext.cpp Wed Dec 14 11:12:03 2011
@@ -300,9 +300,8 @@
 }
 
 bool IndexingContext::handleObjCClass(const ObjCClassDecl *D) {
-  const ObjCClassDecl::ObjCClassRef *Ref = D->getForwardDecl();
-  ObjCInterfaceDecl *IFaceD = Ref->getInterface();
-  SourceLocation Loc = Ref->getLocation();
+  ObjCInterfaceDecl *IFaceD = D->getForwardInterfaceDecl();
+  SourceLocation Loc = D->getNameLoc();
   bool isRedeclaration = IFaceD->getLocation() != Loc;
  
   // For @class forward declarations, suppress them the same way as references.





More information about the cfe-commits mailing list