comp.lang.ada
 help / color / mirror / Atom feed
* JGNAT and Null references
@ 2001-03-01 17:23 Marc A. Criley
  2001-03-01 18:10 ` James Rogers
  2001-03-02 19:27 ` Stephen Leake
  0 siblings, 2 replies; 11+ messages in thread
From: Marc A. Criley @ 2001-03-01 17:23 UTC (permalink / raw)


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

which is perfectly correct since that P2_Icon parameter requires a
pointer to , or the "'access of" an actual object.

Buuuuuut, I don't have, or want to pass, an Icon to display with the
tab, and specifying "null" is how I would indicate that in Java.  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.

Thanks much,

Marc A. Criley



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

* Re: JGNAT and Null references
  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
  1 sibling, 0 replies; 11+ messages in thread
From: James Rogers @ 2001-03-01 18:10 UTC (permalink / raw)


"Marc A. Criley" wrote:
> 
> 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 easily handled by defining a constant value of a null access
type.

type Icon_Access is Access all javax.swing.Icon.Typ'Class;

Null_Icon : constant Icon_Access := Null;

Jim Rogers
Colorad Springs, Colorado USA



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

* Re: JGNAT and Null references
  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
  2001-03-03 21:17   ` Marc A. Criley
  1 sibling, 1 reply; 11+ messages in thread
From: Stephen Leake @ 2001-03-02 19:27 UTC (permalink / raw)


"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



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

* Re: JGNAT and Null references
  2001-03-02 19:27 ` Stephen Leake
@ 2001-03-03 21:17   ` Marc A. Criley
  2001-03-04  2:46     ` Randy Brukardt
  0 siblings, 1 reply; 11+ messages in thread
From: Marc A. Criley @ 2001-03-03 21:17 UTC (permalink / raw)


Stephen Leake wrote:
> 
> "Marc A. Criley" <mcqnet@earthlink.net> writes:
>  
> >   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!
> 

Uh...it did work.  Cleared up the problem just fine.  That it works
doesn't totally sit well with me, since my purist mental picture of a
"constant" involves only a value, and not storage.  Nonetheless, 

   Null_Icon : constant Javax.swing.TabbedPanel.ref := null;

was accepted by the AddTab procedure call.

Marc



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

* Re: JGNAT and Null references
  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-07 16:02       ` Tucker Taft
  0 siblings, 2 replies; 11+ messages in thread
From: Randy Brukardt @ 2001-03-04  2:46 UTC (permalink / raw)


Marc A. Criley wrote in message <3AA151BF.C9193700@earthlink.net>...
>Uh...it did work.  Cleared up the problem just fine.  That it works
>doesn't totally sit well with me, since my purist mental picture of a
>"constant" involves only a value, and not storage.  Nonetheless,
>
>   Null_Icon : constant Javax.swing.TabbedPanel.ref := null;
>
>was accepted by the AddTab procedure call.


But does it run? The RM  4.6(49) says that an access parameter cannot be
null, and must raise Constraint_Error. If it does run, you're using a
compiler bug (or "feature"); your code won't be portable...

        Randy.





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

* Re: JGNAT and Null references
  2001-03-04  2:46     ` Randy Brukardt
@ 2001-03-05 13:05       ` Marc A. Criley
  2001-03-05 16:28         ` tmoran
                           ` (2 more replies)
  2001-03-07 16:02       ` Tucker Taft
  1 sibling, 3 replies; 11+ messages in thread
From: Marc A. Criley @ 2001-03-05 13:05 UTC (permalink / raw)


Randy Brukardt wrote:
> 
> Marc A. Criley wrote in message <3AA151BF.C9193700@earthlink.net>...
> >Uh...it did work.  Cleared up the problem just fine.  That it works
> >doesn't totally sit well with me, since my purist mental picture of a
> >"constant" involves only a value, and not storage.  Nonetheless,
> >
> >   Null_Icon : constant Javax.swing.TabbedPanel.ref := null;
> >
> >was accepted by the AddTab procedure call.
> 
> But does it run? The RM  4.6(49) says that an access parameter cannot be
> null, and must raise Constraint_Error. If it does run, you're using a
> compiler bug (or "feature"); your code won't be portable...
> 
>         Randy.

Oh yes, it does run.

As I'm not a supported user of JGNAT, having access only to the public
1.1p version, I can't ask ACT about this.

My question, though, would be: If an access parameter cannot be null,
how am I supposed to pass a null argument to a Java method, given the
way jvm2ada generates the Ada binding?  Is the present behavior a bug? 
Is it a JGNAT-specific extension that perhaps ought to be wrapped in the
Extensions_Allowed behavior?

As for portability, unless there's a standard approach for defining Ada
bindings to Java classes and methods, I suspect I'm strongly wrapped up
in JGNAT-specificity anyways.

Marc



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

* Re: JGNAT and Null references
  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
  2 siblings, 1 reply; 11+ messages in thread
From: tmoran @ 2001-03-05 16:28 UTC (permalink / raw)


> But does it run? The RM  4.6(49) says that an access parameter cannot be
> null, and must raise Constraint_Error. If it does run, you're using a
  Have any Ada->JVM compilers been validated?

>As for portability, unless there's a standard approach for defining Ada
>bindings to Java classes and methods, I suspect I'm strongly wrapped up
>in JGNAT-specificity anyways.
  Have you tried it with the Aonix (Averstar) Ada->JVM compiler?



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

* Re: JGNAT and Null references
  2001-03-05 13:05       ` Marc A. Criley
  2001-03-05 16:28         ` tmoran
@ 2001-03-05 18:11         ` Randy Brukardt
  2001-03-05 20:44         ` Florian Weimer
  2 siblings, 0 replies; 11+ messages in thread
From: Randy Brukardt @ 2001-03-05 18:11 UTC (permalink / raw)


Marc A. Criley wrote in message <3AA3815B.11B1A073@earthlink.net>...

>My question, though, would be: If an access parameter cannot be null,
>how am I supposed to pass a null argument to a Java method, given the
>way jvm2ada generates the Ada binding?  Is the present behavior a bug?
>Is it a JGNAT-specific extension that perhaps ought to be wrapped in
the
>Extensions_Allowed behavior?

I would think it is a bug and/or extension. My first thought is that it
is a bug in jvm2ada, but perhaps they are planning to ignore the RM
rule. (But then, of course, it should be under the extensions flag, as
you note.)

            Randy.






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

* Re: JGNAT and Null references
  2001-03-05 13:05       ` Marc A. Criley
  2001-03-05 16:28         ` tmoran
  2001-03-05 18:11         ` Randy Brukardt
@ 2001-03-05 20:44         ` Florian Weimer
  2 siblings, 0 replies; 11+ messages in thread
From: Florian Weimer @ 2001-03-05 20:44 UTC (permalink / raw)


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

> As I'm not a supported user of JGNAT, having access only to the public
> 1.1p version, I can't ask ACT about this.

You could send in a problem report nevertheless, maybe this problem is
addressed in a future version even though you aren't a supported
customer.



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

* Re: JGNAT and Null references
  2001-03-05 16:28         ` tmoran
@ 2001-03-06  0:57           ` Marc A. Criley
  0 siblings, 0 replies; 11+ messages in thread
From: Marc A. Criley @ 2001-03-06  0:57 UTC (permalink / raw)


tmoran@acm.org wrote:
> 
> > But does it run? The RM  4.6(49) says that an access parameter cannot be
> > null, and must raise Constraint_Error. If it does run, you're using a
>   Have any Ada->JVM compilers been validated?

Dunno.

> 
> >As for portability, unless there's a standard approach for defining Ada
> >bindings to Java classes and methods, I suspect I'm strongly wrapped up
> >in JGNAT-specificity anyways.
>   Have you tried it with the Aonix (Averstar) Ada->JVM compiler?

Nope.  Is that part of the trial ObjectAda compiler package?



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

* Re: JGNAT and Null references
  2001-03-04  2:46     ` Randy Brukardt
  2001-03-05 13:05       ` Marc A. Criley
@ 2001-03-07 16:02       ` Tucker Taft
  1 sibling, 0 replies; 11+ messages in thread
From: Tucker Taft @ 2001-03-07 16:02 UTC (permalink / raw)


Randy Brukardt wrote:
> 
> Marc A. Criley wrote in message <3AA151BF.C9193700@earthlink.net>...
> >Uh...it did work.  Cleared up the problem just fine.  That it works
> >doesn't totally sit well with me, since my purist mental picture of a
> >"constant" involves only a value, and not storage.  Nonetheless,
> >
> >   Null_Icon : constant Javax.swing.TabbedPanel.ref := null;
> >
> >was accepted by the AddTab procedure call.
> 
> But does it run? The RM  4.6(49) says that an access parameter cannot be
> null, and must raise Constraint_Error. If it does run, you're using a
> compiler bug (or "feature"); your code won't be portable...

There was discussion of avoiding the null check when interfacing
with code from some other language (e.g. C or Java).  Given that the
rules for making Java-convention calls are not standardized at
this point, so long as there is an explicit (or implicit?) Java
convention on the routines, JGNAT can do what it wants at this point.

> 
>         Randy.

-- 
-Tucker Taft   stt@avercom.net   http://www.averstar.com/~stt/
Chief Technology Officer, AverCom Corporation (A Titan Company) 
Burlington, MA  USA (AverCom was formerly the Commercial Division of AverStar:
http://www.averstar.com/services/ebusiness_applications.html)



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

end of thread, other threads:[~2001-03-07 16:02 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

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