Section 7.11 Assignment, renaming, and copying

In 7.11, following the paragraph that begins:

                The last statement has new executing a second time, thus creating a new object p2, whose class properties are copied from p1. This is known as a shallow copy. …

ADD the new paragraph

                A shallow copy executes in the following manner:

1.        An object of the class type being copied is allocated. This allocation shall not call the objects constructor or execute any variable declaration initialization assignments.

2.        All class properties, including the internal states uses for randomization and coverage are copied to the new object. Object handles are copied, this includes the object handles for covergroup objects (See clause 18). The internal states for randomization include the RNG state, the ‘constraint_mode’ status of constraints, the ‘rand_mode’ status of random variables, and the cyclic state of randc variables (See clause 13).

3.        A handle to the newly created object is assigned to the variable on the left-hand side.

 Note: A shallow copy does not create new coverage objects (covergroup instances). As a result, the properties of the new object are not covered.

 

MODIFY the example (following the paragraph)

              class A ;

  integer j = 5;

endclass

class B ;

  integer i = 1;

  A a = new;

endclass

class C extend A ;

  rand int x;

  constraint cst1 { x < 10; }

endclass

function integer test;

  B b1 = new; // Create an object of class B

  B b2 = new b1; // Create an object that is a copy of b1

  C c1 = new; // Create an object of class C

  A c2, c3; // Declare class variables (null value)

  b2.i = 10; // i is changed in b2, but not in b1

  b2.a.j = 50; // change a.j, shared by both b1 and b2

  test = b1.i; // test is set to 1 (b1.i has not changed)

  test = b1.a.j; // test is set to 50 (a.j has changed)

  c1.x = 3;

  c2 = c1;  // c2 refers to the same object as c1

  c3 = new c2; // Creates a shallow copy of c1 (including property x)

endfunction