public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* C-frontend NOP_EXPR help
@ 2011-03-11 15:15 Markus Lottmann
  2011-03-11 16:13 ` Ian Lance Taylor
  0 siblings, 1 reply; 2+ messages in thread
From: Markus Lottmann @ 2011-03-11 15:15 UTC (permalink / raw)
  To: gcc-help

Hi,

I try to extract a source code syntax tree for c code from the 
c-frontend of the gcc.
Therefore i have written a plugin which registers a callback for 
PLUGIN_PRE_GENERICIZE.

My problem is that the c-frontend directly breaks while-, do- and 
for-loops in statement list and
does not use FOR_STMT nodes like the c++-frontend.
To reconstruct this statement lists to a tree structure like the one in 
the c++ frontend i have added
a few markings in struct tree_base. The gool is to have a node for the 
init, the condition, the increment
and the body of the loop as children of the FOR_STMT node. But this 
reconstruction should only take
place in a seperate tree in my plugin not the c-frontend internal tree.
That works so far but not for empty do-loops with an always false condition:
     do {

     } while(0);

In this case in c-typeck.c:c_finish_loop() nothing is added to the 
frontend internal tree.
My question is: Is it possible to add a NOP_EXPR, which has no further 
children, to the current
statement list. If yes how?
I could then set a few of my flags in tree_base for this NOP_EXPR and 
would be able to trac empty
do-loops.
If this is possible, am i right in the assumption that this NOP_EXPR is 
removed from the internal tree
in later optimization steps but not before my PLUGIN_PRE_GENERICIZE 
callback was executed?

Thanks for your help and attention,
Markus

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: C-frontend NOP_EXPR help
  2011-03-11 15:15 C-frontend NOP_EXPR help Markus Lottmann
@ 2011-03-11 16:13 ` Ian Lance Taylor
  0 siblings, 0 replies; 2+ messages in thread
From: Ian Lance Taylor @ 2011-03-11 16:13 UTC (permalink / raw)
  To: Markus Lottmann; +Cc: gcc-help

Markus Lottmann <lottvomschlott@gmx.de> writes:

> That works so far but not for empty do-loops with an always false condition:
>     do {
>
>     } while(0);
>
> In this case in c-typeck.c:c_finish_loop() nothing is added to the
> frontend internal tree.
> My question is: Is it possible to add a NOP_EXPR, which has no further
> children, to the current
> statement list. If yes how?

Just do something like
    add_stmt (build1 (NOP_EXPR, void_type_node, integer_zero_node));
See many existing examples.

Ian

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-03-11 16:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-11 15:15 C-frontend NOP_EXPR help Markus Lottmann
2011-03-11 16:13 ` Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).