Commit dc726757 by Hristian Kirtchev Committed by Arnaud Charlet

einfo.adb (Non_Limited_View): Applies to abstract states.

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

	* einfo.adb (Non_Limited_View): Applies to abstract states.
	(Set_From_Limited_With): Applies to abstract states.
	(Set_Non_Limited_View): Applies to abstract states.
	(Write_Field17): Output the non-limited view of an abstract state.
	* einfo.ads: Update the comment on usage and occurrences in
	nodes for attributes From_Limited_With and Non_Limited_View.
	* sem_aux.adb (Available_View): This routine can now handle
	abstract states.
	* sem_aux.ads (Available_View): This routine can now handle
	abstract states. Update the comment on usage.
	* sem_ch8.adb (Find_Expanded_Name): Handle abstract views
	of states and variables.
	(In_Pragmas_Depends_Or_Global): New routine.
	* sem_ch10.adb (Build_Limited_Views): Implement
	abstract (limited) views of variables and states.
	(Build_Shadow_Entity): This routine is now a procedure. Add
	formal parameter Shadow. Update the comment on usage. Add
	context-specific decoration for states and variables.
	(Decorate_State): New routine.	(Decorate_Variable): New routine.
	(Find_And_Process_States): New routine.
	(Process_Declarations): Renamed to Process_Declarations_And_States.
	(Process_Declarations_And_States): Add formal parameters
	Pack and Create_Abstract_Views. Update the comment on usage.
	(Process_States): New routine.
	* sem_prag.adb (Check_Dependency_Clause): Handle abstract
	views of states and variables. Match the abstract view of a state
	against its corresponding non-abstract view.
	(Is_Matching_Input):
	Handle abstract views of states and variables. Match the abstract
	view of a state against its corresponding non-abstract view.
	(Process_Global_Item): Handle abstract views of states and
	variables.

From-SVN: r206808
parent 3a5de596
2014-01-20 Hristian Kirtchev <kirtchev@adacore.com>
* einfo.adb (Non_Limited_View): Applies to abstract states.
(Set_From_Limited_With): Applies to abstract states.
(Set_Non_Limited_View): Applies to abstract states.
(Write_Field17): Output the non-limited view of an abstract state.
* einfo.ads: Update the comment on usage and occurrences in
nodes for attributes From_Limited_With and Non_Limited_View.
* sem_aux.adb (Available_View): This routine can now handle
abstract states.
* sem_aux.ads (Available_View): This routine can now handle
abstract states. Update the comment on usage.
* sem_ch8.adb (Find_Expanded_Name): Handle abstract views
of states and variables.
(In_Pragmas_Depends_Or_Global): New routine.
* sem_ch10.adb (Build_Limited_Views): Implement
abstract (limited) views of variables and states.
(Build_Shadow_Entity): This routine is now a procedure. Add
formal parameter Shadow. Update the comment on usage. Add
context-specific decoration for states and variables.
(Decorate_State): New routine. (Decorate_Variable): New routine.
(Find_And_Process_States): New routine.
(Process_Declarations): Renamed to Process_Declarations_And_States.
(Process_Declarations_And_States): Add formal parameters
Pack and Create_Abstract_Views. Update the comment on usage.
(Process_States): New routine.
* sem_prag.adb (Check_Dependency_Clause): Handle abstract
views of states and variables. Match the abstract view of a state
against its corresponding non-abstract view.
(Is_Matching_Input):
Handle abstract views of states and variables. Match the abstract
view of a state against its corresponding non-abstract view.
(Process_Global_Item): Handle abstract views of states and
variables.
2014-01-20 Bob Duff <duff@adacore.com>
* sem_ch10.adb (Expand_With_Clause): Don't
......
......@@ -2497,7 +2497,8 @@ package body Einfo is
function Non_Limited_View (Id : E) return E is
begin
pragma Assert (Ekind (Id) in Incomplete_Kind);
pragma Assert
(Ekind (Id) in Incomplete_Kind or else Ekind (Id) = E_Abstract_State);
return Node17 (Id);
end Non_Limited_View;
......@@ -3865,7 +3866,8 @@ package body Einfo is
procedure Set_From_Limited_With (Id : E; V : B := True) is
begin
pragma Assert (Is_Type (Id) or else Ekind (Id) = E_Package);
pragma Assert
(Is_Type (Id) or else Ekind_In (Id, E_Abstract_State, E_Package));
Set_Flag159 (Id, V);
end Set_From_Limited_With;
......@@ -5172,7 +5174,8 @@ package body Einfo is
procedure Set_Non_Limited_View (Id : E; V : E) is
begin
pragma Assert (Ekind (Id) in Incomplete_Kind);
pragma Assert
(Ekind (Id) in Incomplete_Kind or else Ekind (Id) = E_Abstract_State);
Set_Node17 (Id, V);
end Set_Non_Limited_View;
......@@ -8787,7 +8790,8 @@ package body Einfo is
when Modular_Integer_Kind =>
Write_Str ("Modulus");
when E_Incomplete_Type =>
when E_Abstract_State |
E_Incomplete_Type =>
Write_Str ("Non_Limited_View");
when E_Incomplete_Subtype =>
......
......@@ -1316,10 +1316,11 @@ package Einfo is
-- Freeze for further details.
-- From_Limited_With (Flag159)
-- Defined in package and type entities. Set to True when the related
-- entity is generated by the expansion of a limited with clause. Such
-- an entity is said to be a "shadow" - it acts as the incomplete view
-- of a type by inheriting relevant attributes from the said type.
-- Defined in abtract states, package and type entities. Set to True when
-- the related entity is generated by the expansion of a limited with
-- clause. Such an entity is said to be a "shadow" - it acts as the
-- abstract view of a state or variable or as the incomplete view of a
-- type by inheriting relevant attributes from the said entity.
-- Full_View (Node11)
-- Defined in all type and subtype entities and in deferred constants.
......@@ -3262,9 +3263,9 @@ package Einfo is
-- types if the modulus value is other than a power of 2.
-- Non_Limited_View (Node17)
-- Defined in incomplete types that are the shadow entities created
-- when analyzing a limited_with_clause (Ada 2005: AI-50217). Points to
-- the defining entity in the original declaration.
-- Defined in abstract states and incomplete types that act as shadow
-- entities created when analysing a limited with clause (Ada 2005:
-- AI-50217). Points to the defining entity of the original declaration.
-- Nonzero_Is_True (Flag162) [base type only]
-- Defined in enumeration types. Set if any non-zero value is to be
......@@ -5120,6 +5121,8 @@ package Einfo is
-- Refinement_Constituents (Elist8)
-- Refined_State (Node10)
-- Body_References (Elist16)
-- Non_Limited_View (Node17)
-- From_Limited_With (Flag159)
-- Has_Body_References (Flag264)
-- Has_Visible_Refinement (Flag263)
-- Has_Non_Null_Refinement (synth)
......
......@@ -76,28 +76,35 @@ package body Sem_Aux is
-- Available_View --
--------------------
function Available_View (Typ : Entity_Id) return Entity_Id is
function Available_View (Ent : Entity_Id) return Entity_Id is
begin
if Is_Incomplete_Type (Typ)
and then Present (Non_Limited_View (Typ))
-- Obtain the non-limited (non-abstract) view of a state or variable
if Ekind (Ent) = E_Abstract_State
and then Present (Non_Limited_View (Ent))
then
-- The non-limited view may itself be an incomplete type, in which
-- case get its full view.
return Non_Limited_View (Ent);
-- The non-limited view of an incomplete type may itself be incomplete
-- in which case obtain its full view.
return Get_Full_View (Non_Limited_View (Typ));
elsif Is_Incomplete_Type (Ent)
and then Present (Non_Limited_View (Ent))
then
return Get_Full_View (Non_Limited_View (Ent));
-- If it is class_wide, check whether the specific type comes from
-- A limited_with.
-- If it is class_wide, check whether the specific type comes from a
-- limited_with.
elsif Is_Class_Wide_Type (Typ)
and then Is_Incomplete_Type (Etype (Typ))
and then From_Limited_With (Etype (Typ))
and then Present (Non_Limited_View (Etype (Typ)))
elsif Is_Class_Wide_Type (Ent)
and then Is_Incomplete_Type (Etype (Ent))
and then From_Limited_With (Etype (Ent))
and then Present (Non_Limited_View (Etype (Ent)))
then
return Class_Wide_Type (Non_Limited_View (Etype (Typ)));
return Class_Wide_Type (Non_Limited_View (Etype (Ent)));
else
return Typ;
return Ent;
end if;
end Available_View;
......
......@@ -90,12 +90,10 @@ package Sem_Aux is
-- subtype then it returns the subtype or type from which the subtype was
-- obtained, otherwise it returns Empty.
function Available_View (Typ : Entity_Id) return Entity_Id;
-- Typ is typically a type that has the With_Type flag set. Returns the
-- non-limited view of the type, if available, otherwise the type itself.
-- For class-wide types, there is no direct link in the tree, so we have
-- to retrieve the class-wide type of the non-limited view of the Etype.
-- Returns the argument unchanged if it is not one of these cases.
function Available_View (Ent : Entity_Id) return Entity_Id;
-- Ent denotes an abstract state or a type that may come from a limited
-- with clause. Return the non-limited view of Ent if there is one or Ent
-- if this is not the case.
function Constant_Value (Ent : Entity_Id) return Node_Id;
-- Ent is a variable, constant, named integer, or named real entity. This
......
......@@ -5171,11 +5171,51 @@ package body Sem_Ch8 is
-- the scope of its declaration.
procedure Find_Expanded_Name (N : Node_Id) is
function In_Pragmas_Depends_Or_Global (N : Node_Id) return Boolean;
-- Determine whether an arbitrary node N appears in pragmas [Refined_]
-- Depends or [Refined_]Global.
----------------------------------
-- In_Pragmas_Depends_Or_Global --
----------------------------------
function In_Pragmas_Depends_Or_Global (N : Node_Id) return Boolean is
Par : Node_Id;
begin
-- Climb the parent chain looking for a pragma
Par := N;
while Present (Par) loop
if Nkind (Par) = N_Pragma
and then Nam_In (Pragma_Name (Par), Name_Depends,
Name_Global,
Name_Refined_Depends,
Name_Refined_Global)
then
return True;
-- Prevent the search from going too far
elsif Is_Body_Or_Package_Declaration (Par) then
return False;
end if;
Par := Parent (Par);
end loop;
return False;
end In_Pragmas_Depends_Or_Global;
-- Local variables
Selector : constant Node_Id := Selector_Name (N);
Candidate : Entity_Id := Empty;
P_Name : Entity_Id;
Id : Entity_Id;
-- Start of processing for Find_Expanded_Name
begin
P_Name := Entity (Prefix (N));
......@@ -5210,6 +5250,27 @@ package body Sem_Ch8 is
Candidate := Id;
Is_New_Candidate := True;
-- Handle abstract views of states and variables. These are
-- acceptable only when the reference to the view appears in
-- pragmas [Refined_]Depends and [Refined_]Global.
if Ekind (Id) = E_Abstract_State
and then From_Limited_With (Id)
and then Present (Non_Limited_View (Id))
then
if In_Pragmas_Depends_Or_Global (N) then
Candidate := Non_Limited_View (Id);
Is_New_Candidate := True;
-- Hide the candidate because it is not used in a proper
-- context.
else
Candidate := Empty;
Is_New_Candidate := False;
end if;
end if;
-- Ada 2005 (AI-217): Handle shadow entities associated with types
-- declared in limited-withed nested packages. We don't need to
-- handle E_Incomplete_Subtype entities because the entities in
......@@ -5221,9 +5282,8 @@ package body Sem_Ch8 is
-- The non-limited view may itself be incomplete, in which case
-- get the full view if available.
elsif From_Limited_With (Id)
and then Is_Type (Id)
and then Ekind (Id) = E_Incomplete_Type
elsif Ekind (Id) = E_Incomplete_Type
and then From_Limited_With (Id)
and then Present (Non_Limited_View (Id))
and then Scope (Non_Limited_View (Id)) = P_Name
then
......@@ -5528,8 +5588,7 @@ package body Sem_Ch8 is
else
Error_Msg_N
("limited withed package can only be used to access "
& "incomplete types",
N);
& "incomplete types", N);
end if;
end if;
......
......@@ -19905,7 +19905,7 @@ package body Sem_Prag is
function Output_Constituents (State_Id : Entity_Id) return Elist_Id;
-- Given a state denoted by State_Id, return a list of all output
-- constituents that may be referenced within Refined_Depends. The
-- contents of the list depend on whethe Refined_Global is present.
-- contents of the list depend on whether Refined_Global is present.
procedure Report_Unused_Constituents (Constits : Elist_Id);
-- Emit errors for all constituents found in list Constits
......@@ -19989,7 +19989,10 @@ package body Sem_Prag is
-- Remaining cases are formal parameters, variables, and states
else
Dep_Id := Entity_Of (Dep_Input);
-- Handle abstract views of states and variables generated
-- for limited with clauses.
Dep_Id := Available_View (Entity_Of (Dep_Input));
-- Inspect all inputs of the refinement clause and attempt
-- to match against the inputs of the dependence clause.
......@@ -20061,6 +20064,18 @@ package body Sem_Prag is
Remove (Ref_Input);
end if;
end if;
-- The abstract view of a state matches its
-- corresponding non-abstract view:
-- Depends => (<output> => Lim_Pack.State)
-- Refined_Depends => (<output> => State)
elsif Is_Entity_Name (Ref_Input)
and then Entity_Of (Ref_Input) = Dep_Id
then
Remove (Ref_Input);
return True;
end if;
-- Formal parameters and variables are matched on
......@@ -20364,14 +20379,18 @@ package body Sem_Prag is
-- The remaining cases are formal parameters, variables and states
elsif Is_Entity_Name (Dep_Output) then
Dep_Id := Entity_Of (Dep_Output);
-- Handle abstract views of states and variables generated for
-- limited with clauses.
Dep_Id := Available_View (Entity_Of (Dep_Output));
if Ekind (Dep_Id) = E_Abstract_State then
-- A state with a null refinement matches either a null
-- output list or nothing at all (no clause):
-- Refined_State => (State => null)
-- Refined_State => (State => null)
-- No clause
......@@ -20446,6 +20465,18 @@ package body Sem_Prag is
Remove (Out_Constits, Ref_Id);
end if;
end if;
-- The abstract view of a state matches is corresponding
-- non-abstract view:
-- Depends => (Lim_Pack.State => <input>)
-- Refined_Depends => (State => <input>)
elsif Is_Entity_Name (Ref_Output)
and then Entity_Of (Ref_Output) = Dep_Id
then
Matching_Clause := Ref_Clause;
exit;
end if;
-- Formal parameters and variables match if their inputs match
......@@ -22127,7 +22158,9 @@ package body Sem_Prag is
-------------------------
procedure Process_Global_Item (Item : Node_Id; Mode : Name_Id) is
Item_Id : constant Entity_Id := Entity_Of (Item);
Item_Id : constant Entity_Id := Available_View (Entity_Of (Item));
-- The above handles abstract views of variables and states built
-- for limited with clauses.
begin
-- Signal that the global list contains at least one abstract
......
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