From 751e0da4e3330a35ef0e0ef8d8eb6682ccdadc8f Mon Sep 17 00:00:00 2001 From: triton Date: Sun, 4 Aug 2013 06:13:57 +0100 Subject: [PATCH] Keep the original pointer that originated the AST declaration node and check if we have already processed the method in WalkMethodCXX (if so, just return the already existing declaration). We depend on this to get the right method instance when walking through the vtable methods. --- src/AST/Declaration.cs | 3 +++ src/Parser/Parser.cpp | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/AST/Declaration.cs b/src/AST/Declaration.cs index 94f85ecc..97d62221 100644 --- a/src/AST/Declaration.cs +++ b/src/AST/Declaration.cs @@ -193,6 +193,9 @@ namespace CppSharp.AST // List of preprocessed entities attached to this declaration. public IList PreprocessedEntities; + // Pointer to the original declaration from Clang. + public IntPtr OriginalPtr; + protected Declaration() { IgnoreFlags = IgnoreFlags.None; diff --git a/src/Parser/Parser.cpp b/src/Parser/Parser.cpp index 6230afa4..7589272d 100644 --- a/src/Parser/Parser.cpp +++ b/src/Parser/Parser.cpp @@ -744,6 +744,20 @@ CppSharp::AST::Method^ Parser::WalkMethodCXX(clang::CXXMethodDecl* MD) { using namespace clang; + // We could be in a redeclaration, so process the primary context. + if (MD->getPrimaryContext() != MD) + return WalkMethodCXX(cast(MD->getPrimaryContext())); + + auto RD = MD->getParent(); + auto Class = WalkRecordCXX(RD); + + // Check for an already existing method that came from the same declaration. + for each (CppSharp::AST::Method^ Method in Class->Methods) + { + if (Method->OriginalPtr.ToPointer() == MD) + return Method; + } + DeclarationName Name = MD->getDeclName(); CppSharp::AST::Method^ Method = gcnew CppSharp::AST::Method(); @@ -1466,6 +1480,7 @@ void Parser::WalkFunction(clang::FunctionDecl* FD, CppSharp::AST::Function^ F, auto NS = GetNamespace(FD); assert(NS && "Expected a valid namespace"); + F->OriginalPtr = System::IntPtr(FD); F->Name = marshalString(FD->getNameAsString()); F->Namespace = NS; F->IsVariadic = FD->isVariadic();