Skip to content

Commit

Permalink
Remove "internal/error.h"
Browse files Browse the repository at this point in the history
  • Loading branch information
yui-knk committed Apr 13, 2023
1 parent afbbd1d commit fa52f3b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
6 changes: 6 additions & 0 deletions external/parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ typedef struct rb_parser_config_struct {
VALUE (*str_resize)(VALUE str, long len);
VALUE (*str_new)(const char *ptr, long len);
VALUE (*str_new_cstr)(const char *ptr);
VALUE (*fstring)(VALUE);
int (*is_ascii_string)(VALUE str);

/* Hash */
VALUE (*hash_clear)(VALUE hash);
Expand All @@ -64,6 +66,10 @@ typedef struct rb_parser_config_struct {
int (*stderr_tty_p)(void);
void (*write_error_str)(VALUE mesg);

/* Error */
const char *(*builtin_class_name)(VALUE x);
// VALUE rb_syntax_error_append(VALUE, VALUE, int, int, rb_encoding*, const char*, va_list);
VALUE (*syntax_error_append)(VALUE, VALUE, int, int, const void*, const char*, va_list);

} rb_parser_config_t;

Expand Down
12 changes: 9 additions & 3 deletions parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ struct lex_context;
#include "internal/compile.h"
#include "internal/compilers.h"
#include "internal/encoding.h"
#include "internal/error.h"
#include "internal/imemo.h"
#include "internal/re.h"
#include "internal/symbol.h"
Expand All @@ -60,6 +59,7 @@ struct lex_context;

#ifdef RIPPER
#include "internal/complex.h"
#include "internal/error.h"
#include "internal/numeric.h"
#include "internal/hash.h"
#include "internal/io.h"
Expand Down Expand Up @@ -125,6 +125,8 @@ RBIMPL_WARNING_POP()
#define rb_str_new p->config.str_new
#undef rb_str_new_cstr
#define rb_str_new_cstr p->config.str_new_cstr
#define rb_fstring p->config.fstring
#define is_ascii_string p->config.is_ascii_string

#define rb_hash_clear p->config.hash_clear
#define rb_hash_new p->config.hash_new
Expand All @@ -145,6 +147,10 @@ RBIMPL_WARNING_POP()
#define rb_stderr_tty_p p->config.stderr_tty_p
#define rb_write_error_str p->config.write_error_str

#define rb_builtin_class_name p->config.builtin_class_name
#define rb_syntax_error_append p->config.syntax_error_append


#endif

#define NO_LEX_CTXT (struct lex_context){0}
Expand Down Expand Up @@ -457,7 +463,7 @@ struct parser_params {
#define STR_NEW(ptr,len) rb_enc_str_new((ptr),(len),p->enc)
#define STR_NEW0() rb_enc_str_new(0,0,p->enc)
#define STR_NEW2(ptr) rb_enc_str_new((ptr),strlen(ptr),p->enc)
#define STR_NEW3(ptr,len,e,func) parser_str_new((ptr),(len),(e),(func),p->enc)
#define STR_NEW3(ptr,len,e,func) parser_str_new(p, (ptr),(len),(e),(func),p->enc)
#define TOK_INTERN() intern_cstr(tok(p), toklen(p), p->enc)

static st_table *
Expand Down Expand Up @@ -7017,7 +7023,7 @@ enum string_type {
};

static VALUE
parser_str_new(const char *ptr, long len, rb_encoding *enc, int func, rb_encoding *enc0)
parser_str_new(struct parser_params *p, const char *ptr, long len, rb_encoding *enc, int func, rb_encoding *enc0)
{
VALUE str;

Expand Down
21 changes: 21 additions & 0 deletions ruby_parser.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
/* This is a wrapper for parse.y */

#include "internal.h"
#include "internal/array.h"
#include "internal/bignum.h"
#include "internal/complex.h"
#include "internal/error.h"
#include "internal/hash.h"
#include "internal/io.h"
#include "internal/parse.h"
#include "internal/rational.h"
#include "internal/ruby_parser.h"
#include "internal/string.h"

#include "ruby/ruby.h"
#include "node.h"
Expand Down Expand Up @@ -55,6 +58,12 @@ bignum_negate(VALUE b)
BIGNUM_NEGATE(b);
}

static int
is_ascii_string2(VALUE str)
{
return is_ascii_string(str);
}

static void
rational_set_num(VALUE r, VALUE n)
{
Expand Down Expand Up @@ -91,6 +100,13 @@ rcomplex_get_imag(VALUE obj)
return RCOMPLEX(obj)->imag;
}

static VALUE
syntax_error_append(VALUE exc, VALUE file, int line, int column,
const void *enc, const char *fmt, va_list args)
{
return rb_syntax_error_append(exc, file, line, column, (rb_encoding *)enc, fmt, args);
}

void
rb_parser_config_initialize(rb_parser_config_t *config)
{
Expand Down Expand Up @@ -123,6 +139,8 @@ rb_parser_config_initialize(rb_parser_config_t *config)
config->str_resize = rb_str_resize;
config->str_new = rb_str_new;
config->str_new_cstr = rb_str_new_cstr;
config->fstring = rb_fstring;
config->is_ascii_string = is_ascii_string2;

config->hash_clear = rb_hash_clear;
config->hash_new = rb_hash_new;
Expand All @@ -142,6 +160,9 @@ rb_parser_config_initialize(rb_parser_config_t *config)

config->stderr_tty_p = rb_stderr_tty_p;
config->write_error_str = rb_write_error_str;

config->builtin_class_name = rb_builtin_class_name;
config->syntax_error_append = syntax_error_append;
}

VALUE
Expand Down

0 comments on commit fa52f3b

Please sign in to comment.