ERROR VCP5103 "Undeclared identifier: c_pd." "gen.sv"

Hi. I am trying to randomize a varaible in an extended transaction through another class.
The baseclass: “transaction”:

class transaction extends uvm_sequence_item;
/*
some code
*/

the extended class “transaction_pd”:


class transaction_pd extends transaction;  
  rand int c_pd;

  
  function new(string inst = "transaction_pd");
    super.new(inst);    
  endfunction
  

  `uvm_object_utils_begin(transaction_pd)
  `uvm_field_int(c_pd,UVM_ALL_ON)  
  `uvm_object_utils_end


 
endclass

the calling for randomization class, “generator”:

class generator extends uvm_sequence#(transaction);
`uvm_object_utils(generator)
 rand integer frames;
 rand integer rows;
  
  function new(string inst = "generator");
  super.new(inst);
  endfunction

 
  virtual task body();
    req = transaction::type_id::create("GEN_TRANS");  
   req.print();////req is transaction_pd type, thanks to the factory mechanizem.
    for (int i=0; i<frames; i++) begin
      for (int j=0; j<rows; j++) begin
   	 	start_item(req);       
        req.randomize() with {c_pd==j;frame==i;row==j;};       
        finish_item(req); //this will return after item_done from the driver.
    end     
    end
  endtask
  
endclass

The problem is that c_pd is “Undeclared identifier” when I’m trying to randomize it through the with clause. If I don’t do it so its working ok and c_pd is getting a random value, as you can see in the printed transaction_pd object:

# KERNEL: ------------------------------------------------------------------------------
# KERNEL: Name                           Type            Size  Value                    
# KERNEL: ------------------------------------------------------------------------------
# KERNEL: GEN_TRANS                      transaction_pd  -     @691                     
# KERNEL:   start_act                    integral        1     'h1                      
# KERNEL:   data_in                      da(integral)    70    -                        
# KERNEL:     [0]                        integral        12    'heb1                    
# KERNEL:     [1]                        integral        12    'h3ed                    
# KERNEL:     [2]                        integral        12    'h7f0                    
# KERNEL:     [3]                        integral        12    'hcc9                    
# KERNEL:     [4]                        integral        12    'h271                    
# KERNEL:     ...                        ...             ...   ...                      
# KERNEL:     [65]                       integral        12    'h1ba                    
# KERNEL:     [66]                       integral        12    'h6bf                    
# KERNEL:     [67]                       integral        12    'he21                    
# KERNEL:     [68]                       integral        12    'hc09                    
# KERNEL:     [69]                       integral        12    'h1ee                    
# KERNEL:   row_width                    integral        10    'h46                     
# KERNEL:   movavgwin_param              integral        2     'h1                      
# KERNEL:   frame                        integral        32    'h0                      
# KERNEL:   row                          integral        32    'h0                      
# KERNEL:   **c_pd**                         integral        32    'h2bf09c4a               
# KERNEL:   begin_time                   time            64    55                       
# KERNEL:   depth                        int             32    'd2                      
# KERNEL:   parent sequence (name)       string          3     gen                      
# KERNEL:   parent sequence (full name)  string          25    uvm_test_top.e.a.seqr.gen
# KERNEL:   sequencer                    string          21    uvm_test_top.e.a.seqr    
# KERNEL: ------------------------------------------------------------------------------
# KERNEL: ------------------------------------------------------------------------------

It seems to me that i don’t know something on the randomize function or about object oriented programming in this case.

Thanks.

This is an OOP issue. The req class variable is declared as a transaction class type—you can only reference identifiers known to that type from that class variable. The c_pd variable is known to the transaction_pd class type. If you want the generator sequence to construct and constrain c_pd variables, then that is how you should have parameterized the generator instead of relying on the factory.

But if you only wanted some pieces of the generator to know about, then you need to downcast the object to a class variable that knows about c_pd.

virtual task body();
    transaction_pd req_pd;
    bit is_pd;
    req = transaction::type_id::create("GEN_TRANS");  
    is_pd = $cast(req_pd,req);
   req.print();////req is transaction_pd type, thanks to the factory mechanizem.
    for (int i=0; i<frames; i++) begin
      for (int j=0; j<rows; j++) begin
   	 	start_item(req); 
        if (is_pd)
          req_pd.randomize() with {c_pd==j;frame==i;row==j;};    
        else   
          req.randomize() with {frame==i;row==j;};    

        finish_item(req); //this will return after item_done from the driver.
    end     
    end
  endtask

Thanks Dave.
But I don’t understand something. When I used the print method (in req.print();) the compiler showed me that req is transaction_pd type (as you can see in the added compiler output ), so why you said its a transaction type?

oh I understand now.
Thanks!

but i still would like to get an explanation.

print() as well as randomize() are virtual methods. See my course on OOP for UVM. as well as searching for more on that topic.