Python/CIndex include file support

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

Python/CIndex include file support

Andrew Sutton
Attached is a patch that implements include file traversal support for the Python binding's TranslationUnit class (plus a test case and a small example program).

The new TranslationUnit.includes property returns a sequence of tuples containing the including file (or None for the "inclusion" of the TU source file), the included file, the source location and the include depth. Basically, it returns an attributed edge list (graph).

I also wrote a small example utility that dumps the include graph as a Graphviz dot file.

Andrew Sutton
[hidden email]

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Python/CIndex include file support

Andrew Sutton
Oops. Now the patch is attached. Stupid 'Send' button.

Andrew Sutton
[hidden email]

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

py.diff (9K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Python/CIndex include file support

Daniel Dunbar
Hi Andrew,

Sorry I haven't had time to look at this yet. I'll try to get to it by
the weekend.

One immediate comment though, I would prefer to not expose this via a
property. I prefer to use functions (get_includes or so) for features
which require significant work, and only use properties for things
which are logically O(1). Otherwise the API tends to give the wrong
mental model of what is going on under the covers.

 - Daniel

On Mon, Feb 1, 2010 at 7:40 AM, Andrew Sutton <[hidden email]> wrote:

> Oops. Now the patch is attached. Stupid 'Send' button.
>
> Andrew Sutton
> [hidden email]
>
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Python/CIndex include file support

Andrew Sutton

Sorry I haven't had time to look at this yet. I'll try to get to it by
the weekend.

No rush.
 
One immediate comment though, I would prefer to not expose this via a
property. I prefer to use functions (get_includes or so) for features
which require significant work, and only use properties for things
which are logically O(1). Otherwise the API tends to give the wrong
mental model of what is going on under the covers.

I was back and forth on that issue.  Also, I'm not fully convinced that the returning tuples is the right thing to do. It might be better to create a class called "Inclusion" that explicitly names the including file, included file, location, depth, etc.

Also, on the CIndex side, is there a plan to support a max-depth on that traversal? It's easy enough to emulate from the Python side, but it wouldn't actually bound the traversal.

Andrew Sutton
[hidden email]

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Python/CIndex include file support

Daniel Dunbar
On Thu, Feb 4, 2010 at 6:36 AM, Andrew Sutton <[hidden email]> wrote:

>
>> Sorry I haven't had time to look at this yet. I'll try to get to it by
>> the weekend.
>
> No rush.
>
>>
>> One immediate comment though, I would prefer to not expose this via a
>> property. I prefer to use functions (get_includes or so) for features
>> which require significant work, and only use properties for things
>> which are logically O(1). Otherwise the API tends to give the wrong
>> mental model of what is going on under the covers.
>
> I was back and forth on that issue.  Also, I'm not fully convinced that the
> returning tuples is the right thing to do. It might be better to create a
> class called "Inclusion" that explicitly names the including file, included
> file, location, depth, etc.

Yeah, I haven't looked closely, but I think it might make sense to have a class.

> Also, on the CIndex side, is there a plan to support a max-depth on that
> traversal? It's easy enough to emulate from the Python side, but it wouldn't
> actually bound the traversal.

Not currently, and I'm not sure how much efficiency there is to gain
with it. Was there a particular use case?

 - Daniel

>
> Andrew Sutton
> [hidden email]
>

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Python/CIndex include file support

Andrew Sutton

> I was back and forth on that issue.  Also, I'm not fully convinced that the
> returning tuples is the right thing to do. It might be better to create a
> class called "Inclusion" that explicitly names the including file, included
> file, location, depth, etc.

Yeah, I haven't looked closely, but I think it might make sense to have a class.

Let me rewrite that and post a new patch for consideration.
 
> Also, on the CIndex side, is there a plan to support a max-depth on that
> traversal? It's easy enough to emulate from the Python side, but it wouldn't
> actually bound the traversal.

Not currently, and I'm not sure how much efficiency there is to gain
with it. Was there a particular use case?

 Not especially. For some reason, I was thinking that the VisitChildren function had a bounded depth, and that this would be nicely symmetric. Looking closer, I see that I'm wrong. So... never mind :)

Andrew Sutton
[hidden email]

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev