Parser and universal parser share wrapper functions
This commit is contained in:
parent
125e1ed5f7
commit
d07df8567e
@ -16208,6 +16208,7 @@ ruby_parser.$(OBJEXT): $(top_srcdir)/internal/error.h
|
|||||||
ruby_parser.$(OBJEXT): $(top_srcdir)/internal/fixnum.h
|
ruby_parser.$(OBJEXT): $(top_srcdir)/internal/fixnum.h
|
||||||
ruby_parser.$(OBJEXT): $(top_srcdir)/internal/imemo.h
|
ruby_parser.$(OBJEXT): $(top_srcdir)/internal/imemo.h
|
||||||
ruby_parser.$(OBJEXT): $(top_srcdir)/internal/numeric.h
|
ruby_parser.$(OBJEXT): $(top_srcdir)/internal/numeric.h
|
||||||
|
ruby_parser.$(OBJEXT): $(top_srcdir)/internal/parse.h
|
||||||
ruby_parser.$(OBJEXT): $(top_srcdir)/internal/rational.h
|
ruby_parser.$(OBJEXT): $(top_srcdir)/internal/rational.h
|
||||||
ruby_parser.$(OBJEXT): $(top_srcdir)/internal/re.h
|
ruby_parser.$(OBJEXT): $(top_srcdir)/internal/re.h
|
||||||
ruby_parser.$(OBJEXT): $(top_srcdir)/internal/ruby_parser.h
|
ruby_parser.$(OBJEXT): $(top_srcdir)/internal/ruby_parser.h
|
||||||
|
@ -73,6 +73,11 @@ int rb_parser_local_defined(struct parser_params *p, ID id, const struct rb_iseq
|
|||||||
|
|
||||||
RUBY_SYMBOL_EXPORT_END
|
RUBY_SYMBOL_EXPORT_END
|
||||||
|
|
||||||
|
#ifndef UNIVERSAL_PARSER
|
||||||
|
rb_parser_t *rb_ruby_parser_allocate(void);
|
||||||
|
rb_parser_t *rb_ruby_parser_new(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef RIPPER
|
#ifdef RIPPER
|
||||||
void ripper_parser_mark(void *ptr);
|
void ripper_parser_mark(void *ptr);
|
||||||
void ripper_parser_free(void *ptr);
|
void ripper_parser_free(void *ptr);
|
||||||
|
173
parse.y
173
parse.y
@ -15956,20 +15956,6 @@ rb_ruby_parser_memsize(const void *ptr)
|
|||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef UNIVERSAL_PARSER
|
|
||||||
#ifndef RIPPER
|
|
||||||
static const rb_data_type_t parser_data_type = {
|
|
||||||
"parser",
|
|
||||||
{
|
|
||||||
rb_ruby_parser_mark,
|
|
||||||
rb_ruby_parser_free,
|
|
||||||
rb_ruby_parser_memsize,
|
|
||||||
},
|
|
||||||
0, 0, RUBY_TYPED_FREE_IMMEDIATELY
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef RIPPER
|
#ifndef RIPPER
|
||||||
#undef rb_reserved_word
|
#undef rb_reserved_word
|
||||||
|
|
||||||
@ -15997,6 +15983,23 @@ rb_ruby_parser_new(const rb_parser_config_t *config)
|
|||||||
parser_initialize(p);
|
parser_initialize(p);
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
rb_parser_t *
|
||||||
|
rb_ruby_parser_allocate(void)
|
||||||
|
{
|
||||||
|
/* parser_initialize expects fields to be set to 0 */
|
||||||
|
rb_parser_t *p = (rb_parser_t *)ruby_xcalloc(1, sizeof(rb_parser_t));
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
rb_parser_t *
|
||||||
|
rb_ruby_parser_new(void)
|
||||||
|
{
|
||||||
|
/* parser_initialize expects fields to be set to 0 */
|
||||||
|
rb_parser_t *p = rb_ruby_parser_allocate();
|
||||||
|
parser_initialize(p);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
rb_parser_t *
|
rb_parser_t *
|
||||||
@ -16026,148 +16029,6 @@ rb_ruby_parser_keep_tokens(rb_parser_t *p)
|
|||||||
p->tokens = rb_parser_ary_new_capa_for_ast_token(p, 10);
|
p->tokens = rb_parser_ary_new_capa_for_ast_token(p, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef UNIVERSAL_PARSER
|
|
||||||
rb_ast_t*
|
|
||||||
rb_parser_compile_file_path(VALUE vparser, VALUE fname, VALUE file, int start)
|
|
||||||
{
|
|
||||||
struct parser_params *p;
|
|
||||||
|
|
||||||
TypedData_Get_Struct(vparser, struct parser_params, &parser_data_type, p);
|
|
||||||
RB_GC_GUARD(vparser); /* prohibit tail call optimization */
|
|
||||||
return rb_ruby_parser_compile_file_path(p, fname, file, start);
|
|
||||||
}
|
|
||||||
|
|
||||||
rb_ast_t*
|
|
||||||
rb_parser_compile_generic(VALUE vparser, VALUE (*lex_gets)(VALUE, int), VALUE fname, VALUE input, int start)
|
|
||||||
{
|
|
||||||
struct parser_params *p;
|
|
||||||
|
|
||||||
TypedData_Get_Struct(vparser, struct parser_params, &parser_data_type, p);
|
|
||||||
RB_GC_GUARD(vparser); /* prohibit tail call optimization */
|
|
||||||
return rb_ruby_parser_compile_generic(p, lex_gets, fname, input, start);
|
|
||||||
}
|
|
||||||
|
|
||||||
rb_ast_t*
|
|
||||||
rb_parser_compile_string(VALUE vparser, const char *f, VALUE s, int line)
|
|
||||||
{
|
|
||||||
struct parser_params *p;
|
|
||||||
|
|
||||||
TypedData_Get_Struct(vparser, struct parser_params, &parser_data_type, p);
|
|
||||||
RB_GC_GUARD(vparser); /* prohibit tail call optimization */
|
|
||||||
return rb_ruby_parser_compile_string(p, f, s, line);
|
|
||||||
}
|
|
||||||
|
|
||||||
rb_ast_t*
|
|
||||||
rb_parser_compile_string_path(VALUE vparser, VALUE f, VALUE s, int line)
|
|
||||||
{
|
|
||||||
struct parser_params *p;
|
|
||||||
|
|
||||||
TypedData_Get_Struct(vparser, struct parser_params, &parser_data_type, p);
|
|
||||||
RB_GC_GUARD(vparser); /* prohibit tail call optimization */
|
|
||||||
return rb_ruby_parser_compile_string_path(p, f, s, line);
|
|
||||||
}
|
|
||||||
|
|
||||||
VALUE
|
|
||||||
rb_parser_encoding(VALUE vparser)
|
|
||||||
{
|
|
||||||
struct parser_params *p;
|
|
||||||
|
|
||||||
TypedData_Get_Struct(vparser, struct parser_params, &parser_data_type, p);
|
|
||||||
return rb_ruby_parser_encoding(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
VALUE
|
|
||||||
rb_parser_end_seen_p(VALUE vparser)
|
|
||||||
{
|
|
||||||
struct parser_params *p;
|
|
||||||
|
|
||||||
TypedData_Get_Struct(vparser, struct parser_params, &parser_data_type, p);
|
|
||||||
return RBOOL(rb_ruby_parser_end_seen_p(p));
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
rb_parser_error_tolerant(VALUE vparser)
|
|
||||||
{
|
|
||||||
struct parser_params *p;
|
|
||||||
|
|
||||||
TypedData_Get_Struct(vparser, struct parser_params, &parser_data_type, p);
|
|
||||||
rb_ruby_parser_error_tolerant(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
rb_parser_set_script_lines(VALUE vparser)
|
|
||||||
{
|
|
||||||
struct parser_params *p;
|
|
||||||
|
|
||||||
TypedData_Get_Struct(vparser, struct parser_params, &parser_data_type, p);
|
|
||||||
rb_ruby_parser_set_script_lines(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
rb_parser_keep_tokens(VALUE vparser)
|
|
||||||
{
|
|
||||||
struct parser_params *p;
|
|
||||||
|
|
||||||
TypedData_Get_Struct(vparser, struct parser_params, &parser_data_type, p);
|
|
||||||
rb_ruby_parser_keep_tokens(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
VALUE
|
|
||||||
rb_parser_new(void)
|
|
||||||
{
|
|
||||||
struct parser_params *p;
|
|
||||||
VALUE parser = TypedData_Make_Struct(0, struct parser_params,
|
|
||||||
&parser_data_type, p);
|
|
||||||
parser_initialize(p);
|
|
||||||
return parser;
|
|
||||||
}
|
|
||||||
|
|
||||||
VALUE
|
|
||||||
rb_parser_set_context(VALUE vparser, const struct rb_iseq_struct *base, int main)
|
|
||||||
{
|
|
||||||
struct parser_params *p;
|
|
||||||
|
|
||||||
TypedData_Get_Struct(vparser, struct parser_params, &parser_data_type, p);
|
|
||||||
rb_ruby_parser_set_context(p, base, main);
|
|
||||||
return vparser;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
rb_parser_set_options(VALUE vparser, int print, int loop, int chomp, int split)
|
|
||||||
{
|
|
||||||
struct parser_params *p;
|
|
||||||
|
|
||||||
TypedData_Get_Struct(vparser, struct parser_params, &parser_data_type, p);
|
|
||||||
rb_ruby_parser_set_options(p, print, loop, chomp, split);
|
|
||||||
}
|
|
||||||
|
|
||||||
VALUE
|
|
||||||
rb_parser_set_yydebug(VALUE self, VALUE flag)
|
|
||||||
{
|
|
||||||
struct parser_params *p;
|
|
||||||
|
|
||||||
TypedData_Get_Struct(self, struct parser_params, &parser_data_type, p);
|
|
||||||
rb_ruby_parser_set_yydebug(p, RTEST(flag));
|
|
||||||
return flag;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
rb_set_script_lines_for(VALUE self, VALUE path)
|
|
||||||
{
|
|
||||||
struct parser_params *p;
|
|
||||||
VALUE hash;
|
|
||||||
ID script_lines;
|
|
||||||
CONST_ID(script_lines, "SCRIPT_LINES__");
|
|
||||||
if (!rb_const_defined_at(rb_cObject, script_lines)) return;
|
|
||||||
hash = rb_const_get_at(rb_cObject, script_lines);
|
|
||||||
if (RB_TYPE_P(hash, T_HASH)) {
|
|
||||||
rb_hash_aset(hash, path, Qtrue);
|
|
||||||
TypedData_Get_Struct(self, struct parser_params, &parser_data_type, p);
|
|
||||||
rb_ruby_parser_set_script_lines(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif /* !UNIVERSAL_PARSER */
|
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_ruby_parser_encoding(rb_parser_t *p)
|
rb_ruby_parser_encoding(rb_parser_t *p)
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
/* This is a wrapper for parse.y */
|
/* This is a wrapper for parse.y */
|
||||||
|
|
||||||
|
#include "internal/parse.h"
|
||||||
#include "internal/re.h"
|
#include "internal/re.h"
|
||||||
#include "internal/ruby_parser.h"
|
#include "internal/ruby_parser.h"
|
||||||
|
|
||||||
@ -18,7 +19,6 @@
|
|||||||
#include "internal/gc.h"
|
#include "internal/gc.h"
|
||||||
#include "internal/hash.h"
|
#include "internal/hash.h"
|
||||||
#include "internal/io.h"
|
#include "internal/io.h"
|
||||||
#include "internal/parse.h"
|
|
||||||
#include "internal/rational.h"
|
#include "internal/rational.h"
|
||||||
#include "internal/re.h"
|
#include "internal/re.h"
|
||||||
#include "internal/string.h"
|
#include "internal/string.h"
|
||||||
@ -32,41 +32,6 @@
|
|||||||
#include "vm_core.h"
|
#include "vm_core.h"
|
||||||
#include "symbol.h"
|
#include "symbol.h"
|
||||||
|
|
||||||
struct ruby_parser {
|
|
||||||
rb_parser_t *parser_params;
|
|
||||||
};
|
|
||||||
|
|
||||||
static void
|
|
||||||
parser_mark(void *ptr)
|
|
||||||
{
|
|
||||||
struct ruby_parser *parser = (struct ruby_parser*)ptr;
|
|
||||||
rb_ruby_parser_mark(parser->parser_params);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
parser_free(void *ptr)
|
|
||||||
{
|
|
||||||
struct ruby_parser *parser = (struct ruby_parser*)ptr;
|
|
||||||
rb_ruby_parser_free(parser->parser_params);
|
|
||||||
}
|
|
||||||
|
|
||||||
static size_t
|
|
||||||
parser_memsize(const void *ptr)
|
|
||||||
{
|
|
||||||
struct ruby_parser *parser = (struct ruby_parser*)ptr;
|
|
||||||
return rb_ruby_parser_memsize(parser->parser_params);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const rb_data_type_t ruby_parser_data_type = {
|
|
||||||
"parser",
|
|
||||||
{
|
|
||||||
parser_mark,
|
|
||||||
parser_free,
|
|
||||||
parser_memsize,
|
|
||||||
},
|
|
||||||
0, 0, RUBY_TYPED_FREE_IMMEDIATELY
|
|
||||||
};
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
is_ascii_string2(VALUE str)
|
is_ascii_string2(VALUE str)
|
||||||
{
|
{
|
||||||
@ -547,7 +512,44 @@ static const rb_parser_config_t rb_global_parser_config = {
|
|||||||
.static_id2sym = static_id2sym,
|
.static_id2sym = static_id2sym,
|
||||||
.str_coderange_scan_restartable = str_coderange_scan_restartable,
|
.str_coderange_scan_restartable = str_coderange_scan_restartable,
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct ruby_parser {
|
||||||
|
rb_parser_t *parser_params;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void
|
||||||
|
parser_mark(void *ptr)
|
||||||
|
{
|
||||||
|
struct ruby_parser *parser = (struct ruby_parser*)ptr;
|
||||||
|
rb_ruby_parser_mark(parser->parser_params);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
parser_free(void *ptr)
|
||||||
|
{
|
||||||
|
struct ruby_parser *parser = (struct ruby_parser*)ptr;
|
||||||
|
rb_ruby_parser_free(parser->parser_params);
|
||||||
|
}
|
||||||
|
|
||||||
|
static size_t
|
||||||
|
parser_memsize(const void *ptr)
|
||||||
|
{
|
||||||
|
struct ruby_parser *parser = (struct ruby_parser*)ptr;
|
||||||
|
return rb_ruby_parser_memsize(parser->parser_params);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const rb_data_type_t ruby_parser_data_type = {
|
||||||
|
"parser",
|
||||||
|
{
|
||||||
|
parser_mark,
|
||||||
|
parser_free,
|
||||||
|
parser_memsize,
|
||||||
|
},
|
||||||
|
0, 0, RUBY_TYPED_FREE_IMMEDIATELY
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef UNIVERSAL_PARSER
|
||||||
const rb_parser_config_t *
|
const rb_parser_config_t *
|
||||||
rb_ruby_parser_config(void)
|
rb_ruby_parser_config(void)
|
||||||
{
|
{
|
||||||
@ -565,6 +567,13 @@ rb_parser_params_new(void)
|
|||||||
{
|
{
|
||||||
return rb_ruby_parser_new(&rb_global_parser_config);
|
return rb_ruby_parser_new(&rb_global_parser_config);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
rb_parser_t *
|
||||||
|
rb_parser_params_new(void)
|
||||||
|
{
|
||||||
|
return rb_ruby_parser_new();
|
||||||
|
}
|
||||||
|
#endif /* UNIVERSAL_PARSER */
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_parser_new(void)
|
rb_parser_new(void)
|
||||||
@ -726,7 +735,6 @@ rb_set_script_lines_for(VALUE vparser, VALUE path)
|
|||||||
rb_ruby_parser_set_script_lines(parser->parser_params);
|
rb_ruby_parser_set_script_lines(parser->parser_params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_parser_build_script_lines_from(rb_parser_ary_t *lines)
|
rb_parser_build_script_lines_from(rb_parser_ary_t *lines)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user