annotate gcc/ada/sem_disp.ads @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT COMPILER COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- S E M _ D I S P --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
9 -- Copyright (C) 1992-2018, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
kono
parents:
diff changeset
17 -- for more details. You should have received a copy of the GNU General --
kono
parents:
diff changeset
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
kono
parents:
diff changeset
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
kono
parents:
diff changeset
20 -- --
kono
parents:
diff changeset
21 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
23 -- --
kono
parents:
diff changeset
24 ------------------------------------------------------------------------------
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 -- This package contains routines involved in tagged types and dynamic
kono
parents:
diff changeset
27 -- dispatching.
kono
parents:
diff changeset
28
kono
parents:
diff changeset
29 with Types; use Types;
kono
parents:
diff changeset
30 package Sem_Disp is
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 procedure Check_Controlling_Formals (Typ : Entity_Id; Subp : Entity_Id);
kono
parents:
diff changeset
33 -- Check that all controlling parameters of Subp are of type Typ, that
kono
parents:
diff changeset
34 -- defaults for controlling parameters are tag-indeterminate, and that the
kono
parents:
diff changeset
35 -- nominal subtype of the parameters and result statically match the first
kono
parents:
diff changeset
36 -- subtype of the controlling type. Issues appropriate error messages if
kono
parents:
diff changeset
37 -- any of these requirements is not met.
kono
parents:
diff changeset
38
kono
parents:
diff changeset
39 procedure Check_Dispatching_Call (N : Node_Id);
kono
parents:
diff changeset
40 -- Check if the call N is a dispatching call. The subprogram is known to be
kono
parents:
diff changeset
41 -- a dispatching operation. The call is dispatching if all the controlling
kono
parents:
diff changeset
42 -- actuals are dynamically tagged. This procedure is called after overload
kono
parents:
diff changeset
43 -- resolution, so the call is known to be unambiguous.
kono
parents:
diff changeset
44
kono
parents:
diff changeset
45 procedure Check_Dispatching_Operation (Subp, Old_Subp : Entity_Id);
kono
parents:
diff changeset
46 -- Add Subp to the list of primitive operations of the corresponding type
kono
parents:
diff changeset
47 -- if it has a parameter of this type and is defined at a proper place for
kono
parents:
diff changeset
48 -- primitive operations (new primitives are only defined in package spec,
kono
parents:
diff changeset
49 -- overridden operation can be defined in any scope). If Old_Subp is not
kono
parents:
diff changeset
50 -- Empty we are in the overriding case. If the tagged type associated with
kono
parents:
diff changeset
51 -- Subp is a concurrent type (case that occurs when the type is declared
kono
parents:
diff changeset
52 -- in a generic because the analysis of generics disables generation of the
kono
parents:
diff changeset
53 -- corresponding record) then this routine does not add Subp to the list of
kono
parents:
diff changeset
54 -- primitive operations but leaves Subp decorated as dispatching operation
kono
parents:
diff changeset
55 -- to enable checks associated with the Object.Operation notation.
kono
parents:
diff changeset
56
kono
parents:
diff changeset
57 procedure Check_Operation_From_Incomplete_Type
kono
parents:
diff changeset
58 (Subp : Entity_Id;
kono
parents:
diff changeset
59 Typ : Entity_Id);
kono
parents:
diff changeset
60 -- If a primitive operation was defined for the incomplete view of the
kono
parents:
diff changeset
61 -- type, and the full type declaration is a derived type definition,
kono
parents:
diff changeset
62 -- the operation may override an inherited one.
kono
parents:
diff changeset
63 -- Need more description here, what are the parameters, and what does
kono
parents:
diff changeset
64 -- this call actually do???
kono
parents:
diff changeset
65
kono
parents:
diff changeset
66 procedure Check_Operation_From_Private_View (Subp, Old_Subp : Entity_Id);
kono
parents:
diff changeset
67 -- Add Old_Subp to the list of primitive operations of the corresponding
kono
parents:
diff changeset
68 -- tagged type if it is the full view of a private tagged type. The Alias
kono
parents:
diff changeset
69 -- of Old_Subp is adjusted to point to the inherited procedure of the
kono
parents:
diff changeset
70 -- full view because it is always this one which has to be called.
kono
parents:
diff changeset
71 -- What is Subp used for???
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73 function Covered_Interface_Op (Prim : Entity_Id) return Entity_Id;
kono
parents:
diff changeset
74 -- Returns the interface primitive that Prim covers, when its controlling
kono
parents:
diff changeset
75 -- type has progenitors.
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 function Find_Controlling_Arg (N : Node_Id) return Node_Id;
kono
parents:
diff changeset
78 -- Returns the actual controlling argument if N is dynamically tagged, and
kono
parents:
diff changeset
79 -- Empty if it is not dynamically tagged.
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 function Find_Dispatching_Type (Subp : Entity_Id) return Entity_Id;
kono
parents:
diff changeset
82 -- Check whether the subprogram Subp is dispatching, and find the tagged
kono
parents:
diff changeset
83 -- type of the controlling argument or arguments. Returns Empty if Subp
kono
parents:
diff changeset
84 -- is not a dispatching operation.
kono
parents:
diff changeset
85
kono
parents:
diff changeset
86 function Find_Primitive_Covering_Interface
kono
parents:
diff changeset
87 (Tagged_Type : Entity_Id;
kono
parents:
diff changeset
88 Iface_Prim : Entity_Id) return Entity_Id;
kono
parents:
diff changeset
89 -- Search the homonym chain for the primitive of Tagged_Type that covers
kono
parents:
diff changeset
90 -- Iface_Prim. The homonym chain traversal is required to catch primitives
kono
parents:
diff changeset
91 -- associated with the partial view of private types when processing the
kono
parents:
diff changeset
92 -- corresponding full view. If the entity is not found, then search for it
kono
parents:
diff changeset
93 -- in the list of primitives of Tagged_Type. This latter search is needed
kono
parents:
diff changeset
94 -- when the interface primitive is covered by a private subprogram. If the
kono
parents:
diff changeset
95 -- primitive has not been covered yet then return the entity that will be
kono
parents:
diff changeset
96 -- overridden when the primitive is covered (that is, return the entity
kono
parents:
diff changeset
97 -- whose alias attribute references the interface primitive). If none of
kono
parents:
diff changeset
98 -- these entities is found then return Empty.
kono
parents:
diff changeset
99
kono
parents:
diff changeset
100 type Subprogram_List is array (Nat range <>) of Entity_Id;
kono
parents:
diff changeset
101 -- Type returned by Inherited_Subprograms function
kono
parents:
diff changeset
102
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
103 generic
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
104 with function Find_DT (Subp : Entity_Id) return Entity_Id;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
105 package Inheritance_Utilities is
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
106
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
107 -- This package provides generic versions of inheritance utilities
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
108 -- provided here. These versions are used in GNATprove backend to adapt
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
109 -- these utilities to GNATprove specific version of visibility of types.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
110
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
111 function Inherited_Subprograms
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
112 (S : Entity_Id;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
113 No_Interfaces : Boolean := False;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
114 Interfaces_Only : Boolean := False;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
115 One_Only : Boolean := False) return Subprogram_List;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
116
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
117 function Is_Overriding_Subprogram (E : Entity_Id) return Boolean;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
118 end Inheritance_Utilities;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
119
111
kono
parents:
diff changeset
120 function Inherited_Subprograms
kono
parents:
diff changeset
121 (S : Entity_Id;
kono
parents:
diff changeset
122 No_Interfaces : Boolean := False;
kono
parents:
diff changeset
123 Interfaces_Only : Boolean := False;
kono
parents:
diff changeset
124 One_Only : Boolean := False) return Subprogram_List;
kono
parents:
diff changeset
125 -- Given the spec of a subprogram, this function gathers any inherited
kono
parents:
diff changeset
126 -- subprograms from direct inheritance or via interfaces. The result is an
kono
parents:
diff changeset
127 -- array of Entity_Ids of the specs of inherited subprograms. Returns a
kono
parents:
diff changeset
128 -- null array if passed an Empty spec id. Note that the returned array
kono
parents:
diff changeset
129 -- only includes subprograms and generic subprograms (and excludes any
kono
parents:
diff changeset
130 -- other inherited entities, in particular enumeration literals). If
kono
parents:
diff changeset
131 -- No_Interfaces is True, only return inherited subprograms not coming
kono
parents:
diff changeset
132 -- from an interface. If Interfaces_Only is True, only return inherited
kono
parents:
diff changeset
133 -- subprograms from interfaces. Otherwise, subprograms inherited directly
kono
parents:
diff changeset
134 -- come first, starting with the closest ancestors, and are followed by
kono
parents:
diff changeset
135 -- subprograms inherited from interfaces. At most one of No_Interfaces
kono
parents:
diff changeset
136 -- and Interfaces_Only should be True.
kono
parents:
diff changeset
137 --
kono
parents:
diff changeset
138 -- If One_Only is set, the search is discontinued as soon as one entry
kono
parents:
diff changeset
139 -- is found. In this case the resulting array is either null or contains
kono
parents:
diff changeset
140 -- exactly one element.
kono
parents:
diff changeset
141
kono
parents:
diff changeset
142 function Is_Dynamically_Tagged (N : Node_Id) return Boolean;
kono
parents:
diff changeset
143 -- Used to determine whether a call is dispatching, i.e. if it is
kono
parents:
diff changeset
144 -- an expression of a class_Wide type, or a call to a function with
kono
parents:
diff changeset
145 -- controlling result where at least one operand is dynamically tagged.
kono
parents:
diff changeset
146 -- Also used to determine whether an entity has a class-wide type, or a
kono
parents:
diff changeset
147 -- function call that dispatches on the result. Used to verify that all the
kono
parents:
diff changeset
148 -- dependent expressions in a conditional expression are equally tagged.
kono
parents:
diff changeset
149
kono
parents:
diff changeset
150 function Is_Null_Interface_Primitive (E : Entity_Id) return Boolean;
kono
parents:
diff changeset
151 -- Returns True if E is a null procedure that is an interface primitive
kono
parents:
diff changeset
152
kono
parents:
diff changeset
153 function Is_Overriding_Subprogram (E : Entity_Id) return Boolean;
kono
parents:
diff changeset
154 -- Returns True if E is an overriding subprogram
kono
parents:
diff changeset
155
kono
parents:
diff changeset
156 function Is_Tag_Indeterminate (N : Node_Id) return Boolean;
kono
parents:
diff changeset
157 -- Returns true if the expression N is tag-indeterminate. An expression
kono
parents:
diff changeset
158 -- is tag-indeterminate if it is a call that dispatches on result, and all
kono
parents:
diff changeset
159 -- controlling operands are also indeterminate. Such a function call may
kono
parents:
diff changeset
160 -- inherit a tag from an enclosing call.
kono
parents:
diff changeset
161
kono
parents:
diff changeset
162 procedure Override_Dispatching_Operation
kono
parents:
diff changeset
163 (Tagged_Type : Entity_Id;
kono
parents:
diff changeset
164 Prev_Op : Entity_Id;
kono
parents:
diff changeset
165 New_Op : Entity_Id;
kono
parents:
diff changeset
166 Is_Wrapper : Boolean := False);
kono
parents:
diff changeset
167 -- Replace an implicit dispatching operation of the type Tagged_Type
kono
parents:
diff changeset
168 -- with an explicit one. Prev_Op is an inherited primitive operation which
kono
parents:
diff changeset
169 -- is overridden by the explicit declaration of New_Op. Is_Wrapper is
kono
parents:
diff changeset
170 -- True when New_Op is an internally generated wrapper of a controlling
kono
parents:
diff changeset
171 -- function. The caller checks that Tagged_Type is indeed a tagged type.
kono
parents:
diff changeset
172
kono
parents:
diff changeset
173 procedure Propagate_Tag (Control : Node_Id; Actual : Node_Id);
kono
parents:
diff changeset
174 -- If a function call is tag-indeterminate, its controlling argument is
kono
parents:
diff changeset
175 -- found in the context: either an enclosing call, or the left-hand side
kono
parents:
diff changeset
176 -- of the enclosing assignment statement. The tag must be propagated
kono
parents:
diff changeset
177 -- recursively to the tag-indeterminate actuals of the call.
kono
parents:
diff changeset
178 -- Need clear description of the parameters Control and Actual, especially
kono
parents:
diff changeset
179 -- since the comments above refer to actuals in the plural ???
kono
parents:
diff changeset
180
kono
parents:
diff changeset
181 end Sem_Disp;