Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

wserror.h File Reference

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Defines

#define WS_STREAM(_stream)
#define WS_STDOUT   WS_STREAM(stdout)
#define WS_STDERR   WS_STREAM(stderr)

Functions

void ws_info (WsCompilerPtr compiler, char *message,...)
void ws_fatal (char *fmt,...) PRINTFLIKE(1
void ws_error_memory (WsCompilerPtr compiler)
void ws_error_syntax (WsCompilerPtr compiler, WsUInt32 line)
void ws_src_error (WsCompilerPtr compiler, WsUInt32 line, char *message,...)
void ws_src_warning (WsCompilerPtr compiler, WsUInt32 line, char *message,...)
void ws_fprintf (WsIOProc io, void *context, const char *fmt,...)
void ws_vfprintf (WsIOProc io, void *context, const char *fmt, va_list ap)
void ws_puts (WsIOProc io, void *context, const char *str)
void ws_fputc (int ch, WsIOProc io, void *context)


Define Documentation

#define WS_STDERR   WS_STREAM(stderr)
 

Definition at line 114 of file wserror.h.

Referenced by ws_error_memory(), ws_error_syntax(), ws_src_error(), and ws_src_warning().

#define WS_STDOUT   WS_STREAM(stdout)
 

Definition at line 113 of file wserror.h.

Referenced by ws_info().

#define WS_STREAM _stream   ) 
 

Value:

compiler->params._stream ## _cb,    \
compiler->params._stream ## _cb_context

Definition at line 109 of file wserror.h.


Function Documentation

void ws_error_memory WsCompilerPtr  compiler  ) 
 

Definition at line 107 of file wserror.c.

References COMPILER_MAGIC, WsCompilerRec::errors, gw_assert, WsCompilerRec::magic, WS_LINE_TERMINATOR, ws_puts(), WS_STDERR, and WsCompilerPtr.

Referenced by buffer_to_int(), expr_alloc(), read_float_from_exp(), read_float_from_point(), stmt_alloc(), ws_expr_assign(), ws_expr_call(), ws_expr_const_string(), ws_expr_linearize(), ws_expr_postfix_var(), ws_expr_symbol(), ws_expr_unary_var(), ws_formal_parameter(), ws_function(), ws_function_hash(), ws_list_append(), ws_list_new(), ws_pragma_meta_body(), ws_pragma_use(), ws_stmt_linearize(), ws_variable_declaration(), ws_variable_define(), ws_yy_lex(), and yyparse().

00108 {
00109     gw_assert(compiler->magic == COMPILER_MAGIC);
00110 
00111     if (compiler->errors & WS_ERROR_B_MEMORY)
00112         /* We have already reported this error. */
00113         return;
00114 
00115     compiler->errors |= WS_ERROR_B_MEMORY;
00116     ws_puts(WS_STDERR, "wsc: error: out of memory" WS_LINE_TERMINATOR);
00117 }

Here is the call graph for this function:

void ws_error_syntax WsCompilerPtr  compiler,
WsUInt32  line
 

Definition at line 120 of file wserror.c.

References COMPILER_MAGIC, WsCompilerRec::errors, gw_assert, WsCompilerRec::input_name, WsCompilerRec::last_syntax_error_line, WsCompilerRec::linenum, WsCompilerRec::magic, ws_fprintf(), WS_LINE_TERMINATOR, WS_STDERR, and WsCompilerPtr.

Referenced by yyparse().

00121 {
00122     gw_assert(compiler->magic == COMPILER_MAGIC);
00123 
00124     if (compiler->errors & WS_ERROR_B_MEMORY)
00125         /* It makes no sense to report syntax errors when we have run out
00126            of memory.  This information is not too valid. */ 
00127         return;
00128 
00129     if (line == 0)
00130         line = compiler->linenum;
00131 
00132     if (compiler->last_syntax_error_line == line)
00133         /* It makes no sense to report multiple syntax errors from the
00134            same line. */ 
00135         return;
00136 
00137     compiler->last_syntax_error_line = line;
00138     compiler->errors |= WS_ERROR_B_SYNTAX;
00139 
00140     ws_fprintf(WS_STDERR, "%s:%u: syntax error" WS_LINE_TERMINATOR,
00141                compiler->input_name, line);
00142 }

Here is the call graph for this function:

void ws_fatal char *  fmt,
  ...
 

Referenced by ws_bc_decode(), ws_bc_encode(), ws_decode_buffer(), ws_encode_buffer(), ws_expr_linearize(), ws_lexer_free_block(), ws_utf8_append_char(), ws_utf8_to_latin1(), and ws_vfprintf().

void ws_fprintf WsIOProc  io,
void *  context,
const char *  fmt,
  ...
 

Definition at line 190 of file wserror.c.

References ws_vfprintf().

Referenced by ws_error_syntax(), ws_src_error(), and ws_src_warning().

00191 {
00192     va_list ap;
00193 
00194     va_start(ap, fmt);
00195     ws_vfprintf(io, context, fmt, ap);
00196     va_end(ap);
00197 }

Here is the call graph for this function:

void ws_fputc int  ch,
WsIOProc  io,
void *  context
 

Definition at line 324 of file wserror.c.

Referenced by ws_vfprintf().

00325 {
00326     char c = (char) ch;
00327 
00328     (*io)(&c, 1, context);
00329 }

void ws_info WsCompilerPtr  compiler,
char *  message,
  ...
 

Definition at line 74 of file wserror.c.

References message, WsCompilerRec::params, WsCompilerParamsRec::verbose, WS_LINE_TERMINATOR, ws_puts(), WS_STDOUT, ws_vfprintf(), and WsCompilerPtr.

Referenced by compile_stream(), opt_conv(), opt_dead_code(), opt_jumps_to_jumps(), opt_jumps_to_next_instruction(), and opt_peephole().

00075 {
00076     va_list ap;
00077 
00078     if (!compiler->params.verbose)
00079         return;
00080 
00081     ws_puts(WS_STDOUT, "wsc: ");
00082 
00083     va_start(ap, message);
00084     ws_vfprintf(WS_STDOUT, message, ap);
00085     va_end(ap);
00086 
00087     ws_puts(WS_STDOUT, WS_LINE_TERMINATOR);
00088 }

Here is the call graph for this function:

void ws_puts WsIOProc  io,
void *  context,
const char *  str
 

Definition at line 318 of file wserror.c.

Referenced by ws_error_memory(), ws_info(), ws_src_error(), and ws_src_warning().

00319 {
00320     (*io)(str, strlen(str), context);
00321 }

void ws_src_error WsCompilerPtr  compiler,
WsUInt32  line,
char *  message,
  ...
 

Definition at line 145 of file wserror.c.

References COMPILER_MAGIC, WsCompilerRec::errors, gw_assert, WsCompilerRec::input_name, WsCompilerRec::linenum, WsCompilerRec::magic, message, WsCompilerRec::num_errors, ws_fprintf(), WS_LINE_TERMINATOR, ws_puts(), WS_STDERR, ws_vfprintf(), and WsCompilerPtr.

Referenced by buffer_to_int(), read_float_from_exp(), ws_expr_linearize(), ws_function(), ws_pragma_use(), ws_stmt_linearize(), ws_variable_define(), and ws_yy_lex().

00146 {
00147     va_list ap;
00148 
00149     gw_assert(compiler->magic == COMPILER_MAGIC);
00150 
00151     if (line == 0)
00152         line = compiler->linenum;
00153 
00154     compiler->errors |= WS_ERROR_B_SEMANTIC;
00155 
00156     ws_fprintf(WS_STDERR, "%s:%u: ", compiler->input_name, line);
00157 
00158     va_start(ap, message);
00159     ws_vfprintf(WS_STDERR, message, ap);
00160     va_end(ap);
00161 
00162     ws_puts(WS_STDERR, WS_LINE_TERMINATOR);
00163 
00164     compiler->num_errors++;
00165 }

Here is the call graph for this function:

void ws_src_warning WsCompilerPtr  compiler,
WsUInt32  line,
char *  message,
  ...
 

Definition at line 168 of file wserror.c.

References COMPILER_MAGIC, gw_assert, WsCompilerRec::input_name, WsCompilerRec::linenum, WsCompilerRec::magic, message, WsCompilerRec::num_errors, ws_fprintf(), WS_LINE_TERMINATOR, ws_puts(), WS_STDERR, ws_vfprintf(), and WsCompilerPtr.

00169 {
00170     va_list ap;
00171 
00172     gw_assert(compiler->magic == COMPILER_MAGIC);
00173 
00174     if (line == 0)
00175         line = compiler->linenum;
00176 
00177     ws_fprintf(WS_STDERR, "%s:%u: warning: ", compiler->input_name, line);
00178 
00179     va_start(ap, message);
00180     ws_vfprintf(WS_STDERR, message, ap);
00181     va_end(ap);
00182 
00183     ws_puts(WS_STDERR, WS_LINE_TERMINATOR);
00184 
00185     compiler->num_errors++;
00186 }

Here is the call graph for this function:

void ws_vfprintf WsIOProc  io,
void *  context,
const char *  fmt,
va_list  ap
 

Definition at line 200 of file wserror.c.

References ws_fatal(), and ws_fputc().

Referenced by ws_fprintf(), ws_info(), ws_src_error(), and ws_src_warning().

00201 {
00202     int start, i;
00203 
00204     for (start = 0, i = 0; fmt[i]; i++)
00205         if (fmt[i] == '%' && fmt[i + 1]) {
00206             char buf[256];
00207             char *cp;
00208             int ival;
00209             unsigned int uival;
00210             int padder = ' ';
00211             int left = 0;
00212             unsigned int width = 0;
00213 
00214             if (fmt[i + 1] == '%') {
00215                 /* An escaped `%'.  Print leading data including the `%'
00216                           character. */
00217                 i++;
00218                 (*io)(fmt + start, i - start, context);
00219                 start = i + 1;
00220                 continue;
00221             }
00222 
00223             /* An escape sequence. */
00224 
00225             /* Print leading data if any. */
00226             if (i > start)
00227                 (*io)(fmt + start, i - start, context);
00228 
00229             /* We support a minor sub-set of the printf()'s formatting
00230                       capabilities.  Let's see what we got. */
00231             i++;
00232 
00233             /* Alignment? */
00234             if (fmt[i] == '-') {
00235                 left = 1;
00236                 i++;
00237             }
00238 
00239             /* Padding? */
00240             if (fmt[i] == '0') {
00241                 padder = '0';
00242                 i++;
00243             }
00244 
00245             /* Width? */
00246             while ('0' <= fmt[i] && fmt[i] <= '9') {
00247                 width *= 10;
00248                 width += fmt[i++] - '0';
00249             }
00250 
00251             /* Check the format. */
00252             cp = buf;
00253             switch (fmt[i]) {
00254             case 'c':       /* character */
00255                 ival = (int) va_arg(ap, int);
00256 
00257                 snprintf(buf, sizeof(buf), "%c", (char) ival);
00258                 cp = buf;
00259                 break;
00260 
00261             case 's':       /* string */
00262                 cp = va_arg(ap, char *);
00263                 break;
00264 
00265             case 'd':       /* integer */
00266                 ival = va_arg(ap, int);
00267 
00268                 snprintf(buf, sizeof(buf), "%d", ival);
00269                 cp = buf;
00270                 break;
00271 
00272             case 'u':       /* unsigned integer */
00273                 uival = va_arg(ap, unsigned int);
00274 
00275                 snprintf(buf, sizeof(buf), "%u", uival);
00276                 cp = buf;
00277                 break;
00278 
00279             case 'x':       /* unsigned integer in hexadecimal format */
00280                 uival = va_arg(ap, unsigned int);
00281 
00282                 snprintf(buf, sizeof(buf), "%x", uival);
00283                 cp = buf;
00284                 break;
00285 
00286             default:
00287                 ws_fatal("ws_vfprintf(): format %%%c not implemented", fmt[i]);
00288                 break;
00289             }
00290 
00291             if (left)
00292                 /* Output the value left-justified. */
00293                 (*io)(cp, strlen(cp), context);
00294 
00295             /* Need padding? */
00296             if (width > strlen(cp)) {
00297                 /* Yes we need. */
00298                 int amount = width - strlen(cp);
00299 
00300                 while (amount-- > 0)
00301                     ws_fputc(padder, io, context);
00302             }
00303 
00304             if (!left)
00305                 /* Output the value right-justified. */
00306                 (*io)(cp, strlen(cp), context);
00307 
00308             /* Process more. */
00309             start = i + 1;
00310         }
00311 
00312     /* Print trailing data if any. */
00313     if (i > start)
00314         (*io)(fmt + start, i - start, context);
00315 }

Here is the call graph for this function:

See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.