Commit b0186f71 by Arnaud Charlet

[multiple changes]

2011-08-02  Robert Dewar  <dewar@adacore.com>

	* exp_util.adb, par-ch10.adb, par-ch6.adb, sem.adb, sem_ch6.adb,
	sem_ch6.ads, sinfo.adb, sinfo.ads, sprint.adb: Change parameterized
	expression to expression function.

2011-08-02  Ed Schonberg  <schonberg@adacore.com>

	* sem_ch4.adb: transform simple Ada2012 membership into equality only
	if types are compatible.

2011-08-02  Yannick Moy  <moy@adacore.com>

	* sem_res.adb (Matching_Static_Array_Bounds): new function which
	returns True if its argument array types have same dimension and same
	static bounds at each index.
	(Resolve_Actuals): issue an error in formal mode on actuals passed as
	OUT or IN OUT paramaters which are not view conversions in SPARK.
	(Resolve_Arithmetic_Op): issue an error in formal mode on
	multiplication or division with operands of fixed point types which are
	not qualified or explicitly converted.
	(Resolve_Comparison_Op): issue an error in formal mode on comparisons of
	Boolean or array type (except String) operands.
	(Resolve_Equality_Op): issue an error in formal mode on equality
	operators for array types other than String with non-matching static
	bounds.
	(Resolve_Logical_Op): issue an error in formal mode on logical operators
	for array types with non-matching static bounds. Factorize the code in
	Matching_Static_Array_Bounds.
	(Resolve_Qualified_Expression): issue an error in formal mode on
	qualified expressions for array types with non-matching static bounds.
	(Resolve_Type_Conversion): issue an error in formal mode on type
	conversion for array types with non-matching static bounds

From-SVN: r177089
parent 767bb4e8
2011-08-02 Robert Dewar <dewar@adacore.com>
* exp_util.adb, par-ch10.adb, par-ch6.adb, sem.adb, sem_ch6.adb,
sem_ch6.ads, sinfo.adb, sinfo.ads, sprint.adb: Change parameterized
expression to expression function.
2011-08-02 Ed Schonberg <schonberg@adacore.com>
* sem_ch4.adb: transform simple Ada2012 membership into equality only
if types are compatible.
2011-08-02 Yannick Moy <moy@adacore.com>
* sem_res.adb (Matching_Static_Array_Bounds): new function which
returns True if its argument array types have same dimension and same
static bounds at each index.
(Resolve_Actuals): issue an error in formal mode on actuals passed as
OUT or IN OUT paramaters which are not view conversions in SPARK.
(Resolve_Arithmetic_Op): issue an error in formal mode on
multiplication or division with operands of fixed point types which are
not qualified or explicitly converted.
(Resolve_Comparison_Op): issue an error in formal mode on comparisons of
Boolean or array type (except String) operands.
(Resolve_Equality_Op): issue an error in formal mode on equality
operators for array types other than String with non-matching static
bounds.
(Resolve_Logical_Op): issue an error in formal mode on logical operators
for array types with non-matching static bounds. Factorize the code in
Matching_Static_Array_Bounds.
(Resolve_Qualified_Expression): issue an error in formal mode on
qualified expressions for array types with non-matching static bounds.
(Resolve_Type_Conversion): issue an error in formal mode on type
conversion for array types with non-matching static bounds
2011-08-02 Robert Dewar <dewar@adacore.com>
* par-ch10.adb: Minor code reorganization (use Nkind_In).
2011-08-02 Ed Schonberg <schonberg@adacore.com>
......
......@@ -2592,6 +2592,7 @@ package body Exp_Util is
N_Entry_Body |
N_Exception_Declaration |
N_Exception_Renaming_Declaration |
N_Expression_Function |
N_Formal_Abstract_Subprogram_Declaration |
N_Formal_Concrete_Subprogram_Declaration |
N_Formal_Object_Declaration |
......@@ -2613,7 +2614,6 @@ package body Exp_Util is
N_Package_Declaration |
N_Package_Instantiation |
N_Package_Renaming_Declaration |
N_Parameterized_Expression |
N_Private_Extension_Declaration |
N_Private_Type_Declaration |
N_Procedure_Instantiation |
......
......@@ -562,9 +562,9 @@ package body Ch10 is
then
Name_Node := Defining_Unit_Name (Unit_Node);
elsif Nkind (Unit_Node) = N_Parameterized_Expression then
elsif Nkind (Unit_Node) = N_Expression_Function then
Error_Msg_SP
("parameterized expression cannot be used as compilation unit");
("expression function cannot be used as compilation unit");
return Comp_Unit_Node;
-- Anything else is a serious error, abandon scan
......
......@@ -82,7 +82,7 @@ package body Ch6 is
-- This routine scans out a subprogram declaration, subprogram body,
-- subprogram renaming declaration or subprogram generic instantiation.
-- It also handles the new Ada 2012 parameterized expression form
-- It also handles the new Ada 2012 expression function form
-- SUBPROGRAM_DECLARATION ::=
-- SUBPROGRAM_SPECIFICATION
......@@ -126,7 +126,7 @@ package body Ch6 is
-- is classified as a basic declarative item, but it is parsed here, with
-- other subprogram constructs.
-- PARAMETERIZED_EXPRESSION ::=
-- EXPRESSION_FUNCTION ::=
-- FUNCTION SPECIFICATION IS (EXPRESSION);
-- The value in Pf_Flags indicates which of these possible declarations
......@@ -137,7 +137,7 @@ package body Ch6 is
-- Pf_Flags.Pbod Set if proper body OK
-- Pf_Flags.Rnam Set if renaming declaration OK
-- Pf_Flags.Stub Set if body stub OK
-- Pf_Flags.Pexp Set if parameterized expression OK
-- Pf_Flags.Pexp Set if expression function OK
-- If an inappropriate form is encountered, it is scanned out but an
-- error message indicating that it is appearing in an inappropriate
......@@ -598,7 +598,7 @@ package body Ch6 is
end if;
end if;
-- Processing for stub or subprogram body or parameterized expression
-- Processing for stub or subprogram body or expression function
<<Subprogram_Body>>
......@@ -623,21 +623,21 @@ package body Ch6 is
TF_Semicolon;
return Stub_Node;
-- Subprogram body or parameterized expression case
-- Subprogram body or expression function case
else
Scan_Body_Or_Parameterized_Expression : declare
Scan_Body_Or_Expression_Function : declare
function Likely_Parameterized_Expression return Boolean;
-- Returns True if we have a probably case of a parameterized
-- expression omitting the parentheses, if so, returns True
function Likely_Expression_Function return Boolean;
-- Returns True if we have a probable case of an expression
-- function omitting the parentheses, if so, returns True
-- and emits an appropriate error message, else returns False.
-------------------------------------
-- Likely_Parameterized_Expression --
-------------------------------------
--------------------------------
-- Likely_Expression_Function --
--------------------------------
function Likely_Parameterized_Expression return Boolean is
function Likely_Expression_Function return Boolean is
begin
-- If currently pointing to BEGIN or a declaration keyword
-- or a pragma, then we definitely have a subprogram body.
......@@ -650,15 +650,15 @@ package body Ch6 is
return False;
-- Test for tokens which could only start an expression and
-- thus signal the case of a parameterized expression.
-- thus signal the case of a expression function.
elsif Token in Token_Class_Literal
elsif Token in Token_Class_Literal
or else Token in Token_Class_Unary_Addop
or else Token = Tok_Left_Paren
or else Token = Tok_Abs
or else Token = Tok_Null
or else Token = Tok_New
or else Token = Tok_Not
or else Token = Tok_Left_Paren
or else Token = Tok_Abs
or else Token = Tok_Null
or else Token = Tok_New
or else Token = Tok_Not
then
null;
......@@ -680,12 +680,13 @@ package body Ch6 is
-- Otherwise we have to scan ahead. If the identifier is
-- followed by a colon or a comma, it is a declaration
-- and hence we have a subprogram body. Otherwise assume
-- a parameterized expression.
-- a expression function.
else
declare
Scan_State : Saved_Scan_State;
Tok : Token_Type;
begin
Save_Scan_State (Scan_State);
Scan; -- past identifier
......@@ -699,43 +700,41 @@ package body Ch6 is
end if;
end if;
-- Fall through if we have a likely parameterized expression
-- Fall through if we have a likely expression function
Error_Msg_SC
("parameterized expression must be "
& "enclosed in parentheses");
("expression function must be enclosed in parentheses");
return True;
end Likely_Parameterized_Expression;
end Likely_Expression_Function;
-- Start of processing for Scan_Body_Or_Parameterized_Expression
-- Start of processing for Scan_Body_Or_Expression_Function
begin
-- Parameterized_Expression case
-- Expression_Function case
if Token = Tok_Left_Paren
or else Likely_Parameterized_Expression
or else Likely_Expression_Function
then
-- Check parameterized expression allowed here
-- Check expression function allowed here
if not Pf_Flags.Pexp then
Error_Msg_SC
("parameterized expression not allowed here!");
Error_Msg_SC ("expression function not allowed here!");
end if;
-- Check we are in Ada 2012 mode
if Ada_Version < Ada_2012 then
Error_Msg_SC
("parameterized expression is an Ada 2012 feature!");
("expression function is an Ada 2012 feature!");
Error_Msg_SC
("\unit must be compiled with -gnat2012 switch!");
end if;
-- Parse out expression and build parameterized expression
-- Parse out expression and build expression function
Body_Node :=
New_Node
(N_Parameterized_Expression, Sloc (Specification_Node));
(N_Expression_Function, Sloc (Specification_Node));
Set_Specification (Body_Node, Specification_Node);
Set_Expression (Body_Node, P_Expression);
T_Semicolon;
......@@ -775,7 +774,7 @@ package body Ch6 is
end if;
return Body_Node;
end Scan_Body_Or_Parameterized_Expression;
end Scan_Body_Or_Expression_Function;
end if;
-- Processing for subprogram declaration
......
......@@ -223,6 +223,9 @@ package body Sem is
when N_Explicit_Dereference =>
Analyze_Explicit_Dereference (N);
when N_Expression_Function =>
Analyze_Expression_Function (N);
when N_Expression_With_Actions =>
Analyze_Expression_With_Actions (N);
......@@ -439,9 +442,6 @@ package body Sem is
when N_Parameter_Association =>
Analyze_Parameter_Association (N);
when N_Parameterized_Expression =>
Analyze_Parameterized_Expression (N);
when N_Pragma =>
Analyze_Pragma (N);
......
......@@ -2475,7 +2475,8 @@ package body Sem_Ch4 is
end if;
-- If not a range, it can be a subtype mark, or else it is a degenerate
-- membership test with a singleton value, i.e. a test for equality.
-- membership test with a singleton value, i.e. a test for equality,
-- if the types are compatible.
else
Analyze (R);
......@@ -2485,7 +2486,9 @@ package body Sem_Ch4 is
Find_Type (R);
Check_Fully_Declared (Entity (R), R);
elsif Ada_Version >= Ada_2012 then
elsif Ada_Version >= Ada_2012
and then Has_Compatible_Type (R, Etype (L))
then
if Nkind (N) = N_In then
Rewrite (N,
Make_Op_Eq (Loc,
......@@ -2502,8 +2505,8 @@ package body Sem_Ch4 is
return;
else
-- In previous version of the language this is an error that will
-- be diagnosed below.
-- In all versions of the language, if we reach this point there
-- is a previous error that will be diagnosed below.
Find_Type (R);
end if;
......
......@@ -35,11 +35,11 @@ package Sem_Ch6 is
-- type is stronger than the ones preceding it.
procedure Analyze_Abstract_Subprogram_Declaration (N : Node_Id);
procedure Analyze_Expression_Function (N : Node_Id);
procedure Analyze_Extended_Return_Statement (N : Node_Id);
procedure Analyze_Function_Call (N : Node_Id);
procedure Analyze_Operator_Symbol (N : Node_Id);
procedure Analyze_Parameter_Association (N : Node_Id);
procedure Analyze_Parameterized_Expression (N : Node_Id);
procedure Analyze_Procedure_Call (N : Node_Id);
procedure Analyze_Simple_Return_Statement (N : Node_Id);
procedure Analyze_Subprogram_Declaration (N : Node_Id);
......
......@@ -1223,6 +1223,7 @@ package body Sinfo is
or else NT (N).Nkind = N_Discriminant_Association
or else NT (N).Nkind = N_Discriminant_Specification
or else NT (N).Nkind = N_Exception_Declaration
or else NT (N).Nkind = N_Expression_Function
or else NT (N).Nkind = N_Expression_With_Actions
or else NT (N).Nkind = N_Free_Statement
or else NT (N).Nkind = N_Mod_Clause
......@@ -1230,7 +1231,6 @@ package body Sinfo is
or else NT (N).Nkind = N_Number_Declaration
or else NT (N).Nkind = N_Object_Declaration
or else NT (N).Nkind = N_Parameter_Specification
or else NT (N).Nkind = N_Parameterized_Expression
or else NT (N).Nkind = N_Pragma_Argument_Association
or else NT (N).Nkind = N_Qualified_Expression
or else NT (N).Nkind = N_Raise_Statement
......@@ -2797,12 +2797,12 @@ package body Sinfo is
begin
pragma Assert (False
or else NT (N).Nkind = N_Abstract_Subprogram_Declaration
or else NT (N).Nkind = N_Expression_Function
or else NT (N).Nkind = N_Formal_Abstract_Subprogram_Declaration
or else NT (N).Nkind = N_Formal_Concrete_Subprogram_Declaration
or else NT (N).Nkind = N_Generic_Package_Declaration
or else NT (N).Nkind = N_Generic_Subprogram_Declaration
or else NT (N).Nkind = N_Package_Declaration
or else NT (N).Nkind = N_Parameterized_Expression
or else NT (N).Nkind = N_Subprogram_Body
or else NT (N).Nkind = N_Subprogram_Body_Stub
or else NT (N).Nkind = N_Subprogram_Declaration
......@@ -4267,6 +4267,7 @@ package body Sinfo is
or else NT (N).Nkind = N_Discriminant_Association
or else NT (N).Nkind = N_Discriminant_Specification
or else NT (N).Nkind = N_Exception_Declaration
or else NT (N).Nkind = N_Expression_Function
or else NT (N).Nkind = N_Expression_With_Actions
or else NT (N).Nkind = N_Free_Statement
or else NT (N).Nkind = N_Mod_Clause
......@@ -4274,7 +4275,6 @@ package body Sinfo is
or else NT (N).Nkind = N_Number_Declaration
or else NT (N).Nkind = N_Object_Declaration
or else NT (N).Nkind = N_Parameter_Specification
or else NT (N).Nkind = N_Parameterized_Expression
or else NT (N).Nkind = N_Pragma_Argument_Association
or else NT (N).Nkind = N_Qualified_Expression
or else NT (N).Nkind = N_Raise_Statement
......@@ -5842,12 +5842,12 @@ package body Sinfo is
begin
pragma Assert (False
or else NT (N).Nkind = N_Abstract_Subprogram_Declaration
or else NT (N).Nkind = N_Expression_Function
or else NT (N).Nkind = N_Formal_Abstract_Subprogram_Declaration
or else NT (N).Nkind = N_Formal_Concrete_Subprogram_Declaration
or else NT (N).Nkind = N_Generic_Package_Declaration
or else NT (N).Nkind = N_Generic_Subprogram_Declaration
or else NT (N).Nkind = N_Package_Declaration
or else NT (N).Nkind = N_Parameterized_Expression
or else NT (N).Nkind = N_Subprogram_Body
or else NT (N).Nkind = N_Subprogram_Body_Stub
or else NT (N).Nkind = N_Subprogram_Declaration
......
......@@ -4591,17 +4591,17 @@ package Sinfo is
-- Has_Relative_Deadline_Pragma (Flag9-Sem)
-- Has_Pragma_CPU (Flag14-Sem)
------------------------------
-- Parameterized Expression --
------------------------------
-------------------------
-- Expression Function --
-------------------------
-- This is an Ada 2012 extension, we put it here for now, to be labeled
-- and put in its proper section when we know exactly where that is!
-- PARAMETERIZED_EXPRESSION ::=
-- EXPRESSION_FUNCTION ::=
-- FUNCTION SPECIFICATION IS (EXPRESSION);
-- N_Parameterized_Expression
-- N_Expression_Function
-- Sloc points to FUNCTION
-- Specification (Node1)
-- Expression (Node3)
......@@ -7591,6 +7591,7 @@ package Sinfo is
N_Component_Declaration,
N_Entry_Declaration,
N_Expression_Function,
N_Formal_Object_Declaration,
N_Formal_Type_Declaration,
N_Full_Type_Declaration,
......@@ -7598,7 +7599,6 @@ package Sinfo is
N_Iterator_Specification,
N_Loop_Parameter_Specification,
N_Object_Declaration,
N_Parameterized_Expression,
N_Protected_Type_Declaration,
N_Private_Extension_Declaration,
N_Private_Type_Declaration,
......@@ -10818,7 +10818,7 @@ package Sinfo is
4 => True, -- Handled_Statement_Sequence (Node4)
5 => False), -- Corresponding_Spec (Node5-Sem)
N_Parameterized_Expression =>
N_Expression_Function =>
(1 => True, -- Specification (Node1)
2 => False, -- unused
3 => True, -- Expression (Node3)
......@@ -12317,8 +12317,18 @@ package Sinfo is
pragma Inline (Set_Withed_Body);
pragma Inline (Set_Zero_Cost_Handling);
--------------
-- Synonyms --
--------------
-- These synonyms are to aid in transition, they should eventually be
-- removed when all remaining references to the obsolete name are gone.
N_Simple_Return_Statement : constant Node_Kind := N_Return_Statement;
-- Rename N_Return_Statement to be N_Simple_Return_Statement. Clients
-- should refer to N_Simple_Return_Statement.
N_Parameterized_Expression : constant Node_Kind := N_Expression_Function;
-- Old name for expression functions (used during Ada 2012 transition)
end Sinfo;
......@@ -1620,6 +1620,16 @@ package body Sprint is
Indent_End;
Write_Indent;
when N_Expression_Function =>
Write_Indent;
Sprint_Node_Sloc (Specification (Node));
Write_Str (" is");
Indent_Begin;
Write_Indent;
Sprint_Node (Expression (Node));
Write_Char (';');
Indent_End;
when N_Extended_Return_Statement =>
Write_Indent_Str_Sloc ("return ");
Sprint_Node_List (Return_Object_Declarations (Node));
......@@ -2488,17 +2498,6 @@ package body Sprint is
Write_Str (", ");
end if;
when N_Parameterized_Expression =>
Write_Indent;
Sprint_Node_Sloc (Specification (Node));
Write_Str (" is");
Indent_Begin;
Write_Indent;
Sprint_Node (Expression (Node));
Write_Char (';');
Indent_End;
when N_Pop_Constraint_Error_Label =>
Write_Indent_Str ("%pop_constraint_error_label");
......
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