modern objc translator. Finish off first cut of the

modern meta-data translation by commenting out private ivar
declarations in user source. Also, added several tests.

llvm-svn: 150985
This commit is contained in:
Fariborz Jahanian 2012-02-20 20:09:20 +00:00
parent d5c4844e02
commit a7765fea90
10 changed files with 234 additions and 20 deletions

View File

@ -1283,12 +1283,19 @@ class ObjCCategoryDecl : public ObjCContainerDecl {
/// \brief The location of the category name in this declaration.
SourceLocation CategoryNameLoc;
/// class extension may have private ivars.
SourceLocation IvarLBraceLoc;
SourceLocation IvarRBraceLoc;
ObjCCategoryDecl(DeclContext *DC, SourceLocation AtLoc,
SourceLocation ClassNameLoc, SourceLocation CategoryNameLoc,
IdentifierInfo *Id, ObjCInterfaceDecl *IDecl)
IdentifierInfo *Id, ObjCInterfaceDecl *IDecl,
SourceLocation IvarLBraceLoc=SourceLocation(),
SourceLocation IvarRBraceLoc=SourceLocation())
: ObjCContainerDecl(ObjCCategory, DC, Id, ClassNameLoc, AtLoc),
ClassInterface(IDecl), NextClassCategory(0), HasSynthBitfield(false),
CategoryNameLoc(CategoryNameLoc) {
CategoryNameLoc(CategoryNameLoc),
IvarLBraceLoc(IvarLBraceLoc), IvarRBraceLoc(IvarRBraceLoc) {
}
public:
@ -1297,7 +1304,9 @@ public:
SourceLocation ClassNameLoc,
SourceLocation CategoryNameLoc,
IdentifierInfo *Id,
ObjCInterfaceDecl *IDecl);
ObjCInterfaceDecl *IDecl,
SourceLocation IvarLBraceLoc=SourceLocation(),
SourceLocation IvarRBraceLoc=SourceLocation());
static ObjCCategoryDecl *CreateDeserialized(ASTContext &C, unsigned ID);
ObjCInterfaceDecl *getClassInterface() { return ClassInterface; }
@ -1353,6 +1362,11 @@ public:
SourceLocation getCategoryNameLoc() const { return CategoryNameLoc; }
void setCategoryNameLoc(SourceLocation Loc) { CategoryNameLoc = Loc; }
void setIvarLBraceLoc(SourceLocation Loc) { IvarLBraceLoc = Loc; }
SourceLocation getIvarLBraceLoc() const { return IvarLBraceLoc; }
void setIvarRBraceLoc(SourceLocation Loc) { IvarRBraceLoc = Loc; }
SourceLocation getIvarRBraceLoc() const { return IvarRBraceLoc; }
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
static bool classof(const ObjCCategoryDecl *D) { return true; }
@ -1521,6 +1535,10 @@ class ObjCImplementationDecl : public ObjCImplDecl {
virtual void anchor();
/// Implementation Class's super class.
ObjCInterfaceDecl *SuperClass;
/// @implementation may have private ivars.
SourceLocation IvarLBraceLoc;
SourceLocation IvarRBraceLoc;
/// Support for ivar initialization.
/// IvarInitializers - The arguments used to initialize the ivars
CXXCtorInitializer **IvarInitializers;
@ -1535,16 +1553,22 @@ class ObjCImplementationDecl : public ObjCImplDecl {
ObjCImplementationDecl(DeclContext *DC,
ObjCInterfaceDecl *classInterface,
ObjCInterfaceDecl *superDecl,
SourceLocation nameLoc, SourceLocation atStartLoc)
SourceLocation nameLoc, SourceLocation atStartLoc,
SourceLocation IvarLBraceLoc=SourceLocation(),
SourceLocation IvarRBraceLoc=SourceLocation())
: ObjCImplDecl(ObjCImplementation, DC, classInterface, nameLoc, atStartLoc),
SuperClass(superDecl), IvarInitializers(0), NumIvarInitializers(0),
HasCXXStructors(false), HasSynthBitfield(false) {}
SuperClass(superDecl), IvarLBraceLoc(IvarLBraceLoc),
IvarRBraceLoc(IvarRBraceLoc),
IvarInitializers(0), NumIvarInitializers(0),
HasCXXStructors(false), HasSynthBitfield(false){}
public:
static ObjCImplementationDecl *Create(ASTContext &C, DeclContext *DC,
ObjCInterfaceDecl *classInterface,
ObjCInterfaceDecl *superDecl,
SourceLocation nameLoc,
SourceLocation atStartLoc);
SourceLocation atStartLoc,
SourceLocation IvarLBraceLoc=SourceLocation(),
SourceLocation IvarRBraceLoc=SourceLocation());
static ObjCImplementationDecl *CreateDeserialized(ASTContext &C, unsigned ID);
@ -1623,6 +1647,11 @@ public:
void setSuperClass(ObjCInterfaceDecl * superCls) { SuperClass = superCls; }
void setIvarLBraceLoc(SourceLocation Loc) { IvarLBraceLoc = Loc; }
SourceLocation getIvarLBraceLoc() const { return IvarLBraceLoc; }
void setIvarRBraceLoc(SourceLocation Loc) { IvarRBraceLoc = Loc; }
SourceLocation getIvarRBraceLoc() const { return IvarRBraceLoc; }
typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator;
ivar_iterator ivar_begin() const {
return ivar_iterator(decls_begin());

View File

@ -3088,7 +3088,9 @@ Decl *ASTNodeImporter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) {
Loc,
Importer.Import(D->getCategoryNameLoc()),
Name.getAsIdentifierInfo(),
ToInterface);
ToInterface,
Importer.Import(D->getIvarLBraceLoc()),
Importer.Import(D->getIvarRBraceLoc()));
ToCategory->setLexicalDeclContext(LexicalDC);
LexicalDC->addDeclInternal(ToCategory);
Importer.Imported(D, ToCategory);
@ -3434,7 +3436,9 @@ Decl *ASTNodeImporter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
Importer.ImportContext(D->getDeclContext()),
Iface, Super,
Importer.Import(D->getLocation()),
Importer.Import(D->getAtStartLoc()));
Importer.Import(D->getAtStartLoc()),
Importer.Import(D->getIvarLBraceLoc()),
Importer.Import(D->getIvarRBraceLoc()));
if (D->getDeclContext() != D->getLexicalDeclContext()) {
DeclContext *LexicalDC

View File

@ -1070,10 +1070,13 @@ ObjCCategoryDecl *ObjCCategoryDecl::Create(ASTContext &C, DeclContext *DC,
SourceLocation ClassNameLoc,
SourceLocation CategoryNameLoc,
IdentifierInfo *Id,
ObjCInterfaceDecl *IDecl) {
ObjCInterfaceDecl *IDecl,
SourceLocation IvarLBraceLoc,
SourceLocation IvarRBraceLoc) {
ObjCCategoryDecl *CatDecl = new (C) ObjCCategoryDecl(DC, AtLoc, ClassNameLoc,
CategoryNameLoc, Id,
IDecl);
IDecl,
IvarLBraceLoc, IvarRBraceLoc);
if (IDecl) {
// Link this category into its class's category list.
CatDecl->NextClassCategory = IDecl->getCategoryList();
@ -1209,11 +1212,14 @@ ObjCImplementationDecl::Create(ASTContext &C, DeclContext *DC,
ObjCInterfaceDecl *ClassInterface,
ObjCInterfaceDecl *SuperDecl,
SourceLocation nameLoc,
SourceLocation atStartLoc) {
SourceLocation atStartLoc,
SourceLocation IvarLBraceLoc,
SourceLocation IvarRBraceLoc) {
if (ClassInterface && ClassInterface->hasDefinition())
ClassInterface = ClassInterface->getDefinition();
return new (C) ObjCImplementationDecl(DC, ClassInterface, SuperDecl,
nameLoc, atStartLoc);
nameLoc, atStartLoc,
IvarLBraceLoc, IvarRBraceLoc);
}
ObjCImplementationDecl *

View File

@ -934,14 +934,17 @@ void RewriteModernObjC::RewriteCategoryDecl(ObjCCategoryDecl *CatDecl) {
// FIXME: handle category headers that are declared across multiple lines.
ReplaceText(LocStart, 0, "// ");
if (CatDecl->getIvarLBraceLoc().isValid())
InsertText(CatDecl->getIvarLBraceLoc(), "// ");
for (ObjCCategoryDecl::ivar_iterator
I = CatDecl->ivar_begin(), E = CatDecl->ivar_end(); I != E; ++I) {
ObjCIvarDecl *Ivar = (*I);
SourceLocation LocStart = Ivar->getLocStart();
ReplaceText(LocStart, 0, "// ");
}
if (CatDecl->getIvarRBraceLoc().isValid())
InsertText(CatDecl->getIvarRBraceLoc(), "// ");
for (ObjCCategoryDecl::prop_iterator I = CatDecl->prop_begin(),
E = CatDecl->prop_end(); I != E; ++I)
RewriteProperty(*I);
@ -1153,12 +1156,16 @@ void RewriteModernObjC::RewriteImplementationDecl(Decl *OID) {
if (IMD) {
InsertText(IMD->getLocStart(), "// ");
for (ObjCImplementationDecl::ivar_iterator
I = IMD->ivar_begin(), E = IMD->ivar_end(); I != E; ++I) {
ObjCIvarDecl *Ivar = (*I);
SourceLocation LocStart = Ivar->getLocStart();
ReplaceText(LocStart, 0, "// ");
if (IMD->getIvarLBraceLoc().isValid())
InsertText(IMD->getIvarLBraceLoc(), "// ");
for (ObjCImplementationDecl::ivar_iterator
I = IMD->ivar_begin(), E = IMD->ivar_end(); I != E; ++I) {
ObjCIvarDecl *Ivar = (*I);
SourceLocation LocStart = Ivar->getLocStart();
ReplaceText(LocStart, 0, "// ");
}
if (IMD->getIvarRBraceLoc().isValid())
InsertText(IMD->getIvarRBraceLoc(), "// ");
}
else
InsertText(CID->getLocStart(), "// ");

View File

@ -9585,6 +9585,8 @@ void Sema::ActOnFields(Scope* S,
// Only it is in implementation's lexical context.
ClsFields[I]->setLexicalDeclContext(IMPDecl);
CheckImplementationIvars(IMPDecl, ClsFields, RecFields.size(), RBrac);
IMPDecl->setIvarLBraceLoc(LBrac);
IMPDecl->setIvarRBraceLoc(RBrac);
} else if (ObjCCategoryDecl *CDecl =
dyn_cast<ObjCCategoryDecl>(EnclosingDecl)) {
// case of ivars in class extension; all other cases have been
@ -9618,6 +9620,8 @@ void Sema::ActOnFields(Scope* S,
ClsFields[i]->setLexicalDeclContext(CDecl);
CDecl->addDecl(ClsFields[i]);
}
CDecl->setIvarLBraceLoc(LBrac);
CDecl->setIvarRBraceLoc(RBrac);
}
}

View File

@ -770,6 +770,8 @@ void ASTDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
void ASTDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
VisitObjCContainerDecl(CD);
CD->setCategoryNameLoc(ReadSourceLocation(Record, Idx));
CD->setIvarLBraceLoc(ReadSourceLocation(Record, Idx));
CD->setIvarRBraceLoc(ReadSourceLocation(Record, Idx));
// Note that this category has been deserialized. We do this before
// deserializing the interface declaration, so that it will consider this
@ -829,6 +831,8 @@ void ASTDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
void ASTDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
VisitObjCImplDecl(D);
D->setSuperClass(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
D->setIvarLBraceLoc(ReadSourceLocation(Record, Idx));
D->setIvarRBraceLoc(ReadSourceLocation(Record, Idx));
llvm::tie(D->IvarInitializers, D->NumIvarInitializers)
= Reader.ReadCXXCtorInitializers(F, Record, Idx);
D->setHasSynthBitfield(Record[Idx++]);

View File

@ -541,6 +541,8 @@ void ASTDeclWriter::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D) {
void ASTDeclWriter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) {
VisitObjCContainerDecl(D);
Writer.AddSourceLocation(D->getCategoryNameLoc(), Record);
Writer.AddSourceLocation(D->getIvarLBraceLoc(), Record);
Writer.AddSourceLocation(D->getIvarRBraceLoc(), Record);
Writer.AddDeclRef(D->getClassInterface(), Record);
Record.push_back(D->protocol_size());
for (ObjCCategoryDecl::protocol_iterator
@ -593,6 +595,8 @@ void ASTDeclWriter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
void ASTDeclWriter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
VisitObjCImplDecl(D);
Writer.AddDeclRef(D->getSuperClass(), Record);
Writer.AddSourceLocation(D->getIvarLBraceLoc(), Record);
Writer.AddSourceLocation(D->getIvarRBraceLoc(), Record);
Writer.AddCXXCtorInitializers(D->IvarInitializers, D->NumIvarInitializers,
Record);
Record.push_back(D->hasSynthBitfield());

View File

@ -0,0 +1,61 @@
// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp
// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
@protocol PROTO @end
@interface empty_root @end
@interface root_with_ivars
{
id ROOT_IVAR;
id ROOT1_IVAR;
}
@end
@interface MAXIMAL : root_with_ivars<PROTO>
{
double D_IVAR;
double D_PROPERTY;
}
- (void) V_METH;
@end
@implementation MAXIMAL
- (void) V_METH {}
@end
//=========================================
@interface empty_class @end
@implementation empty_class @end
//=========================================
@interface class_empty_root : empty_root @end
@implementation class_empty_root @end
//=========================================
@interface class_with_ivars : empty_root
{
int class_with_ivars_IVAR;
}
@end
@implementation class_with_ivars @end
//=========================================
@interface class_has_no_ivar : root_with_ivars @end
@implementation class_has_no_ivar @end
//============================class needs to be synthesized here=====================
@interface SUPER {
@public
double divar;
SUPER *p_super;
}
@end
@interface INTF @end
@implementation INTF
- (SUPER *) Meth : (SUPER *)arg {
return arg->p_super;
}
@end

View File

@ -0,0 +1,64 @@
// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp
// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
@protocol P @end
@protocol P1 @end
@interface INTF
{
id CLASS_IVAR;
id<P, P1> Q_IVAR;
void (^_block)(id<P>);
void (*_fptr)(void (^_block)(id<P>));
char CLASS_EXT_IVAR;
id<P, P1> (^ext_block)(id<P>, INTF<P,P1>*, INTF*);
id IMPL_IVAR;
double D_IMPL_IVAR;
INTF<P> *(*imp_fptr)(void (^_block)(id<P>, INTF<P,P1>*));
id arr[100];
}
@end
@implementation INTF @end
@interface MISC_INTF
{
id CLASS_IVAR;
id<P, P1> Q_IVAR;
void (^_block)(id<P>);
void (*_fptr)(void (^_block)(id<P>));
unsigned int BF : 8;
}
@end
@interface MISC_INTF()
{
char CLASS_EXT_IVAR;
id<P, P1> (^ext_block)(id<P>, MISC_INTF<P,P1>*, MISC_INTF*);
}
@end
@interface MISC_INTF() {
int II1;
double DD1; }
@end
@interface MISC_INTF() { int II2; double DD2; }
@end
@interface MISC_INTF() { int II3;
double DD3; }
@end
@interface MISC_INTF() { int II4; double DD4;
}
@end
@implementation MISC_INTF
{
id IMPL_IVAR;
double D_IMPL_IVAR;
MISC_INTF<P> *(*imp_fptr)(void (^_block)(id<P>, MISC_INTF<P,P1>*));
}
@end

View File

@ -0,0 +1,31 @@
// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp
// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
@protocol ROOT @end
@protocol P1 @end
@protocol P2<ROOT> @end
@class NSObject;
@protocol PROTO <P1, P2>
- (id) INST_METHOD;
+ (id) CLASS_METHOD : (id)ARG;
@property id Prop_in_PROTO;
@optional
- (id) opt_instance_method;
+ (id) opt_class_method;
@property (readonly, retain) NSObject *AnotherProperty;
@required
- (id) req;
@optional
- (id) X_opt_instance_method;
+ (id) X_opt_class_method;
@end
@interface INTF <PROTO, ROOT>
@end
@implementation INTF
@end