Add some plumbing to help cope with rewriting "id<p>", "Class<p>*".

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43543 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Steve Naroff 2007-10-31 04:38:33 +00:00
Родитель 8baaca50f0
Коммит 9165ad378f
3 изменённых файлов: 35 добавлений и 5 удалений

Просмотреть файл

@ -64,6 +64,8 @@ namespace {
void RewriteProtocolDecl(ObjcProtocolDecl *Dcl); void RewriteProtocolDecl(ObjcProtocolDecl *Dcl);
void RewriteMethods(int nMethods, ObjcMethodDecl **Methods); void RewriteMethods(int nMethods, ObjcMethodDecl **Methods);
void RewriteFunctionDecl(FunctionDecl *FD); void RewriteFunctionDecl(FunctionDecl *FD);
bool functionReferencesAnyObjcQualifiedInterfaceTypes(
const FunctionTypeProto *proto);
// Expression Rewriting. // Expression Rewriting.
Stmt *RewriteFunctionBody(Stmt *S); Stmt *RewriteFunctionBody(Stmt *S);
@ -402,12 +404,41 @@ CallExpr *RewriteTest::SynthesizeCallToFunctionDecl(
return new CallExpr(ICE, args, nargs, FT->getResultType(), SourceLocation()); return new CallExpr(ICE, args, nargs, FT->getResultType(), SourceLocation());
} }
bool RewriteTest::functionReferencesAnyObjcQualifiedInterfaceTypes(
const FunctionTypeProto *proto) {
const PointerType *pType = proto->getResultType()->getAsPointerType();
if (pType) {
Type *pointeeType = pType->getPointeeType().getTypePtr();
if (isa<ObjcQualifiedInterfaceType>(pointeeType))
return true; // we have "Class <Protocol> *".
}
// Now check arguments.
for (unsigned i = 0; i < proto->getNumArgs(); i++) {
pType = proto->getArgType(i)->getAsPointerType();
if (pType) {
Type *pointeeType = pType->getPointeeType().getTypePtr();
if (isa<ObjcQualifiedInterfaceType>(pointeeType))
return true;
}
}
// FIXME: we don't currently represent "id <Protocol>" in the type system.
return false;
}
void RewriteTest::RewriteFunctionDecl(FunctionDecl *FD) { void RewriteTest::RewriteFunctionDecl(FunctionDecl *FD) {
// declared in <objc/objc.h> // declared in <objc/objc.h>
if (strcmp(FD->getName(), "sel_getUid") == 0) if (strcmp(FD->getName(), "sel_getUid") == 0) {
SelGetUidFunctionDecl = FD; SelGetUidFunctionDecl = FD;
return;
// FIXME: Check if any types are isa<ObjcQualifiedInterfaceType> (yuck). }
// Check for ObjC 'id' and class types that have been adorned with protocol
// information (id<p>, C<p>*). The protocol references need to be rewritten!
const FunctionType *funcType = FD->getType()->getAsFunctionType();
assert(funcType && "missing function type");
const FunctionTypeProto *proto = dyn_cast<FunctionTypeProto>(funcType);
if (proto && functionReferencesAnyObjcQualifiedInterfaceTypes(proto)) {
// FIXME: Rewrite function decl...
}
} }
// SynthMsgSendFunctionDecl - id objc_msgSend(id self, SEL op, ...); // SynthMsgSendFunctionDecl - id objc_msgSend(id self, SEL op, ...);

Просмотреть файл

@ -369,6 +369,7 @@ static void InitializePredefinedMacros(Preprocessor &PP,
DefineBuiltinMacro(Buf, "__OBJC__=1"); DefineBuiltinMacro(Buf, "__OBJC__=1");
if (PP.getLangOptions().ObjC2) if (PP.getLangOptions().ObjC2)
DefineBuiltinMacro(Buf, "__OBJC2__=1"); DefineBuiltinMacro(Buf, "__OBJC2__=1");
if (PP.getLangOptions().ObjC1) { if (PP.getLangOptions().ObjC1) {
const char *ObjcType; const char *ObjcType;
// Predefine all the ObjC goodies (traditionally declared in <objc/objc.h>). // Predefine all the ObjC goodies (traditionally declared in <objc/objc.h>).
@ -396,7 +397,6 @@ static void InitializePredefinedMacros(Preprocessor &PP,
ObjcType = "extern SEL sel_getUid(const char *str);\n"; ObjcType = "extern SEL sel_getUid(const char *str);\n";
Buf.insert(Buf.end(), ObjcType, ObjcType+strlen(ObjcType)); Buf.insert(Buf.end(), ObjcType, ObjcType+strlen(ObjcType));
} }
// Add __builtin_va_list typedef. // Add __builtin_va_list typedef.
{ {
const char *VAList = PP.getTargetInfo().getVAListDeclaration(); const char *VAList = PP.getTargetInfo().getVAListDeclaration();

Просмотреть файл

@ -756,7 +756,6 @@
08FB7793FE84155DC02AAC07 /* Project object */ = { 08FB7793FE84155DC02AAC07 /* Project object */ = {
isa = PBXProject; isa = PBXProject;
buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */; buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */;
compatibilityVersion = "Xcode 2.4";
hasScannedForEncodings = 1; hasScannedForEncodings = 1;
mainGroup = 08FB7794FE84155DC02AAC07 /* clang */; mainGroup = 08FB7794FE84155DC02AAC07 /* clang */;
projectDirPath = ""; projectDirPath = "";