SystemVerilog Datatype: Class (Part 1)

Previous: Object Instance and Object Handle | Next: Static properties and Methods

Object Properties and Object Methods

Once you properly define an object handle, you can use the properties and methods associated with that object in your code.

Object properties can be modified or checked following the syntax below. Note that, the delimiter "." is used for accessing properties within a class.

   Triangle t = new;

   t.lastFillTime = $time;

   t.p1.xy.x = 10;
   t.p1.xy.y =  5;

   t.p3.xy.x = 17;
   t.p3.xy.y =  3;

You might have noticed few things in the above example.

  • Recall that, p1, p2 and p3 are of union type point. The delimiter "." is used for both class properties (t.p1 and t.p3) as well as the individual field of the properties (p1.xy.x etc.).
  • Furthermore, p2 is not modified, so its members will have default values as defined by the function new().

For methods, we can use a similar syntax:

   if (!t.isFilled)
      t.fillIt(color1);

Note again, that the methods, such as, t.isFilled() and t.fillIt() can only work on the properties of the same instance of the class, in this case, namely, t. To illustrate this more, suppose there are two object handles t1 and t2 of the class Triangle.

   Triangle t1 = new;
   Triangle t2 = new;

In this case, t1.fillIt(color1) can only work with t1.p1, t1.p2, t1.p3, and t1.lastFillTime, whereas, t2fillIt(myColor) can work on t2.p1, t2.p2, t2.p3, and t2.lastFillTime. This is the essence of object-oriented methodology that classes bring in to SystemVerilog.

Previous: Object Instance Object Handle | Next: Static properties and Methods

Share/Save/Bookmark



Verification Management
Join Verification Management Group


Shop Amazon - Contract Cell Phones & Service Plans

Book of the Month