all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Creating C++ constructor member init lists
@ 2009-10-27 20:08 Sarir Khamsi
  2009-10-27 21:21 ` Pascal J. Bourguignon
  0 siblings, 1 reply; 3+ messages in thread
From: Sarir Khamsi @ 2009-10-27 20:08 UTC (permalink / raw)
  To: help-gnu-emacs

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?
 - Is there code to do something like this already (I looked a bit and
   didn't find exactly what I wanted)?
 - 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.

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

Sarir

-- 
Sarir Khamsi
software guy
sarir.khamsi@raytheon.com


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Creating C++ constructor member init lists
  2009-10-27 20:08 Creating C++ constructor member init lists Sarir Khamsi
@ 2009-10-27 21:21 ` Pascal J. Bourguignon
  2009-10-28 21:29   ` Sarir Khamsi
  0 siblings, 1 reply; 3+ messages in thread
From: Pascal J. Bourguignon @ 2009-10-27 21:21 UTC (permalink / raw)
  To: help-gnu-emacs

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__


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Creating C++ constructor member init lists
  2009-10-27 21:21 ` Pascal J. Bourguignon
@ 2009-10-28 21:29   ` Sarir Khamsi
  0 siblings, 0 replies; 3+ messages in thread
From: Sarir Khamsi @ 2009-10-28 21:29 UTC (permalink / raw)
  To: help-gnu-emacs

pjb@informatimago.com (Pascal J. Bourguignon) writes:

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

[...]

> http://cedet.sourceforge.net 

Thanks, this looks like a great collection of tools to start with.

Sarir

-- 
Sarir Khamsi
software guy
sarir.khamsi@raytheon.com


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-10-28 21:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-27 20:08 Creating C++ constructor member init lists Sarir Khamsi
2009-10-27 21:21 ` Pascal J. Bourguignon
2009-10-28 21:29   ` Sarir Khamsi

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.