[前][次][番号順一覧][スレッド一覧]

ruby-changes:42575

From: nobu <ko1@a...>
Date: Tue, 19 Apr 2016 16:46:14 +0900 (JST)
Subject: [ruby-changes:42575] nobu:r54649 (trunk): refactor parser error

nobu	2016-04-19 17:42:50 +0900 (Tue, 19 Apr 2016)

  New Revision: 54649

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54649

  Log:
    refactor parser error
    
    * error.c (err_vcatf): rename, and separate appending message from
      creating a string buffer.
    * error.c (rb_syntax_error_append): merge rb_error_vsprintf and
      rb_compile_err_append.
    * parse.y (parser_compile_error): use rb_syntax_error_append.

  Modified files:
    trunk/ChangeLog
    trunk/error.c
    trunk/parse.y
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 54648)
+++ ChangeLog	(revision 54649)
@@ -1,3 +1,13 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Apr 19 17:42:47 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* error.c (err_vcatf): rename, and separate appending message from
+	  creating a string buffer.
+
+	* error.c (rb_syntax_error_append): merge rb_error_vsprintf and
+	  rb_compile_err_append.
+
+	* parse.y (parser_compile_error): use rb_syntax_error_append.
+
 Tue Apr 19 13:46:19 2016  Nobuyoshi Nakada  <nobu@r...>
 
 	* compile.c (append_compile_error, compile_bug): pass iseq and get
Index: parse.y
===================================================================
--- parse.y	(revision 54648)
+++ parse.y	(revision 54649)
@@ -11074,21 +11074,22 @@ rb_parser_printf(struct parser_params *p https://github.com/ruby/ruby/blob/trunk/parse.y#L11074
     }
 }
 
-extern VALUE rb_error_vsprintf(VALUE, int, void *, const char *, va_list);
-extern VALUE rb_compile_err_append(VALUE buffer, VALUE mesg);
+extern VALUE rb_syntax_error_append(VALUE exc, VALUE file, int line, int column, rb_encoding *enc, const char *fmt, va_list args);
 
 static void
 parser_compile_error(struct parser_params *parser, const char *fmt, ...)
 {
-    VALUE str;
     va_list ap;
 
     parser->error_p = 1;
     va_start(ap, fmt);
-    str = rb_error_vsprintf(ruby_sourcefile_string, ruby_sourceline,
-			    (void *)current_enc, fmt, ap);
+    parser->error_buffer =
+	rb_syntax_error_append(parser->error_buffer,
+			       ruby_sourcefile_string,
+			       ruby_sourceline,
+			       rb_long2int(lex_p - lex_pbeg),
+			       current_enc, fmt, ap);
     va_end(ap);
-    parser->error_buffer = rb_compile_err_append(parser->error_buffer, str);
 }
 #endif
 
Index: error.c
===================================================================
--- error.c	(revision 54648)
+++ error.c	(revision 54649)
@@ -80,10 +80,9 @@ err_position_0(char *buf, long len, cons https://github.com/ruby/ruby/blob/trunk/error.c#L80
 }
 
 static VALUE
-compile_vsprintf(rb_encoding *enc, const char *pre, const char *file, int line, const char *fmt, va_list args)
+err_vcatf(VALUE str, const char *pre, const char *file, int line,
+	  const char *fmt, va_list args)
 {
-    VALUE str = rb_enc_str_new(0, 0, enc);
-
     if (file) {
 	rb_str_cat2(str, file);
 	if (line) rb_str_catf(str, ":%d", line);
@@ -95,21 +94,25 @@ compile_vsprintf(rb_encoding *enc, const https://github.com/ruby/ruby/blob/trunk/error.c#L94
 }
 
 VALUE
-rb_compile_err_append(VALUE buffer, VALUE mesg)
+rb_syntax_error_append(VALUE exc, VALUE file, int line, int column,
+		       rb_encoding *enc, const char *fmt, va_list args)
 {
-    if (!buffer) {
+    const char *fn = NIL_P(file) ? NULL : RSTRING_PTR(file);
+    if (!exc) {
+	VALUE mesg = rb_enc_str_new(0, 0, enc);
+	err_vcatf(mesg, NULL, fn, line, fmt, args);
 	rb_str_cat2(mesg, "\n");
 	rb_write_error_str(mesg);
     }
-    else if (NIL_P(buffer)) {
-	buffer = mesg;
+    else if (NIL_P(exc)) {
+	VALUE mesg = rb_enc_str_new(0, 0, enc);
+	exc = err_vcatf(mesg, NULL, fn, line, fmt, args);
     }
     else {
-	rb_str_cat2(buffer, "\n");
-	rb_str_append(buffer, mesg);
+	err_vcatf(exc, "\n", fn, line, fmt, args);
     }
 
-    return buffer;
+    return exc;
 }
 
 void
@@ -122,14 +125,6 @@ rb_compile_error(const char *file, int l https://github.com/ruby/ruby/blob/trunk/error.c#L125
 {
 }
 
-VALUE
-rb_error_vsprintf(VALUE file, int line, void *enc, const char *fmt, va_list args)
-{
-    return compile_vsprintf(enc, NULL,
-			    NIL_P(file) ? NULL : RSTRING_PTR(file), line,
-			    fmt, args);
-}
-
 void
 rb_compile_error_append(const char *fmt, ...)
 {
@@ -138,9 +133,9 @@ rb_compile_error_append(const char *fmt, https://github.com/ruby/ruby/blob/trunk/error.c#L133
 static VALUE
 warn_vsprintf(rb_encoding *enc, const char *file, int line, const char *fmt, va_list args)
 {
-    VALUE str;
+    VALUE str = rb_enc_str_new(0, 0, enc);
 
-    str = compile_vsprintf(enc, "warning: ", file, line, fmt, args);
+    err_vcatf(str, "warning: ", file, line, fmt, args);
     return rb_str_cat2(str, "\n");
 }
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]