Browse Source

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.
pull/22/merge
triton 12 years ago
parent
commit
751e0da4e3
  1. 3
      src/AST/Declaration.cs
  2. 15
      src/Parser/Parser.cpp

3
src/AST/Declaration.cs

@ -193,6 +193,9 @@ namespace CppSharp.AST @@ -193,6 +193,9 @@ namespace CppSharp.AST
// List of preprocessed entities attached to this declaration.
public IList<PreprocessedEntity> PreprocessedEntities;
// Pointer to the original declaration from Clang.
public IntPtr OriginalPtr;
protected Declaration()
{
IgnoreFlags = IgnoreFlags.None;

15
src/Parser/Parser.cpp

@ -744,6 +744,20 @@ CppSharp::AST::Method^ Parser::WalkMethodCXX(clang::CXXMethodDecl* MD) @@ -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<CXXMethodDecl>(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, @@ -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<E_UTF8>(FD->getNameAsString());
F->Namespace = NS;
F->IsVariadic = FD->isVariadic();

Loading…
Cancel
Save