Subject: Re: [sv-ec] Re: super and virtual func.
From: Kevin Cameron x3251 (Kevin.Cameron@nsc.com)
Date: Thu Feb 13 2003 - 09:16:12 PST
----------
X-Sun-Data-Type: text
X-Sun-Data-Description: text
X-Sun-Data-Name: text
X-Sun-Charset: us-ascii
X-Sun-Content-Lines: 144
> From: "Arturo Salz" <Arturo.Salz@synopsys.com>
>
> Kevin,
>
> Now I understand. Your issue is not with the semantics of super, but with that particular paragraph.
>
> I can see why it may be confusing. What if that paragraph is changed to:
>
> To call the overridden method from a parent class object (p in the example), the method needs to be declared virtual (see section 11.18).
>
> Arturo
Better - I see what was intended, maybe an example would make it clearer.
Kev.
>
> ----- Original Message -----
> From: "Kevin Cameron" <sv-xx@grfx.com>
> To: <sv-ec@eda.org>
> Cc: <Arturo.Salz@synopsys.COM>
> Sent: Thursday, February 13, 2003 12:11 AM
> Subject: Re: [sv-ec] Re: super and virtual func.
>
>
> > 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.
> >
>
----------
X-Sun-Data-Type: html
X-Sun-Encoding-Info: quoted-printable
X-Sun-Content-Length: 6629
X-Sun-Content-Lines: 142
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4807.2300" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2>Kevin,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Now I understand. Your issue =
is not with=20
the semantics of super, </FONT><FONT face=3DArial size=3D2>but with that =
particular=20
paragraph.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>I can see why it may be =
confusing. What if=20
that paragraph is changed to:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2> To call the =
overridden method=20
from a parent class object (p in the example), the method needs to =
be=20
declared virtual (see section 11.18).</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2> Arturo</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>----- Original Message ----- </FONT>
<DIV><FONT face=3DArial size=3D2>From: "Kevin Cameron" <</FONT><A=20
href=3D"mailto:sv-xx@grfx.com"><FONT face=3DArial=20
size=3D2>sv-xx@grfx.com</FONT></A><FONT face=3DArial =
size=3D2>></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>To: <</FONT><A =
href=3D"mailto:sv-ec@eda.org"><FONT=20
face=3DArial size=3D2>sv-ec@eda.org</FONT></A><FONT face=3DArial=20
size=3D2>></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Cc: <</FONT><A=20
href=3D"mailto:Arturo.Salz@synopsys.COM"><FONT face=3DArial=20
size=3D2>Arturo.Salz@synopsys.COM</FONT></A><FONT face=3DArial=20
size=3D2>></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Sent: Thursday, February 13, 2003 12:11 =
AM</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Subject: Re: [sv-ec] Re: super and =
virtual=20
func.</FONT></DIV></DIV>
<DIV><FONT face=3DArial><BR><FONT size=3D2></FONT></FONT></DIV><FONT =
face=3DArial=20
size=3D2>> From: "Arturo Salz" <</FONT><A=20
href=3D"mailto:Arturo.Salz@synopsys.com"><FONT face=3DArial=20
size=3D2>Arturo.Salz@synopsys.com</FONT></A><FONT face=3DArial =
size=3D2>><BR>>=20
<BR>> Kevin,<BR>> <BR>> Are you suggesting that super is =
restricted to=20
work only<BR>> with virtual routines? There is no such =
restriction in=20
the<BR>> LRM document. Super behaves exactly in the =
same<BR>> way as=20
<parent_class>:: in C++. In fact, the SV version<BR>> of =
your=20
example is:<BR><BR>The LRM says:<BR><BR> To get the overridden =
method, the=20
parent method needs to be<BR> declared virtual (see section=20
11.18).<BR><BR>- I don't see the need for the restriction, in C++ the=20
methods<BR>are visible whether they are virtual or not (you can strip =
all<BR>the=20
virtuals in my example and it still compiles - but runs a<BR>little=20
differently).<BR><BR>Kev.<BR><BR>>=20
-------------------------------------------------------------------------=
-------<BR>>=20
<BR>> class foo;<BR>> virtual task whoami() $display( =
"foo" );=20
endtask<BR>> virtual task whoami2() $display( "foo" );=20
endtask<BR>> endclass<BR>> <BR>> class bar extends=20
foo;<BR>> virtual task whoami() $display( "foo" );=20
endtask<BR>> virtual task whoami2() super.whoami2();=20
endtask<BR>> endclass<BR>> <BR>> task main;<BR>> =
bar bq =3D new;<BR>> <BR>> =20
bq.whoami();<BR>> bq.whoami2();<BR>> endtask<BR>> =
<BR>>=20
initial main;<BR>> <BR>>=20
-------------------------------------------------------------------------=
-------<BR>>=20
<BR>> - gives -<BR>> =20
bar<BR>> foo<BR>> <BR>> You will note =
that=20
whoami2 in class bar calls the virtual<BR>> function whoami2 in the =
parent=20
class. If this call were<BR>> made as a virtual call, it would =
run as=20
an infinite loop.<BR>> Explicit qualification of the class via super =
(or ::=20
in C++)<BR>> always yields exactly that member (or property).<BR>> =
If this=20
were not the case, it wouldn't be possible to<BR>> implement virtual=20
destructors correctly in C++ (and<BR>> destructors should always be=20
virtual).<BR>> <BR>> Arturo<BR>> =
<BR>> -----=20
Original Message ----- <BR>> From: "Kevin Cameron x3251" =
<</FONT><A=20
href=3D"mailto:Kevin.Cameron@nsc.com"><FONT face=3DArial=20
size=3D2>Kevin.Cameron@nsc.com</FONT></A><FONT face=3DArial =
size=3D2>><BR>> To:=20
<</FONT><A href=3D"mailto:sv-ec@eda.org"><FONT face=3DArial=20
size=3D2>sv-ec@eda.org</FONT></A><FONT face=3DArial =
size=3D2>><BR>> Sent:=20
Tuesday, February 11, 2003 1:18 PM<BR>> Subject: [sv-ec] Re: super =
and=20
virtual func.<BR>> <BR>> <BR>> <BR>> C++ does not have the=20
restriction that routines used with<BR>> '::' should be virtual =
-<BR>>=20
<BR>> #include <stdio.h><BR>> <BR>> class foo =
{<BR>> public:<BR>> virtual void whoami() =20
{printf("foo\n");};<BR>> virtual void whoami2()=20
{printf("foo\n");};<BR>> };<BR>> class bar : public =
foo=20
{<BR>> public:<BR>> virtual void =
whoami() =20
{printf("bar\n");};<BR>> virtual void whoami2()=20
{foo::whoami();};<BR>> };<BR>> <BR>> void sub(foo=20
*fp)<BR>> {<BR>> =20
fp->whoami();<BR>> =
fp->whoami2();<BR>> =20
}<BR>> <BR>> main()<BR>> =
{<BR>> bar=20
bq;<BR>> <BR>> =
bq.whoami();<BR>> =20
bq.foo::whoami();<BR>> bq.whoami2();<BR>>=20
<BR>> sub(&bq);<BR>> }<BR>> =
<BR>> -=20
gives -<BR>> <BR>> bar<BR>> foo<BR>> =20
foo<BR>> bar<BR>> foo<BR>> <BR>> A call =
with :: is=20
not a virtual call, it's handled the same<BR>> as a non-virtual =
call.<BR>>=20
<BR>> I.e. the restriction in SV doesn't have a precedent in =
C++.<BR>>=20
<BR>> Kev.<BR>> <BR></FONT></BODY></HTML>
This archive was generated by hypermail 2b28 : Thu Feb 13 2003 - 09:17:38 PST