Re: [sv-ec] Jeda SV-Errata: #14 class method overwrite

From: Michael Burns <Michael.Burns@freescale.com>
Date: Tue Aug 31 2004 - 17:20:38 PDT

Hi Eugene,

I have some questions about this proposal. Do instances of the parent
class also see the overwritten method? How about instances of other
child classes of parent (that do not themselves overwrite or override
it)? What if two child classes try to overwrite the same parent method?
It seems to me that, if all that is desired is for instances of the
overwriting class to see the new definition, that a virtual method would
work fine, even if the call chain goes through a method whose definition
is in the parent. Exposing the overwritten definition to instances of
other classes in the hierarchy (such as the parent or siblings) seems
fraught with peril - a sibling class's code might start behaving
differently, and finding out why would be a difficult task. Besides,
the overwritten definition could refer to data members that only exist
in the overwriting child class, thus making the overwritten definition
meaningless for other class instances.

Mike Burns

eugene zhang wrote:

>
>
> ------------------------------------------------------------
> function overwrite
> ------------------------------------------------------------
>
> problem statement:
> The class construct in Section 11 of the SV 3.1a specification does not
> provide a mechanism for a child class to redefine a function/task
> defined in the parent class.
>
>
> summary: A class function/task attribute, 'overwrite' provides a level
> of flexibility of propagating changes to a redefined function/task from
> the child class to the parent class
>
> description:
> The "overwrite" function provide a level of flexibility beyond what's
> been provided in the current SV specficiation. In developing
> Verification code its literally impossible to develop classes that
> anticipate all the future use of that particular class.
>
> Using inheritance one can extend the base class and redefine the
> task/funciton in the child class but the parent class does not see the
> change. The question then is, how is it possible to have the changes
> made in the child class be reflected to the parent class is an easy way?
> Using existing class constructs, this is not possible until we define
> the new capability with the 'overwrite' construct.
>
> The following example will illustrate the challenge faced as described
> above:
>
> class parent ;
> function new();
>
> task foo ;
> begin
> $display( "parent foo called foo" ) ;
> end
> endtask
>
> task bar ;
> begin
> foo ;
> end
> endtask
>
> task bar1 ;
> begin
> foo ;
> end
> endtask
>
> endclass // end of class parent
>
> class child extends parent ;
> task foo ;
> begin
> $display( "child foo called in child\n" ) ;
> end
> endtask
>
> task method_1 ;
> begin
> foo();
> bar();
> end
> endtask
> endclass
>
> When an instance of the child class calls bar(), the function will refer
> to the definition of the task foo() from the parent class and not the
> redefined foo() inside the child class. If a function is redeclared with
> 'overwrite' attribute in the child class then the change will also be
> visible to the parent class as follows:
>
> class child_a extends parent ;
> overwrite task foo ;
> begin
> $display( "child foo called" ) ;
> end
> endtask
> endclass
>
> This way, the functions bar() and bar1() in the parent class will use
> the redefined task foo() from the child class.
>
> In using the 'overwrite' attribute on a function, the function prototype
> both in the child and parent class have to be identical otherwise a
> runtime error is reported.
>
> Additional information:
>
> BNF changes:
>
> method_qualifier::=
> virtual
> | class_item_qualifier
>
> is modified as
> method_qualifier::=
> virtual | overwrite
> | class_item_qualifier
>
> Attached files:
> None
>
>
>
>
>
Received on Tue Aug 31 17:20:05 2004

This archive was generated by hypermail 2.1.8 : Tue Aug 31 2004 - 17:20:12 PDT