diff options
author | Douglas Gregor <dgregor@apple.com> | 2011-12-14 17:12:03 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2011-12-14 17:12:03 +0000 |
commit | af764723bf94f8cc7596e2b2f2a97766d188ed98 (patch) | |
tree | 5709cfa021ffa4de38d3c4203811d326f39aee99 | |
parent | 553689148f546783e127749438bf6d7806e6bb1d (diff) |
Eliminate the vistigial ObjCClassDecl::ObjCClassRef, and inline its
members into ObjCClassDecl, saving ourselves one pointer per forward
declaration.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146564 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/AST/DeclObjC.h | 37 | ||||
-rw-r--r-- | lib/AST/ASTImporter.cpp | 10 | ||||
-rw-r--r-- | lib/AST/DeclObjC.cpp | 26 | ||||
-rw-r--r-- | lib/Serialization/ASTReaderDecl.cpp | 5 | ||||
-rw-r--r-- | lib/Serialization/ASTWriterDecl.cpp | 4 | ||||
-rw-r--r-- | tools/libclang/CIndex.cpp | 2 | ||||
-rw-r--r-- | tools/libclang/IndexingContext.cpp | 5 |
7 files changed, 35 insertions, 54 deletions
diff --git a/include/clang/AST/DeclObjC.h b/include/clang/AST/DeclObjC.h index feb57b8177..eb60b97227 100644 --- a/include/clang/AST/DeclObjC.h +++ b/include/clang/AST/DeclObjC.h @@ -1021,33 +1021,26 @@ public: /// @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; diff --git a/lib/AST/ASTImporter.cpp b/lib/AST/ASTImporter.cpp index c716031677..423f23d4e0 100644 --- a/lib/AST/ASTImporter.cpp +++ b/lib/AST/ASTImporter.cpp @@ -3605,13 +3605,13 @@ Decl *ASTNodeImporter::VisitObjCClassDecl(ObjCClassDecl *D) { // 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); diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp index 2157762e7f..38efadf3b5 100644 --- a/lib/AST/DeclObjC.cpp +++ b/lib/AST/DeclObjC.cpp @@ -942,31 +942,21 @@ void ObjCProtocolDecl::completedForwardDecl() { //===----------------------------------------------------------------------===// 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); } //===----------------------------------------------------------------------===// diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp index 0641b85501..bdedf8ac7e 100644 --- a/lib/Serialization/ASTReaderDecl.cpp +++ b/lib/Serialization/ASTReaderDecl.cpp @@ -629,9 +629,8 @@ void ASTDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) { 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) { diff --git a/lib/Serialization/ASTWriterDecl.cpp b/lib/Serialization/ASTWriterDecl.cpp index 99df3ea674..1448e59fb6 100644 --- a/lib/Serialization/ASTWriterDecl.cpp +++ b/lib/Serialization/ASTWriterDecl.cpp @@ -526,8 +526,8 @@ void ASTDeclWriter::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D) { 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; } diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index a0f6f686d6..9c057e5520 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -1065,7 +1065,7 @@ bool CursorVisitor::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D) { bool CursorVisitor::VisitObjCClassDecl(ObjCClassDecl *D) { if (Visit(MakeCursorObjCClassRef(D->getForwardInterfaceDecl(), - D->getForwardDecl()->getLocation(), TU))) + D->getNameLoc(), TU))) return true; return false; } diff --git a/tools/libclang/IndexingContext.cpp b/tools/libclang/IndexingContext.cpp index 812669397d..a2480ba092 100644 --- a/tools/libclang/IndexingContext.cpp +++ b/tools/libclang/IndexingContext.cpp @@ -300,9 +300,8 @@ bool IndexingContext::handleTypedefName(const TypedefNameDecl *D) { } 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. |