User guide
24-156
SystemVerilog Testbench Constructs
before task foo(integer x);
x = 99; //force every call to foo to use x=99
endtask
endextends
// End file example.sv
The extends directive in Example 24-17 sets the x parameter inside
the foo() task to 99 before the original code inside of foo() executes.
Actual argument to foo() is not affected, and is not set unless
passed-by-reference using ref.
Example 24-18
// Begin file example.sv
program top ;
packet p;
p = new();
$display(“Output is: %d\n”, p.bar());
endprogram
class packet ;
function integer bar();
bar = 5;
$display(“Point 1: Value = %d\n”, bar);
endfunction
endclass
extends myaspect(packet);
after function integer bar();
$display(“Point 2: Value = %d\n”, bar);
bar = bar + 1; // Stmt A
$display(“Point 3: Value = %d\n”, bar);
endfunction
endextends
// End file example.sv
An advice to a function can access and modify the variable that
stores the return value of the function as shown in Example 24-18,
in this example a call to packet::bar returns 6 instead of 5 as the final
return value is set by the Stmt A in the advice code block.