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 x86-linux, committed on mainline. A bunch of changes related to Ada 2005 features: The switch -gnatwj is supposed to warn on uses of Annex J features. One obscure case (the use of the Constrained attribute on private types) had been accidentally omitted. Implement the new Ada 2005 attribute Mod, which applies to any modular type, and takes one argument of any integer type. The result is the argument value mod the modulus value of the modular type. This allows easier mixing of signed and unsigned arithmetic. Note that this attribute is only available in Ada 2005 mode (-gnat05 mode set). That's because mod is a reserved word, so it requires an Ada 2005 syntax change to allow this reserved word as an attribute name (normally we can freely add new attributes, but not if they have names that correspond to reserved words). A test program k.adb must be compiled with the -gnat05 switch, and generates the following output: 3 6 3 18446744073709551615 1 3 6 18446744073709551615 999 0 This change does not affect any Ada 95 program -- with Text_IO; use Text_IO; procedure K is type R is mod 7; type S is mod 2 ** 64; type U1 is mod 128; type S1 is range -128 .. + 127; X : Integer; function I (M : Integer) return Integer is begin return M; end; begin Put_Line (R'Image (R'Mod (17))); Put_Line (R'Image (R'Mod ( - 1))); Put_Line (R'Image (R'Mod (7 * 10 ** 100 + 3))); Put_Line (S'Image (S'Mod ( - 1))); Put_Line (S'Image (S'Mod (2 ** 80 + 1))); New_Line; X := I (17); Put_Line (R'Image (R'Mod (X))); X := I ( - 1); Put_Line (R'Image (R'Mod (X))); New_Line; Put_Line (S'Image (S'Mod (X))); X := I (999); Put_Line (S'Image (S'Mod (X))); New_Line; X := I ( - 128); Put_Line (U1'Image (U1'Mod (S1(X)))); end; -- Implement the new Ada 2005 restriction No_Dependence => unit, as described in AI-381. The full text of the AI is at www.ada-auth.org/cgi-bin/cvsweb.cgi/AIs/AI-00381.TXT?rev=1.7. There will likely be new revisions, since a critical feature is still under discussion, namely whether the list of possible packages is to be restricted to the language defined packages (the so-called semantic approach), or whether to allow arbitrary package names (the syntactic approach). The AI is written up currently for the former, but we argue for the latter, and the argument appears to be gaining traction in the ARG discussions, so that is what we implement for now since it is much more useful, and also easier to implement (no need to have a complete list of predefined units). The implementation is straightforward, but does require an extension of the ali format to accomodate information from this new kind of restriction. The binder has been modified to read and check this new information, since this is a restriction for which partition consistency is required. Note that the implementation also allows this form of restriction for the Restriction_Warnings pragma. j.adb checks for violation detection at compile time, testing both the explicit with case, and the implicit case of a run-time routine. The output when compiled should be: j.adb:6:06: violation of restriction "No_Dependence => Gnat.Os_Lib" at line 1 j.adb:7:06: warning: violation of restriction "No_Dependence => System" at line 3 j.adb:14:11: violation of restriction "No_Dependence => System.Exn_Int" at line 4 j.adb:15:08: warning: violation of restriction "No_Dependence => System" at line 3 -- pragma Restrictions (No_Dependence => GNAT.Os_Lib); pragma Restriction_Warnings (No_Dependence => System.Arg); pragma Restriction_Warnings (No_Dependence => System); pragma Restrictions (No_Dependence => System.Exn_Int); pragma Restrictions (No_Dependence => Text_IO); with GNAT.OS_Lib; with System; use System; procedure J is A, B, C : Integer; function Ident (X : Integer) return Integer is begin return X; end; begin B := Ident (3); C := Ident (4); A := B ** C; if A'Address = B'Address then B := 3; C := 2; end if; end; -- Implement new Ada 2005 restriction No_Obsolescent_Features, with the obvious meaning (restrict the use of annex J obsolescent features). This new identifier is allowed in both pragma Restrictions and pragma Restriction_Warnings. Conceptually, this is trivial to implement, especially as we already have -gnatwj to generate warnings for such usages. However, there is a nasty glitch. The use of replacement characters (e.g. : instead of # in based numbers) must be flagged at scan time, and scan knows nothing about restrictions. We can't just make a direct call from scng to check the restriction, since scng is a generic which is instantiated in contexts other than the compiler that know nothing about restrictions. So add a new generic formal that is a procedure to be called when an obsolescent character substituation is found. That means all users of scng have to add at least a dummy argument. To further complicate things, previously restrictions were only processed in sem_prag during semantic analysis, but this new restriction must be processed in par-prag at parse type. Just goes to show that sometimes simple things are not so simple. A test program for this new restriction identifier is given in k.adb whose output should be: k.adb:4:18: violation of restriction "No_Obsolescent_Features" at line 1 k.adb:6:04: violation of restriction "No_Obsolescent_Features" at line 1 k.adb:10:07: violation of restriction "No_Obsolescent_Features" at line 1 k.adb:16:14: violation of restriction "No_Obsolescent_Features" at line 1 k.adb:21:09: violation of restriction "No_Obsolescent_Features" at line 1 Note that in accordance with the operable Ada 2005 AI-368, this restriction is not enforced on a partition-wide basis, it applies only to the current compilation. -- pragma Restrictions (No_Obsolescent_Features); with System; use System; procedure K is S : String := %Abc%; Y, Z : Integer; for Z use at Y'Address; task X is entry Q; for Q'address use S'Address; end X; task body X is begin accept Q; end; begin case Y is when 1 ! 2 => null; when others => null; end case; exception when Numeric_Error => null; end; -- Take into account addition recommended by Ada 2005 AI-388. See discussion at www.ada-auth.org/cgi-bin/cvsweb.cgi/AIs/AI-00388.TXT?rev=1.3 for details. This change can be applied unconditionally in both Ada 2005 and Ada 95 modes, since identifiers containing wide characters such as this new greek Pi are not allowed in standard Ada 95 mode in any case. The trivial test program q.adb should compile and run without error, producing no output if it is compiled in Ada 2005 mode (or in Ada 95 mode using the non-standard switch -gnatiw to allow wide characters in identifiers). Note that library units are always compiled in Ada 2005 mode. The one issue that might arise is that older versions of gnat will not compile Ada.Numerics, but in the normal build process, the library is built with the newly built compiler, so this should not be a problem. Another part of this change is to have Scng unconditionally allow wide characters in identifiers in Ada 2005 mode, which is really part of AI-285, but is needed for this change. -- with Ada.Numerics; use Ada.Numerics; procedure Q is Universe_Broken : exception; begin if E > ["03C0"] then raise Universe_Broken; end if; end; -- Fix Ada 2005 AI-377. The pathological case addressed by this AI concerns the implicit generic child units that are visible under certain circumstances in an instance of their parent unit. This implicit unit may have a homograph that is an explicit child unit of the instance, and the context is illegal if it mentions the explicit unit and makes the implicit one visible. Test case: $ gcc -c -gnat05 q1.ads # must generate following errors: q1.ads:1:18: illegal with_clause q1.ads:1:18: child unit has visible homograph (RM 8.3(26), 10.1.1(19)) -- with G1.G2; with I1.G2; package Q1 is package inner renames I1.G2; -- legal? (no) package inst is new I1.G2; end Q1; generic package G1 is end G1; generic package G1.G2 is end G1.G2; with G1; package I1 is new G1; with Some_Package; package I1.G2 renames Some_Package; package Some_Package is end Some_Package; -- 2005-01-03 Robert Dewar <dewar@adacore.com> Ed Schonberg <schonberg@adacore.com> Vincent Celier <celier@adacore.com> * s-atacco.ads, a-direio.adb: Protect use of 'Constrained by warnings on/off, since this is an obsolescent feature, for which we now generate a warning. * sem_attr.adb (Analyze_Attribute, case Constrained): Issue warning if warning mode is set and obsolescent usage of this attribute occurs. (Resolve_Access, case 'Access): Note that GNAT uses the context type to disambiguate overloaded prefixes, in accordance with AI-235. GNAT code predates, and partly motivates, the adoption of the AI. Implement new Ada 2005 attribute Mod * exp_attr.adb (Expand_N_Attribute_Reference): Implement Ada 2005 attribute Mod. * par-ch4.adb (P_Name): In Ada 2005 mode, recognize new attribute Mod * snames.h, snames.ads, snames.adb: Add entry for No_Dependence for pragma restrictions. New entry for Ada 2005 attribute Mod. * par-prag.adb: Add recognition of new pragma Restrictions No_Dependence Recognize restriction No_Obsolescent_Features at parse time * bcheck.adb: Add circuitry for checking for consistency of No_Dependence restrictions. * lib-writ.ads, lib-writ.adb: Output new R lines for No_Dependence restrictions. * restrict.ads, restrict.adb: Add subprograms to deal with No_Dependence restrictions. * rtsfind.adb: Check that implicit with's do not violate No_Dependence restrictions. * sem_ch3.adb, sem_ch11.adb, sem_ch13.adb, lib-xref.adb, sem_attr.adb: Add check for new restriction No_Obsolescent_Features * scn.ads, prj-err.ads, prj-err.adb, ali-util.adb, gprep.adb: Add new dummy parameter to scng instantiation. Needed for new restriction No_Obsolescent_Features * scn.adb: (Obsolescent_Check): New procedure Needed for new restriction No_Obsolescent_Features * scng.ads, scng.adb: Always allow wide characters in Ada 2005 mode, as specified by AI-285, needed for implementation of AI-388 (adding greek pi to Ada.Numerics). Add new generic formal to scng, needed for new restriction No_Obsolescent_Features. * s-rident.ads: Add new restriction No_Obsolescent_Features. * ali.ads, ali.adb: Adjustments for reading new No_Dependence restrictions lines. (Scan_ALI): When finding an unexpected character on an R line, raise exception Bad_R_Line, instead of calling Fatal_Error, so that, when Ignore_Errors is True, default restrictions are set and scanning of the ALI file continues with the next line. Also, when Bad_R_Line is raised and Ignore_Errors is True, skip to the end of le line. * sem_ch10.adb: Check that explicit with's do not violate No_Dependence restrictions. (Install_Withed_Unit): Add code to implement AI-377 and diagnose illegal context clauses containing child units of instance. * sem_prag.adb: Processing and checking for new No_Dependence restrictions. (Analyze_Pragma, case Psect_Object): Call Check_Arg_Is_External_Name to analyze and check the External argument. * a-numeri.ads: Add greek letter pi as alternative spelling of Pi
Attachment:
difs.2
Description: Text document
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |