Commit 99d520ad by Ed Schonberg Committed by Arnaud Charlet

sinfo.ads, sinfo.adb: New semantic attribute Premature_Use...

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

	* sinfo.ads, sinfo.adb: New semantic attribute Premature_Use,
	present in incomplete type declarations to refine the error
	message the full declaration is in the same unit.
	* sem_ch4.adb (Analyze_Selected_Component): If the prefix is of
	an incomplete type, set the Premature_Use for additional message.
	* sem_ch3.adb (Find_Type_Name): If partial view is incomplete
	and Premature_Use is set, place additional information at the
	point of premature use.

From-SVN: r178461
parent 5b5588dd
2011-09-02 Ed Schonberg <schonberg@adacore.com>
* sinfo.ads, sinfo.adb: New semantic attribute Premature_Use,
present in incomplete type declarations to refine the error
message the full declaration is in the same unit.
* sem_ch4.adb (Analyze_Selected_Component): If the prefix is of
an incomplete type, set the Premature_Use for additional message.
* sem_ch3.adb (Find_Type_Name): If partial view is incomplete
and Premature_Use is set, place additional information at the
point of premature use.
2011-09-02 Bob Duff <duff@adacore.com> 2011-09-02 Bob Duff <duff@adacore.com>
* sem_ch6.adb: (Check_Post_State): Suppress warning * sem_ch6.adb: (Check_Post_State): Suppress warning
......
...@@ -3313,17 +3313,21 @@ package body Sem_Ch3 is ...@@ -3313,17 +3313,21 @@ package body Sem_Ch3 is
-- Case of initialization present -- Case of initialization present
else else
-- Check restrictions in Ada 83 and SPARK modes
-- Not allowed in Ada 83
if not Constant_Present (N) then if not Constant_Present (N) then
-- A declaration of unconstrained type in SPARK is limited, -- In SPARK, a declaration of unconstrained type is allowed
-- the only exception to this is the admission of declaration -- only for constants of type string.
-- of constants of type string.
-- Why no check for Comes_From_Source here, seems wrong ???
-- Where is check to differentiate string case ???
Check_SPARK_Restriction Check_SPARK_Restriction
("declaration of unconstrained type is limited", E); ("declaration of object of unconstrained type not allowed",
E);
-- Unconstrained variables not allowed in Ada 83 mode
if Ada_Version = Ada_83 if Ada_Version = Ada_83
and then Comes_From_Source (Object_Definition (N)) and then Comes_From_Source (Object_Definition (N))
...@@ -15056,6 +15060,14 @@ package body Sem_Ch3 is ...@@ -15056,6 +15060,14 @@ package body Sem_Ch3 is
Tag_Mismatch; Tag_Mismatch;
end if; end if;
end if; end if;
if Present (Prev)
and then Nkind (Parent (Prev)) = N_Incomplete_Type_Declaration
and then Present (Premature_Use (Parent (Prev)))
then
Error_Msg_Sloc := Sloc (N);
Error_Msg_N
("\full declaration #", Premature_Use (Parent (Prev)));
end if;
return New_Id; return New_Id;
end if; end if;
......
...@@ -4322,6 +4322,28 @@ package body Sem_Ch4 is ...@@ -4322,6 +4322,28 @@ package body Sem_Ch4 is
Error_Msg_Node_2 := First_Subtype (Prefix_Type); Error_Msg_Node_2 := First_Subtype (Prefix_Type);
Error_Msg_NE ("no selector& for}", N, Sel); Error_Msg_NE ("no selector& for}", N, Sel);
-- If prefix is incomplete, dd information.
if Is_Incomplete_Type (Type_To_Use) then
declare
Inc : constant Entity_Id := First_Subtype (Type_To_Use);
begin
if From_With_Type (Scope (Type_To_Use)) then
Error_Msg_NE
("\limited view of& has no components", N, Inc);
else
Error_Msg_NE
("\premature usage of incomplete type&", N, Inc);
if
Nkind (Parent (Inc)) = N_Incomplete_Type_Declaration
then
Set_Premature_Use (Parent (Inc), N);
end if;
end if;
end;
end if;
Check_Misspelled_Selector (Type_To_Use, Sel); Check_Misspelled_Selector (Type_To_Use, Sel);
end if; end if;
......
...@@ -2459,6 +2459,14 @@ package body Sinfo is ...@@ -2459,6 +2459,14 @@ package body Sinfo is
return Node3 (N); return Node3 (N);
end Prefix; end Prefix;
function Premature_Use
(N : Node_Id) return Node_Id is
begin
pragma Assert (False
or else NT (N).Nkind = N_Incomplete_Type_Declaration);
return Node5 (N);
end Premature_Use;
function Present_Expr function Present_Expr
(N : Node_Id) return Uint is (N : Node_Id) return Uint is
begin begin
...@@ -5510,6 +5518,14 @@ package body Sinfo is ...@@ -5510,6 +5518,14 @@ package body Sinfo is
Set_Node3_With_Parent (N, Val); Set_Node3_With_Parent (N, Val);
end Set_Prefix; end Set_Prefix;
procedure Set_Premature_Use
(N : Node_Id; Val : Node_Id) is
begin
pragma Assert (False
or else NT (N).Nkind = N_Incomplete_Type_Declaration);
Set_Node5 (N, Val);
end Set_Premature_Use;
procedure Set_Present_Expr procedure Set_Present_Expr
(N : Node_Id; Val : Uint) is (N : Node_Id; Val : Uint) is
begin begin
......
...@@ -1598,6 +1598,12 @@ package Sinfo is ...@@ -1598,6 +1598,12 @@ package Sinfo is
-- package specification. This field is Empty for library bodies (the -- package specification. This field is Empty for library bodies (the
-- parent spec in this case can be found from the corresponding spec). -- parent spec in this case can be found from the corresponding spec).
-- Premature_Use (Node5-Sem)
-- Present in N_Incomplete_Type_Declaration node. Used for improved
-- error diagnostics: if there is a premature usage of an incomplete
-- type, a subsequently generated error message indicates the position
-- of its full declaration.
-- Present_Expr (Uint3-Sem) -- Present_Expr (Uint3-Sem)
-- Present in an N_Variant node. This has a meaningful value only after -- Present in an N_Variant node. This has a meaningful value only after
-- Gigi has back annotated the tree with representation information. At -- Gigi has back annotated the tree with representation information. At
...@@ -3091,6 +3097,7 @@ package Sinfo is ...@@ -3091,6 +3097,7 @@ package Sinfo is
-- Discriminant_Specifications (List4) (set to No_List if no -- Discriminant_Specifications (List4) (set to No_List if no
-- discriminant part, or if the discriminant part is an -- discriminant part, or if the discriminant part is an
-- unknown discriminant part) -- unknown discriminant part)
-- Premature_Use (Node5-Sem) used for improved diagnostics.
-- Unknown_Discriminants_Present (Flag13) set if (<>) discriminant -- Unknown_Discriminants_Present (Flag13) set if (<>) discriminant
-- Tagged_Present (Flag15) -- Tagged_Present (Flag15)
...@@ -8814,6 +8821,9 @@ package Sinfo is ...@@ -8814,6 +8821,9 @@ package Sinfo is
function Prefix function Prefix
(N : Node_Id) return Node_Id; -- Node3 (N : Node_Id) return Node_Id; -- Node3
function Premature_Use
(N : Node_Id) return Node_Id; -- Node5
function Present_Expr function Present_Expr
(N : Node_Id) return Uint; -- Uint3 (N : Node_Id) return Uint; -- Uint3
...@@ -9786,6 +9796,9 @@ package Sinfo is ...@@ -9786,6 +9796,9 @@ package Sinfo is
procedure Set_Prefix procedure Set_Prefix
(N : Node_Id; Val : Node_Id); -- Node3 (N : Node_Id; Val : Node_Id); -- Node3
procedure Set_Premature_Use
(N : Node_Id; Val : Node_Id); -- Node5
procedure Set_Present_Expr procedure Set_Present_Expr
(N : Node_Id; Val : Uint); -- Uint3 (N : Node_Id; Val : Uint); -- Uint3
...@@ -10420,7 +10433,7 @@ package Sinfo is ...@@ -10420,7 +10433,7 @@ package Sinfo is
2 => False, -- unused 2 => False, -- unused
3 => False, -- unused 3 => False, -- unused
4 => True, -- Discriminant_Specifications (List4) 4 => True, -- Discriminant_Specifications (List4)
5 => False), -- unused 5 => False), -- Premature_Use
N_Explicit_Dereference => N_Explicit_Dereference =>
(1 => False, -- unused (1 => False, -- unused
...@@ -11993,6 +12006,7 @@ package Sinfo is ...@@ -11993,6 +12006,7 @@ package Sinfo is
pragma Inline (Pragmas_After); pragma Inline (Pragmas_After);
pragma Inline (Pragmas_Before); pragma Inline (Pragmas_Before);
pragma Inline (Prefix); pragma Inline (Prefix);
pragma Inline (Premature_Use);
pragma Inline (Present_Expr); pragma Inline (Present_Expr);
pragma Inline (Prev_Ids); pragma Inline (Prev_Ids);
pragma Inline (Print_In_Hex); pragma Inline (Print_In_Hex);
...@@ -12314,6 +12328,7 @@ package Sinfo is ...@@ -12314,6 +12328,7 @@ package Sinfo is
pragma Inline (Set_Pragmas_After); pragma Inline (Set_Pragmas_After);
pragma Inline (Set_Pragmas_Before); pragma Inline (Set_Pragmas_Before);
pragma Inline (Set_Prefix); pragma Inline (Set_Prefix);
pragma Inline (Set_Premature_Use);
pragma Inline (Set_Present_Expr); pragma Inline (Set_Present_Expr);
pragma Inline (Set_Prev_Ids); pragma Inline (Set_Prev_Ids);
pragma Inline (Set_Print_In_Hex); pragma Inline (Set_Print_In_Hex);
......
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