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


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>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Now I understand.&nbsp;&nbsp;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>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I can see why it may be =
confusing.&nbsp; What if=20
that paragraph is changed to:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; To call the =
overridden method=20
from a parent class object&nbsp;(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>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; Arturo</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>----- Original Message ----- </FONT>
<DIV><FONT face=3DArial size=3D2>From: "Kevin Cameron" &lt;</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>&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>To: &lt;</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>&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Cc: &lt;</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>&gt;</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>&gt; From: "Arturo Salz" &lt;</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>&gt;<BR>&gt;=20
<BR>&gt; Kevin,<BR>&gt; <BR>&gt; Are you suggesting that super is =
restricted to=20
work only<BR>&gt; with virtual routines?&nbsp; There is no such =
restriction in=20
the<BR>&gt; LRM document.&nbsp; Super behaves exactly in the =
same<BR>&gt; way as=20
&lt;parent_class&gt;:: in C++.&nbsp; In fact, the SV version<BR>&gt; of =
your=20
example is:<BR><BR>The LRM says:<BR><BR>&nbsp; To get the overridden =
method, the=20
parent method needs to be<BR>&nbsp; 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>&gt;=20
-------------------------------------------------------------------------=
-------<BR>&gt;=20
<BR>&gt; class foo;<BR>&gt;&nbsp;&nbsp; virtual task whoami() $display( =
"foo" );=20
endtask<BR>&gt;&nbsp;&nbsp; virtual task whoami2() $display( "foo" );=20
endtask<BR>&gt; endclass<BR>&gt; <BR>&gt; class bar extends=20
foo;<BR>&gt;&nbsp;&nbsp; virtual task whoami() $display( "foo" );=20
endtask<BR>&gt;&nbsp;&nbsp; virtual task whoami2() super.whoami2();=20
endtask<BR>&gt; endclass<BR>&gt; <BR>&gt; task main;<BR>&gt;&nbsp;&nbsp; =

bar&nbsp; bq =3D new;<BR>&gt; <BR>&gt;&nbsp;&nbsp;=20
bq.whoami();<BR>&gt;&nbsp;&nbsp; bq.whoami2();<BR>&gt; endtask<BR>&gt; =
<BR>&gt;=20
initial main;<BR>&gt; <BR>&gt;=20
-------------------------------------------------------------------------=
-------<BR>&gt;=20
<BR>&gt; - gives -<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp;=20
bar<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp; foo<BR>&gt; <BR>&gt; You will note =
that=20
whoami2 in class bar calls the virtual<BR>&gt; function whoami2 in the =
parent=20
class.&nbsp; If this call were<BR>&gt; made as a virtual call, it would =
run as=20
an infinite loop.<BR>&gt; Explicit qualification of the class via super =
(or ::=20
in C++)<BR>&gt; always yields exactly that member (or property).<BR>&gt; =
If this=20
were not the case, it wouldn't be possible to<BR>&gt; implement virtual=20
destructors correctly in C++ (and<BR>&gt; destructors should always be=20
virtual).<BR>&gt; <BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp; Arturo<BR>&gt; =
<BR>&gt; -----=20
Original Message ----- <BR>&gt; From: "Kevin Cameron x3251" =
&lt;</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>&gt;<BR>&gt; To:=20
&lt;</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>&gt;<BR>&gt; Sent:=20
Tuesday, February 11, 2003 1:18 PM<BR>&gt; Subject: [sv-ec] Re: super =
and=20
virtual func.<BR>&gt; <BR>&gt; <BR>&gt; <BR>&gt; C++ does not have the=20
restriction that routines used with<BR>&gt; '::' should be virtual =
-<BR>&gt;=20
<BR>&gt;&nbsp; #include &lt;stdio.h&gt;<BR>&gt; <BR>&gt;&nbsp; class foo =

{<BR>&gt;&nbsp; public:<BR>&gt;&nbsp;&nbsp; virtual void whoami()&nbsp;=20
{printf("foo\n");};<BR>&gt;&nbsp;&nbsp; virtual void whoami2()=20
{printf("foo\n");};<BR>&gt;&nbsp; };<BR>&gt;&nbsp; class bar : public =
foo=20
{<BR>&gt;&nbsp; public:<BR>&gt;&nbsp;&nbsp;&nbsp; virtual void =
whoami()&nbsp;=20
{printf("bar\n");};<BR>&gt;&nbsp;&nbsp;&nbsp; virtual void whoami2()=20
{foo::whoami();};<BR>&gt;&nbsp; };<BR>&gt; <BR>&gt;&nbsp; void sub(foo=20
*fp)<BR>&gt;&nbsp; {<BR>&gt;&nbsp;&nbsp;&nbsp;=20
fp-&gt;whoami();<BR>&gt;&nbsp;&nbsp;&nbsp; =
fp-&gt;whoami2();<BR>&gt;&nbsp;=20
}<BR>&gt; <BR>&gt;&nbsp; main()<BR>&gt;&nbsp; =
{<BR>&gt;&nbsp;&nbsp;&nbsp; bar=20
bq;<BR>&gt; <BR>&gt;&nbsp;&nbsp;&nbsp; =
bq.whoami();<BR>&gt;&nbsp;&nbsp;&nbsp;=20
bq.foo::whoami();<BR>&gt;&nbsp;&nbsp;&nbsp; bq.whoami2();<BR>&gt;=20
<BR>&gt;&nbsp;&nbsp;&nbsp; sub(&amp;bq);<BR>&gt;&nbsp; }<BR>&gt; =
<BR>&gt; -=20
gives -<BR>&gt; <BR>&gt;&nbsp; bar<BR>&gt;&nbsp; foo<BR>&gt;&nbsp;=20
foo<BR>&gt;&nbsp; bar<BR>&gt;&nbsp; foo<BR>&gt;&nbsp; <BR>&gt; A call =
with :: is=20
not a virtual call, it's handled the same<BR>&gt; as a non-virtual =
call.<BR>&gt;=20
<BR>&gt; I.e. the restriction in SV doesn't have a precedent in =
C++.<BR>&gt;=20
<BR>&gt; Kev.<BR>&gt; <BR></FONT></BODY></HTML>



This archive was generated by hypermail 2b28 : Thu Feb 13 2003 - 09:17:38 PST