public inbox for java@gcc.gnu.org
 help / color / mirror / Atom feed
* instanceof in CNI
@ 2000-03-25  3:59 Oskar Liljeblad
  2000-03-25  4:09 ` Bryce McKinlay
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Oskar Liljeblad @ 2000-03-25  3:59 UTC (permalink / raw)
  To: java-discuss

Hello

Is there anything similar to the Java instanceof operatior in C++/CNI?

Oskar Liljeblad (osk@hem.passagen.se)

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

* Re: instanceof in CNI
  2000-03-25  3:59 instanceof in CNI Oskar Liljeblad
@ 2000-03-25  4:09 ` Bryce McKinlay
  2000-03-25  8:23   ` Tom Tromey
  2000-04-01  0:00   ` Bryce McKinlay
  2000-03-27 11:23 ` ks
  2000-04-01  0:00 ` Oskar Liljeblad
  2 siblings, 2 replies; 16+ messages in thread
From: Bryce McKinlay @ 2000-03-25  4:09 UTC (permalink / raw)
  To: java-discuss

Oskar Liljeblad wrote:

> Is there anything similar to the Java instanceof operatior in C++/CNI?

You can use _Jv_IsInstanceOf(object, class)

To get a reference to a Class object to compare against, you currently
have to use Class::forName(), or compare against the mangled symbolic
class name directly. This is something we're looking at addressing soon
in gcjh.

regards

  [ bryce ]

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

* Re: instanceof in CNI
  2000-03-25  4:09 ` Bryce McKinlay
@ 2000-03-25  8:23   ` Tom Tromey
  2000-03-25 21:05     ` Per Bothner
  2000-04-01  0:00     ` Tom Tromey
  2000-04-01  0:00   ` Bryce McKinlay
  1 sibling, 2 replies; 16+ messages in thread
From: Tom Tromey @ 2000-03-25  8:23 UTC (permalink / raw)
  To: Bryce McKinlay; +Cc: java-discuss

>> Is there anything similar to the Java instanceof operatior in C++/CNI?

Bryce> You can use _Jv_IsInstanceOf(object, class)

Usually we recommend only using "Jv" functions and not "_Jv_"
functions.  The former are exported and the latter are not.

I recommend using Class::isInstance.

Bryce> To get a reference to a Class object to compare against, you
Bryce> currently have to use Class::forName(), or compare against the
Bryce> mangled symbolic class name directly. This is something we're
Bryce> looking at addressing soon in gcjh.

Lately I've been thinking gcjh could generate a per-class inline
function named something like "$class"; I got this idea because
apparently javac generates an internal function named "class$" to
implement the ".class" notation.

Comments?  Naming here is the big problem, as I see it.

Tom

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

* Re: instanceof in CNI
  2000-03-25  8:23   ` Tom Tromey
@ 2000-03-25 21:05     ` Per Bothner
  2000-03-25 23:25       ` Tom Tromey
  2000-04-01  0:00       ` Per Bothner
  2000-04-01  0:00     ` Tom Tromey
  1 sibling, 2 replies; 16+ messages in thread
From: Per Bothner @ 2000-03-25 21:05 UTC (permalink / raw)
  To: Tom Tromey; +Cc: java-discuss

Tom Tromey <tromey@cygnus.com> writes:

> Lately I've been thinking gcjh could generate a per-class inline
> function named something like "$class"; I got this idea because
> apparently javac generates an internal function named "class$" to
> implement the ".class" notation.

The compiler generates a static field the the actuall
Class object.  If we picked a good name for this,
we could have gcjg also emit it.

E.g.
class java::lang::String : public java::lang::Object
{
  java::lang::Class $class;
}

Then you'd just reference String::$class .
-- 
	--Per Bothner
per@bothner.com   http://www.bothner.com/~per/

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

* Re: instanceof in CNI
  2000-03-25 21:05     ` Per Bothner
@ 2000-03-25 23:25       ` Tom Tromey
  2000-03-26 21:01         ` Per Bothner
  2000-04-01  0:00         ` Tom Tromey
  2000-04-01  0:00       ` Per Bothner
  1 sibling, 2 replies; 16+ messages in thread
From: Tom Tromey @ 2000-03-25 23:25 UTC (permalink / raw)
  To: Per Bothner; +Cc: Tom Tromey, java-discuss

Per> class java::lang::String : public java::lang::Object
Per> {
Per>   java::lang::Class $class;
Per> }
Per> Then you'd just reference String::$class .

Do you mean `Class *$class'?  To me that seems more natural.  We could
do that without changing the mangling or anything; just add a new
static to each class.

Tom

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

* Re: instanceof in CNI
  2000-03-25 23:25       ` Tom Tromey
@ 2000-03-26 21:01         ` Per Bothner
  2000-04-01  0:00           ` Per Bothner
  2000-04-01  0:00         ` Tom Tromey
  1 sibling, 1 reply; 16+ messages in thread
From: Per Bothner @ 2000-03-26 21:01 UTC (permalink / raw)
  To: Tom Tromey; +Cc: java-discuss

Tom Tromey <tromey@cygnus.com> writes:
> Do you mean `Class *$class'?  To me that seems more natural.  We could
> do that without changing the mangling or anything; just add a new
> static to each class.

No, I mean Class $class.  The thing is - we already generate a
static Class field (not Class* field) - the actual Class object.
We just need to make sure it has a reasonable name (`class'
would be nice, since that's what Java does in the syntax `String.class'.
Unfortunately, the C++ parser won't like that, without ugly hacking
that seems hard to justify.  Hence `$class'.

There are other options, including the inline function you
suggested, or a builtin operator like __jv_classof.  I like
the simplicit of using thefield we are already generating.
I think we are currently calling it `class'.

	--Per Bothner
per@bothner.com   http://www.bothner.com/~per/

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

* Re: instanceof in CNI
  2000-03-25  3:59 instanceof in CNI Oskar Liljeblad
  2000-03-25  4:09 ` Bryce McKinlay
@ 2000-03-27 11:23 ` ks
  2000-03-27 11:33   ` Tom Tromey
  2000-04-01  0:00   ` ks
  2000-04-01  0:00 ` Oskar Liljeblad
  2 siblings, 2 replies; 16+ messages in thread
From: ks @ 2000-03-27 11:23 UTC (permalink / raw)
  To: osk, java-discuss

The standard C++ mechanism is to use RTTI as in:

   typeof<foo> == typeof<bar>

but I think that C++ RTTI interferes with Java if I remember correctly.

On Sat, Mar 25, 2000 at 12:52:54PM +0100, osk@hem.passagen.se wrote:
> Hello
> 
> Is there anything similar to the Java instanceof operatior in C++/CNI?
> 
> Oskar Liljeblad (osk@hem.passagen.se)

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

* Re: instanceof in CNI
  2000-03-27 11:23 ` ks
@ 2000-03-27 11:33   ` Tom Tromey
  2000-04-01  0:00     ` Tom Tromey
  2000-04-01  0:00   ` ks
  1 sibling, 1 reply; 16+ messages in thread
From: Tom Tromey @ 2000-03-27 11:33 UTC (permalink / raw)
  To: ks; +Cc: osk, java-discuss

>>>>> "ks" == ks  <ks@micky.rgv.hp.com> writes:

ks> The standard C++ mechanism is to use RTTI as in:
ks>    typeof<foo> == typeof<bar>
ks> but I think that C++ RTTI interferes with Java if I remember correctly.

That's right, they don't interoperate.
This would probably be a good thing to do.
However, it is a very low priority for us; odds are it will have to
wait for a net volunteer to write it.

Tom

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

* instanceof in CNI
  2000-03-25  3:59 instanceof in CNI Oskar Liljeblad
  2000-03-25  4:09 ` Bryce McKinlay
  2000-03-27 11:23 ` ks
@ 2000-04-01  0:00 ` Oskar Liljeblad
  2 siblings, 0 replies; 16+ messages in thread
From: Oskar Liljeblad @ 2000-04-01  0:00 UTC (permalink / raw)
  To: java-discuss

Hello

Is there anything similar to the Java instanceof operatior in C++/CNI?

Oskar Liljeblad (osk@hem.passagen.se)

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

* Re: instanceof in CNI
  2000-03-27 11:33   ` Tom Tromey
@ 2000-04-01  0:00     ` Tom Tromey
  0 siblings, 0 replies; 16+ messages in thread
From: Tom Tromey @ 2000-04-01  0:00 UTC (permalink / raw)
  To: ks; +Cc: osk, java-discuss

>>>>> "ks" == ks  <ks@micky.rgv.hp.com> writes:

ks> The standard C++ mechanism is to use RTTI as in:
ks>    typeof<foo> == typeof<bar>
ks> but I think that C++ RTTI interferes with Java if I remember correctly.

That's right, they don't interoperate.
This would probably be a good thing to do.
However, it is a very low priority for us; odds are it will have to
wait for a net volunteer to write it.

Tom

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

* Re: instanceof in CNI
  2000-03-25 23:25       ` Tom Tromey
  2000-03-26 21:01         ` Per Bothner
@ 2000-04-01  0:00         ` Tom Tromey
  1 sibling, 0 replies; 16+ messages in thread
From: Tom Tromey @ 2000-04-01  0:00 UTC (permalink / raw)
  To: Per Bothner; +Cc: Tom Tromey, java-discuss

Per> class java::lang::String : public java::lang::Object
Per> {
Per>   java::lang::Class $class;
Per> }
Per> Then you'd just reference String::$class .

Do you mean `Class *$class'?  To me that seems more natural.  We could
do that without changing the mangling or anything; just add a new
static to each class.

Tom

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

* Re: instanceof in CNI
  2000-03-27 11:23 ` ks
  2000-03-27 11:33   ` Tom Tromey
@ 2000-04-01  0:00   ` ks
  1 sibling, 0 replies; 16+ messages in thread
From: ks @ 2000-04-01  0:00 UTC (permalink / raw)
  To: osk, java-discuss

The standard C++ mechanism is to use RTTI as in:

   typeof<foo> == typeof<bar>

but I think that C++ RTTI interferes with Java if I remember correctly.

On Sat, Mar 25, 2000 at 12:52:54PM +0100, osk@hem.passagen.se wrote:
> Hello
> 
> Is there anything similar to the Java instanceof operatior in C++/CNI?
> 
> Oskar Liljeblad (osk@hem.passagen.se)

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

* Re: instanceof in CNI
  2000-03-25 21:05     ` Per Bothner
  2000-03-25 23:25       ` Tom Tromey
@ 2000-04-01  0:00       ` Per Bothner
  1 sibling, 0 replies; 16+ messages in thread
From: Per Bothner @ 2000-04-01  0:00 UTC (permalink / raw)
  To: Tom Tromey; +Cc: java-discuss

Tom Tromey <tromey@cygnus.com> writes:

> Lately I've been thinking gcjh could generate a per-class inline
> function named something like "$class"; I got this idea because
> apparently javac generates an internal function named "class$" to
> implement the ".class" notation.

The compiler generates a static field the the actuall
Class object.  If we picked a good name for this,
we could have gcjg also emit it.

E.g.
class java::lang::String : public java::lang::Object
{
  java::lang::Class $class;
}

Then you'd just reference String::$class .
-- 
	--Per Bothner
per@bothner.com   http://www.bothner.com/~per/

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

* Re: instanceof in CNI
  2000-03-25  4:09 ` Bryce McKinlay
  2000-03-25  8:23   ` Tom Tromey
@ 2000-04-01  0:00   ` Bryce McKinlay
  1 sibling, 0 replies; 16+ messages in thread
From: Bryce McKinlay @ 2000-04-01  0:00 UTC (permalink / raw)
  To: java-discuss

Oskar Liljeblad wrote:

> Is there anything similar to the Java instanceof operatior in C++/CNI?

You can use _Jv_IsInstanceOf(object, class)

To get a reference to a Class object to compare against, you currently
have to use Class::forName(), or compare against the mangled symbolic
class name directly. This is something we're looking at addressing soon
in gcjh.

regards

  [ bryce ]

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

* Re: instanceof in CNI
  2000-03-26 21:01         ` Per Bothner
@ 2000-04-01  0:00           ` Per Bothner
  0 siblings, 0 replies; 16+ messages in thread
From: Per Bothner @ 2000-04-01  0:00 UTC (permalink / raw)
  To: Tom Tromey; +Cc: java-discuss

Tom Tromey <tromey@cygnus.com> writes:
> Do you mean `Class *$class'?  To me that seems more natural.  We could
> do that without changing the mangling or anything; just add a new
> static to each class.

No, I mean Class $class.  The thing is - we already generate a
static Class field (not Class* field) - the actual Class object.
We just need to make sure it has a reasonable name (`class'
would be nice, since that's what Java does in the syntax `String.class'.
Unfortunately, the C++ parser won't like that, without ugly hacking
that seems hard to justify.  Hence `$class'.

There are other options, including the inline function you
suggested, or a builtin operator like __jv_classof.  I like
the simplicit of using thefield we are already generating.
I think we are currently calling it `class'.

	--Per Bothner
per@bothner.com   http://www.bothner.com/~per/

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

* Re: instanceof in CNI
  2000-03-25  8:23   ` Tom Tromey
  2000-03-25 21:05     ` Per Bothner
@ 2000-04-01  0:00     ` Tom Tromey
  1 sibling, 0 replies; 16+ messages in thread
From: Tom Tromey @ 2000-04-01  0:00 UTC (permalink / raw)
  To: Bryce McKinlay; +Cc: java-discuss

>> Is there anything similar to the Java instanceof operatior in C++/CNI?

Bryce> You can use _Jv_IsInstanceOf(object, class)

Usually we recommend only using "Jv" functions and not "_Jv_"
functions.  The former are exported and the latter are not.

I recommend using Class::isInstance.

Bryce> To get a reference to a Class object to compare against, you
Bryce> currently have to use Class::forName(), or compare against the
Bryce> mangled symbolic class name directly. This is something we're
Bryce> looking at addressing soon in gcjh.

Lately I've been thinking gcjh could generate a per-class inline
function named something like "$class"; I got this idea because
apparently javac generates an internal function named "class$" to
implement the ".class" notation.

Comments?  Naming here is the big problem, as I see it.

Tom

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

end of thread, other threads:[~2000-04-01  0:00 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-03-25  3:59 instanceof in CNI Oskar Liljeblad
2000-03-25  4:09 ` Bryce McKinlay
2000-03-25  8:23   ` Tom Tromey
2000-03-25 21:05     ` Per Bothner
2000-03-25 23:25       ` Tom Tromey
2000-03-26 21:01         ` Per Bothner
2000-04-01  0:00           ` Per Bothner
2000-04-01  0:00         ` Tom Tromey
2000-04-01  0:00       ` Per Bothner
2000-04-01  0:00     ` Tom Tromey
2000-04-01  0:00   ` Bryce McKinlay
2000-03-27 11:23 ` ks
2000-03-27 11:33   ` Tom Tromey
2000-04-01  0:00     ` Tom Tromey
2000-04-01  0:00   ` ks
2000-04-01  0:00 ` Oskar Liljeblad

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).