]> granicus.if.org Git - clang/blob - lib/CodeGen/CGObjCRuntime.h
Fix Obj-C super sends inside class methods.
[clang] / lib / CodeGen / CGObjCRuntime.h
1 //===----- CGObjCRuntime.h - Interface to ObjC Runtimes ---------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This provides an abstract class for Objective-C code generation.  Concrete
11 // subclasses of this implement code generation for specific Objective-C
12 // runtime libraries.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef CLANG_CODEGEN_OBCJRUNTIME_H
17 #define CLANG_CODEGEN_OBCJRUNTIME_H
18 #include "clang/Basic/IdentifierTable.h" // Selector
19 #include "llvm/ADT/SmallVector.h"
20 #include "llvm/Support/IRBuilder.h"
21 #include <string>
22
23 #include "CGValue.h"
24
25 namespace llvm {
26   class Constant;
27   class Type;
28   class Value;
29   class Module;
30   class Function;
31 }
32
33 namespace clang {
34   namespace CodeGen {
35     class CodeGenFunction;
36   }
37
38   class ObjCCategoryImplDecl;
39   class ObjCImplementationDecl;
40   class ObjCInterfaceDecl;
41   class ObjCMessageExpr;
42   class ObjCMethodDecl;
43   class ObjCProtocolDecl;
44   class Selector;
45
46 namespace CodeGen {
47   class CodeGenModule;
48
49 //FIXME Several methods should be pure virtual but aren't to avoid the
50 //partially-implemented subclass breaking.
51
52 /// Implements runtime-specific code generation functions.
53 class CGObjCRuntime {
54   typedef llvm::IRBuilder<> BuilderType;
55
56 public:
57   virtual ~CGObjCRuntime();
58
59   /// Generate the function required to register all Objective-C components in
60   /// this compilation unit with the runtime library.
61   virtual llvm::Function *ModuleInitFunction() = 0;
62
63   /// Get a selector for the specified name and type values. The
64   /// return value should have the LLVM type for pointer-to
65   /// ASTContext::getObjCSelType().
66   virtual llvm::Value *GetSelector(BuilderType &Builder,
67                                    Selector Sel) = 0;
68
69   /// Generate a constant string object.
70   virtual llvm::Constant *GenerateConstantString(const std::string &String) = 0;
71
72   /// Generate a category.  A category contains a list of methods (and
73   /// accompanying metadata) and a list of protocols.
74   virtual void GenerateCategory(const ObjCCategoryImplDecl *OCD) = 0;
75
76   /// Generate a class stucture for this class.
77   virtual void GenerateClass(const ObjCImplementationDecl *OID) = 0;
78   
79   /// Generate an Objective-C message send operation.
80   virtual CodeGen::RValue 
81   GenerateMessageSend(CodeGen::CodeGenFunction &CGF,
82                       const ObjCMessageExpr *E,
83                       llvm::Value *Receiver,
84                       bool IsClassMessage) = 0;
85
86   /// Generate an Objective-C message send operation to the super
87   /// class initiated in a method for Class and with the given Self
88   /// object.
89   virtual CodeGen::RValue
90   GenerateMessageSendSuper(CodeGen::CodeGenFunction &CGF,
91                            const ObjCMessageExpr *E,
92                            const ObjCInterfaceDecl *Class,
93                            llvm::Value *Self,
94                            bool IsClassMessage) = 0;
95
96   /// Emit the code to return the named protocol as an object, as in a
97   /// @protocol expression.
98   virtual llvm::Value *GenerateProtocolRef(llvm::IRBuilder<true> &Builder,
99                                            const ObjCProtocolDecl *OPD) = 0;
100
101   /// Generate the named protocol.  Protocols contain method metadata but no 
102   /// implementations. 
103   virtual void GenerateProtocol(const ObjCProtocolDecl *OPD) = 0;
104
105   /// Generate a function preamble for a method with the specified
106   /// types.  
107
108   // FIXME: Current this just generates the Function definition, but
109   // really this should also be generating the loads of the
110   // parameters, as the runtime should have full control over how
111   // parameters are passed.
112   virtual llvm::Function *GenerateMethod(const ObjCMethodDecl *OMD) = 0;
113
114   /// GetClass - Return a reference to the class for the given
115   /// interface decl.
116   virtual llvm::Value *GetClass(BuilderType &Builder, 
117                                 const ObjCInterfaceDecl *OID) = 0;
118
119   /// If instance variable addresses are determined at runtime then this should
120   /// return true, otherwise instance variables will be accessed directly from
121   /// the structure.  If this returns true then @defs is invalid for this
122   /// runtime and a warning should be generated.
123   virtual bool LateBoundIVars() { return false; }
124 };
125
126 /// Creates an instance of an Objective-C runtime class.  
127 //TODO: This should include some way of selecting which runtime to target.
128 CGObjCRuntime *CreateGNUObjCRuntime(CodeGenModule &CGM);
129 CGObjCRuntime *CreateMacObjCRuntime(CodeGenModule &CGM);
130 }
131 }
132 #endif