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

Problem parsing castxml output of template function default argument of template type #82

Open lordylike opened 7 years ago

lordylike commented 7 years ago

I've recently started migrating from gccxml to castxml and have encountered the aforementioned problem. I could narrow the problem down to a minimum example that still fails:

template<typename Type>
class TemplateClass
{
public:
    void func(Type val = (Type)0.0)
    {
    }
};
template class TemplateClass<float>;

Called with following cmd line arguments: -std=c++14 -c -x c++ --castxml-cc-msvc "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe" --castxml-gccxml -o "test.xml" "test.h"

Produces an xml with following argument tag:

<Method id="_8" name="func" returns="_14" context="_5" access="public" location="f1:7" file="f1" line="7" inline="1" mangled="?func@?$TemplateClass@MN@@QAEXMN@Z" attributes="__thiscall__">
    <Argument name="val" type="_15" location="f1:7" file="f1" line="7" default="(type-parameter-0-0)0."/>
</Method>

The information referring to the (Type)0.0 default argument given can be found within the (type-parameter-0-0) information found in the Argument tag default coupled with the Class referenced in the Method's context information, which states:

<Class id="_5" name="TemplateClass&lt;float&gt;" context="_1" location="f1:13" file="f1" line="13" members="_8 _9 _10 _11 _12" size="8" align="8"/>

From these two places, I would expect gccxml to figure out that the default argument should be written as (float)0.. Instead it parses this to (type-parameter-0-0)0..

iMichka commented 7 years ago

Hi. Thanks for letting me know. I'll try to have a look at this during the weekend.

RomanYakovenko commented 7 years ago

In the past (gccxml) default arguments was dump almost as "just a text". "Default argument" can contain arbitrary complex C++ expression evaluated at run time. Dumping such expression was out of scope of gccxml and of pygccxml. You were lucky in this case. I was less lucky in other cases.