[multiple changes]
authorArnaud Charlet <charlet@gcc.gnu.org>
Tue, 29 Jan 2013 14:33:47 +0000 (15:33 +0100)
committerArnaud Charlet <charlet@gcc.gnu.org>
Tue, 29 Jan 2013 14:33:47 +0000 (15:33 +0100)
2013-01-29  Ed Schonberg  <schonberg@adacore.com>

* exp_ch5.adb (Expand_Iterator_Loop_Over_Array): Preserve loop
identifier only if it comes from source.
(Expand_N_Loop_Statement): If the domain of iteration is an
enumeration type with a representation clause, remove from
visibility the loop identifier before rewriting the loop as a
block with a declaration for said identifier.
* sem_util.adb (Remove_Homonym): Handle properly the default case.

2013-01-29  Vincent Celier  <celier@adacore.com>

* prj-proc.adb: Minor comment spelling fix.

From-SVN: r195546

gcc/ada/ChangeLog
gcc/ada/exp_ch5.adb
gcc/ada/prj-proc.adb
gcc/ada/sem_util.adb

index 1680a5286ec9f0030ec4d625cb207f5dfbdd938a..73ddbfb571134fb4e1ca1823abaa0873dec16cfd 100644 (file)
@@ -1,3 +1,17 @@
+2013-01-29  Ed Schonberg  <schonberg@adacore.com>
+
+       * exp_ch5.adb (Expand_Iterator_Loop_Over_Array): Preserve loop
+       identifier only if it comes from source.
+       (Expand_N_Loop_Statement): If the domain of iteration is an
+       enumeration type with a representation clause, remove from
+       visibility the loop identifier before rewriting the loop as a
+       block with a declaration for said identifier.
+       * sem_util.adb (Remove_Homonym): Handle properly the default case.
+
+2013-01-29  Vincent Celier  <celier@adacore.com>
+
+       * prj-proc.adb: Minor comment spelling fix.
+
 2013-01-29  Pascal Obry  <obry@adacore.com>
 
        * prj-proc.adb (Process_Expression_Variable_Decl): Prepend
index 66aeb681dac070c906bb3d15551200d19d257e5f..2bdb82797ab6318b258b0831738318731a71860a 100644 (file)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 1992-2012, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2013, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -3743,10 +3743,14 @@ package body Exp_Ch5 is
          end loop;
       end if;
 
-      --  If original loop has a name, preserve it so it can be recognized by
-      --  an exit statement in the body of the rewritten loop.
+      --  If original loop has a source name, preserve it so it can be
+      --  recognized by an exit statement in the body of the rewritten loop.
+      --  This only concerns source names: the generated name of an anonymous
+      --  loop will be create again during the subsequent analysis below.
 
-      if Present (Identifier (N)) then
+      if Present (Identifier (N))
+        and then Comes_From_Source (Identifier (N))
+      then
          Set_Identifier (Core_Loop, Relocate_Node (Identifier (N)));
       end if;
 
@@ -3810,6 +3814,7 @@ package body Exp_Ch5 is
             Ltype   : constant Entity_Id := Etype (Loop_Id);
             Btype   : constant Entity_Id := Base_Type (Ltype);
             Expr    : Node_Id;
+            Decls   : List_Id;
             New_Id  : Entity_Id;
 
          begin
@@ -3869,6 +3874,16 @@ package body Exp_Ch5 is
                         New_List (New_Reference_To (New_Id, Loc)));
                end if;
 
+               --  Build declaration for loop identifier
+
+               Decls :=
+                 New_List (
+                   Make_Object_Declaration (Loc,
+                     Defining_Identifier => Loop_Id,
+                     Constant_Present    => True,
+                     Object_Definition   => New_Reference_To (Ltype, Loc),
+                     Expression          => Expr));
+
                Rewrite (N,
                  Make_Loop_Statement (Loc,
                    Identifier => Identifier (N),
@@ -3916,14 +3931,7 @@ package body Exp_Ch5 is
 
                    Statements => New_List (
                      Make_Block_Statement (Loc,
-                       Declarations => New_List (
-                         Make_Object_Declaration (Loc,
-                           Defining_Identifier => Loop_Id,
-                           Constant_Present    => True,
-                           Object_Definition   =>
-                             New_Reference_To (Ltype, Loc),
-                           Expression          => Expr)),
-
+                       Declarations => Decls,
                        Handled_Statement_Sequence =>
                          Make_Handled_Sequence_Of_Statements (Loc,
                            Statements => Statements (N)))),
@@ -3931,13 +3939,22 @@ package body Exp_Ch5 is
                    End_Label => End_Label (N)));
 
                --  The loop parameter's entity must be removed from the loop
-               --  scope's entity list, since it will now be located in the
-               --  new block scope. Any other entities already associated with
-               --  the loop scope, such as the loop parameter's subtype, will
-               --  remain there.
+               --  scope's entity list and rendered invisible, since it will
+               --  now be located in the new block scope. Any other entities
+               --  already associated with the loop scope, such as the loop
+               --  parameter's subtype, will remain there.
+
+               --  In an element loop, the loop will contain a declaration for
+               --  a cursor variable; otherwise the loop id is the first entity
+               --  in the scope constructed for the loop.
+
+               if Comes_From_Source (Loop_Id) then
+                  pragma Assert (First_Entity (Scope (Loop_Id)) = Loop_Id);
+                  null;
+               end if;
 
-               pragma Assert (First_Entity (Scope (Loop_Id)) = Loop_Id);
                Set_First_Entity (Scope (Loop_Id), Next_Entity (Loop_Id));
+               Remove_Homonym (Loop_Id);
 
                if Last_Entity (Scope (Loop_Id)) = Loop_Id then
                   Set_Last_Entity (Scope (Loop_Id), Empty);
index 5e2828be5d8cfbb406dac4f965ab171d01661e1e..39ebe70b4ad988595379d73e502e38de295f15bd 100644 (file)
@@ -2076,7 +2076,7 @@ package body Prj.Proc is
                      Val := Shared.String_Elements.Table (Val).Next;
                   end loop;
 
-                  --  Prepend them in the oder found in the attribute
+                  --  Prepend them in the order found in the attribute
 
                   for K in Positive range 1 .. Positive (List.Length) loop
                      Prj.Env.Add_Directories
index 0fc236559002063a72a60283e3e3750c67ece453..336ce67c49a7840de9f032c552dc568d50af35a0 100644 (file)
@@ -12638,6 +12638,7 @@ package body Sem_Util is
          else
             Set_Name_Entity_Id (Chars (E), Empty);
          end if;
+
       else
          H := Current_Entity (E);
          while Present (H) and then H /= E loop
@@ -12645,7 +12646,11 @@ package body Sem_Util is
             H    := Homonym (H);
          end loop;
 
-         Set_Homonym (Prev, Homonym (E));
+         --  If E is not on the homonym chain, nothing to do
+
+         if Present (H) then
+            Set_Homonym (Prev, Homonym (E));
+         end if;
       end if;
    end Remove_Homonym;