This patch instantiates objects for forward protocols and in general handles use of
protocols referenced in @protocol declarations.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42191 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Parse/MinimalAction.cpp b/Parse/MinimalAction.cpp
index 7f1f239..c5be83b 100644
--- a/Parse/MinimalAction.cpp
+++ b/Parse/MinimalAction.cpp
@@ -109,6 +109,23 @@
return 0;
}
+/// ObjcForwardProtocolDeclaration -
+/// Scope will always be top level file scope.
+Action::DeclTy *
+MinimalAction::ObjcForwardProtocolDeclaration(Scope *S, SourceLocation AtClassLoc,
+ IdentifierInfo **IdentList, unsigned NumElts) {
+ for (unsigned i = 0; i != NumElts; ++i) {
+ TypeNameInfo *TI =
+ new TypeNameInfo(1, IdentList[i]->getFETokenInfo<TypeNameInfo>());
+
+ IdentList[i]->setFETokenInfo(TI);
+
+ // Remember that this needs to be removed when the scope is popped.
+ S->AddDecl(IdentList[i]);
+ }
+ return 0;
+}
+
/// PopScope - When a scope is popped, if any typedefs are now out-of-scope,
/// they are removed from the IdentifierInfo::FETokenInfo field.
void MinimalAction::PopScope(SourceLocation Loc, Scope *S) {
diff --git a/Parse/ParseObjc.cpp b/Parse/ParseObjc.cpp
index 0533660..116c2d8 100644
--- a/Parse/ParseObjc.cpp
+++ b/Parse/ParseObjc.cpp
@@ -713,13 +713,13 @@
IdentifierInfo *protocolName = Tok.getIdentifierInfo();
SourceLocation nameLoc = ConsumeToken();
- if (Tok.getKind() == tok::semi) { // forward declaration.
+ llvm::SmallVector<IdentifierInfo *, 8> ProtocolRefs;
+ if (Tok.getKind() == tok::semi) { // forward declaration of one protocol.
ConsumeToken();
- return 0; // FIXME: add protocolName
+ ProtocolRefs.push_back(protocolName);
}
if (Tok.getKind() == tok::comma) { // list of forward declarations.
// Parse the list of forward declarations.
- llvm::SmallVector<IdentifierInfo *, 8> ProtocolRefs;
ProtocolRefs.push_back(protocolName);
while (1) {
@@ -738,10 +738,12 @@
// Consume the ';'.
if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@protocol"))
return 0;
- return 0; // FIXME
}
+ if (ProtocolRefs.size() > 0)
+ return Actions.ObjcForwardProtocolDeclaration(CurScope, AtLoc,
+ &ProtocolRefs[0],
+ ProtocolRefs.size());
// Last, and definitely not least, parse a protocol declaration.
- llvm::SmallVector<IdentifierInfo *, 8> ProtocolRefs;
if (Tok.getKind() == tok::less) {
if (ParseObjCProtocolReferences(ProtocolRefs))
return 0;