RE: [sv-ec] Query related to virtual methods in a class

From: Arturo Salz <Arturo.Salz_at_.....>
Date: Thu Oct 19 2006 - 11:44:35 PDT
Don,

 

I believe that the argument names should not be required to match across
class extensions. Thus, Kakoli's example should be legal.

 

There is a bit of confusion regarding matching prototypes because there
are two contexts in which we need to define "matching prototype" (or as
the LRM incorrectly says identical). A matching prototype is needed when
an out-of-body method definition is used, for example:

 

class Base;
  extern task foo(input reg rg);
endclass
 
task Base::foo(input reg rg1);  // name mismatch here
  ...
endtask

 

I believe that the consensus of the committee was to require identical
names in the above case. The second need for matching prototypes is
Kakoli's example, when overriding a virtual method through inheritance.
I don't remember the committee discussing the requirements for this
second type of prototype matching, and, as I said above, I believe the
argument names should not be required to match in that case.

            

There is an existing Mantis item, 1308, that attempts to clarify these
issues (and  others). That item does require matching argument names,
but I believe that is a result of merging the two types of matching.

 

As for your question. An extended class is not required to override (or
re-implement) a virtual method introduced by any of its ancestors. If
the parent class is virtual (i.e., abstract) and the virtual method is
undefined then the extended class must provide an implementation for the
virtual method in order for the class to become concrete - and be able
to create objects of that class. If, on the other hand, the parent class
is not virtual and does provide an implementation of the virtual method
then the extended class does not need to override the virtual method; it
will simply inherit the virtual method implemented by its closest
ancestor. Perhaps, if you provide an example we can identify the exact
problem you are seeing.

 

            Arturo

 

________________________________

From: owner-sv-ec@eda.org [mailto:owner-sv-ec@eda.org] On Behalf Of Don
Mills
Sent: Thursday, October 19, 2006 10:22 AM
To: Kakoli Bhattacharya; sv-ec@eda.org
Subject: Re: [sv-ec] Query related to virtual methods in a class

 

I have second question on the same train of thought that Kakoli
presented.  If a virtual base class contains a virtual method, then when
the base class is extended, is the extended child class required to
include the virtual method?  Or is the virtual method only a prototype
if the child class wished to use that method?  I assumed that base class
virtual methods were required to exist and be defined in extended
classes, but that is not the case with all simulators.  Is my
understanding wrong here?

 

dm



	-----Original Message----- 
	From: Kakoli Bhattacharya 
	Sent: Oct 19, 2006 6:07 AM 
	To: sv-ec@server.eda.org 
	Subject: [sv-ec] Query related to virtual methods in a class 
	
	
	

	Hello,
	 
	Consider the following code:
	 
	virtual class Parent;
	integer it;
	int i;
	virtual task virtual_task(input reg rg);  //This is the
declaration
	endtask
	endclass
	 
	class Child1 extends Parent;
	shortint si;
	longint li;
	virtual task virtual_task1(input reg rg1);
	endtask
	endclass
	 
	class Child2 extends Child1;
	real r1;
	shortreal sr1;
	time t1;
	realtime rt1;
	task virtual_task(input reg rg1);  // This is the redefinition
	it = rg1;
	i = rg1;
	si = rg1;
	li = rg1;
	endtask
	enclass
	 
	My problem concerns the virtual task 'virtual_task'.
	When it has been declared in the parent class 'Parent' then it
takes 'rg' as its argument.
	During its redefinition in the child class 'Child2' it takes
'rg1' as its argument.
	Is it necessary that the names of the variables also have to be
identical?
	 
	In LRM (1800-2005) Section 7.19 it is stated that "Virtual
methods provide prototypes for subroutines,
	i.e., all of the information generally found on the first line
of a method declaration: 
	the encapsulation criteria, the type and number of arguments,
and the return type if it is needed.
	Later, when subclasses override virtual methods, they must
follow the prototype exactly."
	 
	Prototype however do not mean identical variable name.But later
on in the same section it is also stated that 
	"Thus, all versions of the virtual method look identical in all
subclasses"
	 
	So what does the word 'identical' exactly mean overhere? Does it
imply identical argument name also?
	 
	Thanks,
	Kakoli
	 



==========================================================
Don Mills
LCDM Engineering     (Logic, Coding, & Design Methodology) 
mills@lcdm-eng.com                        www.lcdm-eng.com
==========================================================
Received on Thu Oct 19 11:45:00 2006

This archive was generated by hypermail 2.1.8 : Thu Oct 19 2006 - 11:45:07 PDT