[cfe-commits] r147408 - in /cfe/trunk: include/clang/AST/DeclObjC.h lib/AST/ASTImporter.cpp lib/AST/DeclObjC.cpp lib/AST/DumpXML.cpp lib/Rewrite/RewriteObjC.cpp lib/Sema/SemaCodeComplete.cpp lib/Sema/SemaDeclObjC.cpp lib/Serialization/ASTReaderDecl.cpp lib/Serialization/ASTWriterDecl.cpp tools/libclang/CIndex.cpp tools/libclang/IndexDecl.cpp tools/libclang/IndexingContext.cpp
Fariborz Jahanian
fjahanian at apple.com
Sun Jan 1 13:33:59 PST 2012
On Jan 1, 2012, at 11:29 AM, Douglas Gregor wrote:
> Author: dgregor
> Date: Sun Jan 1 13:29:29 2012
> New Revision: 147408
>
> URL: http://llvm.org/viewvc/llvm-project?rev=147408&view=rev
> Log:
> Move the data that corresponds to the definition of a protocol into a
> separately-allocated DefinitionData structure. Introduce various
> functions that will help with the separation of declarations from
> definitions (isThisDeclarationADefinition(), hasDefinition(),
> getDefinition()).
>
>
> Modified:
> cfe/trunk/include/clang/AST/DeclObjC.h
> cfe/trunk/lib/AST/ASTImporter.cpp
> cfe/trunk/lib/AST/DeclObjC.cpp
> cfe/trunk/lib/AST/DumpXML.cpp
> cfe/trunk/lib/Rewrite/RewriteObjC.cpp
> cfe/trunk/lib/Sema/SemaCodeComplete.cpp
> cfe/trunk/lib/Sema/SemaDeclObjC.cpp
> cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
> cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
> cfe/trunk/tools/libclang/CIndex.cpp
> cfe/trunk/tools/libclang/IndexDecl.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=147408&r1=147407&r2=147408&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/AST/DeclObjC.h (original)
> +++ cfe/trunk/include/clang/AST/DeclObjC.h Sun Jan 1 13:29:29 2012
> @@ -1066,22 +1066,34 @@
> class ObjCProtocolDecl : public ObjCContainerDecl {
> virtual void anchor();
>
> - /// Referenced protocols
> - ObjCProtocolList ReferencedProtocols;
> + struct DefinitionData {
> + /// Referenced protocols
> + ObjCProtocolList ReferencedProtocols;
> + };
> +
> + DefinitionData *Data;
>
> bool InitiallyForwardDecl : 1;
> bool isForwardProtoDecl : 1; // declared with @protocol.
>
> SourceLocation EndLoc; // marks the '>' or identifier.
>
> + DefinitionData &data() const {
> + assert(Data && "Objective-C protocol has no definition!");
> + return *Data;
> + }
> +
> ObjCProtocolDecl(DeclContext *DC, IdentifierInfo *Id,
> SourceLocation nameLoc, SourceLocation atStartLoc,
> bool isForwardDecl)
> : ObjCContainerDecl(ObjCProtocol, DC, Id, nameLoc, atStartLoc),
> + Data(0),
> InitiallyForwardDecl(isForwardDecl),
> isForwardProtoDecl(isForwardDecl) {
> }
>
> + void allocateDefinitionData();
> +
> public:
> static ObjCProtocolDecl *Create(ASTContext &C, DeclContext *DC,
> IdentifierInfo *Id,
> @@ -1090,25 +1102,48 @@
> bool isForwardDecl);
>
> const ObjCProtocolList &getReferencedProtocols() const {
> - return ReferencedProtocols;
> + assert(hasDefinition() && "No definition available!");
> + return data().ReferencedProtocols;
> }
> typedef ObjCProtocolList::iterator protocol_iterator;
> - protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();}
> - protocol_iterator protocol_end() const { return ReferencedProtocols.end(); }
> + protocol_iterator protocol_begin() const {
> + if (!hasDefinition())
> + return protocol_iterator();
> +
> + return data().ReferencedProtocols.begin();
> + }
> + protocol_iterator protocol_end() const {
> + if (!hasDefinition())
> + return protocol_iterator();
> +
> + return data().ReferencedProtocols.end();
> + }
> typedef ObjCProtocolList::loc_iterator protocol_loc_iterator;
> protocol_loc_iterator protocol_loc_begin() const {
> - return ReferencedProtocols.loc_begin();
> + if (!hasDefinition())
> + return protocol_loc_iterator();
> +
> + return data().ReferencedProtocols.loc_begin();
> }
> protocol_loc_iterator protocol_loc_end() const {
> - return ReferencedProtocols.loc_end();
> + if (!hasDefinition())
> + return protocol_loc_iterator();
> +
> + return data().ReferencedProtocols.loc_end();
> + }
> + unsigned protocol_size() const {
> + if (!hasDefinition())
> + return 0;
> +
> + return data().ReferencedProtocols.size();
> }
> - unsigned protocol_size() const { return ReferencedProtocols.size(); }
>
> /// setProtocolList - Set the list of protocols that this interface
> /// implements.
> void setProtocolList(ObjCProtocolDecl *const*List, unsigned Num,
> const SourceLocation *Locs, ASTContext &C) {
> - ReferencedProtocols.set(List, Num, Locs, C);
> + assert(Data && "Protocol is not defined");
> + data().ReferencedProtocols.set(List, Num, Locs, C);
> }
>
> ObjCProtocolDecl *lookupProtocolNamed(IdentifierInfo *PName);
> @@ -1123,13 +1158,33 @@
> return lookupMethod(Sel, false/*isInstance*/);
> }
>
> + /// \brief Determine whether this protocol has a definition.
> + bool hasDefinition() const { return Data != 0; }
> +
> + /// \brief Retrieve the definition of this protocol, if any.
> + ObjCProtocolDecl *getDefinition() {
> + return hasDefinition()? this : 0;
> + }
> +
> + /// \brief Retrieve the definition of this protocol, if any.
> + const ObjCProtocolDecl *getDefinition() const {
> + return hasDefinition()? this : 0;
> + }
> +
> + /// \brief Determine whether this particular declaration is also the
> + /// definition.
> + bool isThisDeclarationADefinition() const {
> + return getDefinition() == this;
> + }
> +
> + /// \brief Starts the definition of this Objective-C protocol.
> + void startDefinition();
> +
> /// \brief True if it was initially a forward reference.
> /// Differs with \see isForwardDecl in that \see isForwardDecl will change to
> /// false when we see the definition, but this will remain true.
> bool isInitiallyForwardDecl() const { return InitiallyForwardDecl; }
>
> - bool isForwardDecl() const { return isForwardProtoDecl; }
> -
> void completedForwardDecl();
>
> // Location information, modeled after the Stmt API.
> @@ -1149,6 +1204,7 @@
> static bool classof(const ObjCProtocolDecl *D) { return true; }
> static bool classofKind(Kind K) { return K == ObjCProtocol; }
>
> + friend class ASTReader;
> friend class ASTDeclReader;
> friend class ASTDeclWriter;
> };
>
> Modified: cfe/trunk/lib/AST/ASTImporter.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=147408&r1=147407&r2=147408&view=diff
> ==============================================================================
> --- cfe/trunk/lib/AST/ASTImporter.cpp (original)
> +++ cfe/trunk/lib/AST/ASTImporter.cpp Sun Jan 1 13:29:29 2012
> @@ -3119,7 +3119,7 @@
> }
>
> ObjCProtocolDecl *ToProto = MergeWithProtocol;
> - if (!ToProto || ToProto->isForwardDecl()) {
> + if (!ToProto || !ToProto->hasDefinition()) {
> if (!ToProto) {
> ToProto = ObjCProtocolDecl::Create(Importer.getToContext(), DC,
> Name.getAsIdentifierInfo(), Loc,
> @@ -3127,9 +3127,12 @@
> D->isInitiallyForwardDecl());
> ToProto->setLexicalDeclContext(LexicalDC);
> LexicalDC->addDeclInternal(ToProto);
> - if (D->isInitiallyForwardDecl() && !D->isForwardDecl())
> + if (D->isInitiallyForwardDecl() && D->hasDefinition())
Why the new condition is semantically equivalent to the old. If protocol is forward decl. with a definition somewhere,
old condition returns 'false' while the new condition return 'true'. I guess I don't understand from the context of use
why one can be unconditionally replaced with the negation of the other everywhere.
> ToProto->completedForwardDecl();
> }
> + if (!ToProto->hasDefinition())
> + ToProto->startDefinition();
> +
> Importer.Imported(D, ToProto);
>
> // Import protocols
>
> Modified: cfe/trunk/lib/AST/DeclObjC.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=147408&r1=147407&r2=147408&view=diff
> ==============================================================================
> --- cfe/trunk/lib/AST/DeclObjC.cpp (original)
> +++ cfe/trunk/lib/AST/DeclObjC.cpp Sun Jan 1 13:29:29 2012
> @@ -1003,9 +1003,19 @@
> return NULL;
> }
>
> +void ObjCProtocolDecl::allocateDefinitionData() {
> + assert(!Data && "Protocol already has a definition!");
> + Data = new (getASTContext()) DefinitionData;
> +}
> +
> +void ObjCProtocolDecl::startDefinition() {
> + allocateDefinitionData();
> +}
> +
> void ObjCProtocolDecl::completedForwardDecl() {
> - assert(isForwardDecl() && "Only valid to call for forward refs");
> + assert(!hasDefinition() && "Only valid to call for forward refs");
> isForwardProtoDecl = false;
> + startDefinition();
> if (ASTMutationListener *L = getASTContext().getASTMutationListener())
> L->CompletedObjCForwardRef(this);
> }
>
> Modified: cfe/trunk/lib/AST/DumpXML.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DumpXML.cpp?rev=147408&r1=147407&r2=147408&view=diff
> ==============================================================================
> --- cfe/trunk/lib/AST/DumpXML.cpp (original)
> +++ cfe/trunk/lib/AST/DumpXML.cpp Sun Jan 1 13:29:29 2012
> @@ -819,7 +819,6 @@
>
> // ObjCProtocolDecl
> void visitObjCProtocolDeclAttrs(ObjCProtocolDecl *D) {
> - setFlag("forward_decl", D->isForwardDecl());
> }
Is this method still needed?
- Fariborz
More information about the cfe-commits
mailing list