comp.lang.ada
 help / color / mirror / Atom feed
* Child packages named Ada illegal?
@ 2012-10-31 16:47 Marius Amado-Alves
  2012-10-31 17:02 ` Shark8
  2012-10-31 17:20 ` Adam Beneschan
  0 siblings, 2 replies; 8+ messages in thread
From: Marius Amado-Alves @ 2012-10-31 16:47 UTC (permalink / raw)


I was getting misleading <<missing "with Ada...">> errors from GNAT (the packages were withen). In a moment of inspiration I renamed package AA.Languages.Ada to AA.Languages.Ada_Languages and all went well.

Just curious: was GNAT misbehaving (unlikely) or is it somehow forbidden to have child packages named Ada?

Thanks.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Child packages named Ada illegal?
  2012-10-31 16:47 Child packages named Ada illegal? Marius Amado-Alves
@ 2012-10-31 17:02 ` Shark8
  2012-10-31 17:20 ` Adam Beneschan
  1 sibling, 0 replies; 8+ messages in thread
From: Shark8 @ 2012-10-31 17:02 UTC (permalink / raw)


It's probably an issue of visibility. Consider:

with Ada.Calendar.Time;
Procedure Test is
    package Ada is
    end Ada;
    
    Now : Constant Ada.Calendar.Time:= Ada.Calendar.Clock;
Begin
  null;
End Test;

In this case the Now declaration is prevented from being valid because the type, Time, resides in the package Calendar which is a child of Ada... but Ada at that point refers to Test.Ada which has no Calendar child package.

That te following compiles indicates Ada is not reserved:
Procedure Test is
    Now : Constant Ada.Calendar.Time:= Ada.Calendar.Clock;
Begin
    declare
	package Ada is
	end Ada;
	
    begin
	null;
    end;
End Test;



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Child packages named Ada illegal?
  2012-10-31 16:47 Child packages named Ada illegal? Marius Amado-Alves
  2012-10-31 17:02 ` Shark8
@ 2012-10-31 17:20 ` Adam Beneschan
  2012-10-31 17:59   ` Marius Amado-Alves
  1 sibling, 1 reply; 8+ messages in thread
From: Adam Beneschan @ 2012-10-31 17:20 UTC (permalink / raw)


On Wednesday, October 31, 2012 9:47:04 AM UTC-7, Marius Amado-Alves wrote:
> I was getting misleading <<missing "with Ada...">> errors from GNAT (the packages were withen). In a moment of inspiration I renamed package AA.Languages.Ada to AA.Languages.Ada_Languages and all went well.
> 
> Just curious: was GNAT misbehaving (unlikely) or is it somehow forbidden to have child packages named Ada?
> 

Without seeing your exact code, it's hard to say for sure, but Shark8 is probably right that it's a visibility issue.  If you're inside AA.Languages.Ada, and you refer to the identifier Ada without any other qualification, then that identifier would refer to your child package, not the top level Ada package.  (Standard.Ada would still get you the top-level package.)  The error messages are confusing, though.  I can understand it, because 99.9999% of the time when a user uses one of the language-defined package names and it isn't defined, it's because they forgot to WITH it; the GNAT people apparently didn't think of this possibility, which is understandable.

                           -- Adam



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Child packages named Ada illegal?
  2012-10-31 17:20 ` Adam Beneschan
@ 2012-10-31 17:59   ` Marius Amado-Alves
  2012-10-31 18:16     ` Adam Beneschan
  0 siblings, 1 reply; 8+ messages in thread
From: Marius Amado-Alves @ 2012-10-31 17:59 UTC (permalink / raw)


Thanks. The package is as follows (the entire thing is at sourceforge.net/projects/aalibrary/). GNAT shouts <<missing "with Ada.Characters;">> at line "(if Ada...);". The fix is to rename the package AA.Languages.Ada_Language. The Standard.Ada trick doesn't work.

with Ada.Characters.Handling;
...
package body AA.Languages.Ada is
   ...
   function Non_Alphanum_To_Underscore (From : Character) return Character is
      (if Ada.Characters.Handling.Is_Alphanumeric (From) then From else '_');
   ...
end;



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Child packages named Ada illegal?
  2012-10-31 17:59   ` Marius Amado-Alves
@ 2012-10-31 18:16     ` Adam Beneschan
  2012-10-31 18:41       ` Marius Amado-Alves
  0 siblings, 1 reply; 8+ messages in thread
From: Adam Beneschan @ 2012-10-31 18:16 UTC (permalink / raw)


On Wednesday, October 31, 2012 10:59:26 AM UTC-7, Marius Amado-Alves wrote:
> Thanks. The package is as follows (the entire thing is at sourceforge.net/projects/aalibrary/). GNAT shouts <<missing "with Ada.Characters;">> at line "(if Ada...);". The fix is to rename the package AA.Languages.Ada_Language. The Standard.Ada trick doesn't work.

Hmmm ... interesting, it should work.  I'm using an earlier version of GNAT that doesn't support Ada 2012 syntax, so I had to rewrite the function to try your example.  But it worked fine (inside AA.Languages.Ada) when I referred to Standard.Ada.Characters.Handling.Is_Alphanumeric.  So maybe this is a recently introduced bug?

                           -- Adam


> with Ada.Characters.Handling;
> ...
> package body AA.Languages.Ada is
>    ...
>    function Non_Alphanum_To_Underscore (From : Character) return Character is
>       (if Ada.Characters.Handling.Is_Alphanumeric (From) then From else '_'); 
>    ...
> end;




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Child packages named Ada illegal?
  2012-10-31 18:16     ` Adam Beneschan
@ 2012-10-31 18:41       ` Marius Amado-Alves
  2012-10-31 19:39         ` Shark8
  2012-11-01  9:27         ` AdaMagica
  0 siblings, 2 replies; 8+ messages in thread
From: Marius Amado-Alves @ 2012-10-31 18:41 UTC (permalink / raw)


>> ... The Standard.Ada trick doesn't work.
> 
> Hmmm ... interesting, it should work.

Sorry, it does work. Sorry.

/*
I had boobed with the packages file names with all the renaming and copying. And I was writing "with Standard.Ada...." GNAT does not allow that. But we can with Ada.Characters and use Standard.Ada.Characters.

I had never wrote Standard.Ada... before. Sometimes I write Standard.Integer and such, but for some reason Standard.Ada looked strange to me.
*/



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Child packages named Ada illegal?
  2012-10-31 18:41       ` Marius Amado-Alves
@ 2012-10-31 19:39         ` Shark8
  2012-11-01  9:27         ` AdaMagica
  1 sibling, 0 replies; 8+ messages in thread
From: Shark8 @ 2012-10-31 19:39 UTC (permalink / raw)


> package body AA.Languages.Ada is
>    ...
>    function Non_Alphanum_To_Underscore (From : Character) return Character is
>       (if Ada.Characters.Handling.Is_Alphanumeric (From) then From else '_');
>    ...
> end;

One option would be to put package renaming inside the AA or Languages package; thus:

with Ada.Characters;
Package AA.Language is
...
package Internal_Characters Renames Ada.Characters;
End AA.Language;

would allow you to refer to Ada.Characters via the Internal_Characters name.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Child packages named Ada illegal?
  2012-10-31 18:41       ` Marius Amado-Alves
  2012-10-31 19:39         ` Shark8
@ 2012-11-01  9:27         ` AdaMagica
  1 sibling, 0 replies; 8+ messages in thread
From: AdaMagica @ 2012-11-01  9:27 UTC (permalink / raw)


On Wednesday, October 31, 2012 7:41:12 PM UTC+1, Marius Amado-Alves wrote:
> I had boobed with the packages file names with all the renaming and copying. And I was writing "with Standard.Ada...." GNAT does not allow that. But we can with Ada.Characters and use Standard.Ada.Characters.

GNAT does allow this, but then Standard is a package that you defined like  so:

package Standard is
  ....
end Standard;

This is of course very bad because it hides the name of the predefined package Standard. Thus, if you haven't defined such a package Standard, GNAT refused a with clause beginning with Standard.

(Visibility rules in context clauses are a bit different from the rest of source code.)



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2012-11-01  9:27 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-31 16:47 Child packages named Ada illegal? Marius Amado-Alves
2012-10-31 17:02 ` Shark8
2012-10-31 17:20 ` Adam Beneschan
2012-10-31 17:59   ` Marius Amado-Alves
2012-10-31 18:16     ` Adam Beneschan
2012-10-31 18:41       ` Marius Amado-Alves
2012-10-31 19:39         ` Shark8
2012-11-01  9:27         ` AdaMagica

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox