From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14259 invoked by alias); 25 Apr 2012 17:43:41 -0000 Received: (qmail 14242 invoked by uid 22791); 25 Apr 2012 17:43:39 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from seketeli.net (HELO ms.seketeli.net) (91.121.166.71) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 25 Apr 2012 17:43:20 +0000 Received: from localhost (torimasen.com [82.237.12.13]) by ms.seketeli.net (Postfix) with ESMTP id EC5B3EA040; Wed, 25 Apr 2012 19:58:03 +0200 (CEST) Received: by localhost (Postfix, from userid 500) id 071CA29C046; Wed, 25 Apr 2012 19:43:18 +0200 (CEST) From: Dodji Seketeli To: rick shelton Cc: gcc@gcc.gnu.org Subject: Re: in-class function definitions? References: <1335051802.47595.YahooMailNeo@web162803.mail.bf1.yahoo.com> Mail-Followup-To: gcc@gcc.gnu.org X-URL: http://www.seketeli.net/~dodji Date: Wed, 25 Apr 2012 17:43:00 -0000 In-Reply-To: <1335051802.47595.YahooMailNeo@web162803.mail.bf1.yahoo.com> (rick shelton's message of "Sat, 21 Apr 2012 16:43:22 -0700 (PDT)") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org X-SW-Source: 2012-04/txt/msg00826.txt.bz2 Hello Rick, Since nobody responded, I'll try. :-) rick shelton a =C3=A9crit: > How does the compiler handle an in-class function definition? > Example: > > // File A.h > > class A { > =C2=A0int foo(void) { return x; } > =C2=A0int bar(void); > =C2=A0int 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 =3D TYPE_METHOD (type_a); method; method =3D DECL_CHAIN (method)) /* Do something with method*/; } Then the body of the function can be accessed from the=20 DECL_INITIAL (method) accessor. I hope this helps. --=20 Dodji