@@ -796,6 +796,27 @@ typedef struct {
796
796
pm_node_t *block;
797
797
} pm_arguments_t;
798
798
799
+ /**
800
+ * Retrieve the end location of a `pm_arguments_t` object.
801
+ */
802
+ static inline const uint8_t *
803
+ pm_arguments_end(pm_arguments_t *arguments) {
804
+ if (arguments->block != NULL) {
805
+ const uint8_t *end = arguments->block->location.end;
806
+ if (arguments->closing_loc.start != NULL && arguments->closing_loc.end > end) {
807
+ end = arguments->closing_loc.end;
808
+ }
809
+ return end;
810
+ }
811
+ if (arguments->closing_loc.start != NULL) {
812
+ return arguments->closing_loc.end;
813
+ }
814
+ if (arguments->arguments != NULL) {
815
+ return arguments->arguments->base.location.end;
816
+ }
817
+ return arguments->closing_loc.end;
818
+ }
819
+
799
820
/**
800
821
* Check that we're not about to attempt to attach a brace block to a call that
801
822
* has arguments without parentheses.
@@ -1611,11 +1632,7 @@ pm_call_node_aref_create(pm_parser_t *parser, pm_node_t *receiver, pm_arguments_
1611
1632
pm_call_node_t *node = pm_call_node_create(parser);
1612
1633
1613
1634
node->base.location.start = receiver->location.start;
1614
- if (arguments->block != NULL) {
1615
- node->base.location.end = arguments->block->location.end;
1616
- } else {
1617
- node->base.location.end = arguments->closing_loc.end;
1618
- }
1635
+ node->base.location.end = pm_arguments_end(arguments);
1619
1636
1620
1637
node->receiver = receiver;
1621
1638
node->message_loc.start = arguments->opening_loc.start;
@@ -1664,15 +1681,11 @@ pm_call_node_call_create(pm_parser_t *parser, pm_node_t *receiver, pm_token_t *o
1664
1681
pm_call_node_t *node = pm_call_node_create(parser);
1665
1682
1666
1683
node->base.location.start = receiver->location.start;
1667
- if (arguments->block != NULL) {
1668
- node->base.location.end = arguments->block->location.end;
1669
- } else if (arguments->closing_loc.start != NULL) {
1670
- node->base.location.end = arguments->closing_loc.end;
1671
- } else if (arguments->arguments != NULL) {
1672
- node->base.location.end = arguments->arguments->base.location.end;
1673
- } else {
1674
- node->base.location.end = message->end;
1684
+ const uint8_t *end = pm_arguments_end(arguments);
1685
+ if (end == NULL) {
1686
+ end = message->end;
1675
1687
}
1688
+ node->base.location.end = end;
1676
1689
1677
1690
node->receiver = receiver;
1678
1691
node->call_operator_loc = PM_OPTIONAL_LOCATION_TOKEN_VALUE(operator);
@@ -1699,15 +1712,7 @@ pm_call_node_fcall_create(pm_parser_t *parser, pm_token_t *message, pm_arguments
1699
1712
pm_call_node_t *node = pm_call_node_create(parser);
1700
1713
1701
1714
node->base.location.start = message->start;
1702
- if (arguments->block != NULL) {
1703
- node->base.location.end = arguments->block->location.end;
1704
- } else if (arguments->closing_loc.start != NULL) {
1705
- node->base.location.end = arguments->closing_loc.end;
1706
- } else if (arguments->arguments != NULL) {
1707
- node->base.location.end = arguments->arguments->base.location.end;
1708
- } else {
1709
- node->base.location.end = arguments->closing_loc.end;
1710
- }
1715
+ node->base.location.end = pm_arguments_end(arguments);
1711
1716
1712
1717
node->message_loc = PM_OPTIONAL_LOCATION_TOKEN_VALUE(message);
1713
1718
node->opening_loc = arguments->opening_loc;
@@ -1755,11 +1760,7 @@ pm_call_node_shorthand_create(pm_parser_t *parser, pm_node_t *receiver, pm_token
1755
1760
pm_call_node_t *node = pm_call_node_create(parser);
1756
1761
1757
1762
node->base.location.start = receiver->location.start;
1758
- if (arguments->block != NULL) {
1759
- node->base.location.end = arguments->block->location.end;
1760
- } else {
1761
- node->base.location.end = arguments->closing_loc.end;
1762
- }
1763
+ node->base.location.end = pm_arguments_end(arguments);
1763
1764
1764
1765
node->receiver = receiver;
1765
1766
node->call_operator_loc = PM_OPTIONAL_LOCATION_TOKEN_VALUE(operator);
@@ -5136,16 +5137,9 @@ pm_super_node_create(pm_parser_t *parser, const pm_token_t *keyword, pm_argument
5136
5137
assert(keyword->type == PM_TOKEN_KEYWORD_SUPER);
5137
5138
pm_super_node_t *node = PM_ALLOC_NODE(parser, pm_super_node_t);
5138
5139
5139
- const uint8_t *end;
5140
- if (arguments->block != NULL) {
5141
- end = arguments->block->location.end;
5142
- } else if (arguments->closing_loc.start != NULL) {
5143
- end = arguments->closing_loc.end;
5144
- } else if (arguments->arguments != NULL) {
5145
- end = arguments->arguments->base.location.end;
5146
- } else {
5140
+ const uint8_t *end = pm_arguments_end(arguments);
5141
+ if (end == NULL) {
5147
5142
assert(false && "unreachable");
5148
- end = NULL;
5149
5143
}
5150
5144
5151
5145
*node = (pm_super_node_t) {
0 commit comments