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

NullReferenceException in CppParser.ParseFile #1

Closed EgorBo closed 5 years ago

EgorBo commented 5 years ago

I am trying to parse this file: https://github.com/lemire/simdjson/blob/master/singleheader/simdjson.h (simdjson single header). using the following code:

var cpo = new CppParserOptions();
cpo.ConfigureForWindowsMsvc(CppTargetCpu.X86_64); 
//btw, I'd made ConfigureForWindowsMsvc static + fluent interface :-) 
cpo.AdditionalArguments.Add("-std=c++17");
var compilation = CppParser.ParseFile(@"C:\prj\simdjson.h", cpo);

but getting an NRE. The lib looks great! CppSharp is not that easy to use

xoofx commented 5 years ago

Thanks for the first issue logged... and that's a bug! 😱

This should be fixed by commit 34d3686f26b4dfe18abc509eff4b0d743281bfe9 and available shortly in 0.1.2

xoofx commented 5 years ago

Yeah, this kind of file like simdjson.h ìs not really great for CppAst, as it is not really a file supposed to be consumable by an interop layer, as it doesn't really export any functions and it also imports a vast amount of unsupported C++ constructs (by libclang) into the file.

EgorBo commented 5 years ago

@xoofx Thanks, going to try it anyway for SimdJsonSharp. Currently I generate these two files by hands: C++ to C: https://github.com/EgorBo/SimdJsonSharp/blob/master/src/BindingsForNativeLib/SimdJsonNative/bindings.cpp C# DllImports: https://github.com/EgorBo/SimdJsonSharp/blob/master/src/BindingsForNativeLib/SimdJsonSharp.Bindings/Bindings.cs

xoofx commented 5 years ago

Oh right, yes, you should be able to generate these easily. Let me know if it doesn't work!