Skip to content

Commit 7d82d80

Browse files
authored
Merge pull request YosysHQ#5344 from higuoxing/midrule
verilog_parser: replace manual AST node allocation with typed midrule actions
2 parents a2fc7e4 + 3d2bb1d commit 7d82d80

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

frontends/verilog/verilog_parser.y

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3289,15 +3289,19 @@ basic_expr:
32893289
$$ = AstNode::mkconst_str(@1, *$1);
32903290
SET_AST_NODE_LOC($$.get(), @1, @1);
32913291
} |
3292-
hierarchical_id attr {
3293-
// super sketchy! Orphaned pointer in non-owning extra->ast_stack
3294-
AstNode *node = new AstNode(@1, AST_FCALL);
3295-
node->str = *$1;
3296-
extra->ast_stack.push_back(node);
3297-
SET_AST_NODE_LOC(node, @1, @1);
3298-
append_attr(node, std::move($2));
3292+
hierarchical_id attr <ast_t>{
3293+
// Here we use "Typed Midrule Actions".
3294+
// https://www.gnu.org/software/bison/manual/html_node/Typed-Midrule-Actions.html
3295+
auto fcall = std::make_unique<AstNode>(@1, AST_FCALL);
3296+
AstNode *fcall_node = fcall.get();
3297+
fcall_node->str = *$1;
3298+
extra->ast_stack.push_back(fcall_node);
3299+
SET_AST_NODE_LOC(fcall_node, @1, @1);
3300+
append_attr(fcall_node, std::move($2));
3301+
$$ = std::move(fcall);
32993302
} TOK_LPAREN arg_list optional_comma TOK_RPAREN {
3300-
$$.reset(extra->ast_stack.back());
3303+
log_assert($3 != nullptr);
3304+
$$ = std::move($3);
33013305
extra->ast_stack.pop_back();
33023306
} |
33033307
TOK_TO_SIGNED attr TOK_LPAREN expr TOK_RPAREN {

0 commit comments

Comments
 (0)