In reply to dave_59:
Thanks, Dave. I did some more digging on the C++ forward declarations of classes.
I was wrong about an equivalent bit of C++ code (described above) being compilable. It’s illegal to use a forward class declaration in C++ (defined as an “incomplete type”) to declare a class member ( see http://jatinganhotra.com/blog/2012/11/25/forward-class-declaration-in-c-plus-plus/ and especially c++ - When can I use a forward declaration? - Stack Overflow ).
typedef class this_test;
class unsupported_transaction_seq extends hda_sequence_base;
this_test tst_ptr; // This is illegal in C++ if "this_test" is an incomplete type
From the SV 2012 LRM pg 77 section 6.18 and pg 167 section 8.27, it does not appear that SV behaves like C++ with respect to forward class declarations.
SV 2012 LRM states “The actual data type definition of a forward typedef declaration shall be resolved within the same local scope or generate block.” (pg 77 and 167).
So, for example, it does not appear that you can use an “incomplete type” to declare functions which accept or return incomplete types. The type definition must occur in the same local scope. I think that C++ does allow this construction and so you can defer the type definition until the linker stage of compilation. The advantage in C++ is that you can reduce the number of include dependencies with this capability.
To be more concrete, something like
typedef class bar;
class foo;
extern function bar widget();
endclass : foo
would be illegal in SV unless the class definition were present in the same local scope (you either (1) add an `include of the file containing the class ‘bar’ definition, (2) compile multiple files in the same command-line where 1 of the files contains the class ‘bar’ definition or (3) stick the class definition of ‘bar’ at the end of the file).
I’m trying to understand how to best split class declarations and definitions into separate files (.svh and .sv respectively) to minimize the amount of incremental compilation needed when updates occur. There are some pretty good guidelines on how to do this in C++ but the SV community appears silent on the matter. In the UVM BCL, a class is declared and defined in the same .svh file. Then, they’re all `include’d into a single package (in uvm_pkg.sv).
Is this Mentor’s recommended practice when putting together SV class-based code? That is, declare the class, use extern on class methods (out-of-block declarations) and then later on in the same file include the implementation.