clang API Documentation

AST/ItaniumCXXABI.cpp
Go to the documentation of this file.
00001 //===------- ItaniumCXXABI.cpp - AST support for the Itanium C++ ABI ------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This provides C++ AST support targeting the Itanium C++ ABI, which is
00011 // documented at:
00012 //  http://www.codesourcery.com/public/cxx-abi/abi.html
00013 //  http://www.codesourcery.com/public/cxx-abi/abi-eh.html
00014 //
00015 // It also supports the closely-related ARM C++ ABI, documented at:
00016 // http://infocenter.arm.com/help/topic/com.arm.doc.ihi0041c/IHI0041C_cppabi.pdf
00017 //
00018 //===----------------------------------------------------------------------===//
00019 
00020 #include "CXXABI.h"
00021 #include "clang/AST/ASTContext.h"
00022 #include "clang/AST/RecordLayout.h"
00023 #include "clang/AST/DeclCXX.h"
00024 #include "clang/AST/Type.h"
00025 #include "clang/Basic/TargetInfo.h"
00026 
00027 using namespace clang;
00028 
00029 namespace {
00030 class ItaniumCXXABI : public CXXABI {
00031 protected:
00032   ASTContext &Context;
00033 public:
00034   ItaniumCXXABI(ASTContext &Ctx) : Context(Ctx) { }
00035 
00036   unsigned getMemberPointerSize(const MemberPointerType *MPT) const {
00037     QualType Pointee = MPT->getPointeeType();
00038     if (Pointee->isFunctionType()) return 2;
00039     return 1;
00040   }
00041 
00042   CallingConv getDefaultMethodCallConv() const {
00043     return CC_C;
00044   }
00045 
00046   // We cheat and just check that the class has a vtable pointer, and that it's
00047   // only big enough to have a vtable pointer and nothing more (or less).
00048   bool isNearlyEmpty(const CXXRecordDecl *RD) const {
00049 
00050     // Check that the class has a vtable pointer.
00051     if (!RD->isDynamicClass())
00052       return false;
00053 
00054     const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD);
00055     CharUnits PointerSize = 
00056       Context.toCharUnitsFromBits(Context.getTargetInfo().getPointerWidth(0));
00057     return Layout.getNonVirtualSize() == PointerSize;
00058   }
00059 };
00060 
00061 class ARMCXXABI : public ItaniumCXXABI {
00062 public:
00063   ARMCXXABI(ASTContext &Ctx) : ItaniumCXXABI(Ctx) { }
00064 };
00065 }
00066 
00067 CXXABI *clang::CreateItaniumCXXABI(ASTContext &Ctx) {
00068   return new ItaniumCXXABI(Ctx);
00069 }
00070 
00071 CXXABI *clang::CreateARMCXXABI(ASTContext &Ctx) {
00072   return new ARMCXXABI(Ctx);
00073 }