This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C tree question


hi,

I have been trying lately to understand what kind of data is stored in
the tree output by the C frontend. Thanks to -fdump-translation-unit, I
learned quite a bit but from what I gathered with google and from my
personal tendency to suspicion, I think this flag does not dump all the
nodes in the tree (the default: statement in
tree-dump.c:dequeue_and_dump enforces this suspicion).

So, I started looking into c-parse.y, c-decl.c and the tree.h header.
The exact question I'd like to answer is:
1) if (foo) bar;
2) if (foo) {bar;}
where bar; is a non-compound statement generates the exact same tree out
of the language frontend. -dump-translation-unit seems to be generating
the exact same output.

The following code samples coming from c-parse.y lead me to believe
that, indeed, the '{' token is saved as a COMPOUND_STMT node (see
c-decl.c:c_begin_compound_stmt).

compstmt_start: '{' { compstmt_count++;
                      $$ = c_begin_compound_stmt (); }
        ;
/* [snip] */
compstmt: compstmt_start compstmt_nostart
                { RECHAIN_STMTS ($1, COMPOUND_BODY ($1));
                  last_expr_type = NULL_TREE;
                  $$ = $1; }
        ;

The question thus becomes:
	1) is the code fragment above relevant to my if (foo) {bar} sample ? I
suspect it might be related only to the enclosing {s of function bodies.
	2) If it is related to my sample, does the COMPOUND_STMT node still
exist at the end of the frontend run ?
	3) If it is not related, could someone point me to the relevant piece
of code in c-parse.y ?

regards,
Mathieu
-- 
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]