This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] fix handling of Assert pragma in No_Exception_Propagation mode


Tested on i686-linux, committed on trunk

In the context of the No_Exception_Propagation pragma, we need to expand
pragma Assert differently, so that proper gotos are generated instead of
calls to System.Assertions.Raise_Assert_Failure.

In cases where a package spec file does not allow a body (for
example when the package spec is a package renaming), it is now
possible to provide a dummy body file that contains only comments
and a No_Body pragma. This is recognized as indicating that no
body is present. This is useful in system maintenance when a real
body is eliminated.

The implementation has two parts. First if a spec is being
compiled that does not permit a body, the circuit in gnat1drv
that gives an error if the body is present is disabled if the
body contains a No_Body pragma.

Second, a new procedure in Lib_Load is used when compiling a
body that turns out to have a No_Body pragma. In this case
the procedure Lib_Load.Change_Main_Unit_To_Spec switches the
view to the spec, so that for the rest of the compilation the
spec is compiled and the body is ignored.

A new function Sinput.Source_File_Is_No_Body supports testing
a file to see if it contains a No_Body pragma and nothing else.

Consider the test program:

spec file p.ads contains:

package p is
   type q is array (0 .. 19) of Boolean;
   pragma Pack (q);
end p;

body file p.adb contains

pragma No_Body;

Now compiling either the spec or the body file
is successful with no errors and has the same
effect of compiling the spec only.

--
pragma Explicit_Overring was from an intermediate version of Ada 2005. It
was never fully implemented, and has now been removed from Ada 2005.

     1. package q is
     2.    pragma Explicit_Overriding;
           |
        >>> warning: unrecognized pragma "explicit_overriding"

     3. end q;

Similarly, remove the pragma Optional_Overriding.

Also add a CIL convention to support the .NET platform,
similar to the Java convention for the JVM.

Types that are specified with a pragma Import with C++ convention or
with pragma CPP_Class are implicitly marked as limited types by the
front end. This can result in potentially confusing error messages
related to limitedness of the type, such as when attempting to implement
a nonlimited interface with such a type. The compiler now issues a warning
telling the user that the type should be declared as limited and that the
compiler will implicitly treat the type as limited. This is a warning
rather than an error to avoid incompatibilities with existing code that
uses these pragmas.

The following test should report these warnings and errors when compiled
with -gnat05:

cpp_class_warning.ads:10:32: warning: imported CPP type should be explicitly declared limited
cpp_class_warning.ads:10:32: warning: type will be considered limited
cpp_class_warning.ads:12:04: progenitor interface "Intface" of limited type must be limited
cpp_class_warning.ads:20:22: warning: imported CPP type should be explicitly declared limited
cpp_class_warning.ads:20:22: warning: type will be considered limited
cpp_class_warning.ads:22:04: progenitor interface "Intface" of limited type must be limited

package CPP_Class_Warning is

   type Intface is interface;

   type Ltd_Intface is limited interface;

   type TT is tagged record
      N : Natural;
   end record;
   pragma Import (C_Plus_Plus, TT);

   type New_TT is new TT and Ltd_Intface and Intface with record
      S : String (1 .. 30);
   end record;
   pragma Import (C_Plus_Plus, New_TT);

   type TT2 is tagged record
      N : Natural;
   end record;
   pragma CPP_Class (TT2);

   type New_TT2 is new TT2 and Intface and Ltd_Intface with record
      S : String (1 .. 30);
   end record;
   pragma CPP_Class (New_TT2);

end CPP_Class_Warning;

This patch identifies Ada 2005 attributes and pragmas, and ensures
that these are correctly flagged in Ada 95 mode as violation the
No_Implementation_Pragmas/Attributes restriction, as shown by the
following test compiled in Ada 95 mode:

     1. pragma Restrictions (No_Implementation_Pragmas);
     2. pragma Restrictions (No_Implementation_Attributes);
     3. pragma Assertion_Policy (Check);
        |
        >>> violation of restriction
            "No_Implementation_Pragmas" at line 1

     4. procedure Main is
     5.    Q : Integer := Integer'Stream_Size;
                                 |
        >>> violation of restriction
            "No_Implementation_Attributes" at line 2

     6.    type R is new Short_Short_Integer;
     7.    for R'Stream_Size use 16;
           |
        >>> violation of restriction
            "No_Implementation_Attributes" at line 2

     8. begin
     9.    null;
    10. end;

This test compiles silently in Ada 2005 mode

2007-06-06  Ed Schonberg  <schonberg@adacore.com>
	    Arnaud Charlet  <charlet@adacore.com>
	    Robert Dewar  <dewar@adacore.com>
	    Gary Dismukes  <dismukes@adacore.com>

	* exp_prag.adb (Expand_Pragma_Import_Or_Interface): Remove properly a
	default initialization on an imported object, when there is no
	initialization call generated for it.
	(Expand_Pragma_Assert): Add handling of No_Exception_Propagation
	restriction

	* snames.h, snames.ads, snames.adb, par-prag.adb: New pragma
	Static_Elaboration_Desired.
	Remove pragma Thread_Body.
	Implement a new pragma No_Body
	Removes the Explicit_Overriding pragma
	Remove Optional_Overriding pragma
	(Prag): Deal with Universal_Aliasing.
	(Name_CIL, Name_CIL_Constructor, Convention_CIL,
	Pragma_CIL_Constructor): New names.

	* sem_cat.adb (Validate_Object_Declaration): An initialization that
	uses the equivalent aggregate of a type must be treated as an implicit
	initialization.
	(Get_Categorization): Check a unit for pragma Preelaborate only if it
	has none of the other categories.
	(Process_Import_Or_Interface_Pragma): Report an error for an attempt
	to apply Import to an object renaming declaration.

	* sem_prag.adb (Process_Import_Or_Interface): Warn that a type imported
	from a C++ class should be declared as limited and that it will be
	considererd limited.
	(Analyze_Pragma): Warn that a type specified with pragma CPP_Class
	should be declared as limited and that it will be considererd limited.
	(Ada_2005_Pragma): New procedure, used to deal with Ada 2005 pragmas
	(Analyze_Pragma, case Export): Diagnose export of enumeration literal
	(Analyze_Pragma): Deal with Universal_Aliasing.
	(Sig_Flags): Likewise.
	(Set_Encoded_Interface_Name): Suppress encoding when compiling for AAMP.
	(Overflow_Checks_Unsuppressed): New flag.
	(Process_Suppress_Unsuppress): Set Overflow_Checks_Unsuppressed.
	(Analyze_Pragma [case Pack]): Ignore pragma Pack and post warning in
	case of JVM or .NET targets, and compiling user code.
	Add debugging convenience routine rv

Attachment: difs
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]