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] other improvements in handling of attributes


Tested on i686-linux, committed on trunk

Add useful additional information, as shown by this example:

     1. package r is
     2.    type aa is access procedure;
     3.    type ac is access procedure;
     4.    pragma Convention (C, ac);
     5.    type ad is access procedure;
     6.
     7.    procedure a;
     8.    pragma Import (C, a);
     9.
    10.    procedure c;
    11.    pragma Import (C, c);
    12.
    13.    procedure d;
    14.
    15.    va : aa := a'access;
                      |
        >>> subprogram "a" has wrong convention
        >>> does not match convention of access type "aa"
        >>> probable missing pragma Convention for "aa"

    16.    vc : ac := c'access;
    17.    vd : ad := d'access;
    18. end;

--
There was a missing legality check for the attribute Tag. Like most other
attributes, its prefix cannot be an incomplete type. In particular, it cannot
be the limited view of a type.

Compilation of impl.adb must be rejected with the message:

impl.adb:9:52: prefix of "Tag" attribute cannot be an incomplete type

package E is
   type Event is limited interface;
end E;

limited with E;
package Impl is
   function Event
    (Ptr: not null access E.Event'Class) return Standard.Boolean;
end;

with Ada.Text_IO;
with Ada.Tags;
package body Impl is
   function Event
    (Ptr : not null access E.Event'Class)
       return Standard.Boolean
   is
   begin
      Ada.Text_IO.Put_Line (Ada.Tags.External_Tag (Ptr.all'Tag));
      return True;
   end Event;
end Impl;

When an object is declared with an unconstrained nominal subtype, and obtains
its constraint from an initial expression, the subtype obtained from that
expression is marked Is_Constr_Subt_For_U_Nominal, so that in appropriate places
conformance checks are applied to the base type appearing in the source, rather
than to the computed subtype. The 'access attribute is one such place. The code
incorrectly retrieved the Etype of the prefix type that was so marked. This is
correct when the flag is applied to a subtype, but is incorrect if the type of
the prefix is a private derived type with unknown discriminants, because the
Etype in that case designates the parent type. The base_type is the proper
operation to use in all cases.

gnat.dg/show_deques_priority.adb must compile quietly.

This patch also fixes two problems relating to current value optimization.
First, unrestricted_access must set address_taken, since it behaves
the same as 'address from this point of view, and we might as well
set this flag for any access attribute.

Second, we inhibit current value tracking if the address
is taken. This is a little bit of overkill, but seems
reasonable, better safe than sorry here, and there are
cases of function calls etc where we were doing the
wrong thing.

A test program is:

with System; use System;
procedure g is
   x : integer := 1;
   y : address := x'Address;
   type L is access integer;
   x1 : integer := 1;
   LL : L := x1'Unrestricted_Access;
begin
   x := x + 1;
   x := 2;
   x := x + 1;
   x1 := x1 + 1;
   x1 := 4;
   x1 := x1 + 1;
end;

Compiled with -gnatG, this should generate:
	
Source recreated from tree for g (body)
---------------------------------------

with system;
use system;
with system;

procedure g is
   x : integer := 1;
   y : system__address := x'address;
   type g__l is access integer;
   x1 : integer := 1;
   ll : g__l := x1'unrestricted_access;
begin
   x := x + 1;
   x := 2;
   x := x + 1;
   x1 := x1 + 1;
   x1 := 4;
   x1 := x1 + 1;
   return;
end g;

2007-06-06  Hristian Kirtchev  <kirtchev@adacore.com>
	    Robert Dewar  <dewar@adacore.com>
	    Ed Schonberg  <schonberg@adacore.com>
	    Gary Dismukes  <dismukes@adacore.com>

	* exp_ch2.adb: Remove "with" and "use" clauses for Namet and Snames.
	Add "with" and "use" clauses for Sem_Attr.
	(Expand_Current_Value): Do not replace occurences of attribute
	references where the prefix must be a simple name.

	* sem_attr.ads, sem_attr.adb: Remove "with" and "use" clauses for
	Namet. Add new arrays Attribute_Name_Modifies_Prefix and
	Attribute_Requires_Simple_Name_Prefix.
	(Name_Modifies_Prefix): Body of new function.
	(Requires_Simple_Name_Prefix): Body of new function.
	(Resolve_Attribute, case Access): Improve error message for case of
	mismatched conventions.
	(Analyze_Attribute, case 'Tag): The prefix the attribute cannot be of an
	incomplete type.
	(Analyze_Attribute, case 'Access): If the type of the prefix is a
	constrained subtype for a nominal unconstrained type, use its base type
	to check for conformance with the context.
	(Resolve_Attribute): Remove test of the access type being associated
	with a return statement from condition for performing accessibility
	checks on access attributes, since this case is now captured by
	Is_Local_Anonymous_Access.
	(Analyze_Access_Attribute): Set Address_Taken on entity
	(Analyze_Attribute, case Address): Set Address_Taken on entity
	(OK_Self_Reference): Traverse tree to locate enclosing aggregate when
	validating an access attribute whose prefix is a current instance.
	(Resolve_Attribute): In case of attributes 'Code_Address and 'Address
	applied to dispatching operations, if freezing is required then we set
	the attribute Has_Delayed_Freeze in the prefix's entity.
	(Check_Local_Access): Set flag Suppress_Value_Tracking_On_Call in
	current scope if access of local subprogram taken
	(Analyze_Access_Attribute): Check legality of self-reference even if the
	expression comes from source, as when a single component association in
	an aggregate has a box association.
	(Resolve_Attribute, case 'Access): Do not apply accessibility checks to
	the prefix if it is a protected operation and the attribute is
	Unrestricted_Access.
	(Resolve_Attribute, case 'Access): Set the Etype of the attribute
	reference to the base type of the context, to force a constraint check
	when the context is an access subtype with an explicit constraint.
	(Analyze_Attribute, case 'Class): If the prefix is an interface and the
	node is rewritten as an interface conversion. leave unanalyzed after
	resolution, to ensure that type checking against the context will take
	place.

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]