зеркало из https://github.com/github/ruby.git
*regparse.c (CC_DUP_WARN): use rb_compile_warn if ScanEnv has source
information. [ruby-dev:39105] *re.c (rb_reg_compile): add sourcefile and sourceline to the arguments. *re.c (make_regexp): ditto. *re.c (rb_reg_initialize): ditto. *re.c (rb_reg_initialize_str): ditto. *re.c (rb_reg_compile): ditto. *regcomp.c (onig_compile): ditto. *regint.h (onig_compile): ditto. *re.c (reg_compile_gen): follow above. *re.c (rb_reg_to_s): ditto. *re.c (make_regexp): ditto. *re.c (rb_reg_initialize): ditto. *re.c (rb_reg_initialize_str): ditto. *re.c (rb_reg_new_str): ditto. *re.c (rb_enc_reg_new): ditto. *re.c (rb_reg_initialize_m): ditto. *re.c (rb_reg_init_copy): ditto. *regcomp.c (onig_new): ditto. *regcomp.c (onig_compile): set sourcefile and sourceline to scan_env. *regparse.h (ScanEnv): add sourcefile and sourceline. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24716 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
2a12798d58
Коммит
6ab36c6e19
4
parse.y
4
parse.y
|
@ -8888,7 +8888,7 @@ dvar_curr_gen(struct parser_params *parser, ID id)
|
|||
vtable_included(lvtbl->vars, id));
|
||||
}
|
||||
|
||||
VALUE rb_reg_compile(VALUE str, int options);
|
||||
VALUE rb_reg_compile(VALUE str, int options, const char *sourcefile, int sourceline);
|
||||
VALUE rb_reg_check_preprocess(VALUE);
|
||||
|
||||
static void
|
||||
|
@ -9030,7 +9030,7 @@ reg_compile_gen(struct parser_params* parser, VALUE str, int options)
|
|||
|
||||
reg_fragment_setenc(str, options);
|
||||
err = rb_errinfo();
|
||||
re = rb_reg_compile(str, options & RE_OPTION_MASK);
|
||||
re = rb_reg_compile(str, options & RE_OPTION_MASK, ruby_sourcefile, ruby_sourceline);
|
||||
if (NIL_P(re)) {
|
||||
ID mesg = rb_intern("mesg");
|
||||
VALUE m = rb_attr_get(rb_errinfo(), mesg);
|
||||
|
|
35
re.c
35
re.c
|
@ -528,7 +528,7 @@ rb_reg_to_s(VALUE re)
|
|||
if (r == 0) {
|
||||
++ptr;
|
||||
len -= 2;
|
||||
err = (onig_compile(rp, ptr, ptr + len, NULL) != 0);
|
||||
err = (onig_compile(rp, ptr, ptr + len, NULL, NULL, 0) != 0);
|
||||
}
|
||||
onig_free(rp);
|
||||
}
|
||||
|
@ -731,7 +731,8 @@ rb_reg_named_captures(VALUE re)
|
|||
}
|
||||
|
||||
static Regexp*
|
||||
make_regexp(const char *s, long len, rb_encoding *enc, int flags, onig_errmsg_buffer err)
|
||||
make_regexp(const char *s, long len, rb_encoding *enc, int flags, onig_errmsg_buffer err,
|
||||
const char *sourcefile, int sourceline)
|
||||
{
|
||||
Regexp *rp;
|
||||
int r;
|
||||
|
@ -751,7 +752,7 @@ make_regexp(const char *s, long len, rb_encoding *enc, int flags, onig_errmsg_bu
|
|||
return 0;
|
||||
}
|
||||
|
||||
r = onig_compile(rp, (UChar*)s, (UChar*)(s + len), &einfo);
|
||||
r = onig_compile(rp, (UChar*)s, (UChar*)(s + len), &einfo, sourcefile, sourceline);
|
||||
|
||||
if (r != 0) {
|
||||
onig_free(rp);
|
||||
|
@ -2323,7 +2324,8 @@ rb_reg_preprocess_dregexp(VALUE ary, int options)
|
|||
|
||||
static int
|
||||
rb_reg_initialize(VALUE obj, const char *s, long len, rb_encoding *enc,
|
||||
int options, onig_errmsg_buffer err)
|
||||
int options, onig_errmsg_buffer err,
|
||||
const char *sourcefile, int sourceline)
|
||||
{
|
||||
struct RRegexp *re = RREGEXP(obj);
|
||||
VALUE unescaped;
|
||||
|
@ -2372,7 +2374,8 @@ rb_reg_initialize(VALUE obj, const char *s, long len, rb_encoding *enc,
|
|||
}
|
||||
|
||||
re->ptr = make_regexp(RSTRING_PTR(unescaped), RSTRING_LEN(unescaped), enc,
|
||||
options & ARG_REG_OPTION_MASK, err);
|
||||
options & ARG_REG_OPTION_MASK, err,
|
||||
sourcefile, sourceline);
|
||||
if (!re->ptr) return -1;
|
||||
re->src = rb_enc_str_new(s, len, enc);
|
||||
OBJ_FREEZE(re->src);
|
||||
|
@ -2381,7 +2384,8 @@ rb_reg_initialize(VALUE obj, const char *s, long len, rb_encoding *enc,
|
|||
}
|
||||
|
||||
static int
|
||||
rb_reg_initialize_str(VALUE obj, VALUE str, int options, onig_errmsg_buffer err)
|
||||
rb_reg_initialize_str(VALUE obj, VALUE str, int options, onig_errmsg_buffer err,
|
||||
const char *sourcefile, int sourceline)
|
||||
{
|
||||
int ret;
|
||||
rb_encoding *enc = rb_enc_get(str);
|
||||
|
@ -2396,7 +2400,7 @@ rb_reg_initialize_str(VALUE obj, VALUE str, int options, onig_errmsg_buffer err)
|
|||
}
|
||||
}
|
||||
ret = rb_reg_initialize(obj, RSTRING_PTR(str), RSTRING_LEN(str), enc,
|
||||
options, err);
|
||||
options, err, sourcefile, sourceline);
|
||||
RB_GC_GUARD(str);
|
||||
return ret;
|
||||
}
|
||||
|
@ -2420,7 +2424,7 @@ rb_reg_new_str(VALUE s, int options)
|
|||
VALUE re = rb_reg_s_alloc(rb_cRegexp);
|
||||
onig_errmsg_buffer err = "";
|
||||
|
||||
if (rb_reg_initialize_str(re, s, options, err) != 0) {
|
||||
if (rb_reg_initialize_str(re, s, options, err, NULL, 0) != 0) {
|
||||
rb_reg_raise_str(s, options, err);
|
||||
}
|
||||
|
||||
|
@ -2439,7 +2443,7 @@ rb_enc_reg_new(const char *s, long len, rb_encoding *enc, int options)
|
|||
VALUE re = rb_reg_s_alloc(rb_cRegexp);
|
||||
onig_errmsg_buffer err = "";
|
||||
|
||||
if (rb_reg_initialize(re, s, len, enc, options, err) != 0) {
|
||||
if (rb_reg_initialize(re, s, len, enc, options, err, NULL, 0) != 0) {
|
||||
rb_enc_reg_raise(s, len, enc, options, err);
|
||||
}
|
||||
|
||||
|
@ -2453,13 +2457,13 @@ rb_reg_new(const char *s, long len, int options)
|
|||
}
|
||||
|
||||
VALUE
|
||||
rb_reg_compile(VALUE str, int options)
|
||||
rb_reg_compile(VALUE str, int options, const char *sourcefile, int sourceline)
|
||||
{
|
||||
VALUE re = rb_reg_s_alloc(rb_cRegexp);
|
||||
onig_errmsg_buffer err = "";
|
||||
|
||||
if (!str) str = rb_str_new(0,0);
|
||||
if (rb_reg_initialize_str(re, str, options, err) != 0) {
|
||||
if (rb_reg_initialize_str(re, str, options, err, sourcefile, sourceline) != 0) {
|
||||
rb_set_errinfo(rb_reg_error_desc(str, options, err));
|
||||
return Qnil;
|
||||
}
|
||||
|
@ -2809,7 +2813,7 @@ rb_reg_initialize_m(int argc, VALUE *argv, VALUE self)
|
|||
ptr = RREGEXP_SRC_PTR(re);
|
||||
len = RREGEXP_SRC_LEN(re);
|
||||
enc = rb_enc_get(re);
|
||||
if (rb_reg_initialize(self, ptr, len, enc, flags, err)) {
|
||||
if (rb_reg_initialize(self, ptr, len, enc, flags, err, NULL, 0)) {
|
||||
str = rb_enc_str_new(ptr, len, enc);
|
||||
rb_reg_raise_str(str, flags, err);
|
||||
}
|
||||
|
@ -2833,8 +2837,8 @@ rb_reg_initialize_m(int argc, VALUE *argv, VALUE self)
|
|||
str = argv[0];
|
||||
ptr = StringValuePtr(str);
|
||||
if (enc
|
||||
? rb_reg_initialize(self, ptr, RSTRING_LEN(str), enc, flags, err)
|
||||
: rb_reg_initialize_str(self, str, flags, err)) {
|
||||
? rb_reg_initialize(self, ptr, RSTRING_LEN(str), enc, flags, err, NULL, 0)
|
||||
: rb_reg_initialize_str(self, str, flags, err, NULL, 0)) {
|
||||
rb_reg_raise_str(str, flags, err);
|
||||
}
|
||||
}
|
||||
|
@ -3159,7 +3163,8 @@ rb_reg_init_copy(VALUE copy, VALUE re)
|
|||
rb_reg_check(re);
|
||||
s = RREGEXP_SRC_PTR(re);
|
||||
len = RREGEXP_SRC_LEN(re);
|
||||
if (rb_reg_initialize(copy, s, len, rb_enc_get(re), rb_reg_options(re), err) != 0) {
|
||||
if (rb_reg_initialize(copy, s, len, rb_enc_get(re), rb_reg_options(re),
|
||||
err, NULL, 0) != 0) {
|
||||
rb_reg_raise(s, len, err, re);
|
||||
}
|
||||
return copy;
|
||||
|
|
|
@ -5351,7 +5351,7 @@ static void print_tree P_((FILE* f, Node* node));
|
|||
|
||||
extern int
|
||||
onig_compile(regex_t* reg, const UChar* pattern, const UChar* pattern_end,
|
||||
OnigErrorInfo* einfo)
|
||||
OnigErrorInfo* einfo, const char *sourcefile, int sourceline)
|
||||
{
|
||||
#define COMPILE_INIT_SIZE 20
|
||||
|
||||
|
@ -5362,6 +5362,8 @@ onig_compile(regex_t* reg, const UChar* pattern, const UChar* pattern_end,
|
|||
UnsetAddrList uslist;
|
||||
#endif
|
||||
|
||||
scan_env.sourcefile = sourcefile;
|
||||
scan_env.sourceline = sourceline;
|
||||
reg->state = ONIG_STATE_COMPILING;
|
||||
|
||||
#ifdef ONIG_DEBUG
|
||||
|
@ -5616,7 +5618,7 @@ onig_new(regex_t** reg, const UChar* pattern, const UChar* pattern_end,
|
|||
enc, syntax);
|
||||
if (r) return r;
|
||||
|
||||
r = onig_compile(*reg, pattern, pattern_end, einfo);
|
||||
r = onig_compile(*reg, pattern, pattern_end, einfo, NULL, 0);
|
||||
if (r) {
|
||||
onig_free(*reg);
|
||||
*reg = NULL;
|
||||
|
|
2
regint.h
2
regint.h
|
@ -800,7 +800,7 @@ extern UChar* onig_error_code_to_format P_((int code));
|
|||
extern void onig_snprintf_with_pattern PV_((UChar buf[], int bufsize, OnigEncoding enc, UChar* pat, UChar* pat_end, const UChar *fmt, ...));
|
||||
extern int onig_bbuf_init P_((BBuf* buf, int size));
|
||||
extern int onig_alloc_init P_((regex_t** reg, OnigOptionType option, OnigCaseFoldType case_fold_flag, OnigEncoding enc, const OnigSyntaxType* syntax));
|
||||
extern int onig_compile P_((regex_t* reg, const UChar* pattern, const UChar* pattern_end, OnigErrorInfo* einfo));
|
||||
extern int onig_compile P_((regex_t* reg, const UChar* pattern, const UChar* pattern_end, OnigErrorInfo* einfo, const char *sourcefile, int sourceline));
|
||||
extern void onig_chain_reduce P_((regex_t* reg));
|
||||
extern void onig_chain_link_add P_((regex_t* to, regex_t* add));
|
||||
extern void onig_transfer P_((regex_t* to, regex_t* from));
|
||||
|
|
|
@ -2877,7 +2877,11 @@ CC_DUP_WARN(ScanEnv *env)
|
|||
onig_snprintf_with_pattern(buf, WARN_BUFSIZE, env->enc,
|
||||
env->pattern, env->pattern_end,
|
||||
(UChar* )"character class has duplicated range");
|
||||
(*onig_warn)((char* )buf);
|
||||
|
||||
if (env->sourcefile == NULL)
|
||||
(*onig_warn)((char* )buf);
|
||||
else
|
||||
rb_compile_warn(env->sourcefile, env->sourceline, (char* )buf);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -307,6 +307,8 @@ typedef struct {
|
|||
int has_recursion;
|
||||
#endif
|
||||
int warnings_flag;
|
||||
const char* sourcefile;
|
||||
int sourceline;
|
||||
} ScanEnv;
|
||||
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче