Skip to content

Commit cc0ca08

Browse files
committed
Consolidate macro definitions
1 parent 1988615 commit cc0ca08

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

src/prism.c

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,22 @@ pm_version(void) {
1919
#define MAX(a,b) (((a)>(b))?(a):(b))
2020

2121
/******************************************************************************/
22-
/* Helpful node-related macros */
22+
/* Helpful AST-related macros */
2323
/******************************************************************************/
2424

2525
#define FL PM_NODE_FLAGS
2626
#define UP PM_NODE_UPCAST
2727

2828
#define PM_TOKEN_START(token_) ((token_)->start)
29-
#define PM_TOKEN_END(token_) ((token_)->end)
29+
#define PM_TOKEN_END(token_) ((token_)->end)
3030

3131
#define PM_NODE_START(node_) (UP(node_)->location.start)
32-
#define PM_NODE_END(node_) (UP(node_)->location.end)
32+
#define PM_NODE_END(node_) (UP(node_)->location.end)
33+
34+
#define PM_LOCATION_NULL_VALUE(parser_) ((pm_location_t) { .start = (parser_)->start, .end = (parser_)->start })
35+
#define PM_LOCATION_TOKEN_VALUE(token_) ((pm_location_t) { .start = PM_TOKEN_START(token_), .end = PM_TOKEN_END(token_) })
36+
#define PM_LOCATION_NODE_VALUE(node_) ((pm_location_t) { .start = PM_NODE_START(node_), .end = PM_NODE_END(node_) })
37+
#define PM_OPTIONAL_LOCATION_TOKEN_VALUE(token) ((token)->type == PM_TOKEN_NOT_PROVIDED ? ((pm_location_t) { 0 }) : PM_LOCATION_TOKEN_VALUE(token))
3338

3439
/******************************************************************************/
3540
/* Lex mode manipulations */
@@ -1572,12 +1577,6 @@ not_provided(pm_parser_t *parser) {
15721577
return (pm_token_t) { .type = PM_TOKEN_NOT_PROVIDED, .start = parser->start, .end = parser->start };
15731578
}
15741579

1575-
#define PM_LOCATION_NULL_VALUE(parser) ((pm_location_t) { .start = (parser)->start, .end = (parser)->start })
1576-
#define PM_LOCATION_TOKEN_VALUE(token) ((pm_location_t) { .start = (token)->start, .end = (token)->end })
1577-
#define PM_LOCATION_NODE_VALUE(node) ((pm_location_t) { .start = (node)->location.start, .end = (node)->location.end })
1578-
#define PM_LOCATION_NODE_BASE_VALUE(node) ((pm_location_t) { .start = (node)->base.location.start, .end = (node)->base.location.end })
1579-
#define PM_OPTIONAL_LOCATION_TOKEN_VALUE(token) ((token)->type == PM_TOKEN_NOT_PROVIDED ? ((pm_location_t) { 0 }) : PM_LOCATION_TOKEN_VALUE(token))
1580-
15811580
/**
15821581
* This is a special out parameter to the parse_arguments_list function that
15831582
* includes opening and closing parentheses in addition to the arguments since
@@ -4662,7 +4661,7 @@ pm_instance_variable_write_node_create(pm_parser_t *parser, pm_instance_variable
46624661
*node = (pm_instance_variable_write_node_t) {
46634662
.base = PM_NODE_INIT_NODES(parser, PM_INSTANCE_VARIABLE_WRITE_NODE, flags, read_node, value),
46644663
.name = read_node->name,
4665-
.name_loc = PM_LOCATION_NODE_BASE_VALUE(read_node),
4664+
.name_loc = PM_LOCATION_NODE_VALUE(read_node),
46664665
.operator_loc = PM_OPTIONAL_LOCATION_TOKEN_VALUE(operator),
46674666
.value = value
46684667
};
@@ -7069,8 +7068,6 @@ pm_yield_node_create(pm_parser_t *parser, const pm_token_t *keyword, const pm_lo
70697068
return node;
70707069
}
70717070

7072-
#undef PM_NODE_ALLOC
7073-
70747071
/**
70757072
* Check if any of the currently visible scopes contain a local variable
70767073
* described by the given constant id.
@@ -22293,10 +22290,6 @@ pm_parse_success_p(const uint8_t *source, size_t size, const char *data) {
2229322290
#undef PM_CASE_OPERATOR
2229422291
#undef PM_CASE_WRITABLE
2229522292
#undef PM_STRING_EMPTY
22296-
#undef PM_LOCATION_NODE_BASE_VALUE
22297-
#undef PM_LOCATION_NODE_VALUE
22298-
#undef PM_LOCATION_NULL_VALUE
22299-
#undef PM_LOCATION_TOKEN_VALUE
2230022293

2230122294
// We optionally support serializing to a binary string. For systems that don't
2230222295
// want or need this functionality, it can be turned off with the

0 commit comments

Comments
 (0)