Hello VA community,
From the UVM source code of uvm_object:
// Group: Comparing
// Function: compare
//
// Deep compares members of this data object with those of the object provided
// in the ~rhs~ (right-hand side) argument, returning 1 on a match, 0 otherwise.
//
// The ~compare~ method is not virtual and should not be overloaded in derived
// classes. To compare the fields of a derived class, that class should
// override the <do_compare> method.
//
// The optional ~comparer~ argument specifies the comparison policy. It allows
// you to control some aspects of the comparison operation. It also stores the
// results of the comparison, such as field-by-field miscompare information
// and the total number of miscompares. If a compare policy is not provided,
// then the global ~uvm_default_comparer~ policy is used. See <uvm_comparer>
// for more information.
extern function bit compare (uvm_object rhs, uvm_comparer comparer=null);
// Function: do_compare
//
// The ~do_compare~ method is the user-definable hook called by the <compare>
// method. A derived class should override this method to include its fields
// in a compare operation. It should return 1 if the comparison succeeds, 0
// otherwise.
//
// A typical implementation is as follows:
//
//| class mytype extends uvm_object;
//| ...
//| int f1;
//| virtual function bit do_compare (uvm_object rhs,uvm_comparer comparer);
//| mytype rhs_;
//| do_compare = super.do_compare(rhs,comparer);
//| $cast(rhs_,rhs);
//| do_compare &= comparer.compare_field_int("f1", f1, rhs_.f1);
//| endfunction
//
// A derived class implementation must call ~super.do_compare()~ to ensure its
// base class' properties, if any, are included in the comparison. Also, the
// rhs argument is provided as a generic uvm_object. Thus, you must ~$cast~ it
// to the type of this object before comparing.
//
// The actual comparison should be implemented using the uvm_comparer object
// rather than direct field-by-field comparison. This enables users of your
// class to customize how comparisons are performed and how much miscompare
// information is collected. See uvm_comparer for more details.
extern virtual function bit do_compare (uvm_object rhs,
uvm_comparer comparer);
I don’t understand next phrase:
“The ~compare~ method is not virtual and should not be overloaded in derived classes. To compare the fields of a derived class, that class should override the <do_compare> method”
First, from what I know, SystemVerilog does not support overloading.
Second, “compare” method is not virtual, if we implement it in derived class it, will it be overridden or will we receive compilation/run-time error? Third, for overloading we need same name for method but different parameters. But we do supply same parameters. So how is it overloading?
So my question: is using “overloaded” in this phrase is a typo? Or am I missing something?
Thanks,
Michael