Commit b25ce290 by Ed Schonberg Committed by Arnaud Charlet

sem_ch5.adb (Analyze_Iterator_Specification): Set kind of loop variable after…

sem_ch5.adb (Analyze_Iterator_Specification): Set kind of loop variable after pre-analysis of iterator name...

2012-05-15  Ed Schonberg  <schonberg@adacore.com>

	* sem_ch5.adb (Analyze_Iterator_Specification): Set kind of
	loop variable after pre-analysis of iterator name, to prevent
	premature usage of loop variable.

2012-05-15  Ed Schonberg  <schonberg@adacore.com>

	* sem_util.adb (Is_Variable): In Ada 2012, an explicit
	dereference that is a rewriting of an expression whose type has
	a declared Implicit_Derenference aspect is a variable.

From-SVN: r187531
parent b0d71355
2012-05-15 Ed Schonberg <schonberg@adacore.com>
* sem_ch5.adb (Analyze_Iterator_Specification): Set kind of
loop variable after pre-analysis of iterator name, to prevent
premature usage of loop variable.
2012-05-15 Ed Schonberg <schonberg@adacore.com>
* sem_util.adb (Is_Variable): In Ada 2012, an explicit
dereference that is a rewriting of an expression whose type has
a declared Implicit_Derenference aspect is a variable.
2012-05-15 Hristian Kirtchev <kirtchev@adacore.com>
* exp_ch4.adb (Insert_Dereference_Action): Reimplemented. The
......
......@@ -1650,7 +1650,6 @@ package body Sem_Ch5 is
begin
Enter_Name (Def_Id);
Set_Ekind (Def_Id, E_Variable);
if Present (Subt) then
Analyze (Subt);
......@@ -1658,6 +1657,11 @@ package body Sem_Ch5 is
Preanalyze_Range (Iter_Name);
-- Set the kind of the loop variable, which is not visible within
-- the iterator name.
Set_Ekind (Def_Id, E_Variable);
-- If the domain of iteration is an expression, create a declaration for
-- it, so that finalization actions are introduced outside of the loop.
-- The declaration must be a renaming because the body of the loop may
......@@ -1679,6 +1683,13 @@ package body Sem_Ch5 is
begin
Typ := Etype (Iter_Name);
-- Protect against malformed iterator.
if Typ = Any_Type then
Error_Msg_N ("invalid expression in loop iterator", Iter_Name);
return;
end if;
-- The name in the renaming declaration may be a function call.
-- Indicate that it does not come from source, to suppress
-- spurious warnings on renamings of parameterless functions,
......
......@@ -8674,7 +8674,17 @@ package body Sem_Util is
or else
Is_Variable_Prefix (Original_Node (Prefix (N)));
-- A function call is never a variable
-- in Ada 2012, the dereference may have been added for a type with
-- a declared implicit dereference aspect.
elsif Nkind (N) = N_Explicit_Dereference
and then Present (Etype (Orig_Node))
and then Ada_Version >= Ada_2012
and then Has_Implicit_Dereference (Etype (Orig_Node))
then
return True;
-- A function call is never a variable.
elsif Nkind (N) = N_Function_Call then
return False;
......
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