aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-10-17 19:48:06 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-10-17 19:48:06 +0000
commitb05d7b20171bbd2feb14b059f39332cbe1bf1014 (patch)
tree2ef1220f04e10f7713d2a77dd5ca7e502e054f60
parent541ba16defc1b89630cbdecdf1c09487bafd969f (diff)
Keep track when a ObjC interface/protocol was initially created as a forward reference.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142230 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/AST/DeclObjC.h30
-rw-r--r--lib/AST/ASTImporter.cpp3
-rw-r--r--lib/AST/DeclObjC.cpp10
-rw-r--r--lib/Sema/SemaDeclObjC.cpp6
-rw-r--r--lib/Serialization/ASTReaderDecl.cpp4
-rw-r--r--lib/Serialization/ASTWriterDecl.cpp2
6 files changed, 43 insertions, 12 deletions
diff --git a/include/clang/AST/DeclObjC.h b/include/clang/AST/DeclObjC.h
index 425c89d290..136acf377f 100644
--- a/include/clang/AST/DeclObjC.h
+++ b/include/clang/AST/DeclObjC.h
@@ -566,6 +566,11 @@ class ObjCInterfaceDecl : public ObjCContainerDecl {
/// extensions and implementation. This list is built lazily.
ObjCIvarDecl *IvarList;
+ /// \brief True if it was initially declared with @class.
+ /// Differs with \see ForwardDecl in that \see ForwardDecl will change to
+ /// false when we see the @interface, but InitiallyForwardDecl will remain
+ /// true.
+ bool InitiallyForwardDecl : 1;
bool ForwardDecl:1; // declared with @class.
bool InternalInterface:1; // true - no @interface for @implementation
@@ -693,6 +698,11 @@ public:
unsigned Num,
ASTContext &C);
+ /// \brief True if it was initially declared with @class.
+ /// Differs with \see isForwardDecl in that \see isForwardDecl will change to
+ /// false when we see the @interface, but this will remain true.
+ bool isInitiallyForwardDecl() const { return InitiallyForwardDecl; }
+
bool isForwardDecl() const { return ForwardDecl; }
void setForwardDecl(bool val) { ForwardDecl = val; }
@@ -924,21 +934,25 @@ class ObjCProtocolDecl : public ObjCContainerDecl {
/// Referenced protocols
ObjCProtocolList ReferencedProtocols;
- bool isForwardProtoDecl; // declared with @protocol.
+ bool InitiallyForwardDecl : 1;
+ bool isForwardProtoDecl : 1; // declared with @protocol.
SourceLocation EndLoc; // marks the '>' or identifier.
ObjCProtocolDecl(DeclContext *DC, IdentifierInfo *Id,
- SourceLocation nameLoc, SourceLocation atStartLoc)
+ SourceLocation nameLoc, SourceLocation atStartLoc,
+ bool isForwardDecl)
: ObjCContainerDecl(ObjCProtocol, DC, Id, nameLoc, atStartLoc),
- isForwardProtoDecl(true) {
+ InitiallyForwardDecl(isForwardDecl),
+ isForwardProtoDecl(isForwardDecl) {
}
public:
static ObjCProtocolDecl *Create(ASTContext &C, DeclContext *DC,
IdentifierInfo *Id,
SourceLocation nameLoc,
- SourceLocation atStartLoc);
+ SourceLocation atStartLoc,
+ bool isForwardDecl);
const ObjCProtocolList &getReferencedProtocols() const {
return ReferencedProtocols;
@@ -973,6 +987,11 @@ public:
ObjCMethodDecl *lookupClassMethod(Selector Sel) const {
return lookupMethod(Sel, false/*isInstance*/);
}
+
+ /// \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 setForwardDecl(bool val) { isForwardProtoDecl = val; }
@@ -985,6 +1004,9 @@ public:
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
static bool classof(const ObjCProtocolDecl *D) { return true; }
static bool classofKind(Kind K) { return K == ObjCProtocol; }
+
+ friend class ASTDeclReader;
+ friend class ASTDeclWriter;
};
/// ObjCClassDecl - Specifies a list of forward class declarations. For example:
diff --git a/lib/AST/ASTImporter.cpp b/lib/AST/ASTImporter.cpp
index ae2b8903f2..7e252d1d16 100644
--- a/lib/AST/ASTImporter.cpp
+++ b/lib/AST/ASTImporter.cpp
@@ -3110,7 +3110,8 @@ Decl *ASTNodeImporter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) {
if (!ToProto) {
ToProto = ObjCProtocolDecl::Create(Importer.getToContext(), DC,
Name.getAsIdentifierInfo(), Loc,
- Importer.Import(D->getAtStartLoc()));
+ Importer.Import(D->getAtStartLoc()),
+ D->isInitiallyForwardDecl());
ToProto->setForwardDecl(D->isForwardDecl());
ToProto->setLexicalDeclContext(LexicalDC);
LexicalDC->addDecl(ToProto);
diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp
index a589b7f9d3..5af3cf5990 100644
--- a/lib/AST/DeclObjC.cpp
+++ b/lib/AST/DeclObjC.cpp
@@ -623,8 +623,9 @@ ObjCInterfaceDecl(DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id,
SourceLocation CLoc, bool FD, bool isInternal)
: ObjCContainerDecl(ObjCInterface, DC, Id, CLoc, atLoc),
TypeForDecl(0), SuperClass(0),
- CategoryList(0), IvarList(0),
- ForwardDecl(FD), InternalInterface(isInternal), ExternallyCompleted(false) {
+ CategoryList(0), IvarList(0),
+ InitiallyForwardDecl(FD), ForwardDecl(FD),
+ InternalInterface(isInternal), ExternallyCompleted(false) {
}
void ObjCInterfaceDecl::LoadExternalDefinition() const {
@@ -866,8 +867,9 @@ ObjCAtDefsFieldDecl
ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C, DeclContext *DC,
IdentifierInfo *Id,
SourceLocation nameLoc,
- SourceLocation atStartLoc) {
- return new (C) ObjCProtocolDecl(DC, Id, nameLoc, atStartLoc);
+ SourceLocation atStartLoc,
+ bool isForwardDecl) {
+ return new (C) ObjCProtocolDecl(DC, Id, nameLoc, atStartLoc, isForwardDecl);
}
ObjCProtocolDecl *ObjCProtocolDecl::lookupProtocolNamed(IdentifierInfo *Name) {
diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp
index 62b4a7c0cc..1de17d2131 100644
--- a/lib/Sema/SemaDeclObjC.cpp
+++ b/lib/Sema/SemaDeclObjC.cpp
@@ -597,7 +597,8 @@ Sema::ActOnStartProtocolInterface(SourceLocation AtProtoInterfaceLoc,
PDecl->setChangedSinceDeserialization(true);
} else {
PDecl = ObjCProtocolDecl::Create(Context, CurContext, ProtocolName,
- ProtocolLoc, AtProtoInterfaceLoc);
+ ProtocolLoc, AtProtoInterfaceLoc,
+ /*isForwardDecl=*/false);
PushOnScopeChains(PDecl, TUScope);
PDecl->setForwardDecl(false);
}
@@ -698,7 +699,8 @@ Sema::ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc,
bool isNew = false;
if (PDecl == 0) { // Not already seen?
PDecl = ObjCProtocolDecl::Create(Context, CurContext, Ident,
- IdentList[i].second, AtProtocolLoc);
+ IdentList[i].second, AtProtocolLoc,
+ /*isForwardDecl=*/true);
PushOnScopeChains(PDecl, TUScope, false);
isNew = true;
}
diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp
index 6cc3f0a70b..a15dc424e7 100644
--- a/lib/Serialization/ASTReaderDecl.cpp
+++ b/lib/Serialization/ASTReaderDecl.cpp
@@ -554,6 +554,7 @@ void ASTDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
// We will rebuild this list lazily.
ID->setIvarList(0);
+ ID->InitiallyForwardDecl = Record[Idx++];
ID->setForwardDecl(Record[Idx++]);
ID->setImplicitInterfaceDecl(Record[Idx++]);
ID->setSuperClassLoc(ReadSourceLocation(Record, Idx));
@@ -571,6 +572,7 @@ void ASTDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
VisitObjCContainerDecl(PD);
+ PD->InitiallyForwardDecl = Record[Idx++];
PD->setForwardDecl(Record[Idx++]);
PD->setLocEnd(ReadSourceLocation(Record, Idx));
unsigned NumProtoRefs = Record[Idx++];
@@ -1637,7 +1639,7 @@ Decl *ASTReader::ReadDeclRecord(DeclID ID) {
break;
case DECL_OBJC_PROTOCOL:
D = ObjCProtocolDecl::Create(Context, 0, 0, SourceLocation(),
- SourceLocation());
+ SourceLocation(), 0);
break;
case DECL_OBJC_AT_DEFS_FIELD:
D = ObjCAtDefsFieldDecl::Create(Context, 0, SourceLocation(),
diff --git a/lib/Serialization/ASTWriterDecl.cpp b/lib/Serialization/ASTWriterDecl.cpp
index a8243e502e..2925f49292 100644
--- a/lib/Serialization/ASTWriterDecl.cpp
+++ b/lib/Serialization/ASTWriterDecl.cpp
@@ -470,6 +470,7 @@ void ASTDeclWriter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) {
IEnd = D->ivar_end(); I != IEnd; ++I)
Writer.AddDeclRef(*I, Record);
Writer.AddDeclRef(D->getCategoryList(), Record);
+ Record.push_back(D->isInitiallyForwardDecl());
Record.push_back(D->isForwardDecl());
Record.push_back(D->isImplicitInterfaceDecl());
Writer.AddSourceLocation(D->getSuperClassLoc(), Record);
@@ -499,6 +500,7 @@ void ASTDeclWriter::VisitObjCIvarDecl(ObjCIvarDecl *D) {
void ASTDeclWriter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) {
VisitObjCContainerDecl(D);
+ Record.push_back(D->isInitiallyForwardDecl());
Record.push_back(D->isForwardDecl());
Writer.AddSourceLocation(D->getLocEnd(), Record);
Record.push_back(D->protocol_size());