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] | |
Tested on i686-linux, committed on trunk
Within an instance, the primitive operations of a formal derived type are
those of the actual. To obtain the proper visibility, we iterate over the
primitive operations of the formal and generate renaming declarations that
are visible in the instance. In Ada95 the operations are those of the parent
type in the formal derived type declaration. In Ada2005 the declaration may
include an interface list, and the operations inherited through the progenitors
must also be taken into account.
Also, instances bodies can generate public symbols that are visible to the
linker.
These symbols must have external names that are consistent between the point
at which they are generated for the context of another unit, and the point at
which they are generated when they appear in the current unit. Previously
package Instance bodies were only generated when appearing in the main unit.
or as needed for front-end inlining.
The consistency problem described above requires that whenever a body is
analyzed in order to provide a nested generic for an instantiation, all bodies
of instances appearing before the required generic must be compiled as well.
The procedure Collect_Previous_Instances traverses the current compilation unit
up to the generic being sought, and instantiates the corresponding bodies if
they are available.
The following must compile quietly:
gnatmake -f r2.adb
with P2;
procedure R2 is begin null; end;
with Instances2;
package P2 is
procedure Local_Proc is new Instances2.Wrapper.Itwo.Gproc;
end;
with Gpack;
package Instances2 is
package Ione is new Gpack;
package Wrapper is
package Itwo is new Gpack;
end;
end;
generic
package Gpack is
generic procedure Gproc;
end;
package body Gpack is
function Matrix_Size return Positive is
begin
return 1;
end;
subtype Index_T is Integer range 1 .. Matrix_Size;
M : array (Index_T, Index_T) of Natural;-- := (others => (others => 0));
I : Integer := Index_T'First;
procedure Gproc is
begin
M (1, 1) := 0;
end;
end;
--
An instantiation of a generic package or a generic subprogram is equivalent
to a copy of the generic's declaration and body at the place of
instantiation. In particular, the context clause of the compilation unit
containing the body must be appended to that of the unit containing the
instantiation. Among other consequences, this constrains the order of
elaboration (the spec of any unit with'd by a generic body must be
elaborated before any unit instantiating the generic).
The calls to Inherit_Context that perform this context clause copy was
inhibited by a guard that had become invalid as a result of a change in the
semantics of the Generic_Separately_Compiled predicate. This change removes
the guard so that context clauses are correctly copied again.
When compiling the following code with -gnatG, a with_clause for package
Dep must appear in the expanded tree for Inst's body.
$ gcc -c -gnatG inst.ads
package Dep is
end Dep;
with Dep;
package body Gen is end Gen;
generic package Gen is
pragma Elaborate_Body;
end Gen;
with Gen;
package Inst is new Gen;
2007-08-14 Ed Schonberg <schonberg@adacore.com>
Gary Dismukes <dismukes@adacore.com>
Thomas Quinot <quinot@adacore.com>
* sem_ch12.ads, sem_ch12.adb (Instantiate_Type): If the formal is a
derived type with interface progenitors use the analyzed formal as the
parent of the actual, to create renamings for all the inherited
operations in Derive_Subprograms.
(Collect_Previous_Instances): new procedure within of
Load_Parent_Of_Generic, to instantiate all bodies in the compilation
unit being loaded, to ensure that the generation of global symbols is
consistent in different compilation modes.
(Is_Tagged_Ancestor): New function testing the ancestor relation that
takes progenitor types into account.
(Validate_Derived_Type_Instance): Enforce the rule of 3.9.3(9) by
traversing over the primitives of the formal and actual types to locate
any abstract subprograms of the actual type that correspond to a
nonabstract subprogram of the formal type's ancestor type(s), and issue
an error if such is found.
(Analyze_Package_Instantiation, Analyze_Subprogram_Instantiation,
Instantiate_Package_Body, Instantiate_Subprogram_Body):
Remove bogus guard around calls to Inherit_Context.
(Reset_Entity): If the entity is the selector of a selected component
that denotes a named number, propagate constant-folding to the generic
template only if the named number is global to the generic unit.
(Set_Instance_Env): Only reset the compilation switches when compiling
a predefined or internal unit.
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] |