From 82e1434ef65cf1eead1e9828d12e2ed1a29de0fa Mon Sep 17 00:00:00 2001 From: Jemma Issroff Date: Wed, 23 Aug 2023 10:30:05 -0700 Subject: [PATCH] [ruby/yarp] Pulled scope node out of config.yml, added necessary void returns https://github.com/ruby/yarp/commit/926e6bdd88 --- yarp/config.yml | 14 -------------- yarp/node.h | 10 ++++++++++ yarp/templates/include/yarp/ast.h.erb | 1 + yarp/templates/src/node.c.erb | 4 ++++ yarp/templates/src/prettyprint.c.erb | 4 ++++ yarp/templates/src/serialize.c.erb | 4 ++++ yarp/yarp.c | 2 +- yarp/yarp.h | 2 +- 8 files changed, 25 insertions(+), 16 deletions(-) diff --git a/yarp/config.yml b/yarp/config.yml index bf41d486d4fdd5..e4987013bb6afc 100644 --- a/yarp/config.yml +++ b/yarp/config.yml @@ -1686,20 +1686,6 @@ nodes: return 1 ^^^^^^^^ - - name: ScopeNode - child_nodes: - - name: parameters - type: node? - kind: ParametersNode - - name: statements - type: node? - kind: StatementsNode - - name: locals - type: constant[] - comment: | - Used only to retrieve the scope, not an - actual semantically meaningful node - - name: SelfNode comment: | Represents the `self` keyword. diff --git a/yarp/node.h b/yarp/node.h index a107baddb8d48e..8e059f957ab4db 100644 --- a/yarp/node.h +++ b/yarp/node.h @@ -34,3 +34,13 @@ YP_EXPORTED_FUNCTION const char * yp_node_type_to_str(yp_node_type_t node_type); #define YP_EMPTY_LOCATION_LIST ((yp_location_list_t) { .locations = NULL, .size = 0, .capacity = 0 }) #endif // YARP_NODE_H + +// ScopeNodes are helper nodes, and will never +// be part of the AST. We manually declare them +// here to avoid generating them +typedef struct yp_scope_node { + yp_node_t base; + struct yp_parameters_node *parameters; + struct yp_statements_node *statements; + yp_constant_id_list_t locals; +} yp_scope_node_t; diff --git a/yarp/templates/include/yarp/ast.h.erb b/yarp/templates/include/yarp/ast.h.erb index 5b69c0c8b16231..6fe3bc2c2456bb 100644 --- a/yarp/templates/include/yarp/ast.h.erb +++ b/yarp/templates/include/yarp/ast.h.erb @@ -50,6 +50,7 @@ enum yp_node_type { <%- nodes.each_with_index do |node, index| -%> <%= node.type %> = <%= index + 1 %>, <%- end -%> + YP_NODE_SCOPE_NODE }; typedef uint16_t yp_node_type_t; diff --git a/yarp/templates/src/node.c.erb b/yarp/templates/src/node.c.erb index 371655fdb5fc57..03b720abf73f3e 100644 --- a/yarp/templates/src/node.c.erb +++ b/yarp/templates/src/node.c.erb @@ -115,6 +115,10 @@ yp_node_memsize_node(yp_node_t *node, yp_memsize_t *memsize) { memsize->node_count++; switch (YP_NODE_TYPE(node)) { + // We do not calculate memsize of a ScopeNode + // as it should never be generated + case YP_NODE_SCOPE_NODE: + return; <%- nodes.each do |node| -%> #line <%= __LINE__ + 1 %> "<%= File.basename(__FILE__) %>" case <%= node.type %>: { diff --git a/yarp/templates/src/prettyprint.c.erb b/yarp/templates/src/prettyprint.c.erb index 29d0194dca2bfd..e4403d0e6b0161 100644 --- a/yarp/templates/src/prettyprint.c.erb +++ b/yarp/templates/src/prettyprint.c.erb @@ -16,6 +16,10 @@ prettyprint_location(yp_buffer_t *buffer, yp_parser_t *parser, yp_location_t *lo static void prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) { switch (YP_NODE_TYPE(node)) { + // We do not need to print a ScopeNode as it's not part + // of the AST + case YP_NODE_SCOPE_NODE: + return; <%- nodes.each do |node| -%> case <%= node.type %>: { yp_buffer_append_str(buffer, "<%= node.name %>(", <%= node.name.length + 1 %>); diff --git a/yarp/templates/src/serialize.c.erb b/yarp/templates/src/serialize.c.erb index 63a43f282a687b..b91e3cb7d5d660 100644 --- a/yarp/templates/src/serialize.c.erb +++ b/yarp/templates/src/serialize.c.erb @@ -33,6 +33,10 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) { serialize_location(parser, &node->location, buffer); switch (YP_NODE_TYPE(node)) { + // We do not need to serialize a ScopeNode ever as + // it is not part of the AST + case YP_NODE_SCOPE_NODE: + return; <%- nodes.each do |node| -%> case <%= node.type %>: { <%- if node.needs_serialized_length? -%> diff --git a/yarp/yarp.c b/yarp/yarp.c index 5e63a92f2af2ab..39846d0cb72041 100644 --- a/yarp/yarp.c +++ b/yarp/yarp.c @@ -1033,7 +1033,7 @@ YP_ATTRIBUTE_UNUSED yp_scope_node_create(yp_parameters_node_t *parameters, yp_st // TODO: Implement this for all other nodes which can have a scope void -yp_get_scope_node(yp_node_t *node, yp_scope_node_t *dest) { +yp_scope_node_init(yp_node_t *node, yp_scope_node_t *dest) { yp_parameters_node_t *parameters = NULL; yp_statements_node_t *statements; yp_constant_id_list_t locals; diff --git a/yarp/yarp.h b/yarp/yarp.h index 8e723f414c415a..6b1f3b4ed7e0b9 100644 --- a/yarp/yarp.h +++ b/yarp/yarp.h @@ -31,7 +31,7 @@ void yp_serialize_content(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buf void yp_print_node(yp_parser_t *parser, yp_node_t *node); // Generate a scope node for a DefNode and ClassNode -void yp_get_scope_node(yp_node_t *node, yp_scope_node_t *dest); +void yp_scope_node_init(yp_node_t *node, yp_scope_node_t *dest); // The YARP version and the serialization format. YP_EXPORTED_FUNCTION const char * yp_version(void);