Skip to content

Commit 857f72e

Browse files
committed
Remove unnecessary PM_EMPTY_NODE_LIST
1 parent e2e29be commit 857f72e

File tree

3 files changed

+46
-50
lines changed

3 files changed

+46
-50
lines changed

include/prism/node.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
// Append a new node onto the end of the node list.
88
void pm_node_list_append(pm_node_list_t *list, pm_node_t *node);
99

10-
// Clear the node but preserves the location.
11-
void pm_node_clear(pm_node_t *node);
12-
1310
// Deallocate a node and all of its children.
1411
PRISM_EXPORTED_FUNCTION void pm_node_destroy(pm_parser_t *parser, struct pm_node *node);
1512

@@ -27,6 +24,4 @@ PRISM_EXPORTED_FUNCTION void pm_node_memsize(pm_node_t *node, pm_memsize_t *mems
2724
// Returns a string representation of the given node type.
2825
PRISM_EXPORTED_FUNCTION const char * pm_node_type_to_str(pm_node_type_t node_type);
2926

30-
#define PM_EMPTY_NODE_LIST ((pm_node_list_t) { .nodes = NULL, .size = 0, .capacity = 0 })
31-
3227
#endif // PRISM_NODE_H

src/prism.c

Lines changed: 46 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ pm_arguments_node_create(pm_parser_t *parser) {
945945
.type = PM_ARGUMENTS_NODE,
946946
.location = PM_LOCATION_NULL_VALUE(parser)
947947
},
948-
.arguments = PM_EMPTY_NODE_LIST
948+
.arguments = { 0 }
949949
};
950950

951951
return node;
@@ -981,7 +981,7 @@ pm_array_node_create(pm_parser_t *parser, const pm_token_t *opening) {
981981
},
982982
.opening_loc = PM_OPTIONAL_LOCATION_TOKEN_VALUE(opening),
983983
.closing_loc = PM_OPTIONAL_LOCATION_TOKEN_VALUE(opening),
984-
.elements = PM_EMPTY_NODE_LIST
984+
.elements = { 0 }
985985
};
986986

987987
return node;
@@ -1034,8 +1034,8 @@ pm_array_pattern_node_node_list_create(pm_parser_t *parser, pm_node_list_t *node
10341034
},
10351035
.constant = NULL,
10361036
.rest = NULL,
1037-
.requireds = PM_EMPTY_NODE_LIST,
1038-
.posts = PM_EMPTY_NODE_LIST,
1037+
.requireds = { 0 },
1038+
.posts = { 0 },
10391039
.opening_loc = PM_OPTIONAL_LOCATION_NOT_PROVIDED_VALUE,
10401040
.closing_loc = PM_OPTIONAL_LOCATION_NOT_PROVIDED_VALUE
10411041
};
@@ -1071,8 +1071,8 @@ pm_array_pattern_node_rest_create(pm_parser_t *parser, pm_node_t *rest) {
10711071
},
10721072
.constant = NULL,
10731073
.rest = rest,
1074-
.requireds = PM_EMPTY_NODE_LIST,
1075-
.posts = PM_EMPTY_NODE_LIST,
1074+
.requireds = { 0 },
1075+
.posts = { 0 },
10761076
.opening_loc = PM_OPTIONAL_LOCATION_NOT_PROVIDED_VALUE,
10771077
.closing_loc = PM_OPTIONAL_LOCATION_NOT_PROVIDED_VALUE
10781078
};
@@ -1098,8 +1098,8 @@ pm_array_pattern_node_constant_create(pm_parser_t *parser, pm_node_t *constant,
10981098
.rest = NULL,
10991099
.opening_loc = PM_LOCATION_TOKEN_VALUE(opening),
11001100
.closing_loc = PM_LOCATION_TOKEN_VALUE(closing),
1101-
.requireds = PM_EMPTY_NODE_LIST,
1102-
.posts = PM_EMPTY_NODE_LIST
1101+
.requireds = { 0 },
1102+
.posts = { 0 }
11031103
};
11041104

11051105
return node;
@@ -1123,8 +1123,8 @@ pm_array_pattern_node_empty_create(pm_parser_t *parser, const pm_token_t *openin
11231123
.rest = NULL,
11241124
.opening_loc = PM_LOCATION_TOKEN_VALUE(opening),
11251125
.closing_loc = PM_LOCATION_TOKEN_VALUE(closing),
1126-
.requireds = PM_EMPTY_NODE_LIST,
1127-
.posts = PM_EMPTY_NODE_LIST
1126+
.requireds = { 0 },
1127+
.posts = { 0 }
11281128
};
11291129

11301130
return node;
@@ -1362,7 +1362,7 @@ pm_block_parameters_node_create(pm_parser_t *parser, pm_parameters_node_t *param
13621362
.parameters = parameters,
13631363
.opening_loc = PM_OPTIONAL_LOCATION_TOKEN_VALUE(opening),
13641364
.closing_loc = PM_OPTIONAL_LOCATION_NOT_PROVIDED_VALUE,
1365-
.locals = PM_EMPTY_NODE_LIST
1365+
.locals = { 0 }
13661366
};
13671367

13681368
return node;
@@ -1923,7 +1923,7 @@ pm_case_node_create(pm_parser_t *parser, const pm_token_t *case_keyword, pm_node
19231923
.consequent = consequent,
19241924
.case_keyword_loc = PM_LOCATION_TOKEN_VALUE(case_keyword),
19251925
.end_keyword_loc = PM_LOCATION_TOKEN_VALUE(end_keyword),
1926-
.conditions = PM_EMPTY_NODE_LIST
1926+
.conditions = { 0 }
19271927
};
19281928

19291929
return node;
@@ -2498,7 +2498,7 @@ pm_find_pattern_node_create(pm_parser_t *parser, pm_node_list_t *nodes) {
24982498
.constant = NULL,
24992499
.left = left,
25002500
.right = right,
2501-
.requireds = PM_EMPTY_NODE_LIST,
2501+
.requireds = { 0 },
25022502
.opening_loc = PM_OPTIONAL_LOCATION_NOT_PROVIDED_VALUE,
25032503
.closing_loc = PM_OPTIONAL_LOCATION_NOT_PROVIDED_VALUE
25042504
};
@@ -2689,7 +2689,7 @@ pm_hash_pattern_node_empty_create(pm_parser_t *parser, const pm_token_t *opening
26892689
.constant = NULL,
26902690
.opening_loc = PM_LOCATION_TOKEN_VALUE(opening),
26912691
.closing_loc = PM_LOCATION_TOKEN_VALUE(closing),
2692-
.elements = PM_EMPTY_NODE_LIST,
2692+
.elements = { 0 },
26932693
.rest = NULL
26942694
};
26952695

@@ -2727,7 +2727,7 @@ pm_hash_pattern_node_node_list_create(pm_parser_t *parser, pm_node_list_t *eleme
27272727
},
27282728
},
27292729
.constant = NULL,
2730-
.elements = PM_EMPTY_NODE_LIST,
2730+
.elements = { 0 },
27312731
.rest = rest,
27322732
.opening_loc = PM_OPTIONAL_LOCATION_NOT_PROVIDED_VALUE,
27332733
.closing_loc = PM_OPTIONAL_LOCATION_NOT_PROVIDED_VALUE
@@ -2880,7 +2880,7 @@ pm_hash_node_create(pm_parser_t *parser, const pm_token_t *opening) {
28802880
},
28812881
.opening_loc = PM_LOCATION_TOKEN_VALUE(opening),
28822882
.closing_loc = PM_LOCATION_NULL_VALUE(parser),
2883-
.elements = PM_EMPTY_NODE_LIST
2883+
.elements = { 0 }
28842884
};
28852885

28862886
return node;
@@ -3272,7 +3272,7 @@ pm_interpolated_regular_expression_node_create(pm_parser_t *parser, const pm_tok
32723272
},
32733273
.opening_loc = PM_LOCATION_TOKEN_VALUE(opening),
32743274
.closing_loc = PM_LOCATION_TOKEN_VALUE(opening),
3275-
.parts = PM_EMPTY_NODE_LIST
3275+
.parts = { 0 }
32763276
};
32773277

32783278
return node;
@@ -3311,9 +3311,13 @@ pm_interpolated_string_node_create(pm_parser_t *parser, const pm_token_t *openin
33113311
},
33123312
.opening_loc = PM_OPTIONAL_LOCATION_TOKEN_VALUE(opening),
33133313
.closing_loc = PM_OPTIONAL_LOCATION_TOKEN_VALUE(closing),
3314-
.parts = parts == NULL ? PM_EMPTY_NODE_LIST : *parts
3314+
.parts = { 0 }
33153315
};
33163316

3317+
if (parts != NULL) {
3318+
node->parts = *parts;
3319+
}
3320+
33173321
return node;
33183322
}
33193323

@@ -3350,9 +3354,13 @@ pm_interpolated_symbol_node_create(pm_parser_t *parser, const pm_token_t *openin
33503354
},
33513355
.opening_loc = PM_OPTIONAL_LOCATION_TOKEN_VALUE(opening),
33523356
.closing_loc = PM_OPTIONAL_LOCATION_TOKEN_VALUE(closing),
3353-
.parts = parts == NULL ? PM_EMPTY_NODE_LIST : *parts
3357+
.parts = { 0 }
33543358
};
33553359

3360+
if (parts != NULL) {
3361+
node->parts = *parts;
3362+
}
3363+
33563364
return node;
33573365
}
33583366

@@ -3381,7 +3389,7 @@ pm_interpolated_xstring_node_create(pm_parser_t *parser, const pm_token_t *openi
33813389
},
33823390
.opening_loc = PM_OPTIONAL_LOCATION_TOKEN_VALUE(opening),
33833391
.closing_loc = PM_OPTIONAL_LOCATION_TOKEN_VALUE(closing),
3384-
.parts = PM_EMPTY_NODE_LIST
3392+
.parts = { 0 }
33853393
};
33863394

33873395
return node;
@@ -3409,7 +3417,7 @@ pm_keyword_hash_node_create(pm_parser_t *parser) {
34093417
.type = PM_KEYWORD_HASH_NODE,
34103418
.location = PM_OPTIONAL_LOCATION_NOT_PROVIDED_VALUE
34113419
},
3412-
.elements = PM_EMPTY_NODE_LIST
3420+
.elements = { 0 }
34133421
};
34143422

34153423
return node;
@@ -3752,9 +3760,9 @@ pm_multi_target_node_create(pm_parser_t *parser) {
37523760
.type = PM_MULTI_TARGET_NODE,
37533761
.location = { .start = NULL, .end = NULL }
37543762
},
3755-
.lefts = PM_EMPTY_NODE_LIST,
3763+
.lefts = { 0 },
37563764
.rest = NULL,
3757-
.rights = PM_EMPTY_NODE_LIST,
3765+
.rights = { 0 },
37583766
.lparen_loc = PM_OPTIONAL_LOCATION_NOT_PROVIDED_VALUE,
37593767
.rparen_loc = PM_OPTIONAL_LOCATION_NOT_PROVIDED_VALUE
37603768
};
@@ -3961,10 +3969,10 @@ pm_parameters_node_create(pm_parser_t *parser) {
39613969
.rest = NULL,
39623970
.keyword_rest = NULL,
39633971
.block = NULL,
3964-
.requireds = PM_EMPTY_NODE_LIST,
3965-
.optionals = PM_EMPTY_NODE_LIST,
3966-
.posts = PM_EMPTY_NODE_LIST,
3967-
.keywords = PM_EMPTY_NODE_LIST
3972+
.requireds = { 0 },
3973+
.optionals = { 0 },
3974+
.posts = { 0 },
3975+
.keywords = { 0 }
39683976
};
39693977

39703978
return node;
@@ -4295,7 +4303,7 @@ pm_rescue_node_create(pm_parser_t *parser, const pm_token_t *keyword) {
42954303
.reference = NULL,
42964304
.statements = NULL,
42974305
.consequent = NULL,
4298-
.exceptions = PM_EMPTY_NODE_LIST
4306+
.exceptions = { 0 }
42994307
};
43004308

43014309
return node;
@@ -4503,7 +4511,7 @@ pm_statements_node_create(pm_parser_t *parser) {
45034511
.type = PM_STATEMENTS_NODE,
45044512
.location = PM_LOCATION_NULL_VALUE(parser)
45054513
},
4506-
.body = PM_EMPTY_NODE_LIST
4514+
.body = { 0 }
45074515
};
45084516

45094517
return node;
@@ -4812,7 +4820,7 @@ pm_undef_node_create(pm_parser_t *parser, const pm_token_t *token) {
48124820
.location = PM_LOCATION_TOKEN_VALUE(token),
48134821
},
48144822
.keyword_loc = PM_LOCATION_TOKEN_VALUE(token),
4815-
.names = PM_EMPTY_NODE_LIST
4823+
.names = { 0 }
48164824
};
48174825

48184826
return node;
@@ -4952,7 +4960,7 @@ pm_when_node_create(pm_parser_t *parser, const pm_token_t *keyword) {
49524960
},
49534961
.keyword_loc = PM_LOCATION_TOKEN_VALUE(keyword),
49544962
.statements = NULL,
4955-
.conditions = PM_EMPTY_NODE_LIST
4963+
.conditions = { 0 }
49564964
};
49574965

49584966
return node;
@@ -11418,7 +11426,7 @@ parse_symbol(pm_parser_t *parser, pm_lex_mode_t *lex_mode, pm_lex_state_t next_s
1141811426

1141911427
// Create a node_list first. We'll use this to check if it should be an
1142011428
// InterpolatedSymbolNode or a SymbolNode.
11421-
pm_node_list_t node_list = PM_EMPTY_NODE_LIST;
11429+
pm_node_list_t node_list = { 0 };
1142211430
if (part) pm_node_list_append(&node_list, part);
1142311431

1142411432
while (!match2(parser, PM_TOKEN_STRING_END, PM_TOKEN_EOF)) {
@@ -11861,7 +11869,7 @@ parse_pattern_keyword_rest(pm_parser_t *parser) {
1186111869
// Parse a hash pattern.
1186211870
static pm_hash_pattern_node_t *
1186311871
parse_pattern_hash(pm_parser_t *parser, pm_node_t *first_assoc) {
11864-
pm_node_list_t assocs = PM_EMPTY_NODE_LIST;
11872+
pm_node_list_t assocs = { 0 };
1186511873
pm_node_t *rest = NULL;
1186611874

1186711875
switch (PM_NODE_TYPE(first_assoc)) {
@@ -12308,7 +12316,7 @@ parse_pattern(pm_parser_t *parser, bool top_pattern, pm_diagnostic_id_t diag_id)
1230812316
// If we have a comma, then we are now parsing either an array pattern or a
1230912317
// find pattern. We need to parse all of the patterns, put them into a big
1231012318
// list, and then determine which type of node we have.
12311-
pm_node_list_t nodes = PM_EMPTY_NODE_LIST;
12319+
pm_node_list_t nodes = { 0 };
1231212320
pm_node_list_append(&nodes, node);
1231312321

1231412322
// Gather up all of the patterns into the list.
@@ -12448,7 +12456,7 @@ parse_strings(pm_parser_t *parser) {
1244812456
// In that case we need to switch to an interpolated string to
1244912457
// be able to contain all of the parts.
1245012458
if (match1(parser, PM_TOKEN_STRING_CONTENT)) {
12451-
pm_node_list_t parts = PM_EMPTY_NODE_LIST;
12459+
pm_node_list_t parts = { 0 };
1245212460

1245312461
pm_token_t delimiters = not_provided(parser);
1245412462
pm_node_t *part = (pm_node_t *) pm_string_node_create_unescaped(parser, &delimiters, &content, &delimiters, &unescaped);
@@ -12485,7 +12493,7 @@ parse_strings(pm_parser_t *parser) {
1248512493
} else {
1248612494
// If we get here, then we have interpolation so we'll need
1248712495
// to create a string or symbol node with interpolation.
12488-
pm_node_list_t parts = PM_EMPTY_NODE_LIST;
12496+
pm_node_list_t parts = { 0 };
1248912497
pm_token_t string_opening = not_provided(parser);
1249012498
pm_token_t string_closing = not_provided(parser);
1249112499

@@ -12509,7 +12517,7 @@ parse_strings(pm_parser_t *parser) {
1250912517
// If we get here, then the first part of the string is not plain
1251012518
// string content, in which case we need to parse the string as an
1251112519
// interpolated string.
12512-
pm_node_list_t parts = PM_EMPTY_NODE_LIST;
12520+
pm_node_list_t parts = { 0 };
1251312521
pm_node_t *part;
1251412522

1251512523
while (!match3(parser, PM_TOKEN_STRING_END, PM_TOKEN_LABEL_END, PM_TOKEN_EOF)) {
@@ -13025,7 +13033,7 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power) {
1302513033
// If we get here, then we have multiple parts in the heredoc,
1302613034
// so we'll need to create an interpolated string node to hold
1302713035
// them all.
13028-
pm_node_list_t parts = PM_EMPTY_NODE_LIST;
13036+
pm_node_list_t parts = { 0 };
1302913037
pm_node_list_append(&parts, part);
1303013038

1303113039
while (!match2(parser, PM_TOKEN_HEREDOC_END, PM_TOKEN_EOF)) {

templates/src/node.c.erb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
#line <%= __LINE__ + 1 %> "<%= File.basename(__FILE__) %>"
22
#include "prism/node.h"
33

4-
// Clear the node but preserves the location.
5-
void pm_node_clear(pm_node_t *node) {
6-
pm_location_t location = node->location;
7-
memset(node, 0, sizeof(pm_node_t));
8-
node->location = location;
9-
}
10-
114
static void
125
pm_node_memsize_node(pm_node_t *node, pm_memsize_t *memsize);
136

0 commit comments

Comments
 (0)