[prev in list] [next in list] [prev in thread] [next in thread] 

List:       cfe-dev
Subject:    Re: [cfe-dev] Issue with cindex parsing on python: Can't parse function that returns a std::vector<s
From:       David Blaikie via cfe-dev <cfe-dev () lists ! llvm ! org>
Date:       2018-10-28 21:03:19
Message-ID: CAENS6EsRKz0xdXiSZw=s+waPd39xWch-3sNHQ-JgJSy3R1ozaQ () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


On Sun, Oct 28, 2018 at 1:55 PM Tarcísio Fischer <
tarcisio.fischer.cco@gmail.com> 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 <dblaikie@gmail.com>
> 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 <
>> cfe-dev@lists.llvm.org> 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?
>>>
>>> https://pastebin.com/TF3RLibt
>>>
>>> Results on my machine:
>>>
>>> t.cpp (TypeKind.INVALID)
>>>
>>> ****************************************************************************************************
>>> t.cpp (TypeKind.INVALID)
>>>  example() (TypeKind.FUNCTIONPROTO)
>>>    (TypeKind.INVALID)
>>>     (TypeKind.INVALID)
>>> _______________________________________________
>>> cfe-dev mailing list
>>> cfe-dev@lists.llvm.org
>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>>>
>>

[Attachment #5 (text/html)]

<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Sun, Oct 28, 2018 \
at 1:55 PM Tarcísio Fischer &lt;<a \
href="mailto:tarcisio.fischer.cco@gmail.com">tarcisio.fischer.cco@gmail.com</a>&gt; \
wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 \
.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr"><div \
dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif">Hi, \
David. Thanks for the response!</div><div class="gmail_default" \
style="font-family:verdana,sans-serif"><br></div><div class="gmail_default" \
style="font-family:verdana,sans-serif">As far as I understand, since I&#39;m using \
`-std=c++11` option, it SHOULD be right. Anyway, I tried your suggestion, and it did \
not work (Same problem) :( I&#39;ll leave the link here just for reference:  <a \
href="https://pastebin.com/jvQev5eb" \
target="_blank">https://pastebin.com/jvQev5eb</a></div></div></div></div></blockquote><div><br>Ah, \
right - sorry, didn&#39;t spot that you were already specifying -std=c++11<br>  \
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div \
class="gmail_default" style="font-family:verdana,sans-serif">Good news is... After \
trying a bit more, I managed to make the code work. Turns out it as a missing \
`#include &lt;vector&gt;`. I don&#39;t know why the first example works, (Now I \
believe none of them should work). Here&#39;s the working example:  <a \
href="https://pastebin.com/Setuw9cF" \
target="_blank">https://pastebin.com/Setuw9cF</a><br></div><div class="gmail_default" \
style="font-family:verdana,sans-serif"><br></div><div class="gmail_default" \
style="font-family:verdana,sans-serif">Does anyone knows why the first example was \
working, even with the missing \
include?</div></div></div></div></blockquote><div><br>Yep - C++ is a context \
sensitive language, without seeing the declaration of std::vector as a template, the \
compiler has to parse &quot;std::vector&lt;T&gt;&quot; as &quot;(std::vector &lt; T) \
&gt;&quot; - which fails once it&#39;s apparent that T is a type, not a variable that \
can be less-than (&lt;) compared, etc... - so things go off the rails pretty \
quickly.<br><br>- Dave<br>  </div><blockquote class="gmail_quote" style="margin:0 0 0 \
.8ex;border-left:1px #ccc solid;padding-left:1ex"><br><div class="gmail_quote"><div \
dir="ltr">Em sáb, 27 de out de 2018 às 14:31, David Blaikie &lt;<a \
href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>&gt; \
escreveu:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 \
.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Are you parsing as \
C++98 (the default, I think? That code is invalid C++98/C++03, I think (because the \
&quot;&gt;&gt;&quot; 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.</div><br><div class="gmail_quote"><div dir="ltr">On Fri, Oct 26, 2018 at 2:17 \
PM Tarcísio Fischer via cfe-dev &lt;<a href="mailto:cfe-dev@lists.llvm.org" \
target="_blank">cfe-dev@lists.llvm.org</a>&gt; wrote:<br></div><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"><div dir="ltr"><div class="gmail_default" \
style="font-family:verdana,sans-serif"><div class="gmail_default">Hello. I&#39;m new \
with the clang python bindings (<a \
href="https://github.com/llvm-mirror/clang/tree/master/bindings/python" \
target="_blank">https://github.com/llvm-mirror/clang/tree/master/bindings/python</a>), \
and I&#39;m mostly basing my tests on the test examples on  <a \
href="https://github.com/llvm-mirror/clang/tree/master/bindings/python/tests/cindex" \
target="_blank">https://github.com/llvm-mirror/clang/tree/master/bindings/python/tests/cindex</a> \
. Feel free to suggest any better documentation.</div><div \
class="gmail_default"><br></div><div class="gmail_default">For the following example, \
I&#39;d expect the two results to be similar, but the first one isn&#39;t getting any \
data about the function `example`. Does anyone know why?</div><div \
class="gmail_default"><br></div><div class="gmail_default" \
style="font-family:Arial,Helvetica,sans-serif"><font face="verdana, sans-serif"><a \
href="https://pastebin.com/TF3RLibt" \
target="_blank">https://pastebin.com/TF3RLibt</a></font><br></div><div \
class="gmail_default" style="font-family:Arial,Helvetica,sans-serif"><font \
face="verdana, sans-serif"><br></font></div><div class="gmail_default" \
style="font-family:Arial,Helvetica,sans-serif"><font face="verdana, \
sans-serif">Results on my machine:</font></div><div class="gmail_default" \
style="font-family:Arial,Helvetica,sans-serif"><font face="verdana, \
sans-serif"><br></font></div><div class="gmail_default" \
style="font-family:Arial,Helvetica,sans-serif"><div class="gmail_default"><font \
face="monospace, monospace">t.cpp (TypeKind.INVALID)</font></div><div \
class="gmail_default"><font face="monospace, \
monospace">****************************************************************************************************</font></div><div \
class="gmail_default"><font face="monospace, monospace">t.cpp \
(TypeKind.INVALID)</font></div><div class="gmail_default"><font face="monospace, \
monospace">  example() (TypeKind.FUNCTIONPROTO)</font></div><div \
class="gmail_default"><font face="monospace, monospace">     \
(TypeKind.INVALID)</font></div><div class="gmail_default"><font face="monospace, \
monospace">      (TypeKind.INVALID)</font></div></div></div></div> \
_______________________________________________<br> cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" \
target="_blank">cfe-dev@lists.llvm.org</a><br> <a \
href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" \
target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br> \
</blockquote></div> </blockquote></div>
</blockquote></div></div>


[Attachment #6 (text/plain)]

_______________________________________________
cfe-dev mailing list
cfe-dev@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic