生成 c++重构脚本
我必须重构中等大小的代码块(< 200K LOC)。范围相当适中:重命名一些类,在类层次结构中上下移动一些嵌套定义,删除未使用的内容。
手动完成会非常简单,但我们必须在一两年内从旧代码库中获取错误修复,并且该项目将更改现有代码中至少一半的行。
因此,我计划将更改表示为一系列缩进(据说是 astyle)、sed 脚本和另一个缩进。
我的计划是:手动进行转换,然后开发 sed 脚本来产生相同的结果。前一部分非常清楚,但是手动开发位 sed 脚本似乎并不特别有吸引力,但我没有更好的想法。
请帮忙。
I have to perform refactoring of a medium size code block (< 200K LOC). The scope is pretty moderate: rename some classes, move a few nested definitions up and down the class hierarchy, remove unused stuff.
It would be pretty straightforward to do it by hand but we will have to pick up bug fixes from the older code base for one or two years, and the project will change at least half of lines in the existing code.
So, I am planning to express the changes as a sequence of indent (supposedly astyle), sed script, and another indent.
My plans are: do conversion by hand, then develop the sed script that will yeld the same result. The former part is pretty clear, but developing bit sed script by hand does not seem particularly appealing but I do not have any better idea.
Please, help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看看 mozilla 开发人员正在开发的大规模静态分析和重构工具
https://wiki.mozilla.org /Static_Analysis
我不确定自 gcc 4.5 发布以来发生了什么 - 也许现在 Pork 和 oink 更容易设置。
Have a look at the large scale static analysis and refactoring tools that mozilla devs were working on
https://wiki.mozilla.org/Static_Analysis
I'm not sure what has happened since the release of gcc 4.5 - possibly pork and oink are easier to set up now.
sed
可能会被强迫这样做,但对于多行块,您最好使用更容易使用的东西。即使是 awk 也会有所改进,但我会考虑选择 Perl/Python/脚本语言。最好使用解析器,这也可以节省您最初的缩进
运行。事实上,我会寻找一个生成带注释的语法树的解析器,这使得重构在很大程度上成为移动树枝的问题。
sed
can probably be cozened into doing it, but for multiline blocks you're better off with something easier to work with. Evenawk
would be an improvement, but I'd be looking at Perl/Python/scripting language of choice. Preferably with a parser, which would also save you the initialindent
run.In fact, I'd look for a parser that generated an annotated syntax tree, which makes refactoring largely a matter of moving tree branches around.