tool to parse and edit c++ source

J

Jonathan Lee

Hi all,
anyone know of a tool that can be used to (automatically) edit C++
source to change data? For example, I want to change "i" in the
following to 3

int i = 6; // wanna change this to 3
/* but not the following 'cause its in a comment:
double i = 0.0;
*/

Or change an array or struct, etc? A naive replacement of "stuff" in
"type identifier = stuff;" works fine, but isn't robust against the
comment case above or other possibilities.

Is there a parser for C++ that supports this? or any other tool
someone can recommend?
 
I

Ian Collins

Hi all,
anyone know of a tool that can be used to (automatically) edit C++
source to change data? For example, I want to change "i" in the
following to 3

int i = 6; // wanna change this to 3
/* but not the following 'cause its in a comment:
double i = 0.0;
*/

Or change an array or struct, etc? A naive replacement of "stuff" in
"type identifier = stuff;" works fine, but isn't robust against the
comment case above or other possibilities.

Is there a parser for C++ that supports this? or any other tool
someone can recommend?

The refactoring support in NetBeans probably will. I guess Eclipse will
have something similar as well.
 
J

Jorgen Grahn

Hi all,
anyone know of a tool that can be used to (automatically) edit C++
source to change data? For example, I want to change "i" in the
following to 3

int i = 6; // wanna change this to 3
/* but not the following 'cause its in a comment:
double i = 0.0;
*/

Nitpicks: 'int 3 = 6;' is a syntax error, and normally you want the
comments updated as well.
Or change an array or struct, etc? A naive replacement of "stuff" in
"type identifier = stuff;" works fine, but isn't robust against the
comment case above or other possibilities.

Is there a parser for C++ that supports this? or any other tool
someone can recommend?

In some situations I'd use Perl, and then review the changes (git diff
or whatever), manually restoring the ones I don't want changed

% perl -pi -e 's/\bi\b/3/g' *.cc *.h

But usually I just use my text editor's search-and-replace combined
with the compiler's error messages: change the declaration, and let
the compiler list the places where the now nonexisting name is used.

/Jorgen
 
J

Joshua Maurice

Hi all,
  anyone know of a tool that can be used to (automatically) edit C++
source to change data? For example, I want to change "i" in the
following to 3

    int i = 6; // wanna change this to 3
    /* but not the following 'cause its in a comment:
        double i = 0.0;
    */

Or change an array or struct, etc? A naive replacement of "stuff" in
"type identifier = stuff;" works fine, but isn't robust against the
comment case above or other possibilities.

Is there a parser for C++ that supports this? or any other tool
someone can recommend?

Do you want some generic refactoring tool? Or just a way to say ..
update a version number in a source file? In the second case, use a
macro, and define the macro via the command line "-D" or similar.
 
J

Jonathan Lee

Do you want some generic refactoring tool? Or just a way to say ..
update a version number in a source file? In the second case, use a
macro, and define the macro via the command line "-D" or similar.

More like a generic refactoring tool.

To answer my own question, I thing I might be able to use clang to do
this.

Thanks everyone for your input. Still open to other ideas, too, if
there are any.

--Jonathan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top