mirror of
https://github.com/ruby/ruby.git
synced 2025-08-23 13:04:13 +02:00
Use NODE_CASE2 if case expressions don't exist
When NODE_WHEN is compiled by iseq_compile_each0, the node passed to compile_when is NODE_WHEN (not NODE_CASE). So we can not handle the location of NODE_CASE of case statements which don't have case expressions. e.g. : ``` case; when 1; foo; when 2; bar; else baz; end ``` This commit adds NODE_CASE2, and compiles it by iseq_compile_each0. * compile.c (compile_case): Does not call COMPILE_ when NODE_CASE does not have case expressions. * compile.c (compile_case2): Compile NODE_CASE2 by compile_case2. * compile.c (compile_when): Delete an obsoleted function. * compile.c (iseq_compile_each0): Compile NODE_CASE2. * ext/objspace/objspace.c (count_nodes): Add NODE_CASE2 case. * node.c (dump_node, rb_gc_mark_node): Add NODE_CASE2 case. * node.h (node_type): Add NODE_CASE2. * node.h (NEW_CASE2): Add a macro which generates NODE_CASE2. * parse.y: Generate NODE_CASE2 if case expressions don't exist. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60585 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
bb88b1aab8
commit
a09e175068
5 changed files with 22 additions and 12 deletions
9
node.c
9
node.c
|
@ -219,6 +219,14 @@ dump_node(VALUE buf, VALUE indent, int comment, NODE *node)
|
|||
LAST_NODE;
|
||||
F_NODE(nd_body, "when clauses");
|
||||
return;
|
||||
case NODE_CASE2:
|
||||
ANN("case statement");
|
||||
ANN("format: case; [nd_body]; end");
|
||||
ANN("example: case; when 1; foo; when 2; bar; else baz; end");
|
||||
F_NODE(nd_head, "case expr");
|
||||
LAST_NODE;
|
||||
F_NODE(nd_body, "when clauses");
|
||||
return;
|
||||
|
||||
case NODE_WHEN:
|
||||
ANN("if statement");
|
||||
|
@ -1125,6 +1133,7 @@ rb_gc_mark_node(NODE *obj)
|
|||
case NODE_AND:
|
||||
case NODE_OR:
|
||||
case NODE_CASE:
|
||||
case NODE_CASE2:
|
||||
case NODE_SCLASS:
|
||||
case NODE_DOT2:
|
||||
case NODE_DOT3:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue