xoofx / CppAst.NET

CppAst is a .NET library providing a C/C++ parser for header files powered by Clang/libclang with access to the full AST, comments and macros
BSD 2-Clause "Simplified" License
482 stars 63 forks source link

Try to parse Urho3D headers #4

Closed OmidID closed 5 years ago

OmidID commented 5 years ago

I try to bind Urho3D header files and I got an error

Error: System.ArgumentException: 'An item with the same key has already been added. Key: c:@T@RPCNOTIFICATION_ROUTINE'

   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
   at CppAst.CppModelBuilder.VisitTypeDefDecl(CXCursor cursor, CXCursor parent, CXClientData data)
   at CppAst.CppModelBuilder.VisitMember(CXCursor cursor, CXCursor parent, CXClientData data)
   at CppAst.CppModelBuilder.VisitTranslationUnit(CXCursor cursor, CXCursor parent, CXClientData data)
   at ClangSharp.clang.visitChildren(CXCursor parent, CXCursorVisitor visitor, CXClientData client_data)
   at CppAst.CppParser.ParseInternal(List`1 cppFiles, CppParserOptions options)
   at CppAst.CppParser.ParseFiles(List`1 cppFilenameList, CppParserOptions options)
   at SimdJson.Program.Main(String[] args)

It's weird I can see in there is a checking before add new item to typedefs. I cannot understand why it's will be pass the checking duplicate item! https://github.com/xoofx/CppAst/blob/0.3.0/src/CppAst/CppModelBuilder.cs#L1359

xoofx commented 5 years ago

I don't know much about Urho3D, what are the steps to reproduce this on my side?

OmidID commented 5 years ago

You can download it from the link below: https://sourceforge.net/projects/urho3d/files/latest/download Then you can find headers in include directory.

Actually Egor Bogatov working on a new project base on CppAst and I using that. https://github.com/EgorBo/CppPinvokeGenerator

I used simple parameters and that set

var options = new CppParserOptions();
options.ConfigureForWindowsMsvc(CppTargetCpu.X86_64);
options.AdditionalArguments.Add("-std=c++17");
options.IncludeFolders.Add(outputFolder);
options.IncludeFolders.Add(Path.Combine(outputFolder, "Urho3D", "ThirdParty"));
CppCompilation compilation = CppParser.ParseFile(Path.Combine(outputFolder, @"Urho3DAll.h"), options);
xoofx commented 5 years ago

Fixed by 474d568 available in 0.4.0+