forked from OSchip/llvm-project
Patch to build AST for property implementation declarations and
to print declaration from its AST. llvm-svn: 50117
This commit is contained in:
parent
0224ac57e0
commit
6efdf1ddab
|
@ -53,6 +53,7 @@ namespace {
|
||||||
void PrintObjCCategoryDecl(ObjCCategoryDecl *PID);
|
void PrintObjCCategoryDecl(ObjCCategoryDecl *PID);
|
||||||
void PrintObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *AID);
|
void PrintObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *AID);
|
||||||
void PrintObjCPropertyDecl(ObjCPropertyDecl *PD);
|
void PrintObjCPropertyDecl(ObjCPropertyDecl *PD);
|
||||||
|
void PrintObjCPropertyImplDecl(ObjCPropertyImplDecl *PID);
|
||||||
};
|
};
|
||||||
} // end anonymous namespace
|
} // end anonymous namespace
|
||||||
|
|
||||||
|
@ -228,6 +229,10 @@ void DeclPrinter::PrintObjCImplementationDecl(ObjCImplementationDecl *OID) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (ObjCImplementationDecl::propimpl_iterator I = OID->propimpl_begin(),
|
||||||
|
E = OID->propimpl_end(); I != E; ++I)
|
||||||
|
PrintObjCPropertyImplDecl(*I);
|
||||||
|
|
||||||
Out << "@end\n";
|
Out << "@end\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -287,7 +292,10 @@ void DeclPrinter::PrintObjCCategoryImplDecl(ObjCCategoryImplDecl *PID) {
|
||||||
Out << "@implementation "
|
Out << "@implementation "
|
||||||
<< PID->getClassInterface()->getName()
|
<< PID->getClassInterface()->getName()
|
||||||
<< '(' << PID->getName() << ");\n";
|
<< '(' << 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...
|
// FIXME: implement the rest...
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,7 +375,21 @@ void DeclPrinter::PrintObjCPropertyDecl(ObjCPropertyDecl *PDecl) {
|
||||||
|
|
||||||
Out << ";\n";
|
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@synthesize ";
|
||||||
|
else
|
||||||
|
Out << "\n@dynamic ";
|
||||||
|
Out << PID->getPropertyDecl()->getName();
|
||||||
|
if (PID->getPropertyIvarDecl())
|
||||||
|
Out << "=" << PID->getPropertyIvarDecl()->getName();
|
||||||
|
Out << ";\n";
|
||||||
|
}
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
/// ASTPrinter - Pretty-printer of ASTs
|
/// ASTPrinter - Pretty-printer of ASTs
|
||||||
|
|
||||||
|
|
|
@ -1106,9 +1106,18 @@ private:
|
||||||
/// Null for @dynamic. Required for @synthesize.
|
/// Null for @dynamic. Required for @synthesize.
|
||||||
ObjCIvarDecl *PropertyIvarDecl;
|
ObjCIvarDecl *PropertyIvarDecl;
|
||||||
public:
|
public:
|
||||||
ObjCPropertyImplDecl(SourceLocation atLoc, SourceLocation L)
|
ObjCPropertyImplDecl(SourceLocation atLoc, SourceLocation L,
|
||||||
: Decl(ObjCPropertyImpl, L), AtLoc(atLoc), PropertyDecl(0),
|
ObjCPropertyDecl *property,
|
||||||
PropertyImplementation(OBJC_PR_IMPL_None), PropertyIvarDecl(0) {}
|
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; }
|
void setPropertyDecl(ObjCPropertyDecl *property) { PropertyDecl = property; }
|
||||||
ObjCPropertyDecl *getPropertyDecl() const { return PropertyDecl; }
|
ObjCPropertyDecl *getPropertyDecl() const { return PropertyDecl; }
|
||||||
|
|
|
@ -517,5 +517,14 @@ ObjCInterfaceDecl *ObjCMethodDecl::getClassInterface() {
|
||||||
return 0;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -949,8 +949,9 @@ Sema::DeclTy *Sema::ActOnPropertyImplDecl(SourceLocation AtLoc,
|
||||||
ObjCInterfaceDecl* IDecl = 0;
|
ObjCInterfaceDecl* IDecl = 0;
|
||||||
// Find the class or category class where this property must have
|
// Find the class or category class where this property must have
|
||||||
// a declaration.
|
// a declaration.
|
||||||
if (ObjCImplementationDecl *IC =
|
ObjCImplementationDecl *IC = 0;
|
||||||
dyn_cast<ObjCImplementationDecl>(ClassImpDecl)) {
|
ObjCCategoryImplDecl* CatImplClass = 0;
|
||||||
|
if ((IC = dyn_cast<ObjCImplementationDecl>(ClassImpDecl))) {
|
||||||
IDecl = getObjCInterfaceDecl(IC->getIdentifier());
|
IDecl = getObjCInterfaceDecl(IC->getIdentifier());
|
||||||
// We always synthesize an interface for an implementation
|
// We always synthesize an interface for an implementation
|
||||||
// without an interface decl. So, IDecl is always non-zero.
|
// without an interface decl. So, IDecl is always non-zero.
|
||||||
|
@ -964,8 +965,7 @@ Sema::DeclTy *Sema::ActOnPropertyImplDecl(SourceLocation AtLoc,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (ObjCCategoryImplDecl* CatImplClass =
|
else if ((CatImplClass = dyn_cast<ObjCCategoryImplDecl>(ClassImpDecl))) {
|
||||||
dyn_cast<ObjCCategoryImplDecl>(ClassImpDecl)) {
|
|
||||||
if (Synthesize) {
|
if (Synthesize) {
|
||||||
Diag(AtLoc, diag::error_synthesize_category_decl);
|
Diag(AtLoc, diag::error_synthesize_category_decl);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -994,14 +994,14 @@ Sema::DeclTy *Sema::ActOnPropertyImplDecl(SourceLocation AtLoc,
|
||||||
Diag(AtLoc, diag::error_bad_property_context);
|
Diag(AtLoc, diag::error_bad_property_context);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
ObjCIvarDecl *Ivar = 0;
|
||||||
// Check that we have a valid, previously declared ivar for @synthesize
|
// Check that we have a valid, previously declared ivar for @synthesize
|
||||||
if (Synthesize) {
|
if (Synthesize) {
|
||||||
// @synthesize
|
// @synthesize
|
||||||
if (!PropertyIvar)
|
if (!PropertyIvar)
|
||||||
PropertyIvar = PropertyId;
|
PropertyIvar = PropertyId;
|
||||||
// Check that this is a previously declared 'ivar' in 'IDecl' interface
|
// Check that this is a previously declared 'ivar' in 'IDecl' interface
|
||||||
ObjCIvarDecl *Ivar = IDecl->FindIvarDeclaration(PropertyIvar);
|
Ivar = IDecl->FindIvarDeclaration(PropertyIvar);
|
||||||
if (!Ivar) {
|
if (!Ivar) {
|
||||||
Diag(PropertyLoc, diag::error_missing_property_ivar_decl,
|
Diag(PropertyLoc, diag::error_missing_property_ivar_decl,
|
||||||
PropertyId->getName());
|
PropertyId->getName());
|
||||||
|
@ -1020,15 +1020,17 @@ Sema::DeclTy *Sema::ActOnPropertyImplDecl(SourceLocation AtLoc,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
assert (property && "ActOnPropertyImplDecl - property declaration missing");
|
assert (property && "ActOnPropertyImplDecl - property declaration missing");
|
||||||
// TODO: Build the property implementation AST, pushes it into its
|
ObjCPropertyImplDecl *PIDecl =
|
||||||
// class/cateogory implementation's vector of property implementations
|
ObjCPropertyImplDecl::Create(Context, AtLoc, PropertyLoc, property,
|
||||||
#if 0
|
(Synthesize ?
|
||||||
ObjCCategoryImplDecl *PIDecl =
|
ObjCPropertyImplDecl::OBJC_PR_IMPL_SYNTHSIZE
|
||||||
ObjCCategoryImplDecl::Create(AtLoc, PropertyLoc, property,
|
: ObjCPropertyImplDecl::OBJC_PR_IMPL_DYNAMIC),
|
||||||
Synthesize ? ObjCPropertyImplDecl::OBJC_PR_IMPL_SYNTHSIZE
|
Ivar);
|
||||||
: ObjCPropertyImplDecl::OBJC_PR_IMPL_DYNAMIC,
|
if (IC)
|
||||||
PropertyId, PropertyIvar);
|
IC->addPropertyImplementation(PIDecl);
|
||||||
#endif
|
else
|
||||||
return 0;
|
CatImplClass->addPropertyImplementation(PIDecl);
|
||||||
|
|
||||||
|
return PIDecl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue