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
501 stars 66 forks source link

CppParserOptions.ParseMacros null reference using windows headers #35

Closed amerkoleci closed 4 years ago

amerkoleci commented 4 years ago

Hi, I'm trying to parse windows headers (d3d11.h) in this case and if I set ParseMacros to true it crashes internally with NullReferenceException.

var sdkPath = @"C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um";
            var options = new CppParserOptions
            {
                ParseMacros = true,
            };
            options.SystemIncludeFolders.Add(sdkPath);
            var headerFile = "d3d11.h";
            var compilation = CppParser.ParseFile(Path.Combine(sdkPath, headerFile), options); /* Crash here */

StackTrace:

   at CppAst.CppModelBuilder.ParseMacro(CXCursor cursor)
   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 CppAst.CppParser.ParseFile(String cppFilename, CppParserOptions options)
   at ConsoleApp2.Program.Main(String[] args) in C:\Test\Program.cs:line 45

Any thought?

xoofx commented 4 years ago

No idea, It requires debugging, if you can investigate.

StephenHodgson commented 4 years ago

I'd check out https://github.com/microsoft/CsWinRT

That should give you the CS API access for the windows types you're looking for