bytedeco / javacpp

The missing bridge between Java and native C++
Other
4.43k stars 576 forks source link

Add support variadic templates #81

Open ashleyj opened 8 years ago

ashleyj commented 8 years ago

Add support for variadic templates

eg.

template <typename... Arguments> returntype functionname(Arguments... args);

or

template<typename ...Arguments> class classname;

Currently this throws an NPE:

Caused by: java.lang.NullPointerException
    at org.bytedeco.javacpp.tools.Parser.parameters(Parser.java:1366)
    at org.bytedeco.javacpp.tools.Parser.declarator(Parser.java:845)
    at org.bytedeco.javacpp.tools.Parser.function(Parser.java:1457)
    at org.bytedeco.javacpp.tools.Parser.declarations(Parser.java:2639)
    at org.bytedeco.javacpp.tools.Parser.group(Parser.java:2214)
    at org.bytedeco.javacpp.tools.Parser.declarations(Parser.java:2638)
    at org.bytedeco.javacpp.tools.Parser.namespace(Parser.java:2544)
    at org.bytedeco.javacpp.tools.Parser.declarations(Parser.java:2637)
    at org.bytedeco.javacpp.tools.Parser.parse(Parser.java:2713)
    at org.bytedeco.javacpp.tools.Parser.parse(Parser.java:2806)
    at org.bytedeco.javacpp.tools.Builder.parse(Builder.java:69)
    at org.bytedeco.javacpp.tools.Builder.build(Builder.java:625)
    at org.bytedeco.javacpp.tools.BuildMojo.execute(BuildMojo.java:226)```
saudet commented 8 years ago

That's quite a complicated feature, but fortunately it doesn't look like even LLVM makes heavy use of it. Implementing something that assumes that only the last argument can be variadic should be good enough?

ashleyj commented 8 years ago

I feel like I've created a lot of work for you over the last two weeks. I apologise, but appreciate the work you've done :)

I think that will work -- only having the last argument as variadic...

saudet commented 8 years ago

No problem, the other things didn't take long to fix. This might take a bit more time though... Anyway, I'm glad to have someone looking at the C++ API of LLVM :) Thank you for that!

saudet commented 8 years ago

It just clicked today, but I figured we might not really need to support variadic templates for the current parser. The next big thing I'd like to try is to use Clang as parser and see how far we can go with this, see #51. To get there though, we first need access to the C++ API of Clang, so I've fixed the crash you found in the current parser. It's basically ignoring the templates, but it's also ignoring normal variadic functions, so nothing new here. Anyway, please let me know if you encounter any more crashes or problems with LLVM. We might not need the whole API for the portion of it that could be useful as a better parser for JavaCPP. :)

And thanks for having reported the issues you found up until now!