diff options
author | Jemma Issroff <[email protected]> | 2023-08-23 10:30:05 -0700 |
---|---|---|
committer | git <[email protected]> | 2023-08-24 19:06:00 +0000 |
commit | 82e1434ef65cf1eead1e9828d12e2ed1a29de0fa (patch) | |
tree | e29f1eeeed257ddfbdd6a7aaa8cdac91b1146ca9 | |
parent | d81634d3ef21b5b8072934a1e00f431e42cbce8a (diff) |
[ruby/yarp] Pulled scope node out of config.yml, added necessary void returns
https://github.com/ruby/yarp/commit/926e6bdd88
-rw-r--r-- | yarp/config.yml | 14 | ||||
-rw-r--r-- | yarp/node.h | 10 | ||||
-rw-r--r-- | yarp/templates/include/yarp/ast.h.erb | 1 | ||||
-rw-r--r-- | yarp/templates/src/node.c.erb | 4 | ||||
-rw-r--r-- | yarp/templates/src/prettyprint.c.erb | 4 | ||||
-rw-r--r-- | yarp/templates/src/serialize.c.erb | 4 | ||||
-rw-r--r-- | yarp/yarp.c | 2 | ||||
-rw-r--r-- | yarp/yarp.h | 2 |
8 files changed, 25 insertions, 16 deletions
diff --git a/yarp/config.yml b/yarp/config.yml index bf41d486d4..e4987013bb 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 a107baddb8..8e059f957a 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 5b69c0c8b1..6fe3bc2c24 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 371655fdb5..03b720abf7 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 29d0194dca..e4403d0e6b 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 63a43f282a..b91e3cb7d5 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 5e63a92f2a..39846d0cb7 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 8e723f414c..6b1f3b4ed7 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); |