[cfe-dev] How can I judge whether a "CFGElement" is in the for or while loop?
Jordan Rose
jordan_rose at apple.com
Wed Nov 20 09:16:42 PST 2013
On Nov 16, 2013, at 9:13 , Larry Evans <cppljevans at suddenlink.net> wrote:
>
>
> On 11/04/13 11:33, Jordan Rose wrote:
> > Hi, Shuai.
> > Unfortunately, there's not a great answer for this. Part
> > of the philosophical reason for that is "goto" (or even "switch"),
> > where you can jump "into" a loop, and then possibly leave it again
> > before even evaluating the loop condition.
>
> Hi Jordan,
>
> I've been looking for a real world example of jumping into
> and then out of a loop.
>
> Would happen to have a link to or example of such real world code?
There are some crazy examples, like hand-rolled coroutines:
http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html
Not too many common cases, but possibly the sort of thing you’d find in a library. In any case, the original question was about performing a source-to-source transformation based on basic blocks, and that’s just not something worth doing.
Anna thought of another example why this would be problematic:
if (condition()) {
doSomething();
} else if (anotherCondition()) {
doSomethingElse();
}
Although “else if” looks like a single construct, it’s really “else” followed by a single un-braced statement, "if". Trying to insert something at the start of the else-block (“anotherCondition()” being the first thing evaluated) is probably just as bad as doing it in the condition of a while loop.
Jordan
More information about the cfe-dev
mailing list