-- --
-- B o d y --
-- --
--- Copyright (C) 1992-2005, Free Software Foundation, Inc. --
+-- Copyright (C) 1992-2010, 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- --
--- ware Foundation; either version 2, or (at your option) any later ver- --
+-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
--- Public License distributed with GNAT; see file COPYING. If not, write --
--- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
--- Boston, MA 02110-1301, USA. --
+-- Public License distributed with GNAT; see file COPYING3. If not, go to --
+-- http://www.gnu.org/licenses for a complete copy of the license. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
procedure No_Header (N : Elmt_Id);
-- The label N is known not to be a loop header. Scan forward and
- -- remove all subsequent goto's that may have this node as a target.
+ -- remove all subsequent gotos that may have this node as a target.
procedure Process_Goto (N : Elmt_Id);
- -- N is a forward jump. Scan forward and remove all subsequent goto's
+ -- N is a forward jump. Scan forward and remove all subsequent gotos
-- that may have the same target, to preclude spurious loops.
procedure Rewrite_As_Loop
and then Matches (Node (N), Node (S1))
then
if not Found then
- if Parent (Node (N)) = Parent (Node (S1)) then
+
+ -- If the label and the goto are both in the same statement
+ -- list, then we've found a loop. Note that labels and goto
+ -- statements are always part of some list, so In_Same_List
+ -- always makes sense.
+
+ if In_Same_List (Node (N), Node (S1)) then
Source := S1;
Found := True;
- else
- -- The goto is within some nested structure
+ -- The goto is within some nested structure
+ else
No_Header (N);
return;
end if;
begin
Next_Label_Elmt := First_Elmt (Label_List);
-
while Present (Next_Label_Elmt) loop
Label_Node := Node (Next_Label_Elmt);
-- Now attach the implicit label declaration to the appropriate
-- declarative region, creating a declaration list if none exists
- if not Present (Declarations (Enclosing_Body_Or_Block)) then
+ if No (Declarations (Enclosing_Body_Or_Block)) then
Set_Declarations (Enclosing_Body_Or_Block, New_List);
end if;