From cca59d77c4b84fd2da268018dbaf9431a621e75b Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 16 Mar 2008 01:23:04 +0000 Subject: [PATCH] Give ObjCProtocolDecl a Create method. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@48410 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/DeclObjC.h | 16 ++++++++++------ lib/AST/DeclObjC.cpp | 8 ++++++++ lib/Sema/SemaDeclObjC.cpp | 8 ++++---- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/include/clang/AST/DeclObjC.h b/include/clang/AST/DeclObjC.h index 74f0a25c31..3ee0b9532a 100644 --- a/include/clang/AST/DeclObjC.h +++ b/include/clang/AST/DeclObjC.h @@ -226,8 +226,7 @@ class ObjCInterfaceDecl : public TypeDecl { SourceLocation AtEndLoc; // marks the end of the entire interface. ObjCInterfaceDecl(SourceLocation atLoc, unsigned numRefProtos, - IdentifierInfo *Id, bool FD = false, - bool isInternal = false) + IdentifierInfo *Id, bool FD, bool isInternal) : TypeDecl(ObjCInterface, atLoc, Id, 0), SuperClass(0), ReferencedProtocols(0), NumReferencedProtocols(0), Ivars(0), NumIvars(-1), @@ -429,16 +428,21 @@ class ObjCProtocolDecl : public NamedDecl { SourceLocation EndLoc; // marks the '>' or identifier. SourceLocation AtEndLoc; // marks the end of the entire interface. -public: + ObjCProtocolDecl(SourceLocation L, unsigned numRefProtos, - IdentifierInfo *Id, bool FD = false) + IdentifierInfo *Id, bool FD) : NamedDecl(ObjCProtocol, L, Id), ReferencedProtocols(0), NumReferencedProtocols(0), InstanceMethods(0), NumInstanceMethods(-1), ClassMethods(0), NumClassMethods(-1), isForwardProtoDecl(FD) { - AllocReferencedProtocols(numRefProtos); - } + AllocReferencedProtocols(numRefProtos); + } +public: + static ObjCProtocolDecl *Create(ASTContext &C, SourceLocation L, + unsigned numRefProtos, IdentifierInfo *Id, + bool ForwardDecl = false); + void AllocReferencedProtocols(unsigned numRefProtos) { if (numRefProtos) { ReferencedProtocols = new ObjCProtocolDecl*[numRefProtos]; diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp index 53ba8c1219..17b1d28cad 100644 --- a/lib/AST/DeclObjC.cpp +++ b/lib/AST/DeclObjC.cpp @@ -47,6 +47,14 @@ ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, SourceLocation L, return new (Mem) ObjCIvarDecl(L, Id, T); } +ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C, SourceLocation L, + unsigned numRefProtos, + IdentifierInfo *Id, + bool ForwardDecl) { + void *Mem = C.getAllocator().Allocate(); + return new (Mem) ObjCProtocolDecl(L, numRefProtos, Id, ForwardDecl); +} + //===----------------------------------------------------------------------===// // Objective-C Decl Implementation diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index d5d658d4ff..af57d09ce6 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -211,10 +211,10 @@ Sema::DeclTy *Sema::ActOnStartProtocolInterface( } } else { - PDecl = new ObjCProtocolDecl(AtProtoInterfaceLoc, NumProtoRefs, - ProtocolName); + PDecl = ObjCProtocolDecl::Create(Context, AtProtoInterfaceLoc, NumProtoRefs, + ProtocolName); ObjCProtocols[ProtocolName] = PDecl; - } + } if (NumProtoRefs) { /// Check then save referenced protocols @@ -260,7 +260,7 @@ Sema::ActOnForwardProtocolDeclaration(SourceLocation 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); + PDecl = ObjCProtocolDecl::Create(Context, AtProtocolLoc, 0, P, true); ObjCProtocols[P] = PDecl; } -- 2.40.0