===================================================================
@@ -1414,10 +1414,10 @@
-- Label_Construct (Node2-Sem)
-- Used in an N_Implicit_Label_Declaration node. Refers to an N_Label,
-- N_Block_Statement or N_Loop_Statement node to which the label
- -- declaration applies. This is not currently used in the compiler
- -- itself, but it is useful in the implementation of ASIS queries.
- -- This field is left empty for the special labels generated as part
- -- of expanding raise statements with a local exception handler.
+ -- declaration applies. This attribute is used both in the compiler and
+ -- in the implementation of ASIS queries. The field is left empty for the
+ -- special labels generated as part of expanding raise statements with a
+ -- local exception handler.
-- Library_Unit (Node4-Sem)
-- In a stub node, Library_Unit points to the compilation unit node of
===================================================================
@@ -32,7 +32,6 @@
pragma Style_Checks (All_Checks);
-- Turn off subprogram ordering, not used for this unit
-with Aspects; use Aspects;
with Atree; use Atree;
with Namet; use Namet;
with Nlists; use Nlists;
@@ -6575,27 +6574,41 @@
return Ekind (Id) = E_Procedure and then Chars (Id) = Name_uFinalizer;
end Is_Finalizer;
- -----------------------
- -- Is_Ghost_Function --
- -----------------------
+ ---------------------
+ -- Is_Ghost_Entity --
+ ---------------------
- function Is_Ghost_Function (Id : E) return B is
+ function Is_Ghost_Entity (Id : E) return B is
+ begin
+ if Present (Id) and then Ekind (Id) = E_Variable then
+ return Convention (Id) = Convention_Ghost;
+ else
+ return Is_Ghost_Subprogram (Id);
+ end if;
+ end Is_Ghost_Entity;
+
+ -------------------------
+ -- Is_Ghost_Subprogram --
+ -------------------------
+
+ function Is_Ghost_Subprogram (Id : E) return B is
Subp_Id : Entity_Id := Id;
begin
- if Present (Subp_Id) and then Ekind (Subp_Id) = E_Function then
+ if Present (Subp_Id)
+ and then Ekind_In (Subp_Id, E_Function, E_Procedure)
+ then
+ -- Handle subprogram renamings
- -- Handle renamings of functions
-
if Present (Alias (Subp_Id)) then
Subp_Id := Alias (Subp_Id);
end if;
- return Has_Aspect (Subp_Id, Aspect_Ghost);
+ return Convention (Subp_Id) = Convention_Ghost;
end if;
return False;
- end Is_Ghost_Function;
+ end Is_Ghost_Subprogram;
--------------------
-- Is_Input_State --
===================================================================
@@ -2314,10 +2314,14 @@
-- package, generic function, generic procedure), and False for all
-- other entities.
+-- Is_Ghost_Entity (synthesized)
+-- Applies to all entities. Yields True for a subprogram or a whole
+-- object that has convention Ghost.
+-- Is_Ghost_Subprogram (synthesized)
+-- Applies to all entities. Yields True for a subprogram that has a Ghost
+-- convention.
+
-- Is_Hidden (Flag57)
-- Defined in all entities. Set true for all entities declared in the
-- private part or body of a package. Also marks generic formals of a
@@ -4219,6 +4223,7 @@
-- floating point subtype created by a floating point type declaration.
E_Floating_Point_Subtype,
+
-- Floating point subtype, created by either a floating point subtype
-- or floating point type declaration (in the latter case a floating
-- point type is created for the base type, and this is the first
@@ -5428,7 +5433,8 @@
-- Address_Clause (synth)
-- First_Formal (synth)
-- First_Formal_With_Extras (synth)
- -- Is_Ghost_Function (synth) (non-generic case only)
+ -- Is_Ghost_Entity (synth) (non-generic case only)
+ -- Is_Ghost_Subprogram (synth) (non-generic case only)
-- Last_Formal (synth)
-- Number_Formals (synth)
-- Scope_Depth (synth)
@@ -5701,6 +5707,8 @@
-- First_Formal (synth)
-- First_Formal_With_Extras (synth)
-- Is_Finalizer (synth)
+ -- Is_Ghost_Entity (synth) (non-generic case only)
+ -- Is_Ghost_Subprogram (synth) (non-generic case only)
-- Last_Formal (synth)
-- Number_Formals (synth)
@@ -5907,6 +5915,7 @@
-- Treat_As_Volatile (Flag41)
-- Address_Clause (synth)
-- Alignment_Clause (synth)
+ -- Is_Ghost_Entity (synth)
-- Size_Clause (synth)
-- E_Void
@@ -6638,7 +6647,8 @@
function Is_Discriminal (Id : E) return B;
function Is_Dynamic_Scope (Id : E) return B;
function Is_Finalizer (Id : E) return B;
- function Is_Ghost_Function (Id : E) return B;
+ function Is_Ghost_Entity (Id : E) return B;
+ function Is_Ghost_Subprogram (Id : E) return B;
function Is_Input_State (Id : E) return B;
function Is_Null_State (Id : E) return B;
function Is_Output_State (Id : E) return B;
===================================================================
@@ -4975,9 +4975,16 @@
and then Present (Overridden_Operation (E))
and then C /= Convention (Overridden_Operation (E))
then
- Error_Pragma_Arg
- ("cannot change convention for overridden dispatching "
- & "operation", Arg1);
+ -- An attempt to override a subprogram with a ghost subprogram
+ -- appears as a mismatch in conventions.
+
+ if C = Convention_Ghost then
+ Error_Msg_N ("ghost subprogram & cannot be overriding", E);
+ else
+ Error_Pragma_Arg
+ ("cannot change convention for overridden dispatching "
+ & "operation", Arg1);
+ end if;
end if;
-- Special checks for Convention_Stdcall
@@ -5136,14 +5143,14 @@
if C = Convention_Ada_Pass_By_Copy then
if not Is_First_Subtype (E) then
Error_Pragma_Arg
- ("convention `Ada_Pass_By_Copy` only "
- & "allowed for types", Arg2);
+ ("convention `Ada_Pass_By_Copy` only allowed for types",
+ Arg2);
end if;
if Is_By_Reference_Type (E) then
Error_Pragma_Arg
- ("convention `Ada_Pass_By_Copy` not allowed for "
- & "by-reference type", Arg1);
+ ("convention `Ada_Pass_By_Copy` not allowed for by-reference "
+ & "type", Arg1);
end if;
end if;
@@ -5152,17 +5159,25 @@
if C = Convention_Ada_Pass_By_Reference then
if not Is_First_Subtype (E) then
Error_Pragma_Arg
- ("convention `Ada_Pass_By_Reference` only "
- & "allowed for types", Arg2);
+ ("convention `Ada_Pass_By_Reference` only allowed for types",
+ Arg2);
end if;
if Is_By_Copy_Type (E) then
Error_Pragma_Arg
- ("convention `Ada_Pass_By_Reference` not allowed for "
- & "by-copy type", Arg1);
+ ("convention `Ada_Pass_By_Reference` not allowed for by-copy "
+ & "type", Arg1);
end if;
end if;
+ -- Ghost special checking
+
+ if Is_Ghost_Subprogram (E)
+ and then Present (Overridden_Operation (E))
+ then
+ Error_Msg_N ("ghost subprogram & cannot be overriding", E);
+ end if;
+
-- Go to renamed subprogram if present, since convention applies to
-- the actual renamed entity, not to the renaming entity. If the
-- subprogram is inherited, go to parent subprogram.
@@ -5299,8 +5314,8 @@
Generate_Reference (E, Id, 'i');
end if;
- -- If the pragma comes from from an aspect, it only applies
- -- to the given entity, not its homonyms.
+ -- If the pragma comes from from an aspect, it only applies to the
+ -- given entity, not its homonyms.
if From_Aspect_Specification (N) then
return;
@@ -11842,39 +11857,6 @@
end if;
end Float_Representation;
- -----------
- -- Ghost --
- -----------
-
- -- pragma GHOST (function_LOCAL_NAME);
-
- when Pragma_Ghost => Ghost : declare
- Subp : Node_Id;
- Subp_Id : Entity_Id;
-
- begin
- GNAT_Pragma;
- S14_Pragma;
- Check_Arg_Count (1);
- Check_Arg_Is_Local_Name (Arg1);
-
- -- Ensure the proper placement of the pragma. Ghost must be
- -- associated with a subprogram declaration.
-
- Subp := Parent (Corresponding_Aspect (N));
-
- if Nkind (Subp) /= N_Subprogram_Declaration then
- Pragma_Misplaced;
- return;
- end if;
-
- Subp_Id := Defining_Unit_Name (Specification (Subp));
-
- if Ekind (Subp_Id) /= E_Function then
- Error_Pragma ("pragma % must be applied to a function");
- end if;
- end Ghost;
-
------------
-- Global --
------------
@@ -13120,6 +13102,7 @@
-- before the body is built (e.g. within an expression function).
PDecl := Build_Invariant_Procedure_Declaration (Typ);
+
Insert_After (N, PDecl);
Analyze (PDecl);
@@ -17993,7 +17976,7 @@
Set_Is_Ignored (N, True);
when Name_Disable =>
- Set_Is_Ignored (N, True);
+ Set_Is_Ignored (N, True);
Set_Is_Disabled (N, True);
when others =>
@@ -18277,7 +18260,6 @@
Pragma_Fast_Math => -1,
Pragma_Finalize_Storage_Only => 0,
Pragma_Float_Representation => 0,
- Pragma_Ghost => 0,
Pragma_Global => -1,
Pragma_Ident => -1,
Pragma_Implementation_Defined => -1,
===================================================================
@@ -12401,13 +12401,13 @@
Analyze (Act);
end if;
- -- Ensure that a ghost function does not act as generic actual
+ -- Ensure that a ghost subprogram does not act as generic actual
if Is_Entity_Name (Act)
- and then Is_Ghost_Function (Entity (Act))
+ and then Is_Ghost_Subprogram (Entity (Act))
then
Error_Msg_N
- ("ghost function & cannot act as generic actual", Act);
+ ("ghost subprogram & cannot act as generic actual", Act);
Abandon_Instantiation (Act);
elsif Errs /= Serious_Errors_Detected then
===================================================================
@@ -602,9 +602,9 @@
elsif Aname = Name_Unchecked_Access then
Error_Attr ("attribute% cannot be applied to a subprogram", P);
- elsif Is_Ghost_Function (Entity (P)) then
+ elsif Is_Ghost_Subprogram (Entity (P)) then
Error_Attr_P
- ("prefix of % attribute cannot be a ghost function");
+ ("prefix of % attribute cannot be a ghost subprogram");
end if;
-- Issue an error if the prefix denotes an eliminated subprogram
===================================================================
@@ -684,6 +684,8 @@
Write_Line ("Intrinsic");
when Convention_Entry =>
Write_Line ("Entry");
+ when Convention_Ghost =>
+ Write_Line ("Ghost");
when Convention_Protected =>
Write_Line ("Protected");
when Convention_Assembler =>
===================================================================
@@ -854,10 +854,10 @@
-- Flag indicates whether an interpretation of the prefix is a
-- parameterless call that returns an access_to_subprogram.
- procedure Check_Ghost_Function_Call;
- -- Verify the legality of a call to a ghost function. Such calls can
+ procedure Check_Ghost_Subprogram_Call;
+ -- Verify the legality of a call to a ghost subprogram. Such calls can
-- appear only in assertion expressions except subtype predicates or
- -- from within another ghost function.
+ -- from within another ghost subprogram.
procedure Check_Mixed_Parameter_And_Named_Associations;
-- Check that parameter and named associations are not mixed. This is
@@ -873,15 +873,15 @@
procedure No_Interpretation;
-- Output error message when no valid interpretation exists
- -------------------------------
- -- Check_Ghost_Function_Call --
- -------------------------------
+ ---------------------------------
+ -- Check_Ghost_Subprogram_Call --
+ ---------------------------------
- procedure Check_Ghost_Function_Call is
+ procedure Check_Ghost_Subprogram_Call is
S : Entity_Id;
begin
- -- The ghost function appears inside an assertion expression
+ -- The ghost subprogram appears inside an assertion expression
if In_Assertion_Expression (N) then
return;
@@ -890,9 +890,9 @@
S := Current_Scope;
while Present (S) and then S /= Standard_Standard loop
- -- The call appears inside another ghost function
+ -- The call appears inside another ghost subprogram
- if Is_Ghost_Function (S) then
+ if Is_Ghost_Subprogram (S) then
return;
end if;
@@ -901,9 +901,9 @@
end if;
Error_Msg_N
- ("call to ghost function must appear in assertion expression or "
- & "another ghost function", N);
- end Check_Ghost_Function_Call;
+ ("call to ghost subprogram must appear in assertion expression or "
+ & "another ghost subprogram", N);
+ end Check_Ghost_Subprogram_Call;
--------------------------------------------------
-- Check_Mixed_Parameter_And_Named_Associations --
@@ -1275,11 +1275,11 @@
End_Interp_List;
end if;
- -- A call to a ghost function is allowed only in assertion expressions,
- -- excluding subtype predicates, or from within another ghost function.
+ -- A call to a ghost subprogram is allowed only in assertion expressions
+ -- excluding subtype predicates or from within another ghost subprogram.
- if Is_Ghost_Function (Get_Subprogram_Entity (N)) then
- Check_Ghost_Function_Call;
+ if Is_Ghost_Subprogram (Get_Subprogram_Entity (N)) then
+ Check_Ghost_Subprogram_Call;
end if;
end Analyze_Call;
===================================================================
@@ -358,7 +358,6 @@
Aspect_External_Name => Aspect_External_Name,
Aspect_External_Tag => Aspect_External_Tag,
Aspect_Favor_Top_Level => Aspect_Favor_Top_Level,
- Aspect_Ghost => Aspect_Ghost,
Aspect_Global => Aspect_Global,
Aspect_Implicit_Dereference => Aspect_Implicit_Dereference,
Aspect_Import => Aspect_Import,
===================================================================
@@ -300,12 +300,14 @@
-- Ada --
---------
- -- Note: all RM defined conventions are treated the same
- -- from the point of view of parameter passing mechanism
+ -- Note: all RM defined conventions are treated the same from
+ -- the point of view of parameter passing mechanism. Convention
+ -- Ghost has the same dynamic semantics as convention Ada.
when Convention_Ada |
Convention_Intrinsic |
Convention_Entry |
+ Convention_Ghost |
Convention_Protected |
Convention_Stubbed =>
@@ -486,7 +488,6 @@
else
Set_Mechanism (Formal, By_Reference);
end if;
-
end case;
end if;
===================================================================
@@ -160,7 +160,6 @@
Aspect_Discard_Names,
Aspect_Export,
Aspect_Favor_Top_Level, -- GNAT
- Aspect_Ghost, -- GNAT
Aspect_Independent,
Aspect_Independent_Components,
Aspect_Import,
@@ -215,7 +214,6 @@
Aspect_Dimension => True,
Aspect_Dimension_System => True,
Aspect_Favor_Top_Level => True,
- Aspect_Ghost => True,
Aspect_Global => True,
Aspect_Inline_Always => True,
Aspect_Invariant => True,
@@ -380,7 +378,6 @@
Aspect_External_Tag => Name_External_Tag,
Aspect_Export => Name_Export,
Aspect_Favor_Top_Level => Name_Favor_Top_Level,
- Aspect_Ghost => Name_Ghost,
Aspect_Global => Name_Global,
Aspect_Implicit_Dereference => Name_Implicit_Dereference,
Aspect_Import => Name_Import,
===================================================================
@@ -6292,26 +6292,51 @@
----------------------
procedure Check_Convention (Op : Entity_Id) is
+ function Convention_Of (Id : Entity_Id) return Convention_Id;
+ -- Given an entity, return its convention. The function treats Ghost
+ -- as convention Ada because the two have the same dynamic semantics.
+
+ -------------------
+ -- Convention_Of --
+ -------------------
+
+ function Convention_Of (Id : Entity_Id) return Convention_Id is
+ Conv : constant Convention_Id := Convention (Id);
+ begin
+ if Conv = Convention_Ghost then
+ return Convention_Ada;
+ else
+ return Conv;
+ end if;
+ end Convention_Of;
+
+ -- Local variables
+
+ Op_Conv : constant Convention_Id := Convention_Of (Op);
+ Iface_Conv : Convention_Id;
Iface_Elmt : Elmt_Id;
Iface_Prim_Elmt : Elmt_Id;
Iface_Prim : Entity_Id;
+ -- Start of processing for Check_Convention
+
begin
Iface_Elmt := First_Elmt (Ifaces_List);
while Present (Iface_Elmt) loop
Iface_Prim_Elmt :=
- First_Elmt (Primitive_Operations (Node (Iface_Elmt)));
+ First_Elmt (Primitive_Operations (Node (Iface_Elmt)));
while Present (Iface_Prim_Elmt) loop
Iface_Prim := Node (Iface_Prim_Elmt);
+ Iface_Conv := Convention_Of (Iface_Prim);
if Is_Interface_Conformant (Typ, Iface_Prim, Op)
- and then Convention (Iface_Prim) /= Convention (Op)
+ and then Iface_Conv /= Op_Conv
then
Error_Msg_N
("inconsistent conventions in primitive operations", Typ);
Error_Msg_Name_1 := Chars (Op);
- Error_Msg_Name_2 := Get_Convention_Name (Convention (Op));
+ Error_Msg_Name_2 := Get_Convention_Name (Op_Conv);
Error_Msg_Sloc := Sloc (Op);
if Comes_From_Source (Op) or else No (Alias (Op)) then
@@ -6331,9 +6356,8 @@
end if;
Error_Msg_Name_1 := Chars (Op);
- Error_Msg_Name_2 :=
- Get_Convention_Name (Convention (Iface_Prim));
- Error_Msg_Sloc := Sloc (Iface_Prim);
+ Error_Msg_Name_2 := Get_Convention_Name (Iface_Conv);
+ Error_Msg_Sloc := Sloc (Iface_Prim);
Error_Msg_N
("\\overridden operation % with " &
"convention % defined #", Typ);
@@ -6829,11 +6853,6 @@
else
Set_Overridden_Operation (Subp, Overridden_Subp);
end if;
-
- -- Ensure that a ghost function is not overriding another routine
-
- elsif Is_Ghost_Function (Subp) then
- Error_Msg_N ("ghost function & cannot be overriding", Subp);
end if;
end if;
@@ -12245,6 +12264,7 @@
if Ekind (Designator) /= E_Procedure
and then Expander_Active
+ -- Check of Assertions_Enabled is certainly wrong ???
and then Assertions_Enabled
then
Func_Typ := Etype (Designator);
@@ -12286,6 +12306,7 @@
-- IN OUT args.
if Expander_Active and then Assertions_Enabled then
+ -- Check of Assertions_Enabled is certainly wrong ???
Formal := First_Formal (Designator);
while Present (Formal) loop
if Ekind (Formal) /= E_In_Parameter
===================================================================
@@ -1163,7 +1163,6 @@
Pragma_Fast_Math |
Pragma_Finalize_Storage_Only |
Pragma_Float_Representation |
- Pragma_Ghost |
Pragma_Global |
Pragma_Ident |
Pragma_Implementation_Defined |
===================================================================
@@ -155,6 +155,7 @@
when Name_COBOL => return Convention_COBOL;
when Name_CPP => return Convention_CPP;
when Name_Fortran => return Convention_Fortran;
+ when Name_Ghost => return Convention_Ghost;
when Name_Intrinsic => return Convention_Intrinsic;
when Name_Java => return Convention_Java;
when Name_Stdcall => return Convention_Stdcall;
@@ -192,6 +193,7 @@
when Convention_CPP => return Name_CPP;
when Convention_Entry => return Name_Entry;
when Convention_Fortran => return Name_Fortran;
+ when Convention_Ghost => return Name_Ghost;
when Convention_Intrinsic => return Name_Intrinsic;
when Convention_Java => return Name_Java;
when Convention_Protected => return Name_Protected;
@@ -293,14 +295,14 @@
exit when Preset_Names (P_Index) = '#';
end loop;
- -- Make sure that number of names in standard table is correct. If
- -- this check fails, run utility program XSNAMES to construct a new
- -- properly matching version of the body.
+ -- Make sure that number of names in standard table is correct. If this
+ -- check fails, run utility program XSNAMES to construct a new properly
+ -- matching version of the body.
pragma Assert (Discard_Name = Last_Predefined_Name);
- -- Initialize the convention identifiers table with the standard
- -- set of synonyms that we recognize for conventions.
+ -- Initialize the convention identifiers table with the standard set of
+ -- synonyms that we recognize for conventions.
Convention_Identifiers.Init;
===================================================================
@@ -499,7 +499,6 @@
Name_Export_Valued_Procedure : constant Name_Id := N + $; -- GNAT
Name_External : constant Name_Id := N + $; -- GNAT
Name_Finalize_Storage_Only : constant Name_Id := N + $; -- GNAT
- Name_Ghost : constant Name_Id := N + $; -- GNAT
Name_Global : constant Name_Id := N + $; -- GNAT
Name_Ident : constant Name_Id := N + $; -- VMS
Name_Implementation_Defined : constant Name_Id := N + $; -- GNAT
@@ -642,6 +641,7 @@
Name_COBOL : constant Name_Id := N + $;
Name_CPP : constant Name_Id := N + $;
Name_Fortran : constant Name_Id := N + $;
+ Name_Ghost : constant Name_Id := N + $;
Name_Intrinsic : constant Name_Id := N + $;
Name_Java : constant Name_Id := N + $;
Name_Stdcall : constant Name_Id := N + $;
@@ -1630,6 +1630,7 @@
Convention_Ada,
Convention_Intrinsic,
Convention_Entry,
+ Convention_Ghost,
Convention_Protected,
Convention_Stubbed,
@@ -1795,7 +1796,6 @@
Pragma_Export_Valued_Procedure,
Pragma_External,
Pragma_Finalize_Storage_Only,
- Pragma_Ghost,
Pragma_Global,
Pragma_Ident,
Pragma_Implementation_Defined,