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

From: eugene zhang <eugene@jedatechnologies.com>
Date: Tue Aug 31 2004 - 13:46:43 PDT

 

------------------------------------------------------------
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 13:46:53 2004

This archive was generated by hypermail 2.1.8 : Tue Aug 31 2004 - 13:46:56 PDT