[cfe-dev] Dividing statements

Richard Trieu rtrieu at google.com
Thu Feb 27 20:26:40 PST 2014


Hi Pedro,

What's happening is that the comma operator can only take two expressions.
 When more than two expressions are joined with commas, the first two are
joined by the comma operator, then that result is joined with expression,
then that result is joined to the next expression and so on.  So something
like:

a, b, c, d;

is structurally similiar to:

(((a, b), c), d);

Instead of processing every sub-statement, you only need to process
sub-statements when the current statement is the comma operator (that is,
the statement is a BinaryOperator with comma opcode).  If it is, the right
Expr* is the last statement and the left Expr* is either the first
statement, or another comma operator which you need to recurse on.

Hope that helps.

Richard

On Thu, Feb 27, 2014 at 3:36 AM, Pedro Delgado Perez <
pedro.delgadoperez at mail.uca.es> wrote:

>  Hi,
>
> I have a sentence like this:
>
> method( b )    ,        a = 3     ,        b++;
>
> This sentence is a statement composed of three substatements. What I need
> is to difference those three substatements which are between commas to save
> them in a list:
>
> Statement 1 -> method( b )
> Statement 2->  a = 3
> Statement 3 -> b++
>
> So I tried using the "child_iterator" in the class Stmt, which I though it
> would be easy.
> In the first iteration, the statement is subdivided in:
>
> [method( b )  ,  a = 3]    and     [b++;]
>
> The first sentence is then subdivided again in:
>
> [method( b )]   and    [a = 3]
>
> The problem is that  I don't know when I should stop the division because,
> now, the first statement is divided again to my surprise, taking the
> argument "b" as a new statement. Thus, I'm getting more than three
> statements, what is a major issue in my case.
>
> Is there any way to count the number of statements separated by commas?
> Why it doesn't exist the reverse iterator? In that way, I could compare
> when a statement processed in the child_iterator is the same as the first
> statement divided in the reverse iterator.
>
> Thanks in advance,
>
> Pedro.
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140227/5c701e45/attachment.html>


More information about the cfe-dev mailing list