C 代码重构工具可在 GNU/Linux 上使用吗?自由开源软件更可取

发布于 2025-01-08 07:25:43 字数 281 浏览 3 评论 0原文

有人问过这个问题的变体,但不是特定于 GNU/Linux 和 C。我使用 Komodo Edit 作为我常用的编辑器,但实际上我更喜欢可以从 CLI 使用的东西。 我不需要 C++ 支持;如果该工具只能处理普通的 C 就很好了。

我真的很感激任何指示,因为我找不到任何东西。 我希望我不会被迫自己“滚动”一些东西。

注意:请不要提及 vim;我知道它的存在以及它的功能是什么。我故意选择避免使用 vim,这就是我使用 Komodo(或服务器上的 nano)的原因。

Variations of this question have been asked, but not specific to GNU/Linux and C. I use Komodo Edit as my usual Editor, but I'd actually prefer something that can be used from CLI.
I don't need C++ support; it's fine if the tool can only handle plain C.

I really appreciate any direction, as I was unable to find anything.
I hope I'm not forced to 'roll' something myself.

NOTE: Please refrain from mention vim; I know it exists and what its capabilities are. I purposefully choose to avoid vim, which is why I use Komodo (or nano on the servers).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

森末i 2025-01-15 07:25:43

我认为纯粹的控制台重构工具不好用。
我在 Linux 上使用 Eclipse CDT 来编写和重构 C 代码。
还有用于 Emacs 的 Xrefactory http://www.xref.sk/xrefactory/main.html

如果非控制台重构工具也适合您。

I don't think that a pure console refactoring tool would be nice to use.
I use Eclipse CDT on linux to write and refactor C-Code.
There exists also Xrefactory for Emacs http://www.xref.sk/xrefactory/main.html

if a non console refactoring tool is o.k for you as well.

全部不再 2025-01-15 07:25:43

C-xrefactory 是 xrefactory 的开源版本,涵盖 C 和 Java,在 SourceForge 由 Marián Vittek 根据 GPLv2 开发。

对于那些感兴趣的人,GitHub 上有一个积极维护的 c-xrefactory 分支:

https://github.com/thoni56 /c-xrefactory

GitHub fork 的目标是重构 c-xrefactory 本身,添加测试套件,并尝试记录原始源代码(这是相当晦涩的)。也许,将来也将其转换为LSP C语言服务器和重构工具。

C-xrefactory 适用于 Emacs;安装脚本和说明可以在存储库中找到。 Windows 用户可以通过 WSL/WSL2 运行它。

C-xrefactory was an open source version of xrefactory, covering C and Java, made available on SourceForge by Marián Vittek under GPLv2.

For those interested, there's an actively maintained c-xrefactory fork on GitHub:

https://github.com/thoni56/c-xrefactory

The goal of the GitHub fork is to refactor c-xrefactory itself, add a test suite, and try to document the original source code (which is rather obscure). Maybe, in the future, also convert it into an LSP C language server and refactoring tool.

C-xrefactory works on Emacs; setup scripts and instructions can be found at the repository. Windows users can run it via WSL/WSL2.

溺渁∝ 2025-01-15 07:25:43

您可以考虑为您的 GCC 插件或 MELT 扩展(MELT 是扩展 GCC 的领域特定语言)编写代码需要。

但是,这种方法会花费您一些时间,因为您需要了解一些 GCC 内部结构。

You could consider coding a GCC plugin or a MELT extension (MELT is a domain specific language to extend GCC) for your needs.

However, such approach would take you some time, because you'll need to understand some of GCC internals.

小巷里的女流氓 2025-01-15 07:25:43

仅适用于 Windows,不适用于 FOSS,但您说“任何方向...”

我们的 DMS 软件重组Toolkit” 及其 C 前端 可以将转换应用于 C 源代码 可以配置 DMS 来执行自定义、复杂的可靠转换,尽管配置并不像仅键入“refactor frazzle by doobaz”这样的命令那么简单

。主要的障碍仍然是预处理器可以转换在典型位置(语句、表达式、if/for/while 循环头、声明等)具有预处理器指令的代码,但其他“非结构化条件”。您可以通过扩展不存在的预处理器指令来运行 DMS,或者更重要的是,扩展那些给它带来麻烦的指令,但大多数人不喜欢这样做,因为他们更喜欢保留他们的预处理器指令。所以它并不完美。

[另一个答案建议Concinelle,从我的角度来看,它看起来相当不错。据我所知,它根本不处理预处理器指令;我可能是错的,它可能会像 DMS 那样处理某些情况,但我确信它不能处理所有情况]。

您不想考虑自己推出。构建转换/重构工具比您从未尝试过的想象要困难得多。您需要针对感兴趣的 (C) 方言完整、准确的解析器,而这很难做到正确。你需要一个预处理器、符号表、流分析、转换、代码重新生成机制……这些东西需要多年的努力才能构建并得到正确的结果。相信我,去过那里,做过那件事。

For Windows only, and not FOSS but you said "any direction..."

Our DMS Software Reengineering Toolkit" with its C Front End can apply transformations to C source code. DMS can be configured to carry out custom, complex reliable transformations, although the configuration isn't as easy as typing just a command like "refactor frazzle by doobaz".

One of the principal stumbling blocks is still the preprocessor. DMS can transform code that has preprocessor directives in typical places (around statements, expressions, if/for/while loop heads, declarations, etc.) but other "unstructured conditionals" give it trouble. You can run DMS by expanding the preprocessor directives out of existence, or more imporantly, expanding out the ones that give it trouble, but mostly people don't like this because they prefer to keep thier preprocessor directives. So it isn't perfect.

[Another answer suggested Concinelle, which looks pretty good from my point of view. As far as I know, it doesn't handle preprocessor directives at all; I could be wrong and it might handle some cases as DMS does, but I'm sure it can't handle all the cases].

You don't want to consider rolling your own. Building a transformation/refactoring tool is much harder than you might guess having never tried it. You need full, accurate parsers for the (C) dialect of interest and just that is pretty hard to get right. You need a preprocessor, symbol tables, flow analysis, transformation, code regeneration machinery, ... this stuff takes years of effort to build and get right. Trust me, been there, done that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文