Files
lucisv/crates/vlog_formatter/tests/cases/classes.cases
T
lucioandClaude Fable 5 7f2e78fc1c Add classes: SystemVerilog class support, corpus 58.0% -> 70.5%
The top corpus blocker (142 extends-blocked UVM/DV files) falls.
Structural support: class/virtual class with parameter ports,
extends (named/ordered params), implements, property qualifiers
(rand/randc/local/protected/static/const), virtual interface
properties, parameterized types, method qualifiers with extern and
pure-virtual prototypes plus out-of-body cls::method definitions,
typedef class, scoped parameterized calls, disable fork. Class
bodies reuse the existing item loop, so Meta, directives, macros and
nesting work with no per-site code. Constraint blocks, covergroups
and parameterized-type #() arguments are span-sliced verbatim leaves
-- their internals are a distinct sub-language where formatting has
no payoff and corruption risk is highest, so 9 masked-corruption
rejection tests ship although verify.rs is byte-identical
(invariant-4 discipline, voluntarily; QA's sabotage recreated the
historical in-string corruption and exactly one pin turned red).

Corpus: 476 -> 578/820 formattable (70.5%), parse-error 344 -> 242,
zero regressions by path, all 578 formattable files round-tripped
individually. 72 of the 142 extends files format; 70 advance to
named next blockers -- queues/dynamic arrays are now the top corpus
blocker (41 files). Two verification failures fixed en route: a
pre-existing lexer blank-line-after-continuation bug (proven
pre-existing on a HEAD worktree) and raw_inline convergence for
mid-line verbatim starts.

Handshakes filed: fences inactive inside class bodies; the four
AST-walking lint rules skip class members (line-based rules still
fire); vlog_semantic treats class bodies as opaque -- the LSP
navigation gap is that crate's natural next round. parse() now takes
the source (verbatim capture in strict mode); single caller updated.

612 workspace tests (397 cases). Dev: Opus agent; QA: Sonnet agent
(pre-feature worktree diff, full 578-file round-trip, UVM torture,
two reverted sabotages); review in docs/features/classes/README.md.

Co-Authored-By: Claude Fable 5 <[email protected]>
2026-08-19 13:45:18 -07:00

494 lines
10 KiB
Plaintext

# empty class
class c;
endclass
----
class c;
endclass
====
# class body is indented one level and endclass keeps its label
class c;
localparam int W = 8;
endclass : c
----
class c;
localparam int W = 8;
endclass : c
====
# virtual class
virtual class base;
endclass
----
virtual class base;
endclass
====
# extends a plain base class
class c extends base;
endclass
----
class c extends base;
endclass
====
# extends a package-scoped base class
class c extends pkg::base;
endclass
----
class c extends pkg::base;
endclass
====
# extends with named parameter overrides, joined onto the header line
class ibex_icache_core_driver
extends dv_base_driver #(.ITEM_T (req_item),
.CFG_T (agent_cfg));
endclass
----
class ibex_icache_core_driver extends dv_base_driver #(.ITEM_T(req_item), .CFG_T(agent_cfg));
endclass
====
# extends overrides break one per line when the header does not fit
class ibex_icache_core_agent extends dv_base_agent #(.CFG_T(ibex_icache_core_agent_cfg), .DRIVER_T(ibex_icache_core_driver), .MONITOR_T(ibex_icache_core_monitor));
endclass
----
class ibex_icache_core_agent extends dv_base_agent #(
.CFG_T(ibex_icache_core_agent_cfg),
.DRIVER_T(ibex_icache_core_driver),
.MONITOR_T(ibex_icache_core_monitor)
);
endclass
====
# extends with ordered (positional) overrides
class cov extends dv_base_agent_cov #(agent_cfg);
endclass
----
class cov extends dv_base_agent_cov #(agent_cfg);
endclass
====
# class parameter port list, and an extends clause using those parameters
class push_pull_driver #(
parameter int HostDataWidth = 32,
parameter int DeviceDataWidth = HostDataWidth
) extends dv_base_driver #(.CFG_T(cfg_t));
endclass
----
class push_pull_driver #(
parameter int HostDataWidth = 32,
parameter int DeviceDataWidth = HostDataWidth
) extends dv_base_driver #(.CFG_T(cfg_t));
endclass
====
# implements clause
class c implements a, b;
endclass
----
class c implements a, b;
endclass
====
# rand and randc properties
class item extends uvm_sequence_item;
rand bit [31:0] branch_addr;
randc int num_insns;
endclass
----
class item extends uvm_sequence_item;
rand bit [31:0] branch_addr;
randc int num_insns;
endclass
====
# local, protected, static and const properties
class c;
local int a;
protected bit b;
static int count;
const int limit = 4;
endclass
----
class c;
local int a;
protected bit b;
static int count;
const int limit = 4;
endclass
====
# a virtual-interface property
class cfg extends dv_base_agent_cfg;
virtual ibex_icache_core_if vif;
virtual interface other_if oif;
endclass
----
class cfg extends dv_base_agent_cfg;
virtual ibex_icache_core_if vif;
virtual interface other_if oif;
endclass
====
# a property whose type is parameterized
class c;
uvm_analysis_port #(bit [31:0]) analysis_port;
push_pull_agent_cfg #(HostDataWidth, DeviceDataWidth) cfg;
endclass
----
class c;
uvm_analysis_port #(bit [31:0]) analysis_port;
push_pull_agent_cfg #(HostDataWidth, DeviceDataWidth) cfg;
endclass
====
# methods: new, void function, task, and the qualifiers before them
class c;
function new(string name, uvm_component parent);
super.new(name, parent);
endfunction : new
virtual function void build_phase(uvm_phase phase);
super.build_phase(phase);
endfunction
virtual task automatic reset_signals();
cfg.vif.reset();
endtask
local function int helper();
return 1;
endfunction
endclass
----
class c;
function new(string name, uvm_component parent);
super.new(name, parent);
endfunction : new
virtual function void build_phase(uvm_phase phase);
super.build_phase(phase);
endfunction
virtual task automatic reset_signals();
cfg.vif.reset();
endtask
local function int helper();
return 1;
endfunction
endclass
====
# pure virtual prototypes have no body and no endfunction/endtask
virtual class sub_driver;
pure virtual function void reset_signals();
pure virtual task wait_cb(int num = 1);
endclass
----
virtual class sub_driver;
pure virtual function void reset_signals();
pure virtual task wait_cb(int num = 1);
endclass
====
# extern prototypes, and the out-of-body definition that goes with one
class dv_base_mem;
extern function void set_enable(bit enable);
endclass
function void dv_base_mem::set_enable(bit enable);
this.enable = enable;
endfunction
----
class dv_base_mem;
extern function void set_enable(bit enable);
endclass
function void dv_base_mem::set_enable(bit enable);
this.enable = enable;
endfunction
====
# a constraint block is reproduced byte for byte, only re-indented
class item;
constraint c_branch_addr_alignment {
// The branch address is always required to be half-word aligned.
!branch_addr[0];
(trans_type != Branch) -> branch_addr == 0;
solve trans_type before branch_addr;
}
endclass
----
class item;
constraint c_branch_addr_alignment {
// The branch address is always required to be half-word aligned.
!branch_addr[0];
(trans_type != Branch) -> branch_addr == 0;
solve trans_type before branch_addr;
}
endclass
====
# a constraint written at column 1 is re-indented into the class body
class item;
constraint c_dist {
num_insns dist { 0 :/ 5, [1:20] :/ 20, [21:100] :/ 1 };
}
endclass
----
class item;
constraint c_dist {
num_insns dist { 0 :/ 5, [1:20] :/ 20, [21:100] :/ 1 };
}
endclass
====
# a covergroup is reproduced byte for byte too, endgroup label included
class cov;
covergroup branch_dest_cg with function sample (bit [31:0] addr);
coverpoint addr {
bins zero = { 0 };
bins mid = default;
}
endgroup : branch_dest_cg
endclass
----
class cov;
covergroup branch_dest_cg with function sample (bit [31:0] addr);
coverpoint addr {
bins zero = { 0 };
bins mid = default;
}
endgroup : branch_dest_cg
endclass
====
# macro items inside a class body
class c extends base;
`uvm_component_utils(c)
`uvm_component_new
endclass
----
class c extends base;
`uvm_component_utils(c)
`uvm_component_new
endclass
====
# a bare macro item followed by a parameterized-type declaration
class c;
`uvm_component_new
uvm_analysis_port #(bit [31:0]) analysis_port;
endclass
----
class c;
`uvm_component_new
uvm_analysis_port #(bit [31:0]) analysis_port;
endclass
====
# compiler directives between class members
class c;
`ifdef VERILATOR
int a;
`else
int b;
`endif
`define CB cfg.vif.host_push_cb
endclass
----
class c;
`ifdef VERILATOR
int a;
`else
int b;
`endif
`define CB cfg.vif.host_push_cb
endclass
====
# a class inside a package
package p;
class c extends base;
int x;
endclass : c
endpackage
----
package p;
class c extends base;
int x;
endclass : c
endpackage
====
# a class nested inside a class
class outer;
class inner;
int x;
endclass
int y;
endclass
----
class outer;
class inner;
int x;
endclass
int y;
endclass
====
# typedef forward-declaring a class
typedef class push_pull_sub_driver;
typedef class push_host_driver;
----
typedef class push_pull_sub_driver;
typedef class push_host_driver;
====
# comments on class members, and a blank line between them
class c;
// what this holds
int a; // trailing
// and this
int b;
endclass
----
class c;
// what this holds
int a; // trailing
// and this
int b;
endclass
====
# a comment written just before endclass stays inside the class
class c;
int a;
// last word
endclass
----
class c;
int a;
// last word
endclass
====
# a comment after a constraint's closing brace is not swallowed by it
class c;
constraint x {
a == 0;
} // why
int b;
endclass
----
class c;
constraint x {
a == 0;
} // why
int b;
endclass
====
# statements a class body needs: new, super, scoped create, disable fork
class c;
function void build_phase(uvm_phase phase);
super.build_phase(phase);
analysis_port = new("analysis_port", this);
rsp = rsp_item::type_id::create("rsp");
endfunction
task t();
fork
a();
join_any
disable fork;
endtask
endclass
----
class c;
function void build_phase(uvm_phase phase);
super.build_phase(phase);
analysis_port = new("analysis_port", this);
rsp = rsp_item::type_id::create("rsp");
endfunction
task t();
fork
a();
join_any
disable fork;
endtask
endclass
====
# a parameterized class reference in expression position stays tight
class c;
function void build_phase(uvm_phase phase);
if (!uvm_config_db#(virtual core_if)::get(this, "", "vif", cfg.vif)) begin
`uvm_fatal(`gfn, "no vif")
end
sub = push_host_driver#(HostDataWidth, DeviceDataWidth)::type_id::create("sub");
endfunction
endclass
----
class c;
function void build_phase(uvm_phase phase);
if (!uvm_config_db#(virtual core_if)::get(this, "", "vif", cfg.vif)) begin
`uvm_fatal(`gfn, "no vif")
end
sub = push_host_driver#(HostDataWidth, DeviceDataWidth)::type_id::create("sub");
endfunction
endclass
====
# a local variable of virtual-interface type inside a method
class c;
virtual task body();
virtual core_ibex_dut_probe_if ibex_dut_vif;
x = 1;
endtask
endclass
----
class c;
virtual task body();
virtual core_ibex_dut_probe_if ibex_dut_vif;
x = 1;
endtask
endclass
====
# a declaration of a parameterized type inside a method body
class c;
task t();
item #(A, B) req;
req = null;
endtask
endclass
----
class c;
task t();
item #(A, B) req;
req = null;
endtask
endclass
====
# an instantiation still wins over a parameterized-type declaration
module m;
sub #(.W(8)) u (.a(a));
port_t #(int) p;
endmodule
----
module m;
sub #(.W(8)) u (.a(a));
port_t #(int) p;
endmodule
====
# a typedef and an import inside a class body
class c;
typedef enum logic [1:0] {A, B} state_e;
import pkg::thing;
endclass
----
class c;
typedef enum logic [1:0] {A, B} state_e;
import pkg::thing;
endclass
====
# a class with a static lifetime keyword
class static c;
int x;
endclass
----
class static c;
int x;
endclass
====
# a constraint standing alone with no braces (prototype form)
class c;
constraint x;
endclass
----
class c;
constraint x;
endclass
====
# a string inside a constraint keeps its bytes when the block is re-indented
class c;
constraint x {
name == "a
b";
}
endclass
----
class c;
constraint x {
name == "a
b";
}
endclass