-- --
-- B o d y --
-- --
--- Copyright (C) 1992-2004 Free Software Foundation, Inc. --
+-- Copyright (C) 1992-2007, Free Software Foundation, Inc. --
-- --
-- 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- --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING. If not, write --
--- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
--- MA 02111-1307, USA. --
+-- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
+-- Boston, MA 02110-1301, USA. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
with Atree; use Atree;
with Casing; use Casing;
+with Debug; use Debug;
with Einfo; use Einfo;
with Errout; use Errout;
with Exp_Ch11; use Exp_Ch11;
with Nlists; use Nlists;
with Nmake; use Nmake;
with Opt; use Opt;
+with Restrict; use Restrict;
+with Rident; use Rident;
with Rtsfind; use Rtsfind;
with Sem; use Sem;
with Sem_Eval; use Sem_Eval;
procedure Expand_Pragma_Abort_Defer (N : Node_Id);
procedure Expand_Pragma_Assert (N : Node_Id);
procedure Expand_Pragma_Common_Object (N : Node_Id);
- procedure Expand_Pragma_Import (N : Node_Id);
+ procedure Expand_Pragma_Import_Or_Interface (N : Node_Id);
procedure Expand_Pragma_Import_Export_Exception (N : Node_Id);
procedure Expand_Pragma_Inspection_Point (N : Node_Id);
procedure Expand_Pragma_Interrupt_Priority (N : Node_Id);
Expand_Pragma_Import_Export_Exception (N);
when Pragma_Import =>
- Expand_Pragma_Import (N);
+ Expand_Pragma_Import_Or_Interface (N);
when Pragma_Import_Exception =>
Expand_Pragma_Import_Export_Exception (N);
when Pragma_Inspection_Point =>
Expand_Pragma_Inspection_Point (N);
+ when Pragma_Interface =>
+ Expand_Pragma_Import_Or_Interface (N);
+
when Pragma_Interrupt_Priority =>
Expand_Pragma_Interrupt_Priority (N);
-- Since assertions are on, we rewrite the pragma with its
-- corresponding if statement, and then analyze the statement
- -- The expansion transforms:
+ -- The normal case expansion transforms:
-- pragma Assert (condition [,message]);
-- where Str is the message if one is present, or the default of
-- file:line if no message is given.
- -- First, we need to prepare the character literal
+ -- An alternative expansion is used when the No_Exception_Propagation
+ -- restriction is active and there is a local Assert_Failure handler.
+ -- This is not a common combination of circumstances, but it occurs in
+ -- the context of Aunit and the zero footprint profile. In this case we
+ -- generate:
- if Present (Arg2 (N)) then
- Msg := Strval (Expr_Value_S (Arg2 (N)));
- else
- Build_Location_String (Loc);
- Msg := String_From_Name_Buffer;
- end if;
+ -- if not condition then
+ -- raise Assert_Failure;
+ -- end if;
+
+ -- This will then be transformed into a goto, and the local handler will
+ -- be able to handle the assert error (which would not be the case if a
+ -- call is made to the Raise_Assert_Failure procedure).
- -- Now generate the if statement. Note that we consider this to be
- -- an explicit conditional in the source, not an implicit if, so we
+ -- Note that the reason we do not always generate a direct raise is that
+ -- the form in which the procedure is called allows for more efficient
+ -- breakpointing of assertion errors.
+
+ -- Generate the appropriate if statement. Note that we consider this to
+ -- be an explicit conditional in the source, not an implicit if, so we
-- do not call Make_Implicit_If_Statement.
- Rewrite (N,
- Make_If_Statement (Loc,
- Condition =>
- Make_Op_Not (Loc,
- Right_Opnd => Cond),
- Then_Statements => New_List (
- Make_Procedure_Call_Statement (Loc,
- Name =>
- New_Reference_To (RTE (RE_Raise_Assert_Failure), Loc),
- Parameter_Associations => New_List (
- Make_String_Literal (Loc, Msg))))));
+ -- Case where we generate a direct raise
+
+ if (Debug_Flag_Dot_G
+ or else Restriction_Active (No_Exception_Propagation))
+ and then Present (Find_Local_Handler (RTE (RE_Assert_Failure), N))
+ then
+ Rewrite (N,
+ Make_If_Statement (Loc,
+ Condition =>
+ Make_Op_Not (Loc,
+ Right_Opnd => Cond),
+ Then_Statements => New_List (
+ Make_Raise_Statement (Loc,
+ Name =>
+ New_Reference_To (RTE (RE_Assert_Failure), Loc)))));
+
+ -- Case where we call the procedure
+
+ else
+ -- First, we need to prepare the string literal
+
+ if Present (Arg2 (N)) then
+ Msg := Strval (Expr_Value_S (Arg2 (N)));
+ else
+ Build_Location_String (Loc);
+ Msg := String_From_Name_Buffer;
+ end if;
+
+ -- Now rewrite as an if statement
+
+ Rewrite (N,
+ Make_If_Statement (Loc,
+ Condition =>
+ Make_Op_Not (Loc,
+ Right_Opnd => Cond),
+ Then_Statements => New_List (
+ Make_Procedure_Call_Statement (Loc,
+ Name =>
+ New_Reference_To (RTE (RE_Raise_Assert_Failure), Loc),
+ Parameter_Associations => New_List (
+ Make_String_Literal (Loc, Msg))))));
+ end if;
Analyze (N);
if Nkind (N) = N_Procedure_Call_Statement
and then Is_RTE (Entity (Name (N)), RE_Raise_Assert_Failure)
then
- -- If original condition was a Standard.False, we assume
- -- that this is indeed intented to raise assert error
- -- and no warning is required.
+ -- If original condition was a Standard.False, we assume that this is
+ -- indeed intented to raise assert error and no warning is required.
if Is_Entity_Name (Original_Node (Cond))
and then Entity (Original_Node (Cond)) = Standard_False
-- Expand_Pragma_Common_Object --
---------------------------------
- -- Add series of pragmas to replicate semantic effect in DEC Ada
+ -- Use a machine attribute to replicate semantic effect in DEC Ada
- -- pragma Linker_Section (internal_name, external_name);
- -- pragma Machine_Attribute (internal_name, "overlaid");
- -- pragma Machine_Attribute (internal_name, "global");
- -- pragma Machine_Attribute (internal_name, "initialize");
+ -- pragma Machine_Attribute (intern_name, "common_object", extern_name);
-- For now we do nothing with the size attribute ???
- -- Really this expansion would be much better in the back end. The
- -- front end should not need to know about target dependent, back end
- -- dependent semantics ???
-
procedure Expand_Pragma_Common_Object (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Ploc := Sloc (Psect);
- -- Insert pragmas
-
- Insert_List_After_And_Analyze (N, New_List (
-
- -- The Linker_Section pragma ensures the correct section
-
- Make_Pragma (Loc,
- Chars => Name_Linker_Section,
- Pragma_Argument_Associations => New_List (
- Make_Pragma_Argument_Association (Iloc,
- Expression => New_Copy_Tree (Internal)),
- Make_Pragma_Argument_Association (Ploc,
- Expression => New_Copy_Tree (Psect)))),
-
- -- Machine_Attribute "overlaid" ensures that this section
- -- overlays any other sections of the same name.
-
- Make_Pragma (Loc,
- Chars => Name_Machine_Attribute,
- Pragma_Argument_Associations => New_List (
- Make_Pragma_Argument_Association (Iloc,
- Expression => New_Copy_Tree (Internal)),
- Make_Pragma_Argument_Association (Eloc,
- Expression =>
- Make_String_Literal (Sloc => Ploc,
- Strval => "overlaid")))),
+ -- Insert the pragma
- -- Machine_Attribute "global" ensures that section is visible
+ Insert_After_And_Analyze (N,
Make_Pragma (Loc,
Chars => Name_Machine_Attribute,
Make_Pragma_Argument_Association (Eloc,
Expression =>
Make_String_Literal (Sloc => Ploc,
- Strval => "global")))),
-
- -- Machine_Attribute "initialize" ensures section is demand zeroed
+ Strval => "common_object")),
+ Make_Pragma_Argument_Association (Ploc,
+ Expression => New_Copy_Tree (Psect)))));
- Make_Pragma (Loc,
- Chars => Name_Machine_Attribute,
- Pragma_Argument_Associations => New_List (
- Make_Pragma_Argument_Association (Iloc,
- Expression => New_Copy_Tree (Internal)),
- Make_Pragma_Argument_Association (Eloc,
- Expression =>
- Make_String_Literal (Sloc => Ploc,
- Strval => "initialize"))))));
end Expand_Pragma_Common_Object;
- --------------------------
- -- Expand_Pragma_Import --
- --------------------------
+ ---------------------------------------
+ -- Expand_Pragma_Import_Or_Interface --
+ ---------------------------------------
-- When applied to a variable, the default initialization must not be
-- done. As it is already done when the pragma is found, we just get rid
-- have to elaborate the initialization expression when it is first
-- seen (i.e. this elaboration cannot be deferred to the freeze point).
- procedure Expand_Pragma_Import (N : Node_Id) is
+ procedure Expand_Pragma_Import_Or_Interface (N : Node_Id) is
Def_Id : constant Entity_Id := Entity (Arg2 (N));
Typ : Entity_Id;
Init_Call : Node_Id;
if Ekind (Def_Id) = E_Variable then
Typ := Etype (Def_Id);
- -- Loop to ???
+ -- Iterate from declaration of object to import pragma, to find
+ -- generated initialization call for object, if any.
Init_Call := Next (Parent (Def_Id));
while Present (Init_Call) and then Init_Call /= N loop
-- have explicit initialization, so the expression must have
-- been generated by the compiler.
- if No (Init_Call)
+ if Init_Call = N
and then Present (Expression (Parent (Def_Id)))
then
Set_Expression (Parent (Def_Id), Empty);
end if;
end if;
- end Expand_Pragma_Import;
+ end Expand_Pragma_Import_Or_Interface;
-------------------------------------------
-- Expand_Pragma_Import_Export_Exception --
Rewrite (Expression (Lang1),
Make_Character_Literal (Loc,
Chars => Name_uV,
- Char_Literal_Value => Get_Char_Code ('V')));
+ Char_Literal_Value =>
+ UI_From_Int (Character'Pos ('V'))));
Analyze (Expression (Lang1));
Rewrite (Expression (Lang2),
Make_Character_Literal (Loc,
Chars => Name_uM,
- Char_Literal_Value => Get_Char_Code ('M')));
+ Char_Literal_Value =>
+ UI_From_Int (Character'Pos ('M'))));
Analyze (Expression (Lang2));
Rewrite (Expression (Lang3),
Make_Character_Literal (Loc,
Chars => Name_uS,
- Char_Literal_Value => Get_Char_Code ('S')));
+ Char_Literal_Value =>
+ UI_From_Int (Character'Pos ('S'))));
Analyze (Expression (Lang3));
if Exception_Code (Id) /= No_Uint then
Analyze (Call);
end if;
- if not Present (Interface_Name (Id)) then
+ if No (Interface_Name (Id)) then
Set_Interface_Name (Id,
Make_String_Literal
(Sloc => Loc,