Commit 8ed68165 by Arnaud Charlet

[multiple changes]

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

	* sem_util.ads, sem_util.adb, par.adb, par_util.adb
	(Formal_Error_Msg, Formal_Error_Msg_N, Formal_Error_Msg_SP): move
	procedures out of these packages.
	* errout.ads, errout.adb 
	(Formal_Error_Msg, Formal_Error_Msg_N, Formal_Error_Msg_SP): move
	procedures in of this package
	(Formal_Error_Msg_NE): new procedure for wrapper on Error_Msg_NE
	* par-ch5.adb (Parse_Decls_Begin_End): issue syntax error in SPARK mode
	on misplaced later vs initial declarations, like in Ada 83
	* sem_attr.adb (Processing for Analyze_Attribute): issue error in
	formal mode on attribute of private type whose full type declaration
	is not visible
	* sem_ch3.adb (Analyze_Declarations): issue error in formal mode on a
	package declaration inside a package specification
	(Analyze_Full_Type_Declaration): issue error in formal mode on
	controlled type or discriminant type
	* sem_ch6.adb (Analyze_Subprogram_Specification): only issue error on
	user-defined operator means that it should come from the source
	(New_Overloaded_Entity): issue error in formal mode on overloaded
	entity.
	* sem_ch6.ads, sem_ch13.ads: typos in comments.

2011-08-01  Thomas Quinot  <quinot@adacore.com>

	* atree.adb: Minor reformatting.
	* checks.adb: Minor reformatting.

From-SVN: r177052
parent 4230bdb7
2011-08-01 Yannick Moy <moy@adacore.com>
* sem_util.ads, sem_util.adb, par.adb, par_util.adb
(Formal_Error_Msg, Formal_Error_Msg_N, Formal_Error_Msg_SP): move
procedures out of these packages.
* errout.ads, errout.adb
(Formal_Error_Msg, Formal_Error_Msg_N, Formal_Error_Msg_SP): move
procedures in of this package
(Formal_Error_Msg_NE): new procedure for wrapper on Error_Msg_NE
* par-ch5.adb (Parse_Decls_Begin_End): issue syntax error in SPARK mode
on misplaced later vs initial declarations, like in Ada 83
* sem_attr.adb (Processing for Analyze_Attribute): issue error in
formal mode on attribute of private type whose full type declaration
is not visible
* sem_ch3.adb (Analyze_Declarations): issue error in formal mode on a
package declaration inside a package specification
(Analyze_Full_Type_Declaration): issue error in formal mode on
controlled type or discriminant type
* sem_ch6.adb (Analyze_Subprogram_Specification): only issue error on
user-defined operator means that it should come from the source
(New_Overloaded_Entity): issue error in formal mode on overloaded
entity.
* sem_ch6.ads, sem_ch13.ads: typos in comments.
2011-08-01 Thomas Quinot <quinot@adacore.com>
* atree.adb: Minor reformatting.
* checks.adb: Minor reformatting.
2011-08-01 Vincent Celier <celier@adacore.com> 2011-08-01 Vincent Celier <celier@adacore.com>
* s-parame-vms-ia64.ads: Fix typo in comment * s-parame-vms-ia64.ads: Fix typo in comment
......
...@@ -1196,14 +1196,14 @@ package body Atree is ...@@ -1196,14 +1196,14 @@ package body Atree is
Nodes.Table (New_Id).Link := Empty_List_Or_Node; Nodes.Table (New_Id).Link := Empty_List_Or_Node;
Nodes.Table (New_Id).In_List := False; Nodes.Table (New_Id).In_List := False;
-- If the original is marked as a rewrite insertion, then unmark -- If the original is marked as a rewrite insertion, then unmark the
-- the copy, since we inserted the original, not the copy. -- copy, since we inserted the original, not the copy.
Nodes.Table (New_Id).Rewrite_Ins := False; Nodes.Table (New_Id).Rewrite_Ins := False;
pragma Debug (New_Node_Debugging_Output (New_Id)); pragma Debug (New_Node_Debugging_Output (New_Id));
-- Clear Is_Overloaded since we cannot have semantic interpretations -- Clear Is_Overloaded since we cannot have semantic interpretations
-- of this new node -- of this new node.
if Nkind (Source) in N_Subexpr then if Nkind (Source) in N_Subexpr then
Set_Is_Overloaded (New_Id, False); Set_Is_Overloaded (New_Id, False);
......
...@@ -4560,6 +4560,10 @@ package body Checks is ...@@ -4560,6 +4560,10 @@ package body Checks is
function Entity_Of_Prefix return Entity_Id; function Entity_Of_Prefix return Entity_Id;
-- Returns the entity of the prefix of N (or Empty if not found) -- Returns the entity of the prefix of N (or Empty if not found)
----------------------
-- Entity_Of_Prefix --
----------------------
function Entity_Of_Prefix return Entity_Id is function Entity_Of_Prefix return Entity_Id is
P : Node_Id := Prefix (N); P : Node_Id := Prefix (N);
begin begin
...@@ -4583,6 +4587,8 @@ package body Checks is ...@@ -4583,6 +4587,8 @@ package body Checks is
A_Ent : constant Entity_Id := Entity_Of_Prefix; A_Ent : constant Entity_Id := Entity_Of_Prefix;
Sub : Node_Id; Sub : Node_Id;
-- Start of processing for Generate_Index_Checks
begin begin
-- Ignore call if the prefix is not an array since we have a serious -- Ignore call if the prefix is not an array since we have a serious
-- error in the sources. Ignore it also if index checks are suppressed -- error in the sources. Ignore it also if index checks are suppressed
...@@ -4599,7 +4605,7 @@ package body Checks is ...@@ -4599,7 +4605,7 @@ package body Checks is
-- Generate a raise of constraint error with the appropriate reason and -- Generate a raise of constraint error with the appropriate reason and
-- a condition of the form: -- a condition of the form:
-- Base_Type(Sub) not in array'range (subscript) -- Base_Type (Sub) not in Array'Range (Subscript)
-- Note that the reason we generate the conversion to the base type here -- Note that the reason we generate the conversion to the base type here
-- is that we definitely want the range check to take place, even if it -- is that we definitely want the range check to take place, even if it
...@@ -4627,7 +4633,7 @@ package body Checks is ...@@ -4627,7 +4633,7 @@ package body Checks is
Duplicate_Subexpr_Move_Checks (Sub)), Duplicate_Subexpr_Move_Checks (Sub)),
Right_Opnd => Right_Opnd =>
Make_Attribute_Reference (Loc, Make_Attribute_Reference (Loc,
Prefix => New_Reference_To (Etype (A), Loc), Prefix => New_Reference_To (Etype (A), Loc),
Attribute_Name => Name_Range)), Attribute_Name => Name_Range)),
Reason => CE_Index_Check_Failed)); Reason => CE_Index_Check_Failed));
end if; end if;
...@@ -4680,7 +4686,8 @@ package body Checks is ...@@ -4680,7 +4686,8 @@ package body Checks is
then then
Range_N := Range_N :=
Make_Attribute_Reference (Loc, Make_Attribute_Reference (Loc,
Prefix => New_Reference_To (Etype (A_Idx), Loc), Prefix =>
New_Reference_To (Etype (A_Idx), Loc),
Attribute_Name => Name_Range); Attribute_Name => Name_Range);
-- For arrays with non-constant bounds we cannot generate -- For arrays with non-constant bounds we cannot generate
......
...@@ -1402,6 +1402,49 @@ package body Errout is ...@@ -1402,6 +1402,49 @@ package body Errout is
return S; return S;
end First_Sloc; end First_Sloc;
----------------------
-- Formal_Error_Msg --
----------------------
procedure Formal_Error_Msg (Msg : String; Flag_Location : Source_Ptr) is
begin
pragma Assert (Formal_Verification_Mode);
Error_Msg ("(" & Formal_Language & ") " & Msg, Flag_Location);
end Formal_Error_Msg;
------------------------
-- Formal_Error_Msg_N --
------------------------
procedure Formal_Error_Msg_N (Msg : String; N : Node_Id) is
begin
pragma Assert (Formal_Verification_Mode);
Error_Msg_N ("(" & Formal_Language & ") " & Msg, N);
end Formal_Error_Msg_N;
-------------------------
-- Formal_Error_Msg_NE --
-------------------------
procedure Formal_Error_Msg_NE
(Msg : String;
N : Node_Or_Entity_Id;
E : Node_Or_Entity_Id) is
begin
pragma Assert (Formal_Verification_Mode);
Error_Msg_NE ("(" & Formal_Language & ") " & Msg, N, E);
end Formal_Error_Msg_NE;
-------------------------
-- Formal_Error_Msg_SP --
-------------------------
procedure Formal_Error_Msg_SP (Msg : String) is
begin
pragma Assert (Formal_Verification_Mode);
Error_Msg_SP ("(" & Formal_Language & ") " & Msg);
end Formal_Error_Msg_SP;
---------------- ----------------
-- Initialize -- -- Initialize --
---------------- ----------------
......
...@@ -735,6 +735,25 @@ package Errout is ...@@ -735,6 +735,25 @@ package Errout is
-- where the expression is parenthesized, an attempt is made to include -- where the expression is parenthesized, an attempt is made to include
-- the parentheses (i.e. to return the location of the initial paren). -- the parentheses (i.e. to return the location of the initial paren).
procedure Formal_Error_Msg (Msg : String; Flag_Location : Source_Ptr);
-- Wrapper on Error_Msg which adds a prefix to Msg giving the name of
-- the formal language analyzed (spark or alfa)
procedure Formal_Error_Msg_N (Msg : String; N : Node_Id);
-- Wrapper on Error_Msg_N which adds a prefix to Msg giving the name of
-- the formal language analyzed (spark or alfa)
procedure Formal_Error_Msg_NE
(Msg : String;
N : Node_Or_Entity_Id;
E : Node_Or_Entity_Id);
-- Wrapper on Error_Msg_NE which adds a prefix to Msg giving the name of
-- the formal language analyzed (spark or alfa)
procedure Formal_Error_Msg_SP (Msg : String);
-- Wrapper on Error_Msg_SP which adds a prefix to Msg giving the name of
-- the formal language analyzed (spark or alfa)
procedure Purge_Messages (From : Source_Ptr; To : Source_Ptr) procedure Purge_Messages (From : Source_Ptr; To : Source_Ptr)
renames Erroutc.Purge_Messages; renames Erroutc.Purge_Messages;
-- All error messages whose location is in the range From .. To (not -- All error messages whose location is in the range From .. To (not
......
...@@ -2110,9 +2110,12 @@ package body Ch5 is ...@@ -2110,9 +2110,12 @@ package body Ch5 is
begin begin
Decls := P_Declarative_Part; Decls := P_Declarative_Part;
-- Check for misplacement of later vs basic declarations in Ada 83 -- Check for misplacement of later vs basic declarations in Ada 83.
-- The same is true for the SPARK mode: although SPARK 95 removes
-- the distinction between initial and later declarative items,
-- the distinction remains in the Examiner. (JB01-005)
if Ada_Version = Ada_83 then if Ada_Version = Ada_83 or else SPARK_Mode then
Decl := First (Decls); Decl := First (Decls);
-- Loop through sequence of basic declarative items -- Loop through sequence of basic declarative items
...@@ -2139,6 +2142,11 @@ package body Ch5 is ...@@ -2139,6 +2142,11 @@ package body Ch5 is
Error_Msg_Sloc := Body_Sloc; Error_Msg_Sloc := Body_Sloc;
Error_Msg_N Error_Msg_N
("(Ada 83) decl cannot appear after body#", Decl); ("(Ada 83) decl cannot appear after body#", Decl);
else
pragma Assert (SPARK_Mode);
Error_Msg_Sloc := Body_Sloc;
Formal_Error_Msg_N
("decl cannot appear after body#", Decl);
end if; end if;
end if; end if;
......
...@@ -377,16 +377,6 @@ package body Util is ...@@ -377,16 +377,6 @@ package body Util is
null; null;
end Discard_Junk_Node; end Discard_Junk_Node;
-------------------------
-- Formal_Error_Msg_SP --
-------------------------
procedure Formal_Error_Msg_SP (Msg : String) is
begin
pragma Assert (Formal_Verification_Mode);
Error_Msg_SP ("(" & Formal_Language & ") " & Msg);
end Formal_Error_Msg_SP;
------------ ------------
-- Ignore -- -- Ignore --
------------ ------------
......
...@@ -1158,10 +1158,6 @@ function Par (Configuration_Pragmas : Boolean) return List_Id is ...@@ -1158,10 +1158,6 @@ function Par (Configuration_Pragmas : Boolean) return List_Id is
-- the argument. A typical use is to skip by some junk that is not -- the argument. A typical use is to skip by some junk that is not
-- expected in the current context. -- expected in the current context.
procedure Formal_Error_Msg_SP (Msg : String);
-- Wrapper on Errout.Error_Msg_SP which adds a prefix to Msg giving
-- the name of the formal language analyzed (spark or alfa)
procedure Ignore (T : Token_Type); procedure Ignore (T : Token_Type);
-- If current token matches T, then give an error message and skip -- If current token matches T, then give an error message and skip
-- past it, otherwise the call has no effect at all. T may be any -- past it, otherwise the call has no effect at all. T may be any
......
...@@ -2055,6 +2055,20 @@ package body Sem_Attr is ...@@ -2055,6 +2055,20 @@ package body Sem_Attr is
end if; end if;
end if; end if;
-- In SPARK or ALFA, attributes of private types are only allowed if
-- the full type declaration is visible
if Formal_Verification_Mode
and then Is_Entity_Name (P)
and then Is_Type (Entity (P))
and then Is_Private_Type (P_Type)
and then not In_Open_Scopes (Scope (P_Type))
and then not In_Spec_Expression
then
Formal_Error_Msg_NE
("invisible attribute of}", N, First_Subtype (P_Type));
end if;
-- Remaining processing depends on attribute -- Remaining processing depends on attribute
case Attr_Id is case Attr_Id is
......
...@@ -40,9 +40,9 @@ package Sem_Ch13 is ...@@ -40,9 +40,9 @@ package Sem_Ch13 is
(N : Node_Id; (N : Node_Id;
E : Entity_Id; E : Entity_Id;
L : List_Id); L : List_Id);
-- This procedure is called to analyze aspect specifications for node N. E -- This procedure is called to analyze aspect specifications for node N.
-- is the corresponding entity declared by the declaration node N, and L is -- E is the corresponding entity declared by the declaration node N, and L
-- the list of aspect specifications for this node. If L is No_List, the -- is the list of aspect specifications for this node. If L is No_List, the
-- call is ignored. Note that we can't use a simpler interface of just -- call is ignored. Note that we can't use a simpler interface of just
-- passing the node N, since the analysis of the node may cause it to be -- passing the node N, since the analysis of the node may cause it to be
-- rewritten to a node not permitting aspect specifications. -- rewritten to a node not permitting aspect specifications.
......
...@@ -2027,6 +2027,17 @@ package body Sem_Ch3 is ...@@ -2027,6 +2027,17 @@ package body Sem_Ch3 is
D := First (L); D := First (L);
while Present (D) loop while Present (D) loop
-- Package specification cannot contain a package declaration in
-- SPARK or ALFA
if Formal_Verification_Mode
and then Nkind (D) = N_Package_Declaration
and then Nkind (Parent (L)) = N_Package_Specification
then
Formal_Error_Msg_N ("package specification cannot contain "
& "a package declaration", D);
end if;
-- Complete analysis of declaration -- Complete analysis of declaration
Analyze (D); Analyze (D);
...@@ -2347,6 +2358,21 @@ package body Sem_Ch3 is ...@@ -2347,6 +2358,21 @@ package body Sem_Ch3 is
return; return;
end if; end if;
if Formal_Verification_Mode then
-- Controlled type is not allowed in SPARK and ALFA
if Is_Visibly_Controlled (T) then
Formal_Error_Msg_N ("controlled type is not allowed", N);
end if;
-- Discriminant type is not allowed in SPARK and ALFA
if Present (Discriminant_Specifications (N)) then
Formal_Error_Msg_N ("discriminant type is not allowed", N);
end if;
end if;
-- Some common processing for all types -- Some common processing for all types
Set_Depends_On_Private (T, Has_Private_Component (T)); Set_Depends_On_Private (T, Has_Private_Component (T));
......
...@@ -3072,6 +3072,7 @@ package body Sem_Ch6 is ...@@ -3072,6 +3072,7 @@ package body Sem_Ch6 is
-- User-defined operator is not allowed in SPARK or ALFA -- User-defined operator is not allowed in SPARK or ALFA
if Formal_Verification_Mode if Formal_Verification_Mode
and then Comes_From_Source (N)
and then Nkind (Defining_Unit_Name (N)) = N_Defining_Operator_Symbol and then Nkind (Defining_Unit_Name (N)) = N_Defining_Operator_Symbol
then then
Formal_Error_Msg_N ("user-defined operator is not allowed", N); Formal_Error_Msg_N ("user-defined operator is not allowed", N);
...@@ -8493,6 +8494,15 @@ package body Sem_Ch6 is ...@@ -8493,6 +8494,15 @@ package body Sem_Ch6 is
Check_Overriding_Indicator Check_Overriding_Indicator
(S, Overridden_Subp, Is_Primitive => Is_Primitive_Subp); (S, Overridden_Subp, Is_Primitive => Is_Primitive_Subp);
-- Overloading is not allowed in SPARK or ALFA
if Formal_Verification_Mode
and then Comes_From_Source (S)
then
Error_Msg_Sloc := Sloc (Homonym (S));
Formal_Error_Msg_N ("overloading not allowed with entity#", S);
end if;
-- If S is a derived operation for an untagged type then by -- If S is a derived operation for an untagged type then by
-- definition it's not a dispatching operation (even if the parent -- definition it's not a dispatching operation (even if the parent
-- operation was dispatching), so we don't call -- operation was dispatching), so we don't call
......
...@@ -205,7 +205,7 @@ package Sem_Ch6 is ...@@ -205,7 +205,7 @@ package Sem_Ch6 is
-- Process new overloaded entity. Overloaded entities are created by -- Process new overloaded entity. Overloaded entities are created by
-- enumeration type declarations, subprogram specifications, entry -- enumeration type declarations, subprogram specifications, entry
-- declarations, and (implicitly) by type derivations. Derived_Type non- -- declarations, and (implicitly) by type derivations. Derived_Type non-
-- Empty indicates that this is subprogram derived for that type. -- Empty indicates that this is a subprogram derived for that type.
procedure Process_Formals (T : List_Id; Related_Nod : Node_Id); procedure Process_Formals (T : List_Id; Related_Nod : Node_Id);
-- Enter the formals in the scope of the subprogram or entry, and -- Enter the formals in the scope of the subprogram or entry, and
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
-- Copyright (C) 1992-2011, Free Software Foundation, Inc. -- -- Copyright (C) 1992-2011, 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 Genconflieral Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- -- -- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
...@@ -3644,26 +3644,6 @@ package body Sem_Util is ...@@ -3644,26 +3644,6 @@ package body Sem_Util is
end if; end if;
end First_Actual; end First_Actual;
----------------------
-- Formal_Error_Msg --
----------------------
procedure Formal_Error_Msg (Msg : String; Flag_Location : Source_Ptr) is
begin
pragma Assert (Formal_Verification_Mode);
Error_Msg ("(" & Formal_Language & ") " & Msg, Flag_Location);
end Formal_Error_Msg;
------------------------
-- Formal_Error_Msg_N --
------------------------
procedure Formal_Error_Msg_N (Msg : String; N : Node_Id) is
begin
pragma Assert (Formal_Verification_Mode);
Error_Msg_N ("(" & Formal_Language & ") " & Msg, N);
end Formal_Error_Msg_N;
----------------------- -----------------------
-- Gather_Components -- -- Gather_Components --
----------------------- -----------------------
......
...@@ -407,14 +407,6 @@ package Sem_Util is ...@@ -407,14 +407,6 @@ package Sem_Util is
-- is always the expression (not the N_Parameter_Association nodes, -- is always the expression (not the N_Parameter_Association nodes,
-- even if named association is used). -- even if named association is used).
procedure Formal_Error_Msg (Msg : String; Flag_Location : Source_Ptr);
-- Wrapper on Errout.Error_Msg which adds a prefix to Msg giving
-- the name of the formal language analyzed (spark or alfa)
procedure Formal_Error_Msg_N (Msg : String; N : Node_Id);
-- Wrapper on Errout.Error_Msg_N which adds a prefix to Msg giving
-- the name of the formal language analyzed (spark or alfa)
procedure Gather_Components procedure Gather_Components
(Typ : Entity_Id; (Typ : Entity_Id;
Comp_List : Node_Id; Comp_List : Node_Id;
......
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