From a09e1750682ee19b21c5785f34f3db39e15a2f2e Mon Sep 17 00:00:00 2001 From: yui-knk Date: Tue, 31 Oct 2017 00:46:30 +0000 Subject: 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 --- node.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'node.h') diff --git a/node.h b/node.h index 04434cb48c..29eaafd3ec 100644 --- a/node.h +++ b/node.h @@ -30,6 +30,8 @@ enum node_type { #define NODE_UNLESS NODE_UNLESS NODE_CASE, #define NODE_CASE NODE_CASE + NODE_CASE2, +#define NODE_CASE2 NODE_CASE2 NODE_WHEN, #define NODE_WHEN NODE_WHEN NODE_WHILE, @@ -355,6 +357,7 @@ typedef struct RNode { #define NEW_IF(c,t,e) NEW_NODE(NODE_IF,c,t,e) #define NEW_UNLESS(c,t,e) NEW_NODE(NODE_UNLESS,c,t,e) #define NEW_CASE(h,b) NEW_NODE(NODE_CASE,h,b,0) +#define NEW_CASE2(h,b) NEW_NODE(NODE_CASE2,h,b,0) #define NEW_WHEN(c,t,e) NEW_NODE(NODE_WHEN,c,t,e) #define NEW_WHILE(c,b,n) NEW_NODE(NODE_WHILE,c,b,n) #define NEW_UNTIL(c,b,n) NEW_NODE(NODE_UNTIL,c,b,n) -- cgit v1.2.3