用C支持的反思 [英] Reflection support in C

查看:83
本文介绍了用C支持的反思的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道它是不支持的,但如果有周围没有任何技巧我想知道。任何提示?

I know it is not supported, but I am wondering if there are any tricks around it. Any tips?

推荐答案

反射一般是一个程序来分析一些code结构的手段。
这种分析是用来改变code的有效行为

Reflection in general is a means for a program to analyze the structure of some code. This analysis is used to change the effective behavior of the code.

反思分析一般很弱;通常它只能提供访问功能和字段名称。这个弱点来自于语言的实现基本上是不想使在运行时可用的完整源$ C ​​$ C,用适当的分析程序以及提取​​源$ C ​​$ C自己想要的东西。

Reflection as analysis is generally very weak; usually it can only provide access to function and field names. This weakness comes from the language implementers essentially not wanting to make the full source code available at runtime, along with the appropriate analysis routines to extract what one wants from the source code.

另一种方法是在解决方案的分析头,通过使用强大的程序分析工具,例如,一个可以解析原文完全相同的编译器的方式。
(人们经常提出滥用编译器本身要做到这一点,但通常不工作;编译器机械希望成为一个编译器,它是织补很难将它屈从于其他目的)。

Another approach is tackle program analysis head on, by using a strong program analysis tool, e.g., one that can parse the source text exactly the way the compiler does it. (Often people propose to abuse the compiler itself to do this, but that usually doesn't work; the compiler machinery wants to be a compiler and it is darn hard to bend it to other purposes).

所需要的是一种工具,


  • 解析语言的源文本

  • 构建抽象语法树重新presenting程序的每一个细节。
    (它是有益的,如果AST的保留源的意见和其他细节
     code布局,如列数,文字基数值等。)

  • 构建出每个标识符的范围和含义的符号表

  • 可以从函数中提取控制流

  • 可以extact从code数据流量

  • 可以构造一个调用图形为系统

  • 可以确定每个指针指向的

  • 启用自定义分析仪使用上述事实建设

  • 可根据自定义等分析改造code
    (通常通过修改该重新present解析code中的AST的)

  • 可以再生的源文本(包括布局和评论)从
    修订后的AST的。

使用这种机器,一个在任何需要的详细程度实现了分析,然后变换code以实现运行时反射会达到的效果。
有几大好处:

Using such machinery, one implements analysis at whatever level of detail is needed, and then transforms the code to achieve the effect that runtime reflection would accomplish. There are several major benefits:


  • 分析的详细程度和量是野心的问题(例如,它不
    通过何种运行时反射只能做有限的)

  • 没有任何运行时开销,以实现行为的反射变化

  • 当事人可以是一般性的和在许多语言应用,而这些机器
    不是被限制到什么特定的语言实现提供。

  • 这是你不支付你不使用什么C / C ++的想法兼容。
    如果你不需要思考,不需要这个机器。和你的语言
    并不需要有弱反射内置的智能行李。

请参阅我们的 DMS软件再造工具包的系统,可以做到以上适用于C, Java和COBOL,而且大部分用于C ++。

See our DMS Software Reengineering Toolkit for a system that can do all of the above for C, Java, and COBOL, and most of it for C++.

这篇关于用C支持的反思的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆