2020-04-10 08:11:40 +03:00
|
|
|
#ifndef RUBY_NODE_H
|
|
|
|
#define RUBY_NODE_H 1
|
2000-05-01 13:42:38 +04:00
|
|
|
/**********************************************************************
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
node.h -
|
|
|
|
|
|
|
|
$Author$
|
|
|
|
created at: Fri May 28 15:14:02 JST 1993
|
|
|
|
|
* encoding.c: provide basic features for M17N.
* parse.y: encoding aware parsing.
* parse.y (pragma_encoding): encoding specification pragma.
* parse.y (rb_intern3): encoding specified symbols.
* string.c (rb_str_length): length based on characters.
for older behavior, bytesize method added.
* string.c (rb_str_index_m): index based on characters. rindex as
well.
* string.c (succ_char): encoding aware succeeding string.
* string.c (rb_str_reverse): reverse based on characters.
* string.c (rb_str_inspect): encoding aware string description.
* string.c (rb_str_upcase_bang): encoding aware case conversion.
downcase, capitalize, swapcase as well.
* string.c (rb_str_tr_bang): tr based on characters. delete,
squeeze, tr_s, count as well.
* string.c (rb_str_split_m): split based on characters.
* string.c (rb_str_each_line): encoding aware each_line.
* string.c (rb_str_each_char): added. iteration based on
characters.
* string.c (rb_str_strip_bang): encoding aware whitespace
stripping. lstrip, rstrip as well.
* string.c (rb_str_justify): encoding aware justifying (ljust,
rjust, center).
* string.c (str_encoding): get encoding attribute from a string.
* re.c (rb_reg_initialize): encoding aware regular expression
* sprintf.c (rb_str_format): formatting (i.e. length count) based
on characters.
* io.c (rb_io_getc): getc to return one-character string.
for older behavior, getbyte method added.
* ext/stringio/stringio.c (strio_getc): ditto.
* io.c (rb_io_ungetc): allow pushing arbitrary string at the
current reading point.
* ext/stringio/stringio.c (strio_ungetc): ditto.
* ext/strscan/strscan.c: encoding support.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13261 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-08-25 07:29:39 +04:00
|
|
|
Copyright (C) 1993-2007 Yukihiro Matsumoto
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-05-01 13:42:38 +04:00
|
|
|
**********************************************************************/
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2023-05-28 14:00:20 +03:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include "rubyparser.h"
|
|
|
|
#include "ruby/backward/2/attributes.h"
|
|
|
|
|
|
|
|
typedef void (*bug_report_func)(const char *fmt, ...);
|
|
|
|
|
|
|
|
typedef struct node_buffer_elem_struct {
|
|
|
|
struct node_buffer_elem_struct *next;
|
2023-08-22 04:26:38 +03:00
|
|
|
long len; /* Length of nodes */
|
|
|
|
size_t allocated; /* Total memory size of allocated buf */
|
|
|
|
size_t used; /* Current usage of buf */
|
|
|
|
NODE **nodes; /* Array of node pointers */
|
|
|
|
NODE *buf[FLEX_ARY_LEN];
|
2023-05-28 14:00:20 +03:00
|
|
|
} node_buffer_elem_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
node_buffer_elem_t *head;
|
|
|
|
node_buffer_elem_t *last;
|
|
|
|
} node_buffer_list_t;
|
|
|
|
|
|
|
|
struct node_buffer_struct {
|
|
|
|
node_buffer_list_t unmarkable;
|
|
|
|
node_buffer_list_t markable;
|
|
|
|
struct rb_ast_local_table_link *local_tables;
|
|
|
|
VALUE mark_hash;
|
|
|
|
// - id (sequence number)
|
|
|
|
// - token_type
|
|
|
|
// - text of token
|
|
|
|
// - location info
|
|
|
|
// Array, whose entry is array
|
|
|
|
VALUE tokens;
|
|
|
|
#ifdef UNIVERSAL_PARSER
|
|
|
|
rb_parser_config_t *config;
|
|
|
|
#endif
|
1998-01-16 15:13:05 +03:00
|
|
|
};
|
|
|
|
|
2023-05-28 14:00:20 +03:00
|
|
|
RUBY_SYMBOL_EXPORT_BEGIN
|
2018-01-08 15:30:35 +03:00
|
|
|
|
2023-05-28 14:00:20 +03:00
|
|
|
#ifdef UNIVERSAL_PARSER
|
|
|
|
rb_ast_t *rb_ast_new(rb_parser_config_t *config);
|
|
|
|
#else
|
2023-09-21 17:01:02 +03:00
|
|
|
rb_ast_t *rb_ast_new(void);
|
2023-05-28 14:00:20 +03:00
|
|
|
#endif
|
|
|
|
size_t rb_ast_memsize(const rb_ast_t*);
|
|
|
|
void rb_ast_dispose(rb_ast_t*);
|
|
|
|
VALUE rb_ast_tokens(rb_ast_t *ast);
|
|
|
|
#if RUBY_DEBUG
|
|
|
|
void rb_ast_node_type_change(NODE *n, enum node_type type);
|
|
|
|
#endif
|
|
|
|
const char *ruby_node_name(int node);
|
2023-08-22 04:26:38 +03:00
|
|
|
void rb_node_init(NODE *n, enum node_type type);
|
2021-11-17 21:40:49 +03:00
|
|
|
|
2023-05-28 14:00:20 +03:00
|
|
|
void rb_ast_mark(rb_ast_t*);
|
|
|
|
void rb_ast_update_references(rb_ast_t*);
|
|
|
|
void rb_ast_free(rb_ast_t*);
|
|
|
|
void rb_ast_add_mark_object(rb_ast_t*, VALUE);
|
2023-10-13 13:21:59 +03:00
|
|
|
void rb_ast_delete_mark_object(rb_ast_t*, VALUE);
|
2023-05-28 14:00:20 +03:00
|
|
|
void rb_ast_set_tokens(rb_ast_t*, VALUE);
|
2023-08-22 04:26:38 +03:00
|
|
|
NODE *rb_ast_newnode(rb_ast_t*, enum node_type type, size_t size, size_t alignment);
|
2023-05-28 14:00:20 +03:00
|
|
|
void rb_ast_delete_node(rb_ast_t*, NODE *n);
|
|
|
|
rb_ast_id_table_t *rb_ast_new_local_table(rb_ast_t*, int);
|
|
|
|
rb_ast_id_table_t *rb_ast_resize_latest_local_table(rb_ast_t*, int);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2023-05-28 14:00:20 +03:00
|
|
|
VALUE rb_parser_dump_tree(const NODE *node, int comment);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2023-05-28 14:00:20 +03:00
|
|
|
const struct kwtable *rb_reserved_word(const char *, unsigned int);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2023-05-28 14:00:20 +03:00
|
|
|
struct parser_params;
|
|
|
|
void *rb_parser_malloc(struct parser_params *, size_t);
|
|
|
|
void *rb_parser_realloc(struct parser_params *, void *, size_t);
|
|
|
|
void *rb_parser_calloc(struct parser_params *, size_t, size_t);
|
|
|
|
void rb_parser_free(struct parser_params *, void *);
|
|
|
|
PRINTF_ARGS(void rb_parser_printf(struct parser_params *parser, const char *fmt, ...), 2, 3);
|
|
|
|
VALUE rb_node_set_type(NODE *n, enum node_type t);
|
2004-11-17 05:27:38 +03:00
|
|
|
|
2023-05-28 14:00:20 +03:00
|
|
|
RUBY_SYMBOL_EXPORT_END
|
2004-01-21 19:47:23 +03:00
|
|
|
|
2007-10-07 17:03:05 +04:00
|
|
|
#define NODE_LSHIFT (NODE_TYPESHIFT+7)
|
|
|
|
#define NODE_LMASK (((SIGNED_VALUE)1<<(sizeof(VALUE)*CHAR_BIT-NODE_LSHIFT))-1)
|
2023-05-28 14:00:20 +03:00
|
|
|
|
2017-11-04 14:37:19 +03:00
|
|
|
#define nd_line(n) (int)(((SIGNED_VALUE)(n)->flags)>>NODE_LSHIFT)
|
1998-01-16 15:13:05 +03:00
|
|
|
#define nd_set_line(n,l) \
|
2017-11-04 14:37:19 +03:00
|
|
|
(n)->flags=(((n)->flags&~((VALUE)(-1)<<NODE_LSHIFT))|((VALUE)((l)&NODE_LMASK)<<NODE_LSHIFT))
|
2017-10-30 16:36:20 +03:00
|
|
|
|
2023-05-28 14:00:20 +03:00
|
|
|
|
|
|
|
#define NODE_SPECIAL_REQUIRED_KEYWORD ((NODE *)-1)
|
2023-10-07 03:52:06 +03:00
|
|
|
#define NODE_REQUIRED_KEYWORD_P(node) ((node) == NODE_SPECIAL_REQUIRED_KEYWORD)
|
2023-05-28 14:00:20 +03:00
|
|
|
#define NODE_SPECIAL_NO_NAME_REST ((NODE *)-1)
|
|
|
|
#define NODE_NAMED_REST_P(node) ((node) != NODE_SPECIAL_NO_NAME_REST)
|
|
|
|
#define NODE_SPECIAL_EXCESSIVE_COMMA ((ID)1)
|
|
|
|
#define NODE_SPECIAL_NO_REST_KEYWORD ((NODE *)-1)
|
|
|
|
|
2023-08-22 04:26:38 +03:00
|
|
|
#define nd_first_column(n) ((int)(RNODE(n)->nd_loc.beg_pos.column))
|
|
|
|
#define nd_set_first_column(n, v) (RNODE(n)->nd_loc.beg_pos.column = (v))
|
|
|
|
#define nd_first_lineno(n) ((int)(RNODE(n)->nd_loc.beg_pos.lineno))
|
|
|
|
#define nd_set_first_lineno(n, v) (RNODE(n)->nd_loc.beg_pos.lineno = (v))
|
|
|
|
#define nd_first_loc(n) (RNODE(n)->nd_loc.beg_pos)
|
2018-10-20 13:10:46 +03:00
|
|
|
#define nd_set_first_loc(n, v) (nd_first_loc(n) = (v))
|
2017-11-13 03:14:33 +03:00
|
|
|
|
2023-08-22 04:26:38 +03:00
|
|
|
#define nd_last_column(n) ((int)(RNODE(n)->nd_loc.end_pos.column))
|
|
|
|
#define nd_set_last_column(n, v) (RNODE(n)->nd_loc.end_pos.column = (v))
|
|
|
|
#define nd_last_lineno(n) ((int)(RNODE(n)->nd_loc.end_pos.lineno))
|
|
|
|
#define nd_set_last_lineno(n, v) (RNODE(n)->nd_loc.end_pos.lineno = (v))
|
|
|
|
#define nd_last_loc(n) (RNODE(n)->nd_loc.end_pos)
|
2017-12-14 11:22:22 +03:00
|
|
|
#define nd_set_last_loc(n, v) (nd_last_loc(n) = (v))
|
2023-08-22 04:26:38 +03:00
|
|
|
#define nd_node_id(n) (RNODE(n)->node_id)
|
|
|
|
#define nd_set_node_id(n,id) (RNODE(n)->node_id = (id))
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2021-12-04 04:35:44 +03:00
|
|
|
static inline bool
|
|
|
|
nd_type_p(const NODE *n, enum node_type t)
|
|
|
|
{
|
|
|
|
return (enum node_type)nd_type(n) == t;
|
|
|
|
}
|
1999-10-29 13:25:48 +04:00
|
|
|
|
2007-06-10 07:06:15 +04:00
|
|
|
#endif /* RUBY_NODE_H */
|