//===--- DeclObjC.cpp - ObjC Declaration AST Node Implementation ----------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements the Objective-C related Decl classes.
//
//===----------------------------------------------------------------------===//
#include "clang/AST/DeclObjC.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/Stmt.h"
using namespace clang;
//===----------------------------------------------------------------------===//
// ObjC Decl Allocation/Deallocation Method Implementations
//===----------------------------------------------------------------------===//
ObjCMethodDecl *ObjCMethodDecl::Create(ASTContext &C,
SourceLocation beginLoc,
SourceLocation endLoc,
Selector SelInfo, QualType T,
Decl *contextDecl,
bool isInstance,
bool isVariadic,
bool isSynthesized,
ImplementationControl impControl) {
void *Mem = C.getAllocator().Allocate<ObjCMethodDecl>();
return new (Mem) ObjCMethodDecl(beginLoc, endLoc,
SelInfo, T, contextDecl,
isInstance,
isVariadic, isSynthesized, impControl);
}
ObjCMethodDecl::~ObjCMethodDecl() {
delete [] ParamInfo;
}
void ObjCMethodDecl::Destroy(ASTContext& C) {
if (Body) Body->Destroy(C);
if (SelfDecl) SelfDecl->Destroy(C);
for (param_iterator I=param_begin(), E=param_end(); I!=E; ++I)
if (*I) (*I)->Destroy(C);
Decl::Destroy(C);
}
ObjCInterfaceDecl *ObjCInterfaceDecl::Create(ASTContext &C,
SourceLocation atLoc,
IdentifierInfo *Id,
SourceLocation ClassLoc,
bool ForwardDecl, bool isInternal){
void *Mem = C.getAllocator().Allocate<ObjCInterfaceDecl>();
return new (Mem) ObjCInterfaceDecl(atLoc, Id, ClassLoc, ForwardDecl,
isInternal);
}
ObjCInterfaceDecl::~ObjCInterfaceDecl() {
delete [] Ivars;
delete [] InstanceMethods;
delete [] ClassMethods;
delete [] PropertyDecl;
// FIXME: CategoryList?
}
void ObjCInterfaceDecl::Destroy(ASTContext& C) {
for (ivar_iterator I=ivar_begin(), E=ivar_end(); I!=E; ++I)
if (*I) (*I)->Destroy(C);
for (instmeth_iterator I=instmeth_begin(), E=instmeth_end(); I!=E; ++I)
if (*I) (*I)->Destroy(C);
for (classmeth_iterator I=classmeth_begin(), E=classmeth_end(); I!=E; ++I)
if (*I) (*I)->Destroy(C);
// FIXME: Because there is no clear ownership
// role between ObjCInterfaceDecls and the ObjCPropertyDecls that they
// reference, we destroy ObjCPropertyDecls in ~TranslationUnit.
Decl::Destroy(C);
}
ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, SourceLocation L,
IdentifierInfo *Id, QualType T,
AccessControl ac, Expr *BW) {
void *Mem = C.getAllocator().Allocate<ObjCIvarDecl>();
return new (Mem) ObjCIvarDecl(L, Id, T, ac, BW);
}
ObjCAtDefsFieldDecl
*ObjCAtDefsFieldDecl::Create(ASTContext &C, SourceLocation L,
IdentifierInfo *Id, QualType T, Expr *BW) {
void *Mem = C.getAllocator().Allocate<ObjCAtDefsFieldDecl>();
return new (Mem) ObjCAtDefsFieldDecl(L, Id, T, BW);
}
void ObjCAtDefsFieldDecl::Destroy(ASTContext& C) {
this->~ObjCAtDefsFieldDecl();
C.getAllocator().Deallocate((void *)this);
}
ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C,
SourceLocation L,
IdentifierInfo *Id) {
void *Mem = C.getAllocator().Allocate<ObjCProtocolDecl>();
return new (Mem) ObjCProtocolDecl(L, Id);
}
ObjCProtocolDecl::~ObjCProtocolDecl() {
delete [] InstanceMethods;
delete [] ClassMethods;
delete [] PropertyDecl;
}
void ObjCProtocolDecl::Destroy(ASTContext& C) {
// Referenced Protocols are not owned, so don't Destroy them.
for (instmeth_iterator I=instmeth_begin(), E=instmeth_end(); I!=E; ++I)
if (*I) (*I)->Destroy(C);
for (classmeth_iterator I=classmeth_begin(), E=classmeth_end(); I!=E; ++I)
if (*I) (*I)->Destroy(C);
// FIXME: Because there is no clear ownership
// role between ObjCProtocolDecls and the ObjCPropertyDecls that they
// reference, we destroy ObjCPropertyDecls in ~TranslationUnit.
Decl::Destroy(C);
}
ObjCClassDecl