Skip to content

Commit 6b5522a

Browse files
committed
SystemVerilog: class identifiers
1 parent e042948 commit 6b5522a

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

src/hw_cbmc_irep_ids.h

+1
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ IREP_ID_ONE(verilog_empty_item)
251251
IREP_ID_ONE(verilog_import_item)
252252
IREP_ID_ONE(verilog_interface)
253253
IREP_ID_ONE(verilog_class)
254+
IREP_ID_ONE(verilog_class_type)
254255
IREP_ID_ONE(verilog_module)
255256
IREP_ID_ONE(verilog_package)
256257
IREP_ID_ONE(verilog_package_import)

src/verilog/parser.y

+14-5
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ int yyverilogerror(const char *error)
537537
/* Others */
538538
%token TOK_ENDOFFILE
539539
%token TOK_NON_TYPE_IDENTIFIER
540+
%token TOK_CLASS_IDENTIFIER
540541
%token TOK_PACKAGE_IDENTIFIER
541542
%token TOK_TYPE_IDENTIFIER
542543
%token TOK_NUMBER // number, any base
@@ -819,12 +820,13 @@ checker_port_direction_opt:
819820
;
820821

821822
class_declaration:
822-
TOK_CLASS class_identifier
823+
TOK_CLASS any_identifier
823824
';'
824825
{
825826
init($$, ID_verilog_class);
826-
stack_expr($$).set(ID_base_name, stack_expr($2).id());
827-
push_scope(stack_expr($2).id(), "::", verilog_scopet::CLASS);
827+
auto base_name = stack_expr($2).get(ID_base_name);
828+
stack_expr($$).set(ID_base_name, base_name);
829+
push_scope(base_name, "::", verilog_scopet::CLASS);
828830
}
829831
class_item_brace
830832
TOK_ENDCLASS
@@ -1553,7 +1555,7 @@ data_type:
15531555
{ mto($1, $2);
15541556
add_as_subtype(stack_type($3), stack_type($2));
15551557
$$ = $3; }
1556-
// | class_type
1558+
| class_type
15571559
| TOK_EVENT
15581560
{ init($$, ID_verilog_event); }
15591561
/*
@@ -4383,7 +4385,14 @@ non_type_identifier: TOK_NON_TYPE_IDENTIFIER
43834385

43844386
block_identifier: TOK_NON_TYPE_IDENTIFIER;
43854387

4386-
class_identifier: TOK_NON_TYPE_IDENTIFIER;
4388+
class_identifier: TOK_CLASS_IDENTIFIER
4389+
{
4390+
init($$, ID_verilog_class_type);
4391+
auto base_name = stack_expr($1).id();
4392+
stack_expr($$).set(ID_base_name, base_name);
4393+
stack_expr($$).set(ID_identifier, PARSER.scopes.current_scope().prefix+id2string(base_name));
4394+
}
4395+
;
43874396

43884397
constraint_identifier: TOK_NON_TYPE_IDENTIFIER;
43894398

src/verilog/verilog_scope.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ unsigned verilog_scopest::identifier_token(irep_idt base_name) const
6262
case verilog_scopet::FILE: return TOK_NON_TYPE_IDENTIFIER;
6363
case verilog_scopet::PACKAGE: return TOK_PACKAGE_IDENTIFIER;
6464
case verilog_scopet::MODULE: return TOK_NON_TYPE_IDENTIFIER;
65-
case verilog_scopet::CLASS: return TOK_NON_TYPE_IDENTIFIER;
65+
case verilog_scopet::CLASS: return TOK_CLASS_IDENTIFIER;
6666
case verilog_scopet::BLOCK: return TOK_NON_TYPE_IDENTIFIER;
6767
case verilog_scopet::ENUM_NAME: return TOK_NON_TYPE_IDENTIFIER;
6868
case verilog_scopet::TASK: return TOK_NON_TYPE_IDENTIFIER;

0 commit comments

Comments
 (0)