![]() |
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? |
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 |
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 . |
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. |
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.