Re: [sv-ec] Re: super and virtual func.


Subject: Re: [sv-ec] Re: super and virtual func.
From: Kevin Cameron (sv-xx@grfx.com)
Date: Thu Feb 13 2003 - 00:11:17 PST


> From: "Arturo Salz" <Arturo.Salz@synopsys.com>
>
> Kevin,
>
> Are you suggesting that super is restricted to work only
> with virtual routines? There is no such restriction in the
> LRM document. Super behaves exactly in the same
> way as <parent_class>:: in C++. In fact, the SV version
> of your example is:

The LRM says:

  To get the overridden method, the parent method needs to be
  declared virtual (see section 11.18).

- I don't see the need for the restriction, in C++ the methods
are visible whether they are virtual or not (you can strip all
the virtuals in my example and it still compiles - but runs a
little differently).

Kev.

> --------------------------------------------------------------------------------
>
> class foo;
> virtual task whoami() $display( "foo" ); endtask
> virtual task whoami2() $display( "foo" ); endtask
> endclass
>
> class bar extends foo;
> virtual task whoami() $display( "foo" ); endtask
> virtual task whoami2() super.whoami2(); endtask
> endclass
>
> task main;
> bar bq = new;
>
> bq.whoami();
> bq.whoami2();
> endtask
>
> initial main;
>
> --------------------------------------------------------------------------------
>
> - gives -
> bar
> foo
>
> You will note that whoami2 in class bar calls the virtual
> function whoami2 in the parent class. If this call were
> made as a virtual call, it would run as an infinite loop.
> Explicit qualification of the class via super (or :: in C++)
> always yields exactly that member (or property).
> If this were not the case, it wouldn't be possible to
> implement virtual destructors correctly in C++ (and
> destructors should always be virtual).
>
> Arturo
>
> ----- Original Message -----
> From: "Kevin Cameron x3251" <Kevin.Cameron@nsc.com>
> To: <sv-ec@eda.org>
> Sent: Tuesday, February 11, 2003 1:18 PM
> Subject: [sv-ec] Re: super and virtual func.
>
>
>
> C++ does not have the restriction that routines used with
> '::' should be virtual -
>
> #include <stdio.h>
>
> class foo {
> public:
> virtual void whoami() {printf("foo\n");};
> virtual void whoami2() {printf("foo\n");};
> };
> class bar : public foo {
> public:
> virtual void whoami() {printf("bar\n");};
> virtual void whoami2() {foo::whoami();};
> };
>
> void sub(foo *fp)
> {
> fp->whoami();
> fp->whoami2();
> }
>
> main()
> {
> bar bq;
>
> bq.whoami();
> bq.foo::whoami();
> bq.whoami2();
>
> sub(&bq);
> }
>
> - gives -
>
> bar
> foo
> foo
> bar
> foo
>
> A call with :: is not a virtual call, it's handled the same
> as a non-virtual call.
>
> I.e. the restriction in SV doesn't have a precedent in C++.
>
> Kev.
>



This archive was generated by hypermail 2b28 : Thu Feb 13 2003 - 01:47:13 PST