4#include "internal/symbol.h"
24node_gc_mark(
void *
ptr)
31node_memsize(
const void *
ptr)
61 obj = rb_ast_node_alloc(rb_cNode);
91 return rb_ast_parse_str(
str);
101 return ast_parse_done(
ast);
107 return rb_ast_parse_file(path);
111rb_ast_parse_file(
VALUE path)
122 return ast_parse_done(
ast);
126lex_array(
VALUE array,
int index)
139rb_ast_parse_array(
VALUE array)
145 return ast_parse_done(
ast);
151node_find(
VALUE self,
const int node_id)
160 ary = node_children(data->
ast, data->
node);
166 VALUE result = node_find(child, node_id);
167 if (
RTEST(result))
return result;
177script_lines(
VALUE path)
181 CONST_ID(script_lines,
"SCRIPT_LINES__");
198 iseq = vm_proc_iseq(body);
200 if (!rb_obj_is_iseq((
VALUE)iseq)) {
208 if (!iseq)
return Qnil;
212 if (!
NIL_P(lines = script_lines(path))) {
213 node = rb_ast_parse_array(lines);
219 node = rb_ast_parse_file(path);
222 return node_find(
node, node_id);
226rb_ast_node_alloc(
VALUE klass)
249#define NEW_CHILD(ast, node) node ? ast_new_internal(ast, node) : Qnil
252rb_ary_new_from_node_args(
rb_ast_t *
ast,
long n, ...)
261 for (i=0; i<n; i++) {
276 }
while (
node->nd_next &&
304 if (!
id)
return Qnil;
313 CONST_ID(rest,
"NODE_SPECIAL_NO_NAME_REST");
333 return rb_ary_new_from_node_args(
ast, 3,
node->nd_cond,
node->nd_body,
node->nd_else);
335 return rb_ary_new_from_node_args(
ast, 3,
node->nd_cond,
node->nd_body,
node->nd_else);
337 return rb_ary_new_from_node_args(
ast, 2,
node->nd_head,
node->nd_body);
339 return rb_ary_new_from_node_args(
ast, 2,
node->nd_head,
node->nd_body);
341 return rb_ary_new_from_node_args(
ast, 2,
node->nd_head,
node->nd_body);
343 return rb_ary_new_from_node_args(
ast, 3,
node->nd_head,
node->nd_body,
node->nd_next);
345 return rb_ary_new_from_node_args(
ast, 3,
node->nd_head,
node->nd_body,
node->nd_next);
352 return rb_ary_new_from_node_args(
ast, 2,
node->nd_iter,
node->nd_body);
354 return rb_ary_new_from_node_args(
ast, 1,
node->nd_var);
358 return rb_ary_new_from_node_args(
ast, 1,
node->nd_stts);
360 return rb_ary_new_from_node_args(
ast, 0);
362 return rb_ary_new_from_node_args(
ast, 0);
364 return rb_ary_new_from_node_args(
ast, 1,
node->nd_body);
366 return rb_ary_new_from_node_args(
ast, 3,
node->nd_head,
node->nd_resq,
node->nd_else);
368 return rb_ary_new_from_node_args(
ast, 3,
node->nd_args,
node->nd_body,
node->nd_head);
370 return rb_ary_new_from_node_args(
ast, 2,
node->nd_head,
node->nd_ensr);
387 return rb_ary_new_from_node_args(
ast, 3,
node->nd_value,
node->nd_head,
node->nd_args);
442 return rb_ary_new_from_node_args(
ast, 1,
node->nd_args);
444 return rb_ary_new_from_node_args(
ast, 0);
449 return rb_ary_new_from_node_args(
ast, 0);
451 return rb_ary_new_from_node_args(
ast, 1,
node->nd_head);
453 return rb_ary_new_from_node_args(
ast, 1,
node->nd_head);
472 return rb_ary_new_from_node_args(
ast, 3,
node->nd_recv,
node->nd_value,
node->nd_args);
474 return rb_ary_new_from_node_args(
ast, 2,
node->nd_recv,
node->nd_value);
476 return rb_ary_new_from_node_args(
ast, 2,
node->nd_recv,
node->nd_value);
483 return rb_ary_new_from_node_args(
ast, 1,
node->nd_body);
498 return rb_ary_new_from_node_args(
ast, 1,
node->nd_body);
500 return rb_ary_new_from_node_args(
ast, 2,
node->nd_head,
node->nd_body);
502 return rb_ary_new_from_node_args(
ast, 2,
node->nd_head,
node->nd_body);
504 return rb_ary_new_from_node_args(
ast, 1,
node->nd_head);
506 return rb_ary_new_from_node_args(
ast, 2,
node->nd_head,
node->nd_body);
512 return rb_ary_new_from_node_args(
ast, 2,
node->nd_1st,
node->nd_2nd);
516 return rb_ary_new_from_node_args(
ast, 1,
node->nd_undef);
518 return rb_ary_new_from_node_args(
ast, 3,
node->nd_cpath,
node->nd_super,
node->nd_body);
520 return rb_ary_new_from_node_args(
ast, 2,
node->nd_cpath,
node->nd_body);
522 return rb_ary_new_from_node_args(
ast, 2,
node->nd_recv,
node->nd_body);
531 return rb_ary_new_from_node_args(
ast, 2,
node->nd_beg,
node->nd_end);
533 return rb_ary_new_from_node_args(
ast, 0);
535 return rb_ary_new_from_node_args(
ast, 0);
537 return rb_ary_new_from_node_args(
ast, 0);
539 return rb_ary_new_from_node_args(
ast, 0);
541 return rb_ary_new_from_node_args(
ast, 0);
543 return rb_ary_new_from_node_args(
ast, 1,
node->nd_head);
545 return rb_ary_new_from_node_args(
ast, 1,
node->nd_body);
549 return rb_ary_new_from_node_args(
ast, 1,
node->nd_body);
551 return rb_ary_new_from_node_args(
ast, 2,
node->nd_body,
node->nd_next);
553 return rb_ary_new_from_node_args(
ast, 2,
node->nd_body,
node->nd_next);
556 return rb_ary_new_from_node_args(
ast, 2,
node->nd_1st,
node->nd_2nd);
579 ID *tbl = node->nd_tbl;
580 int i,
size = tbl ? (
int)*tbl++ : 0;
582 for (i = 0; i <
size; i++) {
632 return node_children(data->
ast, data->
node);
684 node_type_to_str(data->
node),
VALUE rb_ary_push(VALUE ary, VALUE item)
VALUE rb_ary_new_capa(long capa)
VALUE rb_check_array_type(VALUE ary)
VALUE rb_ary_entry(VALUE ary, long offset)
#define NEW_CHILD(ast, node)
rb_encoding * rb_utf8_encoding(void)
rb_encoding * rb_enc_get(VALUE obj)
VALUE rb_enc_from_encoding(rb_encoding *encoding)
char str[HTML_ESCAPE_MAX_LEN+1]
#define RSTRING_LEN(string)
#define RSTRING_PTR(string)
void rb_gc_mark(VALUE ptr)
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
VALUE rb_define_module_under(VALUE outer, const char *name)
void rb_raise(VALUE exc, const char *fmt,...)
void rb_exc_raise(VALUE mesg)
Raises an exception in the current thread.
void rb_bug(const char *fmt,...)
VALUE rb_cObject
Object class.
VALUE rb_obj_class(VALUE)
VALUE rb_hash_lookup(VALUE hash, VALUE key)
#define rb_enc_asciicompat(enc)
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
Defines RBIMPL_HAS_BUILTIN.
VALUE rb_file_open_str(VALUE, const char *)
VALUE rb_obj_is_proc(VALUE)
#define rb_strlen_lit(str)
VALUE rb_str_append(VALUE, VALUE)
#define rb_str_new_cstr(str)
int rb_const_defined_at(VALUE, ID)
VALUE rb_class_path(VALUE)
VALUE rb_const_get_at(VALUE, ID)
void rb_undef_alloc_func(VALUE)
ID rb_intern(const char *)
#define DECIMAL_SIZE_OF_BITS(n)
Internal header for the parser.
#define rb_ary_new_from_args(...)
#define rb_sym_intern_ascii_cstr(...)
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
VALUE rb_iseq_path(const rb_iseq_t *iseq)
const char * ruby_node_name(int node)
const rb_iseq_t * rb_method_iseq(VALUE body)
int memcmp(const void *s1, const void *s2, size_t len)
VALUE type(ANYARGS)
ANYARGS-ed function type.
void rb_ast_dispose(rb_ast_t *ast)
size_t rb_ast_memsize(const rb_ast_t *ast)
#define nd_last_lineno(n)
#define nd_first_lineno(n)
#define nd_first_column(n)
#define NODE_NAMED_REST_P(node)
#define NODE_SPECIAL_NO_REST_KEYWORD
#define nd_last_column(n)
#define NODE_REQUIRED_KEYWORD_P(node)
#define NODE_SPECIAL_EXCESSIVE_COMMA
#define RARRAY_AREF(a, i)
VALUE rb_parser_new(void)
rb_ast_t * rb_parser_compile_string_path(VALUE vparser, VALUE f, VALUE s, int line)
VALUE rb_parser_set_context(VALUE vparser, const struct rb_iseq_struct *base, int main)
rb_ast_t * rb_parser_compile_generic(VALUE vparser, VALUE(*lex_gets)(VALUE, int), VALUE fname, VALUE input, int start)
rb_ast_t * rb_parser_compile_file_path(VALUE vparser, VALUE fname, VALUE file, int start)
#define RUBY_TYPED_DEFAULT_FREE
#define TypedData_Get_Struct(obj, type, data_type, sval)
@ RUBY_TYPED_FREE_IMMEDIATELY
#define TypedData_Make_Struct(klass, type, data_type, sval)
VALUE rb_str_catf(VALUE, const char *,...)
rb_iseq_location_t location
struct rb_iseq_constant_body * body
Internal header to suppres / mandate warnings.