Ada派生类型与基元操作

Ada派生类型与基元操作,ada,Ada,我有下面的Ada代码 type U i s tagged private ; type W i s new U with private ; type X i s new W with private ; procedure m1 (P1 : U; P2 : in out U; P3 : Integer ) ; procedure m2 (P1 : Float ; P2 : in out U) ; procedure m2 (P1 : Float ; P2 : Boolean ; P3 : i

我有下面的Ada代码

type U i s tagged private ;
type W i s new U with private ;
type X i s new W with private ;

procedure m1 (P1 : U; P2 : in out U; P3 : Integer ) ;
procedure m2 (P1 : Float ; P2 : in out U) ;
procedure m2 (P1 : Float ; P2 : Boolean ; P3 : in out W) ;
不,我不明白在派生类型中这个操作会发生什么。 我认为这三个步骤都是原始操作

但是派生类型中的过程的签名是什么呢

可能是这个吗

procedure m1 (P1 : W; P2 : in out U; P3 : Integer ) ;
procedure m2 (P1 : Float ; P2 : in out W) ;
procedure m2 (P1 : Float ; P2 : Boolean ; P3 : in out X) ;

或者,在派生类型中,这3个过程的签名是什么样子的?

当类型T有一个基本子程序,并且您说“类型T2是新的T”或“类型T2是新的T,带有…”时,将隐式声明一个新的子程序。在新的子程序中,如果任何参数类型为
T
access T
,则将其替换为
T2
access T2
;如果它是一个返回类型为
T
access T
的函数,则返回类型将被类似地替换

如果不涉及
private
类型或扩展,则新子程序将在派生类型之后隐式声明。例如:

type U is tagged null record ;
procedure m1 (P1 : U; P2 : in out U; P3 : Integer ) ;
procedure m2 (P1 : Float ; P2 : in out U) ;

type W is new U with null record ;
-- procedure m1 (P1 : W; P2 : in out W; P3 : Integer ) ; --implicitly declared
-- procedure m2 (P1 : Float ; P2 : in out W) ; --implicitly declared
procedure m2 (P1 : Float ; P2 : Boolean ; P3 : in out W);
    -- this last is a *new* procedure.  It doesn't override the other m2 because
    -- it has a new Boolean parameter.  Instead, it's an example of *overloading*.

-- So now W has three primitive operations, two that were inherited and one that
-- is brand new.

type X is new W with null record ;
-- procedure m1 (P1 : X; P2 : in out X; P3 : Integer ) ; --implicitly declared
-- procedure m2 (P1 : Float ; P2 : in out X) ; --implicitly declared
-- procedure m2 (P1 : Float ; P2 : Boolean ; P3 : in out X); --implicitly declared

-- All three of W's primitive operations, including the implicitly declared ones,
-- are inherited for X.
带有private的
不会有太大的改变,只是它改变了隐式子程序的声明点。我相信它们是在完整的类型定义之后声明的,该定义将在包的私有部分中。这意味着它们不可见,除非在程序中可以看到包的私有部分的地方。(但是,调度操作仍可能调用它们。)

编辑:对于带有private的
案例,继承子程序的可见性由以下因素决定:

对于private_extension_声明,如果祖先的相应声明在该位置可见,则每个继承的子程序将在private_extension_声明之后立即声明。否则,不会为私有扩展声明继承的子程序,尽管它可能是为完整类型声明的

因此:

M1
M2
的声明在第一次声明
W
的位置可见;因此,他们在这一点上是继承的。由于该点位于P的公共部分,因此任何使用P
的包都可以引用它们。但是:

package P is

    type U is tagged private;

    type W is new U with private;

    procedure M1 (P1 : U; P2 : in out U; P3 : Integer);
    procedure M2 (P1 : Float ; P2 : in out U);

private
    type U is ... -- full type definition
    type W is new U with ...  -- full type definition
    --procedure M1 (P1 : W; P2 : in out W; P3 : Integer); -- implicitly declared
    --procedure M2 (P1 : Float ; P2 : in out W); -- implicitly declared
end P;
M1
M2
的声明在第一次声明
W
时不可见,因为它们尚未被看到。因此,在这一点上它们不是继承的。但隐式声明将在稍后看到完整类型时继承。但是,这些隐式声明位于
P
private
部分;因此,只能在程序中可以看到
P
private
部分,即
P
的主体和
P
的子包中的适当位置直接调用它们(即不通过调度)

package P is

    type U is tagged private;

    type W is new U with private;

    procedure M1 (P1 : U; P2 : in out U; P3 : Integer);
    procedure M2 (P1 : Float ; P2 : in out U);

private
    type U is ... -- full type definition
    type W is new U with ...  -- full type definition
    --procedure M1 (P1 : W; P2 : in out W; P3 : Integer); -- implicitly declared
    --procedure M2 (P1 : Float ; P2 : in out W); -- implicitly declared
end P;