Tags#
Tagged types and type extensions support object-oriented programming, based on inheritance with extension and run-time polymorphism via dispatching operations.
package Ada.Tags
with Preelaborate, Nonblocking, Global => in out synchronized is
type Tag is private
with Preelaborable_Initialization;
type Tag_Array is array(Positive range <>) of Tag;
Tag_Error: exception;
No_Tag: constant Tag;
function Expanded_Name(T: Tag) return String;
function External_Tag (T: Tag) return String;
function Parent_Tag (T: Tag) return Tag;
function Is_Abstract (T: Tag) return Boolean;
function Internal_Tag (External: String) return Tag;
function Descendant_Tag(External: String; Ancestor: Tag) return Tag;
function Is_Descendant_At_Same_Level(Descendant, Ancestor: Tag) return Boolean;
function Interface_Ancestor_Tags(T: Tag) return Tag_Array;
function Wide_Expanded_Name (T: Tag) return Wide_String;
function Wide_Wide_Expanded_Name(T: Tag) return Wide_Wide_String;
end Ada.Tags;
Generic Dispatching Constructor
generic
type T(<>) is abstract tagged limited private;
type Parameters(<>) is limited private;
with function Constructor(Params: not null access Parameters) return T is abstract;
function Ada.Tags.Generic_Dispatching_Constructor(The_Tag: Tag;
Params : not null access Parameters)
return T'Class
with Preelaborate, Nonblocking,
Convention => Intrinsic,
Global => in out synchronized;
Erroneous Execution
If an internal tag provided to an instance of Tags.Generic_Dispatching_Constructor
or to any subprogram
declared in package Tags
identifies either a type that is not library-level and whose tag has not been
created (see 13.14), or a type that does not exist in the partition at the time of the call, then execution
is erroneous.
Examples of tagged record types
type Point is tagged record
X, Y: Real := 0.0;
end record;
type Expression is tagged null record;
-- Components will be added by each extension
Tag Attributes#
For every subtype S
of a tagged type T
(specific or class-wide), the following attributes are defined:
Attribute |
Description |
---|---|
S'Class |
S'Class denotes a subtype of the class-wide type (called T'Class in this document) for the class rooted at T (or if S already denotes a class-wide subtype, then S'Class is the same as S ). S'Class is unconstrained. However, if S is constrained, then the values of S'Class are only those that when converted to the type T belong to S . |
S'Tag |
S'Tag denotes the tag of the type T (or if T is class-wide, the tag of the root type of the corresponding class). The value of this attribute is of type Tag . |
Given a prefix X
that is of a class-wide tagged type [(after any implicit dereference)], the following attribute
is defined:
Attribute |
Description |
---|---|
X'Tag |
X'Tag denotes the tag of X . The value of this attribute is of type Tag . |