CastXML / pygccxml

pygccxml is a specialized XML reader that reads the output from CastXML. It provides a simple framework to navigate C++ declarations, using Python classes.
Boost Software License 1.0
132 stars 45 forks source link

Add method to fetch the type of an argument #15

Closed iMichka closed 8 years ago

iMichka commented 10 years ago

In ITK we need to fetch the type of an argument. For this, I hacked some code together, but there could be a method for this in pygccxml 1.7.0. Using str() is not really intuitive; and also not documented.

https://github.com/InsightSoftwareConsortium/ITK/blob/master/Wrapping/Generators/SwigInterface/igenerator.py#L698

for arg in method.arguments:
        # arg.type is an instance, there is no clean API in pygccxml to get the
        # name of the type as a string. This functionnality needs to be added
        # to pygccxml. Meanwhile, we can use the __str__() method.
        if arg.type.__str__() == "std::string &":
            applyFileNames.append(arg.name)
RomanYakovenko commented 8 years ago

Good evening. Michka, the functionality you are asking for exists and even more. Please take a look on cpptypes.py file type_t.decl_string method implementation. It does exactly what you are asking for. But this is not all. In my opinion, comparing types to string is en error prone approach. For this purpose, I created type_traits.py module. It contains different "type_traits" functions, built very similar to boost::type_traits.

HTH

iMichka commented 8 years ago

Hi

sorry for the long delay. I almost forgot that you answered. Thanks for the hint.

I have read more parts of pygccxml's code, and found what you are mentioning. I will make sure to use the right methods (it's just, I did not know about these when I first wrote that bunch of code 1-2 years ago).

RomanYakovenko commented 8 years ago

You are welcome. I recently used the recent pygccxml version with castxml and it was a pleasure. Thank you very much.

iMichka commented 8 years ago

I wrote a small example demonstrating the usage of is_std_string and is_reference, which shows how that can be used to achieve what I wanted to dO. This works only with the current develop version (e.g. the future v1.8.0). http://pygccxml.readthedocs.io/en/develop/examples/functions/example.html

I can close this now. I'll make a patch in ITK as soon as I update to version 1.8.0 there.