Skip to content

Commit 9effc42

Browse files
committed
1 parent 252b26c commit 9effc42

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+2479
-2119
lines changed

src/main/c/yarp/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ a.out
2828
/java/org/yarp/AbstractNodeVisitor.java
2929
/java/org/yarp/Loader.java
3030
/java/org/yarp/Nodes.java
31+
/java/org/yarp/ParseResult.java
3132
/lib/yarp/node.rb
3233
/lib/yarp/serialize.rb
3334
/src/node.c

src/main/c/yarp/Makefile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ SOEXT := $(shell ruby -e 'puts RbConfig::CONFIG["SOEXT"]')
1212

1313
DEFS := @DEFS@
1414
CPPFLAGS := @DEFS@ -Iinclude
15-
CFLAGS := @CFLAGS@ -std=c99 -Wall -Werror -Wextra -Wpedantic -Wundef -Wsign-conversion -fPIC -fvisibility=hidden
15+
CFLAGS := @CFLAGS@ -std=c99 -Wall -Werror -Wextra -Wpedantic -Wundef -Wconversion -fPIC -fvisibility=hidden
1616
CC := @CC@
1717

1818
HEADERS := $(shell find include -name '*.h')

src/main/c/yarp/config.h.in

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,3 @@
2323

2424
/* Define to the version of this package. */
2525
#undef PACKAGE_VERSION
26-
27-
/* _XOPEN_SOURCE */
28-
#undef _XOPEN_SOURCE

src/main/c/yarp/configure

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3196,9 +3196,6 @@ ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $
31963196
ac_compiler_gnu=$ac_cv_c_compiler_gnu
31973197

31983198

3199-
printf "%s\n" "#define _XOPEN_SOURCE 700" >>confdefs.h
3200-
3201-
32023199

32033200
ac_fn_c_check_func "$LINENO" "mmap" "ac_cv_func_mmap"
32043201
if test "x$ac_cv_func_mmap" = xyes

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ YP_EXPORTED_FUNCTION void yp_serialize(yp_parser_t *parser, yp_node_t *node, yp_
6161

6262
// Parse and serialize the AST represented by the given source to the given
6363
// buffer.
64-
YP_EXPORTED_FUNCTION void yp_parse_serialize(const char *source, size_t size, yp_buffer_t *buffer);
64+
YP_EXPORTED_FUNCTION void yp_parse_serialize(const char *source, size_t size, yp_buffer_t *buffer, const char *metadata);
6565

6666
// Returns a string representation of the given token type.
6767
YP_EXPORTED_FUNCTION const char * yp_token_type_to_str(yp_token_type_t token_type);

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

Lines changed: 127 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ typedef enum yp_token_type {
6262
YP_TOKEN_EQUAL_GREATER, // =>
6363
YP_TOKEN_EQUAL_TILDE, // =~
6464
YP_TOKEN_FLOAT, // a floating point number
65+
YP_TOKEN_FLOAT_IMAGINARY, // a floating pointer number with an imaginary suffix
66+
YP_TOKEN_FLOAT_RATIONAL, // a floating pointer number with a rational suffix
67+
YP_TOKEN_FLOAT_RATIONAL_IMAGINARY, // a floating pointer number with a rational and imaginary suffix
6568
YP_TOKEN_GLOBAL_VARIABLE, // a global variable
6669
YP_TOKEN_GREATER, // >
6770
YP_TOKEN_GREATER_EQUAL, // >=
@@ -71,9 +74,11 @@ typedef enum yp_token_type {
7174
YP_TOKEN_HEREDOC_START, // the start of a heredoc
7275
YP_TOKEN_IDENTIFIER, // an identifier
7376
YP_TOKEN_IGNORED_NEWLINE, // an ignored newline
74-
YP_TOKEN_IMAGINARY_NUMBER, // an imaginary number literal
7577
YP_TOKEN_INSTANCE_VARIABLE, // an instance variable
7678
YP_TOKEN_INTEGER, // an integer (any base)
79+
YP_TOKEN_INTEGER_IMAGINARY, // an integer with an imaginary suffix
80+
YP_TOKEN_INTEGER_RATIONAL, // an integer with a rational suffix
81+
YP_TOKEN_INTEGER_RATIONAL_IMAGINARY, // an integer with a rational and imaginary suffix
7782
YP_TOKEN_KEYWORD_ALIAS, // alias
7883
YP_TOKEN_KEYWORD_AND, // and
7984
YP_TOKEN_KEYWORD_BEGIN, // begin
@@ -151,7 +156,6 @@ typedef enum yp_token_type {
151156
YP_TOKEN_PLUS, // +
152157
YP_TOKEN_PLUS_EQUAL, // +=
153158
YP_TOKEN_QUESTION_MARK, // ?
154-
YP_TOKEN_RATIONAL_NUMBER, // a rational number literal
155159
YP_TOKEN_REGEXP_BEGIN, // the beginning of a regular expression
156160
YP_TOKEN_REGEXP_END, // the end of a regular expression
157161
YP_TOKEN_SEMICOLON, // ;
@@ -166,6 +170,7 @@ typedef enum yp_token_type {
166170
YP_TOKEN_STRING_END, // the end of a string
167171
YP_TOKEN_SYMBOL_BEGIN, // the beginning of a symbol
168172
YP_TOKEN_TILDE, // ~ or ~@
173+
YP_TOKEN_UAMPERSAND, // unary &
169174
YP_TOKEN_UCOLON_COLON, // unary ::
170175
YP_TOKEN_UDOT_DOT, // unary ..
171176
YP_TOKEN_UDOT_DOT_DOT, // unary ...
@@ -245,98 +250,111 @@ typedef enum {
245250
YP_NODE_CONSTANT_PATH_OPERATOR_WRITE_NODE = 34,
246251
YP_NODE_CONSTANT_PATH_WRITE_NODE = 35,
247252
YP_NODE_CONSTANT_READ_NODE = 36,
248-
YP_NODE_DEF_NODE = 37,
249-
YP_NODE_DEFINED_NODE = 38,
250-
YP_NODE_ELSE_NODE = 39,
251-
YP_NODE_EMBEDDED_STATEMENTS_NODE = 40,
252-
YP_NODE_EMBEDDED_VARIABLE_NODE = 41,
253-
YP_NODE_ENSURE_NODE = 42,
254-
YP_NODE_FALSE_NODE = 43,
255-
YP_NODE_FIND_PATTERN_NODE = 44,
256-
YP_NODE_FLOAT_NODE = 45,
257-
YP_NODE_FOR_NODE = 46,
258-
YP_NODE_FORWARDING_ARGUMENTS_NODE = 47,
259-
YP_NODE_FORWARDING_PARAMETER_NODE = 48,
260-
YP_NODE_FORWARDING_SUPER_NODE = 49,
261-
YP_NODE_GLOBAL_VARIABLE_OPERATOR_AND_WRITE_NODE = 50,
262-
YP_NODE_GLOBAL_VARIABLE_OPERATOR_OR_WRITE_NODE = 51,
263-
YP_NODE_GLOBAL_VARIABLE_OPERATOR_WRITE_NODE = 52,
264-
YP_NODE_GLOBAL_VARIABLE_READ_NODE = 53,
265-
YP_NODE_GLOBAL_VARIABLE_WRITE_NODE = 54,
266-
YP_NODE_HASH_NODE = 55,
267-
YP_NODE_HASH_PATTERN_NODE = 56,
268-
YP_NODE_IF_NODE = 57,
269-
YP_NODE_IMAGINARY_NODE = 58,
270-
YP_NODE_IN_NODE = 59,
271-
YP_NODE_INSTANCE_VARIABLE_OPERATOR_AND_WRITE_NODE = 60,
272-
YP_NODE_INSTANCE_VARIABLE_OPERATOR_OR_WRITE_NODE = 61,
273-
YP_NODE_INSTANCE_VARIABLE_OPERATOR_WRITE_NODE = 62,
274-
YP_NODE_INSTANCE_VARIABLE_READ_NODE = 63,
275-
YP_NODE_INSTANCE_VARIABLE_WRITE_NODE = 64,
276-
YP_NODE_INTEGER_NODE = 65,
277-
YP_NODE_INTERPOLATED_REGULAR_EXPRESSION_NODE = 66,
278-
YP_NODE_INTERPOLATED_STRING_NODE = 67,
279-
YP_NODE_INTERPOLATED_SYMBOL_NODE = 68,
280-
YP_NODE_INTERPOLATED_X_STRING_NODE = 69,
281-
YP_NODE_KEYWORD_HASH_NODE = 70,
282-
YP_NODE_KEYWORD_PARAMETER_NODE = 71,
283-
YP_NODE_KEYWORD_REST_PARAMETER_NODE = 72,
284-
YP_NODE_LAMBDA_NODE = 73,
285-
YP_NODE_LOCAL_VARIABLE_OPERATOR_AND_WRITE_NODE = 74,
286-
YP_NODE_LOCAL_VARIABLE_OPERATOR_OR_WRITE_NODE = 75,
287-
YP_NODE_LOCAL_VARIABLE_OPERATOR_WRITE_NODE = 76,
288-
YP_NODE_LOCAL_VARIABLE_READ_NODE = 77,
289-
YP_NODE_LOCAL_VARIABLE_WRITE_NODE = 78,
290-
YP_NODE_MATCH_PREDICATE_NODE = 79,
291-
YP_NODE_MATCH_REQUIRED_NODE = 80,
292-
YP_NODE_MISSING_NODE = 81,
293-
YP_NODE_MODULE_NODE = 82,
294-
YP_NODE_MULTI_WRITE_NODE = 83,
295-
YP_NODE_NEXT_NODE = 84,
296-
YP_NODE_NIL_NODE = 85,
297-
YP_NODE_NO_KEYWORDS_PARAMETER_NODE = 86,
298-
YP_NODE_NUMBERED_REFERENCE_READ_NODE = 87,
299-
YP_NODE_OPTIONAL_PARAMETER_NODE = 88,
300-
YP_NODE_OR_NODE = 89,
301-
YP_NODE_PARAMETERS_NODE = 90,
302-
YP_NODE_PARENTHESES_NODE = 91,
303-
YP_NODE_PINNED_EXPRESSION_NODE = 92,
304-
YP_NODE_PINNED_VARIABLE_NODE = 93,
305-
YP_NODE_POST_EXECUTION_NODE = 94,
306-
YP_NODE_PRE_EXECUTION_NODE = 95,
307-
YP_NODE_PROGRAM_NODE = 96,
308-
YP_NODE_RANGE_NODE = 97,
309-
YP_NODE_RATIONAL_NODE = 98,
310-
YP_NODE_REDO_NODE = 99,
311-
YP_NODE_REGULAR_EXPRESSION_NODE = 100,
312-
YP_NODE_REQUIRED_DESTRUCTURED_PARAMETER_NODE = 101,
313-
YP_NODE_REQUIRED_PARAMETER_NODE = 102,
314-
YP_NODE_RESCUE_MODIFIER_NODE = 103,
315-
YP_NODE_RESCUE_NODE = 104,
316-
YP_NODE_REST_PARAMETER_NODE = 105,
317-
YP_NODE_RETRY_NODE = 106,
318-
YP_NODE_RETURN_NODE = 107,
319-
YP_NODE_SELF_NODE = 108,
320-
YP_NODE_SINGLETON_CLASS_NODE = 109,
321-
YP_NODE_SOURCE_ENCODING_NODE = 110,
322-
YP_NODE_SOURCE_FILE_NODE = 111,
323-
YP_NODE_SOURCE_LINE_NODE = 112,
324-
YP_NODE_SPLAT_NODE = 113,
325-
YP_NODE_STATEMENTS_NODE = 114,
326-
YP_NODE_STRING_CONCAT_NODE = 115,
327-
YP_NODE_STRING_NODE = 116,
328-
YP_NODE_SUPER_NODE = 117,
329-
YP_NODE_SYMBOL_NODE = 118,
330-
YP_NODE_TRUE_NODE = 119,
331-
YP_NODE_UNDEF_NODE = 120,
332-
YP_NODE_UNLESS_NODE = 121,
333-
YP_NODE_UNTIL_NODE = 122,
334-
YP_NODE_WHEN_NODE = 123,
335-
YP_NODE_WHILE_NODE = 124,
336-
YP_NODE_X_STRING_NODE = 125,
337-
YP_NODE_YIELD_NODE = 126,
253+
YP_NODE_CONSTANT_WRITE_NODE = 37,
254+
YP_NODE_DEF_NODE = 38,
255+
YP_NODE_DEFINED_NODE = 39,
256+
YP_NODE_ELSE_NODE = 40,
257+
YP_NODE_EMBEDDED_STATEMENTS_NODE = 41,
258+
YP_NODE_EMBEDDED_VARIABLE_NODE = 42,
259+
YP_NODE_ENSURE_NODE = 43,
260+
YP_NODE_FALSE_NODE = 44,
261+
YP_NODE_FIND_PATTERN_NODE = 45,
262+
YP_NODE_FLOAT_NODE = 46,
263+
YP_NODE_FOR_NODE = 47,
264+
YP_NODE_FORWARDING_ARGUMENTS_NODE = 48,
265+
YP_NODE_FORWARDING_PARAMETER_NODE = 49,
266+
YP_NODE_FORWARDING_SUPER_NODE = 50,
267+
YP_NODE_GLOBAL_VARIABLE_OPERATOR_AND_WRITE_NODE = 51,
268+
YP_NODE_GLOBAL_VARIABLE_OPERATOR_OR_WRITE_NODE = 52,
269+
YP_NODE_GLOBAL_VARIABLE_OPERATOR_WRITE_NODE = 53,
270+
YP_NODE_GLOBAL_VARIABLE_READ_NODE = 54,
271+
YP_NODE_GLOBAL_VARIABLE_WRITE_NODE = 55,
272+
YP_NODE_HASH_NODE = 56,
273+
YP_NODE_HASH_PATTERN_NODE = 57,
274+
YP_NODE_IF_NODE = 58,
275+
YP_NODE_IMAGINARY_NODE = 59,
276+
YP_NODE_IN_NODE = 60,
277+
YP_NODE_INSTANCE_VARIABLE_OPERATOR_AND_WRITE_NODE = 61,
278+
YP_NODE_INSTANCE_VARIABLE_OPERATOR_OR_WRITE_NODE = 62,
279+
YP_NODE_INSTANCE_VARIABLE_OPERATOR_WRITE_NODE = 63,
280+
YP_NODE_INSTANCE_VARIABLE_READ_NODE = 64,
281+
YP_NODE_INSTANCE_VARIABLE_WRITE_NODE = 65,
282+
YP_NODE_INTEGER_NODE = 66,
283+
YP_NODE_INTERPOLATED_REGULAR_EXPRESSION_NODE = 67,
284+
YP_NODE_INTERPOLATED_STRING_NODE = 68,
285+
YP_NODE_INTERPOLATED_SYMBOL_NODE = 69,
286+
YP_NODE_INTERPOLATED_X_STRING_NODE = 70,
287+
YP_NODE_KEYWORD_HASH_NODE = 71,
288+
YP_NODE_KEYWORD_PARAMETER_NODE = 72,
289+
YP_NODE_KEYWORD_REST_PARAMETER_NODE = 73,
290+
YP_NODE_LAMBDA_NODE = 74,
291+
YP_NODE_LOCAL_VARIABLE_OPERATOR_AND_WRITE_NODE = 75,
292+
YP_NODE_LOCAL_VARIABLE_OPERATOR_OR_WRITE_NODE = 76,
293+
YP_NODE_LOCAL_VARIABLE_OPERATOR_WRITE_NODE = 77,
294+
YP_NODE_LOCAL_VARIABLE_READ_NODE = 78,
295+
YP_NODE_LOCAL_VARIABLE_WRITE_NODE = 79,
296+
YP_NODE_MATCH_PREDICATE_NODE = 80,
297+
YP_NODE_MATCH_REQUIRED_NODE = 81,
298+
YP_NODE_MISSING_NODE = 82,
299+
YP_NODE_MODULE_NODE = 83,
300+
YP_NODE_MULTI_WRITE_NODE = 84,
301+
YP_NODE_NEXT_NODE = 85,
302+
YP_NODE_NIL_NODE = 86,
303+
YP_NODE_NO_KEYWORDS_PARAMETER_NODE = 87,
304+
YP_NODE_NUMBERED_REFERENCE_READ_NODE = 88,
305+
YP_NODE_OPTIONAL_PARAMETER_NODE = 89,
306+
YP_NODE_OR_NODE = 90,
307+
YP_NODE_PARAMETERS_NODE = 91,
308+
YP_NODE_PARENTHESES_NODE = 92,
309+
YP_NODE_PINNED_EXPRESSION_NODE = 93,
310+
YP_NODE_PINNED_VARIABLE_NODE = 94,
311+
YP_NODE_POST_EXECUTION_NODE = 95,
312+
YP_NODE_PRE_EXECUTION_NODE = 96,
313+
YP_NODE_PROGRAM_NODE = 97,
314+
YP_NODE_RANGE_NODE = 98,
315+
YP_NODE_RATIONAL_NODE = 99,
316+
YP_NODE_REDO_NODE = 100,
317+
YP_NODE_REGULAR_EXPRESSION_NODE = 101,
318+
YP_NODE_REQUIRED_DESTRUCTURED_PARAMETER_NODE = 102,
319+
YP_NODE_REQUIRED_PARAMETER_NODE = 103,
320+
YP_NODE_RESCUE_MODIFIER_NODE = 104,
321+
YP_NODE_RESCUE_NODE = 105,
322+
YP_NODE_REST_PARAMETER_NODE = 106,
323+
YP_NODE_RETRY_NODE = 107,
324+
YP_NODE_RETURN_NODE = 108,
325+
YP_NODE_SELF_NODE = 109,
326+
YP_NODE_SINGLETON_CLASS_NODE = 110,
327+
YP_NODE_SOURCE_ENCODING_NODE = 111,
328+
YP_NODE_SOURCE_FILE_NODE = 112,
329+
YP_NODE_SOURCE_LINE_NODE = 113,
330+
YP_NODE_SPLAT_NODE = 114,
331+
YP_NODE_STATEMENTS_NODE = 115,
332+
YP_NODE_STRING_CONCAT_NODE = 116,
333+
YP_NODE_STRING_NODE = 117,
334+
YP_NODE_SUPER_NODE = 118,
335+
YP_NODE_SYMBOL_NODE = 119,
336+
YP_NODE_TRUE_NODE = 120,
337+
YP_NODE_UNDEF_NODE = 121,
338+
YP_NODE_UNLESS_NODE = 122,
339+
YP_NODE_UNTIL_NODE = 123,
340+
YP_NODE_WHEN_NODE = 124,
341+
YP_NODE_WHILE_NODE = 125,
342+
YP_NODE_X_STRING_NODE = 126,
343+
YP_NODE_YIELD_NODE = 127,
338344
} yp_node_type_t;
339345

346+
// We store the node type enum in every node in the tree. We don't have nearly
347+
// as many node types as we do bits in an enum, so we're going to use the top
348+
// half of the enum to store flags about the node.
349+
static const unsigned int YP_NODE_FLAGS_SHIFT = sizeof(yp_node_type_t) * 8 / 2;
350+
static const unsigned int YP_NODE_FLAG_NEWLINE = 1 << YP_NODE_FLAGS_SHIFT;
351+
352+
// For easy access, we define some macros that manipulate only the bottom half
353+
// of the node type enum.
354+
static const unsigned int YP_NODE_TYPE_MASK = ((1 << (sizeof(yp_node_type_t) * 8 / 2)) - 1);
355+
#define YP_NODE_TYPE(node) ((node)->type & YP_NODE_TYPE_MASK)
356+
#define YP_NODE_TYPE_P(node, type) (YP_NODE_TYPE(node) == (type))
357+
340358
// This is the overall tagged union representing a node in the syntax tree.
341359
typedef struct yp_node {
342360
// This represents the type of the node. It somewhat maps to the nodes that
@@ -646,6 +664,14 @@ typedef struct yp_constant_read_node {
646664
yp_node_t base;
647665
} yp_constant_read_node_t;
648666

667+
// ConstantWriteNode
668+
typedef struct yp_constant_write_node {
669+
yp_node_t base;
670+
yp_location_t name_loc;
671+
struct yp_node *value;
672+
yp_location_t operator_loc;
673+
} yp_constant_write_node_t;
674+
649675
// DefNode
650676
typedef struct yp_def_node {
651677
yp_node_t base;
@@ -1183,7 +1209,7 @@ typedef struct yp_rescue_node {
11831209
yp_location_t keyword_loc;
11841210
struct yp_node_list exceptions;
11851211
yp_location_t operator_loc;
1186-
struct yp_node *exception;
1212+
struct yp_node *reference;
11871213
struct yp_statements_node *statements;
11881214
struct yp_rescue_node *consequent;
11891215
} yp_rescue_node_t;
@@ -1315,6 +1341,7 @@ typedef struct yp_until_node {
13151341
yp_location_t keyword_loc;
13161342
struct yp_node *predicate;
13171343
struct yp_statements_node *statements;
1344+
uint32_t flags;
13181345
} yp_until_node_t;
13191346

13201347
// WhenNode
@@ -1331,6 +1358,7 @@ typedef struct yp_while_node {
13311358
yp_location_t keyword_loc;
13321359
struct yp_node *predicate;
13331360
struct yp_statements_node *statements;
1361+
uint32_t flags;
13341362
} yp_while_node_t;
13351363

13361364
// XStringNode
@@ -1354,8 +1382,14 @@ typedef struct yp_yield_node {
13541382
// CallNodeFlags
13551383
typedef enum {
13561384
YP_CALL_NODE_FLAGS_SAFE_NAVIGATION = 1 << 0,
1385+
YP_CALL_NODE_FLAGS_VARIABLE_CALL = 1 << 1,
13571386
} yp_call_node_flags_t;
13581387

1388+
// LoopFlags
1389+
typedef enum {
1390+
YP_LOOP_FLAGS_BEGIN_MODIFIER = 1 << 0,
1391+
} yp_loop_flags_t;
1392+
13591393
// RangeNodeFlags
13601394
typedef enum {
13611395
YP_RANGE_NODE_FLAGS_EXCLUDE_END = 1 << 0,

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,16 @@
1212
#include <string.h>
1313

1414
// YP_EXPORTED_FUNCTION
15-
#if defined(_WIN32)
16-
# define YP_EXPORTED_FUNCTION __declspec(dllexport) extern
17-
#elif defined(YP_EXPORT_SYMBOLS)
18-
# ifndef YP_EXPORTED_FUNCTION
19-
# ifndef RUBY_FUNC_EXPORTED
20-
# define YP_EXPORTED_FUNCTION __attribute__((__visibility__("default"))) extern
15+
#ifndef YP_EXPORTED_FUNCTION
16+
# ifdef YP_EXPORT_SYMBOLS
17+
# ifdef _WIN32
18+
# define YP_EXPORTED_FUNCTION __declspec(dllexport) extern
2119
# else
22-
# define YP_EXPORTED_FUNCTION RUBY_FUNC_EXPORTED
20+
# define YP_EXPORTED_FUNCTION __attribute__((__visibility__("default"))) extern
2321
# endif
22+
# else
23+
# define YP_EXPORTED_FUNCTION
2424
# endif
25-
#else
26-
# define YP_EXPORTED_FUNCTION
2725
#endif
2826

2927
// YP_ATTRIBUTE_UNUSED

0 commit comments

Comments
 (0)