summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-04-23 23:18:26 +0000
committerDouglas Gregor <dgregor@apple.com>2009-04-23 23:18:26 +0000
commitde9f17e943118c8c46372cae2dcd16018456e406 (patch)
treea3295ed8abea4170e8fc74683d029481fd4b19cf /clang/lib/Sema
parent838cbe19b70b8e0b5d280ed8f8be6b52eeeaf59a (diff)
downloadbcm5719-llvm-de9f17e943118c8c46372cae2dcd16018456e406.tar.gz
bcm5719-llvm-de9f17e943118c8c46372cae2dcd16018456e406.zip
Eliminate Sema::ObjCProtocols. Instead, we place ObjCProtocolDecls in
their own namespace (IDNS_Protocol) and use the normal name-lookup routines to find them. Aside from the simplification this provides (one less DenseMap!), it means that protocols will be lazily deserialized from PCH files. Make the code size of the selector table block match the code size of the type and decl blocks. llvm-svn: 69939
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r--clang/lib/Sema/Sema.h20
-rw-r--r--clang/lib/Sema/SemaDeclObjC.cpp15
-rw-r--r--clang/lib/Sema/SemaExprObjC.cpp2
-rw-r--r--clang/lib/Sema/SemaLookup.cpp14
4 files changed, 31 insertions, 20 deletions
diff --git a/clang/lib/Sema/Sema.h b/clang/lib/Sema/Sema.h
index 5a53374033d..8cf2af05779 100644
--- a/clang/lib/Sema/Sema.h
+++ b/clang/lib/Sema/Sema.h
@@ -176,11 +176,6 @@ public:
/// we can check for duplicates and find local method declarations.
llvm::SmallVector<ObjCCategoryImplDecl*, 8> ObjCCategoryImpls;
- /// ObjCProtocols - Keep track of all protocol declarations declared
- /// with @protocol keyword, so that we can emit errors on duplicates and
- /// find the declarations when needed.
- llvm::DenseMap<IdentifierInfo*, ObjCProtocolDecl*> ObjCProtocols;
-
/// ObjCInterfaceDecls - Keep track of all class declarations declared
/// with @interface, so that we can emit errors on duplicates and
/// find the declarations when needed.
@@ -769,11 +764,13 @@ public:
/// namespace alias definition, ignoring non-namespace names (C++
/// [basic.lookup.udir]p1).
LookupNamespaceName,
- // Look up an ordinary name that is going to be redeclared as a
- // name with linkage. This lookup ignores any declarations that
- // are outside of the current scope unless they have linkage. See
- // C99 6.2.2p4-5 and C++ [basic.link]p6.
- LookupRedeclarationWithLinkage
+ /// Look up an ordinary name that is going to be redeclared as a
+ /// name with linkage. This lookup ignores any declarations that
+ /// are outside of the current scope unless they have linkage. See
+ /// C99 6.2.2p4-5 and C++ [basic.link]p6.
+ LookupRedeclarationWithLinkage,
+ /// Look up the name of an Objective-C protocol.
+ LookupProtocolName
};
/// @brief Represents the results of name lookup.
@@ -1025,6 +1022,7 @@ public:
case Sema::LookupTagName:
case Sema::LookupMemberName:
case Sema::LookupRedeclarationWithLinkage: // FIXME: check linkage, scoping
+ case Sema::LookupProtocolName:
return D->isInIdentifierNamespace(IDNS);
case Sema::LookupOperatorName:
@@ -1058,6 +1056,8 @@ public:
bool AllowBuiltinCreation = true,
SourceLocation Loc = SourceLocation());
+ ObjCProtocolDecl *LookupProtocol(IdentifierInfo *II);
+
void LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S,
QualType T1, QualType T2,
FunctionSet &Functions);
diff --git a/clang/lib/Sema/SemaDeclObjC.cpp b/clang/lib/Sema/SemaDeclObjC.cpp
index 6702eb9a7a2..7badaa31304 100644
--- a/clang/lib/Sema/SemaDeclObjC.cpp
+++ b/clang/lib/Sema/SemaDeclObjC.cpp
@@ -222,7 +222,7 @@ void Sema::CheckForwardProtocolDeclarationForCircularDependency(
for (ObjCList<ObjCProtocolDecl>::iterator I = PList.begin(),
E = PList.end(); I != E; ++I) {
- if (ObjCProtocolDecl *PDecl = ObjCProtocols[(*I)->getIdentifier()]) {
+ if (ObjCProtocolDecl *PDecl = LookupProtocol((*I)->getIdentifier())) {
if (PDecl->getIdentifier() == PName) {
Diag(Ploc, diag::err_protocol_has_circular_dependency);
Diag(PrevLoc, diag::note_previous_definition);
@@ -243,7 +243,7 @@ Sema::ActOnStartProtocolInterface(SourceLocation AtProtoInterfaceLoc,
AttributeList *AttrList) {
// FIXME: Deal with AttrList.
assert(ProtocolName && "Missing protocol identifier");
- ObjCProtocolDecl *PDecl = ObjCProtocols[ProtocolName];
+ ObjCProtocolDecl *PDecl = LookupProtocol(ProtocolName);
if (PDecl) {
// Protocol already seen. Better be a forward protocol declaration
if (!PDecl->isForwardDecl()) {
@@ -265,10 +265,8 @@ Sema::ActOnStartProtocolInterface(SourceLocation AtProtoInterfaceLoc,
} else {
PDecl = ObjCProtocolDecl::Create(Context, CurContext,
AtProtoInterfaceLoc,ProtocolName);
- // FIXME: PushOnScopeChains?
- CurContext->addDecl(Context, PDecl);
+ PushOnScopeChains(PDecl, TUScope);
PDecl->setForwardDecl(false);
- ObjCProtocols[ProtocolName] = PDecl;
}
if (AttrList)
ProcessDeclAttributeList(PDecl, AttrList);
@@ -291,7 +289,7 @@ Sema::FindProtocolDeclaration(bool WarnOnDeclarations,
unsigned NumProtocols,
llvm::SmallVectorImpl<DeclPtrTy> &Protocols) {
for (unsigned i = 0; i != NumProtocols; ++i) {
- ObjCProtocolDecl *PDecl = ObjCProtocols[ProtocolId[i].first];
+ ObjCProtocolDecl *PDecl = LookupProtocol(ProtocolId[i].first);
if (!PDecl) {
Diag(ProtocolId[i].second, diag::err_undeclared_protocol)
<< ProtocolId[i].first;
@@ -514,12 +512,11 @@ Sema::ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc,
for (unsigned i = 0; i != NumElts; ++i) {
IdentifierInfo *Ident = IdentList[i].first;
- ObjCProtocolDecl *&PDecl = ObjCProtocols[Ident];
+ ObjCProtocolDecl *PDecl = LookupProtocol(Ident);
if (PDecl == 0) { // Not already seen?
PDecl = ObjCProtocolDecl::Create(Context, CurContext,
IdentList[i].second, Ident);
- // FIXME: PushOnScopeChains?
- CurContext->addDecl(Context, PDecl);
+ PushOnScopeChains(PDecl, TUScope);
}
if (attrList)
ProcessDeclAttributeList(PDecl, attrList);
diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp
index 23f6f94dc06..1df7f3dcc91 100644
--- a/clang/lib/Sema/SemaExprObjC.cpp
+++ b/clang/lib/Sema/SemaExprObjC.cpp
@@ -128,7 +128,7 @@ Sema::ExprResult Sema::ParseObjCProtocolExpression(IdentifierInfo *ProtocolId,
SourceLocation ProtoLoc,
SourceLocation LParenLoc,
SourceLocation RParenLoc) {
- ObjCProtocolDecl* PDecl = ObjCProtocols[ProtocolId];
+ ObjCProtocolDecl* PDecl = LookupProtocol(ProtocolId);
if (!PDecl) {
Diag(ProtoLoc, diag::err_undeclared_protocol) << ProtocolId;
return true;
diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index 0b11d9cf68c..613c30bc0cb 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -293,6 +293,10 @@ getIdentifierNamespacesFromLookupNameKind(Sema::LookupNameKind NameKind,
case Sema::LookupNamespaceName:
IDNS = Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Member;
break;
+
+ case Sema::LookupProtocolName:
+ IDNS = Decl::IDNS_Protocol;
+ break;
}
return IDNS;
}
@@ -831,6 +835,10 @@ Sema::LookupName(Scope *S, DeclarationName Name, LookupNameKind NameKind,
S = S->getParent();
IDNS = Decl::IDNS_Ordinary;
break;
+
+ case Sema::LookupProtocolName:
+ IDNS = Decl::IDNS_Protocol;
+ break;
}
// Scan up the scope chain looking for a decl that matches this
@@ -1480,6 +1488,12 @@ IsAcceptableNonMemberOperatorCandidate(FunctionDecl *Fn,
return false;
}
+/// \brief Find the protocol with the given name, if any.
+ObjCProtocolDecl *Sema::LookupProtocol(IdentifierInfo *II) {
+ Decl *D = LookupName(TUScope, II, LookupProtocolName).getAsDecl();
+ return cast_or_null<ObjCProtocolDecl>(D);
+}
+
void Sema::LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S,
QualType T1, QualType T2,
FunctionSet &Functions) {
OpenPOWER on IntegriCloud