Skip to content

Commit 6ca2e4e

Browse files
committed
[GR-45043] Use length() instead of endOffset in YARPTranslator
PullRequest: truffleruby/3849
2 parents d444a29 + 533dc68 commit 6ca2e4e

File tree

16 files changed

+1091
-659
lines changed

16 files changed

+1091
-659
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# NOTE: This is only a small subset of the CI which runs on GitHub Actions.
22
# Most of the CI is defined in ci.jsonnet.
33
name: CI
4-
on: [push, pull_request]
4+
on:
5+
pull_request:
6+
push:
7+
branches: [master]
58
permissions:
69
contents: read
710

src/main/c/yarp/src/yarp/include/yarp/ast.h

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -250,43 +250,43 @@ typedef enum {
250250
YP_NODE_INTERPOLATED_STRING_NODE = 46,
251251
YP_NODE_INTERPOLATED_SYMBOL_NODE = 47,
252252
YP_NODE_INTERPOLATED_X_STRING_NODE = 48,
253-
YP_NODE_KEYWORD_PARAMETER_NODE = 49,
254-
YP_NODE_KEYWORD_REST_PARAMETER_NODE = 50,
255-
YP_NODE_LAMBDA_NODE = 51,
256-
YP_NODE_LOCAL_VARIABLE_READ_NODE = 52,
257-
YP_NODE_LOCAL_VARIABLE_WRITE_NODE = 53,
258-
YP_NODE_MATCH_PREDICATE_NODE = 54,
259-
YP_NODE_MATCH_REQUIRED_NODE = 55,
260-
YP_NODE_MISSING_NODE = 56,
261-
YP_NODE_MODULE_NODE = 57,
262-
YP_NODE_MULTI_WRITE_NODE = 58,
263-
YP_NODE_NEXT_NODE = 59,
264-
YP_NODE_NIL_NODE = 60,
265-
YP_NODE_NO_KEYWORDS_PARAMETER_NODE = 61,
266-
YP_NODE_OPERATOR_AND_ASSIGNMENT_NODE = 62,
267-
YP_NODE_OPERATOR_ASSIGNMENT_NODE = 63,
268-
YP_NODE_OPERATOR_OR_ASSIGNMENT_NODE = 64,
269-
YP_NODE_OPTIONAL_PARAMETER_NODE = 65,
270-
YP_NODE_OR_NODE = 66,
271-
YP_NODE_PARAMETERS_NODE = 67,
272-
YP_NODE_PARENTHESES_NODE = 68,
273-
YP_NODE_PINNED_EXPRESSION_NODE = 69,
274-
YP_NODE_PINNED_VARIABLE_NODE = 70,
275-
YP_NODE_POST_EXECUTION_NODE = 71,
276-
YP_NODE_PRE_EXECUTION_NODE = 72,
277-
YP_NODE_PROGRAM_NODE = 73,
278-
YP_NODE_RANGE_NODE = 74,
279-
YP_NODE_RATIONAL_NODE = 75,
280-
YP_NODE_REDO_NODE = 76,
281-
YP_NODE_REGULAR_EXPRESSION_NODE = 77,
282-
YP_NODE_REQUIRED_DESTRUCTURED_PARAMETER_NODE = 78,
283-
YP_NODE_REQUIRED_PARAMETER_NODE = 79,
284-
YP_NODE_RESCUE_MODIFIER_NODE = 80,
285-
YP_NODE_RESCUE_NODE = 81,
286-
YP_NODE_REST_PARAMETER_NODE = 82,
287-
YP_NODE_RETRY_NODE = 83,
288-
YP_NODE_RETURN_NODE = 84,
289-
YP_NODE_SCOPE_NODE = 85,
253+
YP_NODE_KEYWORD_HASH_NODE = 49,
254+
YP_NODE_KEYWORD_PARAMETER_NODE = 50,
255+
YP_NODE_KEYWORD_REST_PARAMETER_NODE = 51,
256+
YP_NODE_LAMBDA_NODE = 52,
257+
YP_NODE_LOCAL_VARIABLE_READ_NODE = 53,
258+
YP_NODE_LOCAL_VARIABLE_WRITE_NODE = 54,
259+
YP_NODE_MATCH_PREDICATE_NODE = 55,
260+
YP_NODE_MATCH_REQUIRED_NODE = 56,
261+
YP_NODE_MISSING_NODE = 57,
262+
YP_NODE_MODULE_NODE = 58,
263+
YP_NODE_MULTI_WRITE_NODE = 59,
264+
YP_NODE_NEXT_NODE = 60,
265+
YP_NODE_NIL_NODE = 61,
266+
YP_NODE_NO_KEYWORDS_PARAMETER_NODE = 62,
267+
YP_NODE_OPERATOR_AND_ASSIGNMENT_NODE = 63,
268+
YP_NODE_OPERATOR_ASSIGNMENT_NODE = 64,
269+
YP_NODE_OPERATOR_OR_ASSIGNMENT_NODE = 65,
270+
YP_NODE_OPTIONAL_PARAMETER_NODE = 66,
271+
YP_NODE_OR_NODE = 67,
272+
YP_NODE_PARAMETERS_NODE = 68,
273+
YP_NODE_PARENTHESES_NODE = 69,
274+
YP_NODE_PINNED_EXPRESSION_NODE = 70,
275+
YP_NODE_PINNED_VARIABLE_NODE = 71,
276+
YP_NODE_POST_EXECUTION_NODE = 72,
277+
YP_NODE_PRE_EXECUTION_NODE = 73,
278+
YP_NODE_PROGRAM_NODE = 74,
279+
YP_NODE_RANGE_NODE = 75,
280+
YP_NODE_RATIONAL_NODE = 76,
281+
YP_NODE_REDO_NODE = 77,
282+
YP_NODE_REGULAR_EXPRESSION_NODE = 78,
283+
YP_NODE_REQUIRED_DESTRUCTURED_PARAMETER_NODE = 79,
284+
YP_NODE_REQUIRED_PARAMETER_NODE = 80,
285+
YP_NODE_RESCUE_MODIFIER_NODE = 81,
286+
YP_NODE_RESCUE_NODE = 82,
287+
YP_NODE_REST_PARAMETER_NODE = 83,
288+
YP_NODE_RETRY_NODE = 84,
289+
YP_NODE_RETURN_NODE = 85,
290290
YP_NODE_SELF_NODE = 86,
291291
YP_NODE_SINGLETON_CLASS_NODE = 87,
292292
YP_NODE_SOURCE_ENCODING_NODE = 88,
@@ -412,7 +412,7 @@ typedef struct yp_block_argument_node {
412412
// BlockNode
413413
typedef struct yp_block_node {
414414
yp_node_t base;
415-
struct yp_scope_node *scope;
415+
yp_token_list_t locals;
416416
struct yp_block_parameters_node *parameters;
417417
struct yp_node *statements;
418418
yp_location_t opening_loc;
@@ -476,7 +476,7 @@ typedef struct yp_case_node {
476476
// ClassNode
477477
typedef struct yp_class_node {
478478
yp_node_t base;
479-
struct yp_scope_node *scope;
479+
yp_token_list_t locals;
480480
yp_token_t class_keyword;
481481
struct yp_node *constant_path;
482482
yp_token_t inheritance_operator;
@@ -526,7 +526,7 @@ typedef struct yp_def_node {
526526
struct yp_node *receiver;
527527
struct yp_parameters_node *parameters;
528528
struct yp_node *statements;
529-
struct yp_scope_node *scope;
529+
yp_token_list_t locals;
530530
yp_location_t def_keyword_loc;
531531
yp_location_t operator_loc;
532532
yp_location_t lparen_loc;
@@ -716,6 +716,12 @@ typedef struct yp_interpolated_x_string_node {
716716
yp_token_t closing;
717717
} yp_interpolated_x_string_node_t;
718718

719+
// KeywordHashNode
720+
typedef struct yp_keyword_hash_node {
721+
yp_node_t base;
722+
struct yp_node_list elements;
723+
} yp_keyword_hash_node_t;
724+
719725
// KeywordParameterNode
720726
typedef struct yp_keyword_parameter_node {
721727
yp_node_t base;
@@ -733,7 +739,7 @@ typedef struct yp_keyword_rest_parameter_node {
733739
// LambdaNode
734740
typedef struct yp_lambda_node {
735741
yp_node_t base;
736-
struct yp_scope_node *scope;
742+
yp_token_list_t locals;
737743
yp_token_t opening;
738744
struct yp_block_parameters_node *parameters;
739745
struct yp_node *statements;
@@ -742,7 +748,7 @@ typedef struct yp_lambda_node {
742748
// LocalVariableReadNode
743749
typedef struct yp_local_variable_read_node {
744750
yp_node_t base;
745-
int depth;
751+
uint32_t depth;
746752
} yp_local_variable_read_node_t;
747753

748754
// LocalVariableWriteNode
@@ -751,7 +757,7 @@ typedef struct yp_local_variable_write_node {
751757
yp_location_t name_loc;
752758
struct yp_node *value;
753759
yp_location_t operator_loc;
754-
int depth;
760+
uint32_t depth;
755761
} yp_local_variable_write_node_t;
756762

757763
// MatchPredicateNode
@@ -778,7 +784,7 @@ typedef struct yp_missing_node {
778784
// ModuleNode
779785
typedef struct yp_module_node {
780786
yp_node_t base;
781-
struct yp_scope_node *scope;
787+
yp_token_list_t locals;
782788
yp_token_t module_keyword;
783789
struct yp_node *constant_path;
784790
struct yp_node *statements;
@@ -911,7 +917,7 @@ typedef struct yp_pre_execution_node {
911917
// ProgramNode
912918
typedef struct yp_program_node {
913919
yp_node_t base;
914-
struct yp_scope_node *scope;
920+
yp_token_list_t locals;
915921
struct yp_statements_node *statements;
916922
} yp_program_node_t;
917923

@@ -994,12 +1000,6 @@ typedef struct yp_return_node {
9941000
struct yp_arguments_node *arguments;
9951001
} yp_return_node_t;
9961002

997-
// ScopeNode
998-
typedef struct yp_scope_node {
999-
yp_node_t base;
1000-
yp_token_list_t locals;
1001-
} yp_scope_node_t;
1002-
10031003
// SelfNode
10041004
typedef struct yp_self_node {
10051005
yp_node_t base;
@@ -1008,7 +1008,7 @@ typedef struct yp_self_node {
10081008
// SingletonClassNode
10091009
typedef struct yp_singleton_class_node {
10101010
yp_node_t base;
1011-
struct yp_scope_node *scope;
1011+
yp_token_list_t locals;
10121012
yp_token_t class_keyword;
10131013
yp_token_t operator;
10141014
struct yp_node *expression;

src/main/c/yarp/src/yarp/include/yarp/node.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ yp_node_list_init(yp_node_list_t *node_list);
2424

2525
// Append a new node onto the end of the node list.
2626
void
27-
yp_node_list_append(yp_parser_t *parser, yp_node_t *parent, yp_node_list_t *list, yp_node_t *node);
27+
yp_node_list_append(yp_node_list_t *list, yp_node_t *node);
2828

2929
// Clear the node but preserves the location.
3030
void

src/main/c/yarp/src/yarp/include/yarp/parser.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ typedef struct yp_lex_mode {
154154
const char *start;
155155
const char *end;
156156
} numeric;
157-
157+
158158
struct {
159159
// These pointers point to the beginning and end of the heredoc
160160
// identifier.
@@ -195,6 +195,7 @@ typedef enum {
195195
YP_CONTEXT_CLASS, // a class declaration
196196
YP_CONTEXT_DEF, // a method definition
197197
YP_CONTEXT_DEF_PARAMS, // a method definition's parameters
198+
YP_CONTEXT_DEFAULT_PARAMS, // a method definition's default parameter
198199
YP_CONTEXT_ELSE, // an else clause
199200
YP_CONTEXT_ELSIF, // an elsif clause
200201
YP_CONTEXT_EMBEXPR, // an interpolated expression
@@ -280,9 +281,8 @@ typedef struct {
280281
// This struct represents a node in a linked list of scopes. Some scopes can see
281282
// into their parent scopes, while others cannot.
282283
typedef struct yp_scope {
283-
// A pointer to the node that holds the tokens that correspond to the locals
284-
// in the given scope.
285-
yp_scope_node_t *node;
284+
// Locals in the given scope.
285+
yp_token_list_t locals;
286286

287287
// A boolean indicating whether or not this scope can see into its parent. If
288288
// top is true, then the scope cannot see into its parent.

src/main/c/yarp/src/yarp/include/yarp/util/yp_buffer.h

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include "yarp/defines.h"
55

6+
#include <assert.h>
67
#include <stdint.h>
78
#include <stdlib.h>
89
#include <string.h>
@@ -32,22 +33,10 @@ yp_buffer_append_str(yp_buffer_t *buffer, const char *value, size_t length);
3233
void
3334
yp_buffer_append_u8(yp_buffer_t *buffer, uint8_t value);
3435

35-
// Append a 16-bit unsigned integer to the buffer.
36-
void
37-
yp_buffer_append_u16(yp_buffer_t *buffer, uint16_t value);
38-
3936
// Append a 32-bit unsigned integer to the buffer.
4037
void
4138
yp_buffer_append_u32(yp_buffer_t *buffer, uint32_t value);
4239

43-
// Append a 64-bit unsigned integer to the buffer.
44-
void
45-
yp_buffer_append_u64(yp_buffer_t *buffer, uint64_t value);
46-
47-
// Append an integer to the buffer.
48-
void
49-
yp_buffer_append_int(yp_buffer_t *buffer, int value);
50-
5140
// Free the memory associated with the buffer.
5241
__attribute__ ((__visibility__("default"))) extern void
5342
yp_buffer_free(yp_buffer_t *buffer);

0 commit comments

Comments
 (0)