[ruby/yarp] Pulled scope node out of config.yml, added necessary void returns

https://github.com/ruby/yarp/commit/926e6bdd88
This commit is contained in:
Jemma Issroff 2023-08-23 10:30:05 -07:00 committed by git
parent d81634d3ef
commit 82e1434ef6
8 changed files with 25 additions and 16 deletions

View File

@ -1686,20 +1686,6 @@ nodes:
return 1 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 - name: SelfNode
comment: | comment: |
Represents the `self` keyword. Represents the `self` keyword.

View File

@ -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 }) #define YP_EMPTY_LOCATION_LIST ((yp_location_list_t) { .locations = NULL, .size = 0, .capacity = 0 })
#endif // YARP_NODE_H #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;

View File

@ -50,6 +50,7 @@ enum yp_node_type {
<%- nodes.each_with_index do |node, index| -%> <%- nodes.each_with_index do |node, index| -%>
<%= node.type %> = <%= index + 1 %>, <%= node.type %> = <%= index + 1 %>,
<%- end -%> <%- end -%>
YP_NODE_SCOPE_NODE
}; };
typedef uint16_t yp_node_type_t; typedef uint16_t yp_node_type_t;

View File

@ -115,6 +115,10 @@ yp_node_memsize_node(yp_node_t *node, yp_memsize_t *memsize) {
memsize->node_count++; memsize->node_count++;
switch (YP_NODE_TYPE(node)) { 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| -%> <%- nodes.each do |node| -%>
#line <%= __LINE__ + 1 %> "<%= File.basename(__FILE__) %>" #line <%= __LINE__ + 1 %> "<%= File.basename(__FILE__) %>"
case <%= node.type %>: { case <%= node.type %>: {

View File

@ -16,6 +16,10 @@ prettyprint_location(yp_buffer_t *buffer, yp_parser_t *parser, yp_location_t *lo
static void static void
prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) { prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
switch (YP_NODE_TYPE(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| -%> <%- nodes.each do |node| -%>
case <%= node.type %>: { case <%= node.type %>: {
yp_buffer_append_str(buffer, "<%= node.name %>(", <%= node.name.length + 1 %>); yp_buffer_append_str(buffer, "<%= node.name %>(", <%= node.name.length + 1 %>);

View File

@ -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); serialize_location(parser, &node->location, buffer);
switch (YP_NODE_TYPE(node)) { 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| -%> <%- nodes.each do |node| -%>
case <%= node.type %>: { case <%= node.type %>: {
<%- if node.needs_serialized_length? -%> <%- if node.needs_serialized_length? -%>

View File

@ -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 // TODO: Implement this for all other nodes which can have a scope
void 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_parameters_node_t *parameters = NULL;
yp_statements_node_t *statements; yp_statements_node_t *statements;
yp_constant_id_list_t locals; yp_constant_id_list_t locals;

View File

@ -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); void yp_print_node(yp_parser_t *parser, yp_node_t *node);
// Generate a scope node for a DefNode and ClassNode // 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. // The YARP version and the serialization format.
YP_EXPORTED_FUNCTION const char * yp_version(void); YP_EXPORTED_FUNCTION const char * yp_version(void);