User guide

24-161
SystemVerilog Testbench Constructs
Example 24-21 is shows how AOE can be used to introduce new
members into a class definition. myaspect adds a new property,
constraint, coverage group, and method to the packet class.
Example 24-21
class packet;
rand bit[31:0]...
...
endclass
extends myaspect(packet);
integer sending_port;
constraint con2 {
hdr_len == 4;
}
coverage_group cov2 @(posedge CLOCK);
coverpoint sending_port;
endgroup
task print_sender();
$display("Sending port = %0d\n", sending_port);
endtask
endextends
As mentioned earlier, new members that are introduced should not
have the same name as a symbol that is already defined in the class
scope. So, AOE defined in the manner shown in Example 24-22 will
is not allowed, as the aspect myaspect defines x as one of the
introductions when the symbol x is already defined in class foo.
Example 24-22 : Non permissible introduction
class foo;
rand integer myfield;
integer x;
...
endclass
extends myaspect(foo);
integer x ;