[cfe-commits] r48432 - in /cfe/trunk: include/clang/AST/DeclObjC.h lib/AST/DeclObjC.cpp lib/Sema/SemaDeclObjC.cpp
Chris Lattner
sabre at nondot.org
Sun Mar 16 14:17:37 PDT 2008
Author: lattner
Date: Sun Mar 16 16:17:37 2008
New Revision: 48432
URL: http://llvm.org/viewvc/llvm-project?rev=48432&view=rev
Log:
add the last two Create methods for decls, woo!
Modified:
cfe/trunk/include/clang/AST/DeclObjC.h
cfe/trunk/lib/AST/DeclObjC.cpp
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=48432&r1=48431&r2=48432&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Sun Mar 16 16:17:37 2008
@@ -876,13 +876,16 @@
/// Class that this is an alias of.
ObjCInterfaceDecl *AliasedClass;
-public:
ObjCCompatibleAliasDecl(SourceLocation L, IdentifierInfo *Id,
ObjCInterfaceDecl* aliasedClass)
- : ScopedDecl(CompatibleAlias, L, Id, 0),
- AliasedClass(aliasedClass) {}
-
- ObjCInterfaceDecl *getClassInterface() const { return AliasedClass; }
+ : ScopedDecl(CompatibleAlias, L, Id, 0), AliasedClass(aliasedClass) {}
+public:
+ static ObjCCompatibleAliasDecl *Create(ASTContext &C, SourceLocation L,
+ IdentifierInfo *Id,
+ ObjCInterfaceDecl* aliasedClass);
+
+ const ObjCInterfaceDecl *getClassInterface() const { return AliasedClass; }
+ ObjCInterfaceDecl *getClassInterface() { return AliasedClass; }
static bool classof(const Decl *D) {
return D->getKind() == CompatibleAlias;
@@ -914,11 +917,11 @@
IdentifierInfo *GetterName; // getter name of NULL if no getter
IdentifierInfo *SetterName; // setter name of NULL if no setter
-public:
ObjCPropertyDecl(SourceLocation L)
- : Decl(PropertyDecl, L),
- PropertyDecls(0), NumPropertyDecls(-1), PropertyAttributes(OBJC_PR_noattr),
- GetterName(0), SetterName(0) {}
+ : Decl(PropertyDecl, L), PropertyDecls(0), NumPropertyDecls(-1),
+ PropertyAttributes(OBJC_PR_noattr), GetterName(0), SetterName(0) {}
+public:
+ static ObjCPropertyDecl *Create(ASTContext &C, SourceLocation L);
ObjCIvarDecl **const getPropertyDecls() const { return PropertyDecls; }
void setPropertyDecls(ObjCIvarDecl **property) { PropertyDecls = property; }
Modified: cfe/trunk/lib/AST/DeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=48432&r1=48431&r2=48432&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Sun Mar 16 16:17:37 2008
@@ -89,6 +89,19 @@
return new (Mem) ObjCImplementationDecl(L, Id, ClassInterface, SuperDecl);
}
+ObjCCompatibleAliasDecl *
+ObjCCompatibleAliasDecl::Create(ASTContext &C, SourceLocation L,
+ IdentifierInfo *Id,
+ ObjCInterfaceDecl* AliasedClass) {
+ void *Mem = C.getAllocator().Allocate<ObjCCompatibleAliasDecl>();
+ return new (Mem) ObjCCompatibleAliasDecl(L, Id, AliasedClass);
+}
+
+ObjCPropertyDecl *ObjCPropertyDecl::Create(ASTContext &C, SourceLocation L) {
+ void *Mem = C.getAllocator().Allocate<ObjCPropertyDecl>();
+ return new (Mem) ObjCPropertyDecl(L);
+}
+
//===----------------------------------------------------------------------===//
// Objective-C Decl Implementation
//===----------------------------------------------------------------------===//
Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=48432&r1=48431&r2=48432&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Sun Mar 16 16:17:37 2008
@@ -172,20 +172,20 @@
return 0;
}
// Check for class declaration
- ScopedDecl *CDecl = LookupScopedDecl(ClassName, Decl::IDNS_Ordinary,
- ClassLocation, TUScope);
- if (!CDecl || !isa<ObjCInterfaceDecl>(CDecl)) {
- Diag(ClassLocation, diag::warn_undef_interface,
- ClassName->getName());
- if (CDecl)
- Diag(CDecl->getLocation(), diag::warn_previous_declaration);
+ ScopedDecl *CDeclU = LookupScopedDecl(ClassName, Decl::IDNS_Ordinary,
+ ClassLocation, TUScope);
+ ObjCInterfaceDecl *CDecl = dyn_cast_or_null<ObjCInterfaceDecl>(CDeclU);
+ if (CDecl == 0) {
+ Diag(ClassLocation, diag::warn_undef_interface, ClassName->getName());
+ if (CDeclU)
+ Diag(CDeclU->getLocation(), diag::warn_previous_declaration);
return 0;
}
- // Everything checked out, instantiate a new alias declaration ast
+
+ // Everything checked out, instantiate a new alias declaration AST.
ObjCCompatibleAliasDecl *AliasDecl =
- new ObjCCompatibleAliasDecl(AtCompatibilityAliasLoc,
- AliasName,
- dyn_cast<ObjCInterfaceDecl>(CDecl));
+ ObjCCompatibleAliasDecl::Create(Context, AtCompatibilityAliasLoc,
+ AliasName, CDecl);
// Chain & install the interface decl into the identifier.
AliasDecl->setNext(AliasName->getFETokenInfo<ScopedDecl>());
@@ -699,17 +699,19 @@
llvm::DenseMap<Selector, const ObjCMethodDecl*> ClsMap;
bool isInterfaceDeclKind =
- (isa<ObjCInterfaceDecl>(ClassDecl) || isa<ObjCCategoryDecl>(ClassDecl)
- || isa<ObjCProtocolDecl>(ClassDecl));
+ isa<ObjCInterfaceDecl>(ClassDecl) || isa<ObjCCategoryDecl>(ClassDecl)
+ || isa<ObjCProtocolDecl>(ClassDecl);
bool checkIdenticalMethods = isa<ObjCImplementationDecl>(ClassDecl);
// TODO: property declaration in category and protocols.
- if (pNum != 0 && isa<ObjCInterfaceDecl>(ClassDecl)) {
- ObjCPropertyDecl **properties = new ObjCPropertyDecl*[pNum];
- memcpy(properties, allProperties, pNum*sizeof(ObjCPropertyDecl*));
- dyn_cast<ObjCInterfaceDecl>(ClassDecl)->setPropertyDecls(properties);
- dyn_cast<ObjCInterfaceDecl>(ClassDecl)->setNumPropertyDecl(pNum);
- }
+ if (pNum != 0)
+ if (ObjCInterfaceDecl *IDecl = dyn_cast<ObjCInterfaceDecl>(ClassDecl)) {
+ // FIXME: Move the memory allocation into setPropertyDecls!
+ ObjCPropertyDecl **properties = new ObjCPropertyDecl*[pNum];
+ memcpy(properties, allProperties, pNum*sizeof(ObjCPropertyDecl*));
+ IDecl->setPropertyDecls(properties);
+ IDecl->setNumPropertyDecl(pNum);
+ }
for (unsigned i = 0; i < allNum; i++ ) {
ObjCMethodDecl *Method =
@@ -897,7 +899,7 @@
Sema::DeclTy *Sema::ActOnAddObjCProperties(SourceLocation AtLoc,
DeclTy **allProperties, unsigned NumProperties, ObjCDeclSpec &DS) {
- ObjCPropertyDecl *PDecl = new ObjCPropertyDecl(AtLoc);
+ ObjCPropertyDecl *PDecl = ObjCPropertyDecl::Create(Context, AtLoc);
if(DS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_readonly)
PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_readonly);
More information about the cfe-commits
mailing list