|
|
|
|
|
|
|
|
|
|
|
|
Class Members
|
|
|
A class can have following members, |
|
|
|
|
|
|
|
|
|
|
|
Properties
|
|
|
Properties can be of following data types. |
|
|
|
|
|
- reg
- reg [msb:0]
- integer
- string
- event
- class type
- enum type
|
|
|
|
|
|
Properties can be declared as following |
|
|
|
|
|
- local : Properties are local to object. This is visible only inside the class.
- public: Properties are public, this is by default. This is visible outside the class.
- protected : This is not visible outside the class, but can be accessed by friend/peer/inherited class.
|
|
|
|
|
|
Accessing Properties |
|
|
|
|
|
An object can be accessed using the dot operator (.). The handle name for the object precedes the dot, followed by the qualifying property name (for example, address, command). |
|
|
|
|
|
instance_name.property_name |
|
|
|
|
|
Sharing Class Properties |
|
|
The static keyword is used to identify a class property that is shared with all instances of the class. A static properties is not unique to a single object (that is, all objects of the same type share the property). |
|
|
|
|
|
Example : Properties
|
|
|
|
|
|
1 class A {
2 public integer data;
3 local integer addr;
4 protected integer cmd;
5 static integer credits;
6 task new() {
7 data = 100;
8 addr = 200;
9 cmd = 1;
10 credits = 10;
11 }
12 task printA() {
13 printf ("value of data %0d in A\n", data);
14 printf ("value of addr %0d in A\n", addr);
15 printf ("value of cmd %0d in A\n", cmd);
16 }
17 }
18
19 class B extends A {
20 task printB() {
21 printf ("value of data %0d in B\n", data);
22 // Below line will give compile error
23 //printf ("value of addr %0d in B\n", addr);
24 printf ("value of cmd %0d in B\n", cmd);
25 }
26 }
27
28 class C {
29 A a;
30 B b;
31 task new() {
32 a = new();
33 b = new();
34 b.data = 2;
35 }
36 task printC() {
37 printf ("value of data %0d in C\n", a.data);
38 printf ("value of data %0d in C\n", b.data);
39 // Below line will give compile error
40 //printf ("value of addr %0d in C\n", a.addr);
41 //printf ("value of cmd %0d in C\n", a.cmd);
42 //printf ("value of addr %0d in C\n", b.addr);
43 //printf ("value of cmd %0d in C\n", b.cmd);
44 }
45 }
46
47 program properties {
48 C c = new();
49 c.a.printA();
50 c.b.printB();
51 c.printC();
52 printf("value of credits is %0d\n",c.a.credits);
53 printf("value of credits is %0d\n",c.b.credits);
54 c.a.credits ++;
55 printf("value of credits is %0d\n",c.a.credits);
56 printf("value of credits is %0d\n",c.b.credits);
57 c.b.credits ++;
58 printf("value of credits is %0d\n",c.a.credits);
59 printf("value of credits is %0d\n",c.b.credits);
60 }
You could download file properties.vr here
|
|
|
|
|
|
|
|
|
|
|
|
Simulation : Properties
|
|
|
|
|
|
value of data 100 in A
value of addr 200 in A
value of cmd 1 in A
value of data 2 in B
value of cmd 1 in B
value of data 100 in C
value of data 2 in C
value of credits is 10
value of credits is 10
value of credits is 11
value of credits is 11
value of credits is 12
value of credits is 12
|
|
|
|
|
|
Methods
|
|
|
Tasks or functions, known as methods, can be designated as local, public, or protected. They are public by default. Accessing Object Methods An object´s methods can be accessed using the dot operator (.). The handle for the object precedes the dot, followed by the method. |
|
|
|
|
|
this
|
|
|
The this keyword is used to unambiguously refer to properties or methods of the current instance. |
|
|
|
|
|
Example : this
|
|
|
|
|
|
1 class A {
2 integer i;
3
4 task set_i(integer value) {
5 this.i = value;
6 }
7 }
8
9 program this_ex {
10 A a = new();
11 printf("value of i is %0d\n",a.i);
12 a.set_i(100);
13 printf("value of i is %0d\n",a.i);
14 }
You could download file this_ex.vr here
|
|
|
|
|
|
Simulation : this
|
|
|
|
|
|
value of i is x
value of i is 100
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Copyright © 1998-2014 |
Deepak Kumar Tala - All rights reserved |
Do you have any Comment? mail me at:deepak@asic-world.com
|
|