summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-01-08 12:30:35 +0000
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-01-08 12:30:35 +0000
commit47cf2fd7ec0b0deafe209b92f94452e64869b25c (patch)
tree914cceb5169c17f2dc40dcdccd836f023727b0fc
parentdab956b7e66badf0ead4a74d36f3618510bf0aad (diff)
parse.y: Factor out code fragments that merges two code ranges
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61688 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--node.h8
-rw-r--r--parse.y44
2 files changed, 20 insertions, 32 deletions
diff --git a/node.h b/node.h
index b18d96357a..0a2fe4f3ed 100644
--- a/node.h
+++ b/node.h
@@ -232,6 +232,14 @@ typedef struct rb_code_range_struct {
rb_code_location_t last_loc;
} rb_code_range_t;
+static inline rb_code_range_t code_range_gen(rb_code_range_t *cr1, rb_code_range_t *cr2)
+{
+ rb_code_range_t cr;
+ cr.first_loc = cr1->first_loc;
+ cr.last_loc = cr2->last_loc;
+ return cr;
+}
+
typedef struct RNode {
VALUE flags;
union {
diff --git a/parse.y b/parse.y
index c7593d39f0..2ba6925816 100644
--- a/parse.y
+++ b/parse.y
@@ -1398,9 +1398,7 @@ stmt : keyword_alias fitem {SET_LEX_STATE(EXPR_FNAME|EXPR_FITEM);} fitem
{
/*%%%*/
NODE *resq;
- YYLTYPE location;
- location.first_loc = @2.first_loc;
- location.last_loc = @3.last_loc;
+ YYLTYPE location = code_range_gen(&@2, &@3);
resq = NEW_RESBODY(0, remove_begin($3), 0, &location);
$$ = NEW_RESCUE(remove_begin($1), resq, 0, &@$);
/*%
@@ -1492,9 +1490,7 @@ command_asgn : lhs '=' command_rhs
| primary_value tCOLON2 tCONSTANT tOP_ASGN command_rhs
{
/*%%%*/
- YYLTYPE location;
- location.first_loc = @1.first_loc;
- location.last_loc = @3.last_loc;
+ YYLTYPE location = code_range_gen(&@1, &@3);
/*%
%*/
$$ = const_path_field($1, $3, &location);
@@ -1523,9 +1519,7 @@ command_rhs : command_call %prec tOP_ASGN
| command_call modifier_rescue stmt
{
/*%%%*/
- YYLTYPE location;
- location.first_loc = @2.first_loc;
- location.last_loc = @3.last_loc;
+ YYLTYPE location = code_range_gen(&@2, &@3);
value_expr($1);
$$ = NEW_RESCUE($1, NEW_RESBODY(0, remove_begin($3), 0, &location), 0, &@$);
/*%
@@ -1582,8 +1576,7 @@ cmd_brace_block : tLBRACE_ARG brace_body '}'
{
$$ = $2;
/*%%%*/
- $$->nd_body->nd_loc.first_loc = @1.first_loc;
- $$->nd_body->nd_loc.last_loc = @3.last_loc;
+ $$->nd_body->nd_loc = code_range_gen(&@1, &@3);
nd_set_line($$, @1.last_loc.lineno);
/*% %*/
}
@@ -2132,9 +2125,7 @@ arg : lhs '=' arg_rhs
| primary_value tCOLON2 tCONSTANT tOP_ASGN arg_rhs
{
/*%%%*/
- YYLTYPE location;
- location.first_loc = @1.first_loc;
- location.last_loc = @3.last_loc;
+ YYLTYPE location = code_range_gen(&@1, &@3);
/*%
%*/
$$ = const_path_field($1, $3, &location);
@@ -2351,9 +2342,7 @@ arg_rhs : arg %prec tOP_ASGN
| arg modifier_rescue arg
{
/*%%%*/
- YYLTYPE location;
- location.first_loc = @2.first_loc;
- location.last_loc = @3.last_loc;
+ YYLTYPE location = code_range_gen(&@2, &@3);
value_expr($1);
$$ = NEW_RESCUE($1, NEW_RESBODY(0, remove_begin($3), 0, &location), 0, &@$);
/*%
@@ -2858,9 +2847,7 @@ primary : literal
| k_class cpath superclass
{
if (in_def) {
- YYLTYPE location;
- location.first_loc = @1.first_loc;
- location.last_loc = @2.last_loc;
+ YYLTYPE location = code_range_gen(&@1, &@2);
yyerror1(&location, "class definition in method body");
}
$<num>1 = in_class;
@@ -2907,9 +2894,7 @@ primary : literal
| k_module cpath
{
if (in_def) {
- YYLTYPE location;
- location.first_loc = @1.first_loc;
- location.last_loc = @2.last_loc;
+ YYLTYPE location = code_range_gen(&@1, &@2);
yyerror1(&location, "module definition in method body");
}
$<num>1 = in_class;
@@ -3505,8 +3490,7 @@ do_block : keyword_do_block do_body keyword_end
{
$$ = $2;
/*%%%*/
- $$->nd_body->nd_loc.first_loc = @1.first_loc;
- $$->nd_body->nd_loc.last_loc = @3.last_loc;
+ $$->nd_body->nd_loc = code_range_gen(&@1, &@3);
nd_set_line($$, @1.last_loc.lineno);
/*% %*/
}
@@ -3625,8 +3609,7 @@ brace_block : '{' brace_body '}'
{
$$ = $2;
/*%%%*/
- $$->nd_body->nd_loc.first_loc = @1.first_loc;
- $$->nd_body->nd_loc.last_loc = @3.last_loc;
+ $$->nd_body->nd_loc = code_range_gen(&@1, &@3);
nd_set_line($$, @1.last_loc.lineno);
/*% %*/
}
@@ -3634,8 +3617,7 @@ brace_block : '{' brace_body '}'
{
$$ = $2;
/*%%%*/
- $$->nd_body->nd_loc.first_loc = @1.first_loc;
- $$->nd_body->nd_loc.last_loc = @3.last_loc;
+ $$->nd_body->nd_loc = code_range_gen(&@1, &@3);
nd_set_line($$, @1.last_loc.lineno);
/*% %*/
}
@@ -4851,9 +4833,7 @@ assoc : arg_value tASSOC arg_value
| tSTRING_BEG string_contents tLABEL_END arg_value
{
/*%%%*/
- YYLTYPE location;
- location.first_loc = @1.first_loc;
- location.last_loc = @3.last_loc;
+ YYLTYPE location = code_range_gen(&@1, &@3);
$$ = list_append(NEW_LIST(dsym_node($2, &location), &location), $4);
/*%
$$ = dispatch2(assoc_new, dispatch1(dyna_symbol, $2), $4);