public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* how to dumping out function name and its parameters from gcc's AST?
@ 2004-08-12  6:09 Chao Liu
  0 siblings, 0 replies; only message in thread
From: Chao Liu @ 2004-08-12  6:09 UTC (permalink / raw)
  To: gcc-help

Hi, hackers,

I am now try to dump our AST from gcc 3.4.0 for c programming language.
Currently, I'd like to dump out the function name and its parameters if
any.

For example, for a function call to the function foo like "foo(a, b, c)" ,
I would like "foo, a, b, c" dumped out.

My instrumented code into gcc's c-decl.c is

switch (TREE_CODE(expr)){
case CALL_EXPR:
printf("%s", IDENTIFIER_POINTER(DECL_NAME(TREE_OPERAND(expr, 0), 0))));
tree paralist = TREE_VALUE(TREE_OPERAND(expr, 1));
tree para = TREE_CHAIN(paralist);
while(para != NULL_TREE){
printf("%s", IDENTIFIER_POINTER(DECL_NAME(para)));
para = TREE_CHAIN(para);
}

but it failed to give the correct parameter names while function name is
correct. So what's wrong? I know in cases like foo(i+j, p+q), it is
undefined what to dump out but just want to know in the simple case foo(i,
j) how to dump foo, i, j if possible.

btw, for an expression "expr" with TREE_CODE as CALL_EXPR, what is the
type of TREE_OPERAND(expr, 0) and TREE_OPERAND(expr, 1); As documented in
tree.def, they are function and paralist, but what are their TREE_CODES?

Also, given one tree type variable, like tree tmp, how can I know its
TREE_CODE? Do we have some methods to print its type out?

many thanks to your patience. If you are not clear about what I mean, do
let me know.

thanks again,
Chao

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2004-08-12  3:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-12  6:09 how to dumping out function name and its parameters from gcc's AST? Chao Liu

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).