1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* error.c, parse.y, ruby.h (rb_compile_warn, rb_compile_warning): warn

for compilation.  the parser should no longer use rb_warn() and
  rb_warning().  [ruby-dev:30121]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12238 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2007-05-01 21:45:48 +00:00
parent f8c2658700
commit 50e6933b09
4 changed files with 104 additions and 36 deletions

View file

@ -1,3 +1,9 @@
Wed May 2 06:46:43 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* error.c, parse.y, ruby.h (rb_compile_warn, rb_compile_warning): warn
for compilation. the parser should no longer use rb_warn() and
rb_warning(). [ruby-dev:30121]
Wed May 2 05:45:21 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* parse.y (assoc): result of assoc_new needs to be an assoc.

85
error.c
View file

@ -30,20 +30,32 @@ const char *rb_sourcefile(void);
int rb_sourceline(void);
static int
err_position(char *buf, long len)
err_position_0(char *buf, long len, const char *file, long line)
{
ruby_set_current_source();
if (!rb_sourcefile()) {
if (!file) {
return 0;
}
else if (rb_sourceline() == 0) {
return snprintf(buf, len, "%s: ", rb_sourcefile());
else if (line == 0) {
return snprintf(buf, len, "%s: ", file);
}
else {
return snprintf(buf, len, "%s:%d: ", rb_sourcefile(), rb_sourceline());
return snprintf(buf, len, "%s:%d: ", file, line);
}
}
static int
err_position(char *buf, long len)
{
return err_position_0(buf, len, rb_sourcefile(), rb_sourceline());
}
static int
compile_position(char *buf, long len)
{
ruby_set_current_source();
return err_position_0(buf, len, ruby_sourcefile, ruby_sourceline);
}
static void
err_snprintf(char *buf, long len, const char *fmt, va_list args)
{
@ -55,23 +67,29 @@ err_snprintf(char *buf, long len, const char *fmt, va_list args)
}
}
static void err_append(const char*);
static void
err_print(const char *fmt, va_list args)
compile_snprintf(char *buf, long len, const char *fmt, va_list args)
{
char buf[BUFSIZ];
long n;
err_snprintf(buf, BUFSIZ, fmt, args);
err_append(buf);
n = compile_position(buf, len);
if (len > n) {
vsnprintf((char*)buf+n, len-n, fmt, args);
}
}
static void err_append(const char*);
void
rb_compile_error(const char *fmt, ...)
{
va_list args;
char buf[BUFSIZ];
va_start(args, fmt);
err_print(fmt, args);
compile_snprintf(buf, BUFSIZ, fmt, args);
va_end(args);
err_append(buf);
ruby_nerrs++;
}
@ -87,6 +105,49 @@ rb_compile_error_append(const char *fmt, ...)
err_append(buf);
}
static void
compile_warn_print(const char *fmt, va_list args)
{
char buf[BUFSIZ];
int len;
compile_snprintf(buf, BUFSIZ, fmt, args);
len = strlen(buf);
buf[len++] = '\n';
rb_write_error2(buf, len);
}
void
rb_compile_warn(const char *fmt, ...)
{
char buf[BUFSIZ];
va_list args;
if (NIL_P(ruby_verbose)) return;
snprintf(buf, BUFSIZ, "warning: %s", fmt);
va_start(args, fmt);
compile_warn_print(buf, args);
va_end(args);
}
/* rb_compile_warning() reports only in verbose mode */
void
rb_compile_warning(const char *fmt, ...)
{
char buf[BUFSIZ];
va_list args;
if (!RTEST(ruby_verbose)) return;
snprintf(buf, BUFSIZ, "warning: %s", fmt);
va_start(args, fmt);
compile_warn_print(buf, args);
va_end(args);
}
static void
warn_print(const char *fmt, va_list args)
{

20
parse.y
View file

@ -491,11 +491,11 @@ static VALUE ripper_id2sym(ID);
#endif
#ifndef RIPPER
# define rb_warn0(fmt) rb_warn(fmt)
# define rb_warnI(fmt,a) rb_warn(fmt,a)
# define rb_warnS(fmt,a) rb_warn(fmt,a)
# define rb_warning0(fmt) rb_warning(fmt)
# define rb_warningS(fmt,a) rb_warning(fmt,a)
# define rb_warn0(fmt) rb_compile_warn(fmt)
# define rb_warnI(fmt,a) rb_compile_warn(fmt,a)
# define rb_warnS(fmt,a) rb_compile_warn(fmt,a)
# define rb_warning0(fmt) rb_compile_warning(fmt)
# define rb_warningS(fmt,a) rb_compile_warning(fmt,a)
#else
# define rb_warn0(fmt) ripper_warn0(parser, fmt)
# define rb_warnI(fmt,a) ripper_warnI(parser, fmt, a)
@ -735,7 +735,7 @@ bodystmt : compstmt
$$ = NEW_RESCUE($1, $2, $3);
}
else if ($3) {
rb_warn("else without rescue is useless");
rb_warn0("else without rescue is useless");
$$ = block_append($$, $3);
}
if ($4) {
@ -2231,7 +2231,7 @@ opt_call_args : none
call_args : command
{
rb_warn("parenthesize argument(s) for future version");
rb_warn0("parenthesize argument(s) for future version");
/*%%%*/
$$ = NEW_LIST($1);
/*%
@ -6927,7 +6927,7 @@ parser_warn(NODE *node, const char *mesg)
{
int line = ruby_sourceline;
ruby_sourceline = nd_line(node);
rb_warn("%s", mesg);
rb_warnS("%s", mesg);
ruby_sourceline = line;
}
@ -7547,7 +7547,7 @@ void_expr_gen(struct parser_params *parser, NODE *node)
int line = ruby_sourceline;
ruby_sourceline = nd_line(node);
rb_warn("useless use of %s in void context", useless);
rb_warnS("useless use of %s in void context", useless);
ruby_sourceline = line;
}
}
@ -7742,7 +7742,7 @@ cond0(struct parser_params *parser, NODE *node)
case NODE_DSTR:
case NODE_EVSTR:
case NODE_STR:
rb_warn("string literal in condition");
rb_warn0("string literal in condition");
break;
case NODE_DREGX:

3
ruby.h
View file

@ -650,10 +650,11 @@ NORETURN(void rb_notimplement(void));
/* reports if `-w' specified */
PRINTF_ARGS(void rb_warning(const char*, ...), 1, 2);
/* reports if `-w' specified */
PRINTF_ARGS(void rb_compile_warning(const char*, ...), 1, 2);
PRINTF_ARGS(void rb_sys_warning(const char*, ...), 1, 2);
/* reports always */
PRINTF_ARGS(void rb_warn(const char*, ...), 1, 2);
PRINTF_ARGS(void rb_compile_warn(const char*, ...), 1, 2);
VALUE rb_each(VALUE);
VALUE rb_yield(VALUE);