Return doesn't really return

Timon Gehr timon.gehr at gmx.ch
Sat Aug 4 13:01:44 PDT 2012


On 08/04/2012 08:54 PM, Jacob Carlborg wrote:
> On 2012-08-04 19:08, Timon Gehr wrote:
>
>> int opApply (Delegate dg)
>> {
>>     auto result = clang_visitChildren(cursor,
>>     &visitorFunction,cast(CXClientData) &dg);
>>     return result == CXChildVisitResult.CXChildVisit_Break ? 1 : 0; // culprit
>> }
>
> Yes, right. I forgot about that. The Clang API doesn't really have a way
> to represent the difference between "break" and "return" in D. The Clang
> API works like this:
>
> * Return 0 - Stop visiting children
> * Return 1 - Continue visiting children
> * Return 2 - Recursively visit the children
>
> It doesn't really seem to be a way to map the difference between the
> break and return codes that D uses to the Clang API.
>
> Anyone got an idea for a workaround

bugfix.

> or should I just continue to use "break" and never use "return"?
>

Return the exit code by reference:
Pass a tuple of delegate and return value to the visitorFunction per
the CXClientData pointer and make the visitorFunction store the exit 
code inside the return code field. Then return that from opApply.


More information about the Digitalmars-d-learn mailing list