135
136
-------------------------------
137
138
function Corresponding_Base_Entity (Declaration : in Asis.Declaration) return Asis.Expression is
138
use Asis, Asis.Elements, Asis.Expressions;
139
use Asis.Elements, Asis.Expressions;
139
140
Result : Asis.Expression := Asis.Declarations.Corresponding_Base_Entity (Declaration);
140
141
Decl : Asis.Declaration;
176
178
-----------------------------------
178
180
function Corresponding_Called_Function (Expression : in Asis.Expression) return Asis.Declaration is
181
use Asis.Declarations, Asis.Elements;
180
182
Result : constant Asis.Declaration := Asis.Expressions.Corresponding_Called_Function (Expression);
184
-- Special kludge for "/=" which does not return Nil_Element in some version of GNAT
185
-- (although Called_Profile does not return anything)
186
if Is_Nil (Result) then
188
elsif Operator_Kind (Names (Result)(1)) = A_Not_Equal_Operator
189
and then not Is_Nil (Corresponding_Equality_Operator (Result))
191
-- It is a predefined "/=" whose result is Boolean
192
-- Note that it can only be a predefined one, per 6.6(5)
182
196
if Defining_Name_Kind (Result) = A_Defining_Expanded_Name then
183
197
-- Bug: missing one level of Enclosing_Element
198
Trace_Bug ("A4G_Bugs.Corresponding_Called_Function");
184
199
return Enclosing_Element (Result);
194
209
function Corresponding_Expression_Type (Expression : in Asis.Expression) return Asis.Declaration
211
-- Since this is a (partial) rewriting of the function, there is no call to Trace_Bug
196
212
use Ada.Exceptions, Asis.Declarations, Asis.Definitions, Asis.Elements, Asis.Expressions;
198
215
Result : Asis.Element;
199
216
Temp : Asis.Element;
200
Name : Asis.Expression;
202
218
if Expression_Kind (Expression) = An_Explicit_Dereference then
203
219
-- For An_Explicit_Dereference, ASIS returns the type of the pointer
225
241
Result := Result_Profile (Result);
226
242
Temp := Nil_Element;
227
when An_Indexed_Component =>
243
when An_Indexed_Component
244
| An_Explicit_Dereference
228
246
-- The type of the name of an indexed component cannot (yet!) be anonymous
247
-- Similarly, for X.all.all
229
248
Result := Corresponding_Expression_Type (Temp);
230
249
Temp := Nil_Element;
243
262
| A_Single_Protected_Declaration
244
263
| A_Single_Task_Declaration
246
Result := Asis.Definitions.Subtype_Mark (Object_Declaration_View (Temp));
265
Result := Subtype_Simple_Name (Object_Declaration_View (Temp));
247
266
when A_Component_Declaration=>
248
Result := Asis.Definitions.Subtype_Mark (Component_Subtype_Indication
249
(Object_Declaration_View (Temp)));
267
Result := Subtype_Simple_Name (Component_Subtype_Indication (Object_Declaration_View (Temp)));
252
270
Raise_Exception (Program_Error'Identity,
283
301
-- (but beware of intermediate subtyping)
284
302
Result := Type_Declaration_View (Corresponding_First_Subtype (Result));
304
-- Get rid of derivations
305
if Type_Kind (Result) in A_Derived_Type_Definition .. A_Derived_Record_Extension_Definition then
306
Result := Type_Declaration_View (Corresponding_Root_Type (Result));
307
elsif Formal_Type_Kind (Result) = A_Formal_Derived_Type_Definition then
308
Result := Type_Declaration_View (Corresponding_Name_Declaration (Subtype_Simple_Name (Result)));
286
311
-- Here, Result is either the definition of an access-to-object or an access-to-subprogram
287
312
-- In the latter case, we should probably return a Nil_Element (not clear from the standard,
288
313
-- but there is nothing else to return).
339
363
case Declaration_Kind (Result) is
340
364
when A_Component_Declaration =>
342
Name := Asis.Definitions.Subtype_Mark (Component_Subtype_Indication
343
(Object_Declaration_View
345
if Expression_Kind (Name) = A_Selected_Component then
346
Name := Selector (Name);
348
Result := Corresponding_Name_Declaration (Name);
366
Result := Corresponding_Name_Declaration (Subtype_Simple_Name (Component_Subtype_Indication
367
(Object_Declaration_View (Result))));
350
369
when A_Type_Declaration | A_Subtype_Declaration | A_Formal_Type_Declaration =>
360
379
return Nil_Element;
363
Result := Asis.Definitions.Subtype_Mark (Result);
364
if Expression_Kind (Result) = A_Selected_Component then
365
Result := Selector (Result);
367
Result := Corresponding_Name_Declaration (Result);
382
Result := Corresponding_Name_Declaration (Subtype_Simple_Name (Result));
369
384
when Not_A_Declaration =>
370
385
Raise_Exception (Program_Error'Identity,
379
394
end Corresponding_Expression_Type;
396
--------------------------------
397
-- Corresponding_Last_Subtype --
398
--------------------------------
400
function Corresponding_Last_Subtype (Declaration : in Asis.Declaration) return Asis.Declaration is
401
-- Since this is a complete rewriting of the function, there is no call to Trace_Bug
402
use Asis.Declarations, Asis.Elements, Asis.Expressions, Ada.Exceptions;
404
Mark : Asis.Expression;
406
if Declaration_Kind (Declaration) /= A_Subtype_Declaration then
410
Mark := Subtype_Simple_Name (Type_Declaration_View (Declaration));
411
case Expression_Kind (Mark) is
412
when An_Identifier =>
413
return Corresponding_Name_Declaration (Mark);
414
when An_Attribute_Reference =>
415
Mark := Prefix (Mark);
416
if Expression_Kind (Mark) = A_Selected_Component then
417
Mark := Selector (Mark);
419
return Corresponding_Name_Declaration (Mark);
421
Raise_Exception (Program_Error'Identity,
422
"Bug in Corresponding_Last_Subtype, returned "
423
& Expression_Kinds'Image (Expression_Kind (Mark)));
425
end Corresponding_Last_Subtype;
428
-----------------------------
429
-- Corresponding_Root_Type --
430
-----------------------------
432
function Corresponding_Root_Type (Type_Definition : in Asis.Type_Definition) return Asis.Declaration is
433
-- Since this is a complete rewriting of the function, there is no call to Trace_Bug
434
use Asis.Definitions, Asis.Declarations, Asis.Elements, Asis.Expressions;
437
Def : Asis.Definition := Type_Definition;
438
Decl : Asis.Declaration;
439
Name : Asis.Expression;
442
-- Invariant: Def is A_Derived_Type_Definition or A_Derived_Record_Extension_Definition
444
Name := Subtype_Simple_Name (Parent_Subtype_Indication (Def));
445
if Expression_Kind (Name) = An_Attribute_Reference then
446
Name := Prefix (Name);
447
if Expression_Kind (Name) = A_Selected_Component then
448
Name := Selector (Name);
452
Decl := Corresponding_First_Subtype (Corresponding_Name_Declaration (Name));
453
if Declaration_Kind (Decl) /= An_Ordinary_Type_Declaration then
457
Def := Type_Declaration_View (Decl);
458
if Type_Kind (Def) not in A_Derived_Type_Definition .. A_Derived_Record_Extension_Definition then
462
end Corresponding_Root_Type;
508
function Unit_Class (Compilation_Unit : in Asis.Compilation_Unit) return Asis.Unit_Classes is
509
use Asis.Compilation_Units;
510
Result : constant Asis.Unit_Classes := Asis.Compilation_Units.Unit_Class (Compilation_Unit);
512
if Result = A_Public_Body and then Is_Nil (Corresponding_Declaration (Compilation_Unit)) then
513
Trace_Bug ("A4G_Bugs.Unit_Class");
514
return A_Public_Declaration_And_Body;
524
procedure Trace_Bug (Message : Wide_String) is
527
Trace ("ASIS bug workaround triggered in " & Message); --## RULE LINE OFF No_Trace