I was wondering if class scope resolution operator can help to resolve an identifier within an inline constraint.
class trans;
rand bit [31:0] addr;
endclass
class seq;
rand bit [31:0] addr;
trans t;
function void body();
int addr ;
addr = 10 ;
t = new();
if(t.randomize() with { t.addr == seq::addr ; } )
$display("Success with %p",t);
else
$display("Fails");
endfunction
endclass
seq obj ;
initial begin
obj = new() ;
obj.body();
end
This works and I observe ::
Success with '{addr:'h0}
LRM explains about local::qualifier . So I was wondering whether Class Scope Resolution Operator Could be used too ?
Yes, it works in this. I can think of a contrived example where local:: is still needed. For example, when the classes trans and seq are defined in different packages as extensions to different classes with the same base class name.
The search rules are quite simple: the in-line constraint searches identifiers in the object being randomized, if not found, it searches from the scope of the call to randomize.
In your example the reference to t.addr is searching for t in the object being randomized and does not find it. It then searches from the scope of the body() task and finds t a member of the seq class. Then it resolves addr as a member of t. You could have just written addr == seq::addr.
Could you please elaborate where local:: is definitely needed over class scoped identifier
Based on your comments I could figure out code to be ::
// Within PKG1
class Base ;
....
endclass
class Intermediate1 extends Base ;
...
endclass
class trans extends Intermediate1 ;
rand bit [31:0] addr ;
endclass
// Within PKG2
// Import PKG1
class Base ;
....
endclass
class Intermediate2 extends Base ;
...
endclass
class seq extends Intermediate2 ;
rand bit [31:0] addr;
trans t;
function void body();
int addr ;
addr = 10 ;
t = new();
if(t.randomize() with { addr == seq::addr ; } ) // This would still work , I believe
$display("Success with %p",t);
else
$display("Fails");
endfunction
endclass