<div dir="ltr"><div><div><div><div><div>Hi all,<br><br></div>The effort to generate PyKF5 semi-automatically (to replace PyKDE4) is making some headway but I am uncertain as to how best to tackle the problem of %ConvertToSubClassCode. The first clarification question is to check I have understood correctly that the basic process for designing %ConvertToSubClassCode is:<br><br></div><div>    For each .sip file in a  SIP module<br></div><div>        For each type in the .sip<br></div><div>            For all known subclass trees<br></div><div>                Generate a fragment of code (like the sample below)<br><br></div><div>Is that right?<br></div><div>            <br></div><div>Assuming that is correct, the second question is about how to implement the above. In the PyKDE4 days several thousand lines of code like this were lovingly hand-crafted:<br><br>               %ConvertToSubClassCode<br>                    // CTSCC for subclasses of 'KConfigSkeletonItem'<br>                    sipType = NULL;<br><br>                    if (dynamic_cast<KCoreConfigSkeleton::ItemBool*>(sipCpp))<br>                        sipType = sipType_KCoreConfigSkeleton_ItemBool;<br>                    else if (dynamic_cast<KCoreConfigSkeleton::ItemDateTime*>(sipCpp))<br>                        sipType = sipType_KCoreConfigSkeleton_ItemDateTime;<br>                    else if (dynamic_cast<KCoreConfigSkeleton::ItemDouble*>(sipCpp))<br>                        sipType = sipType_KCoreConfigSkeleton_ItemDouble;<br>                    else if (dynamic_cast<KCoreConfigSkeleton::ItemInt*>(sipCpp))<br>                        {<br>                        sipType = sipType_KCoreConfigSkeleton_ItemInt;<br>                        if (dynamic_cast<KCoreConfigSkeleton::ItemEnum*>(sipCpp))<br>                            sipType = sipType_KCoreConfigSkeleton_ItemEnum;<br>                        }<br>                    ...<br><br></div><div>(I have de-duplicated this by hand, and I still have over 1000 lines of code). Now I have over 2000 .sip files across over 100 components that make up PyKF5 and a minor nightmare in prospect :-). It seems to me that I have several manual options:<br></div></div><ol><li>Ignore the problem at this level, and only manually create %ConvertToSubClassCode on an as-requested basis, release-by-release. (On occasion, I may be able to use the PyKDE4 code as a starting point, but the shape and details of the type hierarchy in PyKF5 is often rather different).</li><li>For each of the 100+ components, don't release the component until the work is done.</li></ol></div></div>Neither of these is attractive from a user perspective, and perpetuates the problem from a maintainer perspective. The other way forward might be some kind of automation in the SIP generation automation layer:<br><ol><li>Let's say that the presence of RTTI is a given.</li><li>We know we are dealing with a Qt-like system including all its magic macros and the like.<br></li><li>We can run some kind of offline analyser (the SIP generator uses libclang, and can either operate on a single .h file at a time, or we can even run over a whole directory hierarchy if needed).</li></ol><p>Has anybody attempted this before? Any other suggestions? Can we do something at runtime?</p><p>All input welcome...<br></p><p>Thanks, Shaheed<br></p><div><div><div><br><br><div><br><br><br><br><div><br></div></div></div></div></div></div>