Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > tool to parse and edit c++ source

Reply
Thread Tools

tool to parse and edit c++ source

 
 
Jonathan Lee
Guest
Posts: n/a
 
      05-02-2012
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?
 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      05-02-2012
On 05/ 2/12 02:16 PM, Jonathan Lee wrote:
> 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.

--
Ian Collins
 
Reply With Quote
 
 
 
 
Jorgen Grahn
Guest
Posts: n/a
 
      05-02-2012
On Wed, 2012-05-02, Jonathan Lee wrote:
> 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

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
 
Reply With Quote
 
Joshua Maurice
Guest
Posts: n/a
 
      05-02-2012
On May 1, 7:16*pm, Jonathan Lee <(E-Mail Removed)> wrote:
> 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.
 
Reply With Quote
 
Jonathan Lee
Guest
Posts: n/a
 
      05-03-2012
On May 2, 4:40*pm, Joshua Maurice <(E-Mail Removed)> wrote:
> On May 1, 7:16*pm, Jonathan Lee <(E-Mail Removed)> wrote:
>
>
>
>
>
>
>
>
>
> > 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.


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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do i edit source (like in IE, view..source)? q_q_anonymous@yahoo.co.uk Firefox 4 05-13-2006 11:07 PM
Snapshot restraint - edit, edit, edit Alan Browne Digital Photography 24 05-10-2005 10:15 PM
Snapshot restraint - edit, edit, edit Patrick Digital Photography 0 05-06-2005 10:53 PM
How to parse a string like C program parse the command line string? linzhenhua1205@163.com C Programming 19 03-15-2005 07:41 PM
Edit All Function for DataGrid, and Moving the Edit Function in a DataGrid Schultz ASP .Net 3 02-14-2005 04:47 AM



Advertisments