Commit 2a31c32b by Arnaud Charlet

[multiple changes]

2009-06-25  Vincent Celier  <celier@adacore.com>

	* vms_data.ads: Minor comment change

2009-06-25  Gary Dismukes  <dismukes@adacore.com>

	* exp_ch5.adb (Expand_N_Extended_Return_Statement): Don't build an
	assignment statement to targeting a caller-provided object when the
	result type is an interface type.

	* exp_ch6.adb (Expand_Call): Remove redundant test of
	Is_Limited_Interface (Is_Inherently_Limited is sufficient).
	(Is_Build_In_Place_Function): Remove test for Is_Limited_Interface.

	* sem_aggr.adb (Check_Expr_OK_In_Limited_Aggregate): Add type in call
	to OK_For_Limited_Init.

	* sem_aux.adb (Is_Inherently_Limited_Type): Revise limited type
	condition so that True is returned for all limited interfaces, not
	just synchronized ones. Ignore components of an interface type when
	checking for limited components (such a component can be a parent
	component).

	* sem_ch3.ads (OK_For_Limited_Init_In_05): Add type parameter.
	(OK_For_Limited_Init): Add type parameter.

	* sem_ch3.adb (Check_Initialization): Add type in call to
	OK_For_Limited_Init.
	(OK_For_Limited_Init): Add new type param in call to
	OK_For_Limited_Init_In_05.
	(OK_For_Limited_Init_In_05): Permit arbitrary expressions of a
	nonlimited type when the context type is a limited interface. Add type
	on recursive calls.

	* sem_ch4.adb (Analyze_Allocator): Add type in call to
	OK_For_Limited_Init.

	* sem_ch6.adb (Check_Limited_Return): Add type in call to
	OK_For_Limited_Init.

	* sem_ch12.adb (Analyze_Formal_Object_Declaration): Add type in call to
	OK_For_Limited_Init.
	(Instantiate_Object): Add type in call to OK_For_Limited_Init.

	* sem_type.adb (Interface_Present_In_Ancestor): In the case of a
	class-wide interface, get the base type before applying Etype, in order
	to account for class-wide subtypes.

From-SVN: r148938
parent fadcf313
2009-06-25 Vincent Celier <celier@adacore.com>
* vms_data.ads: Minor comment change
2009-06-25 Gary Dismukes <dismukes@adacore.com>
* exp_ch5.adb (Expand_N_Extended_Return_Statement): Don't build an
assignment statement to targeting a caller-provided object when the
result type is an interface type.
* exp_ch6.adb (Expand_Call): Remove redundant test of
Is_Limited_Interface (Is_Inherently_Limited is sufficient).
(Is_Build_In_Place_Function): Remove test for Is_Limited_Interface.
* sem_aggr.adb (Check_Expr_OK_In_Limited_Aggregate): Add type in call
to OK_For_Limited_Init.
* sem_aux.adb (Is_Inherently_Limited_Type): Revise limited type
condition so that True is returned for all limited interfaces, not
just synchronized ones. Ignore components of an interface type when
checking for limited components (such a component can be a parent
component).
* sem_ch3.ads (OK_For_Limited_Init_In_05): Add type parameter.
(OK_For_Limited_Init): Add type parameter.
* sem_ch3.adb (Check_Initialization): Add type in call to
OK_For_Limited_Init.
(OK_For_Limited_Init): Add new type param in call to
OK_For_Limited_Init_In_05.
(OK_For_Limited_Init_In_05): Permit arbitrary expressions of a
nonlimited type when the context type is a limited interface. Add type
on recursive calls.
* sem_ch4.adb (Analyze_Allocator): Add type in call to
OK_For_Limited_Init.
* sem_ch6.adb (Check_Limited_Return): Add type in call to
OK_For_Limited_Init.
* sem_ch12.adb (Analyze_Formal_Object_Declaration): Add type in call to
OK_For_Limited_Init.
(Instantiate_Object): Add type in call to OK_For_Limited_Init.
* sem_type.adb (Interface_Present_In_Ancestor): In the case of a
class-wide interface, get the base type before applying Etype, in order
to account for class-wide subtypes.
2009-06-25 Emmanuel Briot <briot@adacore.com> 2009-06-25 Emmanuel Briot <briot@adacore.com>
* gnatcmd.adb, prj-proc.adb, make.adb, prj.adb, prj.ads, prj-nmsc.adb, * gnatcmd.adb, prj-proc.adb, make.adb, prj.adb, prj.ads, prj-nmsc.adb,
......
...@@ -2694,10 +2694,21 @@ package body Exp_Ch5 is ...@@ -2694,10 +2694,21 @@ package body Exp_Ch5 is
-- and the declaration isn't marked as No_Initialization, then -- and the declaration isn't marked as No_Initialization, then
-- we need to generate an assignment to the object and insert -- we need to generate an assignment to the object and insert
-- it after the declaration before rewriting it as a renaming -- it after the declaration before rewriting it as a renaming
-- (otherwise we'll lose the initialization). -- (otherwise we'll lose the initialization). The case where
-- the result type is an interface (or class-wide interface)
-- is also excluded because the context of the function call
-- must be unconstrained, so the initialization will always
-- be done as part of an allocator evaluation (storage pool
-- or secondary stack), never to a constrained target object
-- passed in by the caller. Besides the assignment being
-- unneeded in this case, it avoids problems with trying to
-- generate a dispatching assignment when the return expression
-- is a nonlimited descendant of a limited interface (the
-- interface has no assignment operation).
if Present (Return_Obj_Expr) if Present (Return_Obj_Expr)
and then not No_Initialization (Return_Object_Decl) and then not No_Initialization (Return_Object_Decl)
and then not Is_Interface (Return_Obj_Typ)
then then
Init_Assignment := Init_Assignment :=
Make_Assignment_Statement (Loc, Make_Assignment_Statement (Loc,
...@@ -2822,12 +2833,21 @@ package body Exp_Ch5 is ...@@ -2822,12 +2833,21 @@ package body Exp_Ch5 is
if Present (Return_Obj_Expr) if Present (Return_Obj_Expr)
and then not No_Initialization (Return_Object_Decl) and then not No_Initialization (Return_Object_Decl)
then then
-- Always use the type of the expression for the
-- qualified expression, rather than the result type.
-- In general we cannot always use the result type
-- for the allocator, because the expression might be
-- of a specific type, such as in the case of an
-- aggregate or even a nonlimited object when the
-- result type is a limited class-wide interface type.
Heap_Allocator := Heap_Allocator :=
Make_Allocator (Loc, Make_Allocator (Loc,
Expression => Expression =>
Make_Qualified_Expression (Loc, Make_Qualified_Expression (Loc,
Subtype_Mark => Subtype_Mark =>
New_Reference_To (Return_Obj_Typ, Loc), New_Reference_To
(Etype (Return_Obj_Expr), Loc),
Expression => Expression =>
New_Copy_Tree (Return_Obj_Expr))); New_Copy_Tree (Return_Obj_Expr)));
......
...@@ -3065,7 +3065,6 @@ package body Exp_Ch6 is ...@@ -3065,7 +3065,6 @@ package body Exp_Ch6 is
if Needs_Finalization (Etype (Subp)) if Needs_Finalization (Etype (Subp))
and then not Is_Inherently_Limited_Type (Etype (Subp)) and then not Is_Inherently_Limited_Type (Etype (Subp))
and then not Is_Limited_Interface (Etype (Subp))
then then
Expand_Ctrl_Function_Call (N); Expand_Ctrl_Function_Call (N);
end if; end if;
...@@ -4653,12 +4652,10 @@ package body Exp_Ch6 is ...@@ -4653,12 +4652,10 @@ package body Exp_Ch6 is
then then
return False; return False;
-- If the return type is a limited interface it has to be treated -- In Ada 2005 all functions with an inherently limited return type
-- as a return in place, even if the actual object is some non- -- must be handled using a build-in-place profile, including the case
-- limited descendant. -- of a function with a limited interface result, where the function
-- may return objects of nonlimited descendants.
elsif Is_Limited_Interface (Etype (E)) then
return True;
else else
return Is_Inherently_Limited_Type (Etype (E)) return Is_Inherently_Limited_Type (Etype (E))
......
...@@ -776,7 +776,7 @@ package body Sem_Aggr is ...@@ -776,7 +776,7 @@ package body Sem_Aggr is
and then Comes_From_Source (Expr) and then Comes_From_Source (Expr)
and then not In_Instance_Body and then not In_Instance_Body
then then
if not OK_For_Limited_Init (Expr) then if not OK_For_Limited_Init (Etype (Expr), Expr) then
Error_Msg_N ("initialization not allowed for limited types", Expr); Error_Msg_N ("initialization not allowed for limited types", Expr);
Explain_Limited_Type (Etype (Expr), Expr); Explain_Limited_Type (Etype (Expr), Expr);
end if; end if;
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
-- -- -- --
-- B o d y -- -- B o d y --
-- -- -- --
-- Copyright (C) 1992-2008, Free Software Foundation, Inc. -- -- Copyright (C) 1992-2009, 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- --
...@@ -594,11 +594,16 @@ package body Sem_Aux is ...@@ -594,11 +594,16 @@ package body Sem_Aux is
return True; return True;
elsif Is_Record_Type (Btype) then elsif Is_Record_Type (Btype) then
-- Note that we return True for all limited interfaces, even though
-- (unsynchronized) limited interfaces can have descendants that are
-- nonlimited, because this is a predicate on the type itself, and
-- things like functions with limited interface results need to be
-- handled as build in place even though they might return objects
-- of a type that is not inherently limited.
if Is_Limited_Record (Btype) then if Is_Limited_Record (Btype) then
return not Is_Interface (Btype) return True;
or else Is_Protected_Interface (Btype)
or else Is_Synchronized_Interface (Btype)
or else Is_Task_Interface (Btype);
elsif Is_Class_Wide_Type (Btype) then elsif Is_Class_Wide_Type (Btype) then
return Is_Inherently_Limited_Type (Root_Type (Btype)); return Is_Inherently_Limited_Type (Root_Type (Btype));
...@@ -610,7 +615,16 @@ package body Sem_Aux is ...@@ -610,7 +615,16 @@ package body Sem_Aux is
begin begin
C := First_Component (Btype); C := First_Component (Btype);
while Present (C) loop while Present (C) loop
if Is_Inherently_Limited_Type (Etype (C)) then
-- Don't consider components with interface types (which can
-- only occur in the case of a _parent component anyway).
-- They don't have any components, plus it would cause this
-- function to return true for nonlimited types derived from
-- limited intefaces.
if not Is_Interface (Etype (C))
and then Is_Inherently_Limited_Type (Etype (C))
then
return True; return True;
end if; end if;
......
...@@ -1884,7 +1884,7 @@ package body Sem_Ch12 is ...@@ -1884,7 +1884,7 @@ package body Sem_Ch12 is
if Present (E) then if Present (E) then
Preanalyze_Spec_Expression (E, T); Preanalyze_Spec_Expression (E, T);
if Is_Limited_Type (T) and then not OK_For_Limited_Init (E) then if Is_Limited_Type (T) and then not OK_For_Limited_Init (T, E) then
Error_Msg_N Error_Msg_N
("initialization not allowed for limited types", E); ("initialization not allowed for limited types", E);
Explain_Limited_Type (T, E); Explain_Limited_Type (T, E);
...@@ -8434,7 +8434,7 @@ package body Sem_Ch12 is ...@@ -8434,7 +8434,7 @@ package body Sem_Ch12 is
end if; end if;
if Is_Limited_Type (Typ) if Is_Limited_Type (Typ)
and then not OK_For_Limited_Init (Actual) and then not OK_For_Limited_Init (Typ, Actual)
then then
Error_Msg_N Error_Msg_N
("initialization not allowed for limited types", Actual); ("initialization not allowed for limited types", Actual);
......
...@@ -8780,7 +8780,7 @@ package body Sem_Ch3 is ...@@ -8780,7 +8780,7 @@ package body Sem_Ch3 is
and then not In_Instance and then not In_Instance
and then not In_Inlined_Body and then not In_Inlined_Body
then then
if not OK_For_Limited_Init (Exp) then if not OK_For_Limited_Init (T, Exp) then
-- In GNAT mode, this is just a warning, to allow it to be evilly -- In GNAT mode, this is just a warning, to allow it to be evilly
-- turned off. Otherwise it is a real error. -- turned off. Otherwise it is a real error.
...@@ -15316,20 +15316,36 @@ package body Sem_Ch3 is ...@@ -15316,20 +15316,36 @@ package body Sem_Ch3 is
-- ???Check all calls of this, and compare the conditions under which it's -- ???Check all calls of this, and compare the conditions under which it's
-- called. -- called.
function OK_For_Limited_Init (Exp : Node_Id) return Boolean is function OK_For_Limited_Init
(Typ : Entity_Id;
Exp : Node_Id) return Boolean
is
begin begin
return Is_CPP_Constructor_Call (Exp) return Is_CPP_Constructor_Call (Exp)
or else (Ada_Version >= Ada_05 or else (Ada_Version >= Ada_05
and then not Debug_Flag_Dot_L and then not Debug_Flag_Dot_L
and then OK_For_Limited_Init_In_05 (Exp)); and then OK_For_Limited_Init_In_05 (Typ, Exp));
end OK_For_Limited_Init; end OK_For_Limited_Init;
------------------------------- -------------------------------
-- OK_For_Limited_Init_In_05 -- -- OK_For_Limited_Init_In_05 --
------------------------------- -------------------------------
function OK_For_Limited_Init_In_05 (Exp : Node_Id) return Boolean is function OK_For_Limited_Init_In_05
(Typ : Entity_Id;
Exp : Node_Id) return Boolean
is
begin begin
-- An object of a limited interface type can be initialized with any
-- expression of a nonlimited descendant type.
if Is_Class_Wide_Type (Typ)
and then Is_Limited_Interface (Typ)
and then not Is_Limited_Type (Etype (Exp))
then
return True;
end if;
-- Ada 2005 (AI-287, AI-318): Relax the strictness of the front end in -- Ada 2005 (AI-287, AI-318): Relax the strictness of the front end in
-- case of limited aggregates (including extension aggregates), and -- case of limited aggregates (including extension aggregates), and
-- function calls. The function call may have been give in prefixed -- function calls. The function call may have been give in prefixed
...@@ -15341,7 +15357,8 @@ package body Sem_Ch3 is ...@@ -15341,7 +15357,8 @@ package body Sem_Ch3 is
when N_Qualified_Expression => when N_Qualified_Expression =>
return return
OK_For_Limited_Init_In_05 (Expression (Original_Node (Exp))); OK_For_Limited_Init_In_05
(Typ, Expression (Original_Node (Exp)));
-- Ada 2005 (AI-251): If a class-wide interface object is initialized -- Ada 2005 (AI-251): If a class-wide interface object is initialized
-- with a function call, the expander has rewritten the call into an -- with a function call, the expander has rewritten the call into an
...@@ -15354,7 +15371,8 @@ package body Sem_Ch3 is ...@@ -15354,7 +15371,8 @@ package body Sem_Ch3 is
when N_Type_Conversion | N_Unchecked_Type_Conversion => when N_Type_Conversion | N_Unchecked_Type_Conversion =>
return not Comes_From_Source (Exp) return not Comes_From_Source (Exp)
and then and then
OK_For_Limited_Init_In_05 (Expression (Original_Node (Exp))); OK_For_Limited_Init_In_05
(Typ, Expression (Original_Node (Exp)));
when N_Indexed_Component | N_Selected_Component => when N_Indexed_Component | N_Selected_Component =>
return Nkind (Exp) = N_Function_Call; return Nkind (Exp) = N_Function_Call;
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
-- -- -- --
-- S p e c -- -- S p e c --
-- -- -- --
-- Copyright (C) 1992-2008, Free Software Foundation, Inc. -- -- Copyright (C) 1992-2009, 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- --
...@@ -182,18 +182,24 @@ package Sem_Ch3 is ...@@ -182,18 +182,24 @@ package Sem_Ch3 is
-- wide type is created at the same time, and therefore there is a private -- wide type is created at the same time, and therefore there is a private
-- and a full declaration for the class-wide type as well. -- and a full declaration for the class-wide type as well.
function OK_For_Limited_Init_In_05 (Exp : Node_Id) return Boolean; function OK_For_Limited_Init_In_05
-- Presuming Exp is an expression of an inherently limited type, returns (Typ : Entity_Id;
-- True if the expression is allowed in an initialization context by the Exp : Node_Id) return Boolean;
-- rules of Ada 2005. We use the rule in RM-7.5(2.1/2), "...it is an -- Presuming Exp is an expression of an inherently limited type Typ,
-- aggregate, a function_call, or a parenthesized expression or -- returns True if the expression is allowed in an initialization context
-- qualified_expression whose operand is permitted...". Note that in Ada -- by the rules of Ada 2005. We use the rule in RM-7.5(2.1/2), "...it is an
-- 95 mode, we sometimes wish to give warnings based on whether the -- aggregate, a function_call, or a parenthesized expression or qualified
-- program _would_ be legal in Ada 2005. Note that Exp must already have -- expression whose operand is permitted...". Note that in Ada 95 mode,
-- been resolved, so we can know whether it's a function call (as opposed -- we sometimes wish to give warnings based on whether the program _would_
-- to an indexed component, for example). -- be legal in Ada 2005. Note that Exp must already have been resolved,
-- so we can know whether it's a function call (as opposed to an indexed
function OK_For_Limited_Init (Exp : Node_Id) return Boolean; -- component, for example). In the case where Typ is a limited interface's
-- class-wide type, then the expression is allowed to be of any kind if its
-- type is a nonlimited descendant of the interface.
function OK_For_Limited_Init
(Typ : Entity_Id;
Exp : Node_Id) return Boolean;
-- Always False in Ada 95 mode. Equivalent to OK_For_Limited_Init_In_05 in -- Always False in Ada 95 mode. Equivalent to OK_For_Limited_Init_In_05 in
-- Ada 2005 mode. -- Ada 2005 mode.
......
...@@ -387,7 +387,7 @@ package body Sem_Ch4 is ...@@ -387,7 +387,7 @@ package body Sem_Ch4 is
and then Comes_From_Source (N) and then Comes_From_Source (N)
and then not In_Instance_Body and then not In_Instance_Body
then then
if not OK_For_Limited_Init (Expression (E)) then if not OK_For_Limited_Init (Type_Id, Expression (E)) then
Error_Msg_N ("initialization not allowed for limited types", N); Error_Msg_N ("initialization not allowed for limited types", N);
Explain_Limited_Type (Type_Id, N); Explain_Limited_Type (Type_Id, N);
end if; end if;
......
...@@ -464,7 +464,7 @@ package body Sem_Ch6 is ...@@ -464,7 +464,7 @@ package body Sem_Ch6 is
if Is_Limited_Type (R_Type) if Is_Limited_Type (R_Type)
and then Comes_From_Source (N) and then Comes_From_Source (N)
and then not In_Instance_Body and then not In_Instance_Body
and then not OK_For_Limited_Init_In_05 (Expr) and then not OK_For_Limited_Init_In_05 (R_Type, Expr)
then then
-- Error in Ada 2005 -- Error in Ada 2005
......
...@@ -2367,8 +2367,10 @@ package body Sem_Type is ...@@ -2367,8 +2367,10 @@ package body Sem_Type is
-- Start of processing for Interface_Present_In_Ancestor -- Start of processing for Interface_Present_In_Ancestor
begin begin
-- Iface might be a class-wide subtype, so we have to apply Base_Type
if Is_Class_Wide_Type (Iface) then if Is_Class_Wide_Type (Iface) then
Iface_Typ := Etype (Iface); Iface_Typ := Etype (Base_Type (Iface));
else else
Iface_Typ := Iface; Iface_Typ := Iface;
end if; end if;
......
...@@ -820,12 +820,19 @@ package VMS_Data is ...@@ -820,12 +820,19 @@ package VMS_Data is
-- --
-- Work quietly, only output warnings and errors. -- Work quietly, only output warnings and errors.
S_Check_Time : aliased constant S := "/TIME " & S_Check_Time : aliased constant S := "/TIME " &
"-t"; "-t";
-- /NOTIME (D) -- /NOTIME (D)
-- /QUIET -- /TIME
--
-- Print out execution time
S_Check_Log : aliased constant S := "/LOG " &
"-log";
-- /NOLOG (D)
-- /LOG
-- --
-- Print out execution time -- Duplicate all the output sent to Stderr into a log file.
S_Check_Sections : aliased constant S := "/SECTIONS=" & S_Check_Sections : aliased constant S := "/SECTIONS=" &
"DEFAULT " & "DEFAULT " &
...@@ -901,6 +908,7 @@ package VMS_Data is ...@@ -901,6 +908,7 @@ package VMS_Data is
S_Check_Project 'Access, S_Check_Project 'Access,
S_Check_Quiet 'Access, S_Check_Quiet 'Access,
S_Check_Time 'Access, S_Check_Time 'Access,
S_Check_Log 'Access,
S_Check_Sections 'Access, S_Check_Sections 'Access,
S_Check_Short 'Access, S_Check_Short 'Access,
S_Check_Subdirs 'Access, S_Check_Subdirs 'Access,
......
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