* in-class function definitions?
@ 2012-04-21 23:43 rick shelton
2012-04-25 17:43 ` Dodji Seketeli
0 siblings, 1 reply; 2+ messages in thread
From: rick shelton @ 2012-04-21 23:43 UTC (permalink / raw)
To: gcc
How does the compiler handle an in-class function definition?
Example:
// File A.h
class A {
int foo(void) { return x; }
int bar(void);
int x;
}
// File A.cc
#include "A.h"
int A::bar(void) { ... }
How is "foo()" represented in the AST when parsing A.cc?
Thanks,
rick
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: in-class function definitions?
2012-04-21 23:43 in-class function definitions? rick shelton
@ 2012-04-25 17:43 ` Dodji Seketeli
0 siblings, 0 replies; 2+ messages in thread
From: Dodji Seketeli @ 2012-04-25 17:43 UTC (permalink / raw)
To: rick shelton; +Cc: gcc
Hello Rick,
Since nobody responded, I'll try. :-)
rick shelton <thatrickguy@yahoo.com> a écrit:
> How does the compiler handle an in-class function definition?
> Example:
>
> // File A.h
>
> class A {
> int foo(void) { return x; }
> int bar(void);
> int x;
>
> }
>
> // File A.cc
> #include "A.h"
> int A::bar(void) { ... }
>
> How is "foo()" represented in the AST when parsing A.cc?
Let's say the type "A" is represented by type_a. Foo is then
represented by a FUNCTION_DECL tree node that is accessible from the
list of methods of type_a, that you can get from TYPE_METHODS (type_a).
You can walk these methods by doing:
{
/* method is going to be a tree node
of FUNCTION_DECL kind. */
tree method;
for (method = TYPE_METHOD (type_a);
method;
method = DECL_CHAIN (method))
/* Do something with method*/;
}
Then the body of the function can be accessed from the
DECL_INITIAL (method) accessor.
I hope this helps.
--
Dodji
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-04-25 17:43 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-21 23:43 in-class function definitions? rick shelton
2012-04-25 17:43 ` Dodji Seketeli
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).