In reply to shubh2211:
Hi, I’ve gone through ur question and what I understood is that
We are given the names of BASE CLASS and EXTENDED CLASS. We need to find out the name of the BASE CLASS of a particular EXTENDED CLASS.
import uvm_pkg::*;
`include "uvm_macros.svh"
class A extends uvm_object;
`uvm_object_utils(A)
function new(string name = "default");
super.new(name);
endfunction
endclass
class B extends uvm_object;
`uvm_object_utils(B)
function new(string name = "default");
super.new(name);
endfunction
endclass
class AA extends A;
`uvm_object_utils(AA)
function new(string name = "default");
super.new(name);
endfunction
endclass
class BB extends B;
`uvm_object_utils(BB)
function new(string name = "default");
super.new(name);
endfunction
endclass
module test();
A a=new("base_class");
B b=new("base_class");
AA aa=new("ext_class");
BB bb=new("ext_class");
initial begin
if($cast(b,aa))
$display("\nAA is extended from %s", $typename(b));
else if($cast(a,aa))
$display("\nAA is extended from %s",$typename(a));
else
$display("Wrong reqirement");
if($cast(b,bb))
$display("\nBB is extended from %s", $typename(b));
else if($cast(a,bb))
$display("\nBB is extended from %s",$typename(a));
else
$display("Wrong requirement");
end
endmodule
Please let me know whether my approach is right or not and if is there any edge case I have missed out on.
Another point I would like to mention is that there is a difference between $typename(class_object_name) and class_object_name.get_type_name(). After executing dynamic casting get_type_name won’t return the original type name but $typename gets us the expected output. Hope this statement is correct!