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 bugs in visibility and scopes


Tested on i686-linux, committed on HEAD

The scope of an anonymous access function result should be set to the
scope enclosing the function declaration (as per AI-318-02), however
it was being set to the function's scope rather than its parent scope
in the case of a function with parameters. This was due to the function
scope becoming the current scope during analysis of the formal part,
which includes calling Analyze_Return during Process_Formals. In the
case of parameterless functions the scope was being set properly. Now
we set the scope of an anonymous access result type to the scope of
the function associated with Related_Nod in function Access_Definition.
The incorrect setting of the scope resulted in accessibility level
errors being flagged on legal conversions involving calls to functions
returning anonymous access results.
The following test case must compile quietly:

procedure Anon_Access_Conversion is

   package Pkg_1 is
      type Root_Interface is interface;
      type Descendant_1 is abstract new Root_Interface
        with null record;
      function Root_Class_Func (I : Integer)
        return access Root_Interface'Class;
   end Pkg_1;

   package Pkg_2 is
      type Descendant_2 is new Pkg_1.Descendant_1
        with null record;
   end Pkg_2;

   package Pkg_3 is
      type Descendant_3 is abstract new Pkg_2.Descendant_2
        with null record;
      type D3_Acc is access all Descendant_3'Class;
   end Pkg_3;

   package body Pkg_1 is
      function Root_Class_Func (I : Integer)
        return access Root_Interface'Class
      is
      begin
         return null;
      end Root_Class_Func;
   end Pkg_1;

   package body Pkg_2 is
      function Func_D3 return access Pkg_3.Descendant_3'Class is
      begin
         return Pkg_3.D3_Acc (Pkg_1.Root_Class_Func (123));
                -- Legal conversion
      end Func_D3;
   end Pkg_2;

begin
   null;
end Anon_Access_Conversion;

Secondly, when a the full view of an incomplete or private type is analyzed, we
reexamine various entities whose properties may depend on those of the
full type (subtypes, operations that may be primitive in the type, etc).
If a protected operation has an access parameter whose designated type
is incomplete (and whose full view is tagged), it may appear in the list
of its dependents, but is never a dispatching operation, and no code
should be generated to place it in the dispatching table.
The following must compile quietly:

 package P is
    type T;
    protected Obj is
       procedure Change (X : access T);
    end Obj;
    type T is tagged null record;
 end P;

 package body P is
    protected body Obj is
       procedure Change (X : access T) is begin null; end;
    end Obj;
 end P;

Finally, this change ensures that whether or not constant mutable private
records objects have visible discriminants, they will be treated the same. In
particular, when they are initialized by a function call, the function is
called only once, its result is put in a temporary of the maximum size and
the constant object directly points to this temp.

2005-09-01  Cyrille Comar  <comar@adacore.com>
	    Gary Dismukes  <dismukes@adacore.com>
	    Ed Schonberg  <schonberg@adacore.com>
	    Javier Miranda  <miranda@adacore.com>

	* sem_ch3.ads, sem_ch3.adb (Analyze_Object_Declaration): Go to the
	underlying type
	to check if a type is Constrained in cases related to code generation
	(rather than semantic checking) since otherwise we do not generate
	similar code for mutable private types depending if their
	discriminants are visible or not.
	(Check_Abstract_Overriding): Do not complain about failure to override
	the primitive operations used in dispatching selects since they will
	always be overriden at the freeze point of the type.
	(Access_Definition): Separate out handling for resetting the scope
	of an anonymous access function result type. Retrieve the scope
	of the associated function rather than using Current_Scope, which
	does not have a consistent value (depends on whether we're in the
	middle of analyzing formal parameters). Add ??? comment about
	finding a cleaner way to handle the special cases of scope setting.
	(Process_Incomplete_Dependents): A protected operation is never a
	dispatching operation (only its wrapper may be).
	(Build_Derived_Record_Type): In case of tagged private types that
	implement interfaces add derivation of predefined primitive
	operations.
	(Derive_Subprograms): Replace the Is_Interface_Derivation parameter
	by two parameters that are used in case of derivation from abstract
	interface types: No_Predefined_Prims is used to avoid the derivation
	of predefined primitives from the interface, and Predefined
	Prims_Only is used to complete the derivation predefined primitives
	in case of private tagged types implementing interfaces.
	Fix typo in comments
	(Find_Interface_In_Descendant): Protect the frontend against
	wrong code with large circularity chains.
	(Is_Private_Overriding): Add support for entities overriding interface
	subprograms. The test failed because Entities associated with overriden
	interface subprograms are always marked as hidden (and used to build
	the secondary dispatch table); in this case the overriden entity is
	available through the field abstract_interface_alias (cf. override_
	dispatching_operation)
	(Access_Definition): Set the scope of the type to Current_Scope for the
	case of a function with an anonymous access result type.
	(Access_Subprogram_Declaration): Handle creation of the type entity for
	an access-to-function type with an anonymous access result.
	(Check_Anonymous_Access_Types): Change Subtype_Mark to Result_Definition
	in handling for N_Access_Function_Definition.
	(Analyze_Subtype_Declaration): Modify the text of error message.
	(Derived_Type_Declaration): Modify the text of error message.
	(Process_Subtype): Modify the text of error message plus cleanup
	of one redundant error message.
	(Analyze_Component_Declaration): Code cleanup.
	(Analyze_Object_Declaration): Code cleanup.
	(Analyze_Subtype_Declaration): Propagate the null-exclusion
	attribute in case of access types. Code cleanup.
	(Array_Type_Declaration): Code cleanup.
	(Process_Discriminants): Create the new null-excluding itype
	if required. Code cleanup.
	(Process_Subtype): Create the new null-excluding itype if
	required. Code cleanup.
	(Build_Derived_Record_Type): Code cleanup to avoid calling
	twice the subprogram derive_subprograms in case of private
	types that implement interfaces. In this particular case the
	subprogram Complete_Subprograms_Derivation already does the
	job associated with the second call.

        * exp_strm.adb (Build_Elementary_Input_Call): Add an explicit
        conversion to the full view when generating an operation for a
        discriminant whose type may currently be private.

Attachment: difs.35
Description: Text document


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