Browse Source

Use a map to keep track of anonymous declarations else we cannot refer to them later when needed.

This could lead to self-referencing problems when parsing (and stack overflows!).
pull/14/head
triton 12 years ago
parent
commit
cd08295499
  1. 9
      src/AST/Namespace.cs
  2. 21
      src/Parser/Parser.cpp

9
src/AST/Namespace.cs

@ -20,6 +20,9 @@ namespace CppSharp.AST @@ -20,6 +20,9 @@ namespace CppSharp.AST
public List<Variable> Variables;
public List<Event> Events;
// Used to keep track of anonymous declarations.
public Dictionary<ulong, Declaration> Anonymous;
public TranslationUnit TranslationUnit
{
get
@ -41,6 +44,12 @@ namespace CppSharp.AST @@ -41,6 +44,12 @@ namespace CppSharp.AST
Typedefs = new List<TypedefDecl>();
Variables = new List<Variable>();
Events = new List<Event>();
Anonymous = new Dictionary<ulong, Declaration>();
}
public Declaration FindAnonymous(ulong key)
{
return Anonymous.ContainsKey(key) ? Anonymous[key] : null;
}
public Namespace FindNamespace(string name)

21
src/Parser/Parser.cpp

@ -379,14 +379,30 @@ CppSharp::AST::Class^ Parser::WalkRecordCXX(clang::CXXRecordDecl* Record) @@ -379,14 +379,30 @@ CppSharp::AST::Class^ Parser::WalkRecordCXX(clang::CXXRecordDecl* Record)
assert(NS && "Expected a valid namespace");
bool isCompleteDefinition = Record->isCompleteDefinition();
auto Name = marshalString<E_UTF8>(GetTagDeclName(Record));
auto RC = NS->FindClass(Name, isCompleteDefinition, /*Create=*/false);
CppSharp::AST::Class^ RC = nullptr;
auto Name = marshalString<E_UTF8>(GetTagDeclName(Record));
auto HasEmptyName = Record->getDeclName().isEmpty();
if (HasEmptyName)
{
if (auto AR = NS->FindAnonymous((uint64_t)Record))
RC = safe_cast<CppSharp::AST::Class^>(AR);
}
else
{
RC = NS->FindClass(Name, isCompleteDefinition, /*Create=*/false);
}
if (RC)
return RC;
RC = NS->FindClass(Name, isCompleteDefinition, /*Create=*/true);
if (HasEmptyName)
NS->Anonymous[(uint64_t)Record] = RC;
if (!isCompleteDefinition)
return RC;
@ -467,6 +483,7 @@ CppSharp::AST::Class^ Parser::WalkRecordCXX(clang::CXXRecordDecl* Record) @@ -467,6 +483,7 @@ CppSharp::AST::Class^ Parser::WalkRecordCXX(clang::CXXRecordDecl* Record)
break;
}
case Decl::IndirectField: // FIXME: Handle indirect fields
break;
default:
{
auto Decl = WalkDeclaration(D);

Loading…
Cancel
Save