]>
Commit | Line | Data |
---|---|---|
996ae0b0 RK |
1 | ------------------------------------------------------------------------------ |
2 | -- -- | |
3 | -- GNAT COMPILER COMPONENTS -- | |
4 | -- -- | |
5 | -- S E M _ C H 8 -- | |
6 | -- -- | |
7 | -- S p e c -- | |
8 | -- -- | |
cccef051 | 9 | -- Copyright (C) 1992-2023, Free Software Foundation, Inc. -- |
996ae0b0 RK |
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- -- | |
b5c84c3c | 13 | -- ware Foundation; either version 3, or (at your option) any later ver- -- |
996ae0b0 RK |
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 -- | |
b5c84c3c RD |
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. -- | |
996ae0b0 RK |
20 | -- -- |
21 | -- GNAT was originally developed by the GNAT team at New York University. -- | |
71ff80dc | 22 | -- Extensive contributions were provided by Ada Core Technologies Inc. -- |
996ae0b0 RK |
23 | -- -- |
24 | ------------------------------------------------------------------------------ | |
25 | ||
553c37be BD |
26 | with Einfo.Entities; use Einfo.Entities; |
27 | with Types; use Types; | |
996ae0b0 RK |
28 | package Sem_Ch8 is |
29 | ||
30 | ----------------------------------- | |
31 | -- Handling extensions of System -- | |
32 | ----------------------------------- | |
33 | ||
34 | -- For targets that define a much larger System package than given in | |
35 | -- the RM, we use a child package containing additional declarations, | |
36 | -- which is loaded when needed, and whose entities are conceptually | |
37 | -- within System itself. The presence of this auxiliary package is | |
38 | -- controlled with the pragma Extend_System. The following variable | |
39 | -- holds the entity of the auxiliary package, to simplify the special | |
40 | -- visibility rules that apply to it. | |
41 | ||
42 | System_Aux_Id : Entity_Id := Empty; | |
43 | ||
44 | ----------------- | |
45 | -- Subprograms -- | |
46 | ----------------- | |
47 | ||
96691943 AC |
48 | procedure Analyze_Exception_Renaming (N : Node_Id); |
49 | procedure Analyze_Expanded_Name (N : Node_Id); | |
50 | procedure Analyze_Generic_Function_Renaming (N : Node_Id); | |
51 | procedure Analyze_Generic_Package_Renaming (N : Node_Id); | |
52 | procedure Analyze_Generic_Procedure_Renaming (N : Node_Id); | |
53 | procedure Analyze_Object_Renaming (N : Node_Id); | |
54 | procedure Analyze_Package_Renaming (N : Node_Id); | |
55 | procedure Analyze_Subprogram_Renaming (N : Node_Id); | |
851e9f19 | 56 | |
7f5e671b PMR |
57 | procedure Analyze_Use_Package (N : Node_Id; Chain : Boolean := True); |
58 | -- Analyze a use package clause and control (through the Chain parameter) | |
59 | -- whether to add N to the use clause chain for the name denoted within | |
60 | -- use clause N in case we are reanalyzing a use clause because of stack | |
61 | -- manipulation. | |
851e9f19 | 62 | |
7f5e671b PMR |
63 | procedure Analyze_Use_Type (N : Node_Id; Chain : Boolean := True); |
64 | -- Similar to Analyze_Use_Package except the Chain parameter applies to the | |
65 | -- type within N's subtype mark Current_Use_Clause. | |
996ae0b0 | 66 | |
996ae0b0 RK |
67 | procedure End_Scope; |
68 | -- Called at end of scope. On exit from blocks and bodies (subprogram, | |
69 | -- package, task, and protected bodies), the name of the current scope | |
70 | -- must be removed from the scope stack, and the local entities must be | |
71 | -- removed from their homonym chains. On exit from record declarations, | |
72 | -- from package specifications, and from tasks and protected type | |
73 | -- specifications, more specialized procedures are invoked. | |
74 | ||
75 | procedure End_Use_Clauses (Clause : Node_Id); | |
0da2c8ac AC |
76 | -- Invoked on scope exit, to undo the effect of local use clauses. Clause |
77 | -- is the first use-clause of a scope being exited. This can be the current | |
996ae0b0 RK |
78 | -- scope, or some enclosing scopes when building a clean environment to |
79 | -- compile an instance body for inlining. | |
80 | ||
81 | procedure End_Use_Package (N : Node_Id); | |
82 | procedure End_Use_Type (N : Node_Id); | |
96691943 | 83 | -- Subsidiaries of End_Use_Clauses. Also called directly for use clauses |
996ae0b0 RK |
84 | -- appearing in context clauses. |
85 | ||
2bb7741f | 86 | procedure Find_Direct_Name (N : Node_Id); |
11560bcc | 87 | -- Given a direct name (Identifier or Operator_Symbol), this routine scans |
96691943 | 88 | -- the homonym chain for the name, searching for corresponding visible |
6357e162 | 89 | -- entities to find the referenced entity (or in the case of overloading, |
96691943 AC |
90 | -- one candidate interpretation). On return, the Entity and Etype fields |
91 | -- are set. In the non-overloaded case, these are the correct entries. | |
92 | -- In the overloaded case, the flag Is_Overloaded is set, Etype and Entity | |
93 | -- refer to an arbitrary element of the overloads set, and the appropriate | |
94 | -- entries have been added to the overloads table entry for the node. The | |
95 | -- overloading will be disambiguated during type resolution. | |
96 | -- | |
97 | -- Note, when this is called during semantic analysis in the overloaded | |
98 | -- case, the entity set will be the most recently declared homonym. In | |
99 | -- particular, the caller may follow the homonym chain checking for all | |
100 | -- entries in the current scope, and that will give all homonyms that are | |
101 | -- declared before the point of call in the current scope. This is useful | |
102 | -- for example in the processing for pragma Inline. | |
b3b3ada9 HK |
103 | -- |
104 | -- Flag Errors_OK should be set when error diagnostics are desired. Flag | |
105 | -- Marker_OK should be set when a N_Variable_Reference_Marker needs to be | |
106 | -- generated for a SPARK object in order to detect elaboration issues. Flag | |
107 | -- Reference_OK should be set when N must generate a cross reference. | |
996ae0b0 | 108 | |
996ae0b0 RK |
109 | procedure Find_Selected_Component (N : Node_Id); |
110 | -- Resolve various cases of selected components, recognize expanded names | |
111 | ||
112 | procedure Find_Type (N : Node_Id); | |
113 | -- Perform name resolution, and verify that the name found is that of a | |
114 | -- type. On return the Entity and Etype fields of the node N are set | |
115 | -- appropriately. If it is an incomplete type whose full declaration has | |
11560bcc TQ |
116 | -- been seen, they are set to the entity in the full declaration. If it |
117 | -- is an incomplete type associated with an interface visible through a | |
118 | -- limited-with clause, whose full declaration has been seen, they are | |
119 | -- set to the entity in the full declaration. Similarly, if the type is | |
120 | -- private, it has received a full declaration, and we are in the private | |
121 | -- part or body of the package, then the two fields are set to the entity | |
122 | -- of the full declaration as well. This procedure also has special | |
123 | -- processing for 'Class attribute references. | |
996ae0b0 | 124 | |
607d0635 | 125 | function Has_Loop_In_Inner_Open_Scopes (S : Entity_Id) return Boolean; |
8d606a78 RD |
126 | -- S is the entity of an open scope. This function determines if there is |
127 | -- an inner scope of S which is a loop (i.e. it appears somewhere in the | |
128 | -- scope stack after S). | |
607d0635 AC |
129 | |
130 | function In_Open_Scopes (S : Entity_Id) return Boolean; | |
8d606a78 RD |
131 | -- S is the entity of a scope. This function determines if this scope is |
132 | -- currently open (i.e. it appears somewhere in the scope stack). | |
607d0635 | 133 | |
996ae0b0 RK |
134 | procedure Initialize; |
135 | -- Initializes data structures used for visibility analysis. Must be | |
136 | -- called before analyzing each new main source program. | |
137 | ||
0da2c8ac AC |
138 | procedure Install_Use_Clauses |
139 | (Clause : Node_Id; | |
140 | Force_Installation : Boolean := False); | |
141 | -- Applies the use clauses appearing in a given declarative part, | |
996ae0b0 RK |
142 | -- when the corresponding scope has been placed back on the scope |
143 | -- stack after unstacking to compile a different context (subunit or | |
0da2c8ac AC |
144 | -- parent of generic body). Force_Installation is used when called from |
145 | -- Analyze_Subunit.Re_Install_Use_Clauses to insure that, after the | |
146 | -- analysis of the subunit, the parent's environment is again identical. | |
996ae0b0 | 147 | |
851e9f19 PMR |
148 | procedure Mark_Use_Clauses (Id : Node_Or_Entity_Id); |
149 | -- Mark a given entity or node Id's relevant use clauses as effective, | |
150 | -- including redundant ones and ones outside of the current scope. | |
151 | ||
553c37be | 152 | procedure Push_Scope (S : Scope_Kind_Id); |
8d606a78 RD |
153 | -- Make new scope stack entry, pushing S, the entity for a scope onto the |
154 | -- top of the scope table. The current setting of the scope suppress flags | |
155 | -- is saved for restoration on exit. | |
996ae0b0 RK |
156 | |
157 | procedure Pop_Scope; | |
8d606a78 RD |
158 | -- Remove top entry from scope stack, restoring the saved setting of the |
159 | -- scope suppress flags. | |
996ae0b0 RK |
160 | |
161 | function Present_System_Aux (N : Node_Id := Empty) return Boolean; | |
44d6a706 | 162 | -- Return True if the auxiliary system file has been successfully loaded. |
996ae0b0 | 163 | -- Otherwise attempt to load it, using the name supplied by a previous |
67536dcb RD |
164 | -- Extend_System pragma, and report on the success of the load. If N is |
165 | -- present, it is a selected component whose prefix is System, or else a | |
166 | -- with-clause on system. N is absent when the function is called to find | |
167 | -- the visibility of implicit operators. | |
996ae0b0 | 168 | |
85f6a831 RD |
169 | function Save_Scope_Stack |
170 | (Handle_Use : Boolean := True) return Elist_Id; | |
e530a2d1 AC |
171 | procedure Restore_Scope_Stack |
172 | (List : Elist_Id; | |
173 | Handle_Use : Boolean := True); | |
174 | -- These two subprograms are called from Semantics, when a unit U1 is to | |
67536dcb RD |
175 | -- be compiled in the course of the compilation of another unit U2. This |
176 | -- happens whenever Rtsfind is called. U1, the unit retrieved by Rtsfind, | |
177 | -- must be compiled in its own context, and the current scope stack | |
85f6a831 RD |
178 | -- containing U2 and local scopes must be made unreachable. This is |
179 | -- achieved using a call to Save_Scope_Stack. On return, the contents | |
180 | -- of the scope stack must be made accessible again with a call to | |
181 | -- Restore_Scope_Stack. | |
182 | -- | |
183 | -- The flag Handle_Use indicates whether local use clauses must be removed | |
184 | -- or installed. In the case of inlining of instance bodies, the visibility | |
67536dcb | 185 | -- handling is done fully in Inline_Instance_Body, and use clauses are |
e530a2d1 AC |
186 | -- handled there. Save_Scope_Stack returns the list of entities which have |
187 | -- been temporarily removed from visibility; that list must be passed to | |
188 | -- Restore_Scope_Stack to restore their visibility. | |
996ae0b0 | 189 | |
996ae0b0 RK |
190 | procedure Set_Use (L : List_Id); |
191 | -- Find use clauses that are declarative items in a package declaration | |
f2a54683 | 192 | -- and set the potentially use-visible flags of imported entities before |
996ae0b0 RK |
193 | -- analyzing the corresponding package body. |
194 | ||
851e9f19 PMR |
195 | procedure Update_Use_Clause_Chain; |
196 | -- Called at the end of a declarative region to detect unused use type | |
197 | -- clauses and maintain the Current_Use_Clause for type entities. | |
198 | ||
67536dcb RD |
199 | procedure ws; |
200 | -- Debugging routine for use in gdb: dump all entities on scope stack | |
201 | ||
c1ce0691 ES |
202 | procedure we (S : Entity_Id); |
203 | -- Debugging routine for use in gdb: dump all entities in given scope | |
204 | ||
996ae0b0 | 205 | end Sem_Ch8; |