Commit b3e42de5 by Vincent Pucci Committed by Arnaud Charlet

sem.ads, sem.adb (Preanalyze): New routine.

2012-03-15  Vincent Pucci  <pucci@adacore.com>

	* sem.ads, sem.adb (Preanalyze): New routine.
	* sem_ch4.adb (Analyze_Quantified_Expression): Call to the
	Preanalyze routine in Sem added.  Renaming of Needs_Expansion
	into Need_Preanalysis.
	* sem_ch6.adb (Preanalyze): Removed.

From-SVN: r185421
parent 2a1b208c
2012-03-15 Vincent Pucci <pucci@adacore.com>
* sem.ads, sem.adb (Preanalyze): New routine.
* sem_ch4.adb (Analyze_Quantified_Expression): Call to the
Preanalyze routine in Sem added. Renaming of Needs_Expansion
into Need_Preanalysis.
* sem_ch6.adb (Preanalyze): Removed.
2012-03-15 Robert Dewar <dewar@adacore.com> 2012-03-15 Robert Dewar <dewar@adacore.com>
* sem_ch4.adb (Analyze_Quantified_Expression): Add comment. * sem_ch4.adb (Analyze_Quantified_Expression): Add comment.
......
...@@ -1288,6 +1288,23 @@ package body Sem is ...@@ -1288,6 +1288,23 @@ package body Sem is
Scope_Stack.Release; Scope_Stack.Release;
end Lock; end Lock;
----------------
-- Preanalyze --
----------------
procedure Preanalyze (N : Node_Id) is
Save_Full_Analysis : constant Boolean := Full_Analysis;
begin
Full_Analysis := False;
Expander_Mode_Save_And_Set (False);
Analyze (N);
Expander_Mode_Restore;
Full_Analysis := Save_Full_Analysis;
end Preanalyze;
-------------------------------------- --------------------------------------
-- Push_Global_Suppress_Stack_Entry -- -- Push_Global_Suppress_Stack_Entry --
-------------------------------------- --------------------------------------
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
-- -- -- --
-- S p e c -- -- S p e c --
-- -- -- --
-- Copyright (C) 1992-2011, Free Software Foundation, Inc. -- -- Copyright (C) 1992-2012, Free Software Foundation, Inc. --
-- -- -- --
-- GNAT is free software; you can redistribute it and/or modify it under -- -- 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- -- -- terms of the GNU General Public License as published by the Free Soft- --
...@@ -644,6 +644,11 @@ package Sem is ...@@ -644,6 +644,11 @@ package Sem is
-- is False, then the status of the check can be determined simply by -- is False, then the status of the check can be determined simply by
-- examining Scope_Checks (C), so this routine is not called in that case. -- examining Scope_Checks (C), so this routine is not called in that case.
procedure Preanalyze (N : Node_Id);
-- Performs a pre-analysis of node N. During pre-analysis no expansion is
-- carried out for N or its children. For more info on pre-analysis read
-- the spec of Sem.
generic generic
with procedure Action (Item : Node_Id); with procedure Action (Item : Node_Id);
procedure Walk_Library_Items; procedure Walk_Library_Items;
......
...@@ -29,7 +29,6 @@ with Debug; use Debug; ...@@ -29,7 +29,6 @@ with Debug; use Debug;
with Einfo; use Einfo; with Einfo; use Einfo;
with Elists; use Elists; with Elists; use Elists;
with Errout; use Errout; with Errout; use Errout;
with Expander; use Expander;
with Exp_Util; use Exp_Util; with Exp_Util; use Exp_Util;
with Fname; use Fname; with Fname; use Fname;
with Itypes; use Itypes; with Itypes; use Itypes;
...@@ -3391,22 +3390,33 @@ package body Sem_Ch4 is ...@@ -3391,22 +3390,33 @@ package body Sem_Ch4 is
----------------------------------- -----------------------------------
procedure Analyze_Quantified_Expression (N : Node_Id) is procedure Analyze_Quantified_Expression (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N); Loc : constant Source_Ptr := Sloc (N);
Ent : constant Entity_Id := Ent : constant Entity_Id :=
New_Internal_Entity New_Internal_Entity (E_Loop, Current_Scope, Sloc (N), 'L');
(E_Loop, Current_Scope, Sloc (N), 'L');
Needs_Expansion : constant Boolean := Need_Preanalysis : constant Boolean :=
Operating_Mode /= Check_Semantics Operating_Mode /= Check_Semantics
and then not Alfa_Mode; and then not Alfa_Mode;
Iterator : Node_Id; Iterator : Node_Id;
Original_N : Node_Id; Original_N : Node_Id;
begin begin
-- The approach in this procedure is very non-standard and at the
-- very least, extensive comments are required saying why this very
-- non-standard approach is needed???
-- Also general comments are needed in any case saying what is going
-- on here, since tree rewriting of this kind should normally be done
-- by the expander and not by the analyzer ??? Probably Ent, Iterator,
-- and Original_N, and Needs_Preanalysis, all need comments above ???
-- Preserve the original node used for the expansion of the quantified -- Preserve the original node used for the expansion of the quantified
-- expression. -- expression.
if Needs_Expansion then -- This is a very unusual use of Copy_Separate_Tree, needs looking at???
if Need_Preanalysis then
Original_N := Copy_Separate_Tree (N); Original_N := Copy_Separate_Tree (N);
end if; end if;
...@@ -3416,6 +3426,9 @@ package body Sem_Ch4 is ...@@ -3416,6 +3426,9 @@ package body Sem_Ch4 is
Check_SPARK_Restriction ("quantified expression is not allowed", N); Check_SPARK_Restriction ("quantified expression is not allowed", N);
-- The following seems like expansion activity done at analysis
-- time, which seems weird ???
if Present (Loop_Parameter_Specification (N)) then if Present (Loop_Parameter_Specification (N)) then
Iterator := Iterator :=
Make_Iteration_Scheme (Loc, Make_Iteration_Scheme (Loc,
...@@ -3443,21 +3456,21 @@ package body Sem_Ch4 is ...@@ -3443,21 +3456,21 @@ package body Sem_Ch4 is
Set_Parent (Iterator_Specification (Iterator), Iterator); Set_Parent (Iterator_Specification (Iterator), Iterator);
end if; end if;
if Needs_Expansion then if Need_Preanalysis then
-- The full analysis will be performed during the expansion of the -- The full analysis will be performed during the expansion of the
-- quantified expression, only a preanalysis of the condition needs -- quantified expression, only a preanalysis of the condition needs
-- to be done. -- to be done.
-- This is weird and irregular code for several reasons. First, doing -- This is strange for two reasons
-- an Analyze with no Resolve is very suspicious, how can this be
-- right for the overloaded case ??? Second, doing two calls to
-- analyze on the same node is peculiar ??? Why can't we use the
-- normal Preanalyze calls here ???
Expander_Mode_Save_And_Set (False); -- First, there is almost no situation in which Preanalyze vs
Analyze (Condition (N)); -- Analyze should be conditioned on -gnatc mode (since error msgs
Expander_Mode_Restore; -- must be 100% unaffected by -gnatc). Seconed doing a Preanalyze
-- with no resolution almost certainly means that some messages are
-- either missed, or flagged differently in the two cases.
Preanalyze (Condition (N));
else else
Analyze (Condition (N)); Analyze (Condition (N));
end if; end if;
...@@ -3468,7 +3481,7 @@ package body Sem_Ch4 is ...@@ -3468,7 +3481,7 @@ package body Sem_Ch4 is
-- Attach the original node to the iteration scheme created above -- Attach the original node to the iteration scheme created above
if Needs_Expansion then if Need_Preanalysis then
Set_Etype (Original_N, Standard_Boolean); Set_Etype (Original_N, Standard_Boolean);
Set_Parent (Iterator, Original_N); Set_Parent (Iterator, Original_N);
end if; end if;
......
...@@ -4280,11 +4280,6 @@ package body Sem_Ch6 is ...@@ -4280,11 +4280,6 @@ package body Sem_Ch6 is
-- analysis of the non-inlined body will handle these pragmas properly). -- analysis of the non-inlined body will handle these pragmas properly).
-- A new internal name is associated with Body_To_Inline. -- A new internal name is associated with Body_To_Inline.
procedure Preanalyze (N : Node_Id);
-- Performs a pre-analysis of node N. During pre-analysis no expansion
-- is carried out for N or its children. For more info on pre-analysis
-- read the spec of Sem.
procedure Split_Unconstrained_Function procedure Split_Unconstrained_Function
(N : Node_Id; (N : Node_Id;
Spec_Id : Entity_Id); Spec_Id : Entity_Id);
...@@ -5059,23 +5054,6 @@ package body Sem_Ch6 is ...@@ -5059,23 +5054,6 @@ package body Sem_Ch6 is
Set_Corresponding_Spec (Body_To_Inline, Empty); Set_Corresponding_Spec (Body_To_Inline, Empty);
end Generate_Body_To_Inline; end Generate_Body_To_Inline;
----------------
-- Preanalyze --
----------------
procedure Preanalyze (N : Node_Id) is
Save_Full_Analysis : constant Boolean := Full_Analysis;
begin
Full_Analysis := False;
Expander_Mode_Save_And_Set (False);
Analyze (N);
Expander_Mode_Restore;
Full_Analysis := Save_Full_Analysis;
end Preanalyze;
---------------------------------- ----------------------------------
-- Split_Unconstrained_Function -- -- Split_Unconstrained_Function --
---------------------------------- ----------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment