Files
iverilog/ivtest/ivltests/enum_in_class.v
T
Lars-Peter Clausen 427091d3d3 Support access to class constants on objects
It is allowed to access a constant declared in a class scope, such as a
enum value or parameter, on an object of that class type. This is described
in section 8.5 ("Object properties and object parameter data") of the LRM
(1800-2017).

E.g.

```
class C
  enum { A } e;
endclass

C c = new;
c.e = c.A;
```

Support this by in addition of searching for class properties on the object
also search for constants in the class scope.

A bit of refactoring is needed around the parameter elaboration functions
since they expect a non-const NetScope, but for classes we only have a
const scope available.

The non-const scope is needed to be able to mark specparams as
non-annotatable. Since classes can't have specparams this part is factored
out into a separate function the NetScope parameter for the shared
functions is made const.

Signed-off-by: Lars-Peter Clausen <[email protected]>
2022-02-19 13:45:14 +01:00

53 lines
922 B
Verilog

// Check that when a enum type is declared inside a class that the enum is
// properly installed in the scope and the enum items are available.
//
// Also check that when using a typedef of a enum inside a class that the enum
// is not elaborated inside the class and it is possible to have a enum with the
// same names inside the class scope.
module test;
typedef enum integer {
A = 1
} e1_t;
class C;
typedef enum integer {
A = 10
} e2_t;
e1_t e1;
e2_t e2;
function new();
e1 = test.A;
e2 = A;
endfunction
function void set(e2_t new_e2);
e2 = new_e2;
endfunction
endclass
C c;
initial begin
c = new;
c.e1 = A;
c.set(c.e2);
// Not yet supported
// c.e2 = C::A;
c.e2 = c.A;
// Check that they have the numerical value from the right scope
if (c.e1 == 1 && c.e2 == 10) begin
$display("PASSED");
end else begin
$display("FAILED");
end
end
endmodule