1

I need to have some of my C++ classes, functions and namespaces renamed as a part of my build script, which is runned by my CI system.

Unfortunatly a simple sad/awk/gsar/... technique is not enough, and I need smart rename refactoring, that carefully analyses my code.

Actually I found out, that CDT C/C++ rename refactoring does, what I need. But it does it from Eclipse IDE. So I need to find a way to start it from command line, and to make it a part of my CI build script.

I know that Eclipse has eclipsec executable, that allowes running some Eclipse functions from command line (see e.g. here).

But I can't find any suitable documentation for functions, CDT exports to command line. The only thing, I found is the this. But it doesn't solve my problem.

So, I need help to run CDT rename refactoring from command line (or someway like that). If it is not possible, may be someone will advice another tool, that can do rename refactoring for C++ from command line ?

Community
  • 1
  • 1
Meteorite
  • 903
  • 1
  • 9
  • 13
  • Can I ask why you need to do this as part of your build process? – Oliver Charlesworth Nov 11 '11 at 11:11
  • Why you want to do all these \from command line and not the IDE ? – iammilind Nov 11 '11 at 11:14
  • I need to do it from command line, because I don't even want to see the result of this operation, I only need to give it to compiler. I don't want the actual code, I work on to be changed. So I think build script is a right place to do it. – Meteorite Nov 11 '11 at 11:21

2 Answers2

2

Pragmatic Approach

"I need to have renamed as a part of my build script"

This sounds a bit like a design problem. However, I remember having been guilty of the same sin once writing a C++ application on AIX/Win32: most notably, I wanted to be able to link 'conflicting' versions of shared objects. I solved it using a simple preprocessor hack like this:

# makefile

#if($(ALTERNATIVE))
    CPPFLAGS+=-DLIBNAMESPACE=MYLIB_ALTERNATIVE
#else
    CPPFLAGS+=-DLIBNAMESPACE=MYLIB
#endif

./obj64/%.o: %cpp
     xlC++ $(CPPFLAGS) $^ -o %@

Sample source/header file:

namespace MYLIB
{
     class LibService :
     {
     };
}

As you can see, this required only a single

find -iname '*.[hc]pp' -o -iname '*.[hc]' -print0 |
     xargs -0 sed -i 's/OldNamespace/MYLIB/g'

Eclipse Automation

You could have a look at eclim, which does most, if not all, of what you describe, however it targets the vim editor.

What eclim boasts, is full eclipse intergration (completion, refactoring, usage search etc.) from an external program. I'm not fully up to speed with the backend of eclim, but I do know that it works with a eclimd server process that exposes the service interface used by the vim plugin.

I suspect you should be able to reuse the code from eclimd if not just use eclim for your purposes.

sehe
  • 374,641
  • 47
  • 450
  • 633
  • added a pragmatic, real life, approach from a project I once did (sic) :) – sehe Nov 11 '11 at 11:19
  • Oh, yes, of course it is a design problem. But it seems to me, it is too late to redisign now. – Meteorite Nov 11 '11 at 11:26
  • Thanks a lot for 'Pragmatic Approach'. Ii gives some food for thought, I think it is possible to adapt it for my case :) – Meteorite Nov 11 '11 at 11:33
  • I think, for me it is enough to declare that namespaces', classes', etc names as #define macroses to rename them with the means of preprocessor. And of course I should turn on that defines only in the special context. Thank you, sehe! – Meteorite Nov 11 '11 at 11:40
0

We are completing a command-line rename tool for C++, that uses compiler accurate parsing and name resolution, including handling of shadowed names. Contact me (see bio) for further details or if you might be interested in a beta.

Ira Baxter
  • 93,541
  • 22
  • 172
  • 341