diff options
Diffstat (limited to 'gcc/ada/sem_ch4.adb')
-rw-r--r-- | gcc/ada/sem_ch4.adb | 51 |
1 files changed, 19 insertions, 32 deletions
diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb index efc76f11398..4b438e13f1c 100644 --- a/gcc/ada/sem_ch4.adb +++ b/gcc/ada/sem_ch4.adb @@ -6427,38 +6427,20 @@ package body Sem_Ch4 is Func : Entity_Id; Func_Name : Node_Id; Indexing : Node_Id; - Is_Var : Boolean; - Ritem : Node_Id; begin -- Check whether type has a specified indexing aspect Func_Name := Empty; - Is_Var := False; - Ritem := First_Rep_Item (Etype (Prefix)); - while Present (Ritem) loop - if Nkind (Ritem) = N_Aspect_Specification then - - -- Prefer Variable_Indexing, but will settle for Constant - - if Get_Aspect_Id (Chars (Identifier (Ritem))) = - Aspect_Constant_Indexing - then - Func_Name := Expression (Ritem); - - elsif Get_Aspect_Id (Chars (Identifier (Ritem))) = - Aspect_Variable_Indexing - then - Func_Name := Expression (Ritem); - Is_Var := True; - exit; - end if; - end if; + if Is_Variable (Prefix) then + Func_Name := Find_Aspect (Etype (Prefix), Aspect_Variable_Indexing); + end if; - Next_Rep_Item (Ritem); - end loop; + if No (Func_Name) then + Func_Name := Find_Aspect (Etype (Prefix), Aspect_Constant_Indexing); + end if; -- If aspect does not exist the expression is illegal. Error is -- diagnosed in caller. @@ -6478,12 +6460,6 @@ package body Sem_Ch4 is end if; end if; - if Is_Var - and then not Is_Variable (Prefix) - then - Error_Msg_N ("Variable indexing cannot be applied to a constant", N); - end if; - if not Is_Overloaded (Func_Name) then Func := Entity (Func_Name); Indexing := Make_Function_Call (Loc, @@ -6526,11 +6502,11 @@ package body Sem_Ch4 is Analyze_One_Call (N, It.Nam, False, Success); if Success then Set_Etype (Name (N), It.Typ); + Set_Entity (Name (N), It.Nam); -- Add implicit dereference interpretation Disc := First_Discriminant (Etype (It.Nam)); - while Present (Disc) loop if Has_Implicit_Dereference (Disc) then Add_One_Interp @@ -6540,12 +6516,21 @@ package body Sem_Ch4 is Next_Discriminant (Disc); end loop; + + exit; end if; Get_Next_Interp (I, It); end loop; end; end if; + if Etype (N) = Any_Type then + Error_Msg_NE ("container cannot be indexed with&", N, Etype (Expr)); + Rewrite (N, New_Occurrence_Of (Any_Id, Loc)); + else + Analyze (N); + end if; + return True; end Try_Container_Indexing; @@ -6863,7 +6848,8 @@ package body Sem_Ch4 is First_Actual := First (Parameter_Associations (Call_Node)); -- For cross-reference purposes, treat the new node as being in - -- the source if the original one is. + -- the source if the original one is. Set entity and type, even + -- though they may be overwritten during resolution if overloaded. Set_Comes_From_Source (Subprog, Comes_From_Source (N)); Set_Comes_From_Source (Call_Node, Comes_From_Source (N)); @@ -6872,6 +6858,7 @@ package body Sem_Ch4 is and then not Inside_A_Generic then Set_Entity (Selector_Name (N), Entity (Subprog)); + Set_Etype (Selector_Name (N), Etype (Entity (Subprog))); end if; -- If need be, rewrite first actual as an explicit dereference |