File: t_class_super_new.v

package info (click to toggle)
verilator 5.038-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 162,552 kB
  • sloc: cpp: 139,204; python: 20,931; ansic: 10,222; yacc: 6,000; lex: 1,925; makefile: 1,260; sh: 494; perl: 282; fortran: 22
file content (158 lines) | stat: -rw-r--r-- 3,245 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain, for
// any use, without warranty, 2023 by Antmicro Ltd.
// SPDX-License-Identifier: CC0-1.0

`define stop $stop
`define checkh(gotv,expv) do if ((gotv) !== (expv)) begin $write("%%Error: %s:%0d:  got='h%x exp='h%x\n", `__FILE__,`__LINE__, (gotv), (expv)); `stop; end while(0);

class Foo;
   int x;
   function new;
      this.x = 10;
   endfunction
endclass

class Bar extends Foo;
   function new;
      super.new;
   endfunction
endclass

class BarUnusedArg extends Foo;
   function new (int a);
      super.new;
   endfunction
endclass

class FooArg;
   int x;
   function new (int a);
      this.x = a;
   endfunction
endclass

class BarArg extends FooArg;
   function new (int a);
      super.new(a);
   endfunction
endclass

class BarArgWithReturnInIf extends FooArg;
   function new (int a);
      super.new(a);
      if (a < 10) begin
         return;
      end
      this.x = 20;
   endfunction
endclass

class BarExpr extends FooArg;
   function new (int a, string b);
      super.new(a + b.len());
   endfunction
endclass

class Foo2Args;
   int x;
   function new (int a, int b);
      this.x = a + b;
   endfunction
endclass

class Bar2Args extends Foo2Args;
   function new (int a, int b);
      super.new(a, b);
   endfunction
endclass

class OptArgInNew;
   int x;
   function new (int y=1);
      x = y;
   endfunction
endclass

class NoNew extends OptArgInNew;
endclass

class NewWithoutSuper extends OptArgInNew;
   function new;
   endfunction
endclass

class OptArgInNewParam #(parameter int P=1);
   int x;
   function new (int y=1);
      x = y;
   endfunction
endclass

class NoNewParam#(parameter int R) extends OptArgInNewParam#(R);
endclass

class NewWithoutSuperParam#(parameter int R) extends OptArgInNewParam#();
   function new;
   endfunction
endclass

module t (/*AUTOARG*/
   );

   class FooInModule;
      int x;
      function new;
         this.x = 15;
      endfunction
   endclass

   class BarInModule extends FooInModule;
      function new;
         super.new;
      endfunction
   endclass

   Bar bar;
   BarInModule barInModule;
   BarUnusedArg barUnusedArg;
   BarArg barArg;
   BarExpr barExpr;
   Bar2Args bar2Args;
   NoNew noNew;
   NewWithoutSuper newWithoutSuper;
   NoNewParam#(2) noNewParam;
   NewWithoutSuperParam#(1) newWithoutSuperParam;
   BarArgWithReturnInIf barIf1, barIf10;

   initial begin
      bar = new;
      `checkh(bar.x, 10);
      barInModule = new;
      `checkh(barInModule.x, 15);
      barUnusedArg = new(2);
      `checkh(barUnusedArg.x, 10);
      barArg = new(2);
      `checkh(barArg.x, 2);
      barExpr = new (7, "ABCDEFGHI");
      `checkh(barExpr.x, 16);
      bar2Args = new(2, 12);
      `checkh(bar2Args.x, 14);
      noNew = new;
      `checkh(noNew.x, 1);
      newWithoutSuper = new;
      `checkh(newWithoutSuper.x, 1);
      noNewParam = new;
      `checkh(noNewParam.x, 1);
      newWithoutSuperParam = new;
      `checkh(newWithoutSuperParam.x, 1);
      barIf1 = new(1);
      `checkh(barIf1.x, 1);
      barIf10 = new(10);
      `checkh(barIf10.x, 20);

      $write("*-* All Finished *-*\n");
      $finish;
   end
endmodule