summaryrefslogtreecommitdiff
path: root/gcc/ada/sem_util.adb
diff options
context:
space:
mode:
authorbstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4>2013-11-12 15:23:33 +0000
committerbstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4>2013-11-12 15:23:33 +0000
commit9456798d72d0e81a2a553287f436dcb05cff175a (patch)
tree1e80106d0c4f828b72deb6e782c20d788c0dd818 /gcc/ada/sem_util.adb
parente89aee4174fe58eaba553027558144a0f423960c (diff)
downloadgcc-9456798d72d0e81a2a553287f436dcb05cff175a.tar.gz
[./]
2013-11-12 Basile Starynkevitch <basile@starynkevitch.net> {{merge with trunk GCC 4.9 svn rev 204695; previous trunk merge was 202773; very unstable...}} [gcc/] 2013-11-11 Basile Starynkevitch <basile@starynkevitch.net> {{merge with trunk GCC 4.9 svn rev 204695; very unstable}} * melt-runtime.h (MELT_VERSION_STRING): Bump to "1.0.1+". * melt-run.proto.h: Update copyright years. include tree-cfg.h instead of tree-flow.h for GCC 4.9. * melt-runtime.cc: Include tree-cfg.h not tree-flow.h for GCC 4.9. (meltgc_walk_gimple_seq): Fatal error with GCC 4.9 since the walk_use_def_chains function disappeared from GCC... * melt/xtramelt-ana-gimple.melt (walk_gimple_seq) (walk_gimple_seq_unique_tree): issue some #warning-s for GCC 4.9 because walk_use_def_chains function disappeared from GCC... * melt/xtramelt-probe.melt (probe_docmd): Issue an error since currently the MELT probe is not usable with GCC 4.9.... git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/melt-branch@204705 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ada/sem_util.adb')
-rw-r--r--gcc/ada/sem_util.adb745
1 files changed, 702 insertions, 43 deletions
diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index dcad44f1bba..08acd702caf 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -27,8 +27,8 @@ with Atree; use Atree;
with Casing; use Casing;
with Checks; use Checks;
with Debug; use Debug;
-with Errout; use Errout;
with Elists; use Elists;
+with Errout; use Errout;
with Exp_Ch11; use Exp_Ch11;
with Exp_Disp; use Exp_Disp;
with Exp_Util; use Exp_Util;
@@ -212,25 +212,114 @@ package body Sem_Util is
-- Add_Contract_Item --
-----------------------
- procedure Add_Contract_Item (Item : Node_Id; Subp_Id : Entity_Id) is
- Items : constant Node_Id := Contract (Subp_Id);
+ procedure Add_Contract_Item (Prag : Node_Id; Id : Entity_Id) is
+ Items : constant Node_Id := Contract (Id);
Nam : Name_Id;
+ N : Node_Id;
begin
- if Present (Items) and then Nkind (Item) = N_Pragma then
- Nam := Pragma_Name (Item);
+ -- The related context must have a contract and the item to be added
+ -- must be a pragma.
+
+ pragma Assert (Present (Items));
+ pragma Assert (Nkind (Prag) = N_Pragma);
+
+ Nam := Original_Aspect_Name (Prag);
+
+ -- Contract items related to [generic] packages. The applicable pragmas
+ -- are:
+ -- Abstract_States
+ -- Initial_Condition
+ -- Initializes
+
+ if Ekind_In (Id, E_Generic_Package, E_Package) then
+ if Nam_In (Nam, Name_Abstract_State,
+ Name_Initial_Condition,
+ Name_Initializes)
+ then
+ Set_Next_Pragma (Prag, Classifications (Items));
+ Set_Classifications (Items, Prag);
+
+ -- The pragma is not a proper contract item
+
+ else
+ raise Program_Error;
+ end if;
+
+ -- Contract items related to package bodies. The applicable pragmas are:
+ -- Refined_States
+
+ elsif Ekind (Id) = E_Package_Body then
+ if Nam = Name_Refined_State then
+ Set_Next_Pragma (Prag, Classifications (Items));
+ Set_Classifications (Items, Prag);
- if Nam_In (Nam, Name_Precondition, Name_Postcondition) then
- Set_Next_Pragma (Item, Pre_Post_Conditions (Items));
- Set_Pre_Post_Conditions (Items, Item);
+ -- The pragma is not a proper contract item
+
+ else
+ raise Program_Error;
+ end if;
+
+ -- Contract items related to subprogram or entry declarations. The
+ -- applicable pragmas are:
+ -- Contract_Cases
+ -- Depends
+ -- Global
+ -- Post
+ -- Postcondition
+ -- Pre
+ -- Precondition
+ -- Test_Case
+
+ elsif Ekind_In (Id, E_Entry, E_Entry_Family)
+ or else Is_Generic_Subprogram (Id)
+ or else Is_Subprogram (Id)
+ then
+ if Nam_In (Nam, Name_Precondition,
+ Name_Postcondition,
+ Name_Pre,
+ Name_Post,
+ Name_uPre,
+ Name_uPost)
+ then
+ -- Before we add a precondition or postcondition to the list,
+ -- make sure we do not have a disallowed duplicate, which can
+ -- happen if we use a pragma for Pre[_Class] or Post[_Class]
+ -- instead of the corresponding aspect.
+
+ if not From_Aspect_Specification (Prag)
+ and then Nam_In (Nam, Name_Pre_Class,
+ Name_Pre,
+ Name_uPre,
+ Name_Post_Class,
+ Name_Post,
+ Name_uPost)
+ then
+ N := Pre_Post_Conditions (Items);
+ while Present (N) loop
+ if not Split_PPC (N)
+ and then Original_Aspect_Name (N) = Nam
+ then
+ Error_Msg_Sloc := Sloc (N);
+ Error_Msg_NE
+ ("duplication of aspect for & given#", Prag, Id);
+ return;
+ else
+ N := Next_Pragma (N);
+ end if;
+ end loop;
+ end if;
+
+ Set_Next_Pragma (Prag, Pre_Post_Conditions (Items));
+ Set_Pre_Post_Conditions (Items, Prag);
elsif Nam_In (Nam, Name_Contract_Cases, Name_Test_Case) then
- Set_Next_Pragma (Item, Contract_Test_Cases (Items));
- Set_Contract_Test_Cases (Items, Item);
+ Set_Next_Pragma (Prag, Contract_Test_Cases (Items));
+ Set_Contract_Test_Cases (Items, Prag);
elsif Nam_In (Nam, Name_Depends, Name_Global) then
- Set_Next_Pragma (Item, Classifications (Items));
- Set_Classifications (Items, Item);
+ Set_Next_Pragma (Prag, Classifications (Items));
+ Set_Classifications (Items, Prag);
-- The pragma is not a proper contract item
@@ -238,10 +327,21 @@ package body Sem_Util is
raise Program_Error;
end if;
- -- The subprogram has not been properly decorated or the item is illegal
+ -- Contract items related to subprogram bodies. The applicable pragmas
+ -- are:
+ -- Refined_Depends
+ -- Refined_Global
- else
- raise Program_Error;
+ elsif Ekind (Id) = E_Subprogram_Body then
+ if Nam_In (Nam, Name_Refined_Depends, Name_Refined_Global) then
+ Set_Next_Pragma (Prag, Classifications (Items));
+ Set_Classifications (Items, Prag);
+
+ -- The pragma is not a proper contract item
+
+ else
+ raise Program_Error;
+ end if;
end if;
end Add_Contract_Item;
@@ -323,7 +423,7 @@ package body Sem_Util is
Decl := First
(Visible_Declarations
- (Specification (Unit_Declaration_Node (Current_Scope))));
+ (Package_Specification (Current_Scope)));
while Present (Decl) loop
if Nkind (Decl) = N_Private_Extension_Declaration
and then Defining_Entity (Decl) = Typ
@@ -1069,6 +1169,13 @@ package body Sem_Util is
return;
end if;
+ -- Ignore in ASIS mode, elaboration entity is not in source and plays
+ -- no role in analysis.
+
+ if ASIS_Mode then
+ return;
+ end if;
+
-- Construct name of elaboration entity as xxx_E, where xxx is the unit
-- name with dots replaced by double underscore. We have to manually
-- construct this name, since it will be elaborated in the outer scope,
@@ -1338,7 +1445,7 @@ package body Sem_Util is
-- Ada 2005 (AI-50217): If the type is available through a limited
-- with_clause, verify that its full view has been analyzed.
- if From_With_Type (T)
+ if From_Limited_With (T)
and then Present (Non_Limited_View (T))
and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
then
@@ -3141,6 +3248,208 @@ package body Sem_Util is
end if;
end Conditional_Delay;
+ ----------------------------
+ -- Contains_Refined_State --
+ ----------------------------
+
+ function Contains_Refined_State (Prag : Node_Id) return Boolean is
+ function Has_State_In_Dependency (List : Node_Id) return Boolean;
+ -- Determine whether a dependency list mentions a state with a visible
+ -- refinement.
+
+ function Has_State_In_Global (List : Node_Id) return Boolean;
+ -- Determine whether a global list mentions a state with a visible
+ -- refinement.
+
+ function Is_Refined_State (Item : Node_Id) return Boolean;
+ -- Determine whether Item is a reference to an abstract state with a
+ -- visible refinement.
+
+ -----------------------------
+ -- Has_State_In_Dependency --
+ -----------------------------
+
+ function Has_State_In_Dependency (List : Node_Id) return Boolean is
+ Clause : Node_Id;
+ Output : Node_Id;
+
+ begin
+ -- A null dependency list does not mention any states
+
+ if Nkind (List) = N_Null then
+ return False;
+
+ -- Dependency clauses appear as component associations of an
+ -- aggregate.
+
+ elsif Nkind (List) = N_Aggregate
+ and then Present (Component_Associations (List))
+ then
+ Clause := First (Component_Associations (List));
+ while Present (Clause) loop
+
+ -- Inspect the outputs of a dependency clause
+
+ Output := First (Choices (Clause));
+ while Present (Output) loop
+ if Is_Refined_State (Output) then
+ return True;
+ end if;
+
+ Next (Output);
+ end loop;
+
+ -- Inspect the outputs of a dependency clause
+
+ if Is_Refined_State (Expression (Clause)) then
+ return True;
+ end if;
+
+ Next (Clause);
+ end loop;
+
+ -- If we get here, then none of the dependency clauses mention a
+ -- state with visible refinement.
+
+ return False;
+
+ -- An illegal pragma managed to sneak in
+
+ else
+ raise Program_Error;
+ end if;
+ end Has_State_In_Dependency;
+
+ -------------------------
+ -- Has_State_In_Global --
+ -------------------------
+
+ function Has_State_In_Global (List : Node_Id) return Boolean is
+ Item : Node_Id;
+
+ begin
+ -- A null global list does not mention any states
+
+ if Nkind (List) = N_Null then
+ return False;
+
+ -- Simple global list or moded global list declaration
+
+ elsif Nkind (List) = N_Aggregate then
+
+ -- The declaration of a simple global list appear as a collection
+ -- of expressions.
+
+ if Present (Expressions (List)) then
+ Item := First (Expressions (List));
+ while Present (Item) loop
+ if Is_Refined_State (Item) then
+ return True;
+ end if;
+
+ Next (Item);
+ end loop;
+
+ -- The declaration of a moded global list appears as a collection
+ -- of component associations where individual choices denote
+ -- modes.
+
+ else
+ Item := First (Component_Associations (List));
+ while Present (Item) loop
+ if Has_State_In_Global (Expression (Item)) then
+ return True;
+ end if;
+
+ Next (Item);
+ end loop;
+ end if;
+
+ -- If we get here, then the simple/moded global list did not
+ -- mention any states with a visible refinement.
+
+ return False;
+
+ -- Single global item declaration
+
+ elsif Is_Entity_Name (List) then
+ return Is_Refined_State (List);
+
+ -- An illegal pragma managed to sneak in
+
+ else
+ raise Program_Error;
+ end if;
+ end Has_State_In_Global;
+
+ ----------------------
+ -- Is_Refined_State --
+ ----------------------
+
+ function Is_Refined_State (Item : Node_Id) return Boolean is
+ Elmt : Node_Id;
+ Item_Id : Entity_Id;
+
+ begin
+ if Nkind (Item) = N_Null then
+ return False;
+
+ -- States cannot be subject to attribute 'Result. This case arises
+ -- in dependency relations.
+
+ elsif Nkind (Item) = N_Attribute_Reference
+ and then Attribute_Name (Item) = Name_Result
+ then
+ return False;
+
+ -- Multiple items appear as an aggregate. This case arises in
+ -- dependency relations.
+
+ elsif Nkind (Item) = N_Aggregate
+ and then Present (Expressions (Item))
+ then
+ Elmt := First (Expressions (Item));
+ while Present (Elmt) loop
+ if Is_Refined_State (Elmt) then
+ return True;
+ end if;
+
+ Next (Elmt);
+ end loop;
+
+ -- If we get here, then none of the inputs or outputs reference a
+ -- state with visible refinement.
+
+ return False;
+
+ -- Single item
+
+ else
+ Item_Id := Entity_Of (Item);
+
+ return
+ Ekind (Item_Id) = E_Abstract_State
+ and then Has_Visible_Refinement (Item_Id);
+ end if;
+ end Is_Refined_State;
+
+ -- Local variables
+
+ Arg : constant Node_Id :=
+ Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
+ Nam : constant Name_Id := Pragma_Name (Prag);
+
+ -- Start of processing for Contains_Refined_State
+
+ begin
+ if Nam = Name_Depends then
+ return Has_State_In_Dependency (Arg);
+
+ else pragma Assert (Nam = Name_Global);
+ return Has_State_In_Global (Arg);
+ end if;
+ end Contains_Refined_State;
+
-------------------------
-- Copy_Component_List --
-------------------------
@@ -4274,7 +4583,6 @@ package body Sem_Util is
procedure Ensure_Freeze_Node (E : Entity_Id) is
FN : Node_Id;
-
begin
if No (Freeze_Node (E)) then
FN := Make_Freeze_Entity (Sloc (E));
@@ -4567,9 +4875,14 @@ package body Sem_Util is
-- Inherited discriminants and components in derived record types are
-- immediately visible. Itypes are not.
+ -- Unless the Itype is for a record type with a corresponding remote
+ -- type (what is that about, it was not commented ???)
+
if Ekind_In (Def_Id, E_Discriminant, E_Component)
- or else (No (Corresponding_Remote_Type (Def_Id))
- and then not Is_Itype (Def_Id))
+ or else
+ ((not Is_Record_Type (Def_Id)
+ or else No (Corresponding_Remote_Type (Def_Id)))
+ and then not Is_Itype (Def_Id))
then
Set_Is_Immediately_Visible (Def_Id);
Set_Current_Entity (Def_Id);
@@ -4669,6 +4982,35 @@ package body Sem_Util is
end if;
end Enter_Name;
+ ---------------
+ -- Entity_Of --
+ ---------------
+
+ function Entity_Of (N : Node_Id) return Entity_Id is
+ Id : Entity_Id;
+
+ begin
+ Id := Empty;
+
+ if Is_Entity_Name (N) then
+ Id := Entity (N);
+
+ -- Follow a possible chain of renamings to reach the root renamed
+ -- object.
+
+ while Present (Id) and then Present (Renamed_Object (Id)) loop
+ if Is_Entity_Name (Renamed_Object (Id)) then
+ Id := Entity (Renamed_Object (Id));
+ else
+ Id := Empty;
+ exit;
+ end if;
+ end loop;
+ end if;
+
+ return Id;
+ end Entity_Of;
+
--------------------------
-- Explain_Limited_Type --
--------------------------
@@ -5184,9 +5526,9 @@ package body Sem_Util is
Discrim := First (Choices (Assoc));
exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
or else (Present (Corresponding_Discriminant (Entity (Discrim)))
- and then
- Chars (Corresponding_Discriminant (Entity (Discrim)))
- = Chars (Discrim_Name))
+ and then
+ Chars (Corresponding_Discriminant (Entity (Discrim))) =
+ Chars (Discrim_Name))
or else Chars (Original_Record_Component (Entity (Discrim)))
= Chars (Discrim_Name);
@@ -5274,7 +5616,6 @@ package body Sem_Util is
Find_Discrete_Value : while Present (Variant) loop
Discrete_Choice := First (Discrete_Choices (Variant));
while Present (Discrete_Choice) loop
-
exit Find_Discrete_Value when
Nkind (Discrete_Choice) = N_Others_Choice;
@@ -5305,8 +5646,8 @@ package body Sem_Util is
-- If we have found the corresponding choice, recursively add its
-- components to the Into list.
- Gather_Components (Empty,
- Component_List (Variant), Governed_By, Into, Report_Errors);
+ Gather_Components
+ (Empty, Component_List (Variant), Governed_By, Into, Report_Errors);
end Gather_Components;
------------------------
@@ -6441,6 +6782,51 @@ package body Sem_Util is
return False;
end Has_Interfaces;
+ ---------------------------------
+ -- Has_No_Obvious_Side_Effects --
+ ---------------------------------
+
+ function Has_No_Obvious_Side_Effects (N : Node_Id) return Boolean is
+ begin
+ -- For now, just handle literals, constants, and non-volatile
+ -- variables and expressions combining these with operators or
+ -- short circuit forms.
+
+ if Nkind (N) in N_Numeric_Or_String_Literal then
+ return True;
+
+ elsif Nkind (N) = N_Character_Literal then
+ return True;
+
+ elsif Nkind (N) in N_Unary_Op then
+ return Has_No_Obvious_Side_Effects (Right_Opnd (N));
+
+ elsif Nkind (N) in N_Binary_Op or else Nkind (N) in N_Short_Circuit then
+ return Has_No_Obvious_Side_Effects (Left_Opnd (N))
+ and then
+ Has_No_Obvious_Side_Effects (Right_Opnd (N));
+
+ elsif Nkind (N) = N_Expression_With_Actions
+ and then
+ Is_Empty_List (Actions (N))
+ then
+ return Has_No_Obvious_Side_Effects (Expression (N));
+
+ elsif Nkind (N) in N_Has_Entity then
+ return Present (Entity (N))
+ and then Ekind_In (Entity (N), E_Variable,
+ E_Constant,
+ E_Enumeration_Literal,
+ E_In_Parameter,
+ E_Out_Parameter,
+ E_In_Out_Parameter)
+ and then not Is_Volatile (Entity (N));
+
+ else
+ return False;
+ end if;
+ end Has_No_Obvious_Side_Effects;
+
------------------------
-- Has_Null_Exclusion --
------------------------
@@ -7794,7 +8180,7 @@ package body Sem_Util is
-- statement is aliased if its type is immutably limited.
or else (Is_Return_Object (E)
- and then Is_Immutably_Limited_Type (Etype (E)));
+ and then Is_Limited_View (Etype (E)));
elsif Nkind (Obj) = N_Selected_Component then
return Is_Aliased (Entity (Selector_Name (Obj)));
@@ -7929,6 +8315,17 @@ package body Sem_Util is
end if;
end Is_Atomic_Object;
+ -------------------------
+ -- Is_Attribute_Result --
+ -------------------------
+
+ function Is_Attribute_Result (N : Node_Id) return Boolean is
+ begin
+ return
+ Nkind (N) = N_Attribute_Reference
+ and then Attribute_Name (N) = Name_Result;
+ end Is_Attribute_Result;
+
------------------------------------
-- Is_Body_Or_Package_Declaration --
------------------------------------
@@ -7962,6 +8359,181 @@ package body Sem_Util is
Is_RTE (Root_Type (Under), RO_WW_Super_String));
end Is_Bounded_String;
+ -------------------------
+ -- Is_Child_Or_Sibling --
+ -------------------------
+
+ function Is_Child_Or_Sibling
+ (Pack_1 : Entity_Id;
+ Pack_2 : Entity_Id;
+ Private_Child : Boolean) return Boolean
+ is
+ function Distance_From_Standard (Pack : Entity_Id) return Nat;
+ -- Given an arbitrary package, return the number of "climbs" necessary
+ -- to reach scope Standard_Standard.
+
+ procedure Equalize_Depths
+ (Pack : in out Entity_Id;
+ Depth : in out Nat;
+ Depth_To_Reach : Nat);
+ -- Given an arbitrary package, its depth and a target depth to reach,
+ -- climb the scope chain until the said depth is reached. The pointer
+ -- to the package and its depth a modified during the climb.
+
+ function Is_Child (Pack : Entity_Id) return Boolean;
+ -- Given a package Pack, determine whether it is a child package that
+ -- satisfies the privacy requirement (if set).
+
+ ----------------------------
+ -- Distance_From_Standard --
+ ----------------------------
+
+ function Distance_From_Standard (Pack : Entity_Id) return Nat is
+ Dist : Nat;
+ Scop : Entity_Id;
+
+ begin
+ Dist := 0;
+ Scop := Pack;
+ while Present (Scop) and then Scop /= Standard_Standard loop
+ Dist := Dist + 1;
+ Scop := Scope (Scop);
+ end loop;
+
+ return Dist;
+ end Distance_From_Standard;
+
+ ---------------------
+ -- Equalize_Depths --
+ ---------------------
+
+ procedure Equalize_Depths
+ (Pack : in out Entity_Id;
+ Depth : in out Nat;
+ Depth_To_Reach : Nat)
+ is
+ begin
+ -- The package must be at a greater or equal depth
+
+ if Depth < Depth_To_Reach then
+ raise Program_Error;
+ end if;
+
+ -- Climb the scope chain until the desired depth is reached
+
+ while Present (Pack) and then Depth /= Depth_To_Reach loop
+ Pack := Scope (Pack);
+ Depth := Depth - 1;
+ end loop;
+ end Equalize_Depths;
+
+ --------------
+ -- Is_Child --
+ --------------
+
+ function Is_Child (Pack : Entity_Id) return Boolean is
+ begin
+ if Is_Child_Unit (Pack) then
+ if Private_Child then
+ return Is_Private_Descendant (Pack);
+ else
+ return True;
+ end if;
+
+ -- The package is nested, it cannot act a child or a sibling
+
+ else
+ return False;
+ end if;
+ end Is_Child;
+
+ -- Local variables
+
+ P_1 : Entity_Id := Pack_1;
+ P_1_Child : Boolean := False;
+ P_1_Depth : Nat := Distance_From_Standard (P_1);
+ P_2 : Entity_Id := Pack_2;
+ P_2_Child : Boolean := False;
+ P_2_Depth : Nat := Distance_From_Standard (P_2);
+
+ -- Start of processing for Is_Child_Or_Sibling
+
+ begin
+ pragma Assert
+ (Ekind (Pack_1) = E_Package and then Ekind (Pack_2) = E_Package);
+
+ -- Both packages denote the same entity, therefore they cannot be
+ -- children or siblings.
+
+ if P_1 = P_2 then
+ return False;
+
+ -- One of the packages is at a deeper level than the other. Note that
+ -- both may still come from differen hierarchies.
+
+ -- (root) P_2
+ -- / \ :
+ -- X P_2 or X
+ -- : :
+ -- P_1 P_1
+
+ elsif P_1_Depth > P_2_Depth then
+ Equalize_Depths (P_1, P_1_Depth, P_2_Depth);
+ P_1_Child := True;
+
+ -- (root) P_1
+ -- / \ :
+ -- P_1 X or X
+ -- : :
+ -- P_2 P_2
+
+ elsif P_2_Depth > P_1_Depth then
+ Equalize_Depths (P_2, P_2_Depth, P_1_Depth);
+ P_2_Child := True;
+ end if;
+
+ -- At this stage the package pointers have been elevated to the same
+ -- depth. If the related entities are the same, then one package is a
+ -- potential child of the other:
+
+ -- P_1
+ -- :
+ -- X became P_1 P_2 or vica versa
+ -- :
+ -- P_2
+
+ if P_1 = P_2 then
+ if P_1_Child then
+ return Is_Child (Pack_1);
+ else pragma Assert (P_2_Child);
+ return Is_Child (Pack_2);
+ end if;
+
+ -- The packages may come from the same package chain or from entirely
+ -- different hierarcies. To determine this, climb the scope stack until
+ -- a common root is found.
+
+ -- (root) (root 1) (root 2)
+ -- / \ | |
+ -- P_1 P_2 P_1 P_2
+
+ else
+ while Present (P_1) and then Present (P_2) loop
+
+ -- The two packages may be siblings
+
+ if P_1 = P_2 then
+ return Is_Child (Pack_1) and then Is_Child (Pack_2);
+ end if;
+
+ P_1 := Scope (P_1);
+ P_2 := Scope (P_2);
+ end loop;
+ end if;
+
+ return False;
+ end Is_Child_Or_Sibling;
+
-----------------------------
-- Is_Concurrent_Interface --
-----------------------------
@@ -8655,6 +9227,7 @@ package body Sem_Util is
return Is_Fully_Initialized_Variant (U);
end if;
end;
+
else
return False;
end if;
@@ -8787,7 +9360,7 @@ package body Sem_Util is
begin
return
Is_Class_Wide_Type (Typ)
- and then (Is_Limited_Type (Typ) or else From_With_Type (Typ));
+ and then (Is_Limited_Type (Typ) or else From_Limited_With (Typ));
end Is_Limited_Class_Wide_Type;
---------------------------------
@@ -8863,10 +9436,12 @@ package body Sem_Util is
when N_Function_Call =>
return Etype (N) /= Standard_Void_Type;
- -- Attributes 'Input and 'Result produce objects
+ -- Attributes 'Input, 'Old and 'Result produce objects
when N_Attribute_Reference =>
- return Nam_In (Attribute_Name (N), Name_Input, Name_Result);
+ return
+ Nam_In
+ (Attribute_Name (N), Name_Input, Name_Old, Name_Result);
when N_Selected_Component =>
return
@@ -9844,7 +10419,8 @@ package body Sem_Util is
function In_Protected_Function (E : Entity_Id) return Boolean;
-- Within a protected function, the private components of the enclosing
-- protected type are constants. A function nested within a (protected)
- -- procedure is not itself protected.
+ -- procedure is not itself protected. Within the body of a protected
+ -- function the current instance of the protected type is a constant.
function Is_Variable_Prefix (P : Node_Id) return Boolean;
-- Prefixes can involve implicit dereferences, in which case we must
@@ -9856,12 +10432,24 @@ package body Sem_Util is
---------------------------
function In_Protected_Function (E : Entity_Id) return Boolean is
- Prot : constant Entity_Id := Scope (E);
+ Prot : Entity_Id;
S : Entity_Id;
begin
+ -- E is the current instance of a type
+
+ if Is_Type (E) then
+ Prot := E;
+
+ -- E is an object
+
+ else
+ Prot := Scope (E);
+ end if;
+
if not Is_Protected_Type (Prot) then
return False;
+
else
S := Current_Scope;
while Present (S) and then S /= Prot loop
@@ -9982,9 +10570,13 @@ package body Sem_Util is
or else K = E_In_Out_Parameter
or else K = E_Generic_In_Out_Parameter
- -- Current instance of type
+ -- Current instance of type. If this is a protected type, check
+ -- we are not within the body of one of its protected functions.
+
+ or else (Is_Type (E)
+ and then In_Open_Scopes (E)
+ and then not In_Protected_Function (E))
- or else (Is_Type (E) and then In_Open_Scopes (E))
or else (Is_Incomplete_Or_Private_Type (E)
and then In_Open_Scopes (Full_View (E)));
end;
@@ -12215,8 +12807,8 @@ package body Sem_Util is
end if;
if Nkind (P) = N_Selected_Component
- and then Present (
- Entry_Formal (Entity (Selector_Name (P))))
+ and then
+ Present (Entry_Formal (Entity (Selector_Name (P))))
then
-- Case of a reference to an entry formal
@@ -12240,15 +12832,15 @@ package body Sem_Util is
end if;
end;
- elsif Nkind (Exp) = N_Type_Conversion
- or else Nkind (Exp) = N_Unchecked_Type_Conversion
+ elsif Nkind_In (Exp, N_Type_Conversion,
+ N_Unchecked_Type_Conversion)
then
Exp := Expression (Exp);
goto Continue;
- elsif Nkind (Exp) = N_Slice
- or else Nkind (Exp) = N_Indexed_Component
- or else Nkind (Exp) = N_Selected_Component
+ elsif Nkind_In (Exp, N_Slice,
+ N_Indexed_Component,
+ N_Selected_Component)
then
Exp := Prefix (Exp);
goto Continue;
@@ -12307,7 +12899,9 @@ package body Sem_Util is
-- source. This excludes, for example, calls to a dispatching
-- assignment operation when the left-hand side is tagged.
- if Modification_Comes_From_Source or else SPARK_Mode then
+ -- Why is SPARK mode different here ???
+
+ if Modification_Comes_From_Source or SPARK_Mode then
Generate_Reference (Ent, Exp, 'm');
-- If the target of the assignment is the bound variable
@@ -12653,6 +13247,71 @@ package body Sem_Util is
end if;
end Object_Access_Level;
+ --------------------------
+ -- Original_Aspect_Name --
+ --------------------------
+
+ function Original_Aspect_Name (N : Node_Id) return Name_Id is
+ Pras : Node_Id;
+ Name : Name_Id;
+
+ begin
+ pragma Assert (Nkind_In (N, N_Aspect_Specification, N_Pragma));
+ Pras := N;
+
+ if Is_Rewrite_Substitution (Pras)
+ and then Nkind (Original_Node (Pras)) = N_Pragma
+ then
+ Pras := Original_Node (Pras);
+ end if;
+
+ -- Case where we came from aspect specication
+
+ if Nkind (Pras) = N_Pragma and then From_Aspect_Specification (Pras) then
+ Pras := Corresponding_Aspect (Pras);
+ end if;
+
+ -- Get name from aspect or pragma
+
+ if Nkind (Pras) = N_Pragma then
+ Name := Pragma_Name (Pras);
+ else
+ Name := Chars (Identifier (Pras));
+ end if;
+
+ -- Deal with 'Class
+
+ if Class_Present (Pras) then
+ case Name is
+
+ -- Names that need converting to special _xxx form
+
+ when Name_Pre |
+ Name_Pre_Class =>
+ Name := Name_uPre;
+
+ when Name_Post |
+ Name_Post_Class =>
+ Name := Name_uPost;
+
+ when Name_Invariant =>
+ Name := Name_uInvariant;
+
+ when Name_Type_Invariant |
+ Name_Type_Invariant_Class =>
+ Name := Name_uType_Invariant;
+
+ -- Nothing to do for other cases (e.g. a Check that derived
+ -- from Pre_Class and has the flag set). Also we do nothing
+ -- if the name is already in special _xxx form.
+
+ when others =>
+ null;
+ end case;
+ end if;
+
+ return Name;
+ end Original_Aspect_Name;
--------------------------------------
-- Original_Corresponding_Operation --
--------------------------------------
@@ -14970,7 +15629,7 @@ package body Sem_Util is
("\\found an access type with designated}!",
Expr, Designated_Type (Found_Type));
else
- if From_With_Type (Found_Type) then
+ if From_Limited_With (Found_Type) then
Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
Error_Msg_Qual_Level := 99;
Error_Msg_NE -- CODEFIX