annotate gcc/ada/sem_ch8.ads @ 158:494b0b89df80 default tip

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