Jump to content

Base class types access through opaque type parameter extension

Recommended Posts


I'm facing a class inheritance problem that I don't quite understand related to accessing parent class typedef when that parent is passed as type via opaque class type extension.  I'm using this for base classing in the UVM library, but it is not specific to UVM.

In the following example, I can extend the uvm_report_catcher and directly implement the abstract catch function without needing to alias the enumeration type.

virtual class uvm_callback extends uvm_object;
   protected bit m_enabled = 1;
virtual class uvm_report_catcher extends uvm_callback;
    typedef enum { UNKNOWN_ACTION, THROW, CAUGHT} action_e;
    pure virtual function action_e catch();
class my_catcher extends uvm_report_catcher;
  virtual function action_e catch();
    if(m_enabled) `uvm_info("MYCTCHR", "Saw msg when enabled", UVM_LOW)
    return THROW;

Even though action_e is declared/defined in scope of uvm_report_catcher, since my_catcher is an extension I have no issue accessing then same type for the the catch() return value.  Furthermore, I, of course, have no issue accessing the uvm_callback::m_enabled protected class member.

However, I have inserted a middling type-parameterized opaque class between.

virtual class my_object_param#(type T = int) extends T; // middling class
  function new(string name = ""); super.new(name); endfunction
  // some other stuff common in all my object instantiations

virtual class my_catcher extends my_object_param#(uvm_report_catcher);
  function new(string name = "my_catcher"); super.new(name); endfunction
  virtual function action_e catch(); // compile error
    if(m_enabled) `uvm_info("MYCTCHR", "Saw msg when enabled", UVM_LOW)
    return THROW;

Here, I get a compiler error on action_e indicating it is not a valid type (i.e., unknown type).  I would think that, because the resolved inheritance hierarchy is:

  +- my_object_param
     +- my_catcher

that action_e would be in-scope for both my_object_param and my_catcher.  

I can workaround this by specializing to my own report catcher first, then into my_catcher.

virtual class my_report_catcher extends my_object_param#(uvm_report_catcher);
    typedef uvm_report_catcher::action_e action_e;
class my_catcher extends my_report_catcher;
  virtual function action_e catch(); // OK now
    if(m_enabled) `uvm_info("MYCTCHR", "Saw msg when enabled", UVM_LOW)
    return THROW;

Notice that in order to access action_e type I had to alias this into my_catcher's parent class, but m_enabled was always accessible.  That seems strange to me.  It seems incongruous to simply resolve the m_enabled binding while requiring the alias on the typedef.  Nonetheless, this is clearly understood spec behavior -- the compiler error seen and the non-issue on m_enabled is not unique to a specific simulator.

Am I missing something on the opaque extension that would be more appropriate?  It's not a big deal to alias the typedef in this case since the UVM library isn't changing all that often.  However, I do wish to avoid needing to alias each new typedef as base classes evolve.

Thoughts?  Is there another/better forum to direct this question?


Jeremy Ridgeway





Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...