1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2018, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree
; use Atree
;
27 with Checks
; use Checks
;
28 with Debug
; use Debug
;
29 with Einfo
; use Einfo
;
30 with Elists
; use Elists
;
31 with Errout
; use Errout
;
32 with Expander
; use Expander
;
33 with Exp_Atag
; use Exp_Atag
;
34 with Exp_Ch6
; use Exp_Ch6
;
35 with Exp_CG
; use Exp_CG
;
36 with Exp_Dbug
; use Exp_Dbug
;
37 with Exp_Tss
; use Exp_Tss
;
38 with Exp_Util
; use Exp_Util
;
39 with Freeze
; use Freeze
;
40 with Ghost
; use Ghost
;
41 with Itypes
; use Itypes
;
42 with Layout
; use Layout
;
43 with Nlists
; use Nlists
;
44 with Nmake
; use Nmake
;
45 with Namet
; use Namet
;
47 with Output
; use Output
;
48 with Restrict
; use Restrict
;
49 with Rident
; use Rident
;
50 with Rtsfind
; use Rtsfind
;
52 with Sem_Aux
; use Sem_Aux
;
53 with Sem_Ch6
; use Sem_Ch6
;
54 with Sem_Ch7
; use Sem_Ch7
;
55 with Sem_Ch8
; use Sem_Ch8
;
56 with Sem_Disp
; use Sem_Disp
;
57 with Sem_Eval
; use Sem_Eval
;
58 with Sem_Res
; use Sem_Res
;
59 with Sem_Type
; use Sem_Type
;
60 with Sem_Util
; use Sem_Util
;
61 with Sinfo
; use Sinfo
;
62 with Sinput
; use Sinput
;
63 with Snames
; use Snames
;
64 with Stand
; use Stand
;
65 with Stringt
; use Stringt
;
66 with SCIL_LL
; use SCIL_LL
;
67 with Tbuild
; use Tbuild
;
69 package body Exp_Disp
is
71 -----------------------
72 -- Local Subprograms --
73 -----------------------
75 function Default_Prim_Op_Position
(E
: Entity_Id
) return Uint
;
76 -- Ada 2005 (AI-251): Returns the fixed position in the dispatch table
77 -- of the default primitive operations.
79 function Has_DT
(Typ
: Entity_Id
) return Boolean;
80 pragma Inline
(Has_DT
);
81 -- Returns true if we generate a dispatch table for tagged type Typ
83 function Is_Predefined_Dispatching_Alias
(Prim
: Entity_Id
) return Boolean;
84 -- Returns true if Prim is not a predefined dispatching primitive but it is
85 -- an alias of a predefined dispatching primitive (i.e. through a renaming)
87 function New_Value
(From
: Node_Id
) return Node_Id
;
88 -- From is the original Expression. New_Value is equivalent to a call to
89 -- Duplicate_Subexpr with an explicit dereference when From is an access
92 function Original_View_In_Visible_Part
(Typ
: Entity_Id
) return Boolean;
93 -- Check if the type has a private view or if the public view appears in
94 -- the visible part of a package spec.
98 Typ
: Entity_Id
) return Node_Id
;
99 -- Ada 2005 (AI-345): Determine the primitive operation kind of Prim
100 -- according to its type Typ. Return a reference to an RE_Prim_Op_Kind
101 -- enumeration value.
103 function Tagged_Kind
(T
: Entity_Id
) return Node_Id
;
104 -- Ada 2005 (AI-345): Determine the tagged kind of T and return a reference
105 -- to an RE_Tagged_Kind enumeration value.
107 ----------------------
108 -- Apply_Tag_Checks --
109 ----------------------
111 procedure Apply_Tag_Checks
(Call_Node
: Node_Id
) is
112 Loc
: constant Source_Ptr
:= Sloc
(Call_Node
);
113 Ctrl_Arg
: constant Node_Id
:= Controlling_Argument
(Call_Node
);
114 Ctrl_Typ
: constant Entity_Id
:= Base_Type
(Etype
(Ctrl_Arg
));
115 Param_List
: constant List_Id
:= Parameter_Associations
(Call_Node
);
121 Eq_Prim_Op
: Entity_Id
:= Empty
;
124 if No_Run_Time_Mode
then
125 Error_Msg_CRT
("tagged types", Call_Node
);
129 -- Apply_Tag_Checks is called directly from the semantics, so we
130 -- need a check to see whether expansion is active before proceeding.
131 -- In addition, there is no need to expand the call when compiling
132 -- under restriction No_Dispatching_Calls; the semantic analyzer has
133 -- previously notified the violation of this restriction.
135 if not Expander_Active
136 or else Restriction_Active
(No_Dispatching_Calls
)
141 -- Set subprogram. If this is an inherited operation that was
142 -- overridden, the body that is being called is its alias.
144 Subp
:= Entity
(Name
(Call_Node
));
146 if Present
(Alias
(Subp
))
147 and then Is_Inherited_Operation
(Subp
)
148 and then No
(DTC_Entity
(Subp
))
150 Subp
:= Alias
(Subp
);
153 -- Definition of the class-wide type and the tagged type
155 -- If the controlling argument is itself a tag rather than a tagged
156 -- object, then use the class-wide type associated with the subprogram's
157 -- controlling type. This case can occur when a call to an inherited
158 -- primitive has an actual that originated from a default parameter
159 -- given by a tag-indeterminate call and when there is no other
160 -- controlling argument providing the tag (AI-239 requires dispatching).
161 -- This capability of dispatching directly by tag is also needed by the
162 -- implementation of AI-260 (for the generic dispatching constructors).
164 if Ctrl_Typ
= RTE
(RE_Tag
)
165 or else (RTE_Available
(RE_Interface_Tag
)
166 and then Ctrl_Typ
= RTE
(RE_Interface_Tag
))
168 CW_Typ
:= Class_Wide_Type
(Find_Dispatching_Type
(Subp
));
170 -- Class_Wide_Type is applied to the expressions used to initialize
171 -- CW_Typ, to ensure that CW_Typ always denotes a class-wide type, since
172 -- there are cases where the controlling type is resolved to a specific
173 -- type (such as for designated types of arguments such as CW'Access).
175 elsif Is_Access_Type
(Ctrl_Typ
) then
176 CW_Typ
:= Class_Wide_Type
(Designated_Type
(Ctrl_Typ
));
179 CW_Typ
:= Class_Wide_Type
(Ctrl_Typ
);
182 Typ
:= Find_Specific_Type
(CW_Typ
);
184 if not Is_Limited_Type
(Typ
) then
185 Eq_Prim_Op
:= Find_Prim_Op
(Typ
, Name_Op_Eq
);
188 -- Dispatching call to C++ primitive
190 if Is_CPP_Class
(Typ
) then
193 -- Dispatching call to Ada primitive
195 elsif Present
(Param_List
) then
197 -- Generate the Tag checks when appropriate
199 Param
:= First_Actual
(Call_Node
);
200 while Present
(Param
) loop
202 -- No tag check with itself
204 if Param
= Ctrl_Arg
then
207 -- No tag check for parameter whose type is neither tagged nor
208 -- access to tagged (for access parameters)
210 elsif No
(Find_Controlling_Arg
(Param
)) then
213 -- No tag check for function dispatching on result if the
214 -- Tag given by the context is this one
216 elsif Find_Controlling_Arg
(Param
) = Ctrl_Arg
then
219 -- "=" is the only dispatching operation allowed to get operands
220 -- with incompatible tags (it just returns false). We use
221 -- Duplicate_Subexpr_Move_Checks instead of calling Relocate_Node
222 -- because the value will be duplicated to check the tags.
224 elsif Subp
= Eq_Prim_Op
then
227 -- No check in presence of suppress flags
229 elsif Tag_Checks_Suppressed
(Etype
(Param
))
230 or else (Is_Access_Type
(Etype
(Param
))
231 and then Tag_Checks_Suppressed
232 (Designated_Type
(Etype
(Param
))))
236 -- Optimization: no tag checks if the parameters are identical
238 elsif Is_Entity_Name
(Param
)
239 and then Is_Entity_Name
(Ctrl_Arg
)
240 and then Entity
(Param
) = Entity
(Ctrl_Arg
)
244 -- Now we need to generate the Tag check
247 -- Generate code for tag equality check
249 -- Perhaps should have Checks.Apply_Tag_Equality_Check???
251 Insert_Action
(Ctrl_Arg
,
252 Make_Implicit_If_Statement
(Call_Node
,
256 Make_Selected_Component
(Loc
,
257 Prefix
=> New_Value
(Ctrl_Arg
),
260 (First_Tag_Component
(Typ
), Loc
)),
263 Make_Selected_Component
(Loc
,
265 Unchecked_Convert_To
(Typ
, New_Value
(Param
)),
268 (First_Tag_Component
(Typ
), Loc
))),
271 New_List
(New_Constraint_Error
(Loc
))));
277 end Apply_Tag_Checks
;
279 ------------------------
280 -- Building_Static_DT --
281 ------------------------
283 function Building_Static_DT
(Typ
: Entity_Id
) return Boolean is
284 Root_Typ
: Entity_Id
:= Root_Type
(Typ
);
288 -- Handle private types
290 if Present
(Full_View
(Root_Typ
)) then
291 Root_Typ
:= Full_View
(Root_Typ
);
295 Building_Static_Dispatch_Tables
296 and then Is_Library_Level_Tagged_Type
(Typ
)
298 -- If the type is derived from a CPP class we cannot statically
299 -- build the dispatch tables because we must inherit primitives
300 -- from the CPP side.
302 and then not Is_CPP_Class
(Root_Typ
);
304 if not Static_DT
then
305 Check_Restriction
(Static_Dispatch_Tables
, Typ
);
309 end Building_Static_DT
;
311 ----------------------------------
312 -- Building_Static_Secondary_DT --
313 ----------------------------------
315 function Building_Static_Secondary_DT
(Typ
: Entity_Id
) return Boolean is
316 Full_Typ
: Entity_Id
:= Typ
;
317 Root_Typ
: Entity_Id
:= Root_Type
(Typ
);
321 -- Handle private types
323 if Present
(Full_View
(Typ
)) then
324 Full_Typ
:= Full_View
(Typ
);
327 if Present
(Full_View
(Root_Typ
)) then
328 Root_Typ
:= Full_View
(Root_Typ
);
332 Building_Static_DT
(Full_Typ
)
333 and then not Is_Interface
(Full_Typ
)
334 and then Has_Interfaces
(Full_Typ
)
335 and then (Full_Typ
= Root_Typ
336 or else not Is_Variable_Size_Record
(Etype
(Full_Typ
)));
339 and then not Is_Interface
(Full_Typ
)
340 and then Has_Interfaces
(Full_Typ
)
342 Check_Restriction
(Static_Dispatch_Tables
, Typ
);
346 end Building_Static_Secondary_DT
;
348 ----------------------------------
349 -- Build_Static_Dispatch_Tables --
350 ----------------------------------
352 procedure Build_Static_Dispatch_Tables
(N
: Entity_Id
) is
353 Target_List
: List_Id
;
355 procedure Build_Dispatch_Tables
(List
: List_Id
);
356 -- Build the static dispatch table of tagged types found in the list of
357 -- declarations. The generated nodes are added at the end of Target_List
359 procedure Build_Package_Dispatch_Tables
(N
: Node_Id
);
360 -- Build static dispatch tables associated with package declaration N
362 ---------------------------
363 -- Build_Dispatch_Tables --
364 ---------------------------
366 procedure Build_Dispatch_Tables
(List
: List_Id
) is
371 while Present
(D
) loop
373 -- Handle nested packages and package bodies recursively. The
374 -- generated code is placed on the Target_List established for
375 -- the enclosing compilation unit.
377 if Nkind
(D
) = N_Package_Declaration
then
378 Build_Package_Dispatch_Tables
(D
);
380 elsif Nkind
(D
) = N_Package_Body
then
381 Build_Dispatch_Tables
(Declarations
(D
));
383 elsif Nkind
(D
) = N_Package_Body_Stub
384 and then Present
(Library_Unit
(D
))
386 Build_Dispatch_Tables
387 (Declarations
(Proper_Body
(Unit
(Library_Unit
(D
)))));
389 -- Handle full type declarations and derivations of library level
392 elsif Nkind_In
(D
, N_Full_Type_Declaration
,
393 N_Derived_Type_Definition
)
394 and then Is_Library_Level_Tagged_Type
(Defining_Entity
(D
))
395 and then Ekind
(Defining_Entity
(D
)) /= E_Record_Subtype
396 and then not Is_Private_Type
(Defining_Entity
(D
))
398 -- We do not generate dispatch tables for the internal types
399 -- created for a type extension with unknown discriminants
400 -- The needed information is shared with the source type,
401 -- See Expand_N_Record_Extension.
403 if Is_Underlying_Record_View
(Defining_Entity
(D
))
405 (not Comes_From_Source
(Defining_Entity
(D
))
407 Has_Unknown_Discriminants
(Etype
(Defining_Entity
(D
)))
409 not Comes_From_Source
410 (First_Subtype
(Defining_Entity
(D
))))
414 Insert_List_After_And_Analyze
(Last
(Target_List
),
415 Make_DT
(Defining_Entity
(D
)));
418 -- Handle private types of library level tagged types. We must
419 -- exchange the private and full-view to ensure the correct
420 -- expansion. If the full view is a synchronized type ignore
421 -- the type because the table will be built for the corresponding
422 -- record type, that has its own declaration.
424 elsif (Nkind
(D
) = N_Private_Type_Declaration
425 or else Nkind
(D
) = N_Private_Extension_Declaration
)
426 and then Present
(Full_View
(Defining_Entity
(D
)))
429 E1
: constant Entity_Id
:= Defining_Entity
(D
);
430 E2
: constant Entity_Id
:= Full_View
(E1
);
433 if Is_Library_Level_Tagged_Type
(E2
)
434 and then Ekind
(E2
) /= E_Record_Subtype
435 and then not Is_Concurrent_Type
(E2
)
437 Exchange_Declarations
(E1
);
438 Insert_List_After_And_Analyze
(Last
(Target_List
),
440 Exchange_Declarations
(E2
);
447 end Build_Dispatch_Tables
;
449 -----------------------------------
450 -- Build_Package_Dispatch_Tables --
451 -----------------------------------
453 procedure Build_Package_Dispatch_Tables
(N
: Node_Id
) is
454 Spec
: constant Node_Id
:= Specification
(N
);
455 Id
: constant Entity_Id
:= Defining_Entity
(N
);
456 Vis_Decls
: constant List_Id
:= Visible_Declarations
(Spec
);
457 Priv_Decls
: constant List_Id
:= Private_Declarations
(Spec
);
462 if Present
(Priv_Decls
) then
463 Build_Dispatch_Tables
(Vis_Decls
);
464 Build_Dispatch_Tables
(Priv_Decls
);
466 elsif Present
(Vis_Decls
) then
467 Build_Dispatch_Tables
(Vis_Decls
);
471 end Build_Package_Dispatch_Tables
;
473 -- Start of processing for Build_Static_Dispatch_Tables
476 if not Expander_Active
477 or else not Tagged_Type_Expansion
482 if Nkind
(N
) = N_Package_Declaration
then
484 Spec
: constant Node_Id
:= Specification
(N
);
485 Vis_Decls
: constant List_Id
:= Visible_Declarations
(Spec
);
486 Priv_Decls
: constant List_Id
:= Private_Declarations
(Spec
);
489 if Present
(Priv_Decls
)
490 and then Is_Non_Empty_List
(Priv_Decls
)
492 Target_List
:= Priv_Decls
;
494 elsif not Present
(Vis_Decls
) then
495 Target_List
:= New_List
;
496 Set_Private_Declarations
(Spec
, Target_List
);
498 Target_List
:= Vis_Decls
;
501 Build_Package_Dispatch_Tables
(N
);
504 else pragma Assert
(Nkind
(N
) = N_Package_Body
);
505 Target_List
:= Declarations
(N
);
506 Build_Dispatch_Tables
(Target_List
);
508 end Build_Static_Dispatch_Tables
;
510 ------------------------------
511 -- Convert_Tag_To_Interface --
512 ------------------------------
514 function Convert_Tag_To_Interface
516 Expr
: Node_Id
) return Node_Id
518 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
519 Anon_Type
: Entity_Id
;
523 pragma Assert
(Is_Class_Wide_Type
(Typ
)
524 and then Is_Interface
(Typ
)
526 ((Nkind
(Expr
) = N_Selected_Component
527 and then Is_Tag
(Entity
(Selector_Name
(Expr
))))
529 (Nkind
(Expr
) = N_Function_Call
530 and then RTE_Available
(RE_Displace
)
531 and then Entity
(Name
(Expr
)) = RTE
(RE_Displace
))));
533 Anon_Type
:= Create_Itype
(E_Anonymous_Access_Type
, Expr
);
534 Set_Directly_Designated_Type
(Anon_Type
, Typ
);
535 Set_Etype
(Anon_Type
, Anon_Type
);
536 Set_Can_Never_Be_Null
(Anon_Type
);
538 -- Decorate the size and alignment attributes of the anonymous access
539 -- type, as required by the back end.
541 Layout_Type
(Anon_Type
);
543 if Nkind
(Expr
) = N_Selected_Component
544 and then Is_Tag
(Entity
(Selector_Name
(Expr
)))
547 Make_Explicit_Dereference
(Loc
,
548 Unchecked_Convert_To
(Anon_Type
,
549 Make_Attribute_Reference
(Loc
,
551 Attribute_Name
=> Name_Address
)));
554 Make_Explicit_Dereference
(Loc
,
555 Unchecked_Convert_To
(Anon_Type
, Expr
));
559 end Convert_Tag_To_Interface
;
565 function CPP_Num_Prims
(Typ
: Entity_Id
) return Nat
is
567 Tag_Comp
: Entity_Id
;
570 if not Is_Tagged_Type
(Typ
)
571 or else not Is_CPP_Class
(Root_Type
(Typ
))
576 CPP_Typ
:= Enclosing_CPP_Parent
(Typ
);
577 Tag_Comp
:= First_Tag_Component
(CPP_Typ
);
579 -- If number of primitives already set in the tag component, use it
581 if Present
(Tag_Comp
)
582 and then DT_Entry_Count
(Tag_Comp
) /= No_Uint
584 return UI_To_Int
(DT_Entry_Count
(Tag_Comp
));
586 -- Otherwise, count the primitives of the enclosing CPP type
594 Elmt
:= First_Elmt
(Primitive_Operations
(CPP_Typ
));
595 while Present
(Elmt
) loop
606 ------------------------------
607 -- Default_Prim_Op_Position --
608 ------------------------------
610 function Default_Prim_Op_Position
(E
: Entity_Id
) return Uint
is
611 TSS_Name
: TSS_Name_Type
;
614 Get_Name_String
(Chars
(E
));
617 (Name_Buffer
(Name_Len
- TSS_Name
'Length + 1 .. Name_Len
));
619 if Chars
(E
) = Name_uSize
then
622 elsif TSS_Name
= TSS_Stream_Read
then
625 elsif TSS_Name
= TSS_Stream_Write
then
628 elsif TSS_Name
= TSS_Stream_Input
then
631 elsif TSS_Name
= TSS_Stream_Output
then
634 elsif Chars
(E
) = Name_Op_Eq
then
637 elsif Chars
(E
) = Name_uAssign
then
640 elsif TSS_Name
= TSS_Deep_Adjust
then
643 elsif TSS_Name
= TSS_Deep_Finalize
then
646 -- In VM targets unconditionally allow obtaining the position associated
647 -- with predefined interface primitives since in these platforms any
648 -- tagged type has these primitives.
650 elsif Ada_Version
>= Ada_2005
or else not Tagged_Type_Expansion
then
651 if Chars
(E
) = Name_uDisp_Asynchronous_Select
then
654 elsif Chars
(E
) = Name_uDisp_Conditional_Select
then
657 elsif Chars
(E
) = Name_uDisp_Get_Prim_Op_Kind
then
660 elsif Chars
(E
) = Name_uDisp_Get_Task_Id
then
663 elsif Chars
(E
) = Name_uDisp_Requeue
then
666 elsif Chars
(E
) = Name_uDisp_Timed_Select
then
672 end Default_Prim_Op_Position
;
674 ----------------------
675 -- Elab_Flag_Needed --
676 ----------------------
678 function Elab_Flag_Needed
(Typ
: Entity_Id
) return Boolean is
680 return Ada_Version
>= Ada_2005
681 and then not Is_Interface
(Typ
)
682 and then Has_Interfaces
(Typ
)
683 and then not Building_Static_DT
(Typ
);
684 end Elab_Flag_Needed
;
686 -----------------------------
687 -- Expand_Dispatching_Call --
688 -----------------------------
690 procedure Expand_Dispatching_Call
(Call_Node
: Node_Id
) is
691 Loc
: constant Source_Ptr
:= Sloc
(Call_Node
);
692 Call_Typ
: constant Entity_Id
:= Etype
(Call_Node
);
694 Ctrl_Arg
: constant Node_Id
:= Controlling_Argument
(Call_Node
);
695 Ctrl_Typ
: constant Entity_Id
:= Base_Type
(Etype
(Ctrl_Arg
));
696 Param_List
: constant List_Id
:= Parameter_Associations
(Call_Node
);
701 New_Call_Name
: Node_Id
;
702 New_Params
: List_Id
:= No_List
;
705 Subp_Ptr_Typ
: Entity_Id
;
706 Subp_Typ
: Entity_Id
;
708 Eq_Prim_Op
: Entity_Id
:= Empty
;
709 Controlling_Tag
: Node_Id
;
711 procedure Build_Class_Wide_Check
;
712 -- If the denoted subprogram has a class-wide precondition, generate a
713 -- check using that precondition before the dispatching call, because
714 -- this is the only class-wide precondition that applies to the call.
716 function New_Value
(From
: Node_Id
) return Node_Id
;
717 -- From is the original Expression. New_Value is equivalent to a call
718 -- to Duplicate_Subexpr with an explicit dereference when From is an
721 ----------------------------
722 -- Build_Class_Wide_Check --
723 ----------------------------
725 procedure Build_Class_Wide_Check
is
726 function Replace_Formals
(N
: Node_Id
) return Traverse_Result
;
727 -- Replace occurrences of the formals of the subprogram by the
728 -- corresponding actuals in the call, given that this check is
729 -- performed outside of the body of the subprogram.
731 ---------------------
732 -- Replace_Formals --
733 ---------------------
735 function Replace_Formals
(N
: Node_Id
) return Traverse_Result
is
737 if Is_Entity_Name
(N
)
738 and then Present
(Entity
(N
))
739 and then Is_Formal
(Entity
(N
))
746 F
:= First_Formal
(Subp
);
747 A
:= First_Actual
(Call_Node
);
748 while Present
(F
) loop
749 if F
= Entity
(N
) then
750 Rewrite
(N
, New_Copy_Tree
(A
));
752 -- If the formal is class-wide, and thus not a
753 -- controlling argument, preserve its type because
754 -- it may appear in a nested call with a class-wide
757 if Is_Class_Wide_Type
(Etype
(F
)) then
758 Set_Etype
(N
, Etype
(F
));
760 -- Conversely, if this is a controlling argument
761 -- (in a dispatching call in the condition) that is a
762 -- dereference, the source is an access-to-class-wide
763 -- type, so preserve the dispatching nature of the
764 -- call in the rewritten condition.
766 elsif Nkind
(Parent
(N
)) = N_Explicit_Dereference
767 and then Is_Controlling_Actual
(Parent
(N
))
769 Set_Controlling_Argument
(Parent
(Parent
(N
)),
785 procedure Update
is new Traverse_Proc
(Replace_Formals
);
789 Str_Loc
: constant String := Build_Location_String
(Loc
);
795 -- Start of processing for Build_Class_Wide_Check
799 -- Locate class-wide precondition, if any
801 if Present
(Contract
(Subp
))
802 and then Present
(Pre_Post_Conditions
(Contract
(Subp
)))
804 Prec
:= Pre_Post_Conditions
(Contract
(Subp
));
806 while Present
(Prec
) loop
807 exit when Pragma_Name
(Prec
) = Name_Precondition
808 and then Class_Present
(Prec
);
809 Prec
:= Next_Pragma
(Prec
);
812 if No
(Prec
) or else Is_Ignored
(Prec
) then
816 -- The expression for the precondition is analyzed within the
817 -- generated pragma. The message text is the last parameter of
818 -- the generated pragma, indicating source of precondition.
822 (Expression
(First
(Pragma_Argument_Associations
(Prec
))));
825 -- Build message indicating the failed precondition and the
826 -- dispatching call that caused it.
828 Msg
:= Expression
(Last
(Pragma_Argument_Associations
(Prec
)));
830 Append
(Global_Name_Buffer
, Strval
(Msg
));
831 Append
(Global_Name_Buffer
, " in dispatching call at ");
832 Append
(Global_Name_Buffer
, Str_Loc
);
833 Msg
:= Make_String_Literal
(Loc
, Name_Buffer
(1 .. Name_Len
));
835 Insert_Action
(Call_Node
,
836 Make_If_Statement
(Loc
,
837 Condition
=> Make_Op_Not
(Loc
, Cond
),
838 Then_Statements
=> New_List
(
839 Make_Procedure_Call_Statement
(Loc
,
841 New_Occurrence_Of
(RTE
(RE_Raise_Assert_Failure
), Loc
),
842 Parameter_Associations
=> New_List
(Msg
)))));
844 end Build_Class_Wide_Check
;
850 function New_Value
(From
: Node_Id
) return Node_Id
is
851 Res
: constant Node_Id
:= Duplicate_Subexpr
(From
);
853 if Is_Access_Type
(Etype
(From
)) then
855 Make_Explicit_Dereference
(Sloc
(From
),
865 SCIL_Node
: Node_Id
:= Empty
;
866 SCIL_Related_Node
: Node_Id
:= Call_Node
;
868 -- Start of processing for Expand_Dispatching_Call
871 if No_Run_Time_Mode
then
872 Error_Msg_CRT
("tagged types", Call_Node
);
876 -- Expand_Dispatching_Call is called directly from the semantics, so we
877 -- only proceed if the expander is active.
879 if not Expander_Active
881 -- And there is no need to expand the call if we are compiling under
882 -- restriction No_Dispatching_Calls; the semantic analyzer has
883 -- previously notified the violation of this restriction.
885 or else Restriction_Active
(No_Dispatching_Calls
)
887 -- No action needed if the dispatching call has been already expanded
889 or else Is_Expanded_Dispatching_Call
(Name
(Call_Node
))
894 -- Set subprogram. If this is an inherited operation that was
895 -- overridden, the body that is being called is its alias.
897 Subp
:= Entity
(Name
(Call_Node
));
899 if Present
(Alias
(Subp
))
900 and then Is_Inherited_Operation
(Subp
)
901 and then No
(DTC_Entity
(Subp
))
903 Subp
:= Alias
(Subp
);
906 Build_Class_Wide_Check
;
908 -- Definition of the class-wide type and the tagged type
910 -- If the controlling argument is itself a tag rather than a tagged
911 -- object, then use the class-wide type associated with the subprogram's
912 -- controlling type. This case can occur when a call to an inherited
913 -- primitive has an actual that originated from a default parameter
914 -- given by a tag-indeterminate call and when there is no other
915 -- controlling argument providing the tag (AI-239 requires dispatching).
916 -- This capability of dispatching directly by tag is also needed by the
917 -- implementation of AI-260 (for the generic dispatching constructors).
919 if Ctrl_Typ
= RTE
(RE_Tag
)
920 or else (RTE_Available
(RE_Interface_Tag
)
921 and then Ctrl_Typ
= RTE
(RE_Interface_Tag
))
923 CW_Typ
:= Class_Wide_Type
(Find_Dispatching_Type
(Subp
));
925 -- Class_Wide_Type is applied to the expressions used to initialize
926 -- CW_Typ, to ensure that CW_Typ always denotes a class-wide type, since
927 -- there are cases where the controlling type is resolved to a specific
928 -- type (such as for designated types of arguments such as CW'Access).
930 elsif Is_Access_Type
(Ctrl_Typ
) then
931 CW_Typ
:= Class_Wide_Type
(Designated_Type
(Ctrl_Typ
));
934 CW_Typ
:= Class_Wide_Type
(Ctrl_Typ
);
937 Typ
:= Find_Specific_Type
(CW_Typ
);
939 if not Is_Limited_Type
(Typ
) then
940 Eq_Prim_Op
:= Find_Prim_Op
(Typ
, Name_Op_Eq
);
943 -- Dispatching call to C++ primitive. Create a new parameter list
944 -- with no tag checks.
946 New_Params
:= New_List
;
948 if Is_CPP_Class
(Typ
) then
949 Param
:= First_Actual
(Call_Node
);
950 while Present
(Param
) loop
951 Append_To
(New_Params
, Relocate_Node
(Param
));
955 -- Dispatching call to Ada primitive
957 elsif Present
(Param_List
) then
958 Apply_Tag_Checks
(Call_Node
);
960 Param
:= First_Actual
(Call_Node
);
961 while Present
(Param
) loop
963 -- Cases in which we may have generated run-time checks. Note that
964 -- we strip any qualification from Param before comparing with the
965 -- already-stripped controlling argument.
967 if Unqualify
(Param
) = Ctrl_Arg
or else Subp
= Eq_Prim_Op
then
968 Append_To
(New_Params
,
969 Duplicate_Subexpr_Move_Checks
(Param
));
971 elsif Nkind
(Parent
(Param
)) /= N_Parameter_Association
972 or else not Is_Accessibility_Actual
(Parent
(Param
))
974 Append_To
(New_Params
, Relocate_Node
(Param
));
981 -- Generate the appropriate subprogram pointer type
983 if Etype
(Subp
) = Typ
then
986 Res_Typ
:= Etype
(Subp
);
989 Subp_Typ
:= Create_Itype
(E_Subprogram_Type
, Call_Node
);
990 Subp_Ptr_Typ
:= Create_Itype
(E_Access_Subprogram_Type
, Call_Node
);
991 Set_Etype
(Subp_Typ
, Res_Typ
);
992 Set_Returns_By_Ref
(Subp_Typ
, Returns_By_Ref
(Subp
));
993 Set_Convention
(Subp_Typ
, Convention
(Subp
));
995 -- Notify gigi that the designated type is a dispatching primitive
997 Set_Is_Dispatch_Table_Entity
(Subp_Typ
);
999 -- Create a new list of parameters which is a copy of the old formal
1000 -- list including the creation of a new set of matching entities.
1003 Old_Formal
: Entity_Id
:= First_Formal
(Subp
);
1004 New_Formal
: Entity_Id
;
1005 Extra
: Entity_Id
:= Empty
;
1008 if Present
(Old_Formal
) then
1009 New_Formal
:= New_Copy
(Old_Formal
);
1010 Set_First_Entity
(Subp_Typ
, New_Formal
);
1011 Param
:= First_Actual
(Call_Node
);
1014 Set_Scope
(New_Formal
, Subp_Typ
);
1016 -- Change all the controlling argument types to be class-wide
1017 -- to avoid a recursion in dispatching.
1019 if Is_Controlling_Formal
(New_Formal
) then
1020 Set_Etype
(New_Formal
, Etype
(Param
));
1023 -- If the type of the formal is an itype, there was code here
1024 -- introduced in 1998 in revision 1.46, to create a new itype
1025 -- by copy. This seems useless, and in fact leads to semantic
1026 -- errors when the itype is the completion of a type derived
1027 -- from a private type.
1029 Extra
:= New_Formal
;
1030 Next_Formal
(Old_Formal
);
1031 exit when No
(Old_Formal
);
1033 Link_Entities
(New_Formal
, New_Copy
(Old_Formal
));
1034 Next_Entity
(New_Formal
);
1035 Next_Actual
(Param
);
1038 Unlink_Next_Entity
(New_Formal
);
1039 Set_Last_Entity
(Subp_Typ
, Extra
);
1042 -- Now that the explicit formals have been duplicated, any extra
1043 -- formals needed by the subprogram must be created.
1045 if Present
(Extra
) then
1046 Set_Extra_Formal
(Extra
, Empty
);
1049 Create_Extra_Formals
(Subp_Typ
);
1052 -- Complete description of pointer type, including size information, as
1053 -- must be done with itypes to prevent order-of-elaboration anomalies
1056 Set_Etype
(Subp_Ptr_Typ
, Subp_Ptr_Typ
);
1057 Set_Directly_Designated_Type
(Subp_Ptr_Typ
, Subp_Typ
);
1058 Set_Convention
(Subp_Ptr_Typ
, Convention
(Subp_Typ
));
1059 Layout_Type
(Subp_Ptr_Typ
);
1061 -- If the controlling argument is a value of type Ada.Tag or an abstract
1062 -- interface class-wide type then use it directly. Otherwise, the tag
1063 -- must be extracted from the controlling object.
1065 if Ctrl_Typ
= RTE
(RE_Tag
)
1066 or else (RTE_Available
(RE_Interface_Tag
)
1067 and then Ctrl_Typ
= RTE
(RE_Interface_Tag
))
1069 Controlling_Tag
:= Duplicate_Subexpr
(Ctrl_Arg
);
1071 -- Extract the tag from an unchecked type conversion. Done to avoid
1072 -- the expansion of additional code just to obtain the value of such
1073 -- tag because the current management of interface type conversions
1074 -- generates in some cases this unchecked type conversion with the
1075 -- tag of the object (see Expand_Interface_Conversion).
1077 elsif Nkind
(Ctrl_Arg
) = N_Unchecked_Type_Conversion
1079 (Etype
(Expression
(Ctrl_Arg
)) = RTE
(RE_Tag
)
1081 (RTE_Available
(RE_Interface_Tag
)
1083 Etype
(Expression
(Ctrl_Arg
)) = RTE
(RE_Interface_Tag
)))
1085 Controlling_Tag
:= Duplicate_Subexpr
(Expression
(Ctrl_Arg
));
1087 -- Ada 2005 (AI-251): Abstract interface class-wide type
1089 elsif Is_Interface
(Ctrl_Typ
)
1090 and then Is_Class_Wide_Type
(Ctrl_Typ
)
1092 Controlling_Tag
:= Duplicate_Subexpr
(Ctrl_Arg
);
1096 Make_Selected_Component
(Loc
,
1097 Prefix
=> Duplicate_Subexpr_Move_Checks
(Ctrl_Arg
),
1098 Selector_Name
=> New_Occurrence_Of
(DTC_Entity
(Subp
), Loc
));
1101 -- Handle dispatching calls to predefined primitives
1103 if Is_Predefined_Dispatching_Operation
(Subp
)
1104 or else Is_Predefined_Dispatching_Alias
(Subp
)
1106 Build_Get_Predefined_Prim_Op_Address
(Loc
,
1107 Tag_Node
=> Controlling_Tag
,
1108 Position
=> DT_Position
(Subp
),
1109 New_Node
=> New_Node
);
1111 -- Handle dispatching calls to user-defined primitives
1114 Build_Get_Prim_Op_Address
(Loc
,
1115 Typ
=> Underlying_Type
(Find_Dispatching_Type
(Subp
)),
1116 Tag_Node
=> Controlling_Tag
,
1117 Position
=> DT_Position
(Subp
),
1118 New_Node
=> New_Node
);
1122 Unchecked_Convert_To
(Subp_Ptr_Typ
, New_Node
);
1124 -- Generate the SCIL node for this dispatching call. Done now because
1125 -- attribute SCIL_Controlling_Tag must be set after the new call name
1126 -- is built to reference the nodes that will see the SCIL backend
1127 -- (because Build_Get_Prim_Op_Address generates an unchecked type
1128 -- conversion which relocates the controlling tag node).
1130 if Generate_SCIL
then
1131 SCIL_Node
:= Make_SCIL_Dispatching_Call
(Sloc
(Call_Node
));
1132 Set_SCIL_Entity
(SCIL_Node
, Typ
);
1133 Set_SCIL_Target_Prim
(SCIL_Node
, Subp
);
1135 -- Common case: the controlling tag is the tag of an object
1136 -- (for example, obj.tag)
1138 if Nkind
(Controlling_Tag
) = N_Selected_Component
then
1139 Set_SCIL_Controlling_Tag
(SCIL_Node
, Controlling_Tag
);
1141 -- Handle renaming of selected component
1143 elsif Nkind
(Controlling_Tag
) = N_Identifier
1144 and then Nkind
(Parent
(Entity
(Controlling_Tag
))) =
1145 N_Object_Renaming_Declaration
1146 and then Nkind
(Name
(Parent
(Entity
(Controlling_Tag
)))) =
1147 N_Selected_Component
1149 Set_SCIL_Controlling_Tag
(SCIL_Node
,
1150 Name
(Parent
(Entity
(Controlling_Tag
))));
1152 -- If the controlling tag is an identifier, the SCIL node references
1153 -- the corresponding object or parameter declaration
1155 elsif Nkind
(Controlling_Tag
) = N_Identifier
1156 and then Nkind_In
(Parent
(Entity
(Controlling_Tag
)),
1157 N_Object_Declaration
,
1158 N_Parameter_Specification
)
1160 Set_SCIL_Controlling_Tag
(SCIL_Node
,
1161 Parent
(Entity
(Controlling_Tag
)));
1163 -- If the controlling tag is a dereference, the SCIL node references
1164 -- the corresponding object or parameter declaration
1166 elsif Nkind
(Controlling_Tag
) = N_Explicit_Dereference
1167 and then Nkind
(Prefix
(Controlling_Tag
)) = N_Identifier
1168 and then Nkind_In
(Parent
(Entity
(Prefix
(Controlling_Tag
))),
1169 N_Object_Declaration
,
1170 N_Parameter_Specification
)
1172 Set_SCIL_Controlling_Tag
(SCIL_Node
,
1173 Parent
(Entity
(Prefix
(Controlling_Tag
))));
1175 -- For a direct reference of the tag of the type the SCIL node
1176 -- references the internal object declaration containing the tag
1179 elsif Nkind
(Controlling_Tag
) = N_Attribute_Reference
1180 and then Attribute_Name
(Controlling_Tag
) = Name_Tag
1182 Set_SCIL_Controlling_Tag
(SCIL_Node
,
1186 (Access_Disp_Table
(Entity
(Prefix
(Controlling_Tag
)))))));
1188 -- Interfaces are not supported. For now we leave the SCIL node
1189 -- decorated with the Controlling_Tag. More work needed here???
1191 elsif Is_Interface
(Etype
(Controlling_Tag
)) then
1192 Set_SCIL_Controlling_Tag
(SCIL_Node
, Controlling_Tag
);
1195 pragma Assert
(False);
1200 if Nkind
(Call_Node
) = N_Function_Call
then
1202 Make_Function_Call
(Loc
,
1203 Name
=> New_Call_Name
,
1204 Parameter_Associations
=> New_Params
);
1206 -- If this is a dispatching "=", we must first compare the tags so
1207 -- we generate: x.tag = y.tag and then x = y
1209 if Subp
= Eq_Prim_Op
then
1210 Param
:= First_Actual
(Call_Node
);
1216 Make_Selected_Component
(Loc
,
1217 Prefix
=> New_Value
(Param
),
1219 New_Occurrence_Of
(First_Tag_Component
(Typ
),
1223 Make_Selected_Component
(Loc
,
1225 Unchecked_Convert_To
(Typ
,
1226 New_Value
(Next_Actual
(Param
))),
1229 (First_Tag_Component
(Typ
), Loc
))),
1230 Right_Opnd
=> New_Call
);
1232 SCIL_Related_Node
:= Right_Opnd
(New_Call
);
1237 Make_Procedure_Call_Statement
(Loc
,
1238 Name
=> New_Call_Name
,
1239 Parameter_Associations
=> New_Params
);
1242 -- Register the dispatching call in the call graph nodes table
1244 Register_CG_Node
(Call_Node
);
1246 Rewrite
(Call_Node
, New_Call
);
1248 -- Associate the SCIL node of this dispatching call
1250 if Generate_SCIL
then
1251 Set_SCIL_Node
(SCIL_Related_Node
, SCIL_Node
);
1254 -- Suppress all checks during the analysis of the expanded code to avoid
1255 -- the generation of spurious warnings under ZFP run-time.
1257 Analyze_And_Resolve
(Call_Node
, Call_Typ
, Suppress
=> All_Checks
);
1258 end Expand_Dispatching_Call
;
1260 ---------------------------------
1261 -- Expand_Interface_Conversion --
1262 ---------------------------------
1264 procedure Expand_Interface_Conversion
(N
: Node_Id
) is
1265 function Underlying_Record_Type
(Typ
: Entity_Id
) return Entity_Id
;
1266 -- Return the underlying record type of Typ
1268 ----------------------------
1269 -- Underlying_Record_Type --
1270 ----------------------------
1272 function Underlying_Record_Type
(Typ
: Entity_Id
) return Entity_Id
is
1273 E
: Entity_Id
:= Typ
;
1276 -- Handle access types
1278 if Is_Access_Type
(E
) then
1279 E
:= Directly_Designated_Type
(E
);
1282 -- Handle class-wide types. This conversion can appear explicitly in
1283 -- the source code. Example: I'Class (Obj)
1285 if Is_Class_Wide_Type
(E
) then
1289 -- If the target type is a tagged synchronized type, the dispatch
1290 -- table info is in the corresponding record type.
1292 if Is_Concurrent_Type
(E
) then
1293 E
:= Corresponding_Record_Type
(E
);
1296 -- Handle private types
1298 E
:= Underlying_Type
(E
);
1302 return Base_Type
(E
);
1303 end Underlying_Record_Type
;
1307 Loc
: constant Source_Ptr
:= Sloc
(N
);
1308 Etyp
: constant Entity_Id
:= Etype
(N
);
1309 Operand
: constant Node_Id
:= Expression
(N
);
1310 Operand_Typ
: Entity_Id
:= Etype
(Operand
);
1312 Iface_Typ
: constant Entity_Id
:= Underlying_Record_Type
(Etype
(N
));
1313 Iface_Tag
: Entity_Id
;
1314 Is_Static
: Boolean;
1316 -- Start of processing for Expand_Interface_Conversion
1319 -- Freeze the entity associated with the target interface to have
1320 -- available the attribute Access_Disp_Table.
1322 Freeze_Before
(N
, Iface_Typ
);
1324 -- Ada 2005 (AI-345): Handle synchronized interface type derivations
1326 if Is_Concurrent_Type
(Operand_Typ
) then
1327 Operand_Typ
:= Base_Type
(Corresponding_Record_Type
(Operand_Typ
));
1330 -- No displacement of the pointer to the object needed when the type of
1331 -- the operand is not an interface type and the interface is one of
1332 -- its parent types (since they share the primary dispatch table).
1335 Opnd
: Entity_Id
:= Operand_Typ
;
1338 if Is_Access_Type
(Opnd
) then
1339 Opnd
:= Designated_Type
(Opnd
);
1342 Opnd
:= Underlying_Record_Type
(Opnd
);
1344 if not Is_Interface
(Opnd
)
1345 and then Is_Ancestor
(Iface_Typ
, Opnd
, Use_Full_View
=> True)
1350 -- When the type of the operand and the target interface type match,
1351 -- it is generally safe to skip generating code to displace the
1352 -- pointer to the object to reference the secondary dispatch table
1353 -- associated with the target interface type. The exception to this
1354 -- general rule is when the underlying object of the type conversion
1355 -- is an object built by means of a dispatching constructor (since in
1356 -- such case the expansion of the constructor call is a direct call
1357 -- to an object primitive, i.e. without thunks, and the expansion of
1358 -- the constructor call adds an explicit conversion to the target
1359 -- interface type to force the displacement of the pointer to the
1360 -- object to reference the corresponding secondary dispatch table
1361 -- (cf. Make_DT and Expand_Dispatching_Constructor_Call)).
1363 -- At this stage we cannot identify whether the underlying object is
1364 -- a BIP object and hence we cannot skip generating the code to try
1365 -- displacing the pointer to the object. However, under configurable
1366 -- runtime it is safe to skip generating code to displace the pointer
1367 -- to the object, because generic dispatching constructors are not
1371 and then not RTE_Available
(RE_Displace
)
1377 -- Evaluate if we can statically displace the pointer to the object
1380 Opnd_Typ
: constant Node_Id
:= Underlying_Record_Type
(Operand_Typ
);
1384 not Is_Interface
(Opnd_Typ
)
1385 and then Interface_Present_In_Ancestor
1388 and then (Etype
(Opnd_Typ
) = Opnd_Typ
1390 Is_Variable_Size_Record
(Etype
(Opnd_Typ
)));
1393 if not Tagged_Type_Expansion
then
1396 -- A static conversion to an interface type that is not class-wide is
1397 -- curious but legal if the interface operation is a null procedure.
1398 -- If the operation is abstract it will be rejected later.
1401 and then Is_Interface
(Etype
(N
))
1402 and then not Is_Class_Wide_Type
(Etype
(N
))
1403 and then Comes_From_Source
(N
)
1405 Rewrite
(N
, Unchecked_Convert_To
(Etype
(N
), N
));
1410 if not Is_Static
then
1412 -- Give error if configurable run-time and Displace not available
1414 if not RTE_Available
(RE_Displace
) then
1415 Error_Msg_CRT
("dynamic interface conversion", N
);
1419 -- Handle conversion of access-to-class-wide interface types. Target
1420 -- can be an access to an object or an access to another class-wide
1421 -- interface (see -1- and -2- in the following example):
1423 -- type Iface1_Ref is access all Iface1'Class;
1424 -- type Iface2_Ref is access all Iface1'Class;
1426 -- Acc1 : Iface1_Ref := new ...
1427 -- Obj : Obj_Ref := Obj_Ref (Acc); -- 1
1428 -- Acc2 : Iface2_Ref := Iface2_Ref (Acc); -- 2
1430 if Is_Access_Type
(Operand_Typ
) then
1432 Unchecked_Convert_To
(Etype
(N
),
1433 Make_Function_Call
(Loc
,
1434 Name
=> New_Occurrence_Of
(RTE
(RE_Displace
), Loc
),
1435 Parameter_Associations
=> New_List
(
1437 Unchecked_Convert_To
(RTE
(RE_Address
),
1438 Relocate_Node
(Expression
(N
))),
1441 (Node
(First_Elmt
(Access_Disp_Table
(Iface_Typ
))),
1449 Make_Function_Call
(Loc
,
1450 Name
=> New_Occurrence_Of
(RTE
(RE_Displace
), Loc
),
1451 Parameter_Associations
=> New_List
(
1452 Make_Attribute_Reference
(Loc
,
1453 Prefix
=> Relocate_Node
(Expression
(N
)),
1454 Attribute_Name
=> Name_Address
),
1457 (Node
(First_Elmt
(Access_Disp_Table
(Iface_Typ
))),
1462 -- If target is a class-wide interface, change the type of the data
1463 -- returned by IW_Convert to indicate this is a dispatching call.
1466 New_Itype
: Entity_Id
;
1469 New_Itype
:= Create_Itype
(E_Anonymous_Access_Type
, N
);
1470 Set_Etype
(New_Itype
, New_Itype
);
1471 Set_Directly_Designated_Type
(New_Itype
, Etyp
);
1474 Make_Explicit_Dereference
(Loc
,
1476 Unchecked_Convert_To
(New_Itype
, Relocate_Node
(N
))));
1478 Freeze_Itype
(New_Itype
, N
);
1484 Iface_Tag
:= Find_Interface_Tag
(Operand_Typ
, Iface_Typ
);
1485 pragma Assert
(Present
(Iface_Tag
));
1487 -- Keep separate access types to interfaces because one internal
1488 -- function is used to handle the null value (see following comments)
1490 if not Is_Access_Type
(Etype
(N
)) then
1492 -- Statically displace the pointer to the object to reference the
1493 -- component containing the secondary dispatch table.
1496 Convert_Tag_To_Interface
(Class_Wide_Type
(Iface_Typ
),
1497 Make_Selected_Component
(Loc
,
1498 Prefix
=> Relocate_Node
(Expression
(N
)),
1499 Selector_Name
=> New_Occurrence_Of
(Iface_Tag
, Loc
))));
1502 -- Build internal function to handle the case in which the actual is
1503 -- null. If the actual is null returns null because no displacement
1504 -- is required; otherwise performs a type conversion that will be
1505 -- expanded in the code that returns the value of the displaced
1508 -- function Func (O : Address) return Iface_Typ is
1509 -- type Op_Typ is access all Operand_Typ;
1510 -- Aux : Op_Typ := To_Op_Typ (O);
1512 -- if O = Null_Address then
1515 -- return Iface_Typ!(Aux.Iface_Tag'Address);
1520 Desig_Typ
: Entity_Id
;
1522 New_Typ_Decl
: Node_Id
;
1526 Desig_Typ
:= Etype
(Expression
(N
));
1528 if Is_Access_Type
(Desig_Typ
) then
1530 Available_View
(Directly_Designated_Type
(Desig_Typ
));
1533 if Is_Concurrent_Type
(Desig_Typ
) then
1534 Desig_Typ
:= Base_Type
(Corresponding_Record_Type
(Desig_Typ
));
1538 Make_Full_Type_Declaration
(Loc
,
1539 Defining_Identifier
=> Make_Temporary
(Loc
, 'T'),
1541 Make_Access_To_Object_Definition
(Loc
,
1542 All_Present
=> True,
1543 Null_Exclusion_Present
=> False,
1544 Constant_Present
=> False,
1545 Subtype_Indication
=>
1546 New_Occurrence_Of
(Desig_Typ
, Loc
)));
1549 Make_Simple_Return_Statement
(Loc
,
1550 Unchecked_Convert_To
(Etype
(N
),
1551 Make_Attribute_Reference
(Loc
,
1553 Make_Selected_Component
(Loc
,
1555 Unchecked_Convert_To
1556 (Defining_Identifier
(New_Typ_Decl
),
1557 Make_Identifier
(Loc
, Name_uO
)),
1559 New_Occurrence_Of
(Iface_Tag
, Loc
)),
1560 Attribute_Name
=> Name_Address
))));
1562 -- If the type is null-excluding, no need for the null branch.
1563 -- Otherwise we need to check for it and return null.
1565 if not Can_Never_Be_Null
(Etype
(N
)) then
1567 Make_If_Statement
(Loc
,
1570 Left_Opnd
=> Make_Identifier
(Loc
, Name_uO
),
1571 Right_Opnd
=> New_Occurrence_Of
1572 (RTE
(RE_Null_Address
), Loc
)),
1574 Then_Statements
=> New_List
(
1575 Make_Simple_Return_Statement
(Loc
, Make_Null
(Loc
))),
1576 Else_Statements
=> Stats
));
1579 Fent
:= Make_Temporary
(Loc
, 'F');
1581 Make_Subprogram_Body
(Loc
,
1583 Make_Function_Specification
(Loc
,
1584 Defining_Unit_Name
=> Fent
,
1586 Parameter_Specifications
=> New_List
(
1587 Make_Parameter_Specification
(Loc
,
1588 Defining_Identifier
=>
1589 Make_Defining_Identifier
(Loc
, Name_uO
),
1591 New_Occurrence_Of
(RTE
(RE_Address
), Loc
))),
1593 Result_Definition
=>
1594 New_Occurrence_Of
(Etype
(N
), Loc
)),
1596 Declarations
=> New_List
(New_Typ_Decl
),
1598 Handled_Statement_Sequence
=>
1599 Make_Handled_Sequence_Of_Statements
(Loc
, Stats
));
1601 -- Place function body before the expression containing the
1602 -- conversion. We suppress all checks because the body of the
1603 -- internally generated function already takes care of the case
1604 -- in which the actual is null; therefore there is no need to
1605 -- double check that the pointer is not null when the program
1606 -- executes the alternative that performs the type conversion).
1608 Insert_Action
(N
, Func
, Suppress
=> All_Checks
);
1610 if Is_Access_Type
(Etype
(Expression
(N
))) then
1612 -- Generate: Func (Address!(Expression))
1615 Make_Function_Call
(Loc
,
1616 Name
=> New_Occurrence_Of
(Fent
, Loc
),
1617 Parameter_Associations
=> New_List
(
1618 Unchecked_Convert_To
(RTE
(RE_Address
),
1619 Relocate_Node
(Expression
(N
))))));
1622 -- Generate: Func (Operand_Typ!(Expression)'Address)
1625 Make_Function_Call
(Loc
,
1626 Name
=> New_Occurrence_Of
(Fent
, Loc
),
1627 Parameter_Associations
=> New_List
(
1628 Make_Attribute_Reference
(Loc
,
1629 Prefix
=> Unchecked_Convert_To
(Operand_Typ
,
1630 Relocate_Node
(Expression
(N
))),
1631 Attribute_Name
=> Name_Address
))));
1637 end Expand_Interface_Conversion
;
1639 ------------------------------
1640 -- Expand_Interface_Actuals --
1641 ------------------------------
1643 procedure Expand_Interface_Actuals
(Call_Node
: Node_Id
) is
1645 Actual_Dup
: Node_Id
;
1646 Actual_Typ
: Entity_Id
;
1648 Conversion
: Node_Id
;
1650 Formal_Typ
: Entity_Id
;
1652 Formal_DDT
: Entity_Id
:= Empty
; -- initialize to prevent warning
1653 Actual_DDT
: Entity_Id
:= Empty
; -- initialize to prevent warning
1656 -- This subprogram is called directly from the semantics, so we need a
1657 -- check to see whether expansion is active before proceeding.
1659 if not Expander_Active
then
1663 -- Call using access to subprogram with explicit dereference
1665 if Nkind
(Name
(Call_Node
)) = N_Explicit_Dereference
then
1666 Subp
:= Etype
(Name
(Call_Node
));
1668 -- Call using selected component
1670 elsif Nkind
(Name
(Call_Node
)) = N_Selected_Component
then
1671 Subp
:= Entity
(Selector_Name
(Name
(Call_Node
)));
1673 -- Call using direct name
1676 Subp
:= Entity
(Name
(Call_Node
));
1679 -- Ada 2005 (AI-251): Look for interface type formals to force "this"
1682 Formal
:= First_Formal
(Subp
);
1683 Actual
:= First_Actual
(Call_Node
);
1684 while Present
(Formal
) loop
1685 Formal_Typ
:= Etype
(Formal
);
1687 if Ekind
(Formal_Typ
) = E_Record_Type_With_Private
then
1688 Formal_Typ
:= Full_View
(Formal_Typ
);
1691 if Is_Access_Type
(Formal_Typ
) then
1692 Formal_DDT
:= Directly_Designated_Type
(Formal_Typ
);
1695 Actual_Typ
:= Etype
(Actual
);
1697 if Is_Access_Type
(Actual_Typ
) then
1698 Actual_DDT
:= Directly_Designated_Type
(Actual_Typ
);
1701 if Is_Interface
(Formal_Typ
)
1702 and then Is_Class_Wide_Type
(Formal_Typ
)
1704 -- No need to displace the pointer if the type of the actual
1705 -- coincides with the type of the formal.
1707 if Actual_Typ
= Formal_Typ
then
1710 -- No need to displace the pointer if the interface type is a
1711 -- parent of the type of the actual because in this case the
1712 -- interface primitives are located in the primary dispatch table.
1714 elsif Is_Ancestor
(Formal_Typ
, Actual_Typ
,
1715 Use_Full_View
=> True)
1719 -- Implicit conversion to the class-wide formal type to force the
1720 -- displacement of the pointer.
1723 -- Normally, expansion of actuals for calls to build-in-place
1724 -- functions happens as part of Expand_Actuals, but in this
1725 -- case the call will be wrapped in a conversion and soon after
1726 -- expanded further to handle the displacement for a class-wide
1727 -- interface conversion, so if this is a BIP call then we need
1728 -- to handle it now.
1730 if Is_Build_In_Place_Function_Call
(Actual
) then
1731 Make_Build_In_Place_Call_In_Anonymous_Context
(Actual
);
1734 Conversion
:= Convert_To
(Formal_Typ
, Relocate_Node
(Actual
));
1735 Rewrite
(Actual
, Conversion
);
1736 Analyze_And_Resolve
(Actual
, Formal_Typ
);
1739 -- Access to class-wide interface type
1741 elsif Is_Access_Type
(Formal_Typ
)
1742 and then Is_Interface
(Formal_DDT
)
1743 and then Is_Class_Wide_Type
(Formal_DDT
)
1744 and then Interface_Present_In_Ancestor
1746 Iface
=> Etype
(Formal_DDT
))
1748 -- Handle attributes 'Access and 'Unchecked_Access
1750 if Nkind
(Actual
) = N_Attribute_Reference
1752 (Attribute_Name
(Actual
) = Name_Access
1753 or else Attribute_Name
(Actual
) = Name_Unchecked_Access
)
1755 -- This case must have been handled by the analysis and
1756 -- expansion of 'Access. The only exception is when types
1757 -- match and no further expansion is required.
1759 pragma Assert
(Base_Type
(Etype
(Prefix
(Actual
)))
1760 = Base_Type
(Formal_DDT
));
1763 -- No need to displace the pointer if the type of the actual
1764 -- coincides with the type of the formal.
1766 elsif Actual_DDT
= Formal_DDT
then
1769 -- No need to displace the pointer if the interface type is
1770 -- a parent of the type of the actual because in this case the
1771 -- interface primitives are located in the primary dispatch table.
1773 elsif Is_Ancestor
(Formal_DDT
, Actual_DDT
,
1774 Use_Full_View
=> True)
1779 Actual_Dup
:= Relocate_Node
(Actual
);
1781 if From_Limited_With
(Actual_Typ
) then
1783 -- If the type of the actual parameter comes from a limited
1784 -- with_clause and the nonlimited view is already available,
1785 -- we replace the anonymous access type by a duplicate
1786 -- declaration whose designated type is the nonlimited view.
1788 if Has_Non_Limited_View
(Actual_DDT
) then
1789 Anon
:= New_Copy
(Actual_Typ
);
1791 if Is_Itype
(Anon
) then
1792 Set_Scope
(Anon
, Current_Scope
);
1795 Set_Directly_Designated_Type
1796 (Anon
, Non_Limited_View
(Actual_DDT
));
1797 Set_Etype
(Actual_Dup
, Anon
);
1801 Conversion
:= Convert_To
(Formal_Typ
, Actual_Dup
);
1802 Rewrite
(Actual
, Conversion
);
1803 Analyze_And_Resolve
(Actual
, Formal_Typ
);
1807 Next_Actual
(Actual
);
1808 Next_Formal
(Formal
);
1810 end Expand_Interface_Actuals
;
1812 ----------------------------
1813 -- Expand_Interface_Thunk --
1814 ----------------------------
1816 procedure Expand_Interface_Thunk
1818 Thunk_Id
: out Entity_Id
;
1819 Thunk_Code
: out Node_Id
)
1821 Loc
: constant Source_Ptr
:= Sloc
(Prim
);
1822 Actuals
: constant List_Id
:= New_List
;
1823 Decl
: constant List_Id
:= New_List
;
1824 Formals
: constant List_Id
:= New_List
;
1825 Target
: constant Entity_Id
:= Ultimate_Alias
(Prim
);
1832 Iface_Formal
: Node_Id
:= Empty
; -- initialize to prevent warning
1834 Offset_To_Top
: Node_Id
;
1835 Target_Formal
: Entity_Id
;
1839 Thunk_Code
:= Empty
;
1841 -- No thunk needed if the primitive has been eliminated
1843 if Is_Eliminated
(Ultimate_Alias
(Prim
)) then
1846 -- In case of primitives that are functions without formals and a
1847 -- controlling result there is no need to build the thunk.
1849 elsif not Present
(First_Formal
(Target
)) then
1850 pragma Assert
(Ekind
(Target
) = E_Function
1851 and then Has_Controlling_Result
(Target
));
1855 -- Duplicate the formals of the Target primitive. In the thunk, the type
1856 -- of the controlling formal is the covered interface type (instead of
1857 -- the target tagged type). Done to avoid problems with discriminated
1858 -- tagged types because, if the controlling type has discriminants with
1859 -- default values, then the type conversions done inside the body of
1860 -- the thunk (after the displacement of the pointer to the base of the
1861 -- actual object) generate code that modify its contents.
1863 -- Note: This special management is not done for predefined primitives
1866 if not Is_Predefined_Dispatching_Operation
(Prim
) then
1867 Iface_Formal
:= First_Formal
(Interface_Alias
(Prim
));
1870 Formal
:= First_Formal
(Target
);
1871 while Present
(Formal
) loop
1872 Ftyp
:= Etype
(Formal
);
1874 -- Use the interface type as the type of the controlling formal (see
1877 if not Is_Controlling_Formal
(Formal
)
1878 or else Is_Predefined_Dispatching_Operation
(Prim
)
1880 Ftyp
:= Etype
(Formal
);
1881 Expr
:= New_Copy_Tree
(Expression
(Parent
(Formal
)));
1883 Ftyp
:= Etype
(Iface_Formal
);
1888 Make_Parameter_Specification
(Loc
,
1889 Defining_Identifier
=>
1890 Make_Defining_Identifier
(Sloc
(Formal
),
1891 Chars
=> Chars
(Formal
)),
1892 In_Present
=> In_Present
(Parent
(Formal
)),
1893 Out_Present
=> Out_Present
(Parent
(Formal
)),
1894 Parameter_Type
=> New_Occurrence_Of
(Ftyp
, Loc
),
1895 Expression
=> Expr
));
1897 if not Is_Predefined_Dispatching_Operation
(Prim
) then
1898 Next_Formal
(Iface_Formal
);
1901 Next_Formal
(Formal
);
1904 Target_Formal
:= First_Formal
(Target
);
1905 Formal
:= First
(Formals
);
1906 while Present
(Formal
) loop
1908 -- If the parent is a constrained discriminated type, then the
1909 -- primitive operation will have been defined on a first subtype.
1910 -- For proper matching with controlling type, use base type.
1912 if Ekind
(Target_Formal
) = E_In_Parameter
1913 and then Ekind
(Etype
(Target_Formal
)) = E_Anonymous_Access_Type
1916 Base_Type
(Directly_Designated_Type
(Etype
(Target_Formal
)));
1918 Ftyp
:= Base_Type
(Etype
(Target_Formal
));
1921 -- For concurrent types, the relevant information is found in the
1922 -- Corresponding_Record_Type, rather than the type entity itself.
1924 if Is_Concurrent_Type
(Ftyp
) then
1925 Ftyp
:= Corresponding_Record_Type
(Ftyp
);
1928 if Ekind
(Target_Formal
) = E_In_Parameter
1929 and then Ekind
(Etype
(Target_Formal
)) = E_Anonymous_Access_Type
1930 and then Is_Controlling_Formal
(Target_Formal
)
1933 -- type T is access all <<type of the target formal>>
1934 -- S : Storage_Offset := Storage_Offset!(Formal)
1935 -- + Offset_To_Top (address!(Formal))
1938 Make_Full_Type_Declaration
(Loc
,
1939 Defining_Identifier
=> Make_Temporary
(Loc
, 'T'),
1941 Make_Access_To_Object_Definition
(Loc
,
1942 All_Present
=> True,
1943 Null_Exclusion_Present
=> False,
1944 Constant_Present
=> False,
1945 Subtype_Indication
=>
1946 New_Occurrence_Of
(Ftyp
, Loc
)));
1949 Unchecked_Convert_To
(RTE
(RE_Address
),
1950 New_Occurrence_Of
(Defining_Identifier
(Formal
), Loc
));
1952 if not RTE_Available
(RE_Offset_To_Top
) then
1954 Build_Offset_To_Top
(Loc
, New_Arg
);
1957 Make_Function_Call
(Loc
,
1958 Name
=> New_Occurrence_Of
(RTE
(RE_Offset_To_Top
), Loc
),
1959 Parameter_Associations
=> New_List
(New_Arg
));
1963 Make_Object_Declaration
(Loc
,
1964 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
1965 Constant_Present
=> True,
1966 Object_Definition
=>
1967 New_Occurrence_Of
(RTE
(RE_Storage_Offset
), Loc
),
1971 Unchecked_Convert_To
1972 (RTE
(RE_Storage_Offset
),
1974 (Defining_Identifier
(Formal
), Loc
)),
1978 Append_To
(Decl
, Decl_2
);
1979 Append_To
(Decl
, Decl_1
);
1981 -- Reference the new actual. Generate:
1985 Unchecked_Convert_To
1986 (Defining_Identifier
(Decl_2
),
1987 New_Occurrence_Of
(Defining_Identifier
(Decl_1
), Loc
)));
1989 elsif Is_Controlling_Formal
(Target_Formal
) then
1992 -- S1 : Storage_Offset := Storage_Offset!(Formal'Address)
1993 -- + Offset_To_Top (Formal'Address)
1994 -- S2 : Addr_Ptr := Addr_Ptr!(S1)
1997 Make_Attribute_Reference
(Loc
,
1999 New_Occurrence_Of
(Defining_Identifier
(Formal
), Loc
),
2003 if not RTE_Available
(RE_Offset_To_Top
) then
2005 Build_Offset_To_Top
(Loc
, New_Arg
);
2008 Make_Function_Call
(Loc
,
2009 Name
=> New_Occurrence_Of
(RTE
(RE_Offset_To_Top
), Loc
),
2010 Parameter_Associations
=> New_List
(New_Arg
));
2014 Make_Object_Declaration
(Loc
,
2015 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
2016 Constant_Present
=> True,
2017 Object_Definition
=>
2018 New_Occurrence_Of
(RTE
(RE_Storage_Offset
), Loc
),
2022 Unchecked_Convert_To
2023 (RTE
(RE_Storage_Offset
),
2024 Make_Attribute_Reference
(Loc
,
2027 (Defining_Identifier
(Formal
), Loc
),
2028 Attribute_Name
=> Name_Address
)),
2033 Make_Object_Declaration
(Loc
,
2034 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
2035 Constant_Present
=> True,
2036 Object_Definition
=>
2037 New_Occurrence_Of
(RTE
(RE_Addr_Ptr
), Loc
),
2039 Unchecked_Convert_To
2041 New_Occurrence_Of
(Defining_Identifier
(Decl_1
), Loc
)));
2043 Append_To
(Decl
, Decl_1
);
2044 Append_To
(Decl
, Decl_2
);
2046 -- Reference the new actual, generate:
2047 -- Target_Formal (S2.all)
2050 Unchecked_Convert_To
(Ftyp
,
2051 Make_Explicit_Dereference
(Loc
,
2052 New_Occurrence_Of
(Defining_Identifier
(Decl_2
), Loc
))));
2054 -- Ensure proper matching of access types. Required to avoid
2055 -- reporting spurious errors.
2057 elsif Is_Access_Type
(Etype
(Target_Formal
)) then
2059 Unchecked_Convert_To
(Base_Type
(Etype
(Target_Formal
)),
2060 New_Occurrence_Of
(Defining_Identifier
(Formal
), Loc
)));
2062 -- No special management required for this actual
2066 New_Occurrence_Of
(Defining_Identifier
(Formal
), Loc
));
2069 Next_Formal
(Target_Formal
);
2073 Thunk_Id
:= Make_Temporary
(Loc
, 'T');
2074 Set_Ekind
(Thunk_Id
, Ekind
(Prim
));
2075 Set_Is_Thunk
(Thunk_Id
);
2076 Set_Convention
(Thunk_Id
, Convention
(Prim
));
2077 Set_Needs_Debug_Info
(Thunk_Id
, Needs_Debug_Info
(Target
));
2078 Set_Thunk_Entity
(Thunk_Id
, Target
);
2082 if Ekind
(Target
) = E_Procedure
then
2084 Make_Subprogram_Body
(Loc
,
2086 Make_Procedure_Specification
(Loc
,
2087 Defining_Unit_Name
=> Thunk_Id
,
2088 Parameter_Specifications
=> Formals
),
2089 Declarations
=> Decl
,
2090 Handled_Statement_Sequence
=>
2091 Make_Handled_Sequence_Of_Statements
(Loc
,
2092 Statements
=> New_List
(
2093 Make_Procedure_Call_Statement
(Loc
,
2094 Name
=> New_Occurrence_Of
(Target
, Loc
),
2095 Parameter_Associations
=> Actuals
))));
2099 else pragma Assert
(Ekind
(Target
) = E_Function
);
2101 Result_Def
: Node_Id
;
2102 Call_Node
: Node_Id
;
2106 Make_Function_Call
(Loc
,
2107 Name
=> New_Occurrence_Of
(Target
, Loc
),
2108 Parameter_Associations
=> Actuals
);
2110 if not Is_Interface
(Etype
(Prim
)) then
2111 Result_Def
:= New_Copy
(Result_Definition
(Parent
(Target
)));
2113 -- Thunk of function returning a class-wide interface object. No
2114 -- extra displacement needed since the displacement is generated
2115 -- in the return statement of Prim. Example:
2117 -- type Iface is interface ...
2118 -- function F (O : Iface) return Iface'Class;
2120 -- type T is new ... and Iface with ...
2121 -- function F (O : T) return Iface'Class;
2123 elsif Is_Class_Wide_Type
(Etype
(Prim
)) then
2124 Result_Def
:= New_Occurrence_Of
(Etype
(Prim
), Loc
);
2126 -- Thunk of function returning an interface object. Displacement
2129 -- type Iface is interface ...
2130 -- function F (O : Iface) return Iface;
2132 -- type T is new ... and Iface with ...
2133 -- function F (O : T) return T;
2137 New_Occurrence_Of
(Class_Wide_Type
(Etype
(Prim
)), Loc
);
2139 -- Adding implicit conversion to force the displacement of
2140 -- the pointer to the object to reference the corresponding
2141 -- secondary dispatch table.
2144 Make_Type_Conversion
(Loc
,
2146 New_Occurrence_Of
(Class_Wide_Type
(Etype
(Prim
)), Loc
),
2147 Expression
=> Relocate_Node
(Call_Node
));
2151 Make_Subprogram_Body
(Loc
,
2153 Make_Function_Specification
(Loc
,
2154 Defining_Unit_Name
=> Thunk_Id
,
2155 Parameter_Specifications
=> Formals
,
2156 Result_Definition
=> Result_Def
),
2157 Declarations
=> Decl
,
2158 Handled_Statement_Sequence
=>
2159 Make_Handled_Sequence_Of_Statements
(Loc
,
2160 Statements
=> New_List
(
2161 Make_Simple_Return_Statement
(Loc
, Call_Node
))));
2164 end Expand_Interface_Thunk
;
2166 --------------------------
2167 -- Has_CPP_Constructors --
2168 --------------------------
2170 function Has_CPP_Constructors
(Typ
: Entity_Id
) return Boolean is
2174 -- Look for the constructor entities
2176 E
:= Next_Entity
(Typ
);
2177 while Present
(E
) loop
2178 if Ekind
(E
) = E_Function
and then Is_Constructor
(E
) then
2186 end Has_CPP_Constructors
;
2192 function Has_DT
(Typ
: Entity_Id
) return Boolean is
2194 return not Is_Interface
(Typ
)
2195 and then not Restriction_Active
(No_Dispatching_Calls
);
2198 ----------------------------------
2199 -- Is_Expanded_Dispatching_Call --
2200 ----------------------------------
2202 function Is_Expanded_Dispatching_Call
(N
: Node_Id
) return Boolean is
2204 return Nkind
(N
) in N_Subprogram_Call
2205 and then Nkind
(Name
(N
)) = N_Explicit_Dereference
2206 and then Is_Dispatch_Table_Entity
(Etype
(Name
(N
)));
2207 end Is_Expanded_Dispatching_Call
;
2209 -------------------------------------
2210 -- Is_Predefined_Dispatching_Alias --
2211 -------------------------------------
2213 function Is_Predefined_Dispatching_Alias
(Prim
: Entity_Id
) return Boolean
2216 return not Is_Predefined_Dispatching_Operation
(Prim
)
2217 and then Present
(Alias
(Prim
))
2218 and then Is_Predefined_Dispatching_Operation
(Ultimate_Alias
(Prim
));
2219 end Is_Predefined_Dispatching_Alias
;
2221 ----------------------------------------
2222 -- Make_Disp_Asynchronous_Select_Body --
2223 ----------------------------------------
2225 -- For interface types, generate:
2227 -- procedure _Disp_Asynchronous_Select
2228 -- (T : in out <Typ>;
2230 -- P : System.Address;
2231 -- B : out System.Storage_Elements.Dummy_Communication_Block;
2236 -- C := Ada.Tags.POK_Function;
2237 -- end _Disp_Asynchronous_Select;
2239 -- For protected types, generate:
2241 -- procedure _Disp_Asynchronous_Select
2242 -- (T : in out <Typ>;
2244 -- P : System.Address;
2245 -- B : out System.Storage_Elements.Dummy_Communication_Block;
2249 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2250 -- Bnn : System.Tasking.Protected_Objects.Operations.
2251 -- Communication_Block;
2253 -- System.Tasking.Protected_Objects.Operations.Protected_Entry_Call
2254 -- (T._object'Access,
2255 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
2257 -- System.Tasking.Asynchronous_Call,
2259 -- B := System.Storage_Elements.Dummy_Communication_Block (Bnn);
2260 -- end _Disp_Asynchronous_Select;
2262 -- For task types, generate:
2264 -- procedure _Disp_Asynchronous_Select
2265 -- (T : in out <Typ>;
2267 -- P : System.Address;
2268 -- B : out System.Storage_Elements.Dummy_Communication_Block;
2272 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2274 -- System.Tasking.Rendezvous.Task_Entry_Call
2276 -- System.Tasking.Task_Entry_Index (I),
2278 -- System.Tasking.Asynchronous_Call,
2280 -- end _Disp_Asynchronous_Select;
2282 function Make_Disp_Asynchronous_Select_Body
2283 (Typ
: Entity_Id
) return Node_Id
2285 Com_Block
: Entity_Id
;
2286 Conc_Typ
: Entity_Id
:= Empty
;
2287 Decls
: constant List_Id
:= New_List
;
2288 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2290 Stmts
: constant List_Id
:= New_List
;
2294 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2296 -- Null body is generated for interface types
2298 if Is_Interface
(Typ
) then
2300 Make_Subprogram_Body
(Loc
,
2302 Make_Disp_Asynchronous_Select_Spec
(Typ
),
2303 Declarations
=> New_List
,
2304 Handled_Statement_Sequence
=>
2305 Make_Handled_Sequence_Of_Statements
(Loc
,
2307 Make_Assignment_Statement
(Loc
,
2308 Name
=> Make_Identifier
(Loc
, Name_uF
),
2309 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)))));
2312 if Is_Concurrent_Record_Type
(Typ
) then
2313 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
2317 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag! (<type>VP), S);
2319 -- where I will be used to capture the entry index of the primitive
2320 -- wrapper at position S.
2322 if Tagged_Type_Expansion
then
2324 Unchecked_Convert_To
(RTE
(RE_Tag
),
2326 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
));
2329 Make_Attribute_Reference
(Loc
,
2330 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
2331 Attribute_Name
=> Name_Tag
);
2335 Make_Object_Declaration
(Loc
,
2336 Defining_Identifier
=>
2337 Make_Defining_Identifier
(Loc
, Name_uI
),
2338 Object_Definition
=>
2339 New_Occurrence_Of
(Standard_Integer
, Loc
),
2341 Make_Function_Call
(Loc
,
2343 New_Occurrence_Of
(RTE
(RE_Get_Entry_Index
), Loc
),
2344 Parameter_Associations
=>
2345 New_List
(Tag_Node
, Make_Identifier
(Loc
, Name_uS
)))));
2347 if Ekind
(Conc_Typ
) = E_Protected_Type
then
2350 -- Bnn : Communication_Block;
2352 Com_Block
:= Make_Temporary
(Loc
, 'B');
2354 Make_Object_Declaration
(Loc
,
2355 Defining_Identifier
=> Com_Block
,
2356 Object_Definition
=>
2357 New_Occurrence_Of
(RTE
(RE_Communication_Block
), Loc
)));
2359 -- Build T._object'Access for calls below
2362 Make_Attribute_Reference
(Loc
,
2363 Attribute_Name
=> Name_Unchecked_Access
,
2365 Make_Selected_Component
(Loc
,
2366 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
2367 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)));
2369 case Corresponding_Runtime_Package
(Conc_Typ
) is
2370 when System_Tasking_Protected_Objects_Entries
=>
2373 -- Protected_Entry_Call
2374 -- (T._object'Access, -- Object
2375 -- Protected_Entry_Index! (I), -- E
2376 -- P, -- Uninterpreted_Data
2377 -- Asynchronous_Call, -- Mode
2378 -- Bnn); -- Communication_Block
2380 -- where T is the protected object, I is the entry index, P
2381 -- is the wrapped parameters and B is the name of the
2382 -- communication block.
2385 Make_Procedure_Call_Statement
(Loc
,
2387 New_Occurrence_Of
(RTE
(RE_Protected_Entry_Call
), Loc
),
2388 Parameter_Associations
=>
2392 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2395 (RTE
(RE_Protected_Entry_Index
), Loc
),
2396 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
2398 Make_Identifier
(Loc
, Name_uP
), -- parameter block
2399 New_Occurrence_Of
-- Asynchronous_Call
2400 (RTE
(RE_Asynchronous_Call
), Loc
),
2401 New_Occurrence_Of
-- comm block
2402 (Com_Block
, Loc
))));
2405 raise Program_Error
;
2409 -- B := Dummy_Communication_Block (Bnn);
2412 Make_Assignment_Statement
(Loc
,
2413 Name
=> Make_Identifier
(Loc
, Name_uB
),
2415 Make_Unchecked_Type_Conversion
(Loc
,
2418 (RTE
(RE_Dummy_Communication_Block
), Loc
),
2419 Expression
=> New_Occurrence_Of
(Com_Block
, Loc
))));
2425 Make_Assignment_Statement
(Loc
,
2426 Name
=> Make_Identifier
(Loc
, Name_uF
),
2427 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)));
2430 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
2434 -- (T._task_id, -- Acceptor
2435 -- Task_Entry_Index! (I), -- E
2436 -- P, -- Uninterpreted_Data
2437 -- Asynchronous_Call, -- Mode
2438 -- F); -- Rendezvous_Successful
2440 -- where T is the task object, I is the entry index, P is the
2441 -- wrapped parameters and F is the status flag.
2444 Make_Procedure_Call_Statement
(Loc
,
2446 New_Occurrence_Of
(RTE
(RE_Task_Entry_Call
), Loc
),
2447 Parameter_Associations
=>
2449 Make_Selected_Component
(Loc
, -- T._task_id
2450 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
2451 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
2453 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2455 New_Occurrence_Of
(RTE
(RE_Task_Entry_Index
), Loc
),
2456 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
2458 Make_Identifier
(Loc
, Name_uP
), -- parameter block
2459 New_Occurrence_Of
-- Asynchronous_Call
2460 (RTE
(RE_Asynchronous_Call
), Loc
),
2461 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
2465 -- Ensure that the statements list is non-empty
2468 Make_Assignment_Statement
(Loc
,
2469 Name
=> Make_Identifier
(Loc
, Name_uF
),
2470 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)));
2474 Make_Subprogram_Body
(Loc
,
2476 Make_Disp_Asynchronous_Select_Spec
(Typ
),
2477 Declarations
=> Decls
,
2478 Handled_Statement_Sequence
=>
2479 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
2480 end Make_Disp_Asynchronous_Select_Body
;
2482 ----------------------------------------
2483 -- Make_Disp_Asynchronous_Select_Spec --
2484 ----------------------------------------
2486 function Make_Disp_Asynchronous_Select_Spec
2487 (Typ
: Entity_Id
) return Node_Id
2489 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2490 Def_Id
: constant Node_Id
:=
2491 Make_Defining_Identifier
(Loc
,
2492 Name_uDisp_Asynchronous_Select
);
2493 Params
: constant List_Id
:= New_List
;
2496 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2498 -- T : in out Typ; -- Object parameter
2499 -- S : Integer; -- Primitive operation slot
2500 -- P : Address; -- Wrapped parameters
2501 -- B : out Dummy_Communication_Block; -- Communication block dummy
2502 -- F : out Boolean; -- Status flag
2504 Append_List_To
(Params
, New_List
(
2506 Make_Parameter_Specification
(Loc
,
2507 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uT
),
2508 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
),
2510 Out_Present
=> True),
2512 Make_Parameter_Specification
(Loc
,
2513 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uS
),
2514 Parameter_Type
=> New_Occurrence_Of
(Standard_Integer
, Loc
)),
2516 Make_Parameter_Specification
(Loc
,
2517 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uP
),
2518 Parameter_Type
=> New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
2520 Make_Parameter_Specification
(Loc
,
2521 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uB
),
2523 New_Occurrence_Of
(RTE
(RE_Dummy_Communication_Block
), Loc
),
2524 Out_Present
=> True),
2526 Make_Parameter_Specification
(Loc
,
2527 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uF
),
2528 Parameter_Type
=> New_Occurrence_Of
(Standard_Boolean
, Loc
),
2529 Out_Present
=> True)));
2532 Make_Procedure_Specification
(Loc
,
2533 Defining_Unit_Name
=> Def_Id
,
2534 Parameter_Specifications
=> Params
);
2535 end Make_Disp_Asynchronous_Select_Spec
;
2537 ---------------------------------------
2538 -- Make_Disp_Conditional_Select_Body --
2539 ---------------------------------------
2541 -- For interface types, generate:
2543 -- procedure _Disp_Conditional_Select
2544 -- (T : in out <Typ>;
2546 -- P : System.Address;
2547 -- C : out Ada.Tags.Prim_Op_Kind;
2552 -- C := Ada.Tags.POK_Function;
2553 -- end _Disp_Conditional_Select;
2555 -- For protected types, generate:
2557 -- procedure _Disp_Conditional_Select
2558 -- (T : in out <Typ>;
2560 -- P : System.Address;
2561 -- C : out Ada.Tags.Prim_Op_Kind;
2565 -- Bnn : System.Tasking.Protected_Objects.Operations.
2566 -- Communication_Block;
2569 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag (<Typ>VP, S));
2571 -- if C = Ada.Tags.POK_Procedure
2572 -- or else C = Ada.Tags.POK_Protected_Procedure
2573 -- or else C = Ada.Tags.POK_Task_Procedure
2579 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2580 -- System.Tasking.Protected_Objects.Operations.Protected_Entry_Call
2581 -- (T.object'Access,
2582 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
2584 -- System.Tasking.Conditional_Call,
2586 -- F := not Cancelled (Bnn);
2587 -- end _Disp_Conditional_Select;
2589 -- For task types, generate:
2591 -- procedure _Disp_Conditional_Select
2592 -- (T : in out <Typ>;
2594 -- P : System.Address;
2595 -- C : out Ada.Tags.Prim_Op_Kind;
2601 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2602 -- System.Tasking.Rendezvous.Task_Entry_Call
2604 -- System.Tasking.Task_Entry_Index (I),
2606 -- System.Tasking.Conditional_Call,
2608 -- end _Disp_Conditional_Select;
2610 function Make_Disp_Conditional_Select_Body
2611 (Typ
: Entity_Id
) return Node_Id
2613 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2614 Blk_Nam
: Entity_Id
;
2615 Conc_Typ
: Entity_Id
:= Empty
;
2616 Decls
: constant List_Id
:= New_List
;
2618 Stmts
: constant List_Id
:= New_List
;
2622 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2624 -- Null body is generated for interface types
2626 if Is_Interface
(Typ
) then
2628 Make_Subprogram_Body
(Loc
,
2630 Make_Disp_Conditional_Select_Spec
(Typ
),
2631 Declarations
=> No_List
,
2632 Handled_Statement_Sequence
=>
2633 Make_Handled_Sequence_Of_Statements
(Loc
,
2634 New_List
(Make_Assignment_Statement
(Loc
,
2635 Name
=> Make_Identifier
(Loc
, Name_uF
),
2636 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)))));
2639 if Is_Concurrent_Record_Type
(Typ
) then
2640 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
2645 -- where I will be used to capture the entry index of the primitive
2646 -- wrapper at position S.
2649 Make_Object_Declaration
(Loc
,
2650 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uI
),
2651 Object_Definition
=>
2652 New_Occurrence_Of
(Standard_Integer
, Loc
)));
2655 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag! (<type>VP), S);
2657 -- if C = POK_Procedure
2658 -- or else C = POK_Protected_Procedure
2659 -- or else C = POK_Task_Procedure;
2665 Build_Common_Dispatching_Select_Statements
(Typ
, Stmts
);
2668 -- Bnn : Communication_Block;
2670 -- where Bnn is the name of the communication block used in the
2671 -- call to Protected_Entry_Call.
2673 Blk_Nam
:= Make_Temporary
(Loc
, 'B');
2675 Make_Object_Declaration
(Loc
,
2676 Defining_Identifier
=> Blk_Nam
,
2677 Object_Definition
=>
2678 New_Occurrence_Of
(RTE
(RE_Communication_Block
), Loc
)));
2681 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag! (<type>VP), S);
2683 -- I is the entry index and S is the dispatch table slot
2685 if Tagged_Type_Expansion
then
2687 Unchecked_Convert_To
(RTE
(RE_Tag
),
2689 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
));
2693 Make_Attribute_Reference
(Loc
,
2694 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
2695 Attribute_Name
=> Name_Tag
);
2699 Make_Assignment_Statement
(Loc
,
2700 Name
=> Make_Identifier
(Loc
, Name_uI
),
2702 Make_Function_Call
(Loc
,
2704 New_Occurrence_Of
(RTE
(RE_Get_Entry_Index
), Loc
),
2705 Parameter_Associations
=> New_List
(
2707 Make_Identifier
(Loc
, Name_uS
)))));
2709 if Ekind
(Conc_Typ
) = E_Protected_Type
then
2711 Obj_Ref
:= -- T._object'Access
2712 Make_Attribute_Reference
(Loc
,
2713 Attribute_Name
=> Name_Unchecked_Access
,
2715 Make_Selected_Component
(Loc
,
2716 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
2717 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)));
2719 case Corresponding_Runtime_Package
(Conc_Typ
) is
2720 when System_Tasking_Protected_Objects_Entries
=>
2723 -- Protected_Entry_Call
2724 -- (T._object'Access, -- Object
2725 -- Protected_Entry_Index! (I), -- E
2726 -- P, -- Uninterpreted_Data
2727 -- Conditional_Call, -- Mode
2730 -- where T is the protected object, I is the entry index, P
2731 -- are the wrapped parameters and Bnn is the name of the
2732 -- communication block.
2735 Make_Procedure_Call_Statement
(Loc
,
2737 New_Occurrence_Of
(RTE
(RE_Protected_Entry_Call
), Loc
),
2738 Parameter_Associations
=> New_List
(
2741 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2744 (RTE
(RE_Protected_Entry_Index
), Loc
),
2745 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
2747 Make_Identifier
(Loc
, Name_uP
), -- parameter block
2749 New_Occurrence_Of
-- Conditional_Call
2750 (RTE
(RE_Conditional_Call
), Loc
),
2751 New_Occurrence_Of
-- Bnn
2754 when System_Tasking_Protected_Objects_Single_Entry
=>
2756 -- If we are compiling for a restricted run-time, the call
2757 -- uses the simpler form.
2760 Make_Procedure_Call_Statement
(Loc
,
2763 (RTE
(RE_Protected_Single_Entry_Call
), Loc
),
2764 Parameter_Associations
=> New_List
(
2767 Make_Attribute_Reference
(Loc
,
2768 Prefix
=> Make_Identifier
(Loc
, Name_uP
),
2769 Attribute_Name
=> Name_Address
),
2772 (RTE
(RE_Conditional_Call
), Loc
))));
2774 raise Program_Error
;
2778 -- F := not Cancelled (Bnn);
2780 -- where F is the success flag. The status of Cancelled is negated
2781 -- in order to match the behavior of the version for task types.
2784 Make_Assignment_Statement
(Loc
,
2785 Name
=> Make_Identifier
(Loc
, Name_uF
),
2789 Make_Function_Call
(Loc
,
2791 New_Occurrence_Of
(RTE
(RE_Cancelled
), Loc
),
2792 Parameter_Associations
=> New_List
(
2793 New_Occurrence_Of
(Blk_Nam
, Loc
))))));
2795 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
2799 -- (T._task_id, -- Acceptor
2800 -- Task_Entry_Index! (I), -- E
2801 -- P, -- Uninterpreted_Data
2802 -- Conditional_Call, -- Mode
2803 -- F); -- Rendezvous_Successful
2805 -- where T is the task object, I is the entry index, P are the
2806 -- wrapped parameters and F is the status flag.
2809 Make_Procedure_Call_Statement
(Loc
,
2811 New_Occurrence_Of
(RTE
(RE_Task_Entry_Call
), Loc
),
2812 Parameter_Associations
=> New_List
(
2814 Make_Selected_Component
(Loc
, -- T._task_id
2815 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
2816 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
2818 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2820 New_Occurrence_Of
(RTE
(RE_Task_Entry_Index
), Loc
),
2821 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
2823 Make_Identifier
(Loc
, Name_uP
), -- parameter block
2824 New_Occurrence_Of
-- Conditional_Call
2825 (RTE
(RE_Conditional_Call
), Loc
),
2826 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
2830 -- Initialize out parameters
2833 Make_Assignment_Statement
(Loc
,
2834 Name
=> Make_Identifier
(Loc
, Name_uF
),
2835 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)));
2837 Make_Assignment_Statement
(Loc
,
2838 Name
=> Make_Identifier
(Loc
, Name_uC
),
2839 Expression
=> New_Occurrence_Of
(RTE
(RE_POK_Function
), Loc
)));
2843 Make_Subprogram_Body
(Loc
,
2845 Make_Disp_Conditional_Select_Spec
(Typ
),
2846 Declarations
=> Decls
,
2847 Handled_Statement_Sequence
=>
2848 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
2849 end Make_Disp_Conditional_Select_Body
;
2851 ---------------------------------------
2852 -- Make_Disp_Conditional_Select_Spec --
2853 ---------------------------------------
2855 function Make_Disp_Conditional_Select_Spec
2856 (Typ
: Entity_Id
) return Node_Id
2858 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2859 Def_Id
: constant Node_Id
:=
2860 Make_Defining_Identifier
(Loc
,
2861 Name_uDisp_Conditional_Select
);
2862 Params
: constant List_Id
:= New_List
;
2865 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2867 -- T : in out Typ; -- Object parameter
2868 -- S : Integer; -- Primitive operation slot
2869 -- P : Address; -- Wrapped parameters
2870 -- C : out Prim_Op_Kind; -- Call kind
2871 -- F : out Boolean; -- Status flag
2873 Append_List_To
(Params
, New_List
(
2875 Make_Parameter_Specification
(Loc
,
2876 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uT
),
2877 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
),
2879 Out_Present
=> True),
2881 Make_Parameter_Specification
(Loc
,
2882 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uS
),
2883 Parameter_Type
=> New_Occurrence_Of
(Standard_Integer
, Loc
)),
2885 Make_Parameter_Specification
(Loc
,
2886 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uP
),
2887 Parameter_Type
=> New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
2889 Make_Parameter_Specification
(Loc
,
2890 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uC
),
2892 New_Occurrence_Of
(RTE
(RE_Prim_Op_Kind
), Loc
),
2893 Out_Present
=> True),
2895 Make_Parameter_Specification
(Loc
,
2896 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uF
),
2897 Parameter_Type
=> New_Occurrence_Of
(Standard_Boolean
, Loc
),
2898 Out_Present
=> True)));
2901 Make_Procedure_Specification
(Loc
,
2902 Defining_Unit_Name
=> Def_Id
,
2903 Parameter_Specifications
=> Params
);
2904 end Make_Disp_Conditional_Select_Spec
;
2906 -------------------------------------
2907 -- Make_Disp_Get_Prim_Op_Kind_Body --
2908 -------------------------------------
2910 function Make_Disp_Get_Prim_Op_Kind_Body
(Typ
: Entity_Id
) return Node_Id
is
2911 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2915 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2917 if Is_Interface
(Typ
) then
2919 Make_Subprogram_Body
(Loc
,
2921 Make_Disp_Get_Prim_Op_Kind_Spec
(Typ
),
2922 Declarations
=> New_List
,
2923 Handled_Statement_Sequence
=>
2924 Make_Handled_Sequence_Of_Statements
(Loc
,
2925 New_List
(Make_Null_Statement
(Loc
))));
2929 -- C := get_prim_op_kind (tag! (<type>VP), S);
2931 -- where C is the out parameter capturing the call kind and S is the
2932 -- dispatch table slot number.
2934 if Tagged_Type_Expansion
then
2936 Unchecked_Convert_To
(RTE
(RE_Tag
),
2938 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
));
2942 Make_Attribute_Reference
(Loc
,
2943 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
2944 Attribute_Name
=> Name_Tag
);
2948 Make_Subprogram_Body
(Loc
,
2950 Make_Disp_Get_Prim_Op_Kind_Spec
(Typ
),
2951 Declarations
=> New_List
,
2952 Handled_Statement_Sequence
=>
2953 Make_Handled_Sequence_Of_Statements
(Loc
,
2955 Make_Assignment_Statement
(Loc
,
2956 Name
=> Make_Identifier
(Loc
, Name_uC
),
2958 Make_Function_Call
(Loc
,
2960 New_Occurrence_Of
(RTE
(RE_Get_Prim_Op_Kind
), Loc
),
2961 Parameter_Associations
=> New_List
(
2963 Make_Identifier
(Loc
, Name_uS
)))))));
2964 end Make_Disp_Get_Prim_Op_Kind_Body
;
2966 -------------------------------------
2967 -- Make_Disp_Get_Prim_Op_Kind_Spec --
2968 -------------------------------------
2970 function Make_Disp_Get_Prim_Op_Kind_Spec
2971 (Typ
: Entity_Id
) return Node_Id
2973 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2974 Def_Id
: constant Node_Id
:=
2975 Make_Defining_Identifier
(Loc
, Name_uDisp_Get_Prim_Op_Kind
);
2976 Params
: constant List_Id
:= New_List
;
2979 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2981 -- T : in out Typ; -- Object parameter
2982 -- S : Integer; -- Primitive operation slot
2983 -- C : out Prim_Op_Kind; -- Call kind
2985 Append_List_To
(Params
, New_List
(
2987 Make_Parameter_Specification
(Loc
,
2988 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uT
),
2989 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
),
2991 Out_Present
=> True),
2993 Make_Parameter_Specification
(Loc
,
2994 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uS
),
2995 Parameter_Type
=> New_Occurrence_Of
(Standard_Integer
, Loc
)),
2997 Make_Parameter_Specification
(Loc
,
2998 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uC
),
3000 New_Occurrence_Of
(RTE
(RE_Prim_Op_Kind
), Loc
),
3001 Out_Present
=> True)));
3004 Make_Procedure_Specification
(Loc
,
3005 Defining_Unit_Name
=> Def_Id
,
3006 Parameter_Specifications
=> Params
);
3007 end Make_Disp_Get_Prim_Op_Kind_Spec
;
3009 --------------------------------
3010 -- Make_Disp_Get_Task_Id_Body --
3011 --------------------------------
3013 function Make_Disp_Get_Task_Id_Body
3014 (Typ
: Entity_Id
) return Node_Id
3016 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3020 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3022 if Is_Concurrent_Record_Type
(Typ
)
3023 and then Ekind
(Corresponding_Concurrent_Type
(Typ
)) = E_Task_Type
3026 -- return To_Address (_T._task_id);
3029 Make_Simple_Return_Statement
(Loc
,
3031 Make_Unchecked_Type_Conversion
(Loc
,
3032 Subtype_Mark
=> New_Occurrence_Of
(RTE
(RE_Address
), Loc
),
3034 Make_Selected_Component
(Loc
,
3035 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
3036 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
))));
3038 -- A null body is constructed for non-task types
3042 -- return Null_Address;
3045 Make_Simple_Return_Statement
(Loc
,
3046 Expression
=> New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
));
3050 Make_Subprogram_Body
(Loc
,
3051 Specification
=> Make_Disp_Get_Task_Id_Spec
(Typ
),
3052 Declarations
=> New_List
,
3053 Handled_Statement_Sequence
=>
3054 Make_Handled_Sequence_Of_Statements
(Loc
, New_List
(Ret
)));
3055 end Make_Disp_Get_Task_Id_Body
;
3057 --------------------------------
3058 -- Make_Disp_Get_Task_Id_Spec --
3059 --------------------------------
3061 function Make_Disp_Get_Task_Id_Spec
3062 (Typ
: Entity_Id
) return Node_Id
3064 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3067 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3070 Make_Function_Specification
(Loc
,
3071 Defining_Unit_Name
=>
3072 Make_Defining_Identifier
(Loc
, Name_uDisp_Get_Task_Id
),
3073 Parameter_Specifications
=> New_List
(
3074 Make_Parameter_Specification
(Loc
,
3075 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uT
),
3076 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))),
3077 Result_Definition
=>
3078 New_Occurrence_Of
(RTE
(RE_Address
), Loc
));
3079 end Make_Disp_Get_Task_Id_Spec
;
3081 ----------------------------
3082 -- Make_Disp_Requeue_Body --
3083 ----------------------------
3085 function Make_Disp_Requeue_Body
3086 (Typ
: Entity_Id
) return Node_Id
3088 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3089 Conc_Typ
: Entity_Id
:= Empty
;
3090 Stmts
: constant List_Id
:= New_List
;
3093 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3095 -- Null body is generated for interface types and non-concurrent
3098 if Is_Interface
(Typ
)
3099 or else not Is_Concurrent_Record_Type
(Typ
)
3102 Make_Subprogram_Body
(Loc
,
3103 Specification
=> Make_Disp_Requeue_Spec
(Typ
),
3104 Declarations
=> No_List
,
3105 Handled_Statement_Sequence
=>
3106 Make_Handled_Sequence_Of_Statements
(Loc
,
3107 New_List
(Make_Null_Statement
(Loc
))));
3110 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
3112 if Ekind
(Conc_Typ
) = E_Protected_Type
then
3114 -- Generate statements:
3116 -- System.Tasking.Protected_Objects.Operations.
3117 -- Requeue_Protected_Entry
3118 -- (Protection_Entries_Access (P),
3119 -- O._object'Unchecked_Access,
3120 -- Protected_Entry_Index (I),
3123 -- System.Tasking.Protected_Objects.Operations.
3124 -- Requeue_Task_To_Protected_Entry
3125 -- (O._object'Unchecked_Access,
3126 -- Protected_Entry_Index (I),
3130 if Restriction_Active
(No_Entry_Queue
) then
3131 Append_To
(Stmts
, Make_Null_Statement
(Loc
));
3134 Make_If_Statement
(Loc
,
3135 Condition
=> Make_Identifier
(Loc
, Name_uF
),
3140 -- Call to Requeue_Protected_Entry
3142 Make_Procedure_Call_Statement
(Loc
,
3145 (RTE
(RE_Requeue_Protected_Entry
), Loc
),
3146 Parameter_Associations
=>
3149 Make_Unchecked_Type_Conversion
(Loc
, -- PEA (P)
3152 RTE
(RE_Protection_Entries_Access
), Loc
),
3154 Make_Identifier
(Loc
, Name_uP
)),
3156 Make_Attribute_Reference
(Loc
, -- O._object'Acc
3158 Name_Unchecked_Access
,
3160 Make_Selected_Component
(Loc
,
3162 Make_Identifier
(Loc
, Name_uO
),
3164 Make_Identifier
(Loc
, Name_uObject
))),
3166 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3169 (RTE
(RE_Protected_Entry_Index
), Loc
),
3170 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
3172 Make_Identifier
(Loc
, Name_uA
)))), -- abort status
3177 -- Call to Requeue_Task_To_Protected_Entry
3179 Make_Procedure_Call_Statement
(Loc
,
3182 (RTE
(RE_Requeue_Task_To_Protected_Entry
), Loc
),
3183 Parameter_Associations
=>
3186 Make_Attribute_Reference
(Loc
, -- O._object'Acc
3187 Attribute_Name
=> Name_Unchecked_Access
,
3189 Make_Selected_Component
(Loc
,
3191 Make_Identifier
(Loc
, Name_uO
),
3193 Make_Identifier
(Loc
, Name_uObject
))),
3195 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3198 (RTE
(RE_Protected_Entry_Index
), Loc
),
3199 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
3201 Make_Identifier
(Loc
, Name_uA
)))))); -- abort status
3205 pragma Assert
(Is_Task_Type
(Conc_Typ
));
3209 -- System.Tasking.Rendezvous.Requeue_Protected_To_Task_Entry
3210 -- (Protection_Entries_Access (P),
3212 -- Task_Entry_Index (I),
3215 -- System.Tasking.Rendezvous.Requeue_Task_Entry
3217 -- Task_Entry_Index (I),
3222 Make_If_Statement
(Loc
,
3223 Condition
=> Make_Identifier
(Loc
, Name_uF
),
3225 Then_Statements
=> New_List
(
3227 -- Call to Requeue_Protected_To_Task_Entry
3229 Make_Procedure_Call_Statement
(Loc
,
3232 (RTE
(RE_Requeue_Protected_To_Task_Entry
), Loc
),
3234 Parameter_Associations
=> New_List
(
3236 Make_Unchecked_Type_Conversion
(Loc
, -- PEA (P)
3239 (RTE
(RE_Protection_Entries_Access
), Loc
),
3240 Expression
=> Make_Identifier
(Loc
, Name_uP
)),
3242 Make_Selected_Component
(Loc
, -- O._task_id
3243 Prefix
=> Make_Identifier
(Loc
, Name_uO
),
3244 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
3246 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3248 New_Occurrence_Of
(RTE
(RE_Task_Entry_Index
), Loc
),
3249 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
3251 Make_Identifier
(Loc
, Name_uA
)))), -- abort status
3253 Else_Statements
=> New_List
(
3255 -- Call to Requeue_Task_Entry
3257 Make_Procedure_Call_Statement
(Loc
,
3259 New_Occurrence_Of
(RTE
(RE_Requeue_Task_Entry
), Loc
),
3261 Parameter_Associations
=> New_List
(
3263 Make_Selected_Component
(Loc
, -- O._task_id
3264 Prefix
=> Make_Identifier
(Loc
, Name_uO
),
3265 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
3267 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3269 New_Occurrence_Of
(RTE
(RE_Task_Entry_Index
), Loc
),
3270 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
3272 Make_Identifier
(Loc
, Name_uA
)))))); -- abort status
3275 -- Even though no declarations are needed in both cases, we allocate
3276 -- a list for entities added by Freeze.
3279 Make_Subprogram_Body
(Loc
,
3280 Specification
=> Make_Disp_Requeue_Spec
(Typ
),
3281 Declarations
=> New_List
,
3282 Handled_Statement_Sequence
=>
3283 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
3284 end Make_Disp_Requeue_Body
;
3286 ----------------------------
3287 -- Make_Disp_Requeue_Spec --
3288 ----------------------------
3290 function Make_Disp_Requeue_Spec
3291 (Typ
: Entity_Id
) return Node_Id
3293 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3296 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3298 -- O : in out Typ; - Object parameter
3299 -- F : Boolean; - Protected (True) / task (False) flag
3300 -- P : Address; - Protection_Entries_Access value
3301 -- I : Entry_Index - Index of entry call
3302 -- A : Boolean - Abort flag
3304 -- Note that the Protection_Entries_Access value is represented as a
3305 -- System.Address in order to avoid dragging in the tasking runtime
3306 -- when compiling sources without tasking constructs.
3309 Make_Procedure_Specification
(Loc
,
3310 Defining_Unit_Name
=>
3311 Make_Defining_Identifier
(Loc
, Name_uDisp_Requeue
),
3313 Parameter_Specifications
=> New_List
(
3315 Make_Parameter_Specification
(Loc
, -- O
3316 Defining_Identifier
=>
3317 Make_Defining_Identifier
(Loc
, Name_uO
),
3319 New_Occurrence_Of
(Typ
, Loc
),
3321 Out_Present
=> True),
3323 Make_Parameter_Specification
(Loc
, -- F
3324 Defining_Identifier
=>
3325 Make_Defining_Identifier
(Loc
, Name_uF
),
3327 New_Occurrence_Of
(Standard_Boolean
, Loc
)),
3329 Make_Parameter_Specification
(Loc
, -- P
3330 Defining_Identifier
=>
3331 Make_Defining_Identifier
(Loc
, Name_uP
),
3333 New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
3335 Make_Parameter_Specification
(Loc
, -- I
3336 Defining_Identifier
=>
3337 Make_Defining_Identifier
(Loc
, Name_uI
),
3339 New_Occurrence_Of
(Standard_Integer
, Loc
)),
3341 Make_Parameter_Specification
(Loc
, -- A
3342 Defining_Identifier
=>
3343 Make_Defining_Identifier
(Loc
, Name_uA
),
3345 New_Occurrence_Of
(Standard_Boolean
, Loc
))));
3346 end Make_Disp_Requeue_Spec
;
3348 ---------------------------------
3349 -- Make_Disp_Timed_Select_Body --
3350 ---------------------------------
3352 -- For interface types, generate:
3354 -- procedure _Disp_Timed_Select
3355 -- (T : in out <Typ>;
3357 -- P : System.Address;
3360 -- C : out Ada.Tags.Prim_Op_Kind;
3365 -- C := Ada.Tags.POK_Function;
3366 -- end _Disp_Timed_Select;
3368 -- For protected types, generate:
3370 -- procedure _Disp_Timed_Select
3371 -- (T : in out <Typ>;
3373 -- P : System.Address;
3376 -- C : out Ada.Tags.Prim_Op_Kind;
3382 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag (<Typ>VP), S);
3384 -- if C = Ada.Tags.POK_Procedure
3385 -- or else C = Ada.Tags.POK_Protected_Procedure
3386 -- or else C = Ada.Tags.POK_Task_Procedure
3392 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP), S);
3393 -- System.Tasking.Protected_Objects.Operations.
3394 -- Timed_Protected_Entry_Call
3395 -- (T._object'Access,
3396 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
3401 -- end _Disp_Timed_Select;
3403 -- For task types, generate:
3405 -- procedure _Disp_Timed_Select
3406 -- (T : in out <Typ>;
3408 -- P : System.Address;
3411 -- C : out Ada.Tags.Prim_Op_Kind;
3417 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP), S);
3418 -- System.Tasking.Rendezvous.Timed_Task_Entry_Call
3420 -- System.Tasking.Task_Entry_Index (I),
3425 -- end _Disp_Time_Select;
3427 function Make_Disp_Timed_Select_Body
3428 (Typ
: Entity_Id
) return Node_Id
3430 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3431 Conc_Typ
: Entity_Id
:= Empty
;
3432 Decls
: constant List_Id
:= New_List
;
3434 Stmts
: constant List_Id
:= New_List
;
3438 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3440 -- Null body is generated for interface types
3442 if Is_Interface
(Typ
) then
3444 Make_Subprogram_Body
(Loc
,
3445 Specification
=> Make_Disp_Timed_Select_Spec
(Typ
),
3446 Declarations
=> New_List
,
3447 Handled_Statement_Sequence
=>
3448 Make_Handled_Sequence_Of_Statements
(Loc
,
3450 Make_Assignment_Statement
(Loc
,
3451 Name
=> Make_Identifier
(Loc
, Name_uF
),
3452 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)))));
3455 if Is_Concurrent_Record_Type
(Typ
) then
3456 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
3461 -- where I will be used to capture the entry index of the primitive
3462 -- wrapper at position S.
3465 Make_Object_Declaration
(Loc
,
3466 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uI
),
3467 Object_Definition
=>
3468 New_Occurrence_Of
(Standard_Integer
, Loc
)));
3471 -- C := Get_Prim_Op_Kind (tag! (<type>VP), S);
3473 -- if C = POK_Procedure
3474 -- or else C = POK_Protected_Procedure
3475 -- or else C = POK_Task_Procedure;
3481 Build_Common_Dispatching_Select_Statements
(Typ
, Stmts
);
3484 -- I := Get_Entry_Index (tag! (<type>VP), S);
3486 -- I is the entry index and S is the dispatch table slot
3488 if Tagged_Type_Expansion
then
3490 Unchecked_Convert_To
(RTE
(RE_Tag
),
3492 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
));
3496 Make_Attribute_Reference
(Loc
,
3497 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
3498 Attribute_Name
=> Name_Tag
);
3502 Make_Assignment_Statement
(Loc
,
3503 Name
=> Make_Identifier
(Loc
, Name_uI
),
3505 Make_Function_Call
(Loc
,
3506 Name
=> New_Occurrence_Of
(RTE
(RE_Get_Entry_Index
), Loc
),
3507 Parameter_Associations
=> New_List
(
3509 Make_Identifier
(Loc
, Name_uS
)))));
3513 if Ekind
(Conc_Typ
) = E_Protected_Type
then
3515 -- Build T._object'Access
3518 Make_Attribute_Reference
(Loc
,
3519 Attribute_Name
=> Name_Unchecked_Access
,
3521 Make_Selected_Component
(Loc
,
3522 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
3523 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)));
3525 -- Normal case, No_Entry_Queue restriction not active. In this
3526 -- case we generate:
3528 -- Timed_Protected_Entry_Call
3529 -- (T._object'access,
3530 -- Protected_Entry_Index! (I),
3533 -- where T is the protected object, I is the entry index, P are
3534 -- the wrapped parameters, D is the delay amount, M is the delay
3535 -- mode and F is the status flag.
3537 -- Historically, there was also an implementation for single
3538 -- entry protected types (in s-tposen). However, it was removed
3539 -- by also testing for no No_Select_Statements restriction in
3540 -- Exp_Utils.Corresponding_Runtime_Package. This simplified the
3541 -- implementation of s-tposen.adb and provided consistency between
3542 -- all versions of System.Tasking.Protected_Objects.Single_Entry
3545 case Corresponding_Runtime_Package
(Conc_Typ
) is
3546 when System_Tasking_Protected_Objects_Entries
=>
3548 Make_Procedure_Call_Statement
(Loc
,
3551 (RTE
(RE_Timed_Protected_Entry_Call
), Loc
),
3552 Parameter_Associations
=> New_List
(
3555 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3558 (RTE
(RE_Protected_Entry_Index
), Loc
),
3559 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
3561 Make_Identifier
(Loc
, Name_uP
), -- parameter block
3562 Make_Identifier
(Loc
, Name_uD
), -- delay
3563 Make_Identifier
(Loc
, Name_uM
), -- delay mode
3564 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
3567 raise Program_Error
;
3573 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
3576 -- Timed_Task_Entry_Call (
3578 -- Task_Entry_Index! (I),
3584 -- where T is the task object, I is the entry index, P are the
3585 -- wrapped parameters, D is the delay amount, M is the delay
3586 -- mode and F is the status flag.
3589 Make_Procedure_Call_Statement
(Loc
,
3591 New_Occurrence_Of
(RTE
(RE_Timed_Task_Entry_Call
), Loc
),
3593 Parameter_Associations
=> New_List
(
3594 Make_Selected_Component
(Loc
, -- T._task_id
3595 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
3596 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
3598 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3600 New_Occurrence_Of
(RTE
(RE_Task_Entry_Index
), Loc
),
3601 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
3603 Make_Identifier
(Loc
, Name_uP
), -- parameter block
3604 Make_Identifier
(Loc
, Name_uD
), -- delay
3605 Make_Identifier
(Loc
, Name_uM
), -- delay mode
3606 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
3610 -- Initialize out parameters
3613 Make_Assignment_Statement
(Loc
,
3614 Name
=> Make_Identifier
(Loc
, Name_uF
),
3615 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)));
3617 Make_Assignment_Statement
(Loc
,
3618 Name
=> Make_Identifier
(Loc
, Name_uC
),
3619 Expression
=> New_Occurrence_Of
(RTE
(RE_POK_Function
), Loc
)));
3623 Make_Subprogram_Body
(Loc
,
3624 Specification
=> Make_Disp_Timed_Select_Spec
(Typ
),
3625 Declarations
=> Decls
,
3626 Handled_Statement_Sequence
=>
3627 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
3628 end Make_Disp_Timed_Select_Body
;
3630 ---------------------------------
3631 -- Make_Disp_Timed_Select_Spec --
3632 ---------------------------------
3634 function Make_Disp_Timed_Select_Spec
3635 (Typ
: Entity_Id
) return Node_Id
3637 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3638 Def_Id
: constant Node_Id
:=
3639 Make_Defining_Identifier
(Loc
,
3640 Name_uDisp_Timed_Select
);
3641 Params
: constant List_Id
:= New_List
;
3644 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3646 -- T : in out Typ; -- Object parameter
3647 -- S : Integer; -- Primitive operation slot
3648 -- P : Address; -- Wrapped parameters
3649 -- D : Duration; -- Delay
3650 -- M : Integer; -- Delay Mode
3651 -- C : out Prim_Op_Kind; -- Call kind
3652 -- F : out Boolean; -- Status flag
3654 Append_List_To
(Params
, New_List
(
3656 Make_Parameter_Specification
(Loc
,
3657 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uT
),
3658 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
),
3660 Out_Present
=> True),
3662 Make_Parameter_Specification
(Loc
,
3663 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uS
),
3664 Parameter_Type
=> New_Occurrence_Of
(Standard_Integer
, Loc
)),
3666 Make_Parameter_Specification
(Loc
,
3667 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uP
),
3668 Parameter_Type
=> New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
3670 Make_Parameter_Specification
(Loc
,
3671 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uD
),
3672 Parameter_Type
=> New_Occurrence_Of
(Standard_Duration
, Loc
)),
3674 Make_Parameter_Specification
(Loc
,
3675 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uM
),
3676 Parameter_Type
=> New_Occurrence_Of
(Standard_Integer
, Loc
)),
3678 Make_Parameter_Specification
(Loc
,
3679 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uC
),
3681 New_Occurrence_Of
(RTE
(RE_Prim_Op_Kind
), Loc
),
3682 Out_Present
=> True)));
3685 Make_Parameter_Specification
(Loc
,
3686 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uF
),
3687 Parameter_Type
=> New_Occurrence_Of
(Standard_Boolean
, Loc
),
3688 Out_Present
=> True));
3691 Make_Procedure_Specification
(Loc
,
3692 Defining_Unit_Name
=> Def_Id
,
3693 Parameter_Specifications
=> Params
);
3694 end Make_Disp_Timed_Select_Spec
;
3700 -- The frontend supports two models for expanding dispatch tables
3701 -- associated with library-level defined tagged types: statically and
3702 -- non-statically allocated dispatch tables. In the former case the object
3703 -- containing the dispatch table is constant and it is initialized by means
3704 -- of a positional aggregate. In the latter case, the object containing
3705 -- the dispatch table is a variable which is initialized by means of
3708 -- In case of locally defined tagged types, the object containing the
3709 -- object containing the dispatch table is always a variable (instead of a
3710 -- constant). This is currently required to give support to late overriding
3711 -- of primitives. For example:
3713 -- procedure Example is
3715 -- type T1 is tagged null record;
3716 -- procedure Prim (O : T1);
3719 -- type T2 is new Pkg.T1 with null record;
3720 -- procedure Prim (X : T2) is -- late overriding
3726 -- WARNING: This routine manages Ghost regions. Return statements must be
3727 -- replaced by gotos which jump to the end of the routine and restore the
3730 function Make_DT
(Typ
: Entity_Id
; N
: Node_Id
:= Empty
) return List_Id
is
3731 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3733 Max_Predef_Prims
: constant Int
:=
3737 (Parent
(RTE
(RE_Max_Predef_Prims
)))));
3739 DT_Decl
: constant Elist_Id
:= New_Elmt_List
;
3740 DT_Aggr
: constant Elist_Id
:= New_Elmt_List
;
3741 -- Entities marked with attribute Is_Dispatch_Table_Entity
3743 Dummy_Object
: Entity_Id
:= Empty
;
3744 -- Extra nonexistent object of type Typ internally used to compute the
3745 -- offset to the components that reference secondary dispatch tables.
3746 -- Used to statically allocate secondary dispatch tables.
3748 procedure Check_Premature_Freezing
3750 Tagged_Type
: Entity_Id
;
3752 -- Verify that all untagged types in the profile of a subprogram are
3753 -- frozen at the point the subprogram is frozen. This enforces the rule
3754 -- on RM 13.14 (14) as modified by AI05-019. At the point a subprogram
3755 -- is frozen, enough must be known about it to build the activation
3756 -- record for it, which requires at least that the size of all
3757 -- parameters be known. Controlling arguments are by-reference,
3758 -- and therefore the rule only applies to untagged types. Typical
3759 -- violation of the rule involves an object declaration that freezes a
3760 -- tagged type, when one of its primitive operations has a type in its
3761 -- profile whose full view has not been analyzed yet. More complex cases
3762 -- involve composite types that have one private unfrozen subcomponent.
3764 procedure Export_DT
(Typ
: Entity_Id
; DT
: Entity_Id
; Index
: Nat
:= 0);
3765 -- Export the dispatch table DT of tagged type Typ. Required to generate
3766 -- forward references and statically allocate the table. For primary
3767 -- dispatch tables Index is 0; for secondary dispatch tables the value
3768 -- of index must match the Suffix_Index value assigned to the table by
3769 -- Make_Tags when generating its unique external name, and it is used to
3770 -- retrieve from the Dispatch_Table_Wrappers list associated with Typ
3771 -- the external name generated by Import_DT.
3773 procedure Make_Secondary_DT
3776 Iface_Comp
: Node_Id
;
3778 Num_Iface_Prims
: Nat
;
3779 Iface_DT_Ptr
: Entity_Id
;
3780 Predef_Prims_Ptr
: Entity_Id
;
3781 Build_Thunks
: Boolean;
3783 -- Ada 2005 (AI-251): Expand the declarations for a Secondary Dispatch
3784 -- Table of Typ associated with Iface. Each abstract interface of Typ
3785 -- has two secondary dispatch tables: one containing pointers to thunks
3786 -- and another containing pointers to the primitives covering the
3787 -- interface primitives. The former secondary table is generated when
3788 -- Build_Thunks is True, and provides common support for dispatching
3789 -- calls through interface types; the latter secondary table is
3790 -- generated when Build_Thunks is False, and provides support for
3791 -- Generic Dispatching Constructors that dispatch calls through
3792 -- interface types. When constructing this latter table the value of
3793 -- Suffix_Index is -1 to indicate that there is no need to export such
3794 -- table when building statically allocated dispatch tables; a positive
3795 -- value of Suffix_Index must match the Suffix_Index value assigned to
3796 -- this secondary dispatch table by Make_Tags when its unique external
3797 -- name was generated.
3799 ------------------------------
3800 -- Check_Premature_Freezing --
3801 ------------------------------
3803 procedure Check_Premature_Freezing
3805 Tagged_Type
: Entity_Id
;
3810 function Is_Actual_For_Formal_Incomplete_Type
3811 (T
: Entity_Id
) return Boolean;
3812 -- In Ada 2012, if a nested generic has an incomplete formal type,
3813 -- the actual may be (and usually is) a private type whose completion
3814 -- appears later. It is safe to build the dispatch table in this
3815 -- case, gigi will have full views available.
3817 ------------------------------------------
3818 -- Is_Actual_For_Formal_Incomplete_Type --
3819 ------------------------------------------
3821 function Is_Actual_For_Formal_Incomplete_Type
3822 (T
: Entity_Id
) return Boolean
3824 Gen_Par
: Entity_Id
;
3828 if not Is_Generic_Instance
(Current_Scope
)
3829 or else not Used_As_Generic_Actual
(T
)
3833 Gen_Par
:= Generic_Parent
(Parent
(Current_Scope
));
3838 (Generic_Formal_Declarations
3839 (Unit_Declaration_Node
(Gen_Par
)));
3840 while Present
(F
) loop
3841 if Ekind
(Defining_Identifier
(F
)) = E_Incomplete_Type
then
3849 end Is_Actual_For_Formal_Incomplete_Type
;
3851 -- Start of processing for Check_Premature_Freezing
3854 -- Note that if the type is a (subtype of) a generic actual, the
3855 -- actual will have been frozen by the instantiation.
3858 and then Is_Private_Type
(Typ
)
3859 and then No
(Full_View
(Typ
))
3860 and then not Is_Generic_Type
(Typ
)
3861 and then not Is_Tagged_Type
(Typ
)
3862 and then not Is_Frozen
(Typ
)
3863 and then not Is_Generic_Actual_Type
(Typ
)
3865 Error_Msg_Sloc
:= Sloc
(Subp
);
3867 ("declaration must appear after completion of type &", N
, Typ
);
3869 ("\which is an untagged type in the profile of "
3870 & "primitive operation & declared#", N
, Subp
);
3873 Comp
:= Private_Component
(Typ
);
3875 if not Is_Tagged_Type
(Typ
)
3876 and then Present
(Comp
)
3877 and then not Is_Frozen
(Comp
)
3878 and then not Is_Actual_For_Formal_Incomplete_Type
(Comp
)
3880 Error_Msg_Sloc
:= Sloc
(Subp
);
3881 Error_Msg_Node_2
:= Subp
;
3882 Error_Msg_Name_1
:= Chars
(Tagged_Type
);
3884 ("declaration must appear after completion of type &",
3887 ("\which is a component of untagged type& in the profile "
3888 & "of primitive & of type % that is frozen by the "
3889 & "declaration ", N
, Typ
);
3892 end Check_Premature_Freezing
;
3898 procedure Export_DT
(Typ
: Entity_Id
; DT
: Entity_Id
; Index
: Nat
:= 0)
3904 Set_Is_Statically_Allocated
(DT
);
3905 Set_Is_True_Constant
(DT
);
3906 Set_Is_Exported
(DT
);
3909 Elmt
:= First_Elmt
(Dispatch_Table_Wrappers
(Typ
));
3910 while Count
/= Index
loop
3915 pragma Assert
(Related_Type
(Node
(Elmt
)) = Typ
);
3917 Get_External_Name
(Node
(Elmt
));
3918 Set_Interface_Name
(DT
,
3919 Make_String_Literal
(Loc
,
3920 Strval
=> String_From_Name_Buffer
));
3922 -- Ensure proper Sprint output of this implicit importation
3924 Set_Is_Internal
(DT
);
3928 -----------------------
3929 -- Make_Secondary_DT --
3930 -----------------------
3932 procedure Make_Secondary_DT
3935 Iface_Comp
: Node_Id
;
3937 Num_Iface_Prims
: Nat
;
3938 Iface_DT_Ptr
: Entity_Id
;
3939 Predef_Prims_Ptr
: Entity_Id
;
3940 Build_Thunks
: Boolean;
3943 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3944 Exporting_Table
: constant Boolean :=
3945 Building_Static_DT
(Typ
)
3946 and then Suffix_Index
> 0;
3947 Iface_DT
: constant Entity_Id
:= Make_Temporary
(Loc
, 'T');
3948 Predef_Prims
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
3949 DT_Constr_List
: List_Id
;
3950 DT_Aggr_List
: List_Id
;
3951 Empty_DT
: Boolean := False;
3952 Nb_Predef_Prims
: Nat
:= 0;
3956 OSD_Aggr_List
: List_Id
;
3959 Prim_Elmt
: Elmt_Id
;
3960 Prim_Ops_Aggr_List
: List_Id
;
3963 -- Handle cases in which we do not generate statically allocated
3966 if not Building_Static_DT
(Typ
) then
3967 Set_Ekind
(Predef_Prims
, E_Variable
);
3968 Set_Ekind
(Iface_DT
, E_Variable
);
3970 -- Statically allocated dispatch tables and related entities are
3974 Set_Ekind
(Predef_Prims
, E_Constant
);
3975 Set_Is_Statically_Allocated
(Predef_Prims
);
3976 Set_Is_True_Constant
(Predef_Prims
);
3978 Set_Ekind
(Iface_DT
, E_Constant
);
3979 Set_Is_Statically_Allocated
(Iface_DT
);
3980 Set_Is_True_Constant
(Iface_DT
);
3983 -- Calculate the number of slots of the dispatch table. If the number
3984 -- of primitives of Typ is 0 we reserve a dummy single entry for its
3985 -- DT because at run time the pointer to this dummy entry will be
3988 if Num_Iface_Prims
= 0 then
3992 Nb_Prim
:= Num_Iface_Prims
;
3997 -- Predef_Prims : Address_Array (1 .. Default_Prim_Ops_Count) :=
3998 -- (predef-prim-op-thunk-1'address,
3999 -- predef-prim-op-thunk-2'address,
4001 -- predef-prim-op-thunk-n'address);
4002 -- for Predef_Prims'Alignment use Address'Alignment
4004 -- Stage 1: Calculate the number of predefined primitives
4006 if not Building_Static_DT
(Typ
) then
4007 Nb_Predef_Prims
:= Max_Predef_Prims
;
4009 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
4010 while Present
(Prim_Elmt
) loop
4011 Prim
:= Node
(Prim_Elmt
);
4013 if Is_Predefined_Dispatching_Operation
(Prim
)
4014 and then not Is_Abstract_Subprogram
(Prim
)
4016 Pos
:= UI_To_Int
(DT_Position
(Prim
));
4018 if Pos
> Nb_Predef_Prims
then
4019 Nb_Predef_Prims
:= Pos
;
4023 Next_Elmt
(Prim_Elmt
);
4027 if Generate_SCIL
then
4028 Nb_Predef_Prims
:= 0;
4031 -- Stage 2: Create the thunks associated with the predefined
4032 -- primitives and save their entity to fill the aggregate.
4035 Prim_Table
: array (Nat
range 1 .. Nb_Predef_Prims
) of Entity_Id
;
4037 Thunk_Id
: Entity_Id
;
4038 Thunk_Code
: Node_Id
;
4041 Prim_Ops_Aggr_List
:= New_List
;
4042 Prim_Table
:= (others => Empty
);
4044 if Building_Static_DT
(Typ
) then
4045 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
4046 while Present
(Prim_Elmt
) loop
4047 Prim
:= Node
(Prim_Elmt
);
4049 if Is_Predefined_Dispatching_Operation
(Prim
)
4050 and then not Is_Abstract_Subprogram
(Prim
)
4051 and then not Is_Eliminated
(Prim
)
4052 and then not Generate_SCIL
4053 and then not Present
(Prim_Table
4054 (UI_To_Int
(DT_Position
(Prim
))))
4056 if not Build_Thunks
then
4057 Prim_Table
(UI_To_Int
(DT_Position
(Prim
))) :=
4061 Expand_Interface_Thunk
4062 (Ultimate_Alias
(Prim
), Thunk_Id
, Thunk_Code
);
4064 if Present
(Thunk_Id
) then
4065 Append_To
(Result
, Thunk_Code
);
4066 Prim_Table
(UI_To_Int
(DT_Position
(Prim
))) :=
4072 Next_Elmt
(Prim_Elmt
);
4076 for J
in Prim_Table
'Range loop
4077 if Present
(Prim_Table
(J
)) then
4079 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
4080 Make_Attribute_Reference
(Loc
,
4081 Prefix
=> New_Occurrence_Of
(Prim_Table
(J
), Loc
),
4082 Attribute_Name
=> Name_Unrestricted_Access
));
4084 New_Node
:= Make_Null
(Loc
);
4087 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
4091 Make_Aggregate
(Loc
, Expressions
=> Prim_Ops_Aggr_List
);
4093 -- Remember aggregates initializing dispatch tables
4095 Append_Elmt
(New_Node
, DT_Aggr
);
4098 Make_Subtype_Declaration
(Loc
,
4099 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
4100 Subtype_Indication
=>
4101 New_Occurrence_Of
(RTE
(RE_Address_Array
), Loc
));
4103 Append_To
(Result
, Decl
);
4106 Make_Object_Declaration
(Loc
,
4107 Defining_Identifier
=> Predef_Prims
,
4108 Constant_Present
=> Building_Static_DT
(Typ
),
4109 Aliased_Present
=> True,
4110 Object_Definition
=> New_Occurrence_Of
4111 (Defining_Identifier
(Decl
), Loc
),
4112 Expression
=> New_Node
));
4115 Make_Attribute_Definition_Clause
(Loc
,
4116 Name
=> New_Occurrence_Of
(Predef_Prims
, Loc
),
4117 Chars
=> Name_Alignment
,
4119 Make_Attribute_Reference
(Loc
,
4121 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
4122 Attribute_Name
=> Name_Alignment
)));
4127 -- OSD : Ada.Tags.Object_Specific_Data (Nb_Prims) :=
4128 -- (OSD_Table => (1 => <value>,
4132 -- Iface_DT : Dispatch_Table (Nb_Prims) :=
4133 -- ([ Signature => <sig-value> ],
4134 -- Tag_Kind => <tag_kind-value>,
4135 -- Predef_Prims => Predef_Prims'Address,
4136 -- Offset_To_Top => 0,
4137 -- OSD => OSD'Address,
4138 -- Prims_Ptr => (prim-op-1'address,
4139 -- prim-op-2'address,
4141 -- prim-op-n'address));
4142 -- for Iface_DT'Alignment use Address'Alignment;
4144 -- Stage 3: Initialize the discriminant and the record components
4146 DT_Constr_List
:= New_List
;
4147 DT_Aggr_List
:= New_List
;
4151 Append_To
(DT_Constr_List
, Make_Integer_Literal
(Loc
, Nb_Prim
));
4152 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, Nb_Prim
));
4156 if RTE_Record_Component_Available
(RE_Signature
) then
4157 Append_To
(DT_Aggr_List
,
4158 New_Occurrence_Of
(RTE
(RE_Secondary_DT
), Loc
));
4163 if RTE_Record_Component_Available
(RE_Tag_Kind
) then
4164 Append_To
(DT_Aggr_List
, Tagged_Kind
(Typ
));
4169 Append_To
(DT_Aggr_List
,
4170 Make_Attribute_Reference
(Loc
,
4171 Prefix
=> New_Occurrence_Of
(Predef_Prims
, Loc
),
4172 Attribute_Name
=> Name_Address
));
4174 -- If the location of the component that references this secondary
4175 -- dispatch table is variable then we have not declared the internal
4176 -- dummy object; the value of Offset_To_Top will be set by the init
4179 if No
(Dummy_Object
) then
4180 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, 0));
4183 Append_To
(DT_Aggr_List
,
4185 Make_Attribute_Reference
(Loc
,
4187 Make_Selected_Component
(Loc
,
4189 New_Occurrence_Of
(Dummy_Object
, Loc
),
4191 New_Occurrence_Of
(Iface_Comp
, Loc
)),
4192 Attribute_Name
=> Name_Position
)));
4195 -- Generate the Object Specific Data table required to dispatch calls
4196 -- through synchronized interfaces.
4199 or else Is_Abstract_Type
(Typ
)
4200 or else Is_Controlled
(Typ
)
4201 or else Restriction_Active
(No_Dispatching_Calls
)
4202 or else not Is_Limited_Type
(Typ
)
4203 or else not Has_Interfaces
(Typ
)
4204 or else not Build_Thunks
4205 or else not RTE_Record_Component_Available
(RE_OSD_Table
)
4207 -- No OSD table required
4209 Append_To
(DT_Aggr_List
,
4210 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
));
4213 OSD_Aggr_List
:= New_List
;
4216 Prim_Table
: array (Nat
range 1 .. Nb_Prim
) of Entity_Id
;
4218 Prim_Alias
: Entity_Id
;
4219 Prim_Elmt
: Elmt_Id
;
4225 Prim_Table
:= (others => Empty
);
4226 Prim_Alias
:= Empty
;
4228 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
4229 while Present
(Prim_Elmt
) loop
4230 Prim
:= Node
(Prim_Elmt
);
4232 if Present
(Interface_Alias
(Prim
))
4233 and then Find_Dispatching_Type
4234 (Interface_Alias
(Prim
)) = Iface
4236 Prim_Alias
:= Interface_Alias
(Prim
);
4237 E
:= Ultimate_Alias
(Prim
);
4238 Pos
:= UI_To_Int
(DT_Position
(Prim_Alias
));
4240 if Present
(Prim_Table
(Pos
)) then
4241 pragma Assert
(Prim_Table
(Pos
) = E
);
4245 Prim_Table
(Pos
) := E
;
4247 Append_To
(OSD_Aggr_List
,
4248 Make_Component_Association
(Loc
,
4249 Choices
=> New_List
(
4250 Make_Integer_Literal
(Loc
,
4251 DT_Position
(Prim_Alias
))),
4253 Make_Integer_Literal
(Loc
,
4254 DT_Position
(Alias
(Prim
)))));
4260 Next_Elmt
(Prim_Elmt
);
4262 pragma Assert
(Count
= Nb_Prim
);
4265 OSD
:= Make_Temporary
(Loc
, 'I');
4268 Make_Object_Declaration
(Loc
,
4269 Defining_Identifier
=> OSD
,
4270 Object_Definition
=>
4271 Make_Subtype_Indication
(Loc
,
4273 New_Occurrence_Of
(RTE
(RE_Object_Specific_Data
), Loc
),
4275 Make_Index_Or_Discriminant_Constraint
(Loc
,
4276 Constraints
=> New_List
(
4277 Make_Integer_Literal
(Loc
, Nb_Prim
)))),
4280 Make_Aggregate
(Loc
,
4281 Component_Associations
=> New_List
(
4282 Make_Component_Association
(Loc
,
4283 Choices
=> New_List
(
4285 (RTE_Record_Component
(RE_OSD_Num_Prims
), Loc
)),
4287 Make_Integer_Literal
(Loc
, Nb_Prim
)),
4289 Make_Component_Association
(Loc
,
4290 Choices
=> New_List
(
4292 (RTE_Record_Component
(RE_OSD_Table
), Loc
)),
4293 Expression
=> Make_Aggregate
(Loc
,
4294 Component_Associations
=> OSD_Aggr_List
))))));
4297 Make_Attribute_Definition_Clause
(Loc
,
4298 Name
=> New_Occurrence_Of
(OSD
, Loc
),
4299 Chars
=> Name_Alignment
,
4301 Make_Attribute_Reference
(Loc
,
4303 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
4304 Attribute_Name
=> Name_Alignment
)));
4306 -- In secondary dispatch tables the Typeinfo component contains
4307 -- the address of the Object Specific Data (see a-tags.ads)
4309 Append_To
(DT_Aggr_List
,
4310 Make_Attribute_Reference
(Loc
,
4311 Prefix
=> New_Occurrence_Of
(OSD
, Loc
),
4312 Attribute_Name
=> Name_Address
));
4315 -- Initialize the table of primitive operations
4317 Prim_Ops_Aggr_List
:= New_List
;
4320 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
4322 elsif Is_Abstract_Type
(Typ
)
4323 or else not Building_Static_DT
(Typ
)
4325 for J
in 1 .. Nb_Prim
loop
4326 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
4331 CPP_Nb_Prims
: constant Nat
:= CPP_Num_Prims
(Typ
);
4334 Prim_Table
: array (Nat
range 1 .. Nb_Prim
) of Entity_Id
;
4335 Thunk_Code
: Node_Id
;
4336 Thunk_Id
: Entity_Id
;
4339 Prim_Table
:= (others => Empty
);
4341 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
4342 while Present
(Prim_Elmt
) loop
4343 Prim
:= Node
(Prim_Elmt
);
4344 E
:= Ultimate_Alias
(Prim
);
4345 Prim_Pos
:= UI_To_Int
(DT_Position
(E
));
4347 -- Do not reference predefined primitives because they are
4348 -- located in a separate dispatch table; skip abstract and
4349 -- eliminated primitives; skip primitives located in the C++
4350 -- part of the dispatch table because their slot is set by
4353 if not Is_Predefined_Dispatching_Operation
(Prim
)
4354 and then Present
(Interface_Alias
(Prim
))
4355 and then not Is_Abstract_Subprogram
(Alias
(Prim
))
4356 and then not Is_Eliminated
(Alias
(Prim
))
4357 and then (not Is_CPP_Class
(Root_Type
(Typ
))
4358 or else Prim_Pos
> CPP_Nb_Prims
)
4359 and then Find_Dispatching_Type
4360 (Interface_Alias
(Prim
)) = Iface
4362 -- Generate the code of the thunk only if the abstract
4363 -- interface type is not an immediate ancestor of
4364 -- Tagged_Type. Otherwise the DT associated with the
4365 -- interface is the primary DT.
4367 and then not Is_Ancestor
(Iface
, Typ
,
4368 Use_Full_View
=> True)
4370 if not Build_Thunks
then
4372 UI_To_Int
(DT_Position
(Interface_Alias
(Prim
)));
4373 Prim_Table
(Prim_Pos
) := Alias
(Prim
);
4376 Expand_Interface_Thunk
(Prim
, Thunk_Id
, Thunk_Code
);
4378 if Present
(Thunk_Id
) then
4380 UI_To_Int
(DT_Position
(Interface_Alias
(Prim
)));
4382 Prim_Table
(Prim_Pos
) := Thunk_Id
;
4383 Append_To
(Result
, Thunk_Code
);
4388 Next_Elmt
(Prim_Elmt
);
4391 for J
in Prim_Table
'Range loop
4392 if Present
(Prim_Table
(J
)) then
4394 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
4395 Make_Attribute_Reference
(Loc
,
4396 Prefix
=> New_Occurrence_Of
(Prim_Table
(J
), Loc
),
4397 Attribute_Name
=> Name_Unrestricted_Access
));
4400 New_Node
:= Make_Null
(Loc
);
4403 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
4409 Make_Aggregate
(Loc
,
4410 Expressions
=> Prim_Ops_Aggr_List
);
4412 Append_To
(DT_Aggr_List
, New_Node
);
4414 -- Remember aggregates initializing dispatch tables
4416 Append_Elmt
(New_Node
, DT_Aggr
);
4418 -- Note: Secondary dispatch tables are declared constant only if
4419 -- we can compute their offset field by means of the extra dummy
4420 -- object; otherwise they cannot be declared constant and the
4421 -- Offset_To_Top component is initialized by the IP routine.
4424 Make_Object_Declaration
(Loc
,
4425 Defining_Identifier
=> Iface_DT
,
4426 Aliased_Present
=> True,
4427 Constant_Present
=> Present
(Dummy_Object
),
4429 Object_Definition
=>
4430 Make_Subtype_Indication
(Loc
,
4431 Subtype_Mark
=> New_Occurrence_Of
4432 (RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
4433 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
,
4434 Constraints
=> DT_Constr_List
)),
4437 Make_Aggregate
(Loc
,
4438 Expressions
=> DT_Aggr_List
)));
4441 Make_Attribute_Definition_Clause
(Loc
,
4442 Name
=> New_Occurrence_Of
(Iface_DT
, Loc
),
4443 Chars
=> Name_Alignment
,
4446 Make_Attribute_Reference
(Loc
,
4448 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
4449 Attribute_Name
=> Name_Alignment
)));
4451 if Exporting_Table
then
4452 Export_DT
(Typ
, Iface_DT
, Suffix_Index
);
4454 -- Generate code to create the pointer to the dispatch table
4456 -- Iface_DT_Ptr : Tag := Tag!(DT.Prims_Ptr'Address);
4458 -- Note: This declaration is not added here if the table is exported
4459 -- because in such case Make_Tags has already added this declaration.
4463 Make_Object_Declaration
(Loc
,
4464 Defining_Identifier
=> Iface_DT_Ptr
,
4465 Constant_Present
=> True,
4467 Object_Definition
=>
4468 New_Occurrence_Of
(RTE
(RE_Interface_Tag
), Loc
),
4471 Unchecked_Convert_To
(RTE
(RE_Interface_Tag
),
4472 Make_Attribute_Reference
(Loc
,
4474 Make_Selected_Component
(Loc
,
4475 Prefix
=> New_Occurrence_Of
(Iface_DT
, Loc
),
4478 (RTE_Record_Component
(RE_Prims_Ptr
), Loc
)),
4479 Attribute_Name
=> Name_Address
))));
4483 Make_Object_Declaration
(Loc
,
4484 Defining_Identifier
=> Predef_Prims_Ptr
,
4485 Constant_Present
=> True,
4487 Object_Definition
=>
4488 New_Occurrence_Of
(RTE
(RE_Address
), Loc
),
4491 Make_Attribute_Reference
(Loc
,
4493 Make_Selected_Component
(Loc
,
4494 Prefix
=> New_Occurrence_Of
(Iface_DT
, Loc
),
4497 (RTE_Record_Component
(RE_Predef_Prims
), Loc
)),
4498 Attribute_Name
=> Name_Address
)));
4500 -- Remember entities containing dispatch tables
4502 Append_Elmt
(Predef_Prims
, DT_Decl
);
4503 Append_Elmt
(Iface_DT
, DT_Decl
);
4504 end Make_Secondary_DT
;
4508 Elab_Code
: constant List_Id
:= New_List
;
4509 Result
: constant List_Id
:= New_List
;
4510 Tname
: constant Name_Id
:= Chars
(Typ
);
4512 -- When pragmas Discard_Names and No_Tagged_Streams simultaneously apply
4513 -- we initialize the Expanded_Name and the External_Tag of this tagged
4514 -- type with an empty string. This is useful to avoid exposing entity
4515 -- names at binary level. It can be done when both pragmas apply because
4516 -- (1) Discard_Names allows initializing Expanded_Name with an
4517 -- implementation defined value (Ada RM Section C.5 (7/2)).
4518 -- (2) External_Tag (combined with Internal_Tag) is used for object
4519 -- streaming and No_Tagged_Streams inhibits the generation of
4522 Discard_Names
: constant Boolean :=
4523 Present
(No_Tagged_Streams_Pragma
(Typ
))
4524 and then (Global_Discard_Names
4525 or else Einfo
.Discard_Names
(Typ
));
4527 -- The following name entries are used by Make_DT to generate a number
4528 -- of entities related to a tagged type. These entities may be generated
4529 -- in a scope other than that of the tagged type declaration, and if
4530 -- the entities for two tagged types with the same name happen to be
4531 -- generated in the same scope, we have to take care to use different
4532 -- names. This is achieved by means of a unique serial number appended
4533 -- to each generated entity name.
4535 Name_DT
: constant Name_Id
:=
4536 New_External_Name
(Tname
, 'T', Suffix_Index
=> -1);
4537 Name_Exname
: constant Name_Id
:=
4538 New_External_Name
(Tname
, 'E', Suffix_Index
=> -1);
4539 Name_HT_Link
: constant Name_Id
:=
4540 New_External_Name
(Tname
, 'H', Suffix_Index
=> -1);
4541 Name_Predef_Prims
: constant Name_Id
:=
4542 New_External_Name
(Tname
, 'R', Suffix_Index
=> -1);
4543 Name_SSD
: constant Name_Id
:=
4544 New_External_Name
(Tname
, 'S', Suffix_Index
=> -1);
4545 Name_TSD
: constant Name_Id
:=
4546 New_External_Name
(Tname
, 'B', Suffix_Index
=> -1);
4548 Saved_GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
4549 Saved_IGR
: constant Node_Id
:= Ignored_Ghost_Region
;
4550 -- Save the Ghost-related attributes to restore on exit
4553 AI_Tag_Elmt
: Elmt_Id
;
4554 AI_Tag_Comp
: Elmt_Id
;
4556 DT_Aggr_List
: List_Id
;
4557 DT_Constr_List
: List_Id
;
4560 HT_Link
: Entity_Id
;
4563 Iface_Table_Node
: Node_Id
;
4564 Name_ITable
: Name_Id
;
4565 Nb_Predef_Prims
: Nat
:= 0;
4568 Num_Ifaces
: Nat
:= 0;
4569 Parent_Typ
: Entity_Id
;
4570 Predef_Prims
: Entity_Id
;
4572 Prim_Elmt
: Elmt_Id
;
4573 Prim_Ops_Aggr_List
: List_Id
;
4576 Typ_Comps
: Elist_Id
;
4577 Typ_Ifaces
: Elist_Id
;
4579 TSD_Aggr_List
: List_Id
;
4580 TSD_Tags_List
: List_Id
;
4582 -- Start of processing for Make_DT
4585 pragma Assert
(Is_Frozen
(Typ
));
4587 -- The tagged type being processed may be subject to pragma Ghost. Set
4588 -- the mode now to ensure that any nodes generated during dispatch table
4589 -- creation are properly marked as Ghost.
4591 Set_Ghost_Mode
(Typ
);
4593 -- Handle cases in which there is no need to build the dispatch table
4595 if Has_Dispatch_Table
(Typ
)
4596 or else No
(Access_Disp_Table
(Typ
))
4597 or else Is_CPP_Class
(Typ
)
4601 elsif No_Run_Time_Mode
then
4602 Error_Msg_CRT
("tagged types", Typ
);
4605 elsif not RTE_Available
(RE_Tag
) then
4607 Make_Object_Declaration
(Loc
,
4608 Defining_Identifier
=>
4609 Node
(First_Elmt
(Access_Disp_Table
(Typ
))),
4610 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
4611 Constant_Present
=> True,
4613 Unchecked_Convert_To
(RTE
(RE_Tag
),
4614 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
))));
4616 Analyze_List
(Result
, Suppress
=> All_Checks
);
4617 Error_Msg_CRT
("tagged types", Typ
);
4621 -- Ensure that the value of Max_Predef_Prims defined in a-tags is
4622 -- correct. Valid values are 9 under configurable runtime or 15
4623 -- with full runtime.
4625 if RTE_Available
(RE_Interface_Data
) then
4626 if Max_Predef_Prims
/= 15 then
4627 Error_Msg_N
("run-time library configuration error", Typ
);
4631 if Max_Predef_Prims
/= 9 then
4632 Error_Msg_N
("run-time library configuration error", Typ
);
4633 Error_Msg_CRT
("tagged types", Typ
);
4638 DT
:= Make_Defining_Identifier
(Loc
, Name_DT
);
4639 Exname
:= Make_Defining_Identifier
(Loc
, Name_Exname
);
4640 HT_Link
:= Make_Defining_Identifier
(Loc
, Name_HT_Link
);
4641 Predef_Prims
:= Make_Defining_Identifier
(Loc
, Name_Predef_Prims
);
4642 SSD
:= Make_Defining_Identifier
(Loc
, Name_SSD
);
4643 TSD
:= Make_Defining_Identifier
(Loc
, Name_TSD
);
4645 -- Initialize Parent_Typ handling private types
4647 Parent_Typ
:= Etype
(Typ
);
4649 if Present
(Full_View
(Parent_Typ
)) then
4650 Parent_Typ
:= Full_View
(Parent_Typ
);
4653 -- Ensure that all the primitives are frozen. This is only required when
4654 -- building static dispatch tables --- the primitives must be frozen to
4655 -- be referenced (otherwise we have problems with the backend). It is
4656 -- not a requirement with nonstatic dispatch tables because in this case
4657 -- we generate now an empty dispatch table; the extra code required to
4658 -- register the primitives in the slots will be generated later --- when
4659 -- each primitive is frozen (see Freeze_Subprogram).
4661 if Building_Static_DT
(Typ
) then
4663 Saved_FLLTT
: constant Boolean :=
4664 Freezing_Library_Level_Tagged_Type
;
4669 Prim_Elmt
: Elmt_Id
;
4672 Freezing_Library_Level_Tagged_Type
:= True;
4674 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
4675 while Present
(Prim_Elmt
) loop
4676 Prim
:= Node
(Prim_Elmt
);
4677 Frnodes
:= Freeze_Entity
(Prim
, Typ
);
4679 -- We disable this check for abstract subprograms, given that
4680 -- they cannot be called directly and thus the state of their
4681 -- untagged formals is of no concern. The RM is unclear in any
4682 -- case concerning the need for this check, and this topic may
4683 -- go back to the ARG.
4685 if not Is_Abstract_Subprogram
(Prim
) then
4686 Formal
:= First_Formal
(Prim
);
4687 while Present
(Formal
) loop
4688 Check_Premature_Freezing
(Prim
, Typ
, Etype
(Formal
));
4689 Next_Formal
(Formal
);
4692 Check_Premature_Freezing
(Prim
, Typ
, Etype
(Prim
));
4695 if Present
(Frnodes
) then
4696 Append_List_To
(Result
, Frnodes
);
4699 Next_Elmt
(Prim_Elmt
);
4702 Freezing_Library_Level_Tagged_Type
:= Saved_FLLTT
;
4706 if Building_Static_Secondary_DT
(Typ
) then
4708 Cannot_Have_Null_Disc
: Boolean := False;
4709 Name_Dummy_Object
: constant Name_Id
:=
4710 New_External_Name
(Tname
,
4711 'P', Suffix_Index
=> -1);
4713 Dummy_Object
:= Make_Defining_Identifier
(Loc
, Name_Dummy_Object
);
4715 -- Define the extra object imported and constant to avoid linker
4716 -- errors (since this object is never declared). Required because
4717 -- we implement RM 13.3(19) for exported and imported (variable)
4718 -- objects by making them volatile.
4720 Set_Is_Imported
(Dummy_Object
);
4721 Set_Ekind
(Dummy_Object
, E_Constant
);
4722 Set_Is_True_Constant
(Dummy_Object
);
4723 Set_Related_Type
(Dummy_Object
, Typ
);
4725 -- The scope must be set now to call Get_External_Name
4727 Set_Scope
(Dummy_Object
, Current_Scope
);
4729 Get_External_Name
(Dummy_Object
);
4730 Set_Interface_Name
(Dummy_Object
,
4731 Make_String_Literal
(Loc
, Strval
=> String_From_Name_Buffer
));
4733 -- Ensure proper Sprint output of this implicit importation
4735 Set_Is_Internal
(Dummy_Object
);
4737 if not Has_Discriminants
(Typ
) then
4739 Make_Object_Declaration
(Loc
,
4740 Defining_Identifier
=> Dummy_Object
,
4741 Constant_Present
=> True,
4742 Object_Definition
=> New_Occurrence_Of
(Typ
, Loc
)));
4745 Constr_List
: constant List_Id
:= New_List
;
4749 Discrim
:= First_Discriminant
(Typ
);
4750 while Present
(Discrim
) loop
4751 if Is_Discrete_Type
(Etype
(Discrim
)) then
4752 Append_To
(Constr_List
,
4753 Make_Attribute_Reference
(Loc
,
4755 New_Occurrence_Of
(Etype
(Discrim
), Loc
),
4756 Attribute_Name
=> Name_First
));
4759 pragma Assert
(Is_Access_Type
(Etype
(Discrim
)));
4760 Cannot_Have_Null_Disc
:=
4761 Cannot_Have_Null_Disc
4762 or else Can_Never_Be_Null
(Etype
(Discrim
));
4763 Append_To
(Constr_List
, Make_Null
(Loc
));
4766 Next_Discriminant
(Discrim
);
4770 Make_Object_Declaration
(Loc
,
4771 Defining_Identifier
=> Dummy_Object
,
4772 Constant_Present
=> True,
4773 Object_Definition
=>
4774 Make_Subtype_Indication
(Loc
,
4775 Subtype_Mark
=> New_Occurrence_Of
(Typ
, Loc
),
4777 Make_Index_Or_Discriminant_Constraint
(Loc
,
4778 Constraints
=> Constr_List
))));
4782 -- Given that the dummy object will not be declared at run time,
4783 -- analyze its declaration with expansion disabled and warnings
4784 -- and error messages ignored.
4786 Expander_Mode_Save_And_Set
(False);
4787 Ignore_Errors_Enable
:= Ignore_Errors_Enable
+ 1;
4788 Analyze
(Last
(Result
), Suppress
=> All_Checks
);
4789 Ignore_Errors_Enable
:= Ignore_Errors_Enable
- 1;
4790 Expander_Mode_Restore
;
4794 -- Ada 2005 (AI-251): Build the secondary dispatch tables
4796 if Has_Interfaces
(Typ
) then
4797 Collect_Interface_Components
(Typ
, Typ_Comps
);
4799 -- Each secondary dispatch table is assigned an unique positive
4800 -- suffix index; such value also corresponds with the location of
4801 -- its entity in the Dispatch_Table_Wrappers list (see Make_Tags).
4803 -- Note: This value must be kept sync with the Suffix_Index values
4804 -- generated by Make_Tags
4808 Next_Elmt
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(Typ
))));
4810 AI_Tag_Comp
:= First_Elmt
(Typ_Comps
);
4811 while Present
(AI_Tag_Comp
) loop
4812 pragma Assert
(Has_Suffix
(Node
(AI_Tag_Elmt
), 'P'));
4814 -- Build the secondary table containing pointers to thunks
4819 Base_Type
(Related_Type
(Node
(AI_Tag_Comp
))),
4820 Iface_Comp
=> Node
(AI_Tag_Comp
),
4821 Suffix_Index
=> Suffix_Index
,
4823 UI_To_Int
(DT_Entry_Count
(Node
(AI_Tag_Comp
))),
4824 Iface_DT_Ptr
=> Node
(AI_Tag_Elmt
),
4825 Predef_Prims_Ptr
=> Node
(Next_Elmt
(AI_Tag_Elmt
)),
4826 Build_Thunks
=> True,
4829 -- Skip secondary dispatch table referencing thunks to predefined
4832 Next_Elmt
(AI_Tag_Elmt
);
4833 pragma Assert
(Has_Suffix
(Node
(AI_Tag_Elmt
), 'Y'));
4835 -- Secondary dispatch table referencing user-defined primitives
4836 -- covered by this interface.
4838 Next_Elmt
(AI_Tag_Elmt
);
4839 pragma Assert
(Has_Suffix
(Node
(AI_Tag_Elmt
), 'D'));
4841 -- Build the secondary table containing pointers to primitives
4842 -- (used to give support to Generic Dispatching Constructors).
4847 (Related_Type
(Node
(AI_Tag_Comp
))),
4848 Iface_Comp
=> Node
(AI_Tag_Comp
),
4850 Num_Iface_Prims
=> UI_To_Int
4851 (DT_Entry_Count
(Node
(AI_Tag_Comp
))),
4852 Iface_DT_Ptr
=> Node
(AI_Tag_Elmt
),
4853 Predef_Prims_Ptr
=> Node
(Next_Elmt
(AI_Tag_Elmt
)),
4854 Build_Thunks
=> False,
4857 -- Skip secondary dispatch table referencing predefined primitives
4859 Next_Elmt
(AI_Tag_Elmt
);
4860 pragma Assert
(Has_Suffix
(Node
(AI_Tag_Elmt
), 'Z'));
4862 Suffix_Index
:= Suffix_Index
+ 1;
4863 Next_Elmt
(AI_Tag_Elmt
);
4864 Next_Elmt
(AI_Tag_Comp
);
4868 -- Get the _tag entity and number of primitives of its dispatch table
4870 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Typ
)));
4871 Nb_Prim
:= UI_To_Int
(DT_Entry_Count
(First_Tag_Component
(Typ
)));
4873 if Generate_SCIL
then
4877 Set_Is_Statically_Allocated
(DT
, Is_Library_Level_Tagged_Type
(Typ
));
4878 Set_Is_Statically_Allocated
(SSD
, Is_Library_Level_Tagged_Type
(Typ
));
4879 Set_Is_Statically_Allocated
(TSD
, Is_Library_Level_Tagged_Type
(Typ
));
4880 Set_Is_Statically_Allocated
(Predef_Prims
,
4881 Is_Library_Level_Tagged_Type
(Typ
));
4883 -- In case of locally defined tagged type we declare the object
4884 -- containing the dispatch table by means of a variable. Its
4885 -- initialization is done later by means of an assignment. This is
4886 -- required to generate its External_Tag.
4888 if not Building_Static_DT
(Typ
) then
4891 -- DT : No_Dispatch_Table_Wrapper;
4892 -- for DT'Alignment use Address'Alignment;
4893 -- DT_Ptr : Tag := !Tag (DT.NDT_Prims_Ptr'Address);
4895 if not Has_DT
(Typ
) then
4897 Make_Object_Declaration
(Loc
,
4898 Defining_Identifier
=> DT
,
4899 Aliased_Present
=> True,
4900 Constant_Present
=> False,
4901 Object_Definition
=>
4903 (RTE
(RE_No_Dispatch_Table_Wrapper
), Loc
)));
4906 Make_Attribute_Definition_Clause
(Loc
,
4907 Name
=> New_Occurrence_Of
(DT
, Loc
),
4908 Chars
=> Name_Alignment
,
4910 Make_Attribute_Reference
(Loc
,
4912 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
4913 Attribute_Name
=> Name_Alignment
)));
4916 Make_Object_Declaration
(Loc
,
4917 Defining_Identifier
=> DT_Ptr
,
4918 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
4919 Constant_Present
=> True,
4921 Unchecked_Convert_To
(RTE
(RE_Tag
),
4922 Make_Attribute_Reference
(Loc
,
4924 Make_Selected_Component
(Loc
,
4925 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
4928 (RTE_Record_Component
(RE_NDT_Prims_Ptr
), Loc
)),
4929 Attribute_Name
=> Name_Address
))));
4931 Set_Is_Statically_Allocated
(DT_Ptr
,
4932 Is_Library_Level_Tagged_Type
(Typ
));
4934 -- Generate the SCIL node for the previous object declaration
4935 -- because it has a tag initialization.
4937 if Generate_SCIL
then
4939 Make_SCIL_Dispatch_Table_Tag_Init
(Sloc
(Last
(Result
)));
4940 Set_SCIL_Entity
(New_Node
, Typ
);
4941 Set_SCIL_Node
(Last
(Result
), New_Node
);
4945 -- Gnat2scil has its own implementation of dispatch tables,
4946 -- different than what is being implemented here. Generating
4947 -- further dispatch table initialization code would just
4948 -- cause gnat2scil to generate useless Scil which CodePeer
4949 -- would waste time and space analyzing, so we skip it.
4953 -- DT : Dispatch_Table_Wrapper (Nb_Prim);
4954 -- for DT'Alignment use Address'Alignment;
4955 -- DT_Ptr : Tag := !Tag (DT.Prims_Ptr'Address);
4958 -- If the tagged type has no primitives we add a dummy slot
4959 -- whose address will be the tag of this type.
4963 New_List
(Make_Integer_Literal
(Loc
, 1));
4966 New_List
(Make_Integer_Literal
(Loc
, Nb_Prim
));
4970 Make_Object_Declaration
(Loc
,
4971 Defining_Identifier
=> DT
,
4972 Aliased_Present
=> True,
4973 Constant_Present
=> False,
4974 Object_Definition
=>
4975 Make_Subtype_Indication
(Loc
,
4977 New_Occurrence_Of
(RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
4979 Make_Index_Or_Discriminant_Constraint
(Loc
,
4980 Constraints
=> DT_Constr_List
))));
4983 Make_Attribute_Definition_Clause
(Loc
,
4984 Name
=> New_Occurrence_Of
(DT
, Loc
),
4985 Chars
=> Name_Alignment
,
4987 Make_Attribute_Reference
(Loc
,
4989 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
4990 Attribute_Name
=> Name_Alignment
)));
4993 Make_Object_Declaration
(Loc
,
4994 Defining_Identifier
=> DT_Ptr
,
4995 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
4996 Constant_Present
=> True,
4998 Unchecked_Convert_To
(RTE
(RE_Tag
),
4999 Make_Attribute_Reference
(Loc
,
5001 Make_Selected_Component
(Loc
,
5002 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
5005 (RTE_Record_Component
(RE_Prims_Ptr
), Loc
)),
5006 Attribute_Name
=> Name_Address
))));
5008 Set_Is_Statically_Allocated
(DT_Ptr
,
5009 Is_Library_Level_Tagged_Type
(Typ
));
5011 -- Generate the SCIL node for the previous object declaration
5012 -- because it has a tag initialization.
5014 if Generate_SCIL
then
5016 Make_SCIL_Dispatch_Table_Tag_Init
(Sloc
(Last
(Result
)));
5017 Set_SCIL_Entity
(New_Node
, Typ
);
5018 Set_SCIL_Node
(Last
(Result
), New_Node
);
5022 -- Gnat2scil has its own implementation of dispatch tables,
5023 -- different than what is being implemented here. Generating
5024 -- further dispatch table initialization code would just
5025 -- cause gnat2scil to generate useless Scil which CodePeer
5026 -- would waste time and space analyzing, so we skip it.
5030 Make_Object_Declaration
(Loc
,
5031 Defining_Identifier
=>
5032 Node
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(Typ
)))),
5033 Constant_Present
=> True,
5034 Object_Definition
=>
5035 New_Occurrence_Of
(RTE
(RE_Address
), Loc
),
5037 Make_Attribute_Reference
(Loc
,
5039 Make_Selected_Component
(Loc
,
5040 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
5043 (RTE_Record_Component
(RE_Predef_Prims
), Loc
)),
5044 Attribute_Name
=> Name_Address
)));
5048 -- Generate: Expanded_Name : constant String := "";
5050 if Discard_Names
then
5052 Make_Object_Declaration
(Loc
,
5053 Defining_Identifier
=> Exname
,
5054 Constant_Present
=> True,
5055 Object_Definition
=> New_Occurrence_Of
(Standard_String
, Loc
),
5057 Make_String_Literal
(Loc
, "")));
5059 -- Generate: Exname : constant String := full_qualified_name (typ);
5060 -- The type itself may be an anonymous parent type, so use the first
5061 -- subtype to have a user-recognizable name.
5065 Make_Object_Declaration
(Loc
,
5066 Defining_Identifier
=> Exname
,
5067 Constant_Present
=> True,
5068 Object_Definition
=> New_Occurrence_Of
(Standard_String
, Loc
),
5070 Make_String_Literal
(Loc
,
5071 Fully_Qualified_Name_String
(First_Subtype
(Typ
)))));
5074 Set_Is_Statically_Allocated
(Exname
);
5075 Set_Is_True_Constant
(Exname
);
5077 -- Declare the object used by Ada.Tags.Register_Tag
5079 if RTE_Available
(RE_Register_Tag
) then
5081 Make_Object_Declaration
(Loc
,
5082 Defining_Identifier
=> HT_Link
,
5083 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
5084 Expression
=> New_Occurrence_Of
(RTE
(RE_No_Tag
), Loc
)));
5087 -- Generate code to create the storage for the type specific data object
5088 -- with enough space to store the tags of the ancestors plus the tags
5089 -- of all the implemented interfaces (as described in a-tags.adb).
5091 -- TSD : Type_Specific_Data (I_Depth) :=
5092 -- (Idepth => I_Depth,
5093 -- Access_Level => Type_Access_Level (Typ),
5094 -- Alignment => Typ'Alignment,
5095 -- Expanded_Name => Cstring_Ptr!(Exname'Address))
5096 -- External_Tag => Cstring_Ptr!(Exname'Address))
5097 -- HT_Link => HT_Link'Address,
5098 -- Transportable => <<boolean-value>>,
5099 -- Is_Abstract => <<boolean-value>>,
5100 -- Needs_Finalization => <<boolean-value>>,
5101 -- [ Size_Func => Size_Prim'Access, ]
5102 -- [ Interfaces_Table => <<access-value>>, ]
5103 -- [ SSD => SSD_Table'Address ]
5104 -- Tags_Table => (0 => null,
5107 -- for TSD'Alignment use Address'Alignment
5109 TSD_Aggr_List
:= New_List
;
5111 -- Idepth: Count ancestors to compute the inheritance depth. For private
5112 -- extensions, always go to the full view in order to compute the real
5113 -- inheritance depth.
5116 Current_Typ
: Entity_Id
;
5117 Parent_Typ
: Entity_Id
;
5123 Parent_Typ
:= Etype
(Current_Typ
);
5125 if Is_Private_Type
(Parent_Typ
) then
5126 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
5129 exit when Parent_Typ
= Current_Typ
;
5131 I_Depth
:= I_Depth
+ 1;
5132 Current_Typ
:= Parent_Typ
;
5136 Append_To
(TSD_Aggr_List
,
5137 Make_Integer_Literal
(Loc
, I_Depth
));
5141 Append_To
(TSD_Aggr_List
,
5142 Make_Integer_Literal
(Loc
, Type_Access_Level
(Typ
)));
5146 -- For CPP types we cannot rely on the value of 'Alignment provided
5147 -- by the backend to initialize this TSD field.
5149 if Convention
(Typ
) = Convention_CPP
5150 or else Is_CPP_Class
(Root_Type
(Typ
))
5152 Append_To
(TSD_Aggr_List
,
5153 Make_Integer_Literal
(Loc
, 0));
5155 Append_To
(TSD_Aggr_List
,
5156 Make_Attribute_Reference
(Loc
,
5157 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
5158 Attribute_Name
=> Name_Alignment
));
5163 Append_To
(TSD_Aggr_List
,
5164 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
5165 Make_Attribute_Reference
(Loc
,
5166 Prefix
=> New_Occurrence_Of
(Exname
, Loc
),
5167 Attribute_Name
=> Name_Address
)));
5169 -- External_Tag of a local tagged type
5171 -- <typ>A : constant String :=
5172 -- "Internal tag at 16#tag-addr#: <full-name-of-typ>";
5174 -- The reason we generate this strange name is that we do not want to
5175 -- enter local tagged types in the global hash table used to compute
5176 -- the Internal_Tag attribute for two reasons:
5178 -- 1. It is hard to avoid a tasking race condition for entering the
5179 -- entry into the hash table.
5181 -- 2. It would cause a storage leak, unless we rig up considerable
5182 -- mechanism to remove the entry from the hash table on exit.
5184 -- So what we do is to generate the above external tag name, where the
5185 -- hex address is the address of the local dispatch table (i.e. exactly
5186 -- the value we want if Internal_Tag is computed from this string).
5188 -- Of course this value will only be valid if the tagged type is still
5189 -- in scope, but it clearly must be erroneous to compute the internal
5190 -- tag of a tagged type that is out of scope.
5192 -- We don't do this processing if an explicit external tag has been
5193 -- specified. That's an odd case for which we have already issued a
5194 -- warning, where we will not be able to compute the internal tag.
5196 if not Discard_Names
5197 and then not Is_Library_Level_Entity
(Typ
)
5198 and then not Has_External_Tag_Rep_Clause
(Typ
)
5201 Exname
: constant Entity_Id
:=
5202 Make_Defining_Identifier
(Loc
,
5203 Chars
=> New_External_Name
(Tname
, 'A'));
5204 Full_Name
: constant String_Id
:=
5205 Fully_Qualified_Name_String
(First_Subtype
(Typ
));
5206 Str1_Id
: String_Id
;
5207 Str2_Id
: String_Id
;
5211 -- Str1 = "Internal tag at 16#";
5214 Store_String_Chars
("Internal tag at 16#");
5215 Str1_Id
:= End_String
;
5218 -- Str2 = "#: <type-full-name>";
5221 Store_String_Chars
("#: ");
5222 Store_String_Chars
(Full_Name
);
5223 Str2_Id
:= End_String
;
5226 -- Exname : constant String :=
5227 -- Str1 & Address_Image (Tag) & Str2;
5229 if RTE_Available
(RE_Address_Image
) then
5231 Make_Object_Declaration
(Loc
,
5232 Defining_Identifier
=> Exname
,
5233 Constant_Present
=> True,
5234 Object_Definition
=> New_Occurrence_Of
5235 (Standard_String
, Loc
),
5237 Make_Op_Concat
(Loc
,
5238 Left_Opnd
=> Make_String_Literal
(Loc
, Str1_Id
),
5240 Make_Op_Concat
(Loc
,
5242 Make_Function_Call
(Loc
,
5245 (RTE
(RE_Address_Image
), Loc
),
5246 Parameter_Associations
=> New_List
(
5247 Unchecked_Convert_To
(RTE
(RE_Address
),
5248 New_Occurrence_Of
(DT_Ptr
, Loc
)))),
5250 Make_String_Literal
(Loc
, Str2_Id
)))));
5253 -- Exname : constant String := Str1 & Str2;
5257 Make_Object_Declaration
(Loc
,
5258 Defining_Identifier
=> Exname
,
5259 Constant_Present
=> True,
5260 Object_Definition
=>
5261 New_Occurrence_Of
(Standard_String
, Loc
),
5263 Make_Op_Concat
(Loc
,
5264 Left_Opnd
=> Make_String_Literal
(Loc
, Str1_Id
),
5265 Right_Opnd
=> Make_String_Literal
(Loc
, Str2_Id
))));
5269 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
5270 Make_Attribute_Reference
(Loc
,
5271 Prefix
=> New_Occurrence_Of
(Exname
, Loc
),
5272 Attribute_Name
=> Name_Address
));
5275 -- External tag of a library-level tagged type: Check for a definition
5276 -- of External_Tag. The clause is considered only if it applies to this
5277 -- specific tagged type, as opposed to one of its ancestors.
5278 -- If the type is an unconstrained type extension, we are building the
5279 -- dispatch table of its anonymous base type, so the external tag, if
5280 -- any was specified, must be retrieved from the first subtype. Go to
5281 -- the full view in case the clause is in the private part.
5285 Def
: constant Node_Id
:= Get_Attribute_Definition_Clause
5286 (Underlying_Type
(First_Subtype
(Typ
)),
5287 Attribute_External_Tag
);
5289 Old_Val
: String_Id
;
5290 New_Val
: String_Id
;
5294 if not Present
(Def
)
5295 or else Entity
(Name
(Def
)) /= First_Subtype
(Typ
)
5298 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
5299 Make_Attribute_Reference
(Loc
,
5300 Prefix
=> New_Occurrence_Of
(Exname
, Loc
),
5301 Attribute_Name
=> Name_Address
));
5303 Old_Val
:= Strval
(Expr_Value_S
(Expression
(Def
)));
5305 -- For the rep clause "for <typ>'external_tag use y" generate:
5307 -- <typ>A : constant string := y;
5309 -- <typ>A'Address is used to set the External_Tag component
5312 -- Create a new nul terminated string if it is not already
5314 if String_Length
(Old_Val
) > 0
5316 Get_String_Char
(Old_Val
, String_Length
(Old_Val
)) = 0
5320 Start_String
(Old_Val
);
5321 Store_String_Char
(Get_Char_Code
(ASCII
.NUL
));
5322 New_Val
:= End_String
;
5325 E
:= Make_Defining_Identifier
(Loc
,
5326 New_External_Name
(Chars
(Typ
), 'A'));
5329 Make_Object_Declaration
(Loc
,
5330 Defining_Identifier
=> E
,
5331 Constant_Present
=> True,
5332 Object_Definition
=>
5333 New_Occurrence_Of
(Standard_String
, Loc
),
5335 Make_String_Literal
(Loc
, New_Val
)));
5338 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
5339 Make_Attribute_Reference
(Loc
,
5340 Prefix
=> New_Occurrence_Of
(E
, Loc
),
5341 Attribute_Name
=> Name_Address
));
5346 Append_To
(TSD_Aggr_List
, New_Node
);
5350 if RTE_Available
(RE_Register_Tag
) then
5351 Append_To
(TSD_Aggr_List
,
5352 Unchecked_Convert_To
(RTE
(RE_Tag_Ptr
),
5353 Make_Attribute_Reference
(Loc
,
5354 Prefix
=> New_Occurrence_Of
(HT_Link
, Loc
),
5355 Attribute_Name
=> Name_Address
)));
5357 elsif RTE_Record_Component_Available
(RE_HT_Link
) then
5358 Append_To
(TSD_Aggr_List
,
5359 Unchecked_Convert_To
(RTE
(RE_Tag_Ptr
),
5360 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
)));
5363 -- Transportable: Set for types that can be used in remote calls
5364 -- with respect to E.4(18) legality rules.
5367 Transportable
: Entity_Id
;
5373 or else Is_Shared_Passive
(Typ
)
5375 ((Is_Remote_Types
(Typ
)
5376 or else Is_Remote_Call_Interface
(Typ
))
5377 and then Original_View_In_Visible_Part
(Typ
))
5378 or else not Comes_From_Source
(Typ
));
5380 Append_To
(TSD_Aggr_List
,
5381 New_Occurrence_Of
(Transportable
, Loc
));
5384 -- Is_Abstract (Ada 2012: AI05-0173). This functionality is not
5385 -- available in the HIE runtime.
5387 if RTE_Record_Component_Available
(RE_Is_Abstract
) then
5389 Is_Abstract
: Entity_Id
;
5391 Is_Abstract
:= Boolean_Literals
(Is_Abstract_Type
(Typ
));
5392 Append_To
(TSD_Aggr_List
,
5393 New_Occurrence_Of
(Is_Abstract
, Loc
));
5397 -- Needs_Finalization: Set if the type is controlled or has controlled
5401 Needs_Fin
: Entity_Id
;
5403 Needs_Fin
:= Boolean_Literals
(Needs_Finalization
(Typ
));
5404 Append_To
(TSD_Aggr_List
, New_Occurrence_Of
(Needs_Fin
, Loc
));
5409 if RTE_Record_Component_Available
(RE_Size_Func
) then
5411 -- Initialize this field to Null_Address if we are not building
5412 -- static dispatch tables static or if the size function is not
5413 -- available. In the former case we cannot initialize this field
5414 -- until the function is frozen and registered in the dispatch
5415 -- table (see Register_Primitive).
5417 if not Building_Static_DT
(Typ
) or else not Has_DT
(Typ
) then
5418 Append_To
(TSD_Aggr_List
,
5419 Unchecked_Convert_To
(RTE
(RE_Size_Ptr
),
5420 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
)));
5424 Prim_Elmt
: Elmt_Id
;
5426 Size_Comp
: Node_Id
:= Empty
;
5429 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5430 while Present
(Prim_Elmt
) loop
5431 Prim
:= Node
(Prim_Elmt
);
5433 if Chars
(Prim
) = Name_uSize
then
5434 Prim
:= Ultimate_Alias
(Prim
);
5436 if Is_Abstract_Subprogram
(Prim
) then
5438 Unchecked_Convert_To
(RTE
(RE_Size_Ptr
),
5439 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
));
5442 Unchecked_Convert_To
(RTE
(RE_Size_Ptr
),
5443 Make_Attribute_Reference
(Loc
,
5444 Prefix
=> New_Occurrence_Of
(Prim
, Loc
),
5445 Attribute_Name
=> Name_Unrestricted_Access
));
5451 Next_Elmt
(Prim_Elmt
);
5454 pragma Assert
(Present
(Size_Comp
));
5455 Append_To
(TSD_Aggr_List
, Size_Comp
);
5460 -- Interfaces_Table (required for AI-405)
5462 if RTE_Record_Component_Available
(RE_Interfaces_Table
) then
5464 -- Count the number of interface types implemented by Typ
5466 Collect_Interfaces
(Typ
, Typ_Ifaces
);
5468 AI
:= First_Elmt
(Typ_Ifaces
);
5469 while Present
(AI
) loop
5470 Num_Ifaces
:= Num_Ifaces
+ 1;
5474 if Num_Ifaces
= 0 then
5475 Iface_Table_Node
:= Make_Null
(Loc
);
5477 -- Generate the Interface_Table object
5481 TSD_Ifaces_List
: constant List_Id
:= New_List
;
5483 Ifaces_List
: Elist_Id
:= No_Elist
;
5484 Ifaces_Comp_List
: Elist_Id
:= No_Elist
;
5485 Ifaces_Tag_List
: Elist_Id
;
5486 Offset_To_Top
: Node_Id
;
5487 Sec_DT_Tag
: Node_Id
;
5490 -- Collect interfaces information if we need to compute the
5491 -- offset to the top using the dummy object.
5493 if Present
(Dummy_Object
) then
5494 Collect_Interfaces_Info
(Typ
,
5495 Ifaces_List
, Ifaces_Comp_List
, Ifaces_Tag_List
);
5498 AI
:= First_Elmt
(Typ_Ifaces
);
5499 while Present
(AI
) loop
5500 if Is_Ancestor
(Node
(AI
), Typ
, Use_Full_View
=> True) then
5501 Sec_DT_Tag
:= New_Occurrence_Of
(DT_Ptr
, Loc
);
5506 (Next_Elmt
(First_Elmt
(Access_Disp_Table
(Typ
))));
5507 pragma Assert
(Has_Thunks
(Node
(Elmt
)));
5509 while Is_Tag
(Node
(Elmt
))
5511 Is_Ancestor
(Node
(AI
), Related_Type
(Node
(Elmt
)),
5512 Use_Full_View
=> True)
5514 pragma Assert
(Has_Thunks
(Node
(Elmt
)));
5516 pragma Assert
(Has_Thunks
(Node
(Elmt
)));
5518 pragma Assert
(not Has_Thunks
(Node
(Elmt
)));
5520 pragma Assert
(not Has_Thunks
(Node
(Elmt
)));
5524 pragma Assert
(Ekind
(Node
(Elmt
)) = E_Constant
5526 Has_Thunks
(Node
(Next_Elmt
(Next_Elmt
(Elmt
)))));
5530 (Node
(Next_Elmt
(Next_Elmt
(Elmt
))), Loc
);
5533 -- For static dispatch tables compute Offset_To_Top using
5534 -- the dummy object.
5536 if Present
(Dummy_Object
) then
5538 Iface
: constant Node_Id
:= Node
(AI
);
5539 Iface_Comp
: Node_Id
:= Empty
;
5540 Iface_Comp_Elmt
: Elmt_Id
;
5541 Iface_Elmt
: Elmt_Id
;
5544 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
5545 Iface_Comp_Elmt
:= First_Elmt
(Ifaces_Comp_List
);
5547 while Present
(Iface_Elmt
) loop
5548 if Node
(Iface_Elmt
) = Iface
then
5549 Iface_Comp
:= Node
(Iface_Comp_Elmt
);
5553 Next_Elmt
(Iface_Elmt
);
5554 Next_Elmt
(Iface_Comp_Elmt
);
5557 pragma Assert
(Present
(Iface_Comp
));
5561 Make_Attribute_Reference
(Loc
,
5563 Make_Selected_Component
(Loc
,
5565 New_Occurrence_Of
(Dummy_Object
, Loc
),
5567 New_Occurrence_Of
(Iface_Comp
, Loc
)),
5568 Attribute_Name
=> Name_Position
));
5571 Offset_To_Top
:= Make_Integer_Literal
(Loc
, 0);
5574 Append_To
(TSD_Ifaces_List
,
5575 Make_Aggregate
(Loc
,
5576 Expressions
=> New_List
(
5580 Unchecked_Convert_To
(RTE
(RE_Tag
),
5582 (Node
(First_Elmt
(Access_Disp_Table
(Node
(AI
)))),
5585 -- Static_Offset_To_Top
5587 New_Occurrence_Of
(Standard_True
, Loc
),
5589 -- Offset_To_Top_Value
5593 -- Offset_To_Top_Func
5599 Unchecked_Convert_To
(RTE
(RE_Tag
), Sec_DT_Tag
))));
5604 Name_ITable
:= New_External_Name
(Tname
, 'I');
5605 ITable
:= Make_Defining_Identifier
(Loc
, Name_ITable
);
5606 Set_Is_Statically_Allocated
(ITable
,
5607 Is_Library_Level_Tagged_Type
(Typ
));
5609 -- The table of interfaces is constant if we are building a
5610 -- static dispatch table; otherwise is not constant because
5611 -- its slots are filled at run time by the IP routine.
5614 Make_Object_Declaration
(Loc
,
5615 Defining_Identifier
=> ITable
,
5616 Aliased_Present
=> True,
5617 Constant_Present
=> Present
(Dummy_Object
),
5618 Object_Definition
=>
5619 Make_Subtype_Indication
(Loc
,
5621 New_Occurrence_Of
(RTE
(RE_Interface_Data
), Loc
),
5623 Make_Index_Or_Discriminant_Constraint
(Loc
,
5624 Constraints
=> New_List
(
5625 Make_Integer_Literal
(Loc
, Num_Ifaces
)))),
5628 Make_Aggregate
(Loc
,
5629 Expressions
=> New_List
(
5630 Make_Integer_Literal
(Loc
, Num_Ifaces
),
5631 Make_Aggregate
(Loc
, TSD_Ifaces_List
)))));
5634 Make_Attribute_Definition_Clause
(Loc
,
5635 Name
=> New_Occurrence_Of
(ITable
, Loc
),
5636 Chars
=> Name_Alignment
,
5638 Make_Attribute_Reference
(Loc
,
5640 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
5641 Attribute_Name
=> Name_Alignment
)));
5644 Make_Attribute_Reference
(Loc
,
5645 Prefix
=> New_Occurrence_Of
(ITable
, Loc
),
5646 Attribute_Name
=> Name_Unchecked_Access
);
5650 Append_To
(TSD_Aggr_List
, Iface_Table_Node
);
5653 -- Generate the Select Specific Data table for synchronized types that
5654 -- implement synchronized interfaces. The size of the table is
5655 -- constrained by the number of non-predefined primitive operations.
5657 if RTE_Record_Component_Available
(RE_SSD
) then
5658 if Ada_Version
>= Ada_2005
5659 and then Has_DT
(Typ
)
5660 and then Is_Concurrent_Record_Type
(Typ
)
5661 and then Has_Interfaces
(Typ
)
5662 and then Nb_Prim
> 0
5663 and then not Is_Abstract_Type
(Typ
)
5664 and then not Is_Controlled
(Typ
)
5665 and then not Restriction_Active
(No_Dispatching_Calls
)
5666 and then not Restriction_Active
(No_Select_Statements
)
5669 Make_Object_Declaration
(Loc
,
5670 Defining_Identifier
=> SSD
,
5671 Aliased_Present
=> True,
5672 Object_Definition
=>
5673 Make_Subtype_Indication
(Loc
,
5674 Subtype_Mark
=> New_Occurrence_Of
(
5675 RTE
(RE_Select_Specific_Data
), Loc
),
5677 Make_Index_Or_Discriminant_Constraint
(Loc
,
5678 Constraints
=> New_List
(
5679 Make_Integer_Literal
(Loc
, Nb_Prim
))))));
5682 Make_Attribute_Definition_Clause
(Loc
,
5683 Name
=> New_Occurrence_Of
(SSD
, Loc
),
5684 Chars
=> Name_Alignment
,
5686 Make_Attribute_Reference
(Loc
,
5688 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
5689 Attribute_Name
=> Name_Alignment
)));
5691 -- This table is initialized by Make_Select_Specific_Data_Table,
5692 -- which calls Set_Entry_Index and Set_Prim_Op_Kind.
5694 Append_To
(TSD_Aggr_List
,
5695 Make_Attribute_Reference
(Loc
,
5696 Prefix
=> New_Occurrence_Of
(SSD
, Loc
),
5697 Attribute_Name
=> Name_Unchecked_Access
));
5699 Append_To
(TSD_Aggr_List
, Make_Null
(Loc
));
5703 -- Initialize the table of ancestor tags. In case of interface types
5704 -- this table is not needed.
5706 TSD_Tags_List
:= New_List
;
5708 -- If we are not statically allocating the dispatch table then we must
5709 -- fill position 0 with null because we still have not generated the
5712 if not Building_Static_DT
(Typ
)
5713 or else Is_Interface
(Typ
)
5715 Append_To
(TSD_Tags_List
,
5716 Unchecked_Convert_To
(RTE
(RE_Tag
),
5717 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
)));
5719 -- Otherwise we can safely reference the tag
5722 Append_To
(TSD_Tags_List
,
5723 New_Occurrence_Of
(DT_Ptr
, Loc
));
5726 -- Fill the rest of the table with the tags of the ancestors
5729 Current_Typ
: Entity_Id
;
5730 Parent_Typ
: Entity_Id
;
5738 Parent_Typ
:= Etype
(Current_Typ
);
5740 if Is_Private_Type
(Parent_Typ
) then
5741 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
5744 exit when Parent_Typ
= Current_Typ
;
5746 if Is_CPP_Class
(Parent_Typ
) then
5748 -- The tags defined in the C++ side will be inherited when
5749 -- the object is constructed (Exp_Ch3.Build_Init_Procedure)
5751 Append_To
(TSD_Tags_List
,
5752 Unchecked_Convert_To
(RTE
(RE_Tag
),
5753 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
)));
5755 Append_To
(TSD_Tags_List
,
5757 (Node
(First_Elmt
(Access_Disp_Table
(Parent_Typ
))),
5762 Current_Typ
:= Parent_Typ
;
5765 pragma Assert
(Pos
= I_Depth
+ 1);
5768 Append_To
(TSD_Aggr_List
,
5769 Make_Aggregate
(Loc
,
5770 Expressions
=> TSD_Tags_List
));
5772 -- Build the TSD object
5775 Make_Object_Declaration
(Loc
,
5776 Defining_Identifier
=> TSD
,
5777 Aliased_Present
=> True,
5778 Constant_Present
=> Building_Static_DT
(Typ
),
5779 Object_Definition
=>
5780 Make_Subtype_Indication
(Loc
,
5781 Subtype_Mark
=> New_Occurrence_Of
(
5782 RTE
(RE_Type_Specific_Data
), Loc
),
5784 Make_Index_Or_Discriminant_Constraint
(Loc
,
5785 Constraints
=> New_List
(
5786 Make_Integer_Literal
(Loc
, I_Depth
)))),
5788 Expression
=> Make_Aggregate
(Loc
,
5789 Expressions
=> TSD_Aggr_List
)));
5791 Set_Is_True_Constant
(TSD
, Building_Static_DT
(Typ
));
5794 Make_Attribute_Definition_Clause
(Loc
,
5795 Name
=> New_Occurrence_Of
(TSD
, Loc
),
5796 Chars
=> Name_Alignment
,
5798 Make_Attribute_Reference
(Loc
,
5800 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
5801 Attribute_Name
=> Name_Alignment
)));
5803 -- Initialize or declare the dispatch table object
5805 if not Has_DT
(Typ
) then
5806 DT_Constr_List
:= New_List
;
5807 DT_Aggr_List
:= New_List
;
5812 Make_Attribute_Reference
(Loc
,
5813 Prefix
=> New_Occurrence_Of
(TSD
, Loc
),
5814 Attribute_Name
=> Name_Address
);
5816 Append_To
(DT_Constr_List
, New_Node
);
5817 Append_To
(DT_Aggr_List
, New_Copy
(New_Node
));
5818 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, 0));
5820 -- In case of locally defined tagged types we have already declared
5821 -- and uninitialized object for the dispatch table, which is now
5822 -- initialized by means of the following assignment:
5824 -- DT := (TSD'Address, 0);
5826 if not Building_Static_DT
(Typ
) then
5828 Make_Assignment_Statement
(Loc
,
5829 Name
=> New_Occurrence_Of
(DT
, Loc
),
5830 Expression
=> Make_Aggregate
(Loc
, DT_Aggr_List
)));
5832 -- In case of library level tagged types we declare and export now
5833 -- the constant object containing the dummy dispatch table. There
5834 -- is no need to declare the tag here because it has been previously
5835 -- declared by Make_Tags
5837 -- DT : aliased constant No_Dispatch_Table :=
5838 -- (NDT_TSD => TSD'Address;
5839 -- NDT_Prims_Ptr => 0);
5840 -- for DT'Alignment use Address'Alignment;
5844 Make_Object_Declaration
(Loc
,
5845 Defining_Identifier
=> DT
,
5846 Aliased_Present
=> True,
5847 Constant_Present
=> True,
5848 Object_Definition
=>
5849 New_Occurrence_Of
(RTE
(RE_No_Dispatch_Table_Wrapper
), Loc
),
5850 Expression
=> Make_Aggregate
(Loc
, DT_Aggr_List
)));
5853 Make_Attribute_Definition_Clause
(Loc
,
5854 Name
=> New_Occurrence_Of
(DT
, Loc
),
5855 Chars
=> Name_Alignment
,
5857 Make_Attribute_Reference
(Loc
,
5859 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
5860 Attribute_Name
=> Name_Alignment
)));
5862 Export_DT
(Typ
, DT
);
5865 -- Common case: Typ has a dispatch table
5869 -- Predef_Prims : Address_Array (1 .. Default_Prim_Ops_Count) :=
5870 -- (predef-prim-op-1'address,
5871 -- predef-prim-op-2'address,
5873 -- predef-prim-op-n'address);
5874 -- for Predef_Prims'Alignment use Address'Alignment
5876 -- DT : Dispatch_Table (Nb_Prims) :=
5877 -- (Signature => <sig-value>,
5878 -- Tag_Kind => <tag_kind-value>,
5879 -- Predef_Prims => Predef_Prims'First'Address,
5880 -- Offset_To_Top => 0,
5881 -- TSD => TSD'Address;
5882 -- Prims_Ptr => (prim-op-1'address,
5883 -- prim-op-2'address,
5885 -- prim-op-n'address));
5886 -- for DT'Alignment use Address'Alignment
5893 if not Building_Static_DT
(Typ
) then
5894 Nb_Predef_Prims
:= Max_Predef_Prims
;
5897 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5898 while Present
(Prim_Elmt
) loop
5899 Prim
:= Node
(Prim_Elmt
);
5901 if Is_Predefined_Dispatching_Operation
(Prim
)
5902 and then not Is_Abstract_Subprogram
(Prim
)
5904 Pos
:= UI_To_Int
(DT_Position
(Prim
));
5906 if Pos
> Nb_Predef_Prims
then
5907 Nb_Predef_Prims
:= Pos
;
5911 Next_Elmt
(Prim_Elmt
);
5917 (Nat
range 1 .. Nb_Predef_Prims
) of Entity_Id
;
5922 Prim_Ops_Aggr_List
:= New_List
;
5924 Prim_Table
:= (others => Empty
);
5926 if Building_Static_DT
(Typ
) then
5927 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5928 while Present
(Prim_Elmt
) loop
5929 Prim
:= Node
(Prim_Elmt
);
5931 if Is_Predefined_Dispatching_Operation
(Prim
)
5932 and then not Is_Abstract_Subprogram
(Prim
)
5933 and then not Is_Eliminated
(Prim
)
5934 and then not Present
(Prim_Table
5935 (UI_To_Int
(DT_Position
(Prim
))))
5937 E
:= Ultimate_Alias
(Prim
);
5938 pragma Assert
(not Is_Abstract_Subprogram
(E
));
5939 Prim_Table
(UI_To_Int
(DT_Position
(Prim
))) := E
;
5942 Next_Elmt
(Prim_Elmt
);
5946 for J
in Prim_Table
'Range loop
5947 if Present
(Prim_Table
(J
)) then
5949 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
5950 Make_Attribute_Reference
(Loc
,
5952 New_Occurrence_Of
(Prim_Table
(J
), Loc
),
5953 Attribute_Name
=> Name_Unrestricted_Access
));
5955 New_Node
:= Make_Null
(Loc
);
5958 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
5962 Make_Aggregate
(Loc
,
5963 Expressions
=> Prim_Ops_Aggr_List
);
5966 Make_Subtype_Declaration
(Loc
,
5967 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
5968 Subtype_Indication
=>
5969 New_Occurrence_Of
(RTE
(RE_Address_Array
), Loc
));
5971 Append_To
(Result
, Decl
);
5974 Make_Object_Declaration
(Loc
,
5975 Defining_Identifier
=> Predef_Prims
,
5976 Aliased_Present
=> True,
5977 Constant_Present
=> Building_Static_DT
(Typ
),
5978 Object_Definition
=>
5979 New_Occurrence_Of
(Defining_Identifier
(Decl
), Loc
),
5980 Expression
=> New_Node
));
5982 -- Remember aggregates initializing dispatch tables
5984 Append_Elmt
(New_Node
, DT_Aggr
);
5987 Make_Attribute_Definition_Clause
(Loc
,
5988 Name
=> New_Occurrence_Of
(Predef_Prims
, Loc
),
5989 Chars
=> Name_Alignment
,
5991 Make_Attribute_Reference
(Loc
,
5993 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
5994 Attribute_Name
=> Name_Alignment
)));
5998 -- Stage 1: Initialize the discriminant and the record components
6000 DT_Constr_List
:= New_List
;
6001 DT_Aggr_List
:= New_List
;
6003 -- Num_Prims. If the tagged type has no primitives we add a dummy
6004 -- slot whose address will be the tag of this type.
6007 New_Node
:= Make_Integer_Literal
(Loc
, 1);
6009 New_Node
:= Make_Integer_Literal
(Loc
, Nb_Prim
);
6012 Append_To
(DT_Constr_List
, New_Node
);
6013 Append_To
(DT_Aggr_List
, New_Copy
(New_Node
));
6017 if RTE_Record_Component_Available
(RE_Signature
) then
6018 Append_To
(DT_Aggr_List
,
6019 New_Occurrence_Of
(RTE
(RE_Primary_DT
), Loc
));
6024 if RTE_Record_Component_Available
(RE_Tag_Kind
) then
6025 Append_To
(DT_Aggr_List
, Tagged_Kind
(Typ
));
6030 Append_To
(DT_Aggr_List
,
6031 Make_Attribute_Reference
(Loc
,
6032 Prefix
=> New_Occurrence_Of
(Predef_Prims
, Loc
),
6033 Attribute_Name
=> Name_Address
));
6037 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, 0));
6041 Append_To
(DT_Aggr_List
,
6042 Make_Attribute_Reference
(Loc
,
6043 Prefix
=> New_Occurrence_Of
(TSD
, Loc
),
6044 Attribute_Name
=> Name_Address
));
6046 -- Stage 2: Initialize the table of user-defined primitive operations
6048 Prim_Ops_Aggr_List
:= New_List
;
6051 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
6053 elsif not Building_Static_DT
(Typ
) then
6054 for J
in 1 .. Nb_Prim
loop
6055 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
6060 CPP_Nb_Prims
: constant Nat
:= CPP_Num_Prims
(Typ
);
6063 Prim_Elmt
: Elmt_Id
;
6065 Prim_Table
: array (Nat
range 1 .. Nb_Prim
) of Entity_Id
;
6068 Prim_Table
:= (others => Empty
);
6070 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
6071 while Present
(Prim_Elmt
) loop
6072 Prim
:= Node
(Prim_Elmt
);
6074 -- Retrieve the ultimate alias of the primitive for proper
6075 -- handling of renamings and eliminated primitives.
6077 E
:= Ultimate_Alias
(Prim
);
6079 -- If the alias is not a primitive operation then Prim does
6080 -- not rename another primitive, but rather an operation
6081 -- declared elsewhere (e.g. in another scope) and therefore
6082 -- Prim is a new primitive.
6084 if No
(Find_Dispatching_Type
(E
)) then
6088 Prim_Pos
:= UI_To_Int
(DT_Position
(E
));
6090 -- Skip predefined primitives because they are located in a
6091 -- separate dispatch table.
6093 if not Is_Predefined_Dispatching_Operation
(Prim
)
6094 and then not Is_Predefined_Dispatching_Operation
(E
)
6096 -- Skip entities with attribute Interface_Alias because
6097 -- those are only required to build secondary dispatch
6100 and then not Present
(Interface_Alias
(Prim
))
6102 -- Skip abstract and eliminated primitives
6104 and then not Is_Abstract_Subprogram
(E
)
6105 and then not Is_Eliminated
(E
)
6107 -- For derivations of CPP types skip primitives located in
6108 -- the C++ part of the dispatch table because their slots
6109 -- are initialized by the IC routine.
6111 and then (not Is_CPP_Class
(Root_Type
(Typ
))
6112 or else Prim_Pos
> CPP_Nb_Prims
)
6114 -- Skip ignored Ghost subprograms as those will be removed
6115 -- from the executable.
6117 and then not Is_Ignored_Ghost_Entity
(E
)
6120 (UI_To_Int
(DT_Position
(Prim
)) <= Nb_Prim
);
6122 Prim_Table
(UI_To_Int
(DT_Position
(Prim
))) := E
;
6125 Next_Elmt
(Prim_Elmt
);
6128 for J
in Prim_Table
'Range loop
6129 if Present
(Prim_Table
(J
)) then
6131 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
6132 Make_Attribute_Reference
(Loc
,
6134 New_Occurrence_Of
(Prim_Table
(J
), Loc
),
6135 Attribute_Name
=> Name_Unrestricted_Access
));
6137 New_Node
:= Make_Null
(Loc
);
6140 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
6146 Make_Aggregate
(Loc
,
6147 Expressions
=> Prim_Ops_Aggr_List
);
6149 Append_To
(DT_Aggr_List
, New_Node
);
6151 -- Remember aggregates initializing dispatch tables
6153 Append_Elmt
(New_Node
, DT_Aggr
);
6155 -- In case of locally defined tagged types we have already declared
6156 -- and uninitialized object for the dispatch table, which is now
6157 -- initialized by means of an assignment.
6159 if not Building_Static_DT
(Typ
) then
6161 Make_Assignment_Statement
(Loc
,
6162 Name
=> New_Occurrence_Of
(DT
, Loc
),
6163 Expression
=> Make_Aggregate
(Loc
, DT_Aggr_List
)));
6165 -- In case of library level tagged types we declare now and export
6166 -- the constant object containing the dispatch table.
6170 Make_Object_Declaration
(Loc
,
6171 Defining_Identifier
=> DT
,
6172 Aliased_Present
=> True,
6173 Constant_Present
=> True,
6174 Object_Definition
=>
6175 Make_Subtype_Indication
(Loc
,
6176 Subtype_Mark
=> New_Occurrence_Of
6177 (RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
6178 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
,
6179 Constraints
=> DT_Constr_List
)),
6180 Expression
=> Make_Aggregate
(Loc
, DT_Aggr_List
)));
6183 Make_Attribute_Definition_Clause
(Loc
,
6184 Name
=> New_Occurrence_Of
(DT
, Loc
),
6185 Chars
=> Name_Alignment
,
6187 Make_Attribute_Reference
(Loc
,
6189 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
6190 Attribute_Name
=> Name_Alignment
)));
6192 Export_DT
(Typ
, DT
);
6196 -- Initialize the table of ancestor tags if not building static
6199 if not Building_Static_DT
(Typ
)
6200 and then not Is_Interface
(Typ
)
6201 and then not Is_CPP_Class
(Typ
)
6204 Make_Assignment_Statement
(Loc
,
6206 Make_Indexed_Component
(Loc
,
6208 Make_Selected_Component
(Loc
,
6209 Prefix
=> New_Occurrence_Of
(TSD
, Loc
),
6212 (RTE_Record_Component
(RE_Tags_Table
), Loc
)),
6214 New_List
(Make_Integer_Literal
(Loc
, 0))),
6218 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
)));
6221 -- Inherit the dispatch tables of the parent. There is no need to
6222 -- inherit anything from the parent when building static dispatch tables
6223 -- because the whole dispatch table (including inherited primitives) has
6224 -- been already built.
6226 if Building_Static_DT
(Typ
) then
6229 -- If the ancestor is a CPP_Class type we inherit the dispatch tables
6230 -- in the init proc, and we don't need to fill them in here.
6232 elsif Is_CPP_Class
(Parent_Typ
) then
6235 -- Otherwise we fill in the dispatch tables here
6238 if Typ
/= Parent_Typ
6239 and then not Is_Interface
(Typ
)
6240 and then not Restriction_Active
(No_Dispatching_Calls
)
6242 -- Inherit the dispatch table
6244 if not Is_Interface
(Typ
)
6245 and then not Is_Interface
(Parent_Typ
)
6246 and then not Is_CPP_Class
(Parent_Typ
)
6249 Nb_Prims
: constant Int
:=
6250 UI_To_Int
(DT_Entry_Count
6251 (First_Tag_Component
(Parent_Typ
)));
6254 Append_To
(Elab_Code
,
6255 Build_Inherit_Predefined_Prims
(Loc
,
6261 (Access_Disp_Table
(Parent_Typ
)))), Loc
),
6267 (Access_Disp_Table
(Typ
)))), Loc
)));
6269 if Nb_Prims
/= 0 then
6270 Append_To
(Elab_Code
,
6271 Build_Inherit_Prims
(Loc
,
6277 (Access_Disp_Table
(Parent_Typ
))), Loc
),
6278 New_Tag_Node
=> New_Occurrence_Of
(DT_Ptr
, Loc
),
6279 Num_Prims
=> Nb_Prims
));
6284 -- Inherit the secondary dispatch tables of the ancestor
6286 if not Is_CPP_Class
(Parent_Typ
) then
6288 Sec_DT_Ancestor
: Elmt_Id
:=
6294 Sec_DT_Typ
: Elmt_Id
:=
6298 (Access_Disp_Table
(Typ
))));
6300 procedure Copy_Secondary_DTs
(Typ
: Entity_Id
);
6301 -- Local procedure required to climb through the ancestors
6302 -- and copy the contents of all their secondary dispatch
6305 ------------------------
6306 -- Copy_Secondary_DTs --
6307 ------------------------
6309 procedure Copy_Secondary_DTs
(Typ
: Entity_Id
) is
6314 -- Climb to the ancestor (if any) handling private types
6316 if Present
(Full_View
(Etype
(Typ
))) then
6317 if Full_View
(Etype
(Typ
)) /= Typ
then
6318 Copy_Secondary_DTs
(Full_View
(Etype
(Typ
)));
6321 elsif Etype
(Typ
) /= Typ
then
6322 Copy_Secondary_DTs
(Etype
(Typ
));
6325 if Present
(Interfaces
(Typ
))
6326 and then not Is_Empty_Elmt_List
(Interfaces
(Typ
))
6328 Iface
:= First_Elmt
(Interfaces
(Typ
));
6329 E
:= First_Entity
(Typ
);
6331 and then Present
(Node
(Sec_DT_Ancestor
))
6332 and then Ekind
(Node
(Sec_DT_Ancestor
)) = E_Constant
6334 if Is_Tag
(E
) and then Chars
(E
) /= Name_uTag
then
6336 Num_Prims
: constant Int
:=
6337 UI_To_Int
(DT_Entry_Count
(E
));
6340 if not Is_Interface
(Etype
(Typ
)) then
6342 -- Inherit first secondary dispatch table
6344 Append_To
(Elab_Code
,
6345 Build_Inherit_Predefined_Prims
(Loc
,
6347 Unchecked_Convert_To
(RTE
(RE_Tag
),
6350 (Next_Elmt
(Sec_DT_Ancestor
)),
6353 Unchecked_Convert_To
(RTE
(RE_Tag
),
6355 (Node
(Next_Elmt
(Sec_DT_Typ
)),
6358 if Num_Prims
/= 0 then
6359 Append_To
(Elab_Code
,
6360 Build_Inherit_Prims
(Loc
,
6361 Typ
=> Node
(Iface
),
6363 Unchecked_Convert_To
6366 (Node
(Sec_DT_Ancestor
),
6369 Unchecked_Convert_To
6372 (Node
(Sec_DT_Typ
), Loc
)),
6373 Num_Prims
=> Num_Prims
));
6377 Next_Elmt
(Sec_DT_Ancestor
);
6378 Next_Elmt
(Sec_DT_Typ
);
6380 -- Skip the secondary dispatch table of
6381 -- predefined primitives
6383 Next_Elmt
(Sec_DT_Ancestor
);
6384 Next_Elmt
(Sec_DT_Typ
);
6386 if not Is_Interface
(Etype
(Typ
)) then
6388 -- Inherit second secondary dispatch table
6390 Append_To
(Elab_Code
,
6391 Build_Inherit_Predefined_Prims
(Loc
,
6393 Unchecked_Convert_To
(RTE
(RE_Tag
),
6396 (Next_Elmt
(Sec_DT_Ancestor
)),
6399 Unchecked_Convert_To
(RTE
(RE_Tag
),
6401 (Node
(Next_Elmt
(Sec_DT_Typ
)),
6404 if Num_Prims
/= 0 then
6405 Append_To
(Elab_Code
,
6406 Build_Inherit_Prims
(Loc
,
6407 Typ
=> Node
(Iface
),
6409 Unchecked_Convert_To
6412 (Node
(Sec_DT_Ancestor
),
6415 Unchecked_Convert_To
6418 (Node
(Sec_DT_Typ
), Loc
)),
6419 Num_Prims
=> Num_Prims
));
6424 Next_Elmt
(Sec_DT_Ancestor
);
6425 Next_Elmt
(Sec_DT_Typ
);
6427 -- Skip the secondary dispatch table of
6428 -- predefined primitives
6430 Next_Elmt
(Sec_DT_Ancestor
);
6431 Next_Elmt
(Sec_DT_Typ
);
6439 end Copy_Secondary_DTs
;
6442 if Present
(Node
(Sec_DT_Ancestor
))
6443 and then Ekind
(Node
(Sec_DT_Ancestor
)) = E_Constant
6445 -- Handle private types
6447 if Present
(Full_View
(Typ
)) then
6448 Copy_Secondary_DTs
(Full_View
(Typ
));
6450 Copy_Secondary_DTs
(Typ
);
6458 -- Generate code to check if the external tag of this type is the same
6459 -- as the external tag of some other declaration.
6461 -- Check_TSD (TSD'Unrestricted_Access);
6463 -- This check is a consequence of AI05-0113-1/06, so it officially
6464 -- applies to Ada 2005 (and Ada 2012). It might be argued that it is
6465 -- a desirable check to add in Ada 95 mode, but we hesitate to make
6466 -- this change, as it would be incompatible, and could conceivably
6467 -- cause a problem in existing Ada 95 code.
6469 -- We check for No_Run_Time_Mode here, because we do not want to pick
6470 -- up the RE_Check_TSD entity and call it in No_Run_Time mode.
6472 -- We cannot perform this check if the generation of its expanded name
6475 if not No_Run_Time_Mode
6476 and then not Discard_Names
6477 and then Ada_Version
>= Ada_2005
6478 and then RTE_Available
(RE_Check_TSD
)
6479 and then not Duplicated_Tag_Checks_Suppressed
(Typ
)
6481 Append_To
(Elab_Code
,
6482 Make_Procedure_Call_Statement
(Loc
,
6484 New_Occurrence_Of
(RTE
(RE_Check_TSD
), Loc
),
6485 Parameter_Associations
=> New_List
(
6486 Make_Attribute_Reference
(Loc
,
6487 Prefix
=> New_Occurrence_Of
(TSD
, Loc
),
6488 Attribute_Name
=> Name_Unchecked_Access
))));
6491 -- Generate code to register the Tag in the External_Tag hash table for
6492 -- the pure Ada type only.
6494 -- Register_Tag (Dt_Ptr);
6496 -- Skip this action in the following cases:
6497 -- 1) if Register_Tag is not available.
6498 -- 2) in No_Run_Time mode.
6499 -- 3) if Typ is not defined at the library level (this is required
6500 -- to avoid adding concurrency control to the hash table used
6501 -- by the run-time to register the tags).
6503 if not No_Run_Time_Mode
6504 and then Is_Library_Level_Entity
(Typ
)
6505 and then RTE_Available
(RE_Register_Tag
)
6507 Append_To
(Elab_Code
,
6508 Make_Procedure_Call_Statement
(Loc
,
6510 New_Occurrence_Of
(RTE
(RE_Register_Tag
), Loc
),
6511 Parameter_Associations
=>
6512 New_List
(New_Occurrence_Of
(DT_Ptr
, Loc
))));
6515 if not Is_Empty_List
(Elab_Code
) then
6516 Append_List_To
(Result
, Elab_Code
);
6519 -- Populate the two auxiliary tables used for dispatching asynchronous,
6520 -- conditional and timed selects for synchronized types that implement
6521 -- a limited interface. Skip this step in Ravenscar profile or when
6522 -- general dispatching is forbidden.
6524 if Ada_Version
>= Ada_2005
6525 and then Is_Concurrent_Record_Type
(Typ
)
6526 and then Has_Interfaces
(Typ
)
6527 and then not Restriction_Active
(No_Dispatching_Calls
)
6528 and then not Restriction_Active
(No_Select_Statements
)
6530 Append_List_To
(Result
,
6531 Make_Select_Specific_Data_Table
(Typ
));
6534 -- Remember entities containing dispatch tables
6536 Append_Elmt
(Predef_Prims
, DT_Decl
);
6537 Append_Elmt
(DT
, DT_Decl
);
6539 Analyze_List
(Result
, Suppress
=> All_Checks
);
6540 Set_Has_Dispatch_Table
(Typ
);
6542 -- Mark entities containing dispatch tables. Required by the backend to
6543 -- handle them properly.
6545 if Has_DT
(Typ
) then
6550 -- Object declarations
6552 Elmt
:= First_Elmt
(DT_Decl
);
6553 while Present
(Elmt
) loop
6554 Set_Is_Dispatch_Table_Entity
(Node
(Elmt
));
6555 pragma Assert
(Ekind
(Etype
(Node
(Elmt
))) = E_Array_Subtype
6556 or else Ekind
(Etype
(Node
(Elmt
))) = E_Record_Subtype
);
6557 Set_Is_Dispatch_Table_Entity
(Etype
(Node
(Elmt
)));
6561 -- Aggregates initializing dispatch tables
6563 Elmt
:= First_Elmt
(DT_Aggr
);
6564 while Present
(Elmt
) loop
6565 Set_Is_Dispatch_Table_Entity
(Etype
(Node
(Elmt
)));
6573 -- Register the tagged type in the call graph nodes table
6575 Register_CG_Node
(Typ
);
6578 Restore_Ghost_Region
(Saved_GM
, Saved_IGR
);
6583 -------------------------------------
6584 -- Make_Select_Specific_Data_Table --
6585 -------------------------------------
6587 function Make_Select_Specific_Data_Table
6588 (Typ
: Entity_Id
) return List_Id
6590 Assignments
: constant List_Id
:= New_List
;
6591 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
6593 Conc_Typ
: Entity_Id
;
6594 Decls
: List_Id
:= No_List
;
6596 Prim_Als
: Entity_Id
;
6597 Prim_Elmt
: Elmt_Id
;
6601 type Examined_Array
is array (Int
range <>) of Boolean;
6603 function Find_Entry_Index
(E
: Entity_Id
) return Uint
;
6604 -- Given an entry, find its index in the visible declarations of the
6605 -- corresponding concurrent type of Typ.
6607 ----------------------
6608 -- Find_Entry_Index --
6609 ----------------------
6611 function Find_Entry_Index
(E
: Entity_Id
) return Uint
is
6612 Index
: Uint
:= Uint_1
;
6613 Subp_Decl
: Entity_Id
;
6617 and then not Is_Empty_List
(Decls
)
6619 Subp_Decl
:= First
(Decls
);
6620 while Present
(Subp_Decl
) loop
6621 if Nkind
(Subp_Decl
) = N_Entry_Declaration
then
6622 if Defining_Identifier
(Subp_Decl
) = E
then
6634 end Find_Entry_Index
;
6640 -- Start of processing for Make_Select_Specific_Data_Table
6643 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
6645 if Present
(Corresponding_Concurrent_Type
(Typ
)) then
6646 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
6648 if Present
(Full_View
(Conc_Typ
)) then
6649 Conc_Typ
:= Full_View
(Conc_Typ
);
6652 if Ekind
(Conc_Typ
) = E_Protected_Type
then
6653 Decls
:= Visible_Declarations
(Protected_Definition
(
6654 Parent
(Conc_Typ
)));
6656 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
6657 Decls
:= Visible_Declarations
(Task_Definition
(
6658 Parent
(Conc_Typ
)));
6662 -- Count the non-predefined primitive operations
6664 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
6665 while Present
(Prim_Elmt
) loop
6666 Prim
:= Node
(Prim_Elmt
);
6668 if not (Is_Predefined_Dispatching_Operation
(Prim
)
6669 or else Is_Predefined_Dispatching_Alias
(Prim
))
6671 Nb_Prim
:= Nb_Prim
+ 1;
6674 Next_Elmt
(Prim_Elmt
);
6678 Examined
: Examined_Array
(1 .. Nb_Prim
) := (others => False);
6681 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
6682 while Present
(Prim_Elmt
) loop
6683 Prim
:= Node
(Prim_Elmt
);
6685 -- Look for primitive overriding an abstract interface subprogram
6687 if Present
(Interface_Alias
(Prim
))
6690 (Find_Dispatching_Type
(Interface_Alias
(Prim
)), Typ
,
6691 Use_Full_View
=> True)
6692 and then not Examined
(UI_To_Int
(DT_Position
(Alias
(Prim
))))
6694 Prim_Pos
:= DT_Position
(Alias
(Prim
));
6695 pragma Assert
(UI_To_Int
(Prim_Pos
) <= Nb_Prim
);
6696 Examined
(UI_To_Int
(Prim_Pos
)) := True;
6698 -- Set the primitive operation kind regardless of subprogram
6700 -- Ada.Tags.Set_Prim_Op_Kind (DT_Ptr, <position>, <kind>);
6702 if Tagged_Type_Expansion
then
6705 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
);
6709 Make_Attribute_Reference
(Loc
,
6710 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
6711 Attribute_Name
=> Name_Tag
);
6714 Append_To
(Assignments
,
6715 Make_Procedure_Call_Statement
(Loc
,
6716 Name
=> New_Occurrence_Of
(RTE
(RE_Set_Prim_Op_Kind
), Loc
),
6717 Parameter_Associations
=> New_List
(
6719 Make_Integer_Literal
(Loc
, Prim_Pos
),
6720 Prim_Op_Kind
(Alias
(Prim
), Typ
))));
6722 -- Retrieve the root of the alias chain
6724 Prim_Als
:= Ultimate_Alias
(Prim
);
6726 -- In the case of an entry wrapper, set the entry index
6728 if Ekind
(Prim
) = E_Procedure
6729 and then Is_Primitive_Wrapper
(Prim_Als
)
6730 and then Ekind
(Wrapped_Entity
(Prim_Als
)) = E_Entry
6733 -- Ada.Tags.Set_Entry_Index
6734 -- (DT_Ptr, <position>, <index>);
6736 if Tagged_Type_Expansion
then
6739 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
);
6742 Make_Attribute_Reference
(Loc
,
6743 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
6744 Attribute_Name
=> Name_Tag
);
6747 Append_To
(Assignments
,
6748 Make_Procedure_Call_Statement
(Loc
,
6750 New_Occurrence_Of
(RTE
(RE_Set_Entry_Index
), Loc
),
6751 Parameter_Associations
=> New_List
(
6753 Make_Integer_Literal
(Loc
, Prim_Pos
),
6754 Make_Integer_Literal
(Loc
,
6755 Find_Entry_Index
(Wrapped_Entity
(Prim_Als
))))));
6759 Next_Elmt
(Prim_Elmt
);
6764 end Make_Select_Specific_Data_Table
;
6770 function Make_Tags
(Typ
: Entity_Id
) return List_Id
is
6771 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
6772 Result
: constant List_Id
:= New_List
;
6775 (Tag_Typ
: Entity_Id
;
6777 Is_Secondary_DT
: Boolean);
6778 -- Import the dispatch table DT of tagged type Tag_Typ. Required to
6779 -- generate forward references and statically allocate the table. For
6780 -- primary dispatch tables that require no dispatch table generate:
6782 -- DT : static aliased constant Non_Dispatch_Table_Wrapper;
6783 -- pragma Import (Ada, DT);
6785 -- Otherwise generate:
6787 -- DT : static aliased constant Dispatch_Table_Wrapper (Nb_Prim);
6788 -- pragma Import (Ada, DT);
6795 (Tag_Typ
: Entity_Id
;
6797 Is_Secondary_DT
: Boolean)
6799 DT_Constr_List
: List_Id
;
6803 Set_Is_Imported
(DT
);
6804 Set_Ekind
(DT
, E_Constant
);
6805 Set_Related_Type
(DT
, Typ
);
6807 -- The scope must be set now to call Get_External_Name
6809 Set_Scope
(DT
, Current_Scope
);
6811 Get_External_Name
(DT
);
6812 Set_Interface_Name
(DT
,
6813 Make_String_Literal
(Loc
, Strval
=> String_From_Name_Buffer
));
6815 -- Ensure proper Sprint output of this implicit importation
6817 Set_Is_Internal
(DT
);
6819 -- Save this entity to allow Make_DT to generate its exportation
6821 Append_Elmt
(DT
, Dispatch_Table_Wrappers
(Typ
));
6823 -- No dispatch table required
6825 if not Is_Secondary_DT
and then not Has_DT
(Tag_Typ
) then
6827 Make_Object_Declaration
(Loc
,
6828 Defining_Identifier
=> DT
,
6829 Aliased_Present
=> True,
6830 Constant_Present
=> True,
6831 Object_Definition
=>
6833 (RTE
(RE_No_Dispatch_Table_Wrapper
), Loc
)));
6836 -- Calculate the number of primitives of the dispatch table and
6837 -- the size of the Type_Specific_Data record.
6840 UI_To_Int
(DT_Entry_Count
(First_Tag_Component
(Tag_Typ
)));
6842 -- If the tagged type has no primitives we add a dummy slot whose
6843 -- address will be the tag of this type.
6847 New_List
(Make_Integer_Literal
(Loc
, 1));
6850 New_List
(Make_Integer_Literal
(Loc
, Nb_Prim
));
6854 Make_Object_Declaration
(Loc
,
6855 Defining_Identifier
=> DT
,
6856 Aliased_Present
=> True,
6857 Constant_Present
=> True,
6858 Object_Definition
=>
6859 Make_Subtype_Indication
(Loc
,
6861 New_Occurrence_Of
(RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
6862 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
,
6863 Constraints
=> DT_Constr_List
))));
6869 Tname
: constant Name_Id
:= Chars
(Typ
);
6870 AI_Tag_Comp
: Elmt_Id
;
6871 DT
: Node_Id
:= Empty
;
6873 Predef_Prims_Ptr
: Node_Id
;
6874 Iface_DT
: Node_Id
:= Empty
;
6875 Iface_DT_Ptr
: Node_Id
;
6879 Typ_Comps
: Elist_Id
;
6881 -- Start of processing for Make_Tags
6884 pragma Assert
(No
(Access_Disp_Table
(Typ
)));
6885 Set_Access_Disp_Table
(Typ
, New_Elmt_List
);
6887 -- If the elaboration of this tagged type needs a boolean flag then
6888 -- define now its entity. It is initialized to True to indicate that
6889 -- elaboration is still pending; set to False by the IP routine.
6891 -- TypFxx : boolean := True;
6893 if Elab_Flag_Needed
(Typ
) then
6894 Set_Access_Disp_Table_Elab_Flag
(Typ
,
6895 Make_Defining_Identifier
(Loc
,
6896 Chars
=> New_External_Name
(Tname
, 'F')));
6899 Make_Object_Declaration
(Loc
,
6900 Defining_Identifier
=> Access_Disp_Table_Elab_Flag
(Typ
),
6901 Object_Definition
=> New_Occurrence_Of
(Standard_Boolean
, Loc
),
6902 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
6905 -- 1) Generate the primary tag entities
6907 -- Primary dispatch table containing user-defined primitives
6909 DT_Ptr
:= Make_Defining_Identifier
(Loc
, New_External_Name
(Tname
, 'P'));
6910 Set_Etype
(DT_Ptr
, RTE
(RE_Tag
));
6911 Append_Elmt
(DT_Ptr
, Access_Disp_Table
(Typ
));
6913 -- Minimum decoration
6915 Set_Ekind
(DT_Ptr
, E_Variable
);
6916 Set_Related_Type
(DT_Ptr
, Typ
);
6918 -- Notify back end that the types are associated with a dispatch table
6920 Set_Is_Dispatch_Table_Entity
(RTE
(RE_Prim_Ptr
));
6921 Set_Is_Dispatch_Table_Entity
(RTE
(RE_Predef_Prims_Table_Ptr
));
6923 -- For CPP types there is no need to build the dispatch tables since
6924 -- they are imported from the C++ side. If the CPP type has an IP then
6925 -- we declare now the variable that will store the copy of the C++ tag.
6926 -- If the CPP type is an interface, we need the variable as well because
6927 -- it becomes the pointer to the corresponding secondary table.
6929 if Is_CPP_Class
(Typ
) then
6930 if Has_CPP_Constructors
(Typ
) or else Is_Interface
(Typ
) then
6932 Make_Object_Declaration
(Loc
,
6933 Defining_Identifier
=> DT_Ptr
,
6934 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
6936 Unchecked_Convert_To
(RTE
(RE_Tag
),
6937 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
))));
6939 Set_Is_Statically_Allocated
(DT_Ptr
,
6940 Is_Library_Level_Tagged_Type
(Typ
));
6946 -- Primary dispatch table containing predefined primitives
6949 Make_Defining_Identifier
(Loc
,
6950 Chars
=> New_External_Name
(Tname
, 'Y'));
6951 Set_Etype
(Predef_Prims_Ptr
, RTE
(RE_Address
));
6952 Append_Elmt
(Predef_Prims_Ptr
, Access_Disp_Table
(Typ
));
6954 -- Import the forward declaration of the Dispatch Table wrapper
6955 -- record (Make_DT will take care of exporting it).
6957 if Building_Static_DT
(Typ
) then
6958 Set_Dispatch_Table_Wrappers
(Typ
, New_Elmt_List
);
6961 Make_Defining_Identifier
(Loc
,
6962 Chars
=> New_External_Name
(Tname
, 'T'));
6964 Import_DT
(Typ
, DT
, Is_Secondary_DT
=> False);
6966 if Has_DT
(Typ
) then
6968 Make_Object_Declaration
(Loc
,
6969 Defining_Identifier
=> DT_Ptr
,
6970 Constant_Present
=> True,
6971 Object_Definition
=>
6972 New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
6974 Unchecked_Convert_To
(RTE
(RE_Tag
),
6975 Make_Attribute_Reference
(Loc
,
6977 Make_Selected_Component
(Loc
,
6978 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
6981 (RTE_Record_Component
(RE_Prims_Ptr
), Loc
)),
6982 Attribute_Name
=> Name_Address
))));
6984 -- Generate the SCIL node for the previous object declaration
6985 -- because it has a tag initialization.
6987 if Generate_SCIL
then
6989 Make_SCIL_Dispatch_Table_Tag_Init
(Sloc
(Last
(Result
)));
6990 Set_SCIL_Entity
(New_Node
, Typ
);
6991 Set_SCIL_Node
(Last
(Result
), New_Node
);
6995 Make_Object_Declaration
(Loc
,
6996 Defining_Identifier
=> Predef_Prims_Ptr
,
6997 Constant_Present
=> True,
6998 Object_Definition
=>
6999 New_Occurrence_Of
(RTE
(RE_Address
), Loc
),
7001 Make_Attribute_Reference
(Loc
,
7003 Make_Selected_Component
(Loc
,
7004 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
7007 (RTE_Record_Component
(RE_Predef_Prims
), Loc
)),
7008 Attribute_Name
=> Name_Address
)));
7010 -- No dispatch table required
7014 Make_Object_Declaration
(Loc
,
7015 Defining_Identifier
=> DT_Ptr
,
7016 Constant_Present
=> True,
7017 Object_Definition
=>
7018 New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
7020 Unchecked_Convert_To
(RTE
(RE_Tag
),
7021 Make_Attribute_Reference
(Loc
,
7023 Make_Selected_Component
(Loc
,
7024 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
7027 (RTE_Record_Component
(RE_NDT_Prims_Ptr
),
7029 Attribute_Name
=> Name_Address
))));
7032 Set_Is_True_Constant
(DT_Ptr
);
7033 Set_Is_Statically_Allocated
(DT_Ptr
);
7037 -- 2) Generate the secondary tag entities
7039 -- Collect the components associated with secondary dispatch tables
7041 if Has_Interfaces
(Typ
) then
7042 Collect_Interface_Components
(Typ
, Typ_Comps
);
7044 -- For each interface type we build a unique external name associated
7045 -- with its secondary dispatch table. This name is used to declare an
7046 -- object that references this secondary dispatch table, whose value
7047 -- will be used for the elaboration of Typ objects, and also for the
7048 -- elaboration of objects of types derived from Typ that do not
7049 -- override the primitives of this interface type.
7053 -- Note: The value of Suffix_Index must be in sync with the values of
7054 -- Suffix_Index in secondary dispatch tables generated by Make_DT.
7056 if Is_CPP_Class
(Typ
) then
7057 AI_Tag_Comp
:= First_Elmt
(Typ_Comps
);
7058 while Present
(AI_Tag_Comp
) loop
7059 Get_Secondary_DT_External_Name
7060 (Typ
, Related_Type
(Node
(AI_Tag_Comp
)), Suffix_Index
);
7061 Typ_Name
:= Name_Find
;
7063 -- Declare variables to store copy of the C++ secondary tags
7066 Make_Defining_Identifier
(Loc
,
7067 Chars
=> New_External_Name
(Typ_Name
, 'P'));
7068 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Interface_Tag
));
7069 Set_Ekind
(Iface_DT_Ptr
, E_Variable
);
7070 Set_Is_Tag
(Iface_DT_Ptr
);
7072 Set_Has_Thunks
(Iface_DT_Ptr
);
7074 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
7075 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
7078 Make_Object_Declaration
(Loc
,
7079 Defining_Identifier
=> Iface_DT_Ptr
,
7080 Object_Definition
=> New_Occurrence_Of
7081 (RTE
(RE_Interface_Tag
), Loc
),
7083 Unchecked_Convert_To
(RTE
(RE_Interface_Tag
),
7084 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
))));
7086 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
7087 Is_Library_Level_Tagged_Type
(Typ
));
7089 Next_Elmt
(AI_Tag_Comp
);
7092 -- This is not a CPP_Class type
7095 AI_Tag_Comp
:= First_Elmt
(Typ_Comps
);
7096 while Present
(AI_Tag_Comp
) loop
7097 Get_Secondary_DT_External_Name
7098 (Typ
, Related_Type
(Node
(AI_Tag_Comp
)), Suffix_Index
);
7099 Typ_Name
:= Name_Find
;
7101 if Building_Static_DT
(Typ
) then
7103 Make_Defining_Identifier
(Loc
,
7104 Chars
=> New_External_Name
(Typ_Name
, 'T'));
7106 (Tag_Typ
=> Related_Type
(Node
(AI_Tag_Comp
)),
7108 Is_Secondary_DT
=> True);
7111 -- Secondary dispatch table referencing thunks to user-defined
7112 -- primitives covered by this interface.
7115 Make_Defining_Identifier
(Loc
,
7116 Chars
=> New_External_Name
(Typ_Name
, 'P'));
7117 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Interface_Tag
));
7118 Set_Ekind
(Iface_DT_Ptr
, E_Constant
);
7119 Set_Is_Tag
(Iface_DT_Ptr
);
7120 Set_Has_Thunks
(Iface_DT_Ptr
);
7121 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
7122 Is_Library_Level_Tagged_Type
(Typ
));
7123 Set_Is_True_Constant
(Iface_DT_Ptr
);
7125 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
7126 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
7128 if Building_Static_DT
(Typ
) then
7130 Make_Object_Declaration
(Loc
,
7131 Defining_Identifier
=> Iface_DT_Ptr
,
7132 Constant_Present
=> True,
7133 Object_Definition
=> New_Occurrence_Of
7134 (RTE
(RE_Interface_Tag
), Loc
),
7136 Unchecked_Convert_To
(RTE
(RE_Interface_Tag
),
7137 Make_Attribute_Reference
(Loc
,
7139 Make_Selected_Component
(Loc
,
7141 New_Occurrence_Of
(Iface_DT
, Loc
),
7144 (RTE_Record_Component
(RE_Prims_Ptr
),
7146 Attribute_Name
=> Name_Address
))));
7149 -- Secondary dispatch table referencing thunks to predefined
7153 Make_Defining_Identifier
(Loc
,
7154 Chars
=> New_External_Name
(Typ_Name
, 'Y'));
7155 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Address
));
7156 Set_Ekind
(Iface_DT_Ptr
, E_Constant
);
7157 Set_Is_Tag
(Iface_DT_Ptr
);
7158 Set_Has_Thunks
(Iface_DT_Ptr
);
7159 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
7160 Is_Library_Level_Tagged_Type
(Typ
));
7161 Set_Is_True_Constant
(Iface_DT_Ptr
);
7163 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
7164 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
7166 -- Secondary dispatch table referencing user-defined primitives
7167 -- covered by this interface.
7170 Make_Defining_Identifier
(Loc
,
7171 Chars
=> New_External_Name
(Typ_Name
, 'D'));
7172 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Interface_Tag
));
7173 Set_Ekind
(Iface_DT_Ptr
, E_Constant
);
7174 Set_Is_Tag
(Iface_DT_Ptr
);
7175 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
7176 Is_Library_Level_Tagged_Type
(Typ
));
7177 Set_Is_True_Constant
(Iface_DT_Ptr
);
7179 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
7180 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
7182 -- Secondary dispatch table referencing predefined primitives
7185 Make_Defining_Identifier
(Loc
,
7186 Chars
=> New_External_Name
(Typ_Name
, 'Z'));
7187 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Address
));
7188 Set_Ekind
(Iface_DT_Ptr
, E_Constant
);
7189 Set_Is_Tag
(Iface_DT_Ptr
);
7190 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
7191 Is_Library_Level_Tagged_Type
(Typ
));
7192 Set_Is_True_Constant
(Iface_DT_Ptr
);
7194 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
7195 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
7197 Next_Elmt
(AI_Tag_Comp
);
7202 -- 3) At the end of Access_Disp_Table, if the type has user-defined
7203 -- primitives, we add the entity of an access type declaration that
7204 -- is used by Build_Get_Prim_Op_Address to expand dispatching calls
7205 -- through the primary dispatch table.
7207 if UI_To_Int
(DT_Entry_Count
(First_Tag_Component
(Typ
))) = 0 then
7208 Analyze_List
(Result
);
7211 -- subtype Typ_DT is Address_Array (1 .. Nb_Prims);
7212 -- type Typ_DT_Acc is access Typ_DT;
7216 Name_DT_Prims
: constant Name_Id
:=
7217 New_External_Name
(Tname
, 'G');
7218 Name_DT_Prims_Acc
: constant Name_Id
:=
7219 New_External_Name
(Tname
, 'H');
7220 DT_Prims
: constant Entity_Id
:=
7221 Make_Defining_Identifier
(Loc
,
7223 DT_Prims_Acc
: constant Entity_Id
:=
7224 Make_Defining_Identifier
(Loc
,
7228 Make_Subtype_Declaration
(Loc
,
7229 Defining_Identifier
=> DT_Prims
,
7230 Subtype_Indication
=>
7231 Make_Subtype_Indication
(Loc
,
7233 New_Occurrence_Of
(RTE
(RE_Address_Array
), Loc
),
7235 Make_Index_Or_Discriminant_Constraint
(Loc
, New_List
(
7237 Low_Bound
=> Make_Integer_Literal
(Loc
, 1),
7239 Make_Integer_Literal
(Loc
,
7241 (First_Tag_Component
(Typ
)))))))));
7244 Make_Full_Type_Declaration
(Loc
,
7245 Defining_Identifier
=> DT_Prims_Acc
,
7247 Make_Access_To_Object_Definition
(Loc
,
7248 Subtype_Indication
=>
7249 New_Occurrence_Of
(DT_Prims
, Loc
))));
7251 Append_Elmt
(DT_Prims_Acc
, Access_Disp_Table
(Typ
));
7253 -- Analyze the resulting list and suppress the generation of the
7254 -- Init_Proc associated with the above array declaration because
7255 -- this type is never used in object declarations. It is only used
7256 -- to simplify the expansion associated with dispatching calls.
7258 Analyze_List
(Result
);
7259 Set_Suppress_Initialization
(Base_Type
(DT_Prims
));
7261 -- Disable backend optimizations based on assumptions about the
7262 -- aliasing status of objects designated by the access to the
7263 -- dispatch table. Required to handle dispatch tables imported
7266 Set_No_Strict_Aliasing
(Base_Type
(DT_Prims_Acc
));
7268 -- Add the freezing nodes of these declarations; required to avoid
7269 -- generating these freezing nodes in wrong scopes (for example in
7270 -- the IC routine of a derivation of Typ).
7272 -- What is an "IC routine"? Is "init_proc" meant here???
7274 Append_List_To
(Result
, Freeze_Entity
(DT_Prims
, Typ
));
7275 Append_List_To
(Result
, Freeze_Entity
(DT_Prims_Acc
, Typ
));
7277 -- Mark entity of dispatch table. Required by the back end to
7278 -- handle them properly.
7280 Set_Is_Dispatch_Table_Entity
(DT_Prims
);
7284 -- Mark entities of dispatch table. Required by the back end to handle
7287 if Present
(DT
) then
7288 Set_Is_Dispatch_Table_Entity
(DT
);
7289 Set_Is_Dispatch_Table_Entity
(Etype
(DT
));
7292 if Present
(Iface_DT
) then
7293 Set_Is_Dispatch_Table_Entity
(Iface_DT
);
7294 Set_Is_Dispatch_Table_Entity
(Etype
(Iface_DT
));
7297 if Is_CPP_Class
(Root_Type
(Typ
)) then
7298 Set_Ekind
(DT_Ptr
, E_Variable
);
7300 Set_Ekind
(DT_Ptr
, E_Constant
);
7303 Set_Is_Tag
(DT_Ptr
);
7304 Set_Related_Type
(DT_Ptr
, Typ
);
7313 function New_Value
(From
: Node_Id
) return Node_Id
is
7314 Res
: constant Node_Id
:= Duplicate_Subexpr
(From
);
7316 if Is_Access_Type
(Etype
(From
)) then
7317 return Make_Explicit_Dereference
(Sloc
(From
), Prefix
=> Res
);
7323 -----------------------------------
7324 -- Original_View_In_Visible_Part --
7325 -----------------------------------
7327 function Original_View_In_Visible_Part
(Typ
: Entity_Id
) return Boolean is
7328 Scop
: constant Entity_Id
:= Scope
(Typ
);
7331 -- The scope must be a package
7333 if not Is_Package_Or_Generic_Package
(Scop
) then
7337 -- A type with a private declaration has a private view declared in
7338 -- the visible part.
7340 if Has_Private_Declaration
(Typ
) then
7344 return List_Containing
(Parent
(Typ
)) =
7345 Visible_Declarations
(Package_Specification
(Scop
));
7346 end Original_View_In_Visible_Part
;
7352 function Prim_Op_Kind
7354 Typ
: Entity_Id
) return Node_Id
7356 Full_Typ
: Entity_Id
:= Typ
;
7357 Loc
: constant Source_Ptr
:= Sloc
(Prim
);
7358 Prim_Op
: Entity_Id
;
7361 -- Retrieve the original primitive operation
7363 Prim_Op
:= Ultimate_Alias
(Prim
);
7365 if Ekind
(Typ
) = E_Record_Type
7366 and then Present
(Corresponding_Concurrent_Type
(Typ
))
7368 Full_Typ
:= Corresponding_Concurrent_Type
(Typ
);
7371 -- When a private tagged type is completed by a concurrent type,
7372 -- retrieve the full view.
7374 if Is_Private_Type
(Full_Typ
) then
7375 Full_Typ
:= Full_View
(Full_Typ
);
7378 if Ekind
(Prim_Op
) = E_Function
then
7380 -- Protected function
7382 if Ekind
(Full_Typ
) = E_Protected_Type
then
7383 return New_Occurrence_Of
(RTE
(RE_POK_Protected_Function
), Loc
);
7387 elsif Ekind
(Full_Typ
) = E_Task_Type
then
7388 return New_Occurrence_Of
(RTE
(RE_POK_Task_Function
), Loc
);
7393 return New_Occurrence_Of
(RTE
(RE_POK_Function
), Loc
);
7397 pragma Assert
(Ekind
(Prim_Op
) = E_Procedure
);
7399 if Ekind
(Full_Typ
) = E_Protected_Type
then
7403 if Is_Primitive_Wrapper
(Prim_Op
)
7404 and then Ekind
(Wrapped_Entity
(Prim_Op
)) = E_Entry
7406 return New_Occurrence_Of
(RTE
(RE_POK_Protected_Entry
), Loc
);
7408 -- Protected procedure
7412 New_Occurrence_Of
(RTE
(RE_POK_Protected_Procedure
), Loc
);
7415 elsif Ekind
(Full_Typ
) = E_Task_Type
then
7419 if Is_Primitive_Wrapper
(Prim_Op
)
7420 and then Ekind
(Wrapped_Entity
(Prim_Op
)) = E_Entry
7422 return New_Occurrence_Of
(RTE
(RE_POK_Task_Entry
), Loc
);
7424 -- Task "procedure". These are the internally Expander-generated
7425 -- procedures (task body for instance).
7428 return New_Occurrence_Of
(RTE
(RE_POK_Task_Procedure
), Loc
);
7431 -- Regular procedure
7434 return New_Occurrence_Of
(RTE
(RE_POK_Procedure
), Loc
);
7439 ------------------------
7440 -- Register_Primitive --
7441 ------------------------
7443 function Register_Primitive
7445 Prim
: Entity_Id
) return List_Id
7448 Iface_Prim
: Entity_Id
;
7449 Iface_Typ
: Entity_Id
;
7450 Iface_DT_Ptr
: Entity_Id
;
7451 Iface_DT_Elmt
: Elmt_Id
;
7452 L
: constant List_Id
:= New_List
;
7455 Tag_Typ
: Entity_Id
;
7456 Thunk_Id
: Entity_Id
;
7457 Thunk_Code
: Node_Id
;
7460 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
7462 -- Do not register in the dispatch table eliminated primitives
7464 if not RTE_Available
(RE_Tag
)
7465 or else Is_Eliminated
(Ultimate_Alias
(Prim
))
7466 or else Generate_SCIL
7471 if not Present
(Interface_Alias
(Prim
)) then
7472 Tag_Typ
:= Scope
(DTC_Entity
(Prim
));
7473 Pos
:= DT_Position
(Prim
);
7474 Tag
:= First_Tag_Component
(Tag_Typ
);
7476 if Is_Predefined_Dispatching_Operation
(Prim
)
7477 or else Is_Predefined_Dispatching_Alias
(Prim
)
7480 Node
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(Tag_Typ
))));
7483 Build_Set_Predefined_Prim_Op_Address
(Loc
,
7484 Tag_Node
=> New_Occurrence_Of
(DT_Ptr
, Loc
),
7487 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7488 Make_Attribute_Reference
(Loc
,
7489 Prefix
=> New_Occurrence_Of
(Prim
, Loc
),
7490 Attribute_Name
=> Name_Unrestricted_Access
))));
7492 -- Register copy of the pointer to the 'size primitive in the TSD
7494 if Chars
(Prim
) = Name_uSize
7495 and then RTE_Record_Component_Available
(RE_Size_Func
)
7497 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Tag_Typ
)));
7499 Build_Set_Size_Function
(Loc
,
7500 Tag_Node
=> New_Occurrence_Of
(DT_Ptr
, Loc
),
7501 Size_Func
=> Prim
));
7505 pragma Assert
(Pos
/= Uint_0
and then Pos
<= DT_Entry_Count
(Tag
));
7507 -- Skip registration of primitives located in the C++ part of the
7508 -- dispatch table. Their slot is set by the IC routine.
7510 if not Is_CPP_Class
(Root_Type
(Tag_Typ
))
7511 or else Pos
> CPP_Num_Prims
(Tag_Typ
)
7513 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Tag_Typ
)));
7515 Build_Set_Prim_Op_Address
(Loc
,
7517 Tag_Node
=> New_Occurrence_Of
(DT_Ptr
, Loc
),
7520 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7521 Make_Attribute_Reference
(Loc
,
7522 Prefix
=> New_Occurrence_Of
(Prim
, Loc
),
7523 Attribute_Name
=> Name_Unrestricted_Access
))));
7527 -- Ada 2005 (AI-251): Primitive associated with an interface type
7529 -- Generate the code of the thunk only if the interface type is not an
7530 -- immediate ancestor of Typ; otherwise the dispatch table associated
7531 -- with the interface is the primary dispatch table and we have nothing
7535 Tag_Typ
:= Find_Dispatching_Type
(Alias
(Prim
));
7536 Iface_Typ
:= Find_Dispatching_Type
(Interface_Alias
(Prim
));
7538 pragma Assert
(Is_Interface
(Iface_Typ
));
7540 -- No action needed for interfaces that are ancestors of Typ because
7541 -- their primitives are located in the primary dispatch table.
7543 if Is_Ancestor
(Iface_Typ
, Tag_Typ
, Use_Full_View
=> True) then
7546 -- No action needed for primitives located in the C++ part of the
7547 -- dispatch table. Their slot is set by the IC routine.
7549 elsif Is_CPP_Class
(Root_Type
(Tag_Typ
))
7550 and then DT_Position
(Alias
(Prim
)) <= CPP_Num_Prims
(Tag_Typ
)
7551 and then not Is_Predefined_Dispatching_Operation
(Prim
)
7552 and then not Is_Predefined_Dispatching_Alias
(Prim
)
7557 Expand_Interface_Thunk
(Prim
, Thunk_Id
, Thunk_Code
);
7559 if not Is_Ancestor
(Iface_Typ
, Tag_Typ
, Use_Full_View
=> True)
7560 and then Present
(Thunk_Code
)
7562 -- Generate the code necessary to fill the appropriate entry of
7563 -- the secondary dispatch table of Prim's controlling type with
7564 -- Thunk_Id's address.
7566 Iface_DT_Elmt
:= Find_Interface_ADT
(Tag_Typ
, Iface_Typ
);
7567 Iface_DT_Ptr
:= Node
(Iface_DT_Elmt
);
7568 pragma Assert
(Has_Thunks
(Iface_DT_Ptr
));
7570 Iface_Prim
:= Interface_Alias
(Prim
);
7571 Pos
:= DT_Position
(Iface_Prim
);
7572 Tag
:= First_Tag_Component
(Iface_Typ
);
7574 Prepend_To
(L
, Thunk_Code
);
7576 if Is_Predefined_Dispatching_Operation
(Prim
)
7577 or else Is_Predefined_Dispatching_Alias
(Prim
)
7580 Build_Set_Predefined_Prim_Op_Address
(Loc
,
7582 New_Occurrence_Of
(Node
(Next_Elmt
(Iface_DT_Elmt
)), Loc
),
7585 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7586 Make_Attribute_Reference
(Loc
,
7587 Prefix
=> New_Occurrence_Of
(Thunk_Id
, Loc
),
7588 Attribute_Name
=> Name_Unrestricted_Access
))));
7590 Next_Elmt
(Iface_DT_Elmt
);
7591 Next_Elmt
(Iface_DT_Elmt
);
7592 Iface_DT_Ptr
:= Node
(Iface_DT_Elmt
);
7593 pragma Assert
(not Has_Thunks
(Iface_DT_Ptr
));
7596 Build_Set_Predefined_Prim_Op_Address
(Loc
,
7598 New_Occurrence_Of
(Node
(Next_Elmt
(Iface_DT_Elmt
)), Loc
),
7601 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7602 Make_Attribute_Reference
(Loc
,
7604 New_Occurrence_Of
(Alias
(Prim
), Loc
),
7605 Attribute_Name
=> Name_Unrestricted_Access
))));
7608 pragma Assert
(Pos
/= Uint_0
7609 and then Pos
<= DT_Entry_Count
(Tag
));
7612 Build_Set_Prim_Op_Address
(Loc
,
7614 Tag_Node
=> New_Occurrence_Of
(Iface_DT_Ptr
, Loc
),
7617 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7618 Make_Attribute_Reference
(Loc
,
7619 Prefix
=> New_Occurrence_Of
(Thunk_Id
, Loc
),
7620 Attribute_Name
=> Name_Unrestricted_Access
))));
7622 Next_Elmt
(Iface_DT_Elmt
);
7623 Next_Elmt
(Iface_DT_Elmt
);
7624 Iface_DT_Ptr
:= Node
(Iface_DT_Elmt
);
7625 pragma Assert
(not Has_Thunks
(Iface_DT_Ptr
));
7628 Build_Set_Prim_Op_Address
(Loc
,
7630 Tag_Node
=> New_Occurrence_Of
(Iface_DT_Ptr
, Loc
),
7633 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7634 Make_Attribute_Reference
(Loc
,
7636 New_Occurrence_Of
(Alias
(Prim
), Loc
),
7637 Attribute_Name
=> Name_Unrestricted_Access
))));
7644 end Register_Primitive
;
7646 -------------------------
7647 -- Set_All_DT_Position --
7648 -------------------------
7650 procedure Set_All_DT_Position
(Typ
: Entity_Id
) is
7652 function In_Predef_Prims_DT
(Prim
: Entity_Id
) return Boolean;
7653 -- Returns True if Prim is located in the dispatch table of
7654 -- predefined primitives
7656 procedure Validate_Position
(Prim
: Entity_Id
);
7657 -- Check that position assigned to Prim is completely safe (it has not
7658 -- been assigned to a previously defined primitive operation of Typ).
7660 ------------------------
7661 -- In_Predef_Prims_DT --
7662 ------------------------
7664 function In_Predef_Prims_DT
(Prim
: Entity_Id
) return Boolean is
7666 -- Predefined primitives
7668 if Is_Predefined_Dispatching_Operation
(Prim
) then
7671 -- Renamings of predefined primitives
7673 elsif Present
(Alias
(Prim
))
7674 and then Is_Predefined_Dispatching_Operation
(Ultimate_Alias
(Prim
))
7676 if Chars
(Ultimate_Alias
(Prim
)) /= Name_Op_Eq
then
7679 -- An overriding operation that is a user-defined renaming of
7680 -- predefined equality inherits its slot from the overridden
7681 -- operation. Otherwise it is treated as a predefined op and
7682 -- occupies the same predefined slot as equality. A call to it is
7683 -- transformed into a call to its alias, which is the predefined
7684 -- equality op. A dispatching call thus uses the proper slot if
7685 -- operation is further inherited and called with class-wide
7690 not Comes_From_Source
(Prim
)
7691 or else No
(Overridden_Operation
(Prim
));
7694 -- User-defined primitives
7699 end In_Predef_Prims_DT
;
7701 -----------------------
7702 -- Validate_Position --
7703 -----------------------
7705 procedure Validate_Position
(Prim
: Entity_Id
) is
7710 -- Aliased primitives are safe
7712 if Present
(Alias
(Prim
)) then
7716 Op_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
7717 while Present
(Op_Elmt
) loop
7718 Op
:= Node
(Op_Elmt
);
7720 -- No need to check against itself
7725 -- Primitive operations covering abstract interfaces are
7728 elsif Present
(Interface_Alias
(Op
)) then
7731 -- Predefined dispatching operations are completely safe. They
7732 -- are allocated at fixed positions in a separate table.
7734 elsif Is_Predefined_Dispatching_Operation
(Op
)
7735 or else Is_Predefined_Dispatching_Alias
(Op
)
7739 -- Aliased subprograms are safe
7741 elsif Present
(Alias
(Op
)) then
7744 elsif DT_Position
(Op
) = DT_Position
(Prim
)
7745 and then not Is_Predefined_Dispatching_Operation
(Op
)
7746 and then not Is_Predefined_Dispatching_Operation
(Prim
)
7747 and then not Is_Predefined_Dispatching_Alias
(Op
)
7748 and then not Is_Predefined_Dispatching_Alias
(Prim
)
7750 -- Handle aliased subprograms
7759 if Present
(Overridden_Operation
(Op_1
)) then
7760 Op_1
:= Overridden_Operation
(Op_1
);
7761 elsif Present
(Alias
(Op_1
)) then
7762 Op_1
:= Alias
(Op_1
);
7770 if Present
(Overridden_Operation
(Op_2
)) then
7771 Op_2
:= Overridden_Operation
(Op_2
);
7772 elsif Present
(Alias
(Op_2
)) then
7773 Op_2
:= Alias
(Op_2
);
7779 if Op_1
/= Op_2
then
7780 raise Program_Error
;
7785 Next_Elmt
(Op_Elmt
);
7787 end Validate_Position
;
7791 Parent_Typ
: constant Entity_Id
:= Etype
(Typ
);
7792 First_Prim
: constant Elmt_Id
:= First_Elmt
(Primitive_Operations
(Typ
));
7793 The_Tag
: constant Entity_Id
:= First_Tag_Component
(Typ
);
7795 Adjusted
: Boolean := False;
7796 Finalized
: Boolean := False;
7802 Prim_Elmt
: Elmt_Id
;
7804 -- Start of processing for Set_All_DT_Position
7807 pragma Assert
(Present
(First_Tag_Component
(Typ
)));
7809 -- Set the DT_Position for each primitive operation. Perform some sanity
7810 -- checks to avoid building inconsistent dispatch tables.
7812 -- First stage: Set DTC entity of all the primitive operations. This is
7813 -- required to properly read the DT_Position attribute in latter stages.
7815 Prim_Elmt
:= First_Prim
;
7817 while Present
(Prim_Elmt
) loop
7818 Prim
:= Node
(Prim_Elmt
);
7820 -- Predefined primitives have a separate dispatch table
7822 if not In_Predef_Prims_DT
(Prim
) then
7823 Count_Prim
:= Count_Prim
+ 1;
7826 Set_DTC_Entity_Value
(Typ
, Prim
);
7828 -- Clear any previous value of the DT_Position attribute. In this
7829 -- way we ensure that the final position of all the primitives is
7830 -- established by the following stages of this algorithm.
7832 Set_DT_Position_Value
(Prim
, No_Uint
);
7834 Next_Elmt
(Prim_Elmt
);
7838 Fixed_Prim
: array (Int
range 0 .. Count_Prim
) of Boolean :=
7843 procedure Handle_Inherited_Private_Subprograms
(Typ
: Entity_Id
);
7844 -- Called if Typ is declared in a nested package or a public child
7845 -- package to handle inherited primitives that were inherited by Typ
7846 -- in the visible part, but whose declaration was deferred because
7847 -- the parent operation was private and not visible at that point.
7849 procedure Set_Fixed_Prim
(Pos
: Nat
);
7850 -- Sets to true an element of the Fixed_Prim table to indicate
7851 -- that this entry of the dispatch table of Typ is occupied.
7853 ------------------------------------------
7854 -- Handle_Inherited_Private_Subprograms --
7855 ------------------------------------------
7857 procedure Handle_Inherited_Private_Subprograms
(Typ
: Entity_Id
) is
7860 Op_Elmt_2
: Elmt_Id
;
7861 Prim_Op
: Entity_Id
;
7862 Parent_Subp
: Entity_Id
;
7865 Op_List
:= Primitive_Operations
(Typ
);
7867 Op_Elmt
:= First_Elmt
(Op_List
);
7868 while Present
(Op_Elmt
) loop
7869 Prim_Op
:= Node
(Op_Elmt
);
7871 -- Search primitives that are implicit operations with an
7872 -- internal name whose parent operation has a normal name.
7874 if Present
(Alias
(Prim_Op
))
7875 and then Find_Dispatching_Type
(Alias
(Prim_Op
)) /= Typ
7876 and then not Comes_From_Source
(Prim_Op
)
7877 and then Is_Internal_Name
(Chars
(Prim_Op
))
7878 and then not Is_Internal_Name
(Chars
(Alias
(Prim_Op
)))
7880 Parent_Subp
:= Alias
(Prim_Op
);
7882 -- Check if the type has an explicit overriding for this
7885 Op_Elmt_2
:= Next_Elmt
(Op_Elmt
);
7886 while Present
(Op_Elmt_2
) loop
7887 if Chars
(Node
(Op_Elmt_2
)) = Chars
(Parent_Subp
)
7888 and then Type_Conformant
(Prim_Op
, Node
(Op_Elmt_2
))
7890 Set_DT_Position_Value
(Prim_Op
,
7891 DT_Position
(Parent_Subp
));
7892 Set_DT_Position_Value
(Node
(Op_Elmt_2
),
7893 DT_Position
(Parent_Subp
));
7894 Set_Fixed_Prim
(UI_To_Int
(DT_Position
(Prim_Op
)));
7896 goto Next_Primitive
;
7899 Next_Elmt
(Op_Elmt_2
);
7904 Next_Elmt
(Op_Elmt
);
7906 end Handle_Inherited_Private_Subprograms
;
7908 --------------------
7909 -- Set_Fixed_Prim --
7910 --------------------
7912 procedure Set_Fixed_Prim
(Pos
: Nat
) is
7914 pragma Assert
(Pos
<= Count_Prim
);
7915 Fixed_Prim
(Pos
) := True;
7917 when Constraint_Error
=>
7918 raise Program_Error
;
7922 -- In case of nested packages and public child package it may be
7923 -- necessary a special management on inherited subprograms so that
7924 -- the dispatch table is properly filled.
7926 if Ekind
(Scope
(Scope
(Typ
))) = E_Package
7927 and then Scope
(Scope
(Typ
)) /= Standard_Standard
7928 and then ((Is_Derived_Type
(Typ
) and then not Is_Private_Type
(Typ
))
7930 (Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
7931 and then Is_Generic_Type
(Typ
)))
7932 and then In_Open_Scopes
(Scope
(Etype
(Typ
)))
7933 and then Is_Base_Type
(Typ
)
7935 Handle_Inherited_Private_Subprograms
(Typ
);
7938 -- Second stage: Register fixed entries
7941 Prim_Elmt
:= First_Prim
;
7942 while Present
(Prim_Elmt
) loop
7943 Prim
:= Node
(Prim_Elmt
);
7945 -- Predefined primitives have a separate table and all its
7946 -- entries are at predefined fixed positions.
7948 if In_Predef_Prims_DT
(Prim
) then
7949 if Is_Predefined_Dispatching_Operation
(Prim
) then
7950 Set_DT_Position_Value
(Prim
,
7951 Default_Prim_Op_Position
(Prim
));
7953 else pragma Assert
(Present
(Alias
(Prim
)));
7954 Set_DT_Position_Value
(Prim
,
7955 Default_Prim_Op_Position
(Ultimate_Alias
(Prim
)));
7958 -- Overriding primitives of ancestor abstract interfaces
7960 elsif Present
(Interface_Alias
(Prim
))
7961 and then Is_Ancestor
7962 (Find_Dispatching_Type
(Interface_Alias
(Prim
)), Typ
,
7963 Use_Full_View
=> True)
7965 pragma Assert
(DT_Position
(Prim
) = No_Uint
7966 and then Present
(DTC_Entity
(Interface_Alias
(Prim
))));
7968 E
:= Interface_Alias
(Prim
);
7969 Set_DT_Position_Value
(Prim
, DT_Position
(E
));
7972 (DT_Position
(Alias
(Prim
)) = No_Uint
7973 or else DT_Position
(Alias
(Prim
)) = DT_Position
(E
));
7974 Set_DT_Position_Value
(Alias
(Prim
), DT_Position
(E
));
7975 Set_Fixed_Prim
(UI_To_Int
(DT_Position
(Prim
)));
7977 -- Overriding primitives must use the same entry as the overridden
7978 -- primitive. Note that the Alias of the operation is set when the
7979 -- operation is declared by a renaming, in which case it is not
7980 -- overriding. If it renames another primitive it will use the
7981 -- same dispatch table slot, but if it renames an operation in a
7982 -- nested package it's a new primitive and will have its own slot.
7984 elsif not Present
(Interface_Alias
(Prim
))
7985 and then Present
(Alias
(Prim
))
7986 and then Chars
(Prim
) = Chars
(Alias
(Prim
))
7987 and then Nkind
(Unit_Declaration_Node
(Prim
)) /=
7988 N_Subprogram_Renaming_Declaration
7991 Par_Type
: constant Entity_Id
:=
7992 Find_Dispatching_Type
(Alias
(Prim
));
7995 if Present
(Par_Type
)
7996 and then Par_Type
/= Typ
7997 and then Is_Ancestor
(Par_Type
, Typ
, Use_Full_View
=> True)
7998 and then Present
(DTC_Entity
(Alias
(Prim
)))
8001 Set_DT_Position_Value
(Prim
, DT_Position
(E
));
8003 if not Is_Predefined_Dispatching_Alias
(E
) then
8004 Set_Fixed_Prim
(UI_To_Int
(DT_Position
(E
)));
8010 Next_Elmt
(Prim_Elmt
);
8013 -- Third stage: Fix the position of all the new primitives. Entries
8014 -- associated with primitives covering interfaces are handled in a
8017 Prim_Elmt
:= First_Prim
;
8018 while Present
(Prim_Elmt
) loop
8019 Prim
:= Node
(Prim_Elmt
);
8021 -- Skip primitives previously set entries
8023 if DT_Position
(Prim
) /= No_Uint
then
8026 -- Primitives covering interface primitives are handled later
8028 elsif Present
(Interface_Alias
(Prim
)) then
8032 -- Take the next available position in the DT
8035 Nb_Prim
:= Nb_Prim
+ 1;
8036 pragma Assert
(Nb_Prim
<= Count_Prim
);
8037 exit when not Fixed_Prim
(Nb_Prim
);
8040 Set_DT_Position_Value
(Prim
, UI_From_Int
(Nb_Prim
));
8041 Set_Fixed_Prim
(Nb_Prim
);
8044 Next_Elmt
(Prim_Elmt
);
8048 -- Fourth stage: Complete the decoration of primitives covering
8049 -- interfaces (that is, propagate the DT_Position attribute from
8050 -- the aliased primitive)
8052 Prim_Elmt
:= First_Prim
;
8053 while Present
(Prim_Elmt
) loop
8054 Prim
:= Node
(Prim_Elmt
);
8056 if DT_Position
(Prim
) = No_Uint
8057 and then Present
(Interface_Alias
(Prim
))
8059 pragma Assert
(Present
(Alias
(Prim
))
8060 and then Find_Dispatching_Type
(Alias
(Prim
)) = Typ
);
8062 -- Check if this entry will be placed in the primary DT
8065 (Find_Dispatching_Type
(Interface_Alias
(Prim
)), Typ
,
8066 Use_Full_View
=> True)
8068 pragma Assert
(DT_Position
(Alias
(Prim
)) /= No_Uint
);
8069 Set_DT_Position_Value
(Prim
, DT_Position
(Alias
(Prim
)));
8071 -- Otherwise it will be placed in the secondary DT
8075 (DT_Position
(Interface_Alias
(Prim
)) /= No_Uint
);
8076 Set_DT_Position_Value
(Prim
,
8077 DT_Position
(Interface_Alias
(Prim
)));
8081 Next_Elmt
(Prim_Elmt
);
8084 -- Generate listing showing the contents of the dispatch tables. This
8085 -- action is done before some further static checks because in case of
8086 -- critical errors caused by a wrong dispatch table we need to see the
8087 -- contents of such table.
8089 if Debug_Flag_ZZ
then
8093 -- Final stage: Ensure that the table is correct plus some further
8094 -- verifications concerning the primitives.
8096 Prim_Elmt
:= First_Prim
;
8098 while Present
(Prim_Elmt
) loop
8099 Prim
:= Node
(Prim_Elmt
);
8101 -- At this point all the primitives MUST have a position in the
8104 if DT_Position
(Prim
) = No_Uint
then
8105 raise Program_Error
;
8108 -- Calculate real size of the dispatch table
8110 if not In_Predef_Prims_DT
(Prim
)
8111 and then UI_To_Int
(DT_Position
(Prim
)) > DT_Length
8113 DT_Length
:= UI_To_Int
(DT_Position
(Prim
));
8116 -- Ensure that the assigned position to non-predefined dispatching
8117 -- operations in the dispatch table is correct.
8119 if not Is_Predefined_Dispatching_Operation
(Prim
)
8120 and then not Is_Predefined_Dispatching_Alias
(Prim
)
8122 Validate_Position
(Prim
);
8125 if Chars
(Prim
) = Name_Finalize
then
8129 if Chars
(Prim
) = Name_Adjust
then
8133 -- An abstract operation cannot be declared in the private part for a
8134 -- visible abstract type, because it can't be overridden outside this
8135 -- package hierarchy. For explicit declarations this is checked at
8136 -- the point of declaration, but for inherited operations it must be
8137 -- done when building the dispatch table.
8139 -- Ada 2005 (AI-251): Primitives associated with interfaces are
8140 -- excluded from this check because interfaces must be visible in
8141 -- the public and private part (RM 7.3 (7.3/2))
8143 -- We disable this check in Relaxed_RM_Semantics mode, to accommodate
8146 if not Relaxed_RM_Semantics
8147 and then Is_Abstract_Type
(Typ
)
8148 and then Is_Abstract_Subprogram
(Prim
)
8149 and then Present
(Alias
(Prim
))
8150 and then not Is_Interface
8151 (Find_Dispatching_Type
(Ultimate_Alias
(Prim
)))
8152 and then not Present
(Interface_Alias
(Prim
))
8153 and then Is_Derived_Type
(Typ
)
8154 and then In_Private_Part
(Current_Scope
)
8156 List_Containing
(Parent
(Prim
)) =
8157 Private_Declarations
(Package_Specification
(Current_Scope
))
8158 and then Original_View_In_Visible_Part
(Typ
)
8160 -- We exclude Input and Output stream operations because
8161 -- Limited_Controlled inherits useless Input and Output stream
8162 -- operations from Root_Controlled, which can never be overridden.
8164 if not Is_TSS
(Prim
, TSS_Stream_Input
)
8166 not Is_TSS
(Prim
, TSS_Stream_Output
)
8169 ("abstract inherited private operation&" &
8170 " must be overridden (RM 3.9.3(10))",
8171 Parent
(Typ
), Prim
);
8175 Next_Elmt
(Prim_Elmt
);
8180 if Is_Controlled
(Typ
) then
8181 if not Finalized
then
8183 ("controlled type has no explicit Finalize method??", Typ
);
8185 elsif not Adjusted
then
8187 ("controlled type has no explicit Adjust method??", Typ
);
8191 -- Set the final size of the Dispatch Table
8193 Set_DT_Entry_Count
(The_Tag
, UI_From_Int
(DT_Length
));
8195 -- The derived type must have at least as many components as its parent
8196 -- (for root types Etype points to itself and the test cannot fail).
8198 if DT_Entry_Count
(The_Tag
) <
8199 DT_Entry_Count
(First_Tag_Component
(Parent_Typ
))
8201 raise Program_Error
;
8203 end Set_All_DT_Position
;
8205 --------------------------
8206 -- Set_CPP_Constructors --
8207 --------------------------
8209 procedure Set_CPP_Constructors
(Typ
: Entity_Id
) is
8211 function Gen_Parameters_Profile
(E
: Entity_Id
) return List_Id
;
8212 -- Duplicate the parameters profile of the imported C++ constructor
8213 -- adding the "this" pointer to the object as the additional first
8214 -- parameter under the usual form _Init : in out Typ.
8216 ----------------------------
8217 -- Gen_Parameters_Profile --
8218 ----------------------------
8220 function Gen_Parameters_Profile
(E
: Entity_Id
) return List_Id
is
8221 Loc
: constant Source_Ptr
:= Sloc
(E
);
8228 Make_Parameter_Specification
(Loc
,
8229 Defining_Identifier
=>
8230 Make_Defining_Identifier
(Loc
, Name_uInit
),
8232 Out_Present
=> True,
8233 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)));
8235 if Present
(Parameter_Specifications
(Parent
(E
))) then
8236 P
:= First
(Parameter_Specifications
(Parent
(E
)));
8237 while Present
(P
) loop
8239 Make_Parameter_Specification
(Loc
,
8240 Defining_Identifier
=>
8241 Make_Defining_Identifier
(Loc
,
8242 Chars
=> Chars
(Defining_Identifier
(P
))),
8243 Parameter_Type
=> New_Copy_Tree
(Parameter_Type
(P
)),
8244 Expression
=> New_Copy_Tree
(Expression
(P
))));
8250 end Gen_Parameters_Profile
;
8256 Found
: Boolean := False;
8262 Covers_Default_Constructor
: Entity_Id
:= Empty
;
8264 -- Start of processing for Set_CPP_Constructor
8267 pragma Assert
(Is_CPP_Class
(Typ
));
8269 -- Look for the constructor entities
8271 E
:= Next_Entity
(Typ
);
8272 while Present
(E
) loop
8273 if Ekind
(E
) = E_Function
8274 and then Is_Constructor
(E
)
8278 Parms
:= Gen_Parameters_Profile
(E
);
8279 IP
:= Make_Defining_Identifier
(Loc
, Make_Init_Proc_Name
(Typ
));
8281 -- Case 1: Constructor of untagged type
8283 -- If the C++ class has no virtual methods then the matching Ada
8284 -- type is an untagged record type. In such case there is no need
8285 -- to generate a wrapper of the C++ constructor because the _tag
8286 -- component is not available.
8288 if not Is_Tagged_Type
(Typ
) then
8290 (Make_Subprogram_Declaration
(Loc
,
8292 Make_Procedure_Specification
(Loc
,
8293 Defining_Unit_Name
=> IP
,
8294 Parameter_Specifications
=> Parms
)));
8296 Set_Init_Proc
(Typ
, IP
);
8297 Set_Is_Imported
(IP
);
8298 Set_Is_Constructor
(IP
);
8299 Set_Interface_Name
(IP
, Interface_Name
(E
));
8300 Set_Convention
(IP
, Convention_CPP
);
8302 Set_Has_Completion
(IP
);
8304 -- Case 2: Constructor of a tagged type
8306 -- In this case we generate the IP routine as a wrapper of the
8307 -- C++ constructor because IP must also save a copy of the _tag
8308 -- generated in the C++ side. The copy of the _tag is used by
8309 -- Build_CPP_Init_Procedure to elaborate derivations of C++ types.
8312 -- procedure IP (_init : in out Typ; ...) is
8313 -- procedure ConstructorP (_init : in out Typ; ...);
8314 -- pragma Import (ConstructorP);
8316 -- ConstructorP (_init, ...);
8317 -- if Typ._tag = null then
8318 -- Typ._tag := _init._tag;
8324 Body_Stmts
: constant List_Id
:= New_List
;
8325 Constructor_Id
: Entity_Id
;
8326 Constructor_Decl_Node
: Node_Id
;
8327 Init_Tags_List
: List_Id
;
8330 Constructor_Id
:= Make_Temporary
(Loc
, 'P');
8332 Constructor_Decl_Node
:=
8333 Make_Subprogram_Declaration
(Loc
,
8334 Make_Procedure_Specification
(Loc
,
8335 Defining_Unit_Name
=> Constructor_Id
,
8336 Parameter_Specifications
=> Parms
));
8338 Set_Is_Imported
(Constructor_Id
);
8339 Set_Is_Constructor
(Constructor_Id
);
8340 Set_Interface_Name
(Constructor_Id
, Interface_Name
(E
));
8341 Set_Convention
(Constructor_Id
, Convention_CPP
);
8342 Set_Is_Public
(Constructor_Id
);
8343 Set_Has_Completion
(Constructor_Id
);
8345 -- Build the init procedure as a wrapper of this constructor
8347 Parms
:= Gen_Parameters_Profile
(E
);
8349 -- Invoke the C++ constructor
8352 Actuals
: constant List_Id
:= New_List
;
8356 while Present
(P
) loop
8358 New_Occurrence_Of
(Defining_Identifier
(P
), Loc
));
8362 Append_To
(Body_Stmts
,
8363 Make_Procedure_Call_Statement
(Loc
,
8364 Name
=> New_Occurrence_Of
(Constructor_Id
, Loc
),
8365 Parameter_Associations
=> Actuals
));
8368 -- Initialize copies of C++ primary and secondary tags
8370 Init_Tags_List
:= New_List
;
8377 Tag_Elmt
:= First_Elmt
(Access_Disp_Table
(Typ
));
8378 Tag_Comp
:= First_Tag_Component
(Typ
);
8380 while Present
(Tag_Elmt
)
8381 and then Is_Tag
(Node
(Tag_Elmt
))
8383 -- Skip the following assertion with primary tags
8384 -- because Related_Type is not set on primary tag
8388 (Tag_Comp
= First_Tag_Component
(Typ
)
8389 or else Related_Type
(Node
(Tag_Elmt
))
8390 = Related_Type
(Tag_Comp
));
8392 Append_To
(Init_Tags_List
,
8393 Make_Assignment_Statement
(Loc
,
8395 New_Occurrence_Of
(Node
(Tag_Elmt
), Loc
),
8397 Make_Selected_Component
(Loc
,
8399 Make_Identifier
(Loc
, Name_uInit
),
8401 New_Occurrence_Of
(Tag_Comp
, Loc
))));
8403 Tag_Comp
:= Next_Tag_Component
(Tag_Comp
);
8404 Next_Elmt
(Tag_Elmt
);
8408 Append_To
(Body_Stmts
,
8409 Make_If_Statement
(Loc
,
8414 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))),
8417 Unchecked_Convert_To
(RTE
(RE_Tag
),
8418 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
))),
8419 Then_Statements
=> Init_Tags_List
));
8422 Make_Subprogram_Body
(Loc
,
8424 Make_Procedure_Specification
(Loc
,
8425 Defining_Unit_Name
=> IP
,
8426 Parameter_Specifications
=> Parms
),
8427 Declarations
=> New_List
(Constructor_Decl_Node
),
8428 Handled_Statement_Sequence
=>
8429 Make_Handled_Sequence_Of_Statements
(Loc
,
8430 Statements
=> Body_Stmts
,
8431 Exception_Handlers
=> No_List
));
8433 Discard_Node
(IP_Body
);
8434 Set_Init_Proc
(Typ
, IP
);
8438 -- If this constructor has parameters and all its parameters have
8439 -- defaults then it covers the default constructor. The semantic
8440 -- analyzer ensures that only one constructor with defaults covers
8441 -- the default constructor.
8443 if Present
(Parameter_Specifications
(Parent
(E
)))
8444 and then Needs_No_Actuals
(E
)
8446 Covers_Default_Constructor
:= IP
;
8453 -- If there are no constructors, mark the type as abstract since we
8454 -- won't be able to declare objects of that type.
8457 Set_Is_Abstract_Type
(Typ
);
8460 -- Handle constructor that has all its parameters with defaults and
8461 -- hence it covers the default constructor. We generate a wrapper IP
8462 -- which calls the covering constructor.
8464 if Present
(Covers_Default_Constructor
) then
8466 Body_Stmts
: List_Id
;
8469 Loc
:= Sloc
(Covers_Default_Constructor
);
8471 Body_Stmts
:= New_List
(
8472 Make_Procedure_Call_Statement
(Loc
,
8474 New_Occurrence_Of
(Covers_Default_Constructor
, Loc
),
8475 Parameter_Associations
=> New_List
(
8476 Make_Identifier
(Loc
, Name_uInit
))));
8478 IP
:= Make_Defining_Identifier
(Loc
, Make_Init_Proc_Name
(Typ
));
8481 Make_Subprogram_Body
(Loc
,
8483 Make_Procedure_Specification
(Loc
,
8484 Defining_Unit_Name
=> IP
,
8485 Parameter_Specifications
=> New_List
(
8486 Make_Parameter_Specification
(Loc
,
8487 Defining_Identifier
=>
8488 Make_Defining_Identifier
(Loc
, Name_uInit
),
8489 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)))),
8491 Declarations
=> No_List
,
8493 Handled_Statement_Sequence
=>
8494 Make_Handled_Sequence_Of_Statements
(Loc
,
8495 Statements
=> Body_Stmts
,
8496 Exception_Handlers
=> No_List
));
8498 Discard_Node
(IP_Body
);
8499 Set_Init_Proc
(Typ
, IP
);
8503 -- If the CPP type has constructors then it must import also the default
8504 -- C++ constructor. It is required for default initialization of objects
8505 -- of the type. It is also required to elaborate objects of Ada types
8506 -- that are defined as derivations of this CPP type.
8508 if Has_CPP_Constructors
(Typ
)
8509 and then No
(Init_Proc
(Typ
))
8511 Error_Msg_N
("??default constructor must be imported from C++", Typ
);
8513 end Set_CPP_Constructors
;
8515 ---------------------------
8516 -- Set_DT_Position_Value --
8517 ---------------------------
8519 procedure Set_DT_Position_Value
(Prim
: Entity_Id
; Value
: Uint
) is
8521 Set_DT_Position
(Prim
, Value
);
8523 -- Propagate the value to the wrapped subprogram (if one is present)
8525 if Ekind_In
(Prim
, E_Function
, E_Procedure
)
8526 and then Is_Primitive_Wrapper
(Prim
)
8527 and then Present
(Wrapped_Entity
(Prim
))
8528 and then Is_Dispatching_Operation
(Wrapped_Entity
(Prim
))
8530 Set_DT_Position
(Wrapped_Entity
(Prim
), Value
);
8532 end Set_DT_Position_Value
;
8534 --------------------------
8535 -- Set_DTC_Entity_Value --
8536 --------------------------
8538 procedure Set_DTC_Entity_Value
8539 (Tagged_Type
: Entity_Id
;
8543 if Present
(Interface_Alias
(Prim
))
8544 and then Is_Interface
8545 (Find_Dispatching_Type
(Interface_Alias
(Prim
)))
8547 Set_DTC_Entity
(Prim
,
8550 Iface
=> Find_Dispatching_Type
(Interface_Alias
(Prim
))));
8552 Set_DTC_Entity
(Prim
,
8553 First_Tag_Component
(Tagged_Type
));
8556 -- Propagate the value to the wrapped subprogram (if one is present)
8558 if Ekind_In
(Prim
, E_Function
, E_Procedure
)
8559 and then Is_Primitive_Wrapper
(Prim
)
8560 and then Present
(Wrapped_Entity
(Prim
))
8561 and then Is_Dispatching_Operation
(Wrapped_Entity
(Prim
))
8563 Set_DTC_Entity
(Wrapped_Entity
(Prim
), DTC_Entity
(Prim
));
8565 end Set_DTC_Entity_Value
;
8571 function Tagged_Kind
(T
: Entity_Id
) return Node_Id
is
8572 Conc_Typ
: Entity_Id
;
8573 Loc
: constant Source_Ptr
:= Sloc
(T
);
8577 (Is_Tagged_Type
(T
) and then RTE_Available
(RE_Tagged_Kind
));
8581 if Is_Abstract_Type
(T
) then
8582 if Is_Limited_Record
(T
) then
8583 return New_Occurrence_Of
8584 (RTE
(RE_TK_Abstract_Limited_Tagged
), Loc
);
8586 return New_Occurrence_Of
8587 (RTE
(RE_TK_Abstract_Tagged
), Loc
);
8592 elsif Is_Concurrent_Record_Type
(T
) then
8593 Conc_Typ
:= Corresponding_Concurrent_Type
(T
);
8595 if Present
(Full_View
(Conc_Typ
)) then
8596 Conc_Typ
:= Full_View
(Conc_Typ
);
8599 if Ekind
(Conc_Typ
) = E_Protected_Type
then
8600 return New_Occurrence_Of
(RTE
(RE_TK_Protected
), Loc
);
8602 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
8603 return New_Occurrence_Of
(RTE
(RE_TK_Task
), Loc
);
8606 -- Regular tagged kinds
8609 if Is_Limited_Record
(T
) then
8610 return New_Occurrence_Of
(RTE
(RE_TK_Limited_Tagged
), Loc
);
8612 return New_Occurrence_Of
(RTE
(RE_TK_Tagged
), Loc
);
8621 procedure Write_DT
(Typ
: Entity_Id
) is
8626 -- Protect this procedure against wrong usage. Required because it will
8627 -- be used directly from GDB
8629 if not (Typ
<= Last_Node_Id
)
8630 or else not Is_Tagged_Type
(Typ
)
8632 Write_Str
("wrong usage: Write_DT must be used with tagged types");
8637 Write_Int
(Int
(Typ
));
8639 Write_Name
(Chars
(Typ
));
8641 if Is_Interface
(Typ
) then
8642 Write_Str
(" is interface");
8647 Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
8648 while Present
(Elmt
) loop
8649 Prim
:= Node
(Elmt
);
8652 -- Indicate if this primitive will be allocated in the primary
8653 -- dispatch table or in a secondary dispatch table associated
8654 -- with an abstract interface type
8656 if Present
(DTC_Entity
(Prim
)) then
8657 if Etype
(DTC_Entity
(Prim
)) = RTE
(RE_Tag
) then
8664 -- Output the node of this primitive operation and its name
8666 Write_Int
(Int
(Prim
));
8669 if Is_Predefined_Dispatching_Operation
(Prim
) then
8670 Write_Str
("(predefined) ");
8673 -- Prefix the name of the primitive with its corresponding tagged
8674 -- type to facilitate seeing inherited primitives.
8676 if Present
(Alias
(Prim
)) then
8678 (Chars
(Find_Dispatching_Type
(Ultimate_Alias
(Prim
))));
8680 Write_Name
(Chars
(Typ
));
8684 Write_Name
(Chars
(Prim
));
8686 -- Indicate if this primitive has an aliased primitive
8688 if Present
(Alias
(Prim
)) then
8689 Write_Str
(" (alias = ");
8690 Write_Int
(Int
(Alias
(Prim
)));
8692 -- If the DTC_Entity attribute is already set we can also output
8693 -- the name of the interface covered by this primitive (if any).
8695 if Ekind_In
(Alias
(Prim
), E_Function
, E_Procedure
)
8696 and then Present
(DTC_Entity
(Alias
(Prim
)))
8697 and then Is_Interface
(Scope
(DTC_Entity
(Alias
(Prim
))))
8699 Write_Str
(" from interface ");
8700 Write_Name
(Chars
(Scope
(DTC_Entity
(Alias
(Prim
)))));
8703 if Present
(Interface_Alias
(Prim
)) then
8704 Write_Str
(", AI_Alias of ");
8706 if Is_Null_Interface_Primitive
(Interface_Alias
(Prim
)) then
8707 Write_Str
("null primitive ");
8711 (Chars
(Find_Dispatching_Type
(Interface_Alias
(Prim
))));
8713 Write_Int
(Int
(Interface_Alias
(Prim
)));
8719 -- Display the final position of this primitive in its associated
8720 -- (primary or secondary) dispatch table.
8722 if Present
(DTC_Entity
(Prim
))
8723 and then DT_Position
(Prim
) /= No_Uint
8725 Write_Str
(" at #");
8726 Write_Int
(UI_To_Int
(DT_Position
(Prim
)));
8729 if Is_Abstract_Subprogram
(Prim
) then
8730 Write_Str
(" is abstract;");
8732 -- Check if this is a null primitive
8734 elsif Comes_From_Source
(Prim
)
8735 and then Ekind
(Prim
) = E_Procedure
8736 and then Null_Present
(Parent
(Prim
))
8738 Write_Str
(" is null;");
8741 if Is_Eliminated
(Ultimate_Alias
(Prim
)) then
8742 Write_Str
(" (eliminated)");
8745 if Is_Imported
(Prim
)
8746 and then Convention
(Prim
) = Convention_CPP
8748 Write_Str
(" (C++)");