From mboxrd@z Thu Jan  1 00:00:00 1970
Path: news.gmane.org!not-for-mail
From: pjb@informatimago.com (Pascal J. Bourguignon)
Newsgroups: gmane.emacs.help
Subject: Re: Creating C++ constructor member init lists
Date: Tue, 27 Oct 2009 22:21:13 +0100
Organization: Informatimago
Message-ID: <871vkottx2.fsf@galatea.local>
References: <u3a5438hd.fsf@raytheon.com>
NNTP-Posting-Host: lo.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Trace: ger.gmane.org 1256679707 21658 80.91.229.12 (27 Oct 2009 21:41:47 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Tue, 27 Oct 2009 21:41:47 +0000 (UTC)
To: help-gnu-emacs@gnu.org
Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Oct 27 22:41:41 2009
Return-path: <help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org>
Envelope-to: geh-help-gnu-emacs@m.gmane.org
Original-Received: from lists.gnu.org ([199.232.76.165])
	by lo.gmane.org with esmtp (Exim 4.50)
	id 1N2tnK-0008Mc-2U
	for geh-help-gnu-emacs@m.gmane.org; Tue, 27 Oct 2009 22:41:34 +0100
Original-Received: from localhost ([127.0.0.1]:59357 helo=lists.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43)
	id 1N2tnJ-0005S1-DU
	for geh-help-gnu-emacs@m.gmane.org; Tue, 27 Oct 2009 17:41:33 -0400
Original-Path: news.stanford.edu!usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
Original-Newsgroups: gnu.emacs.help
Original-Lines: 80
Original-X-Trace: individual.net o+giS7C5Xk86s2aPpEotqwD3D2PbhTTymTkXPDQKIDr7hqTTGJ
Cancel-Lock: sha1:NDIxNTE0NzQzM2Y5YmU0NjBhZjBhZTcxOWFhZGNiNzBkNjcyZTZlNw==
	sha1:sa9A99k/8rbn8iKShWOz4XhcqD0=
Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA
	oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9
	033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac
	l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR
	mV+hO/VvFAAAAABJRU5ErkJggg==
X-Accept-Language: fr, es, en
X-Disabled: X-No-Archive: no
User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/22.3 (darwin)
Original-Xref: news.stanford.edu gnu.emacs.help:174213
X-BeenThere: help-gnu-emacs@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Users list for the GNU Emacs text editor <help-gnu-emacs.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/help-gnu-emacs>,
	<mailto:help-gnu-emacs-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/pipermail/help-gnu-emacs>
List-Post: <mailto:help-gnu-emacs@gnu.org>
List-Help: <mailto:help-gnu-emacs-request@gnu.org?subject=help>
List-Subscribe: <http://lists.gnu.org/mailman/listinfo/help-gnu-emacs>,
	<mailto:help-gnu-emacs-request@gnu.org?subject=subscribe>
Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org
Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org
Xref: news.gmane.org gmane.emacs.help:69296
Archived-At: <http://permalink.gmane.org/gmane.emacs.help/69296>

Sarir Khamsi <sarir.khamsi@raytheon.com> writes:

> I'd like to write some code in some language (preferably in Emacs
> Lisp) to take a C++ class and add member variables to the
> constructor's member initialization list in an automated
> fashion. Given something like:
>
>    struct MyType
>    {
>       MyType();
>       // ...
>    private:
>       int i1_;
>       double d_;
>       T1 *pT1_;
>       T2 t2_;
>    };
>
> I'd like the code to generate:
>
>    struct MyType
>    {
>       MyType() :
>          i1_(0),
>          d_(0.0),
>          pT1_(0),
>          t2_()
>       {
>       }
>       // ...
>    private:
>       int i1_;
>       double d_;
>       T1 *pT1_;
>       T2 t2_;
>    };
>
> It would be easy to write something that just default-constructs the
> members, but I'd like to make it smart enough to init bools to
> "false", ints to "0", doubles to "0.0", etc. My questions are:
>
>  - Are there helper functions in c++-mode that can be used to
>    enumerate member variables, or make life easier?

Not in c++-mode.  But you might find that with the cedet project.


>  - Is there code to do something like this already (I looked a bit and
>    didn't find exactly what I wanted)?

Possibly in cedet.  At least, there there are the tools to do such a
thing, (eg. the bovinator is a parser generator to implement the
partial parsers needed for such kind of tools).


>  - Is GCC-XML worth looking into? I've looked at the output of a small
>    C++ class and could use Python to do what I want.

If you need something more precise.  However, if you are working in
emacs, you may want to be able to work on code that is not perfect,
syntax-wise (code that you are editing), and therefore the tools
you'll find in the cedet project will probably be more adapted to what
you want to do than gcc-xml.


> I haven't started the coding and wanted to get other people's
> input. Thanks.


http://cedet.sourceforge.net 

The C/C++ parser is already implemented (click on "Parts of CEDET" /
Semantic ) Also, if you want to generate your constructors, you can do
so with SRecode, which is a template based code generation tool. (But
I guess you will have to add your features to collect the attributes
of the class and put them in the constructor tranmission).


-- 
__Pascal Bourguignon__