diff options
author | Gary Dismukes <dismukes@adacore.com> | 2023-10-31 19:50:46 +0000 |
---|---|---|
committer | Marc Poulhiès <poulhies@adacore.com> | 2023-11-21 10:57:42 +0100 |
commit | ea60a4cd194eeea2d7a63b93b6b01b9c951302da (patch) | |
tree | c3f615477dfcdb9c1a4f1e35347aab435318aac3 /gcc/ada/sem_util.ads | |
parent | 35510341fc24eed8fa3cd08171dc560b6d833fb2 (diff) | |
download | gcc-ea60a4cd194eeea2d7a63b93b6b01b9c951302da.zip gcc-ea60a4cd194eeea2d7a63b93b6b01b9c951302da.tar.gz gcc-ea60a4cd194eeea2d7a63b93b6b01b9c951302da.tar.bz2 |
ada: Compiler error reporting illegal prefix on legal loop iterator with "in"
During semantic analysis, the compiler fails to determine the cursor type
in the case of a generalized iterator loop with "in", in the case where the
iterator type has a parent type that is a controlled type (for example) and
its ancestor iterator interface type is given after as a progenitor. It also
improperly determines the ancestor interface type during expansion (within
Expand_Iterator_Loop_Over_Container), for both "in" and "of" iterator forms.
The FE was assuming that the iterator interface is simply the parent type
of the iterator type, but that type can occur later in the interface list,
or be inherited. A new function is added that properly locates a type's
iterator interface ancestor, if any, and is called for analysis and expansion.
gcc/ada/
* exp_ch5.adb (Expand_Iterator_Loop_Over_Container): Retrieve the
iteration type's iteration interface progenitor via
Iterator_Interface_Ancestor, in the case of both "in" and "of"
iterators. Narrow the scope of Pack, so it's declared and
initialized only within the code related to "of" iterators, and
change its name to Cont_Type_Pack. Adjust comments.
* sem_ch5.adb (Get_Cursor_Type): In the case of a derived type,
retrieve the iteration type's iterator interface progenitor (if it
exists) via Iterator_Interface_Ancestor rather than assuming that
the parent type is the interface progenitor.
* sem_util.ads (Iterator_Interface_Ancestor): New function.
* sem_util.adb (Iterator_Interface_Ancestor): New function
returning a type's associated iterator interface type, if any, by
collecting and traversing the type's interfaces.
Diffstat (limited to 'gcc/ada/sem_util.ads')
-rw-r--r-- | gcc/ada/sem_util.ads | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/gcc/ada/sem_util.ads b/gcc/ada/sem_util.ads index caf6a66..96b4730 100644 --- a/gcc/ada/sem_util.ads +++ b/gcc/ada/sem_util.ads @@ -2480,6 +2480,13 @@ package Sem_Util is -- Calls Handle_Parameter for each pair of formal and actual parameters of -- a function, procedure, or entry call. + function Iterator_Interface_Ancestor (Typ : Entity_Id) return Entity_Id; + -- If Typ has an ancestor that is an iterator interface type declared in + -- an instance of Ada.Iterator_Interfaces, then returns that interface + -- type. Otherwise returns Empty. (It's not clear what it means if there + -- is more than one such ancestor, perhaps coming from multiple instances, + -- but this function returns the first such ancestor it finds. ???) + procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False); -- This procedure is called to clear all constant indications from all -- entities in the current scope and in any parent scopes if the current |