зеркало из https://github.com/microsoft/clang-1.git
Remove addition of protocol names to declaration scopes, use a separate
DenseMap to keep track of such declarations and derive ObjcProtocolDecl directyly from NamedScope. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42801 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
057aaf6304
Коммит
05672a0ce8
|
@ -87,6 +87,11 @@ class Sema : public Action {
|
|||
/// @implementation's, so that we can emit errors on duplicates.
|
||||
llvm::SmallPtrSet<IdentifierInfo*, 8> ObjcImplementations;
|
||||
|
||||
/// ObjcProtocols - Keep track of all protocol declarations declared
|
||||
/// with @protocol keyword, so that we can emit errors on duplicates and
|
||||
/// find the declarations when needded.
|
||||
llvm::DenseMap<IdentifierInfo*, ObjcProtocolDecl*> ObjcProtocols;
|
||||
|
||||
// Enum values used by KnownFunctionIDs (see below).
|
||||
enum {
|
||||
id_printf,
|
||||
|
@ -195,8 +200,6 @@ private:
|
|||
ScopedDecl *LookupScopedDecl(IdentifierInfo *II, unsigned NSI,
|
||||
SourceLocation IdLoc, Scope *S);
|
||||
ObjcInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *Id);
|
||||
ObjcProtocolDecl *getObjCProtocolDecl(Scope *S,
|
||||
IdentifierInfo *Id, SourceLocation IdLoc);
|
||||
ScopedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, Scope *S);
|
||||
ScopedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II,
|
||||
Scope *S);
|
||||
|
|
|
@ -97,25 +97,6 @@ ObjcInterfaceDecl *Sema::getObjCInterfaceDecl(IdentifierInfo *Id) {
|
|||
return cast_or_null<ObjcInterfaceDecl>(static_cast<Decl*>(IdDecl));
|
||||
}
|
||||
|
||||
/// getObjcProtocolDecl - Look up a for a protocol declaration in the scope.
|
||||
/// return 0 if one not found.
|
||||
ObjcProtocolDecl *Sema::getObjCProtocolDecl(Scope *S,
|
||||
IdentifierInfo *Id,
|
||||
SourceLocation IdLoc) {
|
||||
// Note that Protocols have their own namespace.
|
||||
ScopedDecl *PrDecl = NULL;
|
||||
for (ScopedDecl *D = Id->getFETokenInfo<ScopedDecl>(); D; D = D->getNext()) {
|
||||
if (D->getIdentifierNamespace() == Decl::IDNS_Protocol) {
|
||||
PrDecl = D;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (PrDecl && !isa<ObjcProtocolDecl>(PrDecl))
|
||||
PrDecl = 0;
|
||||
return cast_or_null<ObjcProtocolDecl>(static_cast<Decl*>(PrDecl));
|
||||
}
|
||||
|
||||
/// LookupScopedDecl - Look up the inner-most declaration in the specified
|
||||
/// namespace.
|
||||
ScopedDecl *Sema::LookupScopedDecl(IdentifierInfo *II, unsigned NSI,
|
||||
|
@ -911,8 +892,7 @@ Sema::DeclTy *Sema::ActOnStartClassInterface(Scope* S,
|
|||
// Check for another declaration kind with the same name.
|
||||
ScopedDecl *PrevDecl = LookupScopedDecl(ClassName, Decl::IDNS_Ordinary,
|
||||
ClassLoc, S);
|
||||
if (PrevDecl && !isa<ObjcInterfaceDecl>(PrevDecl)
|
||||
&& !isa<ObjcProtocolDecl>(PrevDecl)) {
|
||||
if (PrevDecl && !isa<ObjcInterfaceDecl>(PrevDecl)) {
|
||||
Diag(ClassLoc, diag::err_redefinition_different_kind,
|
||||
ClassName->getName());
|
||||
Diag(PrevDecl->getLocation(), diag::err_previous_definition);
|
||||
|
@ -941,8 +921,7 @@ Sema::DeclTy *Sema::ActOnStartClassInterface(Scope* S,
|
|||
// Check if a different kind of symbol declared in this scope.
|
||||
PrevDecl = LookupScopedDecl(SuperName, Decl::IDNS_Ordinary,
|
||||
SuperLoc, S);
|
||||
if (PrevDecl && !isa<ObjcInterfaceDecl>(PrevDecl)
|
||||
&& !isa<ObjcProtocolDecl>(PrevDecl)) {
|
||||
if (PrevDecl && !isa<ObjcInterfaceDecl>(PrevDecl)) {
|
||||
Diag(SuperLoc, diag::err_redefinition_different_kind,
|
||||
SuperName->getName());
|
||||
Diag(PrevDecl->getLocation(), diag::err_previous_definition);
|
||||
|
@ -961,8 +940,7 @@ Sema::DeclTy *Sema::ActOnStartClassInterface(Scope* S,
|
|||
|
||||
/// Check then save referenced protocols
|
||||
for (unsigned int i = 0; i != NumProtocols; i++) {
|
||||
ObjcProtocolDecl* RefPDecl = getObjCProtocolDecl(S, ProtocolNames[i],
|
||||
ClassLoc);
|
||||
ObjcProtocolDecl* RefPDecl = ObjcProtocols[ProtocolNames[i]];
|
||||
if (!RefPDecl || RefPDecl->isForwardDecl())
|
||||
Diag(ClassLoc, diag::err_undef_protocolref,
|
||||
ProtocolNames[i]->getName(),
|
||||
|
@ -978,7 +956,7 @@ Sema::DeclTy *Sema::ActOnStartProtocolInterface(Scope* S,
|
|||
IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc,
|
||||
IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs) {
|
||||
assert(ProtocolName && "Missing protocol identifier");
|
||||
ObjcProtocolDecl *PDecl = getObjCProtocolDecl(S, ProtocolName, ProtocolLoc);
|
||||
ObjcProtocolDecl *PDecl = ObjcProtocols[ProtocolName];
|
||||
if (PDecl) {
|
||||
// Protocol already seen. Better be a forward protocol declaration
|
||||
if (!PDecl->isForwardDecl())
|
||||
|
@ -992,16 +970,12 @@ Sema::DeclTy *Sema::ActOnStartProtocolInterface(Scope* S,
|
|||
else {
|
||||
PDecl = new ObjcProtocolDecl(AtProtoInterfaceLoc, NumProtoRefs,
|
||||
ProtocolName);
|
||||
PDecl->setForwardDecl(false);
|
||||
// Chain & install the protocol decl into the identifier.
|
||||
PDecl->setNext(ProtocolName->getFETokenInfo<ScopedDecl>());
|
||||
ProtocolName->setFETokenInfo(PDecl);
|
||||
ObjcProtocols[ProtocolName] = PDecl;
|
||||
}
|
||||
|
||||
/// Check then save referenced protocols
|
||||
for (unsigned int i = 0; i != NumProtoRefs; i++) {
|
||||
ObjcProtocolDecl* RefPDecl = getObjCProtocolDecl(S, ProtoRefNames[i],
|
||||
ProtocolLoc);
|
||||
ObjcProtocolDecl* RefPDecl = ObjcProtocols[ProtoRefNames[i]];
|
||||
if (!RefPDecl || RefPDecl->isForwardDecl())
|
||||
Diag(ProtocolLoc, diag::err_undef_protocolref,
|
||||
ProtoRefNames[i]->getName(),
|
||||
|
@ -1021,8 +995,7 @@ Sema::ActOnFindProtocolDeclaration(Scope *S,
|
|||
IdentifierInfo **ProtocolId,
|
||||
unsigned NumProtocols) {
|
||||
for (unsigned i = 0; i != NumProtocols; ++i) {
|
||||
ObjcProtocolDecl *PDecl = getObjCProtocolDecl(S, ProtocolId[i],
|
||||
TypeLoc);
|
||||
ObjcProtocolDecl *PDecl = ObjcProtocols[ProtocolId[i]];
|
||||
if (!PDecl)
|
||||
Diag(TypeLoc, diag::err_undeclared_protocol,
|
||||
ProtocolId[i]->getName());
|
||||
|
@ -1039,16 +1012,11 @@ Sema::ActOnForwardProtocolDeclaration(Scope *S, SourceLocation AtProtocolLoc,
|
|||
|
||||
for (unsigned i = 0; i != NumElts; ++i) {
|
||||
IdentifierInfo *P = IdentList[i];
|
||||
ObjcProtocolDecl *PDecl = getObjCProtocolDecl(S, P, AtProtocolLoc);
|
||||
ObjcProtocolDecl *PDecl = ObjcProtocols[P];
|
||||
if (!PDecl) { // Not already seen?
|
||||
// FIXME: Pass in the location of the identifier!
|
||||
PDecl = new ObjcProtocolDecl(AtProtocolLoc, 0, P, true);
|
||||
// Chain & install the protocol decl into the identifier.
|
||||
PDecl->setNext(IdentList[i]->getFETokenInfo<ScopedDecl>());
|
||||
IdentList[i]->setFETokenInfo(PDecl);
|
||||
|
||||
// Remember that this needs to be removed when the scope is popped.
|
||||
S->AddDecl(PDecl);
|
||||
ObjcProtocols[P] = PDecl;
|
||||
}
|
||||
|
||||
Protocols.push_back(PDecl);
|
||||
|
@ -1090,8 +1058,7 @@ Sema::DeclTy *Sema::ActOnStartCategoryInterface(Scope* S,
|
|||
|
||||
/// Check then save referenced protocols
|
||||
for (unsigned int i = 0; i != NumProtoRefs; i++) {
|
||||
ObjcProtocolDecl* RefPDecl = getObjCProtocolDecl(S, ProtoRefNames[i],
|
||||
CategoryLoc);
|
||||
ObjcProtocolDecl* RefPDecl = ObjcProtocols[ProtoRefNames[i]];
|
||||
if (!RefPDecl || RefPDecl->isForwardDecl()) {
|
||||
Diag(CategoryLoc, diag::err_undef_protocolref,
|
||||
ProtoRefNames[i]->getName(),
|
||||
|
@ -1148,8 +1115,7 @@ Sema::DeclTy *Sema::ActOnStartClassImplementation(Scope *S,
|
|||
// Check if a different kind of symbol declared in this scope.
|
||||
PrevDecl = LookupScopedDecl(SuperClassname, Decl::IDNS_Ordinary,
|
||||
SuperClassLoc, S);
|
||||
if (PrevDecl && !isa<ObjcInterfaceDecl>(PrevDecl)
|
||||
&& !isa<ObjcProtocolDecl>(PrevDecl)) {
|
||||
if (PrevDecl && !isa<ObjcInterfaceDecl>(PrevDecl)) {
|
||||
Diag(SuperClassLoc, diag::err_redefinition_different_kind,
|
||||
SuperClassname->getName());
|
||||
Diag(PrevDecl->getLocation(), diag::err_previous_definition);
|
||||
|
|
|
@ -739,6 +739,7 @@
|
|||
08FB7793FE84155DC02AAC07 /* Project object */ = {
|
||||
isa = PBXProject;
|
||||
buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */;
|
||||
compatibilityVersion = "Xcode 2.4";
|
||||
hasScannedForEncodings = 1;
|
||||
mainGroup = 08FB7794FE84155DC02AAC07 /* clang */;
|
||||
projectDirPath = "";
|
||||
|
|
|
@ -84,7 +84,6 @@ public:
|
|||
IDNS_Label,
|
||||
IDNS_Tag,
|
||||
IDNS_Member,
|
||||
IDNS_Protocol,
|
||||
IDNS_Ordinary
|
||||
};
|
||||
|
||||
|
@ -133,8 +132,6 @@ public:
|
|||
case Class:
|
||||
case Enum:
|
||||
return IDNS_Tag;
|
||||
case ObjcProtocol:
|
||||
return IDNS_Protocol;
|
||||
}
|
||||
}
|
||||
// global temp stats (until we have a per-module visitor)
|
||||
|
|
|
@ -279,7 +279,7 @@ public:
|
|||
///
|
||||
/// id <NSDraggingInfo> anyObjectThatImplementsNSDraggingInfo;
|
||||
///
|
||||
class ObjcProtocolDecl : public ScopedDecl {
|
||||
class ObjcProtocolDecl : public NamedDecl {
|
||||
/// referenced protocols
|
||||
ObjcProtocolDecl **ReferencedProtocols; // Null if none
|
||||
int NumReferencedProtocols; // -1 if none
|
||||
|
@ -296,7 +296,7 @@ class ObjcProtocolDecl : public ScopedDecl {
|
|||
public:
|
||||
ObjcProtocolDecl(SourceLocation L, unsigned numRefProtos,
|
||||
IdentifierInfo *Id, bool FD = false)
|
||||
: ScopedDecl(ObjcProtocol, L, Id, 0),
|
||||
: NamedDecl(ObjcProtocol, L, Id),
|
||||
ReferencedProtocols(0), NumReferencedProtocols(-1),
|
||||
InstanceMethods(0), NumInstanceMethods(-1),
|
||||
ClassMethods(0), NumClassMethods(-1),
|
||||
|
|
|
@ -64,7 +64,6 @@ public:
|
|||
DISPATCH_CASE(Class,RecordDecl) // FIXME: Refine.
|
||||
DISPATCH_CASE(Enum,EnumDecl)
|
||||
DISPATCH_CASE(ObjcInterface,ObjcInterfaceDecl)
|
||||
DISPATCH_CASE(ObjcProtocol,ObjcProtocolDecl)
|
||||
default:
|
||||
assert(false && "Subtype of ScopedDecl not handled.");
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче