comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <stephen.a.leake.1@gsfc.nasa.gov>
Subject: Re: JGNAT and Null references
Date: 02 Mar 2001 14:27:57 -0500
Date: 2001-03-02T19:41:48+00:00	[thread overview]
Message-ID: <uy9uoynr6.fsf@gsfc.nasa.gov> (raw)
In-Reply-To: 3A9E77D4.D40FEAA@earthlink.net

"Marc A. Criley" <mcqnet@earthlink.net> writes:

> Let me just plow right into an annotated example here, rather than
> trying to explain it first...
> 
> The Java class javax.swing.JTabbedPane provides a method called addTab
> that looks like this:
> 
> public void addTab(String title,
>                    Icon icon,
>                    Component component,
>                    String tip)
> 
> When this class is run through JGNAT's jvm2ada, the Ada equivalent of
> that method is:
> 
>    procedure addTab (This : access Typ; 
>                      P1_String : access java.lang.String.Typ'Class; 
>                      P2_Icon : access javax.swing.Icon.Typ'Class; 
>                      P3_Component : access java.awt.Component.Typ'Class; 
>                      P4_String : access java.lang.String.Typ'Class);
> 
> Okay, so far so good.
> 
> In Java, if I don't have an icon to accompany this tab pane, I can just
> supply that parameter with a null:
> 
>    jtp.addTab("My title", null, a_component, "a_tool_tip");
> 
> Attempting this in Ada:
> 
>    AddTab(Jtp, +"My title", null, A_Component, +"a_tool_tip");
> 
> generates an error when compiled:
> 
>    null cannot be of an anonymous access type

This is a bug in jvm2ada; if addTab can accept "null" for Icon, the
Ada version should not be an access parameter, it should be an "in"
parameter of an access type. I'm not clear how jvm2ada can tell
whether "null" is valid; seems like it would have to read the body of
the class, or the programmer's mind, or something. Apparently it just
assumes "null" is never valid.

Report it to report@gnat.com.

In the meantime, you can probably just edit the spec where AddTab is
defined, to pass an "in" parameter of an appropriate access type,
which can then be "null". Not fun, but it should work.

>   What
> do I provide as a "null argument" in JGNAT?  I was hoping to find some
> sort of predefined "null_reference" constant, analogous to
> System.Null_Address, but no such luck.

You can't pass "null", in any form. Defining it as a constant won't
work; the compiler is smarter than that!

If you don't want to edit the spec for AddTab, you will have to define
an Icon somewhere (but don't ask me how), and pass that instead of
null.

-- 
-- Stephe



  parent reply	other threads:[~2001-03-02 19:27 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-03-01 17:23 JGNAT and Null references Marc A. Criley
2001-03-01 18:10 ` James Rogers
2001-03-02 19:27 ` Stephen Leake [this message]
2001-03-03 21:17   ` Marc A. Criley
2001-03-04  2:46     ` Randy Brukardt
2001-03-05 13:05       ` Marc A. Criley
2001-03-05 16:28         ` tmoran
2001-03-06  0:57           ` Marc A. Criley
2001-03-05 18:11         ` Randy Brukardt
2001-03-05 20:44         ` Florian Weimer
2001-03-07 16:02       ` Tucker Taft
replies disabled

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