This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: in-class function definitions?
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