Re: [sv-ec] Cliff's 1308 email No-vote - See attached example

From: Gordon Vreugdenhil <gordonv_at_.....>
Date: Tue Mar 28 2006 - 13:54:32 PST
Cliff,

I don't think we want to make this as long and tedious a
description as all the ISO/ANSI C++ rules - you might
want to look at that if you really want to get confused. :-)

We are following "normal" OO rules here -- virtual methods
with static property binding in the methods.  I think that
some of your questions are based on not having a completely
correct understanding of normal OO binding rules.

See below for [Gord -- ...] for corrections to your
expected output.



Clifford E. Cummings wrote:

> Cliff votes NO on the 1308 proposal as is. Friendly(?) amendments 
> pending (to be proposed by Cliff)
> 
> Reason - not yet clear enough. I will propose additional clarifications 
> to Dave's greatly-improved-wording after I understand the following 
> example. In the following example, there are two levels of extension and 
> an interesting mixture of virtual and non-virtual methods. Please 
> examine the (untested) example (shown below and attached) and let me 
> know if my reasoning is correct or not. The output lines with ??? are 
> where I am most unsure.
> 
> Regards - Cliff
> 
> module virtualmenthods;
>   //-------------------------------------------------------------
>   class BasePacket;
>     int A = 1;
>     int B = 2;
>     int C = 3;
> 
>     function void printA;
>       $display("BasePacket::A is %d",A);
>     endfunction : printA
> 
>     virtual function void printB;
>       $display("BasePacket::B is %d",B);
>     endfunction : printB
> 
>     virtual function void printC;
>       $display("BasePacket::C is %d",C);
>     endfunction : printC
>   endclass : BasePacket
>   //-------------------------------------------------------------
>   class MyPacket1 extends BasePacket;
>     int A = 4;
>     int B = 5;
>     int C = 6;
> 
>     function void printA;
>       $display("MyPacket1::A  is %d",A);
>     endfunction : printA
> 
>     function void printB;
>       $display("MyPacket1::B  is %d",B);
>     endfunction : printB
> 
>     virtual function void printC;
>       $display("MyPacket1::C  is %d",C);
>     endfunction : printC
>   endclass : MyPacket1
>   //-------------------------------------------------------------
>   class ExtPacket extends MyPacket1;
>     int A = 7;
>     int B = 8;
>     int C = 9;


[Gord -- "C" here is useless; it will not be used by any method;
          bind is NOT dynamic.  A method declaration (virtual or not)
          binds to the member visible at the level of hierarchy
          of the declaration.  Only methods are virtual -- I think
          you are viewing the property as virtual as well.
]

> 
>     function void printA;
>       $display("ExtPacket::A  is %d",A);
>     endfunction : printA
> 
>     virtual function void printB;
>       $display("ExtPacket::B  is %d",B);
>     endfunction : printB
> 
>     // No printC function in ExtPacket
>     // Inherit printC from MyPacket1
>   endclass : ExtPacket
>   //-------------------------------------------------------------
> 
>   BasePacket P1 = new;
>   MyPacket1  P2 = new;
>   ExtPacket  P3 = new;
> 
>   initial begin
>     P1.printA; // displays 'BasePacket::A is 1'
>     P1.printB; // displays 'BasePacket::B is 2'
>     P1.printC; // displays 'BasePacket::C is 3'
>     //-----------------------------------------------------------
>     P1 = P2; // P1 has a handle to a MyPacket1 object
> 
>     P1.printA; // displays 'BasePacket::A is 1'
>     P1.printB; // displays 'MyPacket1::B  is 5' - latest derived method
>     P1.printC; // displays 'MyPacket1::C  is 6' - latest derived method
> 
>     P2.printA; // displays 'MyPacket1::A  is 4'
>     P2.printB; // displays 'MyPacket1::B  is 5'
>     P2.printC; // displays 'MyPacket1::C  is 6'
>     //-----------------------------------------------------------
>     P1 = P3; // P1 has a handle to an ExtPacket object
>     P2 = P3; // P2 has a handle to an ExtPacket object
> 
>     P1.printA; // displays 'BasePacket::A is 1'
>     P1.printB; // displays 'ExtPacket::B  is 8' - ???

[Gord - yes.]

>     P1.printC; // displays 'MyPacket1::C  is 9' - ???

[Gord - no.  printC in object P3 (referenced by P1) is
         a virtual method defined in class MyPacket1 which
         is the "latest" override.  The "C" that is
         visible to that method is the one in MyPacket1
         with the value 6.
]

> 
>     P2.printA; // displays 'MyPacket1::A  is 4'
>     P2.printB; // displays 'ExtPacket::B  is 8' - ??? (virtual again???)

[Gord - I don't know what you mean by "again".  printB is *always*
         virtual since the root of the hierarchy declared it as
         virtual.  So, yes, the output you give is correct but
         possibly from faulty reasoning
]

>     P2.printC; // displays 'MyPacket1::C  is 9' - ??? (9???)

[Gord - no.  You get the value 6 for the same reason as above. ]

> 
>     P3.printA; // displays 'ExtPacket::A  is 7'
>     P3.printB; // displays 'ExtPacket::B  is 8'
>     P3.printC; // displays 'MyPacket1::C  is 9' - ??? (9???)

[Gord - no.  Same reason again]



Gord


>     //-----------------------------------------------------------
>   end
> endmodule
> 
> 
> 
> ----------------------------------------------------
> Cliff Cummings - Sunburst Design, Inc.
> 14314 SW Allen Blvd., PMB 501, Beaverton, OR 97005
> Phone: 503-641-8446 / FAX: 503-641-8486
> cliffc@sunburst-design.com / www.sunburst-design.com
> Expert Verilog, SystemVerilog, Synthesis and Verification Training
> 
> 
> ------------------------------------------------------------------------
> 
> module virtualmenthods;
>   //-------------------------------------------------------------
>   class BasePacket;
>     int A = 1;
>     int B = 2;
>     int C = 3;
>   
>     function void printA;
>       $display("BasePacket::A is %d",A);
>     endfunction : printA
>   
>     virtual function void printB;
>       $display("BasePacket::B is %d",B);
>     endfunction : printB
>   
>     virtual function void printC;
>       $display("BasePacket::C is %d",C);
>     endfunction : printC
>   endclass : BasePacket
>   //-------------------------------------------------------------
>   class MyPacket1 extends BasePacket;
>     int A = 4;
>     int B = 5;
>     int C = 6;
>   
>     function void printA;
>       $display("MyPacket1::A  is %d",A);
>     endfunction : printA
>   
>     function void printB;
>       $display("MyPacket1::B  is %d",B);
>     endfunction : printB
>   
>     virtual function void printC;
>       $display("MyPacket1::C  is %d",C);
>     endfunction : printC
>   endclass : MyPacket1
>   //-------------------------------------------------------------
>   class ExtPacket extends MyPacket1;
>     int A = 7;
>     int B = 8;
>     int C = 9;
>   
>     function void printA;
>       $display("ExtPacket::A  is %d",A);
>     endfunction : printA
>   
>     virtual function void printB;
>       $display("ExtPacket::B  is %d",B);
>     endfunction : printB
> 
>     // No printC function in ExtPacket
>     // Inherit printC from MyPacket1
>   endclass : ExtPacket
>   //-------------------------------------------------------------
>   
>   BasePacket P1 = new;
>   MyPacket1  P2 = new;
>   ExtPacket  P3 = new;
>   
>   initial begin
>     P1.printA; // displays ‘BasePacket::A is 1’
>     P1.printB; // displays ‘BasePacket::B is 2’
>     P1.printC; // displays ‘BasePacket::C is 3’
>     //-----------------------------------------------------------
>     P1 = P2; // P1 has a handle to a MyPacket1 object
> 
>     P1.printA; // displays ‘BasePacket::A is 1’
>     P1.printB; // displays ‘MyPacket1::B  is 5’ - latest derived method
>     P1.printC; // displays ‘MyPacket1::C  is 6’ - latest derived method
> 
>     P2.printA; // displays ‘MyPacket1::A  is 4’
>     P2.printB; // displays ‘MyPacket1::B  is 5’
>     P2.printC; // displays ‘MyPacket1::C  is 6’
>     //-----------------------------------------------------------
>     P1 = P3; // P1 has a handle to an ExtPacket object
>     P2 = P3; // P2 has a handle to an ExtPacket object
> 
>     P1.printA; // displays ‘BasePacket::A is 1’
>     P1.printB; // displays ‘ExtPacket::B  is 8’ - ???
>     P1.printC; // displays ‘MyPacket1::C  is 9’ - ???
>     
>     P2.printA; // displays ‘MyPacket1::A  is 4’
>     P2.printB; // displays ‘ExtPacket::B  is 8’ - ??? (virtual again???)
>     P2.printC; // displays ‘MyPacket1::C  is 9’ - ??? (9???)
>    
>     P3.printA; // displays ‘ExtPacket::A  is 7’
>     P3.printB; // displays ‘ExtPacket::B  is 8’
>     P3.printC; // displays ‘MyPacket1::C  is 9’ - ??? (9???)
>     //-----------------------------------------------------------
>   end
> endmodule

-- 
--------------------------------------------------------------------
Gordon Vreugdenhil                                503-685-0808
Model Technology (Mentor Graphics)                gordonv@model.com
Received on Tue Mar 28 13:54:37 2006

This archive was generated by hypermail 2.1.8 : Tue Mar 28 2006 - 13:54:42 PST