逆向工程 C++使用“企业架构师”编写代码
这又是一个“如何正确地做”的问题。抱歉,如果有人生气了。
我必须理解大约 150 个 C/C++ 混合物的 TLOC。我已经在 UML 工具“Enterprise Architect”中导入了代码,并得到了一个凌乱的图表。由于这种类似 C 的构造,许多结构和枚举都具有匿名名称:typedef struct/enum {...} MyType;
在第二次运行中,我将其转换为 C++ 形式:struct/ enum MyType{...};
但得到了一堆不相关的结构。不幸的是,Enterprise Architect 无法解析 typedef。例如,A、B 和 C 之间没有关系被识别:
struct A;
struct B;
typedef A *PtrA;
typedef List<B> BList;
struct C{ PtrA pA; BList lB; };
由于整个命名约定,我能够用原始类型替换所有 typedef,如下所示:
struct C{ A pA; B lB; };
现在在“企业架构师”中导入源代码给出了包含所有关系的漂亮图表。 当然,代码无法编译,并且不一样。代码中的所有更改都需要进行烦人的转换,以使 EA 再次可以理解此“伪”代码。因此我的问题是:
- 是否有可能教授 EA 识别原始类型?
- 其他 UML 工具是否识别这些类型 (并在它们之间建立关系) 更稳健?
非常感谢您的任何建议! 瓦伦丁·海尼茨
It is again a sort of "how to do it properly" question. Sorry if someone is annoyed.
I've got to understand ca 150 TLOCs of C/C++ mixture. I've imported the code in UML-Tool "Enterprise Architect" and got a messy chart. Many Structs and Enums had anonymous names because of this C-ish constructs: typedef struct/enum {...} MyType;
In second run I've converted it to C++ form: struct/enum MyType{...};
but got a bunch of unrelated structs. Unfortunately, Enterprise Architect doesn't resolve typedefs. e.g. no relations between A, B and C were recognized:
struct A;
struct B;
typedef A *PtrA;
typedef List<B> BList;
struct C{ PtrA pA; BList lB; };
Thanks to throughout naming convention, I was able to replace all typedefs by original type like this:
struct C{ A pA; B lB; };
Now importing source-code in "Enterprise Architect" gave a nice diagram with all relations.
Of cause, the code doesn't compile, and is not the same. All changes in code require an annoying conversion for making this "pseudo" code understandable by EA again. Therefore my questions:
- Is there any possibility to teach EA
recognizing the original types? - Do other UML-Tools recognize the types
(and create relations between them)
more robust?
Thank you very much for any advice!
Valentin Heinitz
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我有 Enterprise Architect,并且几乎总是为了在大型代码体上执行您尝试的操作,我使用 doxygen 代替。它生成类图和调用图。将其与 GraphViz 和“UML 样式”类图一起使用,您将获得相当好的代码导航和理解工具,具有灵活的配置,可以根据需要添加或排除细节。
I have Enterprise Architect, and almost invariably for doing what you are attempting on a large code body I use doxygen instead. It generates both class and call graphs. Use it with GraphViz and "UML-style" class diagrams, and you have a reasonably good code navigation and comprehension tool, with flexible configuration to add or exclude detail as necessary.