mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
*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:
parent
2a12798d58
commit
6ab36c6e19
6 changed files with 34 additions and 21 deletions
4
parse.y
4
parse.y
|
@ -8888,7 +8888,7 @@ dvar_curr_gen(struct parser_params *parser, ID id)
|
||||||
vtable_included(lvtbl->vars, 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);
|
VALUE rb_reg_check_preprocess(VALUE);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -9030,7 +9030,7 @@ reg_compile_gen(struct parser_params* parser, VALUE str, int options)
|
||||||
|
|
||||||
reg_fragment_setenc(str, options);
|
reg_fragment_setenc(str, options);
|
||||||
err = rb_errinfo();
|
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)) {
|
if (NIL_P(re)) {
|
||||||
ID mesg = rb_intern("mesg");
|
ID mesg = rb_intern("mesg");
|
||||||
VALUE m = rb_attr_get(rb_errinfo(), 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) {
|
if (r == 0) {
|
||||||
++ptr;
|
++ptr;
|
||||||
len -= 2;
|
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);
|
onig_free(rp);
|
||||||
}
|
}
|
||||||
|
@ -731,7 +731,8 @@ rb_reg_named_captures(VALUE re)
|
||||||
}
|
}
|
||||||
|
|
||||||
static Regexp*
|
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;
|
Regexp *rp;
|
||||||
int r;
|
int r;
|
||||||
|
@ -751,7 +752,7 @@ make_regexp(const char *s, long len, rb_encoding *enc, int flags, onig_errmsg_bu
|
||||||
return 0;
|
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) {
|
if (r != 0) {
|
||||||
onig_free(rp);
|
onig_free(rp);
|
||||||
|
@ -2323,7 +2324,8 @@ rb_reg_preprocess_dregexp(VALUE ary, int options)
|
||||||
|
|
||||||
static int
|
static int
|
||||||
rb_reg_initialize(VALUE obj, const char *s, long len, rb_encoding *enc,
|
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);
|
struct RRegexp *re = RREGEXP(obj);
|
||||||
VALUE unescaped;
|
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,
|
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;
|
if (!re->ptr) return -1;
|
||||||
re->src = rb_enc_str_new(s, len, enc);
|
re->src = rb_enc_str_new(s, len, enc);
|
||||||
OBJ_FREEZE(re->src);
|
OBJ_FREEZE(re->src);
|
||||||
|
@ -2381,7 +2384,8 @@ rb_reg_initialize(VALUE obj, const char *s, long len, rb_encoding *enc,
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
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;
|
int ret;
|
||||||
rb_encoding *enc = rb_enc_get(str);
|
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,
|
ret = rb_reg_initialize(obj, RSTRING_PTR(str), RSTRING_LEN(str), enc,
|
||||||
options, err);
|
options, err, sourcefile, sourceline);
|
||||||
RB_GC_GUARD(str);
|
RB_GC_GUARD(str);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -2420,7 +2424,7 @@ rb_reg_new_str(VALUE s, int options)
|
||||||
VALUE re = rb_reg_s_alloc(rb_cRegexp);
|
VALUE re = rb_reg_s_alloc(rb_cRegexp);
|
||||||
onig_errmsg_buffer err = "";
|
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);
|
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);
|
VALUE re = rb_reg_s_alloc(rb_cRegexp);
|
||||||
onig_errmsg_buffer err = "";
|
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);
|
rb_enc_reg_raise(s, len, enc, options, err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2453,13 +2457,13 @@ rb_reg_new(const char *s, long len, int options)
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
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);
|
VALUE re = rb_reg_s_alloc(rb_cRegexp);
|
||||||
onig_errmsg_buffer err = "";
|
onig_errmsg_buffer err = "";
|
||||||
|
|
||||||
if (!str) str = rb_str_new(0,0);
|
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));
|
rb_set_errinfo(rb_reg_error_desc(str, options, err));
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
@ -2809,7 +2813,7 @@ rb_reg_initialize_m(int argc, VALUE *argv, VALUE self)
|
||||||
ptr = RREGEXP_SRC_PTR(re);
|
ptr = RREGEXP_SRC_PTR(re);
|
||||||
len = RREGEXP_SRC_LEN(re);
|
len = RREGEXP_SRC_LEN(re);
|
||||||
enc = rb_enc_get(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);
|
str = rb_enc_str_new(ptr, len, enc);
|
||||||
rb_reg_raise_str(str, flags, err);
|
rb_reg_raise_str(str, flags, err);
|
||||||
}
|
}
|
||||||
|
@ -2833,8 +2837,8 @@ rb_reg_initialize_m(int argc, VALUE *argv, VALUE self)
|
||||||
str = argv[0];
|
str = argv[0];
|
||||||
ptr = StringValuePtr(str);
|
ptr = StringValuePtr(str);
|
||||||
if (enc
|
if (enc
|
||||||
? rb_reg_initialize(self, ptr, RSTRING_LEN(str), enc, flags, err)
|
? rb_reg_initialize(self, ptr, RSTRING_LEN(str), enc, flags, err, NULL, 0)
|
||||||
: rb_reg_initialize_str(self, str, flags, err)) {
|
: rb_reg_initialize_str(self, str, flags, err, NULL, 0)) {
|
||||||
rb_reg_raise_str(str, flags, err);
|
rb_reg_raise_str(str, flags, err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3159,7 +3163,8 @@ rb_reg_init_copy(VALUE copy, VALUE re)
|
||||||
rb_reg_check(re);
|
rb_reg_check(re);
|
||||||
s = RREGEXP_SRC_PTR(re);
|
s = RREGEXP_SRC_PTR(re);
|
||||||
len = RREGEXP_SRC_LEN(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);
|
rb_reg_raise(s, len, err, re);
|
||||||
}
|
}
|
||||||
return copy;
|
return copy;
|
||||||
|
|
|
@ -5351,7 +5351,7 @@ static void print_tree P_((FILE* f, Node* node));
|
||||||
|
|
||||||
extern int
|
extern int
|
||||||
onig_compile(regex_t* reg, const UChar* pattern, const UChar* pattern_end,
|
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
|
#define COMPILE_INIT_SIZE 20
|
||||||
|
|
||||||
|
@ -5362,6 +5362,8 @@ onig_compile(regex_t* reg, const UChar* pattern, const UChar* pattern_end,
|
||||||
UnsetAddrList uslist;
|
UnsetAddrList uslist;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
scan_env.sourcefile = sourcefile;
|
||||||
|
scan_env.sourceline = sourceline;
|
||||||
reg->state = ONIG_STATE_COMPILING;
|
reg->state = ONIG_STATE_COMPILING;
|
||||||
|
|
||||||
#ifdef ONIG_DEBUG
|
#ifdef ONIG_DEBUG
|
||||||
|
@ -5616,7 +5618,7 @@ onig_new(regex_t** reg, const UChar* pattern, const UChar* pattern_end,
|
||||||
enc, syntax);
|
enc, syntax);
|
||||||
if (r) return r;
|
if (r) return r;
|
||||||
|
|
||||||
r = onig_compile(*reg, pattern, pattern_end, einfo);
|
r = onig_compile(*reg, pattern, pattern_end, einfo, NULL, 0);
|
||||||
if (r) {
|
if (r) {
|
||||||
onig_free(*reg);
|
onig_free(*reg);
|
||||||
*reg = NULL;
|
*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 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_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_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_reduce P_((regex_t* reg));
|
||||||
extern void onig_chain_link_add P_((regex_t* to, regex_t* add));
|
extern void onig_chain_link_add P_((regex_t* to, regex_t* add));
|
||||||
extern void onig_transfer P_((regex_t* to, regex_t* from));
|
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,
|
onig_snprintf_with_pattern(buf, WARN_BUFSIZE, env->enc,
|
||||||
env->pattern, env->pattern_end,
|
env->pattern, env->pattern_end,
|
||||||
(UChar* )"character class has duplicated range");
|
(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;
|
int has_recursion;
|
||||||
#endif
|
#endif
|
||||||
int warnings_flag;
|
int warnings_flag;
|
||||||
|
const char* sourcefile;
|
||||||
|
int sourceline;
|
||||||
} ScanEnv;
|
} ScanEnv;
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue