Issue with cindex parsing on python: Can't parse function that returns a std::vector<std::vector<int>>

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Issue with cindex parsing on python: Can't parse function that returns a std::vector<std::vector<int>>

David Blaikie via cfe-dev
Hello. I'm new with the clang python bindings (https://github.com/llvm-mirror/clang/tree/master/bindings/python), and I'm mostly basing my tests on the test examples on https://github.com/llvm-mirror/clang/tree/master/bindings/python/tests/cindex . Feel free to suggest any better documentation.

For the following example, I'd expect the two results to be similar, but the first one isn't getting any data about the function `example`. Does anyone know why?


Results on my machine:

t.cpp (TypeKind.INVALID)
****************************************************************************************************
t.cpp (TypeKind.INVALID)
 example() (TypeKind.FUNCTIONPROTO)
   (TypeKind.INVALID)
    (TypeKind.INVALID)

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Issue with cindex parsing on python: Can't parse function that returns a std::vector<std::vector<int>>

David Blaikie via cfe-dev
Are you parsing as C++98 (the default, I think? That code is invalid C++98/C++03, I think (because the ">>" is interpreted as a right shift operator, not the end of two template argument lists). In C++11 and above, it should do the right thing.

On Fri, Oct 26, 2018 at 2:17 PM Tarcísio Fischer via cfe-dev <[hidden email]> wrote:
Hello. I'm new with the clang python bindings (https://github.com/llvm-mirror/clang/tree/master/bindings/python), and I'm mostly basing my tests on the test examples on https://github.com/llvm-mirror/clang/tree/master/bindings/python/tests/cindex . Feel free to suggest any better documentation.

For the following example, I'd expect the two results to be similar, but the first one isn't getting any data about the function `example`. Does anyone know why?


Results on my machine:

t.cpp (TypeKind.INVALID)
****************************************************************************************************
t.cpp (TypeKind.INVALID)
 example() (TypeKind.FUNCTIONPROTO)
   (TypeKind.INVALID)
    (TypeKind.INVALID)
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Issue with cindex parsing on python: Can't parse function that returns a std::vector<std::vector<int>>

David Blaikie via cfe-dev
Hi, David. Thanks for the response!

As far as I understand, since I'm using `-std=c++11` option, it SHOULD be right. Anyway, I tried your suggestion, and it did not work (Same problem) :( I'll leave the link here just for reference: https://pastebin.com/jvQev5eb

Good news is... After trying a bit more, I managed to make the code work. Turns out it as a missing `#include <vector>`. I don't know why the first example works, (Now I believe none of them should work). Here's the working example: https://pastebin.com/Setuw9cF

Does anyone knows why the first example was working, even with the missing include?

Em sáb, 27 de out de 2018 às 14:31, David Blaikie <[hidden email]> escreveu:
Are you parsing as C++98 (the default, I think? That code is invalid C++98/C++03, I think (because the ">>" is interpreted as a right shift operator, not the end of two template argument lists). In C++11 and above, it should do the right thing.

On Fri, Oct 26, 2018 at 2:17 PM Tarcísio Fischer via cfe-dev <[hidden email]> wrote:
Hello. I'm new with the clang python bindings (https://github.com/llvm-mirror/clang/tree/master/bindings/python), and I'm mostly basing my tests on the test examples on https://github.com/llvm-mirror/clang/tree/master/bindings/python/tests/cindex . Feel free to suggest any better documentation.

For the following example, I'd expect the two results to be similar, but the first one isn't getting any data about the function `example`. Does anyone know why?


Results on my machine:

t.cpp (TypeKind.INVALID)
****************************************************************************************************
t.cpp (TypeKind.INVALID)
 example() (TypeKind.FUNCTIONPROTO)
   (TypeKind.INVALID)
    (TypeKind.INVALID)
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Issue with cindex parsing on python: Can't parse function that returns a std::vector<std::vector<int>>

David Blaikie via cfe-dev


On Sun, Oct 28, 2018 at 1:55 PM Tarcísio Fischer <[hidden email]> wrote:
Hi, David. Thanks for the response!

As far as I understand, since I'm using `-std=c++11` option, it SHOULD be right. Anyway, I tried your suggestion, and it did not work (Same problem) :( I'll leave the link here just for reference: https://pastebin.com/jvQev5eb

Ah, right - sorry, didn't spot that you were already specifying -std=c++11
 
Good news is... After trying a bit more, I managed to make the code work. Turns out it as a missing `#include <vector>`. I don't know why the first example works, (Now I believe none of them should work). Here's the working example: https://pastebin.com/Setuw9cF

Does anyone knows why the first example was working, even with the missing include?

Yep - C++ is a context sensitive language, without seeing the declaration of std::vector as a template, the compiler has to parse "std::vector<T>" as "(std::vector < T) >" - which fails once it's apparent that T is a type, not a variable that can be less-than (<) compared, etc... - so things go off the rails pretty quickly.

- Dave
 

Em sáb, 27 de out de 2018 às 14:31, David Blaikie <[hidden email]> escreveu:
Are you parsing as C++98 (the default, I think? That code is invalid C++98/C++03, I think (because the ">>" is interpreted as a right shift operator, not the end of two template argument lists). In C++11 and above, it should do the right thing.

On Fri, Oct 26, 2018 at 2:17 PM Tarcísio Fischer via cfe-dev <[hidden email]> wrote:
Hello. I'm new with the clang python bindings (https://github.com/llvm-mirror/clang/tree/master/bindings/python), and I'm mostly basing my tests on the test examples on https://github.com/llvm-mirror/clang/tree/master/bindings/python/tests/cindex . Feel free to suggest any better documentation.

For the following example, I'd expect the two results to be similar, but the first one isn't getting any data about the function `example`. Does anyone know why?


Results on my machine:

t.cpp (TypeKind.INVALID)
****************************************************************************************************
t.cpp (TypeKind.INVALID)
 example() (TypeKind.FUNCTIONPROTO)
   (TypeKind.INVALID)
    (TypeKind.INVALID)
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev