-
Notifications
You must be signed in to change notification settings - Fork 529
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #984 from larsclausen/class-constructor-chain
Fix class constructor chaining corner cases
- Loading branch information
Showing
16 changed files
with
216 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Check that the constructor of a base class gets called exactly once when | ||
// mixing implicit and explicit constructors. | ||
|
||
module test; | ||
|
||
bit failed = 1'b0; | ||
|
||
`define check(val, exp) do begin \ | ||
if ((val) !== (exp)) begin \ | ||
$display("FAILED(%0d): `%s`, expected `%0d`, got `%0d`.", `__LINE__, \ | ||
`"val`", (exp), (val)); \ | ||
failed = 1'b1; \ | ||
end \ | ||
end while (0) | ||
|
||
int c_new_calls = 0; | ||
|
||
class C; | ||
function new; | ||
c_new_calls++; | ||
endfunction | ||
endclass | ||
|
||
class D extends C; | ||
int x = 10; | ||
endclass | ||
|
||
initial begin | ||
D d; | ||
d = new; | ||
|
||
`check(c_new_calls, 1); | ||
`check(d.x, 10); | ||
|
||
if (!failed) begin | ||
$display("PASSED"); | ||
end | ||
end | ||
|
||
endmodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Check that the constructor of a base class gets called exactly once when | ||
// mixing implicit and explicit constructors. | ||
|
||
module test; | ||
|
||
bit failed = 1'b0; | ||
|
||
`define check(val, exp) do begin \ | ||
if ((val) !== (exp)) begin \ | ||
$display("FAILED(%0d): `%s`, expected `%0d`, got `%0d`.", `__LINE__, \ | ||
`"val`", (exp), (val)); \ | ||
failed = 1'b1; \ | ||
end \ | ||
end while (0) | ||
|
||
int d_new_calls = 0; | ||
|
||
class C; | ||
int x = 10; | ||
endclass | ||
|
||
class D extends C; | ||
function new; | ||
d_new_calls++; | ||
endfunction | ||
endclass | ||
|
||
class E extends D; | ||
int y; | ||
function new; | ||
y = 20; | ||
endfunction | ||
endclass | ||
|
||
initial begin | ||
E e; | ||
e = new; | ||
|
||
`check(d_new_calls, 1); | ||
`check(e.x, 10); | ||
`check(e.y, 20); | ||
|
||
if (!failed) begin | ||
$display("PASSED"); | ||
end | ||
end | ||
|
||
endmodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Check that forwarding base class constructor arguments through the `extends` | ||
// works when the derived class has no constructor. | ||
|
||
module test; | ||
|
||
class C; | ||
function new(int a); | ||
if (a == 10) begin | ||
$display("PASSED"); | ||
end else begin | ||
$display("FAILED"); | ||
end | ||
endfunction | ||
endclass | ||
|
||
// D has no constructor | ||
class D extends C(10); | ||
endclass | ||
|
||
D d = new; | ||
|
||
endmodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Check that forwarding base class constructor arguments through the `extends` | ||
// works when the derived class has an implicit constructor. | ||
|
||
module test; | ||
|
||
class C; | ||
function new(int a); | ||
if (a == 10) begin | ||
$display("PASSED"); | ||
end else begin | ||
$display("FAILED"); | ||
end | ||
endfunction | ||
endclass | ||
|
||
// D has an implicit constructor | ||
class D extends C(10); | ||
int y; | ||
endclass | ||
|
||
D d = new; | ||
|
||
endmodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Check that forwarding base class constructor arguments through the `extends` | ||
// works when the derived class has an explicit constructor. | ||
|
||
module test; | ||
|
||
class C; | ||
function new(int a); | ||
if (a == 10) begin | ||
$display("PASSED"); | ||
end else begin | ||
$display("FAILED"); | ||
end | ||
endfunction | ||
endclass | ||
|
||
// D has an explicit constructor | ||
class D extends C(10); | ||
int x; | ||
function new; | ||
x = 10; | ||
endfunction | ||
endclass | ||
|
||
D d = new; | ||
|
||
endmodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"type" : "normal", | ||
"source" : "sv_chained_constructor1.v", | ||
"iverilog-args" : [ "-g2005-sv" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"type" : "normal", | ||
"source" : "sv_chained_constructor2.v", | ||
"iverilog-args" : [ "-g2005-sv" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"type" : "normal", | ||
"source" : "sv_chained_constructor3.v", | ||
"iverilog-args" : [ "-g2005-sv" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"type" : "normal", | ||
"source" : "sv_chained_constructor4.v", | ||
"iverilog-args" : [ "-g2005-sv" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"type" : "normal", | ||
"source" : "sv_chained_constructor5.v", | ||
"iverilog-args" : [ "-g2005-sv" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters