解决方法"配置不支持动态接口转换"

时间:2018-06-12 13:25:30

标签: oop interface ada dispatch ada2012

我有一个面向对象的设计如下(Ada 2012)。 问题不在于设计本身,而在于特定运行时配置文件的后果。

-- several packages ommitted here, ads/adb mixed together
type Interface_A is interface;
type Interface_A_Class_Access is access all Interface_A'Class;

type Interface_B is interface and Interface_A;
type Interface_B_Class_Access is access all Interface_B'Class;

type Interface_C is interface and Interface_B
type Interface_C_Class_Access is access all Interface_C'Class;

type B_Impl is abstract tagged ...;
type B_Impl_Access is access all B_Impl;
type C_Impl is new B_Impl and Interface_C ...;
type C_Impl_Access is access all C_Impl;

function Create_C return C_Impl_Access is begin
   return new C_Impl'(...);
end Create;

我有一个工厂来实例化Interface_A,Interface_B或Interface_C的对象。

package body My_Factory is
   procedure Create_A return Interface_A_Class_Access is begin
      return Create_A_Impl; -- error: dynamic interface conversion not supported by configuration
   end Create_B;

   procedure Create_B return Interface_B_Class_Access is begin
      return Create_C_Impl; -- error: dynamic interface conversion not supported by configuration
   end Create_B;

   procedure Create_C return Interface_C_Class_Access is begin
      return Create_C_Impl; -- error: dynamic interface conversion not supported by configuration
   end Create_C;
end package My_Factory;

使用我的开关,我为两个工厂创建功能都收到以下错误:

error: dynamic interface conversion not supported by configuration

环境:

  • GNAT 17.2
  • ZFP MPC8641
  • GPRBUILD Pro 18 +

到目前为止我尝试了什么:

  1. 使用显式强制转换或显式临时变量分配更改工厂实施:
  2. 样品:

    package body My_Factory is
       ...
       procedure Create_B return Interface_B_Class_Access is begin
          return Interface_B_Class_Access(Create_C); -- error: dynamic interface conversion not supported by configuration
       end Create_B;
    
       procedure Create_C return Interface_C_Class_Access is
          tmp : Interface_C_Class_Access;
       begin
          tmp := Create_C; -- error: dynamic interface conversion not supported by configuration
          return tmp;
       end Create_C;
    end package My_Factory;
    

    同样的问题。

    1. 添加显式构造函数方法(将' new'表示为类访问变量)
    2. 样品:

      function Create_C return Interface_A_Class_Access is begin
         return new C_Impl'(...); -- error: dynamic interface conversion not supported by configuration
      end Create;
      
      function Create_C return Interface_B_Class_Access is
         tmp : Interface_B_Class_Access;
      begin
         tmp := new C_Impl'(...); -- works fine
         return tmp;
      end Create;
      
      function Create_C return Interface_C_Class_Access is
         tmp : Interface_B_Class_Access;
      begin
         tmp := new C_Impl'(...); -- works fine
         return tmp;
      end Create;
      

      第二种选择正常。

      1. 使用标准配置文件时,不会出现问题。我(天真地)移植到特定的配置文件时遇到了这个问题。据我所知,这是合法的面向对象设计,但有些结构不是以同样的方式处理。
      2. 我的问题:

        1. 我的第二个选择是否可以接受?为什么会有效?

        2. 我错过了什么吗?我知道这与编译器生成的代码管理调度表有一定关系,但我并没有真正得到深层机制/原因。

1 个答案:

答案 0 :(得分:2)

"配置不支持"消息提示这是运行时的限制。并且您正在使用零占用(ZFP)运行时,例如,当涉及到不确定类型(如类范围类型和无约束数组)时,它具有严重的限制。

运行时文档应提供有关这些限制/限制的更多信息。