Skip to content

Commit cec815b

Browse files
committed
Use #ifndef for semantic fields only check
1 parent 5dc9658 commit cec815b

3 files changed

Lines changed: 13 additions & 19 deletions

File tree

src/prism.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22843,7 +22843,11 @@ pm_serialize_header(pm_buffer_t *buffer) {
2284322843
pm_buffer_append_byte(buffer, PRISM_VERSION_MAJOR);
2284422844
pm_buffer_append_byte(buffer, PRISM_VERSION_MINOR);
2284522845
pm_buffer_append_byte(buffer, PRISM_VERSION_PATCH);
22846-
pm_buffer_append_byte(buffer, PRISM_SERIALIZE_ONLY_SEMANTICS_FIELDS);
22846+
#ifdef PRISM_SERIALIZE_ONLY_SEMANTICS_FIELDS
22847+
pm_buffer_append_byte(buffer, 1);
22848+
#else
22849+
pm_buffer_append_byte(buffer, 0);
22850+
#endif
2284722851
}
2284822852

2284922853
/**

templates/include/prism/ast.h.erb

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -267,14 +267,4 @@ typedef enum pm_<%= flag.human %> {
267267
PRISM_EXPORTED_FUNCTION pm_<%= node.human %>_t * pm_<%= node.human %>_new(pm_arena_t *arena, uint32_t node_id, pm_node_flags_t flags, pm_location_t location<%= params.empty? ? "" : ", #{params.join(", ")}" %>);
268268
<%- end -%>
269269

270-
/**
271-
* When we're serializing to Java, we want to skip serializing the location
272-
* fields as they won't be used by JRuby or TruffleRuby. This boolean allows us
273-
* to specify that through the environment. It will never be true except for in
274-
* those build systems.
275-
*/
276-
#ifndef PRISM_SERIALIZE_ONLY_SEMANTICS_FIELDS
277-
#define PRISM_SERIALIZE_ONLY_SEMANTICS_FIELDS 0
278-
#endif
279-
280270
#endif

templates/src/serialize.c.erb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
9494
<%- if node.flags -%>
9595
pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
9696
<%- else -%>
97-
if (!PRISM_SERIALIZE_ONLY_SEMANTICS_FIELDS) {
97+
#ifndef PRISM_SERIALIZE_ONLY_SEMANTICS_FIELDS
9898
pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
99-
}
99+
#endif
100100
<%- end -%>
101101
<%- node.fields.each do |field| -%>
102102
<%- case field -%>
@@ -126,15 +126,15 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
126126
}
127127
<%- when Prism::Template::LocationField -%>
128128
<%- unless field.semantic_field? -%>
129-
if (!PRISM_SERIALIZE_ONLY_SEMANTICS_FIELDS) {
129+
#ifndef PRISM_SERIALIZE_ONLY_SEMANTICS_FIELDS
130130
<%- end -%>
131131
pm_serialize_location(&((pm_<%= node.human %>_t *)node)-><%= field.name %>, buffer);
132132
<%- unless field.semantic_field? -%>
133-
}
133+
#endif
134134
<%- end -%>
135135
<%- when Prism::Template::OptionalLocationField -%>
136136
<%- unless field.semantic_field? -%>
137-
if (!PRISM_SERIALIZE_ONLY_SEMANTICS_FIELDS) {
137+
#ifndef PRISM_SERIALIZE_ONLY_SEMANTICS_FIELDS
138138
<%- end -%>
139139
if (((pm_<%= node.human %>_t *)node)-><%= field.name %>.length == 0) {
140140
pm_buffer_append_byte(buffer, 0);
@@ -143,7 +143,7 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
143143
pm_serialize_location(&((pm_<%= node.human %>_t *)node)-><%= field.name %>, buffer);
144144
}
145145
<%- unless field.semantic_field? -%>
146-
}
146+
#endif
147147
<%- end -%>
148148
<%- when Prism::Template::UInt8Field -%>
149149
pm_buffer_append_byte(buffer, ((pm_<%= node.human %>_t *)node)-><%= field.name %>);
@@ -273,9 +273,9 @@ pm_serialize_metadata(pm_parser_t *parser, pm_buffer_t *buffer) {
273273
pm_serialize_encoding(parser->encoding, buffer);
274274
pm_buffer_append_varsint(buffer, parser->start_line);
275275
pm_serialize_line_offset_list(&parser->line_offsets, buffer);
276-
if (!PRISM_SERIALIZE_ONLY_SEMANTICS_FIELDS) {
276+
#ifndef PRISM_SERIALIZE_ONLY_SEMANTICS_FIELDS
277277
pm_serialize_comment_list(&parser->comment_list, buffer);
278-
}
278+
#endif
279279
pm_serialize_magic_comment_list(&parser->magic_comment_list, buffer);
280280
pm_serialize_data_loc(parser, buffer);
281281
pm_serialize_diagnostic_list(&parser->error_list, buffer);

0 commit comments

Comments
 (0)