clang API Documentation
00001 //===------- MicrosoftCXXABI.cpp - AST support for the Microsoft 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 Microsoft Visual C++ 00011 // ABI. 00012 // 00013 //===----------------------------------------------------------------------===// 00014 00015 #include "CXXABI.h" 00016 #include "clang/AST/ASTContext.h" 00017 #include "clang/AST/DeclCXX.h" 00018 #include "clang/AST/RecordLayout.h" 00019 #include "clang/AST/Type.h" 00020 #include "clang/Basic/TargetInfo.h" 00021 00022 using namespace clang; 00023 00024 namespace { 00025 class MicrosoftCXXABI : public CXXABI { 00026 ASTContext &Context; 00027 public: 00028 MicrosoftCXXABI(ASTContext &Ctx) : Context(Ctx) { } 00029 00030 unsigned getMemberPointerSize(const MemberPointerType *MPT) const; 00031 00032 CallingConv getDefaultMethodCallConv() const { 00033 if (Context.getTargetInfo().getTriple().getArch() == llvm::Triple::x86) 00034 return CC_X86ThisCall; 00035 else 00036 return CC_C; 00037 } 00038 00039 bool isNearlyEmpty(const CXXRecordDecl *RD) const { 00040 // FIXME: Audit the corners 00041 if (!RD->isDynamicClass()) 00042 return false; 00043 00044 const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD); 00045 00046 // In the Microsoft ABI, classes can have one or two vtable pointers. 00047 CharUnits PointerSize = 00048 Context.toCharUnitsFromBits(Context.getTargetInfo().getPointerWidth(0)); 00049 return Layout.getNonVirtualSize() == PointerSize || 00050 Layout.getNonVirtualSize() == PointerSize * 2; 00051 } 00052 }; 00053 } 00054 00055 unsigned MicrosoftCXXABI::getMemberPointerSize(const MemberPointerType *MPT) const { 00056 QualType Pointee = MPT->getPointeeType(); 00057 CXXRecordDecl *RD = MPT->getClass()->getAsCXXRecordDecl(); 00058 if (RD->getNumVBases() > 0) { 00059 if (Pointee->isFunctionType()) 00060 return 3; 00061 else 00062 return 2; 00063 } else if (RD->getNumBases() > 1 && Pointee->isFunctionType()) 00064 return 2; 00065 return 1; 00066 } 00067 00068 CXXABI *clang::CreateMicrosoftCXXABI(ASTContext &Ctx) { 00069 return new MicrosoftCXXABI(Ctx); 00070 } 00071