From 571f222a73169ae264e0a981d4ba2ede878f6fae Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sat, 26 Mar 2022 20:37:41 +0100 Subject: [PATCH] Add additional regression tests for class syntax Check that it is possible to both declare and call class constructors without using parenthesis after the `new` keyword. Check that a non-ANSI port for a class constructor results in an error. Check that it is possible to invoke a class task through a implicit class handle (`this` or `super`) without using parenthesis after the task name. Signed-off-by: Lars-Peter Clausen --- ivtest/ivltests/sv_class_constructor1.v | 14 +++++++++++++ ivtest/ivltests/sv_class_constructor_fail.v | 14 +++++++++++++ ivtest/ivltests/sv_class_super1.v | 21 ++++++++++++++++++++ ivtest/ivltests/sv_class_super2.v | 21 ++++++++++++++++++++ ivtest/ivltests/sv_class_task1.v | 22 +++++++++++++++++++++ ivtest/regress-sv.list | 5 +++++ ivtest/regress-vlog95.list | 4 ++++ 7 files changed, 101 insertions(+) create mode 100644 ivtest/ivltests/sv_class_constructor1.v create mode 100644 ivtest/ivltests/sv_class_constructor_fail.v create mode 100644 ivtest/ivltests/sv_class_super1.v create mode 100644 ivtest/ivltests/sv_class_super2.v create mode 100644 ivtest/ivltests/sv_class_task1.v diff --git a/ivtest/ivltests/sv_class_constructor1.v b/ivtest/ivltests/sv_class_constructor1.v new file mode 100644 index 000000000..e886b6f57 --- /dev/null +++ b/ivtest/ivltests/sv_class_constructor1.v @@ -0,0 +1,14 @@ +// Check that a class constructor declaration without parenthesis after the +// `new` is supported. + +module test; + + class C; + function new; + $display("PASSED"); + endfunction + endclass + + C c = new; + +endmodule diff --git a/ivtest/ivltests/sv_class_constructor_fail.v b/ivtest/ivltests/sv_class_constructor_fail.v new file mode 100644 index 000000000..66490d706 --- /dev/null +++ b/ivtest/ivltests/sv_class_constructor_fail.v @@ -0,0 +1,14 @@ +// Check that a class constructor with non-ANSI port results in an error. + +module test; + + class C; + function new; + input x; // This is a syntax error + $display("FAILED"); + endfunction + endclass + + C c = new; + +endmodule diff --git a/ivtest/ivltests/sv_class_super1.v b/ivtest/ivltests/sv_class_super1.v new file mode 100644 index 000000000..ddc7b1a77 --- /dev/null +++ b/ivtest/ivltests/sv_class_super1.v @@ -0,0 +1,21 @@ +// Check that it is possible to explicitly call the base class constructor, even +// if it does not take any parameters. Check that it is possible to call it with +// parenthesis after the `new`. + +module test; + + class B; + function new(); + $display("PASSED"); + endfunction + endclass + + class C extends B; + function new(); + super.new(); + endfunction + endclass + + C c = new; + +endmodule diff --git a/ivtest/ivltests/sv_class_super2.v b/ivtest/ivltests/sv_class_super2.v new file mode 100644 index 000000000..b21165d1f --- /dev/null +++ b/ivtest/ivltests/sv_class_super2.v @@ -0,0 +1,21 @@ +// Check that it is possible to explicitly call the base class constructor, even +// if it does not take any parameters. Check that it is possible to call it +// without parenthesis after the `new`. + +module test; + + class B; + function new(); + $display("PASSED"); + endfunction + endclass + + class C extends B; + function new(); + super.new; + endfunction + endclass + + C c = new; + +endmodule diff --git a/ivtest/ivltests/sv_class_task1.v b/ivtest/ivltests/sv_class_task1.v new file mode 100644 index 000000000..5674ec950 --- /dev/null +++ b/ivtest/ivltests/sv_class_task1.v @@ -0,0 +1,22 @@ +// Check that it is possible to call a class task without parenthesis after the +// task name when using the implicit `this` class handle. + +module test; + + class C; + task a; + $display("PASSED"); + endtask + + task b; + this.a; + endtask + endclass + + C c = new; + + initial begin + c.b; + end + +endmodule diff --git a/ivtest/regress-sv.list b/ivtest/regress-sv.list index 8312bd6b3..4cdfd6f39 100644 --- a/ivtest/regress-sv.list +++ b/ivtest/regress-sv.list @@ -474,11 +474,16 @@ sv_class21 normal,-g2009 ivltests sv_class22 normal,-g2009 ivltests sv_class23 normal,-g2009 ivltests sv_class24 normal,-g2009 ivltests +sv_class_constructor1 normal,-g2009 ivltests +sv_class_constructor_fail CE,-g2009 ivltests sv_class_empty_item normal,-g2009 ivltests sv_class_extends_scoped normal,-g2009 ivltests sv_class_localparam normal,-g2009 ivltests sv_class_new_init normal,-g2009 ivltests sv_class_in_module_decl normal,-g2009 ivltests +sv_class_super1 normal,-g2009 ivltests +sv_class_super2 normal,-g2009 ivltests +sv_class_task1 normal,-g2009 ivltests sv_darray1 normal,-g2009 ivltests sv_darray2 normal,-g2009 ivltests sv_darray3 normal,-g2009 ivltests diff --git a/ivtest/regress-vlog95.list b/ivtest/regress-vlog95.list index f5944b788..a9ddc0ff2 100644 --- a/ivtest/regress-vlog95.list +++ b/ivtest/regress-vlog95.list @@ -372,11 +372,15 @@ sv_class21 CE,-g2009 ivltests sv_class22 CE,-g2009 ivltests sv_class23 CE,-g2009 ivltests sv_class24 CE,-g2009 ivltests +sv_class_constructor1 CE,-g2009 ivltests sv_class_empty_item CE,-g2009 ivltests sv_class_extends_scoped CE,-g2009 ivltests sv_class_localparam CE,-g2009 ivltests sv_class_new_init CE,-g2009 ivltests sv_class_in_module_decl CE,-g2009 ivltests +sv_class_super1 CE,-g2009 ivltests +sv_class_super2 CE,-g2009 ivltests +sv_class_task1 CE,-g2009 ivltests sv_end_label CE,-g2009 ivltests # Also generate sv_foreach2 CE,-g2009,-pallowsigned=1 ivltests sv_foreach3 CE,-g2009 ivltests