]> granicus.if.org Git - clang/commitdiff
Refactor.
authorMike Stump <mrs@apple.com>
Wed, 12 Aug 2009 23:00:59 +0000 (23:00 +0000)
committerMike Stump <mrs@apple.com>
Wed, 12 Aug 2009 23:00:59 +0000 (23:00 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@78854 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGCXX.cpp
lib/CodeGen/CodeGenFunction.h

index 80781ad934d74c40960a361366d5d4b5e9caaf11..e63bd7c87e0d18a7f414acff2db67ebf04aa28f1 100644 (file)
@@ -621,6 +621,22 @@ llvm::Constant *CodeGenFunction::GenerateRtti(const CXXRecordDecl *RD) {
   return Rtti;
 }
 
+void CodeGenFunction::GenerateMethods(std::vector<llvm::Constant *> &methods,
+                                      const CXXRecordDecl *RD,
+                                      llvm::Type *Ptr8Ty) {
+  typedef CXXRecordDecl::method_iterator meth_iter;
+  llvm::Constant *m;
+
+  for (meth_iter mi = RD->method_begin(), me = RD->method_end(); mi != me;
+       ++mi) {
+    if (mi->isVirtual()) {
+      m = CGM.GetAddrOfFunction(GlobalDecl(*mi));
+      m = llvm::ConstantExpr::getBitCast(m, Ptr8Ty);
+      methods.push_back(m);
+    }
+  }
+}
+
 void CodeGenFunction::GenerateVtableForBase(const CXXRecordDecl *RD,
                                             const CXXRecordDecl *Class,
                                             llvm::Constant *rtti,
@@ -700,29 +716,13 @@ void CodeGenFunction::GenerateVtableForBase(const CXXRecordDecl *RD,
   }
 
   if (!isPrimary) {
-    if (!RD)
-      return;
-
-    for (meth_iter mi = RD->method_begin(), me = RD->method_end(); mi != me;
-         ++mi) {
-      if (mi->isVirtual()) {
-        m = CGM.GetAddrOfFunction(GlobalDecl(*mi));
-        m = llvm::ConstantExpr::getBitCast(m, Ptr8Ty);
-        methods.push_back(m);
-      }
-    }
+    if (RD)
+      GenerateMethods(methods, RD, Ptr8Ty);
     return;
   }
 
   // And add the virtuals for the class to the primary vtable.
-  for (meth_iter mi = Class->method_begin(), me = Class->method_end(); mi != me;
-       ++mi) {
-    if (mi->isVirtual()) {
-      m = CGM.GetAddrOfFunction(GlobalDecl(*mi));
-      m = llvm::ConstantExpr::getBitCast(m, Ptr8Ty);
-      methods.push_back(m);
-    }
-  }
+  GenerateMethods(methods, Class, Ptr8Ty);
 }
 
 llvm::Value *CodeGenFunction::GenerateVtable(const CXXRecordDecl *RD) {
index 226c272c318bbc6ea7b192ef53c8ed9074e1fbe3..75dd3f55f9031bbefe86fe2c5d45209d7f955436 100644 (file)
@@ -359,6 +359,8 @@ public:
   void FinishFunction(SourceLocation EndLoc=SourceLocation());
 
   llvm::Constant *GenerateRtti(const CXXRecordDecl *RD);
+  void GenerateMethods(std::vector<llvm::Constant *> &methods,
+                       const CXXRecordDecl *RD, llvm::Type *Ptr8Ty);
   void GenerateVtableForBase(const CXXRecordDecl *RD,
                              const CXXRecordDecl *Class,
                              llvm::Constant *rtti,