| 1 |
------------------------------------------------------------------------------ |
| 2 |
-- -- |
| 3 |
-- GNAT COMPILER COMPONENTS -- |
| 4 |
-- -- |
| 5 |
-- S E M _ R E S -- |
| 6 |
-- -- |
| 7 |
-- S p e c -- |
| 8 |
-- -- |
| 9 |
-- Copyright (C) 1992-2025, 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 |
|
| 26 |
-- Resolution processing for all subexpression nodes. Note that the separate |
| 27 |
-- package Sem_Aggr contains the actual resolution routines for aggregates, |
| 28 |
-- which are separated off since aggregate processing is complex. |
| 29 |
|
| 30 |
with Types; use Types; |
| 31 |
|
| 32 |
package Sem_Res is |
| 33 |
|
| 34 |
-- As described in Sem_Type, the type resolution proceeds in two phases. |
| 35 |
-- The first phase is a bottom up pass that is achieved during the |
| 36 |
-- recursive traversal performed by the Analyze procedures. This phase |
| 37 |
-- determines unambiguous types, and collects sets of possible types |
| 38 |
-- where the interpretation is potentially ambiguous. |
| 39 |
|
| 40 |
-- On completing this bottom up pass, which corresponds to a call to |
| 41 |
-- Analyze on a complete context, the Resolve routine is called which |
| 42 |
-- performs a top down resolution with recursive calls to itself to |
| 43 |
-- resolve operands. |
| 44 |
|
| 45 |
-- Since in practice a lot of semantic analysis has to be postponed until |
| 46 |
-- types are known (e.g. static folding, setting of suppress flags), the |
| 47 |
-- Resolve routines also complete the semantic analysis, and call the |
| 48 |
-- expander for possible expansion of the completely type resolved node. |
| 49 |
|
| 50 |
procedure Ambiguous_Character (C : Node_Id); |
| 51 |
-- Give list of candidate interpretations when a character literal cannot |
| 52 |
-- be resolved, for example in a (useless) comparison such as 'A' = 'B'. |
| 53 |
-- In Ada 95 the literals in question can be of type Character or Wide_ |
| 54 |
-- Character. In Ada 2005 Wide_Wide_Character is also a candidate. The |
| 55 |
-- node may also be overloaded with user-defined character types. |
| 56 |
|
| 57 |
procedure Analyze_And_Resolve (N : Node_Id); |
| 58 |
procedure Analyze_And_Resolve (N : Node_Id; Typ : Entity_Id); |
| 59 |
procedure Analyze_And_Resolve |
| 60 |
(N : Node_Id; |
| 61 |
Typ : Entity_Id; |
| 62 |
Suppress : Check_Id); |
| 63 |
procedure Analyze_And_Resolve |
| 64 |
(N : Node_Id; |
| 65 |
Suppress : Check_Id); |
| 66 |
-- These routines combine the effect of Analyze and Resolve. If a Suppress |
| 67 |
-- argument is present, then the analysis is done with the specified check |
| 68 |
-- suppressed (can be All_Checks to suppress all checks). These checks are |
| 69 |
-- suppressed for both the analysis and resolution. If the type argument |
| 70 |
-- is not present, then the Etype of the expression after the Analyze |
| 71 |
-- call is used for the Resolve. |
| 72 |
|
| 73 |
procedure Check_Parameterless_Call (N : Node_Id); |
| 74 |
-- Several forms of names can denote calls to entities without parameters. |
| 75 |
-- The context determines whether the name denotes the entity or a call to |
| 76 |
-- it. When it is a call, the node must be rebuilt accordingly and |
| 77 |
-- reanalyzed to obtain possible interpretations. |
| 78 |
-- |
| 79 |
-- The name may be that of an overloadable construct, or it can be an |
| 80 |
-- explicit dereference of a prefix that denotes an access to subprogram. |
| 81 |
-- In that case, we want to convert the name into a call only if the |
| 82 |
-- context requires the return type of the subprogram. Finally, a |
| 83 |
-- parameterless protected subprogram appears as a selected component. |
| 84 |
-- |
| 85 |
-- The parameter T is the Typ for the corresponding resolve call. |
| 86 |
|
| 87 |
function Is_Ambiguous_Operand |
| 88 |
(Operand : Node_Id; |
| 89 |
In_Interp_Expr : Boolean := False; |
| 90 |
Report_Errors : Boolean := True) return Boolean; |
| 91 |
-- Examine the interpretations of the given overloaded operand in a type |
| 92 |
-- conversion or interpolated expression. Returns True if the call is |
| 93 |
-- ambiguous; reports errors for ambiguous calls unless Report_Errors is |
| 94 |
-- set to False. In_Interp_Expr is True when the operand is an |
| 95 |
-- interpolated expression; used to improve the clarity of reported |
| 96 |
-- error messages. |
| 97 |
|
| 98 |
procedure Preanalyze_And_Resolve (N : Node_Id; T : Entity_Id); |
| 99 |
-- Performs a preanalysis of expression node N. During preanalysis, N is |
| 100 |
-- analyzed and then resolved against type T, but no expansion is carried |
| 101 |
-- out for N or its children. For more info on preanalysis read the spec |
| 102 |
-- of Sem. |
| 103 |
|
| 104 |
procedure Preanalyze_And_Resolve (N : Node_Id); |
| 105 |
-- Same, but use type of node because context does not impose a single type |
| 106 |
|
| 107 |
procedure Resolve (N : Node_Id; Typ : Entity_Id); |
| 108 |
procedure Resolve (N : Node_Id; Typ : Entity_Id; Suppress : Check_Id); |
| 109 |
-- Top-level type-checking procedure, called in a complete context. The |
| 110 |
-- construct N, which is a subexpression, has already been analyzed, and |
| 111 |
-- is required to be of type Typ given the analysis of the context (which |
| 112 |
-- uses the information gathered on the bottom-up phase in Analyze). The |
| 113 |
-- resolve routines do various other processing, e.g. static evaluation. |
| 114 |
-- If a Suppress argument is present, then the resolution is done with the |
| 115 |
-- specified check suppressed (can be All_Checks to suppress all checks). |
| 116 |
|
| 117 |
procedure Resolve (N : Node_Id); |
| 118 |
-- A version of Resolve where the type to be used for resolution is taken |
| 119 |
-- from the Etype (N). This is commonly used in cases where the context |
| 120 |
-- does not add anything and the first pass of analysis found the correct |
| 121 |
-- expected type. |
| 122 |
|
| 123 |
procedure Resolve_Discrete_Subtype_Indication |
| 124 |
(N : Node_Id; |
| 125 |
Typ : Entity_Id); |
| 126 |
-- Resolve subtype indications in choices (case statements and aggregates) |
| 127 |
-- and in index constraints. Note that the resulting Etype of the subtype_ |
| 128 |
-- indication node is set to the Etype of the contained range (i.e. an |
| 129 |
-- Itype is not constructed for the actual subtype). |
| 130 |
|
| 131 |
procedure Resolve_Entry (Entry_Name : Node_Id); |
| 132 |
-- Find name of entry being called, and resolve prefix of name with its |
| 133 |
-- own type. For now we assume that the prefix cannot be overloaded and |
| 134 |
-- the name of the entry plays no role in the resolution. |
| 135 |
|
| 136 |
procedure Resolve_Implicit_Dereference (P : Node_Id); |
| 137 |
-- Called when P is the prefix of an indexed component, or of a selected |
| 138 |
-- component, or of a slice. If P is of an access type, we unconditionally |
| 139 |
-- rewrite it as an explicit dereference. This ensures that the expander |
| 140 |
-- and the code generator have a fully explicit tree to work with. |
| 141 |
|
| 142 |
procedure Resolve_Membership_Equality (N : Node_Id; Typ : Entity_Id); |
| 143 |
-- Resolve the equality operator in an individual membership test |
| 144 |
|
| 145 |
function Valid_Conversion |
| 146 |
(N : Node_Id; |
| 147 |
Target : Entity_Id; |
| 148 |
Operand : Node_Id; |
| 149 |
Report_Errs : Boolean := True) return Boolean; |
| 150 |
-- Verify legality rules given in 4.6 (8-23). Target is the target type |
| 151 |
-- of the conversion, which may be an implicit conversion of an actual |
| 152 |
-- parameter to an anonymous access type (in which case N denotes the |
| 153 |
-- actual parameter and N = Operand). Returns a Boolean result indicating |
| 154 |
-- whether the conversion is legal. Reports errors in the case of illegal |
| 155 |
-- conversions, unless Report_Errs is False. |
| 156 |
|
| 157 |
private |
| 158 |
procedure Resolve_Implicit_Type (N : Node_Id) renames Resolve; |
| 159 |
pragma Inline (Resolve_Implicit_Type); |
| 160 |
-- We use this renaming to make the application of Inline very explicit to |
| 161 |
-- this version, since other versions of Resolve are not inlined. |
| 162 |
|
| 163 |
end Sem_Res; |