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
For each actual type in an instantiation we create a subtype declaration
that serves as a renaming of the formal in the body of the instance. Some
of the attributes of the actual (in particular size and alignment values)
must be transferred explicitly to the renaming, because they are not
captured by the analysis of the subtype declaration. If the formal is
a constrained array, these values must be obtained from the first subtype
of the actual (i.e. the actual itself) and not from its base type, because
the (anonymous) base is unconstrained and carries no size information.
The following instantiation must compile quietly:
--
package A is
C_Width : constant := 140/4;
type Index is (One, Two, Three, Four);
type Line is private;
type ARR_4 is private;
private
type Line is new String(1..C_Width);
type ARR_4 is array(Index) of Line;
for ARR_4'size use 140*8;
end A;
--
package Gen is
generic
type Item_Type is private;
procedure Priv;
end Gen;
--
package body Gen is
procedure Priv is
begin
null;
end Priv;
end Gen;
--
with a;
with gen;
procedure inst is new gen.priv (a.arr_4);
--
In Ada 2005, a generic formal object of mode in can have a limited type, and
is allowed to be initialized by aggregates and function calls. However other
forms of intialization expressions are illegal, and so legality checks are
added to enforce that for both default and actual expressions.
The following test must issue this error output when compiled with
gcc -c -gnat05 limited_formal_bug.ads:
limited_formal_bug.ads:11:21: initialization not allowed for limited types
limited_formal_bug.ads:16:28: initialization not allowed for limited types
package Limited_Formal_Bug is
type LR is limited record
I : Integer;
end record;
X : LR;
generic
F1 : in LR := X; -- Error
F2 : in LR := (I => 123); -- OK
package GP is
end;
package NGP1 is new GP (X); -- Error
package NGP2 is new GP ((I => 456)); -- OK
end Limited_Formal_Bug;
--
A formal package is handled somewhat like an instantiation, to match the
given actuals to the formals of the generic package. As a result, fatal
errors during parameter matching will raise Instantiation_Error, which
must be handled locally to allow for semantic analysis to continue.
Compiling package g2.ads must yield:
--
g2.ads:5:31: "T" is not visible
g2.ads:5:31: non-visible declaration at g1.ads:2
--
generic
type T is private;
package G1 is
end G1;
--
with G1;
generic
type T2 is private;
with package P2 is new G1 (T);
package G2 is
end G2;
2007-04-06 Ed Schonberg <schonberg@adacore.com>
Gary Dismukes <dismukes@adacore.com>
* sem_ch12.adb (Check_Generic_Actuals): Use first subtype of actual
when capturing size information, instead of base type, which for a
formal array type will be the unconstrained type.
(Analyze_Formal_Object_Declaration): Add check for illegal default
expressions for a formal in object of a limited type.
(Instantiate_Object): Ditto.
(Check_Formal_Package_Instance): Skip entities that are formal objects,
because they were defaulted in the formal package and no check applies
to them.
(Check_Formal_Package_Instance): Extend conformance check to other
discrete types beyond Integer.
(Process_Default): Copy directly the unmatched formal. A generic copy
has already been performed in Analyze_Formal_Package.
(Analyze_Associations): If a formal subprogram has no match, check for
partial parametrization before looking for a default, to prevent
spurious errors.
(Analyze_Package_Instantiation, Analyze_Subprogram_Instantiation): Do
not set the instantiation environment before analyzing the actuals.
Fixes regression on 8515-003 with implementation of AI-133.
Set_Instance_Env checks whether the generic unit is a predefined
unit, in which case the instance must be analyzed with the latest Ada
mode. This setting must take place after analysis of the actuals,
because the actuals must be analyzed and frozen in the Ada mode extant
outside of the current instantiation.
(Save_Env, Restore_Env): Preserve and restore the configuration
parameters so that predefined units can be compiled in the proper Ada
mode.
(Analyze_Formal_Object_Declaration,Analyze_Formal_Subprogram,
Instantiate_Type): Split Is_Abstract flag into Is_Abstract_Subprogram
and Is_Abstract_Type.
(Analyze_Formal_Package): For better error recovery, Add exception
handler to catch Instantion_Error, which can be raised in
Analyze_Associations
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] |