1------------------------------------------------------------------------------ 2-- -- 3-- GNAT COMPILER COMPONENTS -- 4-- -- 5-- S E M _ C H 6 -- 6-- -- 7-- S p e c -- 8-- -- 9-- Copyright (C) 1992-2012, Free Software Foundation, Inc. -- 10-- -- 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. -- 20-- -- 21-- GNAT was originally developed by the GNAT team at New York University. -- 22-- Extensive contributions were provided by Ada Core Technologies Inc. -- 23-- -- 24------------------------------------------------------------------------------ 25 26with Types; use Types; 27package Sem_Ch6 is 28 29 type Conformance_Type is 30 (Type_Conformant, Mode_Conformant, Subtype_Conformant, Fully_Conformant); 31 -- pragma Ordered (Conformance_Type); 32 -- Why is above line commented out ??? 33 -- Conformance type used in conformance checks between specs and bodies, 34 -- and for overriding. The literals match the RM definitions of the 35 -- corresponding terms. This is an ordered type, since each conformance 36 -- type is stronger than the ones preceding it. 37 38 procedure Analyze_Abstract_Subprogram_Declaration (N : Node_Id); 39 procedure Analyze_Expression_Function (N : Node_Id); 40 procedure Analyze_Extended_Return_Statement (N : Node_Id); 41 procedure Analyze_Function_Call (N : Node_Id); 42 procedure Analyze_Operator_Symbol (N : Node_Id); 43 procedure Analyze_Parameter_Association (N : Node_Id); 44 procedure Analyze_Procedure_Call (N : Node_Id); 45 procedure Analyze_Simple_Return_Statement (N : Node_Id); 46 procedure Analyze_Subprogram_Declaration (N : Node_Id); 47 procedure Analyze_Subprogram_Body (N : Node_Id); 48 49 function Analyze_Subprogram_Specification (N : Node_Id) return Entity_Id; 50 -- Analyze subprogram specification in both subprogram declarations 51 -- and body declarations. Returns the defining entity for the 52 -- specification N. 53 54 procedure Cannot_Inline 55 (Msg : String; 56 N : Node_Id; 57 Subp : Entity_Id; 58 Is_Serious : Boolean := False); 59 -- This procedure is called if the node N, an instance of a call to 60 -- subprogram Subp, cannot be inlined. Msg is the message to be issued, 61 -- which ends with ? (it does not end with ?p?, this routine takes care of 62 -- the need to change ? to ?p?). Temporarily the behavior of this routine 63 -- depends on the value of -gnatd.k: 64 -- 65 -- * If -gnatd.k is not set (ie. old inlining model) then if Subp has 66 -- a pragma Always_Inlined, then an error message is issued (by 67 -- removing the last character of Msg). If Subp is not Always_Inlined, 68 -- then a warning is issued if the flag Ineffective_Inline_Warnings 69 -- is set, adding ?p to the msg, and if not, the call has no effect. 70 -- 71 -- * If -gnatd.k is set (ie. new inlining model) then: 72 -- - If Is_Serious is true, then an error is reported (by removing the 73 -- last character of Msg); 74 -- 75 -- - otherwise: 76 -- 77 -- * Compiling without optimizations if Subp has a pragma 78 -- Always_Inlined, then an error message is issued; if Subp is 79 -- not Always_Inlined, then a warning is issued if the flag 80 -- Ineffective_Inline_Warnings is set (adding p?), and if not, 81 -- the call has no effect. 82 -- 83 -- * Compiling with optimizations then a warning is issued if the 84 -- flag Ineffective_Inline_Warnings is set (adding p?); otherwise 85 -- no effect since inlining may be performed by the backend. 86 87 procedure Check_Conventions (Typ : Entity_Id); 88 -- Ada 2005 (AI-430): Check that the conventions of all inherited and 89 -- overridden dispatching operations of type Typ are consistent with their 90 -- respective counterparts. 91 92 procedure Check_Delayed_Subprogram (Designator : Entity_Id); 93 -- Designator can be a E_Subprogram_Type, E_Procedure or E_Function. If a 94 -- type in its profile depends on a private type without a full 95 -- declaration, indicate that the subprogram or type is delayed. 96 97 procedure Check_Discriminant_Conformance 98 (N : Node_Id; 99 Prev : Entity_Id; 100 Prev_Loc : Node_Id); 101 -- Check that the discriminants of a full type N fully conform to the 102 -- discriminants of the corresponding partial view Prev. Prev_Loc indicates 103 -- the source location of the partial view, which may be different than 104 -- Prev in the case of private types. 105 106 procedure Check_Fully_Conformant 107 (New_Id : Entity_Id; 108 Old_Id : Entity_Id; 109 Err_Loc : Node_Id := Empty); 110 -- Check that two callable entities (subprograms, entries, literals) 111 -- are fully conformant, post error message if not (RM 6.3.1(17)) with 112 -- the flag being placed on the Err_Loc node if it is specified, and 113 -- on the appropriate component of the New_Id construct if not. Note: 114 -- when checking spec/body conformance, New_Id must be the body entity 115 -- and Old_Id is the spec entity (the code in the implementation relies 116 -- on this ordering, and in any case, this makes sense, since if flags 117 -- are to be placed on the construct, they clearly belong on the body. 118 119 procedure Check_Mode_Conformant 120 (New_Id : Entity_Id; 121 Old_Id : Entity_Id; 122 Err_Loc : Node_Id := Empty; 123 Get_Inst : Boolean := False); 124 -- Check that two callable entities (subprograms, entries, literals) 125 -- are mode conformant, post error message if not (RM 6.3.1(15)) with 126 -- the flag being placed on the Err_Loc node if it is specified, and 127 -- on the appropriate component of the New_Id construct if not. The 128 -- argument Get_Inst is set to True when this is a check against a 129 -- formal access-to-subprogram type, indicating that mapping of types 130 -- is needed. 131 132 procedure Check_Overriding_Indicator 133 (Subp : Entity_Id; 134 Overridden_Subp : Entity_Id; 135 Is_Primitive : Boolean); 136 -- Verify the consistency of an overriding_indicator given for subprogram 137 -- declaration, body, renaming, or instantiation. Overridden_Subp is set 138 -- if the scope where we are introducing the subprogram contains a 139 -- type-conformant subprogram that becomes hidden by the new subprogram. 140 -- Is_Primitive indicates whether the subprogram is primitive. 141 142 procedure Check_Subprogram_Contract (Spec_Id : Entity_Id); 143 -- Spec_Id is the spec entity for a subprogram. This routine issues 144 -- warnings on suspicious contracts if Warn_On_Suspicious_Contract is set. 145 146 procedure Check_Subtype_Conformant 147 (New_Id : Entity_Id; 148 Old_Id : Entity_Id; 149 Err_Loc : Node_Id := Empty; 150 Skip_Controlling_Formals : Boolean := False; 151 Get_Inst : Boolean := False); 152 -- Check that two callable entities (subprograms, entries, literals) 153 -- are subtype conformant, post error message if not (RM 6.3.1(16)), 154 -- the flag being placed on the Err_Loc node if it is specified, and 155 -- on the appropriate component of the New_Id construct if not. 156 -- Skip_Controlling_Formals is True when checking the conformance of 157 -- a subprogram that implements an interface operation. In that case, 158 -- only the non-controlling formals can (and must) be examined. The 159 -- argument Get_Inst is set to True when this is a check against a 160 -- formal access-to-subprogram type, indicating that mapping of types 161 -- is needed. 162 163 procedure Check_Type_Conformant 164 (New_Id : Entity_Id; 165 Old_Id : Entity_Id; 166 Err_Loc : Node_Id := Empty); 167 -- Check that two callable entities (subprograms, entries, literals) 168 -- are type conformant, post error message if not (RM 6.3.1(14)) with 169 -- the flag being placed on the Err_Loc node if it is specified, and 170 -- on the appropriate component of the New_Id construct if not. 171 172 function Conforming_Types 173 (T1 : Entity_Id; 174 T2 : Entity_Id; 175 Ctype : Conformance_Type; 176 Get_Inst : Boolean := False) return Boolean; 177 -- Check that the types of two formal parameters are conforming. In most 178 -- cases this is just a name comparison, but within an instance it involves 179 -- generic actual types, and in the presence of anonymous access types 180 -- it must examine the designated types. The argument Get_Inst is set to 181 -- True when this is a check against a formal access-to-subprogram type, 182 -- indicating that mapping of types is needed. 183 184 procedure Create_Extra_Formals (E : Entity_Id); 185 -- For each parameter of a subprogram or entry that requires an additional 186 -- formal (such as for access parameters and indefinite discriminated 187 -- parameters), creates the appropriate formal and attach it to its 188 -- associated parameter. Each extra formal will also be appended to 189 -- the end of Subp's parameter list (with each subsequent extra formal 190 -- being attached to the preceding extra formal). 191 192 function Find_Corresponding_Spec 193 (N : Node_Id; 194 Post_Error : Boolean := True) return Entity_Id; 195 -- Use the subprogram specification in the body to retrieve the previous 196 -- subprogram declaration, if any. 197 198 function Fully_Conformant (New_Id, Old_Id : Entity_Id) return Boolean; 199 -- Determine whether two callable entities (subprograms, entries, 200 -- literals) are fully conformant (RM 6.3.1(17)) 201 202 function Fully_Conformant_Expressions 203 (Given_E1 : Node_Id; 204 Given_E2 : Node_Id) return Boolean; 205 -- Determines if two (non-empty) expressions are fully conformant 206 -- as defined by (RM 6.3.1(18-21)) 207 208 function Fully_Conformant_Discrete_Subtypes 209 (Given_S1 : Node_Id; 210 Given_S2 : Node_Id) return Boolean; 211 -- Determines if two subtype definitions are fully conformant. Used 212 -- for entry family conformance checks (RM 6.3.1 (24)). 213 214 procedure Install_Entity (E : Entity_Id); 215 -- Place a single entity on the visibility chain 216 217 procedure Install_Formals (Id : Entity_Id); 218 -- On entry to a subprogram body, make the formals visible. Note that 219 -- simply placing the subprogram on the scope stack is not sufficient: 220 -- the formals must become the current entities for their names. This 221 -- procedure is also used to get visibility to the formals when analyzing 222 -- preconditions and postconditions appearing in the spec. 223 224 function Is_Interface_Conformant 225 (Tagged_Type : Entity_Id; 226 Iface_Prim : Entity_Id; 227 Prim : Entity_Id) return Boolean; 228 -- Returns true if both primitives have a matching name (including support 229 -- for names of inherited private primitives --which have suffix 'P'), they 230 -- are type conformant, and Prim is defined in the scope of Tagged_Type. 231 -- Special management is done for functions returning interfaces. 232 233 procedure List_Inherited_Pre_Post_Aspects (E : Entity_Id); 234 -- E is the entity for a subprogram or generic subprogram spec. This call 235 -- lists all inherited Pre/Post aspects if List_Inherited_Pre_Post is True. 236 237 function Mode_Conformant (New_Id, Old_Id : Entity_Id) return Boolean; 238 -- Determine whether two callable entities (subprograms, entries, 239 -- literals) are mode conformant (RM 6.3.1(15)) 240 241 procedure New_Overloaded_Entity 242 (S : Entity_Id; 243 Derived_Type : Entity_Id := Empty); 244 -- Process new overloaded entity. Overloaded entities are created by 245 -- enumeration type declarations, subprogram specifications, entry 246 -- declarations, and (implicitly) by type derivations. If Derived_Type 247 -- is non-empty then this is a subprogram derived for that type. 248 249 procedure Process_Formals (T : List_Id; Related_Nod : Node_Id); 250 -- Enter the formals in the scope of the subprogram or entry, and 251 -- analyze default expressions if any. The implicit types created for 252 -- access parameter are attached to the Related_Nod which comes from the 253 -- context. 254 255 procedure Reference_Body_Formals (Spec : Entity_Id; Bod : Entity_Id); 256 -- If there is a separate spec for a subprogram or generic subprogram, the 257 -- formals of the body are treated as references to the corresponding 258 -- formals of the spec. This reference does not count as an actual use of 259 -- the formal, in order to diagnose formals that are unused in the body. 260 -- This procedure is also used in renaming_as_body declarations, where 261 -- the formals of the specification must be treated as body formals that 262 -- correspond to the previous subprogram declaration, and not as new 263 -- entities with their defining entry in the cross-reference information. 264 265 procedure Set_Actual_Subtypes (N : Node_Id; Subp : Entity_Id); 266 -- If the formals of a subprogram are unconstrained, build a subtype 267 -- declaration that uses the bounds or discriminants of the actual to 268 -- construct an actual subtype for them. This is an optimization that 269 -- is done only in some cases where the actual subtype cannot change 270 -- during execution of the subprogram. By setting the actual subtype 271 -- once, we avoid recomputing it unnecessarily. 272 273 procedure Set_Formal_Mode (Formal_Id : Entity_Id); 274 -- Set proper Ekind to reflect formal mode (in, out, in out) 275 276 function Subtype_Conformant 277 (New_Id : Entity_Id; 278 Old_Id : Entity_Id; 279 Skip_Controlling_Formals : Boolean := False) return Boolean; 280 -- Determine whether two callable entities (subprograms, entries, literals) 281 -- are subtype conformant (RM 6.3.1(16)). Skip_Controlling_Formals is True 282 -- when checking the conformance of a subprogram that implements an 283 -- interface operation. In that case, only the non-controlling formals 284 -- can (and must) be examined. 285 286 function Type_Conformant 287 (New_Id : Entity_Id; 288 Old_Id : Entity_Id; 289 Skip_Controlling_Formals : Boolean := False) return Boolean; 290 -- Determine whether two callable entities (subprograms, entries, literals) 291 -- are type conformant (RM 6.3.1(14)). Skip_Controlling_Formals is True 292 -- when checking the conformance of a subprogram that implements an 293 -- interface operation. In that case, only the non-controlling formals 294 -- can (and must) be examined. 295 296 procedure Valid_Operator_Definition (Designator : Entity_Id); 297 -- Verify that an operator definition has the proper number of formals 298 299end Sem_Ch6; 300