[cfe-commits] r50117 - in /cfe/trunk: Driver/ASTConsumers.cpp include/clang/AST/DeclObjC.h lib/AST/DeclObjC.cpp lib/Sema/SemaDeclObjC.cpp
Fariborz Jahanian
fjahanian at apple.com
Tue Apr 22 17:06:02 PDT 2008
Author: fjahanian
Date: Tue Apr 22 19:06:01 2008
New Revision: 50117
URL: http://llvm.org/viewvc/llvm-project?rev=50117&view=rev
Log:
Patch to build AST for property implementation declarations and
to print declaration from its AST.
Modified:
cfe/trunk/Driver/ASTConsumers.cpp
cfe/trunk/include/clang/AST/DeclObjC.h
cfe/trunk/lib/AST/DeclObjC.cpp
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
Modified: cfe/trunk/Driver/ASTConsumers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/ASTConsumers.cpp?rev=50117&r1=50116&r2=50117&view=diff
==============================================================================
--- cfe/trunk/Driver/ASTConsumers.cpp (original)
+++ cfe/trunk/Driver/ASTConsumers.cpp Tue Apr 22 19:06:01 2008
@@ -53,6 +53,7 @@
void PrintObjCCategoryDecl(ObjCCategoryDecl *PID);
void PrintObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *AID);
void PrintObjCPropertyDecl(ObjCPropertyDecl *PD);
+ void PrintObjCPropertyImplDecl(ObjCPropertyImplDecl *PID);
};
} // end anonymous namespace
@@ -228,6 +229,10 @@
}
}
+ for (ObjCImplementationDecl::propimpl_iterator I = OID->propimpl_begin(),
+ E = OID->propimpl_end(); I != E; ++I)
+ PrintObjCPropertyImplDecl(*I);
+
Out << "@end\n";
}
@@ -287,7 +292,10 @@
Out << "@implementation "
<< PID->getClassInterface()->getName()
<< '(' << PID->getName() << ");\n";
-
+ for (ObjCCategoryImplDecl::propimpl_iterator I = PID->propimpl_begin(),
+ E = PID->propimpl_end(); I != E; ++I)
+ PrintObjCPropertyImplDecl(*I);
+ Out << "@end\n";
// FIXME: implement the rest...
}
@@ -367,7 +375,21 @@
Out << ";\n";
}
-
+
+/// PrintObjCPropertyImplDecl - Print an objective-c property implementation
+/// declaration syntax.
+///
+void DeclPrinter::PrintObjCPropertyImplDecl(ObjCPropertyImplDecl *PID) {
+ if (PID->getPropertyImplementation() ==
+ ObjCPropertyImplDecl::OBJC_PR_IMPL_SYNTHSIZE)
+ Out << "\n at synthesize ";
+ else
+ Out << "\n at dynamic ";
+ Out << PID->getPropertyDecl()->getName();
+ if (PID->getPropertyIvarDecl())
+ Out << "=" << PID->getPropertyIvarDecl()->getName();
+ Out << ";\n";
+}
//===----------------------------------------------------------------------===//
/// ASTPrinter - Pretty-printer of ASTs
Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=50117&r1=50116&r2=50117&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Tue Apr 22 19:06:01 2008
@@ -1106,9 +1106,18 @@
/// Null for @dynamic. Required for @synthesize.
ObjCIvarDecl *PropertyIvarDecl;
public:
- ObjCPropertyImplDecl(SourceLocation atLoc, SourceLocation L)
- : Decl(ObjCPropertyImpl, L), AtLoc(atLoc), PropertyDecl(0),
- PropertyImplementation(OBJC_PR_IMPL_None), PropertyIvarDecl(0) {}
+ ObjCPropertyImplDecl(SourceLocation atLoc, SourceLocation L,
+ ObjCPropertyDecl *property,
+ PropertyImplKind propertyKind,
+ ObjCIvarDecl *ivarDecl)
+ : Decl(ObjCPropertyImpl, L), AtLoc(atLoc), PropertyDecl(property),
+ PropertyImplementation(propertyKind), PropertyIvarDecl(ivarDecl){}
+
+ static ObjCPropertyImplDecl *Create(ASTContext &C, SourceLocation atLoc,
+ SourceLocation L,
+ ObjCPropertyDecl *property,
+ PropertyImplKind propertyKind,
+ ObjCIvarDecl *ivarDecl);
void setPropertyDecl(ObjCPropertyDecl *property) { PropertyDecl = property; }
ObjCPropertyDecl *getPropertyDecl() const { return PropertyDecl; }
Modified: cfe/trunk/lib/AST/DeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=50117&r1=50116&r2=50117&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Tue Apr 22 19:06:01 2008
@@ -517,5 +517,14 @@
return 0;
}
+ObjCPropertyImplDecl *ObjCPropertyImplDecl::Create(ASTContext &C,
+ SourceLocation atLoc,
+ SourceLocation L,
+ ObjCPropertyDecl *property,
+ PropertyImplKind kind,
+ ObjCIvarDecl *ivar) {
+ void *Mem = C.getAllocator().Allocate<ObjCPropertyImplDecl>();
+ return new (Mem) ObjCPropertyImplDecl(atLoc, L, property, kind, ivar);
+}
Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=50117&r1=50116&r2=50117&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Tue Apr 22 19:06:01 2008
@@ -949,8 +949,9 @@
ObjCInterfaceDecl* IDecl = 0;
// Find the class or category class where this property must have
// a declaration.
- if (ObjCImplementationDecl *IC =
- dyn_cast<ObjCImplementationDecl>(ClassImpDecl)) {
+ ObjCImplementationDecl *IC = 0;
+ ObjCCategoryImplDecl* CatImplClass = 0;
+ if ((IC = dyn_cast<ObjCImplementationDecl>(ClassImpDecl))) {
IDecl = getObjCInterfaceDecl(IC->getIdentifier());
// We always synthesize an interface for an implementation
// without an interface decl. So, IDecl is always non-zero.
@@ -964,8 +965,7 @@
return 0;
}
}
- else if (ObjCCategoryImplDecl* CatImplClass =
- dyn_cast<ObjCCategoryImplDecl>(ClassImpDecl)) {
+ else if ((CatImplClass = dyn_cast<ObjCCategoryImplDecl>(ClassImpDecl))) {
if (Synthesize) {
Diag(AtLoc, diag::error_synthesize_category_decl);
return 0;
@@ -994,14 +994,14 @@
Diag(AtLoc, diag::error_bad_property_context);
return 0;
}
-
+ ObjCIvarDecl *Ivar = 0;
// Check that we have a valid, previously declared ivar for @synthesize
if (Synthesize) {
// @synthesize
if (!PropertyIvar)
PropertyIvar = PropertyId;
// Check that this is a previously declared 'ivar' in 'IDecl' interface
- ObjCIvarDecl *Ivar = IDecl->FindIvarDeclaration(PropertyIvar);
+ Ivar = IDecl->FindIvarDeclaration(PropertyIvar);
if (!Ivar) {
Diag(PropertyLoc, diag::error_missing_property_ivar_decl,
PropertyId->getName());
@@ -1020,15 +1020,17 @@
return 0;
}
assert (property && "ActOnPropertyImplDecl - property declaration missing");
- // TODO: Build the property implementation AST, pushes it into its
- // class/cateogory implementation's vector of property implementations
-#if 0
- ObjCCategoryImplDecl *PIDecl =
- ObjCCategoryImplDecl::Create(AtLoc, PropertyLoc, property,
- Synthesize ? ObjCPropertyImplDecl::OBJC_PR_IMPL_SYNTHSIZE
- : ObjCPropertyImplDecl::OBJC_PR_IMPL_DYNAMIC,
- PropertyId, PropertyIvar);
-#endif
- return 0;
+ ObjCPropertyImplDecl *PIDecl =
+ ObjCPropertyImplDecl::Create(Context, AtLoc, PropertyLoc, property,
+ (Synthesize ?
+ ObjCPropertyImplDecl::OBJC_PR_IMPL_SYNTHSIZE
+ : ObjCPropertyImplDecl::OBJC_PR_IMPL_DYNAMIC),
+ Ivar);
+ if (IC)
+ IC->addPropertyImplementation(PIDecl);
+ else
+ CatImplClass->addPropertyImplementation(PIDecl);
+
+ return PIDecl;
}
More information about the cfe-commits
mailing list