| 
8 | 8 | #include "CXTranslationUnit.h"  | 
9 | 9 | #include "CXType.h"  | 
10 | 10 | 
 
  | 
 | 11 | +#ifdef _MSC_VER  | 
11 | 12 | #pragma warning(push)  | 
12 | 13 | #pragma warning(disable : 4146 4244 4267 4291 4624 4996)  | 
 | 14 | +#endif  | 
13 | 15 | 
 
  | 
14 | 16 | #include <clang/Basic/SourceManager.h>  | 
15 | 17 | 
 
  | 
 | 18 | +#ifdef _MSC_VER  | 
16 | 19 | #pragma warning(pop)  | 
 | 20 | +#endif  | 
17 | 21 | 
 
  | 
18 | 22 | using namespace clang;  | 
19 | 23 | using namespace clang::cxcursor;  | 
@@ -61,6 +65,25 @@ bool isStmtOrExpr(CXCursorKind kind) {  | 
61 | 65 |     return clang_isStatement(kind) || clang_isExpression(kind);  | 
62 | 66 | }  | 
63 | 67 | 
 
  | 
 | 68 | +int64_t getVtblIdx(const GlobalDecl& d)  | 
 | 69 | +{  | 
 | 70 | +    const CXXMethodDecl* CMD = static_cast<const CXXMethodDecl*>(d.getDecl());  | 
 | 71 | +    if (VTableContextBase::hasVtableSlot(CMD)) {  | 
 | 72 | +        VTableContextBase* VTC = CMD->getASTContext().getVTableContext();  | 
 | 73 | + | 
 | 74 | +        if (MicrosoftVTableContext* MSVTC = dyn_cast<MicrosoftVTableContext>(VTC)) {  | 
 | 75 | +            MethodVFTableLocation ML = MSVTC->getMethodVFTableLocation(d);  | 
 | 76 | +            return ML.Index;  | 
 | 77 | +        }  | 
 | 78 | + | 
 | 79 | +        if (ItaniumVTableContext* IVTC = dyn_cast<ItaniumVTableContext>(VTC)) {  | 
 | 80 | +            return IVTC->getMethodVTableIndex(d);  | 
 | 81 | +        }  | 
 | 82 | +    }  | 
 | 83 | + | 
 | 84 | +    return -1;  | 
 | 85 | +}  | 
 | 86 | + | 
64 | 87 | CXCursor clangsharp_Cursor_getArgument(CXCursor C, unsigned i) {  | 
65 | 88 |     if (isDeclOrTU(C.kind)) {  | 
66 | 89 |         const Decl* D = getCursorDecl(C);  | 
@@ -4693,23 +4716,30 @@ CXCursor clangsharp_Cursor_getVBase(CXCursor C, unsigned i) {  | 
4693 | 4716 |     return clang_getNullCursor();  | 
4694 | 4717 | }  | 
4695 | 4718 | 
 
  | 
4696 |  | -int64_t clangsharp_Cursor_getVtblIdx(CXCursor C) {  | 
 | 4719 | +int64_t clangsharp_Cursor_getDtorVtblIdx(CXCursor C, CX_DestructorType dtor)  | 
 | 4720 | +{  | 
4697 | 4721 |     if (isDeclOrTU(C.kind)) {  | 
4698 | 4722 |         const Decl* D = getCursorDecl(C);  | 
4699 | 4723 | 
 
  | 
4700 |  | -        if (const CXXMethodDecl* CMD = dyn_cast<CXXMethodDecl>(D)) {  | 
4701 |  | -            if (VTableContextBase::hasVtableSlot(CMD)) {  | 
4702 |  | -                VTableContextBase* VTC = getASTUnit(getCursorTU(C))->getASTContext().getVTableContext();  | 
 | 4724 | +        if (const CXXDestructorDecl* CMD = dyn_cast<CXXDestructorDecl>(D)) {  | 
 | 4725 | +            return getVtblIdx(GlobalDecl(CMD, static_cast<CXXDtorType>(dtor)));  | 
 | 4726 | +        }  | 
 | 4727 | +    }  | 
 | 4728 | +    return -1;  | 
 | 4729 | +}  | 
4703 | 4730 | 
 
  | 
4704 |  | -                if (MicrosoftVTableContext* MSVTC = dyn_cast<MicrosoftVTableContext>(VTC)) {  | 
4705 |  | -                    MethodVFTableLocation ML = MSVTC->getMethodVFTableLocation(CMD);  | 
4706 |  | -                    return ML.Index;  | 
4707 |  | -                }  | 
 | 4731 | +int64_t clangsharp_Cursor_getVtblIdx(CXCursor C) {  | 
 | 4732 | +    if (isDeclOrTU(C.kind)) {  | 
 | 4733 | +        const Decl* D = getCursorDecl(C);  | 
4708 | 4734 | 
 
  | 
4709 |  | -                if (ItaniumVTableContext* IVTC = dyn_cast<ItaniumVTableContext>(VTC)) {  | 
4710 |  | -                    return IVTC->getMethodVTableIndex(CMD);  | 
4711 |  | -                }  | 
 | 4735 | +        if (const CXXMethodDecl* CMD = dyn_cast<CXXMethodDecl>(D)) {  | 
 | 4736 | +            int64_t dtorIdx = clangsharp_Cursor_getDtorVtblIdx(C, Deleting); // will test if CMD is a dtor  | 
 | 4737 | +            if (dtorIdx != -1) { // yes, it is a dtor  | 
 | 4738 | +                return dtorIdx;  | 
4712 | 4739 |             }  | 
 | 4740 | + | 
 | 4741 | +            // no, it is a regular method  | 
 | 4742 | +            return getVtblIdx(CMD);  | 
4713 | 4743 |         }  | 
4714 | 4744 |     }  | 
4715 | 4745 | 
 
  | 
 | 
0 commit comments