Commit 58827738 by Arnaud Charlet

[multiple changes]

2014-01-20  Hristian Kirtchev  <kirtchev@adacore.com>

	* sem_prag.adb (Analyze_Pragma): Ensure that
	the sole argument of pragmas Abstract_State, Contract_Cases,
	Depends, Global and Initializes in in aggregate form.
	(Analyze_Refined_Pragma): Ensure that the sole argument of
	pragmas Refined_Depends, Refined_Global and Refined_State is in
	aggregate form.
	(Ensure_Aggregate_Form): New routine.

2014-01-20  Doug Rupp  <rupp@adacore.com>

	* sem_attr.adb (Analyze_Attribute): case
	Attribute_Constrained => treat all prefixes as legal for Declib
	compatibility.

From-SVN: r206836
parent 9559eccf
2014-01-20 Hristian Kirtchev <kirtchev@adacore.com> 2014-01-20 Hristian Kirtchev <kirtchev@adacore.com>
* sem_prag.adb (Analyze_Pragma): Ensure that
the sole argument of pragmas Abstract_State, Contract_Cases,
Depends, Global and Initializes in in aggregate form.
(Analyze_Refined_Pragma): Ensure that the sole argument of
pragmas Refined_Depends, Refined_Global and Refined_State is in
aggregate form.
(Ensure_Aggregate_Form): New routine.
2014-01-20 Doug Rupp <rupp@adacore.com>
* sem_attr.adb (Analyze_Attribute): case
Attribute_Constrained => treat all prefixes as legal for Declib
compatibility.
2014-01-20 Hristian Kirtchev <kirtchev@adacore.com>
* sem_prag.adb (Check_Mode): Reimplement the routine. * sem_prag.adb (Check_Mode): Reimplement the routine.
(Find_Mode): New routine. (Find_Mode): New routine.
......
...@@ -3037,6 +3037,15 @@ package body Sem_Attr is ...@@ -3037,6 +3037,15 @@ package body Sem_Attr is
and then Extensions_Allowed and then Extensions_Allowed
then then
return; return;
-- For compatibility with Declib code, treat all prefixes as
-- legal, including non-discriminated types.
-- ??? this non-conforming language extension needs documenting
-- ??? anyway it should not depend on Extend_System!
elsif Present (System_Extend_Unit) then
return;
end if; end if;
end if; end if;
......
----------------------------------------------------------------------------- ------------------------------------------------------------------------------
-- -- -- --
-- GNAT COMPILER COMPONENTS -- -- GNAT COMPILER COMPONENTS --
-- -- -- --
...@@ -449,39 +449,38 @@ package body Sem_Prag is ...@@ -449,39 +449,38 @@ package body Sem_Prag is
Subp_Id := Defining_Entity (Subp_Decl); Subp_Id := Defining_Entity (Subp_Decl);
All_Cases := Get_Pragma_Arg (First (Pragma_Argument_Associations (N))); All_Cases := Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
-- Multiple contract cases appear in aggregate form -- Single and multiple contract cases must appear in aggregate form. If
-- this is not the case, then either the parser of the analysis of the
if Nkind (All_Cases) = N_Aggregate then -- pragma failed to produce an aggregate.
if No (Component_Associations (All_Cases)) then
Error_Msg_N ("wrong syntax for aspect Contract_Cases", N);
-- Individual contract cases appear as component associations pragma Assert (Nkind (All_Cases) = N_Aggregate);
else if No (Component_Associations (All_Cases)) then
-- Ensure that the formal parameters are visible when analyzing Error_Msg_N ("wrong syntax for aspect Contract_Cases", N);
-- all clauses. This falls out of the general rule of aspects
-- pertaining to subprogram declarations. Skip the installation
-- for subprogram bodies because the formals are already visible.
if not In_Open_Scopes (Subp_Id) then -- Individual contract cases appear as component associations
Restore_Scope := True;
Push_Scope (Subp_Id);
Install_Formals (Subp_Id);
end if;
CCase := First (Component_Associations (All_Cases)); else
while Present (CCase) loop -- Ensure that the formal parameters are visible when analyzing all
Analyze_Contract_Case (CCase); -- clauses. This falls out of the general rule of aspects pertaining
Next (CCase); -- to subprogram declarations. Skip the installation for subprogram
end loop; -- bodies because the formals are already visible.
if Restore_Scope then if not In_Open_Scopes (Subp_Id) then
End_Scope; Restore_Scope := True;
end if; Push_Scope (Subp_Id);
Install_Formals (Subp_Id);
end if; end if;
else CCase := First (Component_Associations (All_Cases));
Error_Msg_N ("wrong syntax for aspect Contract_Cases", N); while Present (CCase) loop
Analyze_Contract_Case (CCase);
Next (CCase);
end loop;
if Restore_Scope then
End_Scope;
end if;
end if; end if;
end Analyze_Contract_Cases_In_Decl_Part; end Analyze_Contract_Cases_In_Decl_Part;
...@@ -2577,32 +2576,26 @@ package body Sem_Prag is ...@@ -2577,32 +2576,26 @@ package body Sem_Prag is
Collect_States_And_Variables; Collect_States_And_Variables;
-- Multiple initialization clauses appear as an aggregate -- Single and multiple initialization clauses must appear as an
-- aggregate. If this is not the case, then either the parser of
-- the analysis of the pragma failed to produce an aggregate.
if Nkind (Inits) = N_Aggregate then pragma Assert (Nkind (Inits) = N_Aggregate);
if Present (Expressions (Inits)) then
Init := First (Expressions (Inits));
while Present (Init) loop
Analyze_Initialization_Item (Init);
Next (Init);
end loop;
end if;
if Present (Component_Associations (Inits)) then if Present (Expressions (Inits)) then
Init := First (Component_Associations (Inits)); Init := First (Expressions (Inits));
while Present (Init) loop while Present (Init) loop
Analyze_Initialization_Item_With_Inputs (Init); Analyze_Initialization_Item (Init);
Next (Init);
Next (Init); end loop;
end loop; end if;
end if;
-- Various forms of a single initialization clause. Note that these may
-- include malformed initializations.
else if Present (Component_Associations (Inits)) then
Analyze_Initialization_Item (Inits); Init := First (Component_Associations (Inits));
while Present (Init) loop
Analyze_Initialization_Item_With_Inputs (Init);
Next (Init);
end loop;
end if; end if;
end Analyze_Initializes_In_Decl_Part; end Analyze_Initializes_In_Decl_Part;
...@@ -2620,8 +2613,8 @@ package body Sem_Prag is ...@@ -2620,8 +2613,8 @@ package body Sem_Prag is
-- name may be different from the pragma name. -- name may be different from the pragma name.
Pragma_Exit : exception; Pragma_Exit : exception;
-- This exception is used to exit pragma processing completely. It is -- This exception is used to exit pragma processing completely. It
-- used when an error is detected, and no further processing is -- is used when an error is detected, and no further processing is
-- required. It is also used if an earlier error has left the tree in -- required. It is also used if an earlier error has left the tree in
-- a state where the pragma should not be processed. -- a state where the pragma should not be processed.
...@@ -2656,8 +2649,8 @@ package body Sem_Prag is ...@@ -2656,8 +2649,8 @@ package body Sem_Prag is
-- Subsidiary routine to the analysis of body pragmas Refined_Depends, -- Subsidiary routine to the analysis of body pragmas Refined_Depends,
-- Refined_Global and Refined_Post. Check the placement and related -- Refined_Global and Refined_Post. Check the placement and related
-- context of the pragma. Spec_Id is the entity of the related -- context of the pragma. Spec_Id is the entity of the related
-- subprogram. Body_Id is the entity of the subprogram body. Flag Legal -- subprogram. Body_Id is the entity of the subprogram body. Flag
-- is set when the pragma is properly placed. -- Legal is set when the pragma is properly placed.
procedure Check_Ada_83_Warning; procedure Check_Ada_83_Warning;
-- Issues a warning message for the current pragma if operating in Ada -- Issues a warning message for the current pragma if operating in Ada
...@@ -2910,6 +2903,12 @@ package body Sem_Prag is ...@@ -2910,6 +2903,12 @@ package body Sem_Prag is
-- presence of at least one component. UU_Typ is the related Unchecked_ -- presence of at least one component. UU_Typ is the related Unchecked_
-- Union type. -- Union type.
procedure Ensure_Aggregate_Form (Arg : Node_Id);
-- Subsidiary routine to the processing of pragmas Abstract_State,
-- Contract_Cases, Depends, Global, Initializes, Refined_Depends,
-- Refined_Global and Refined_State. Transform argument Arg into an
-- aggregate if not one already. N_Null is never transformed.
procedure Error_Pragma (Msg : String); procedure Error_Pragma (Msg : String);
pragma No_Return (Error_Pragma); pragma No_Return (Error_Pragma);
-- Outputs error message for current pragma. The message contains a % -- Outputs error message for current pragma. The message contains a %
...@@ -2936,15 +2935,15 @@ package body Sem_Prag is ...@@ -2936,15 +2935,15 @@ package body Sem_Prag is
procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id); procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
pragma No_Return (Error_Pragma_Arg_Ident); pragma No_Return (Error_Pragma_Arg_Ident);
-- Outputs error message for current pragma. The message may contain -- Outputs error message for current pragma. The message may contain a %
-- a % that will be replaced with the pragma name. The parameter Arg -- that will be replaced with the pragma name. The parameter Arg must be
-- must be a pragma argument association with a non-empty identifier -- a pragma argument association with a non-empty identifier (i.e. its
-- (i.e. its Chars field must be set), and the error message is placed -- Chars field must be set), and the error message is placed on the
-- on the identifier. The message is placed using Error_Msg_N so -- identifier. The message is placed using Error_Msg_N so the message
-- the message may also contain an & insertion character which will -- may also contain an & insertion character which will reference
-- reference the identifier. After placing the message, Pragma_Exit -- the identifier. After placing the message, Pragma_Exit is raised.
-- is raised. Note: this routine calls Fix_Error (see spec of that -- Note: this routine calls Fix_Error (see spec of that procedure for
-- procedure for details). -- details).
procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id); procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
pragma No_Return (Error_Pragma_Ref); pragma No_Return (Error_Pragma_Ref);
...@@ -3221,6 +3220,13 @@ package body Sem_Prag is ...@@ -3221,6 +3220,13 @@ package body Sem_Prag is
Check_Arg_Count (1); Check_Arg_Count (1);
Check_No_Identifiers; Check_No_Identifiers;
if Nam_In (Pname, Name_Refined_Depends,
Name_Refined_Global,
Name_Refined_State)
then
Ensure_Aggregate_Form (Arg1);
end if;
-- Verify the placement of the pragma and check for duplicates. The -- Verify the placement of the pragma and check for duplicates. The
-- pragma must apply to a subprogram body [stub]. -- pragma must apply to a subprogram body [stub].
...@@ -5110,6 +5116,70 @@ package body Sem_Prag is ...@@ -5110,6 +5116,70 @@ package body Sem_Prag is
end loop; end loop;
end Check_Variant; end Check_Variant;
---------------------------
-- Ensure_Aggregate_Form --
---------------------------
procedure Ensure_Aggregate_Form (Arg : Node_Id) is
Expr : constant Node_Id := Get_Pragma_Arg (Arg);
Loc : constant Source_Ptr := Sloc (Arg);
Nam : constant Name_Id := Chars (Arg);
Comps : List_Id := No_List;
Exprs : List_Id := No_List;
begin
-- The argument is already in aggregate form, but the presence of a
-- name causes this to be interpreted as a named association which in
-- turn must be converted into an aggregate.
-- pragma Global (In_Out => (A, B, C))
-- ^ ^
-- name aggregate
-- pragma Global ((In_Out => (A, B, C)))
-- ^ ^
-- aggregate aggregate
if Nkind (Expr) = N_Aggregate then
if Nam = No_Name then
return;
end if;
-- Do not transform a null argument into an aggregate as N_Null has
-- special meaning in formal verification pragmas.
elsif Nkind (Expr) = N_Null then
return;
end if;
-- Positional argument is transformed into an aggregate with an
-- Expressions list.
if Nam = No_Name then
Exprs := New_List (Relocate_Node (Expr));
-- An associative argument is transformed into an aggregate with
-- Component_Associations.
else
Comps := New_List (
Make_Component_Association (Loc,
Choices => New_List (Make_Identifier (Loc, Chars (Arg))),
Expression => Relocate_Node (Expr)));
end if;
-- Remove the pragma argument name as this information has been
-- captured in the aggregate.
Set_Chars (Arg, No_Name);
Set_Expression (Arg,
Make_Aggregate (Loc,
Component_Associations => Comps,
Expressions => Exprs));
end Ensure_Aggregate_Form;
------------------ ------------------
-- Error_Pragma -- -- Error_Pragma --
------------------ ------------------
...@@ -9654,6 +9724,7 @@ package body Sem_Prag is ...@@ -9654,6 +9724,7 @@ package body Sem_Prag is
GNAT_Pragma; GNAT_Pragma;
S14_Pragma; S14_Pragma;
Check_Arg_Count (1); Check_Arg_Count (1);
Ensure_Aggregate_Form (Arg1);
-- Ensure the proper placement of the pragma. Abstract states must -- Ensure the proper placement of the pragma. Abstract states must
-- be associated with a package declaration. -- be associated with a package declaration.
...@@ -9677,7 +9748,7 @@ package body Sem_Prag is ...@@ -9677,7 +9748,7 @@ package body Sem_Prag is
State := Expression (Arg1); State := Expression (Arg1);
-- Multiple abstract states appear as an aggregate -- Multiple non-null abstract states appear as an aggregate
if Nkind (State) = N_Aggregate then if Nkind (State) = N_Aggregate then
State := First (Expressions (State)); State := First (Expressions (State));
...@@ -11305,6 +11376,7 @@ package body Sem_Prag is ...@@ -11305,6 +11376,7 @@ package body Sem_Prag is
begin begin
GNAT_Pragma; GNAT_Pragma;
Check_Arg_Count (1); Check_Arg_Count (1);
Ensure_Aggregate_Form (Arg1);
-- The pragma is analyzed at the end of the declarative part which -- The pragma is analyzed at the end of the declarative part which
-- contains the related subprogram. Reset the analyzed flag. -- contains the related subprogram. Reset the analyzed flag.
...@@ -11824,6 +11896,7 @@ package body Sem_Prag is ...@@ -11824,6 +11896,7 @@ package body Sem_Prag is
GNAT_Pragma; GNAT_Pragma;
S14_Pragma; S14_Pragma;
Check_Arg_Count (1); Check_Arg_Count (1);
Ensure_Aggregate_Form (Arg1);
-- Ensure the proper placement of the pragma. Depends must be -- Ensure the proper placement of the pragma. Depends must be
-- associated with a subprogram declaration or a body that acts -- associated with a subprogram declaration or a body that acts
...@@ -13094,6 +13167,7 @@ package body Sem_Prag is ...@@ -13094,6 +13167,7 @@ package body Sem_Prag is
GNAT_Pragma; GNAT_Pragma;
S14_Pragma; S14_Pragma;
Check_Arg_Count (1); Check_Arg_Count (1);
Ensure_Aggregate_Form (Arg1);
-- Ensure the proper placement of the pragma. Global must be -- Ensure the proper placement of the pragma. Global must be
-- associated with a subprogram declaration or a body that acts -- associated with a subprogram declaration or a body that acts
...@@ -13937,6 +14011,7 @@ package body Sem_Prag is ...@@ -13937,6 +14011,7 @@ package body Sem_Prag is
GNAT_Pragma; GNAT_Pragma;
S14_Pragma; S14_Pragma;
Check_Arg_Count (1); Check_Arg_Count (1);
Ensure_Aggregate_Form (Arg1);
-- Ensure the proper placement of the pragma. Initializes must be -- Ensure the proper placement of the pragma. Initializes must be
-- associated with a package declaration. -- associated with a package declaration.
...@@ -22116,7 +22191,7 @@ package body Sem_Prag is ...@@ -22116,7 +22191,7 @@ package body Sem_Prag is
Abstr_States := New_Copy_Elist (Abstract_States (Spec_Id)); Abstr_States := New_Copy_Elist (Abstract_States (Spec_Id));
Collect_Hidden_States; Collect_Hidden_States;
-- Multiple state refinements appear as an aggregate -- Multiple non-null state refinements appear as an aggregate
if Nkind (Clauses) = N_Aggregate then if Nkind (Clauses) = N_Aggregate then
if Present (Expressions (Clauses)) then if Present (Expressions (Clauses)) then
......
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