简体   繁体   English

任何可以处理这种情况的优秀C ++重构工具

[英]Any good C++ refactoring tools that could handle this scenario

I have a large C++ code base that contains a couple of functions for error logging that I'm planning to rewrite, defined as follows; 我有一个很大的C ++代码库,其中包含一些我打算重写的错误记录功能,定义如下:

void LogError(ErrorLevel elvl,LPCTSTR Format,...);  // Literal version
void LogError(ErrorLevel elvl,UINT ResourceID,...); // Resource version

I'm planning to rewrite these as a single function 我打算将它们重写为一个函数

void LogError(ErrNo No,...);

ErrNo in this case is will be an enum, used to look up the rest of the error details from an external file. 在这种情况下,ErrNo将是一个枚举,用于从外部文件中查找其余的错误详细信息。 While I'm using and love Visual Assist, it doesn't appear to be up to this kind of thing. 当我使用并喜欢Visual Assist时,它似乎并不取决于这种情况。 I'm thinking the easiest way to carry out this refactor is to write a small program that uses the results of a search output to find all the occurences of this function, eg 我认为执行此重构的最简单方法是编写一个小程序,该程序使用搜索输出的结果来查找此函数的所有出现情况,例如

    c:\cpp\common\Atlas\Comps\LSADJUST.cpp
        LSAFormNormalEquations (174):    LogError(elvl_Error,IDS_WINWRN0058,i+1,TravObs.setup_no,TravObs.round_no
        LSAFormNormalEquations (180):    LogError(elvl_Error,IDS_WINWRN0059,i+1,TravObs.setup_no,TravObs.round_no
        LSAFormNormalEquations (186):    LogError(elvl_Error,IDS_WINWRN0060,i+1,TravObs.setup_no,TravObs.round_no
    c:\cpp\common\Atlas\Comps\LSADJUSTZ.CPP
        LSAFormNormalEquationsZ (45):    LogError(elvl_Note,_T("Adjusting heights by least squares"));
    c:\cpp\Win32\Atlas\Section\OptmizeSectionVolumes.cpp
        OnSectionOptimizeVolumes (239):    LogError(elvl_Note,"Shifted section at chainage %0.1lf by %0.3lf",Graph.c1,Offset);

and then parse and modify the source. 然后解析并修改源。 Are there any other tools that could simplify this task for me? 还有其他工具可以简化我的工作吗? If looked at a related question which suggets there isn't much out there. 如果看一个有关建议的问题 ,那边就没有太多了。 I don't mind spending a small amount for a reasonably easy to use tool, but don't have the time or budget for anything more than this. 我不介意为合理易用的工具花费少量资金,但没有时间或预算来做更多的事情。

If you were using Unix, using sed to edit all your source-code might handle most of the changes. 如果使用Unix,则使用sed编辑所有源代码可能会处理大多数更改。 You would have to complete some of the changes by hand. 您将需要手动完成一些更改。 I have used this technique in the past. 我过去曾经使用过这种技术。

Searching around for something light weight that met my needs drew a blank, and learning SED while worthwhile would have been a fair amount of work for something that did not quite solve my problem. 寻找可以满足我需求的轻量级物品成为空白,而在值得的同时学习SED对于那些不能完全解决我的问题的东西来说将是很多工作。 I ended up writing my own tool to carry out the refactor needed on a seperate copy of the code base until I was happy that it was doing exactly what I needed. 我最终编写了自己的工具,以在单独的代码库副本上执行所需的重构,直到我对它完全满足我的要求感到满意为止。 This involved taking the output from Visual Assists find all references option, and use it to refactor the code base. 这涉及从Visual Assists的输出中找到所有引用选项,并使用它来重构代码库。 I'd post the code, but as it stands is pretty awful and would be liable to fail under a different code base. 我会发布代码,但就目前情况而言,这太糟糕了,在不同的代码库下可能会失败。 The general problem can be better stated as something like this 一般问题可以更好地表述为:

  • For a C++ code base, find every occurence of function fn taking parameters a,b,...n 对于C ++代码库,使用参数a,b,... n查找函数fn的每一次出现
  • Remove the occurence of fn from the source file 从源文件中删除fn的出现
  • Extract the parameters as text variables 将参数提取为文本变量
  • Add a few more variables such as instance number, source file name, etc... 添加更多变量,例如实例号,源文件名等。
  • At the point where fn was removed, write a formatted string that can include available variables 在删除fn的那一点上,编写一个可以包含可用变量的格式化字符串
  • Append similar formatted strings to one or more external files (eg resource files etc...) 将类似格式的字符串附加到一个或多个外部文件(例如资源文件等)

I'm guessing the above functionality would be easy enough to implement for someone who is already parsing the source, and will pass a link to this question to Whole Tomato as an enhancement suggestion. 我猜想对于已经解析了源代码的人来说,上面的功能将很容易实现,并将此问题的链接传递给Whole Tomato作为增强建议。

Edit: For anyone interested, there's some follow up on the VA forum here . 编辑:对于任何感兴趣的人,这里的VA论坛都有一些后续活动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM