* Position of "use" @ 2014-07-05 6:43 Victor Porton 2014-07-05 7:12 ` J-P. Rosen ` (2 more replies) 0 siblings, 3 replies; 28+ messages in thread From: Victor Porton @ 2014-07-05 6:43 UTC (permalink / raw) What is the difference between with X; use X; package Y is end Y; and with X; package Y is use X; end Y; ? -- Victor Porton - http://portonvictor.org ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: Position of "use" 2014-07-05 6:43 Position of "use" Victor Porton @ 2014-07-05 7:12 ` J-P. Rosen 2014-07-07 16:45 ` Adam Beneschan 2014-07-08 19:30 ` Adam Beneschan 2014-07-09 10:36 ` anon 2 siblings, 1 reply; 28+ messages in thread From: J-P. Rosen @ 2014-07-05 7:12 UTC (permalink / raw) Le 05/07/2014 08:43, Victor Porton a écrit : > What is the difference between > > with X; use X; > package Y is > end Y; > > and > > with X; > package Y is > use X; > end Y; > > ? > A use clause (as well as any declaration) is usable from where it appears up to the associated "end". In the first case, it will allow short names for other with/use clauses, while in the second case it will be effective only inside the package. Personal note: it is quite rare to need use clauses in context clauses (the first case), and my personal policy is to use use clauses, but restricted to the innermost scope where they are useful. Therefore, I tend to prefer the second solution. -- J-P. Rosen Adalog 2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00 http://www.adalog.fr ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: Position of "use" 2014-07-05 7:12 ` J-P. Rosen @ 2014-07-07 16:45 ` Adam Beneschan 2014-07-07 17:08 ` Pascal Obry 2014-07-08 5:26 ` J-P. Rosen 0 siblings, 2 replies; 28+ messages in thread From: Adam Beneschan @ 2014-07-07 16:45 UTC (permalink / raw) On Saturday, July 5, 2014 12:12:59 AM UTC-7, J-P. Rosen wrote: > Le 05/07/2014 08:43, Victor Porton a �crit : > > > What is the difference between > > > with X; use X; > > package Y is > > end Y; > > > and > > > with X; > > package Y is > > use X; > > end Y; > > ? > > A use clause (as well as any declaration) is usable from where it > appears up to the associated "end". > > > In the first case, it will allow short names for other with/use clauses, > while in the second case it will be effective only inside the package. Not true. This is illegal: with Ada; use Ada; with Strings.Unbounded; package X is ... You can't use this as a substitute for "with Ada.Strings.Unbounded". The visibility rules for context clauses are separate from visibility rules in other cases. At the moment, I am not sure there is any difference at all between Victor's two examples; I'll have to study the rules carefully to make sure. It's possible that there is a difference if there is a child package (package X.Child is ...), or if there is a pragma in the context clause. I'll try to look at it later. -- Adam ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: Position of "use" 2014-07-07 16:45 ` Adam Beneschan @ 2014-07-07 17:08 ` Pascal Obry 2014-07-07 17:40 ` Peter Chapin 2014-07-07 19:17 ` Adam Beneschan 2014-07-08 5:26 ` J-P. Rosen 1 sibling, 2 replies; 28+ messages in thread From: Pascal Obry @ 2014-07-07 17:08 UTC (permalink / raw) Le lundi 07 juillet 2014 à 09:45 -0700, Adam Beneschan a écrit : > The visibility rules for context clauses are separate from visibility > rules in other cases. At the moment, I am not sure there is any > difference at all between Victor's two examples; I'll have to study > the rules carefully to make sure. It's possible that there is a > difference if there is a child package (package X.Child is ...), or if > there is a pragma in the context clause. I'll try to look at it later. I suppose it is different if there is multiple units in a single file? -- Pascal Obry / Magny Les Hameaux (78) The best way to travel is by means of imagination http://v2p.fr.eu.org http://www.obry.net gpg --keyserver keys.gnupg.net --recv-key F949BD3B ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: Position of "use" 2014-07-07 17:08 ` Pascal Obry @ 2014-07-07 17:40 ` Peter Chapin 2014-07-07 19:17 ` Adam Beneschan 1 sibling, 0 replies; 28+ messages in thread From: Peter Chapin @ 2014-07-07 17:40 UTC (permalink / raw) On 2014-07-07 13:08, Pascal Obry wrote: > Le lundi 07 juillet 2014 à 09:45 -0700, Adam Beneschan a écrit : >> The visibility rules for context clauses are separate from visibility >> rules in other cases. At the moment, I am not sure there is any >> difference at all between Victor's two examples; I'll have to study >> the rules carefully to make sure. It's possible that there is a >> difference if there is a child package (package X.Child is ...), or if >> there is a pragma in the context clause. I'll try to look at it later. > > I suppose it is different if there is multiple units in a single file? In that case, doesn't each unit have it's own context clause even so? with A; package P1 is ... end P1; with B; -- The 'with A' above is not relevant here (yes?) package body P2 is ... end P2; ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: Position of "use" 2014-07-07 17:08 ` Pascal Obry 2014-07-07 17:40 ` Peter Chapin @ 2014-07-07 19:17 ` Adam Beneschan 1 sibling, 0 replies; 28+ messages in thread From: Adam Beneschan @ 2014-07-07 19:17 UTC (permalink / raw) On Monday, July 7, 2014 10:08:37 AM UTC-7, Pascal Obry wrote: > I suppose it is different if there is multiple units in a single file? Absolutely not. Ada's rules do not treat compilation units in the same file any differently than compilation units in different files. -- Adam ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: Position of "use" 2014-07-07 16:45 ` Adam Beneschan 2014-07-07 17:08 ` Pascal Obry @ 2014-07-08 5:26 ` J-P. Rosen 2014-07-08 15:32 ` Adam Beneschan 1 sibling, 1 reply; 28+ messages in thread From: J-P. Rosen @ 2014-07-08 5:26 UTC (permalink / raw) Le 07/07/2014 18:45, Adam Beneschan a écrit : >> In the first case, it will allow short names for other with/use clauses, >> > while in the second case it will be effective only inside the package. > Not true. This is illegal: > > with Ada; > use Ada; > with Strings.Unbounded; > package X is ... > > You can't use this as a substitute for "with Ada.Strings.Unbounded". Yes of course, I typed a bit too fast for "with", but it still applies to "use" clause as context clauses. -- J-P. Rosen Adalog 2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00 http://www.adalog.fr ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: Position of "use" 2014-07-08 5:26 ` J-P. Rosen @ 2014-07-08 15:32 ` Adam Beneschan 0 siblings, 0 replies; 28+ messages in thread From: Adam Beneschan @ 2014-07-08 15:32 UTC (permalink / raw) On Monday, July 7, 2014 10:26:36 PM UTC-7, J-P. Rosen wrote: > > Not true. This is illegal: > > with Ada; > > use Ada; > > with Strings.Unbounded; > > package X is ... > > You can't use this as a substitute for "with Ada.Strings.Unbounded". > > Yes of course, I typed a bit too fast for "with", but it still applies > to "use" clause as context clauses. with Ada; use Ada; with Ada.Strings.Unbounded; use Strings.Unbounded; package X is ... Still illegal, according to both GNAT and ICC Ada. -- Adam ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: Position of "use" 2014-07-05 6:43 Position of "use" Victor Porton 2014-07-05 7:12 ` J-P. Rosen @ 2014-07-08 19:30 ` Adam Beneschan 2014-07-08 22:39 ` Victor Porton 2014-07-09 10:36 ` anon 2 siblings, 1 reply; 28+ messages in thread From: Adam Beneschan @ 2014-07-08 19:30 UTC (permalink / raw) On Friday, July 4, 2014 11:43:46 PM UTC-7, Victor Porton wrote: > What is the difference between > > with X; use X; > package Y is > end Y; > > and > > with X; > package Y is > use X; > end Y; > > ? OK, I've looked into it, and there's no difference. I'm assuming that there may be more code in the specification of Y, but that in the second example, "use X" is the first thing in this specification. RM 8.4(6-7) describe the "scope" of a use_clause, which is the portion of code that is affected by the "use". If it's in the context clause, the scope is the entire declarative region of the package. If it's inside the declarative region, the scope is the part of the declarative region starting from the "use" and ending at the end of the declarative region; if the "use" clause is the first thing in the region (as in the second example above), that means that the scope is the entire declarative region of the package, same as the first example. (Note that in both cases, the declarative region will include child packages, if any. This follows from the rules in RM 8.1.) The scope doesn't include the context clause itself. (The context clause is the "with" and "use" statements that occur before the "package/procedure/function" of a top-level library unit, and it may include pragmas.) RM 10.1.6 says that the visibility rules don't apply to the context clause, and it contains special rules for context clauses. Nothing in those rules says that "use" makes anything visible in a context clause; therefore, a "use" in a context clause has no effect on any other "with", "use", or "pragma" in the context clause, or in any other context clause (i.e. the context clause on a child package or subunit). Therefore, the effect of a "use" that is the first thing in a package specification has the exact same effect as a "use" appearing in the context clause. -- Adam ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: Position of "use" 2014-07-08 19:30 ` Adam Beneschan @ 2014-07-08 22:39 ` Victor Porton 0 siblings, 0 replies; 28+ messages in thread From: Victor Porton @ 2014-07-08 22:39 UTC (permalink / raw) Adam Beneschan wrote: > On Friday, July 4, 2014 11:43:46 PM UTC-7, Victor Porton wrote: >> What is the difference between >> >> with X; use X; >> package Y is >> end Y; >> >> and >> >> with X; >> package Y is >> use X; >> end Y; >> >> ? > > OK, I've looked into it, and there's no difference. I'm assuming that > there may be more code in the specification of Y, but that in the second > example, "use X" is the first thing in this specification. > > RM 8.4(6-7) describe the "scope" of a use_clause, which is the portion of > code that is affected by the "use". If it's in the context clause, the > scope is the entire declarative region of the package. If it's inside the > declarative region, the scope is the part of the declarative region > starting from the "use" and ending at the end of the declarative region; > if the "use" clause is the first thing in the region (as in the second > example above), that means that the scope is the entire declarative region > of the package, same as the first example. (Note that in both cases, the > declarative region will include child packages, if any. This follows from > the rules in RM 8.1.) > > The scope doesn't include the context clause itself. (The context clause > is the "with" and "use" statements that occur before the > "package/procedure/function" of a top-level library unit, and it may > include pragmas.) RM 10.1.6 says that the visibility rules don't apply to > the context clause, and it contains special rules for context clauses. > Nothing in those rules says that "use" makes anything visible in a context > clause; therefore, a "use" in a context clause has no effect on any other > "with", "use", or "pragma" in the context clause, or in any other context > clause (i.e. the context clause on a child package or subunit). > > Therefore, the effect of a "use" that is the first thing in a package > specification has the exact same effect as a "use" appearing in the > context clause. > > -- Adam Possible reason why these two equal variants of syntax were introduced by Ada designers: It would be different if we'd replace package with a procedure or a function, because use can apply or not apply to procedure parameters. The same applies to generic packages. -- Victor Porton - http://portonvictor.org ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: Position of "use" 2014-07-05 6:43 Position of "use" Victor Porton 2014-07-05 7:12 ` J-P. Rosen 2014-07-08 19:30 ` Adam Beneschan @ 2014-07-09 10:36 ` anon 2014-07-09 15:14 ` Adam Beneschan 2 siblings, 1 reply; 28+ messages in thread From: anon @ 2014-07-09 10:36 UTC (permalink / raw) Using a global "use_clause" can sometime cause the compiler to hide all routines of one or more libraries. It is better to place most use_clause in a local routine or within the declare section of a block_statement. -- -- Example File: Test_2.adb -- -- Showing where compiler could hide visibility access to packages. -- with Ada.Text_IO ; -- There are a number of routines that are with GNAT.IO ; -- common in both packages so, placement of -- the use_clause is critical, if used. procedure body Test_2 is -- Both Ada.Text_IO and GNAT.IO packages must be access by using -- "selected_component" at this point procedure Test_2b is use GNAT.IO ; -- Grants global visibility to package GNAT.IO. but -- limits Ada.Text_IO to a "selected_component" -- access begin null ; end ; -- Allow all following routines will have visibility to -- Ada.Text_IO could also cause visibility problems with other -- packages. use Ada.Text_IO ; procedure Test_2a is use GNAT.IO ; -- Will cause the compiler to hide packages, -- so in this example any reference must be by -- "selected_component" for both Ada.Text_IO -- and GNAT.IO packages begin null ; end ; begin null ; end ; For Ada compilers, where you can have more than one compilation_unit within one file (RM 10.1 -- 10.1.1), it allows all preceding compilation_unit to have access the same library with only one "with_clause" without sharing global visibility to that package. Note: GNAT limits the compilation_unit to one per file. But GNAT still allows this type of program design. Putting the "with_clause" in the specification file (.ads) allows access for the corresponding body file (.adb) in some cases without having the "with_clause" in the body file. -- -- Example of a multiple compilation_unit File: Test_Lib.ada -- -- Showing different access/visibility to package Text_IO -- -- compilation_unit 1 : Access to Text_IO is forbidden in this -- package package Test_Init is -- ... end Test_Init ; -- with Text_IO ; -- Access is Allowed -- use Text_IO ; -- Visibility would be global to all -- -- specification and body units if this -- -- statement is used. -- -- compilation_unit 2 : Limits visibility to Text_IO to a -- "selected_component", unless the -- global "use_clause" is used. -- -- example : Text_IO.Col -- package Test_55 is procedure Init ; -- ... end Test_55 ; -- -- -- compilation_unit 3 : Visibility of package depend upon -- placement of the "use_clause" -- package body Test_55 is -- use Text_IO ; -- Visibility is global within this package body procedure Init is use Text_IO ; -- Visibility is local to procedure begin Set_Col ( 5 ) ; Set_Line ( 2 ) ; end Init ; procedure Error is begin declare use Text_IO ; -- Visibility is local to this block statement begin Put ( "Error" ) ; end ; end Error ; -- ... end Test_55 ; -- -- -- compilation_unit 4 : Limits visibility to Text_IO to a -- "selected_component", unless the -- global "use_clause" is used. -- -- example : Text_IO.New_Line ; -- package Test_Cal is -- ... end Test_Cal ; In <lp86r0$ssl$1@speranza.aioe.org>, Victor Porton <porton@narod.ru> writes: >What is the difference between > >with X; use X; >package Y is >end Y; > >and > >with X; >package Y is > use X; >end Y; > >? > >-- >Victor Porton - http://portonvictor.org ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: Position of "use" 2014-07-09 10:36 ` anon @ 2014-07-09 15:14 ` Adam Beneschan 2014-07-10 1:27 ` anon 0 siblings, 1 reply; 28+ messages in thread From: Adam Beneschan @ 2014-07-09 15:14 UTC (permalink / raw) On Wednesday, July 9, 2014 3:36:09 AM UTC-7, an...@att.net wrote: > For Ada compilers, where you can have more than one compilation_unit > within one file (RM 10.1 -- 10.1.1), it allows all preceding > compilation_unit to have access the same library with only one > "with_clause" without sharing global visibility to that package. > > Note: GNAT limits the compilation_unit to one per file. But GNAT still > allows this type of program design. Putting the "with_clause" in the > specification file (.ads) allows access for the corresponding body file > (.adb) in some cases without having the "with_clause" in the body file. I'm not sure what you're trying to say here, but I want to reiterate: according to the Ada rules, putting multiple compilation units in the same file has *no* effect on the visibility rules (or any other rules). If you have package specifications for two different packages, P1 and P2, in the same file, a "with" or "use" clause on P1 does not apply to P2, and vice versa. A "with" clause on a specification of any package automatically applies to the body, and it also automatically applies to any child unit specifications or bodies. This is due to the rules in RM 8.1 and has nothing to do with GNAT, and nothing to do with whether the specification and body are in the same file or not. Thus, in this example, the comments are wrong: > -- > -- compilation_unit 4 : Limits visibility to Text_IO to a > -- "selected_component", unless the > -- global "use_clause" is used. > -- > -- example : Text_IO.New_Line ; > -- > package Test_Cal is > -- ... > end Test_Cal ; Text_IO is not visible at all, since there is no "with Text_IO" on Test_Cal. The "with Text_IO" earlier in the file, on "package Test_55", has no effect. -- Adam ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: Position of "use" 2014-07-09 15:14 ` Adam Beneschan @ 2014-07-10 1:27 ` anon 2014-07-10 9:50 ` AdaMagica 2014-07-10 15:54 ` Adam Beneschan 0 siblings, 2 replies; 28+ messages in thread From: anon @ 2014-07-10 1:27 UTC (permalink / raw) Actually, the comments for compilation_unit 4 are correct under multiple compilation_unit type files, which GNAT does not support. It was tested under AdaEd-1.11.0a compiled for SuSE Linux, before I posted a condensed version. Note: GNAT (Adacore or GNU) does not support multiple compilation_unit (s) within one file. For multiple compilation_unit, likes those files found in ACVC, the external visibility starts with the "with_clause" and that clause grants all succeeding compilation_unit(s) access to that package or routine no matter how many compilation_unit there are. In other words you only need one "with_clause" for Ada compilers that support multiple compilation_unit in the same file. But the direct visibility is allowed by the "use_clause". Exception is where two or more routines from two sources are the same. Example is GNAT.IO.Put ( S : String ) and Ada.Text_IO.Put ( Item : in String ) In this case the compiler requires help to link to the correct package with requires a "selected_component" type statement to correctly identify the correct routine. Under Ada the following should work but some versions of GNAT over the years have not match the formal_parameter of two or more routines correctly when using two unique packages. Put ( S => <string> ) ; -- GNAT.IO Put ( Item => <string> ) ; -- Ada.Text_IO so it better just to use GNAT.IO.Put ( <String> ) -- or Ada.Text_IO.Put ( <String> ) or GNAT.IO.Put ( S => <String> ) -- or Ada.Text_IO.Put ( Item => <String> ) In <33fbd821-cb30-4be9-93c1-17002470413e@googlegroups.com>, Adam Beneschan <adambeneschan@gmail.com> writes: >On Wednesday, July 9, 2014 3:36:09 AM UTC-7, an...@att.net wrote: > >> For Ada compilers, where you can have more than one compilation_unit=20 >> within one file (RM 10.1 -- 10.1.1), it allows all preceding=20 >> compilation_unit to have access the same library with only one=20 >> "with_clause" without sharing global visibility to that package. >>=20 >> Note: GNAT limits the compilation_unit to one per file. But GNAT still= >=20 >> allows this type of program design. Putting the "with_clause" in the=20 >> specification file (.ads) allows access for the corresponding body file= >=20 >> (.adb) in some cases without having the "with_clause" in the body file. > >I'm not sure what you're trying to say here, but I want to reiterate: accor= >ding to the Ada rules, putting multiple compilation units in the same file = >has *no* effect on the visibility rules (or any other rules). If you have = >package specifications for two different packages, P1 and P2, in the same f= >ile, a "with" or "use" clause on P1 does not apply to P2, and vice versa. > >A "with" clause on a specification of any package automatically applies to = >the body, and it also automatically applies to any child unit specification= >s or bodies. This is due to the rules in RM 8.1 and has nothing to do with= > GNAT, and nothing to do with whether the specification and body are in the= > same file or not. > >Thus, in this example, the comments are wrong: > >> -- >> -- compilation_unit 4 : Limits visibility to Text_IO to a=20 >> -- "selected_component", unless the=20 >> -- global "use_clause" is used. >> -- >> -- example : Text_IO.New_Line ; >> -- >> package Test_Cal is >> -- ... >> end Test_Cal ; > >Text_IO is not visible at all, since there is no "with Text_IO" on Test_Cal= >.. The "with Text_IO" earlier in the file, on "package Test_55", has no eff= >ect. > > -- Adam ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: Position of "use" 2014-07-10 1:27 ` anon @ 2014-07-10 9:50 ` AdaMagica 2014-07-10 13:10 ` J-P. Rosen 2014-07-15 5:56 ` anon 2014-07-10 15:54 ` Adam Beneschan 1 sibling, 2 replies; 28+ messages in thread From: AdaMagica @ 2014-07-10 9:50 UTC (permalink / raw) On Thursday, July 10, 2014 3:27:08 AM UTC+2, an...@att.net wrote: > Actually, the comments for compilation_unit 4 are correct under multiple > compilation_unit type files, which GNAT does not support. It was tested > under AdaEd-1.11.0a compiled for SuSE Linux, before I posted a condensed > version. That sounds quite unbelievable to me; looks like AdaEd has a severe bug - if your claim is correct. > Note: GNAT (Adacore or GNU) does not support multiple > compilation_unit (s) within one file. > > For multiple compilation_unit, likes those files found in ACVC, the > external visibility starts with the "with_clause" and that clause > grants all succeeding compilation_unit(s) access to that package or > routine no matter how many compilation_unit there are. In other words > you only need one "with_clause" for Ada compilers that support multiple > compilation_unit in the same file. Please show us such a file or at least give the reference in ACATS 3.1. ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: Position of "use" 2014-07-10 9:50 ` AdaMagica @ 2014-07-10 13:10 ` J-P. Rosen 2014-07-10 15:57 ` Adam Beneschan 2014-07-10 19:15 ` Jeffrey Carter 2014-07-15 5:56 ` anon 1 sibling, 2 replies; 28+ messages in thread From: J-P. Rosen @ 2014-07-10 13:10 UTC (permalink / raw) Le 10/07/2014 11:50, AdaMagica a écrit : > That sounds quite unbelievable to me; looks like AdaEd has a severe bug - if your claim is correct. AdaEd is roughly 30 years old, and not updated since... It's quite unbelievable that anybody is still using it, and it is certainly not a trustable reference nowadays. -- J-P. Rosen Adalog 2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00 http://www.adalog.fr ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: Position of "use" 2014-07-10 13:10 ` J-P. Rosen @ 2014-07-10 15:57 ` Adam Beneschan 2014-07-10 17:47 ` Tero Koskinen 2014-07-10 19:15 ` Jeffrey Carter 1 sibling, 1 reply; 28+ messages in thread From: Adam Beneschan @ 2014-07-10 15:57 UTC (permalink / raw) On Thursday, July 10, 2014 6:10:10 AM UTC-7, J-P. Rosen wrote: > > That sounds quite unbelievable to me; looks like AdaEd has a severe bug - if your claim is correct. > > AdaEd is roughly 30 years old, and not updated since... It's quite > unbelievable that anybody is still using it, and it is certainly not a > trustable reference nowadays. True, but even younger compilers that are actively being maintained aren't completely trustable references. GNAT lets things slip through that should be errors. -- Adam ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: Position of "use" 2014-07-10 15:57 ` Adam Beneschan @ 2014-07-10 17:47 ` Tero Koskinen 0 siblings, 0 replies; 28+ messages in thread From: Tero Koskinen @ 2014-07-10 17:47 UTC (permalink / raw) 10.7.2014 18:57, Adam Beneschan wrote: > GNAT lets things slip through that should be errors. To GNAT's defence, this kind of bugs are pretty hard to find, especially afterwards if enough care has not been taken during the initial implementation. Many times you only notice "accepts invalid code" bug if another compiler rejects the code.[1] Some of my recent examples: 1) GNAT compiles Strings Edit 2.9 cleanly, while ICCAda rejects the code: > > "strings_edit-integers-subscript.ads", line 31: Error: Undefined > identifier: > > Number. [RM 4.1(11), 8.3, 8.6(28)] > (See http://build.ada-language.com/job/Strings_Edit_ICCAda/3/console for full log.) 2) ICCAda and GNAT both compile Debug package from Adalog ( http://www.adalog.fr/compo2.htm#Debug ) while Janus/Ada rejects the code: > In File C:\work\adalog-debug\DEBUG.ADS at line 206 > -------------- > 205: type Debug_String is new String; > 206: procedure Free is new Ada.Unchecked_Deallocation > (Debug_String, Debug_String_Access); >-------------------------------------------------------------------------^ > *ERROR* Formal and actual must both be constrained or unconstrained > (6.4.10) [RM 12.5.4(3)] Of course, in these cases, one could probably argue which compilers are correct and which are not; luckily I a user, who does not need to worry about the compiler implementation. :) Yours, Tero [1] Yes, there is ACATS, but as you can see, it does not cover everything. ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: Position of "use" 2014-07-10 13:10 ` J-P. Rosen 2014-07-10 15:57 ` Adam Beneschan @ 2014-07-10 19:15 ` Jeffrey Carter 1 sibling, 0 replies; 28+ messages in thread From: Jeffrey Carter @ 2014-07-10 19:15 UTC (permalink / raw) On 07/10/2014 06:10 AM, J-P. Rosen wrote: > Le 10/07/2014 11:50, AdaMagica a écrit : >> That sounds quite unbelievable to me; looks like AdaEd has a severe bug - if your claim is correct. > AdaEd is roughly 30 years old, and not updated since... It's quite > unbelievable that anybody is still using it, and it is certainly not a > trustable reference nowadays. Anon has never been a trustable reference. -- Jeff Carter "Spam! Spam! Spam! Spam! Spam! Spam! Spam! Spam!" Monty Python's Flying Circus 53 ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: Position of "use" 2014-07-10 9:50 ` AdaMagica 2014-07-10 13:10 ` J-P. Rosen @ 2014-07-15 5:56 ` anon 2014-07-15 7:36 ` Georg Bauhaus 1 sibling, 1 reply; 28+ messages in thread From: anon @ 2014-07-15 5:56 UTC (permalink / raw) -- -- Just because one may think its wrong, does not make it so. -- The RM does not limit scope of the "with_clause". And does not -- fully check the simple_name for duplicates. -- -- This makes it a RM problem not a compiler bug. The "With_Clause" -- scope is defined in RM 10.1.2 (5), and does suggest that the -- "With_Clause" for a multiple compilation files are global. -- -- This example works under GNAT. -- with Ada.Text_IO ; -- Some will say that the compiler should give a warning for -- duplicate entry but the RM permit the following statements with Ada.Text_IO ; with Ada.Text_IO ; procedure t is use Ada ; use Ada.Text_IO ; use Text_IO ; -- Should give a warning for duplicate but the RM permit this use Text_IO ; begin Ada.Text_IO.New_Page ; Text_IO.Put ( "T" ) ; New_Line ; end ; In <f8345aa5-d4e9-4919-8b32-541336a2e436@googlegroups.com>, AdaMagica <christ-usch.grein@t-online.de> writes: >On Thursday, July 10, 2014 3:27:08 AM UTC+2, an...@att.net wrote: >> Actually, the comments for compilation_unit 4 are correct under multiple >> compilation_unit type files, which GNAT does not support. It was tested >> under AdaEd-1.11.0a compiled for SuSE Linux, before I posted a condensed >> version. > >That sounds quite unbelievable to me; looks like AdaEd has a severe bug - if your claim is correct. > >> Note: GNAT (Adacore or GNU) does not support multiple >> compilation_unit (s) within one file. >> >> For multiple compilation_unit, likes those files found in ACVC, the >> external visibility starts with the "with_clause" and that clause >> grants all succeeding compilation_unit(s) access to that package or >> routine no matter how many compilation_unit there are. In other words >> you only need one "with_clause" for Ada compilers that support multiple >> compilation_unit in the same file. > >Please show us such a file or at least give the reference in ACATS 3.1. ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: Position of "use" 2014-07-15 5:56 ` anon @ 2014-07-15 7:36 ` Georg Bauhaus 2014-07-15 17:01 ` Simon Wright 0 siblings, 1 reply; 28+ messages in thread From: Georg Bauhaus @ 2014-07-15 7:36 UTC (permalink / raw) On 15.07.14 07:56, anon@att.net wrote: > The "With_Clause" > -- scope is defined in RM 10.1.2 (5), and does suggest that the > -- "With_Clause" for a multiple compilation files are global. 10.1.2 (5) refers to a declaration (such as a package declaration), and to this declaration's declarative region. 10.1.1 lists compilation_unit as either a library_item or a subunit. (For example, a package spec, or a separate procedure body.) 8.1, at which Adam Beneschan has hinted, expounds declarative_region, mentioned in 10.1.2. For any such declaration, as I understand it, a with_clause is in scope of the corresponding declarative_region, but nowhere else. So, for example, a with_clause above a package spec will be in scope of a package spec, its body, a separate procedure body (subunit) declared somewhere in the package, and children of the package. But, for example, another package (other than children of the first, or subunits) that happens to be declared in the same file establishes another declarative region. Any with_clause, then, that is atop any prior declarative region is not in scope of this package's declarative region. GNAT's gnatchop will confirm this when run on the two units below placed in the same one file. I do get a warning about redundant with clauses, when the compiler analyses the resulting unit associated with the name Foo. I do get two files, foo.adb and bar.adb. But gnatchop does not place a with_clause ("with Ada.Text_Io") in bar.adb. Correspondingly, any use_clause placed anywhere in the declarative region of Bar will not work. Nor will Ada.Text_Io.Put_Line name a procedure, as Ada.Text_IO will not have been with-ed there. with Ada.Text_Io; with Ada.Text_Io ; procedure Foo is begin Ada.Text_Io.Put_Line ("Foo"); end Foo; procedure Bar is begin Ada.Text_Io.Put_Line ("Bar"); end Bar; ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: Position of "use" 2014-07-15 7:36 ` Georg Bauhaus @ 2014-07-15 17:01 ` Simon Wright 2014-07-15 17:23 ` Jeffrey Carter ` (2 more replies) 0 siblings, 3 replies; 28+ messages in thread From: Simon Wright @ 2014-07-15 17:01 UTC (permalink / raw) Georg Bauhaus <rm.dash-bauhaus@futureapps.de> writes: > But, for example, another package (other than children of the first, > or subunits) that happens to be declared in the same file establishes > another declarative region. Any with_clause, then, that is atop any > prior declarative region is not in scope of this package's declarative > region. But, in Ada83, a *pragma*'s scope extended over the whole compilation (all the compilation units). GNAT (gnatchop) doesn't seem to support this; the modern equivalent would be configuration pragmas, ARM 10.1.5(1)[1]. I think perhaps Mr Anon is confusing context clauses with pragmas. [1] http://www.adaic.org/resources/add_content/standards/12rm/html/RM-10-1-5.html#p8 ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: Position of "use" 2014-07-15 17:01 ` Simon Wright @ 2014-07-15 17:23 ` Jeffrey Carter 2014-07-15 19:44 ` Simon Wright 2014-07-15 17:47 ` G.B. 2014-07-15 17:51 ` Adam Beneschan 2 siblings, 1 reply; 28+ messages in thread From: Jeffrey Carter @ 2014-07-15 17:23 UTC (permalink / raw) On 07/15/2014 10:01 AM, Simon Wright wrote: > > I think perhaps Mr Anon is confusing context clauses with pragmas. "Mr"? What evidence do you have that "anon" is an adult, human male? :) -- Jeff Carter "Ah, go away or I'll kill ya." Never Give a Sucker an Even Break 100 ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: Position of "use" 2014-07-15 17:23 ` Jeffrey Carter @ 2014-07-15 19:44 ` Simon Wright 0 siblings, 0 replies; 28+ messages in thread From: Simon Wright @ 2014-07-15 19:44 UTC (permalink / raw) Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org> writes: > On 07/15/2014 10:01 AM, Simon Wright wrote: >> >> I think perhaps Mr Anon is confusing context clauses with pragmas. > > "Mr"? What evidence do you have that "anon" is an adult, human male? :) I suppose I just think that women usually have more sense. Gender profiling, then. ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: Position of "use" 2014-07-15 17:01 ` Simon Wright 2014-07-15 17:23 ` Jeffrey Carter @ 2014-07-15 17:47 ` G.B. 2014-07-15 17:51 ` Adam Beneschan 2 siblings, 0 replies; 28+ messages in thread From: G.B. @ 2014-07-15 17:47 UTC (permalink / raw) On 15.07.14 19:01, Simon Wright wrote: > But, in Ada83, a*pragma*'s scope extended over the whole compilation > (all the compilation units). > > GNAT (gnatchop) doesn't seem to support this; the modern equivalent > would be configuration pragmas, ARM 10.1.5(1)[1]. There's 8.2 Operating gnatchop in Compilation Mode in the User's Guide saying gnatchop prepends configuration pragmas to all chopped files if run in this mode. $ gnatchop -h -c compilation mode, configuration pragmas follow RM rules ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: Position of "use" 2014-07-15 17:01 ` Simon Wright 2014-07-15 17:23 ` Jeffrey Carter 2014-07-15 17:47 ` G.B. @ 2014-07-15 17:51 ` Adam Beneschan 2014-07-15 20:04 ` Simon Wright 2014-07-16 7:19 ` anon 2 siblings, 2 replies; 28+ messages in thread From: Adam Beneschan @ 2014-07-15 17:51 UTC (permalink / raw) On Tuesday, July 15, 2014 10:01:12 AM UTC-7, Simon Wright wrote: > But, in Ada83, a *pragma*'s scope extended over the whole compilation > (all the compilation units). I don't know that this was universally true; I don't see a general rule to that effect. The rules vary from pragma to pragma. STORAGE_UNIT and SYSTEM_NAME (since removed) had to appear at the beginning of a compilation and applied to every compilation unit in the compilation (this seems to anticipate the "configuration pragma" rules of Ada 95 and beyond). ELABORATE, however, appears in a context clause (as does the "use" clause) but only applies to one compilation unit. Most of the pragmas were only allowed inside declarations. LIST(ON) and LIST(OFF) apply to the entire compilation, of course, but since it controls only the listing output and has no effect on semantics or generated code, it's really a special case. Implementation-defined pragmas follow whatever rules the vendor decides they should. I think the situation is pretty much the same in Ada 95+, except a little more formalized. There's no one rule defining the scope of pragmas, but there are rules for categories of pragmas (in particular "configuration pragmas"). -- Adam ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: Position of "use" 2014-07-15 17:51 ` Adam Beneschan @ 2014-07-15 20:04 ` Simon Wright 2014-07-16 7:19 ` anon 1 sibling, 0 replies; 28+ messages in thread From: Simon Wright @ 2014-07-15 20:04 UTC (permalink / raw) Adam Beneschan <adambeneschan@gmail.com> writes: > On Tuesday, July 15, 2014 10:01:12 AM UTC-7, Simon Wright wrote: > >> But, in Ada83, a *pragma*'s scope extended over the whole compilation >> (all the compilation units). > > I don't know that this was universally true; I don't see a general > rule to that effect. The rules vary from pragma to pragma. > STORAGE_UNIT and SYSTEM_NAME (since removed) had to appear at the > beginning of a compilation and applied to every compilation unit in > the compilation (this seems to anticipate the "configuration pragma" > rules of Ada 95 and beyond). ELABORATE, however, appears in a context > clause (as does the "use" clause) but only applies to one compilation > unit. Most of the pragmas were only allowed inside declarations. -gnat83 isn't perfect, and even with it gnatchop -c doesn't treat Storage_Unit as a configuration pragma. ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: Position of "use" 2014-07-15 17:51 ` Adam Beneschan 2014-07-15 20:04 ` Simon Wright @ 2014-07-16 7:19 ` anon 1 sibling, 0 replies; 28+ messages in thread From: anon @ 2014-07-16 7:19 UTC (permalink / raw) Adam. Note: I was not talking or using option -gnat83, or pragma Ada_83. Only the "with_clause" and "use_clause" using AdaEd and GNAT. I used AdaEd and GNAT and their RM so anyone see what I am saying, because only AdaEd and GNAT compilers are downloadable and free and both have been validated, while the others compilers requires purchasing, and no guarantee they will work with current OS. Also, unsure if the sold IBM Apex compiler is even available to the general public. Now, "-gnat83" basically just set the restrictions mode for 83, like the pragma Ada_83. But, in the GNAT_RM pragma Ada_83. states: "However, there is no guarantee that code that is processed correctly by GNAT in Ada 83 mode will in fact compile and execute with an Ada 83 compiler, since GNAT does not enforce all the additional checks required by Ada 83." Then there the change to "copy by type to the second stack" aka "Return by type" so, a number of Ada 83, 95, and early Ada 2005 programs will no longer compile as initially written. Which suggest that unless you using a pre-"Return by type" compiler that the pragma Ada_83, Ada_95 or Ada_05, or command options -gnat83, -gnat95, -gnat05 will not truly guarantee the code to be processed correctly. This one one reason I wish Adacore would make available for download the compiler source package for each Ada standard. such as GNAT 0.xx: initial version of gnat for Ada 83, Ada 95 code removed GNAT 3.1x: gnat for Ada 95 GNAT 2011: gnat for Ada 2005 Or course it up to the downloader to find a way to compile the code. And add the correct gcc back_end. Also most people use GNAT by either gnat make <program_name> or when binding to other languages. gnat compile <program_name>.adb gnat build <program_name>.ali gnat link <program_name>.ali <non-Ada object code list> while the other 10+ routines like chop are not normally used. Plus, GNAT "Chop" splits the file by looking for the end of the "library_unit" or "secondary_unit". Any statement after the end of the unit begins on the next file, this can include comments after unit. Also, "Chop" does not check for configuration pragmas because GNAT does not support theses pragmas ( System_Name, Memory_Size, Storage_Unit ). In <f02e3f5c-dcfc-4d69-9caa-ee0f14723f70@googlegroups.com>, Adam Beneschan <adambeneschan@gmail.com> writes: >On Tuesday, July 15, 2014 10:01:12 AM UTC-7, Simon Wright wrote: > >> But, in Ada83, a *pragma*'s scope extended over the whole compilation >> (all the compilation units). > >I don't know that this was universally true; I don't see a general rule to = >that effect. The rules vary from pragma to pragma. STORAGE_UNIT and SYSTE= >M_NAME (since removed) had to appear at the beginning of a compilation and = >applied to every compilation unit in the compilation (this seems to anticip= >ate the "configuration pragma" rules of Ada 95 and beyond). ELABORATE, how= >ever, appears in a context clause (as does the "use" clause) but only appli= >es to one compilation unit. Most of the pragmas were only allowed inside d= >eclarations. LIST(ON) and LIST(OFF) apply to the entire compilation, of co= >urse, but since it controls only the listing output and has no effect on se= >mantics or generated code, it's really a special case. Implementation-defi= >ned pragmas follow whatever rules the vendor decides they should. > >I think the situation is pretty much the same in Ada 95+, except a little m= >ore formalized. There's no one rule defining the scope of pragmas, but the= >re are rules for categories of pragmas (in particular "configuration pragma= >s"). > > -- Adam ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: Position of "use" 2014-07-10 1:27 ` anon 2014-07-10 9:50 ` AdaMagica @ 2014-07-10 15:54 ` Adam Beneschan 1 sibling, 0 replies; 28+ messages in thread From: Adam Beneschan @ 2014-07-10 15:54 UTC (permalink / raw) On Wednesday, July 9, 2014 6:27:08 PM UTC-7, an...@att.net wrote: > Actually, the comments for compilation_unit 4 are correct under multiple > compilation_unit type files, which GNAT does not support. It was tested > under AdaEd-1.11.0a compiled for SuSE Linux, before I posted a condensed > version. The language rules are clear. 10.1.2(5) says that the scope of a with_clause that appears on a library unit declaration consists of the entire declarative region of the *declaration*, which includes all children and subunits (and, by 8.1(8), includes the package body if the with_clause appears on a package specification). If a file contains two compilation units, they are two separate declarations. Therefore, unless the second declaration is a body or child unit or subunit of the first one, the scope of a with_clause on the first unit in a file does not include the second unit. The fact that one or another compiler accepts it means nothing. Compilers have bugs. Compiler bugs that allow illegal code to be accepted are given less attention, in my experience, than compiler bugs that reject legal Ada code or generate incorrect object code. That's certainly the case with GNAT, which has a number of bugs in which illegal code is accepted (which unfortunately means that open-source Ada projects that get put on the Internet sometimes have illegal Ada in them). But to determine whether a construct is legal or an identifier is visible or whatever, you have to check the language standard; you cannot count on a compiler to get it 100% right. > For multiple compilation_unit, likes those files found in ACVC, the > external visibility starts with the "with_clause" and that clause > grants all succeeding compilation_unit(s) access to that package or > routine no matter how many compilation_unit there are. In other words > you only need one "with_clause" for Ada compilers that support multiple > compilation_unit in the same file. No, that isn't true. It may *appear* to be true in the ACATS because a later compilation unit is often the completion (body) of an earlier one, or it's a child unit. And, as I pointed out, with_clauses on package specs *do* apply to their bodies and child units. But if you can find a case where a with_clause on one package in a ACATS file applies to a later *unrelated* package, please post it. (But really, don't bother, because there aren't any. If there were, our compiler would have caught it a long time ago.) -- Adam ^ permalink raw reply [flat|nested] 28+ messages in thread
end of thread, other threads:[~2014-07-16 7:19 UTC | newest] Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2014-07-05 6:43 Position of "use" Victor Porton 2014-07-05 7:12 ` J-P. Rosen 2014-07-07 16:45 ` Adam Beneschan 2014-07-07 17:08 ` Pascal Obry 2014-07-07 17:40 ` Peter Chapin 2014-07-07 19:17 ` Adam Beneschan 2014-07-08 5:26 ` J-P. Rosen 2014-07-08 15:32 ` Adam Beneschan 2014-07-08 19:30 ` Adam Beneschan 2014-07-08 22:39 ` Victor Porton 2014-07-09 10:36 ` anon 2014-07-09 15:14 ` Adam Beneschan 2014-07-10 1:27 ` anon 2014-07-10 9:50 ` AdaMagica 2014-07-10 13:10 ` J-P. Rosen 2014-07-10 15:57 ` Adam Beneschan 2014-07-10 17:47 ` Tero Koskinen 2014-07-10 19:15 ` Jeffrey Carter 2014-07-15 5:56 ` anon 2014-07-15 7:36 ` Georg Bauhaus 2014-07-15 17:01 ` Simon Wright 2014-07-15 17:23 ` Jeffrey Carter 2014-07-15 19:44 ` Simon Wright 2014-07-15 17:47 ` G.B. 2014-07-15 17:51 ` Adam Beneschan 2014-07-15 20:04 ` Simon Wright 2014-07-16 7:19 ` anon 2014-07-10 15:54 ` Adam Beneschan
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox