From 6630e10ccc01b849b2c0208b6f42821ea02c2ede Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Tue, 12 Aug 2008 05:08:18 +0000 Subject: Protocol related tweaks - Implement type conversion of ObjCQualifiedIdType - Wire @protocol(...) to GenerateProtocolRef in ScalarExprEmitter llvm-svn: 54666 --- clang/lib/CodeGen/CGExprScalar.cpp | 7 +++++++ clang/lib/CodeGen/CGObjCRuntime.h | 18 +++++++++++++++--- clang/lib/CodeGen/CodeGenTypes.cpp | 8 ++++++-- 3 files changed, 28 insertions(+), 5 deletions(-) (limited to 'clang/lib/CodeGen') diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp index decf539f1c8..294965498ec 100644 --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -14,6 +14,7 @@ #include "CodeGenFunction.h" #include "CodeGenModule.h" #include "clang/AST/ASTContext.h" +#include "clang/AST/DeclObjC.h" #include "clang/AST/StmtVisitor.h" #include "clang/Basic/TargetInfo.h" #include "llvm/Constants.h" @@ -135,6 +136,7 @@ public: } Value *VisitObjCMessageExpr(ObjCMessageExpr *E); Value *VisitObjCSelectorExpr(ObjCSelectorExpr *E); + Value *VisitObjCProtocolExpr(ObjCProtocolExpr *E); Value *VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) { return EmitLoadOfLValue(E);} Value *VisitArraySubscriptExpr(ArraySubscriptExpr *E); Value *VisitShuffleVectorExpr(ShuffleVectorExpr *E); @@ -506,6 +508,11 @@ Value *ScalarExprEmitter::VisitObjCSelectorExpr(ObjCSelectorExpr *E) { return Runtime->GetSelector(Builder, E->getSelector()); } +Value *ScalarExprEmitter::VisitObjCProtocolExpr(ObjCProtocolExpr *E) { + // FIXME: This should pass the Decl not the name. + return Runtime->GenerateProtocolRef(Builder, E->getProtocol()->getName()); +} + Value *ScalarExprEmitter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { // Emit subscript expressions in rvalue context's. For most cases, this just // loads the lvalue formed by the subscript expr. However, we have to be diff --git a/clang/lib/CodeGen/CGObjCRuntime.h b/clang/lib/CodeGen/CGObjCRuntime.h index 5e8172b6651..d4f7bb07cd0 100644 --- a/clang/lib/CodeGen/CGObjCRuntime.h +++ b/clang/lib/CodeGen/CGObjCRuntime.h @@ -47,6 +47,10 @@ public: /// Generate an Objective-C message send operation virtual llvm::Value *GenerateMessageSend(BuilderType &Builder, const llvm::Type *ReturnTy, + // FIXME: This should be + // dropped, it is unused + // and generates a spurious + // load. llvm::Value *Sender, llvm::Value *Receiver, Selector Sel, @@ -81,17 +85,25 @@ public: const llvm::SmallVectorImpl &ClassMethodSels, const llvm::SmallVectorImpl &ClassMethodTypes, const llvm::SmallVectorImpl &Protocols) =0; - /// Generate a reference to the named protocol. - virtual llvm::Value *GenerateProtocolRef(llvm::IRBuilder &Builder, - const char *ProtocolName) = 0; virtual llvm::Value *GenerateMessageSendSuper(llvm::IRBuilder &Builder, const llvm::Type *ReturnTy, + // FIXME: This should + // be dropped, it is + // unused and + // generates a + // spurious load. llvm::Value *Sender, const char *SuperClassName, llvm::Value *Receiver, Selector Sel, llvm::Value** ArgV, unsigned ArgC) = 0; + + /// Emit the code to return the named protocol as an object, as in a + /// @protocol expression. + virtual llvm::Value *GenerateProtocolRef(llvm::IRBuilder &Builder, + const char *ProtocolName) = 0; + /// Generate the named protocol. Protocols contain method metadata but no /// implementations. virtual void GenerateProtocol(const char *ProtocolName, diff --git a/clang/lib/CodeGen/CodeGenTypes.cpp b/clang/lib/CodeGen/CodeGenTypes.cpp index ab0829e81fe..2d5bd12f928 100644 --- a/clang/lib/CodeGen/CodeGenTypes.cpp +++ b/clang/lib/CodeGen/CodeGenTypes.cpp @@ -306,6 +306,10 @@ const llvm::Type *CodeGenTypes::ConvertNewType(QualType T) { ConvertTypeRecursive(QualType(cast(Ty).getBaseType(), 0)); case Type::ObjCInterface: { + // FIXME: This comment is broken. Either the code should check for + // the flag it is referring to or it should do the right thing in + // the presence of it. + // Warning: Use of this is strongly discouraged. Late binding of instance // variables is supported on some runtimes and so using static binding can // break code when libraries are updated. Only use this if you have @@ -322,8 +326,8 @@ const llvm::Type *CodeGenTypes::ConvertNewType(QualType T) { break; case Type::ObjCQualifiedId: - assert(0 && "FIXME: add missing functionality here"); - break; + // Protocols don't influence the LLVM type. + return ConvertTypeRecursive(Context.getObjCIdType()); case Type::Tagged: { const TagDecl *TD = cast(Ty).getDecl(); -- cgit v1.2.3