diff options
-rw-r--r-- | include/clang/AST/DeclObjC.h | 25 | ||||
-rw-r--r-- | lib/Rewrite/RewriteObjC.cpp | 2 | ||||
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 2 | ||||
-rw-r--r-- | lib/Sema/SemaDeclObjC.cpp | 22 | ||||
-rw-r--r-- | lib/Serialization/ASTReaderDecl.cpp | 4 | ||||
-rw-r--r-- | lib/Serialization/ASTWriterDecl.cpp | 4 |
6 files changed, 34 insertions, 25 deletions
diff --git a/include/clang/AST/DeclObjC.h b/include/clang/AST/DeclObjC.h index 6215fb0b4d..d3335220e1 100644 --- a/include/clang/AST/DeclObjC.h +++ b/include/clang/AST/DeclObjC.h @@ -576,8 +576,14 @@ class ObjCInterfaceDecl : public ObjCContainerDecl /// completed by the external AST source when required. mutable bool ExternallyCompleted : 1; - SourceLocation SuperClassLoc; // location of the super class identifier. + /// \brief The location of the superclass, if any. + SourceLocation SuperClassLoc; + /// \brief The location of the last location in this declaration, before + /// the properties/methods. For example, this will be the '>', '}', or + /// identifier, + SourceLocation EndLoc; + DefinitionData() : Definition(), SuperClass(), CategoryList(), IvarList(), ExternallyCompleted() { } }; @@ -591,11 +597,6 @@ class ObjCInterfaceDecl : public ObjCContainerDecl /// which will be NULL if this class has not yet been defined. DefinitionData *Data; - /// \brief The location of the last location in this declaration, e.g., - /// the '>', '}', or identifier. - /// FIXME: This seems like the wrong location to care about. - SourceLocation EndLoc; - DefinitionData &data() const { assert(Data != 0 && "Declaration has no definition!"); return *Data; @@ -874,10 +875,14 @@ public: // Lookup a method in the classes implementation hierarchy. ObjCMethodDecl *lookupPrivateMethod(const Selector &Sel, bool Instance=true); - // Location information, modeled after the Stmt API. - SourceLocation getLocStart() const { return getAtStartLoc(); } // '@'interface - SourceLocation getLocEnd() const { return EndLoc; } - void setLocEnd(SourceLocation LE) { EndLoc = LE; } + SourceLocation getEndOfDefinitionLoc() const { + if (!hasDefinition()) + return getLocation(); + + return data().EndLoc; + } + + void setEndOfDefinitionLoc(SourceLocation LE) { data().EndLoc = LE; } void setSuperClassLoc(SourceLocation Loc) { data().SuperClassLoc = Loc; } SourceLocation getSuperClassLoc() const { return data().SuperClassLoc; } diff --git a/lib/Rewrite/RewriteObjC.cpp b/lib/Rewrite/RewriteObjC.cpp index b8b1497435..8fa1e83340 100644 --- a/lib/Rewrite/RewriteObjC.cpp +++ b/lib/Rewrite/RewriteObjC.cpp @@ -3133,7 +3133,7 @@ void RewriteObjC::RewriteObjCInternalStruct(ObjCInterfaceDecl *CDecl, ObjCInterfaceDecl *RCDecl = CDecl->getSuperClass(); int NumIvars = CDecl->ivar_size(); SourceLocation LocStart = CDecl->getLocStart(); - SourceLocation LocEnd = CDecl->getLocEnd(); + SourceLocation LocEnd = CDecl->getEndOfDefinitionLoc(); const char *startBuf = SM->getCharacterData(LocStart); const char *endBuf = SM->getCharacterData(LocEnd); diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index a42b4a54a8..5edeab416d 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -9341,7 +9341,7 @@ void Sema::ActOnFields(Scope* S, ObjCIvarDecl **ClsFields = reinterpret_cast<ObjCIvarDecl**>(RecFields.data()); if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(EnclosingDecl)) { - ID->setLocEnd(RBrac); + ID->setEndOfDefinitionLoc(RBrac); // Add ivar's to class's DeclContext. for (unsigned i = 0, e = RecFields.size(); i != e; ++i) { ClsFields[i]->setLexicalDeclContext(ID); diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index 3d1f01fec3..02a83e5327 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -419,7 +419,7 @@ ActOnStartClassInterface(SourceLocation AtInterfaceLoc, if (declaresSameEntity(PrevDecl, IDecl)) { Diag(SuperLoc, diag::err_recursive_superclass) << SuperName << ClassName << SourceRange(AtInterfaceLoc, ClassLoc); - IDecl->setLocEnd(ClassLoc); + IDecl->setEndOfDefinitionLoc(ClassLoc); } else { ObjCInterfaceDecl *SuperClassDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl); @@ -466,17 +466,17 @@ ActOnStartClassInterface(SourceLocation AtInterfaceLoc, } IDecl->setSuperClass(SuperClassDecl); IDecl->setSuperClassLoc(SuperLoc); - IDecl->setLocEnd(SuperLoc); + IDecl->setEndOfDefinitionLoc(SuperLoc); } } else { // we have a root class. - IDecl->setLocEnd(ClassLoc); + IDecl->setEndOfDefinitionLoc(ClassLoc); } // Check then save referenced protocols. if (NumProtoRefs) { IDecl->setProtocolList((ObjCProtocolDecl**)ProtoRefs, NumProtoRefs, ProtoLocs, Context); - IDecl->setLocEnd(EndProtoLoc); + IDecl->setEndOfDefinitionLoc(EndProtoLoc); } CheckObjCDeclScope(IDecl); @@ -930,9 +930,14 @@ Decl *Sema::ActOnStartClassImplementation( IDecl = ObjCInterfaceDecl::Create(Context, CurContext, AtClassImplLoc, ClassName, ClassLoc, true); IDecl->startDefinition(); - IDecl->setSuperClass(SDecl); - IDecl->setLocEnd(ClassLoc); - + if (SDecl) { + IDecl->setSuperClass(SDecl); + IDecl->setSuperClassLoc(SuperClassLoc); + IDecl->setEndOfDefinitionLoc(SuperClassLoc); + } else { + IDecl->setEndOfDefinitionLoc(ClassLoc); + } + PushOnScopeChains(IDecl, TUScope); } else { // Mark the interface as being completed, even if it was just as @@ -978,7 +983,7 @@ void Sema::CheckImplementationIvars(ObjCImplementationDecl *ImpDecl, /// (legacy objective-c @implementation decl without an @interface decl). /// Add implementations's ivar to the synthesize class's ivar list. if (IDecl->isImplicitInterfaceDecl()) { - IDecl->setLocEnd(RBrace); + IDecl->setEndOfDefinitionLoc(RBrace); // Add ivar's to class's DeclContext. for (unsigned i = 0, e = numIvars; i != e; ++i) { ivars[i]->setLexicalDeclContext(ImpDecl); @@ -1773,7 +1778,6 @@ Sema::ActOnForwardClassDeclaration(SourceLocation AtClassLoc, = ObjCInterfaceDecl::Create(Context, CurContext, AtClassLoc, IdentList[i], IdentLocs[i], true); IDecl->setAtEndRange(IdentLocs[i]); - IDecl->setLocEnd(IdentLocs[i]); // If there was a previous declaration, link to it. if (ObjCInterfaceDecl *PrevIDecl diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp index 12b61b0cdd..cacacd2394 100644 --- a/lib/Serialization/ASTReaderDecl.cpp +++ b/lib/Serialization/ASTReaderDecl.cpp @@ -569,6 +569,8 @@ void ASTDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) { Data.SuperClass = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx); Data.SuperClassLoc = ReadSourceLocation(Record, Idx); + Data.EndLoc = ReadSourceLocation(Record, Idx); + // Read the directly referenced protocols and their SourceLocations. unsigned NumProtocols = Record[Idx++]; SmallVector<ObjCProtocolDecl *, 16> Protocols; @@ -628,8 +630,6 @@ void ASTDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) { } } } - - ID->setLocEnd(ReadSourceLocation(Record, Idx)); } void ASTDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) { diff --git a/lib/Serialization/ASTWriterDecl.cpp b/lib/Serialization/ASTWriterDecl.cpp index 7a194a8d18..9b74aaeae4 100644 --- a/lib/Serialization/ASTWriterDecl.cpp +++ b/lib/Serialization/ASTWriterDecl.cpp @@ -460,7 +460,8 @@ void ASTDeclWriter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { Writer.AddDeclRef(D->getSuperClass(), Record); Writer.AddSourceLocation(D->getSuperClassLoc(), Record); - + Writer.AddSourceLocation(D->getEndOfDefinitionLoc(), Record); + // Write out the protocols that are directly referenced by the @interface. Record.push_back(Data.ReferencedProtocols.size()); for (ObjCInterfaceDecl::protocol_iterator P = D->protocol_begin(), @@ -489,7 +490,6 @@ void ASTDeclWriter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { Writer.AddDeclRef(D->getCategoryList(), Record); } - Writer.AddSourceLocation(D->getLocEnd(), Record); Code = serialization::DECL_OBJC_INTERFACE; } |