I'd like a tool that could move (explicit or implicit inline) function
bodies of C++ class methods declared in the class definition, to just after
the class.  For example:

   struct X
   {
      bool foo( int x = 1 )
      {
         return true ;
      }

      inline bool moo( int x, int y )
      {
         return true ;
      }

      static bool boo(void)
      (
         return true ;
      )
   } ;

and produce rewritten code like:

   struct X
   {
      inline bool foo( int x = 1 ) ;

      inline bool moo( int x, int y ) ;

      static inline bool boo( void ) ;
   } ;

   inline bool X::foo( int x )
   {
      return true ;
   }

   inline bool X::moo( int x, int y )
   {
      return true ;
   }

   inline bool X::boo( void ) ;
   (
      return true ;
   )

Having done this manually a number of times (to decouple class definitions
from implementation, and reduce #include tree sizes), the steps are:

1) add inline in the declaration of the function if required.
2) delete the body at the declaration point.
3) add a semicolon.
4) move the body to after the class (i.e. as prep for manually moving
problematic inlines elsewhere that introduce dependencies)
5) remove any static specifier from the relocated body.
6) make sure there's an inline specifier in the relocated function body.
7) remove any default parameters that should only be included with the
prototype.
8) add the class specifier (X:: in the example above)

This seems like a highly automatable task given the libtooling
infrastructure, and it wouldn't suprise me if a rewriter like this has been
thought about as a companion for google's include_what_you_use libtooling
tool.

Before trying to implement such a beast, I thought I'd ask if anybody knows
of such a tool.  If no such tool is known, perhaps somebody point me to an
example (or examples) of a transformation tools that have one or more
aspects of the rewriting steps above.

-- 
Peeter
_______________________________________________
cfe-users mailing list
cfe-users@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-users

Reply via email to