首页 > 解决方案 > Eiffel:如何获取过程的特定操作数的类型

问题描述

正如我在调试器中看到的那样,可以获取操作数和过程名称,有没有办法获取它?

在此处输入图像描述

似乎 estudio 可以访问 ROUTINE 客户端所没有的信息,为什么他是特权者?他在作弊吗?

标签: introspectioneiffel

解决方案


以下代码演示了如何检索有关例程对象的开放参数类型的信息:

        p: ROUTINE -- Routine object.
        t: TYPE [detachable ANY] -- Current open argument type.
    do
        p := agent (i: INTEGER; s: STRING)
            do
            end
        across
            1 |..| p.open_count as i
        loop
            t := p.generating_type.generic_parameter_type (1).generic_parameter_type (i.item)
            io.put_string (t.name)
            io.put_new_line
        end

对我来说,上面的代码打印

INTEGER_32
!STRING_8

注释:

  1. p.open_count给出开放参数的总数.
  2. p.generating_type检索例程对象的类型。
  3. p.generating_type.generic_parameter_type (1)检索开放参数元组对象的类型。
  4. 最终调用generating_type检索带有 index 的打开参数的类型i.item

推荐阅读