Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   tool to parse and edit c++ source (http://www.velocityreviews.com/forums/t945896-tool-to-parse-and-edit-c-source.html)

Jonathan Lee 05-02-2012 02:16 AM

tool to parse and edit c++ source
 
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?

Ian Collins 05-02-2012 05:29 AM

Re: tool to parse and edit c++ source
 
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

Jorgen Grahn 05-02-2012 09:01 AM

Re: tool to parse and edit c++ source
 
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 .

Joshua Maurice 05-02-2012 09:40 PM

Re: tool to parse and edit c++ source
 
On May 1, 7:16*pm, Jonathan Lee <jonathan.lee....@gmail.com> 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.

Jonathan Lee 05-03-2012 01:20 AM

Re: tool to parse and edit c++ source
 
On May 2, 4:40*pm, Joshua Maurice <joshuamaur...@gmail.com> wrote:
> On May 1, 7:16*pm, Jonathan Lee <jonathan.lee....@gmail.com> 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


All times are GMT. The time now is 03:22 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57