Kannel: Open Source WAP and SMS gateway  svn-r5335
ws.c File Reference
#include "wsint.h"
#include "ws.h"
#include "wsstree.h"
#include "wsasm.h"

Go to the source code of this file.

Macros

#define WS_CHECK_COMPILE_ERROR()
 

Functions

static WsResult compile_stream (WsCompilerPtr compiler, const char *input_name, WsStream *input, unsigned char **output_return, size_t *output_len_return)
 
static void std_io (const char *data, size_t len, void *context)
 
static int sort_functions_cmp (const void *a, const void *b)
 
WsCompilerPtr ws_create (WsCompilerParams *params)
 
void ws_destroy (WsCompilerPtr compiler)
 
WsResult ws_compile_file (WsCompilerPtr compiler, const char *input_name, FILE *input, FILE *output)
 
WsResult ws_compile_data (WsCompilerPtr compiler, const char *input_name, const unsigned char *input, size_t input_len, unsigned char **output_return, size_t *output_len_return)
 
void ws_free_byte_code (unsigned char *byte_code)
 
const char * ws_result_to_string (WsResult result)
 
WsBool ws_lexer_register_block (WsCompiler *compiler, void *ptr)
 
WsBool ws_lexer_register_utf8 (WsCompiler *compiler, WsUtf8String *string)
 
void ws_lexer_free_block (WsCompiler *compiler, void *ptr)
 
void ws_lexer_free_utf8 (WsCompiler *compiler, WsUtf8String *string)
 

Variables

struct {
   WsResult   code
 
   char *   description
 
result_codes []
 

Macro Definition Documentation

◆ WS_CHECK_COMPILE_ERROR

#define WS_CHECK_COMPILE_ERROR ( )
Value:
do { \
if (compiler->errors != 0) { \
if (compiler->errors & WS_ERROR_B_MEMORY) \
else if (compiler->errors & WS_ERROR_B_SYNTAX) \
result = WS_ERROR_SYNTAX; \
else if (compiler->errors & WS_ERROR_B_SEMANTIC) \
result = WS_ERROR_SEMANTIC; \
else \
/* This shouldn't happen. */ \
result = WS_ERROR; \
goto out; \
} \
} while (0);
#define WS_ERROR_B_SYNTAX
Definition: wsint.h:141
#define WS_ERROR_B_SEMANTIC
Definition: wsint.h:146
#define WS_ERROR_B_MEMORY
Definition: wsint.h:138
Definition: ws.h:222

Definition at line 78 of file ws.c.

Referenced by compile_stream().

Function Documentation

◆ compile_stream()

static WsResult compile_stream ( WsCompilerPtr  compiler,
const char *  input_name,
WsStream input,
unsigned char **  output_return,
size_t *  output_len_return 
)
static

Definition at line 316 of file ws.c.

References WsCompilerRec::asm_head, WsCompilerRec::asm_tail, WsCompilerRec::bc, WsFunctionRec::block, WsCompilerRec::byte_code, WsListItemRec::data, WsCompilerRec::errors, WsFunctionRec::externp, WsFunctionRec::findex, WsFunctionHashRec::findex, WsCompilerRec::functions, WsCompilerRec::functions_hash, WsListRec::head, WsCompilerRec::input, WsCompilerRec::input_name, WsCompilerRec::last_syntax_error_line, WsCompilerRec::lexer_active_list, WsCompilerRec::lexer_active_list_size, WsCompilerRec::linenum, parm::name, WsFunctionRec::name, WsListItemRec::next, WsCompilerRec::next_label, WsCompilerRec::next_vindex, WsCompilerParamsRec::no_opt_sort_bc_functions, WsCompilerRec::num_errors, WsCompilerRec::num_extern_functions, WsCompilerRec::num_functions, WsListRec::num_items, WsCompilerRec::num_local_functions, WsCompilerRec::num_warnings, WsCompilerRec::params, WsFunctionRec::params, WsCompilerRec::pool_asm, WsCompilerRec::pool_stree, WsCompilerRec::pragma_use_hash, WsCompilerParamsRec::print_assembler, WsCompilerParamsRec::print_symbolic_assembler, sort_functions_cmp(), WsFunctionRec::usage_count, WsFunctionHashRec::usage_count, WsCompilerParamsRec::use_latin1_strings, WsCompilerRec::variables_hash, ws_asm_dasm(), ws_asm_linearize(), ws_asm_optimize(), ws_asm_print(), ws_bc_add_function(), ws_bc_alloc(), ws_bc_encode(), ws_bc_free(), WS_BC_STRING_ENC_ISO_8859_1, WS_BC_STRING_ENC_UTF8, ws_buffer_init(), ws_buffer_len(), ws_buffer_ptr(), ws_buffer_uninit(), WS_CHECK_COMPILE_ERROR, WS_ERROR_OUT_OF_MEMORY, ws_f_create(), ws_f_destroy(), WS_FALSE, ws_free(), ws_function_hash(), ws_function_hash_create(), ws_hash_destroy(), ws_info(), WS_OK, ws_pragma_use_hash_create(), ws_stmt_linearize(), ws_variable_define(), ws_variable_hash_create(), and ws_yy_parse().

Referenced by ws_compile_data(), and ws_compile_file().

319 {
320  WsResult result = WS_OK;
321  WsUInt32 i;
322  WsListItem *li;
323  WsUInt8 findex;
324  WsUInt8 num_locals;
325  WsBcStringEncoding string_encoding = WS_BC_STRING_ENC_UTF8;
326 
327  /* Initialize the compiler context. */
328 
329  compiler->linenum = 1;
330  compiler->input_name = input_name;
331 
332  compiler->num_errors = 0;
333  compiler->num_warnings = 0;
334  compiler->num_extern_functions = 0;
335  compiler->num_local_functions = 0;
336  compiler->errors = 0;
337  compiler->last_syntax_error_line = 0;
338 
339  /* Allocate fast-malloc pool for the syntax tree. */
340 
341  compiler->pool_stree = ws_f_create(1024 * 1024);
342  if (compiler->pool_stree == NULL) {
343  result = WS_ERROR_OUT_OF_MEMORY;
344  goto out;
345  }
346 
347  /* Allocate hash tables. */
348 
350  if (compiler->pragma_use_hash == NULL) {
351  result = WS_ERROR_OUT_OF_MEMORY;
352  goto out;
353  }
354 
356  if (compiler->functions_hash == NULL) {
357  result = WS_ERROR_OUT_OF_MEMORY;
358  goto out;
359  }
360 
361  /* Allocate a byte-code module. */
362 
363  if (compiler->params.use_latin1_strings)
364  string_encoding = WS_BC_STRING_ENC_ISO_8859_1;
365 
366  compiler->bc = ws_bc_alloc(string_encoding);
367  if (compiler->bc == NULL) {
368  result = WS_ERROR_OUT_OF_MEMORY;
369  goto out;
370  }
371 
372  /* Save the input stream. */
373  compiler->input = input;
374 
375  /* Parse the input. */
376 #if WS_DEBUG
377  global_compiler = compiler;
378 #endif /* WS_DEBUG */
379 
380  ws_yy_parse(compiler);
381 
382  /* Free all lexer's active not freed blocks. If we have any blocks
383  on the used list, our compilation was not successful. */
384  {
385  size_t j;
386 
387  for (j = 0; j < compiler->lexer_active_list_size; j++)
388  ws_free(compiler->lexer_active_list[j]);
389  ws_free(compiler->lexer_active_list);
390 
391  compiler->lexer_active_list = NULL;
392  }
393 
395 
396  /* Sort functions if allowed and it helps. */
397  if (!compiler->params.no_opt_sort_bc_functions
398  && compiler->num_functions > 7) {
399  WsUInt32 i;
400 
401  ws_info(compiler, "optimize: sorting functions");
402 
403  /* Fetch the usage counts from the functions hash. */
404  for (i = 0; i < compiler->num_functions; i++) {
405  WsFunctionHash *fh = ws_function_hash(compiler,
406  compiler->functions[i].name);
407  compiler->functions[i].usage_count = fh->usage_count;
408  }
409 
410  /* Sort functions. */
411  qsort(compiler->functions, compiler->num_functions,
412  sizeof(compiler->functions[0]), sort_functions_cmp);
413 
414  /* Patch the function indexes. */
415  for (i = 0; i < compiler->num_functions; i++) {
416  WsFunctionHash *fh = ws_function_hash(compiler,
417  compiler->functions[i].name);
418  compiler->functions[i].findex = i;
419  fh->findex = i;
420  }
421  }
422 
423  /* Linearize functions */
424  for (i = 0; i < compiler->num_functions; i++) {
425  WsFunction *func = &compiler->functions[i];
426 
427  ws_info(compiler, "linearizing function `%s'...", func->name);
428 
429  compiler->pool_asm = ws_f_create(100 * 1024);
430  if (compiler->pool_asm == NULL) {
431  result = WS_ERROR_OUT_OF_MEMORY;
432  goto out;
433  }
434 
435  compiler->next_label = 0;
436  compiler->asm_head = compiler->asm_tail = NULL;
437 
438  /* Create variables namespace. */
439  compiler->next_vindex = 0;
441  if (compiler->variables_hash == NULL) {
442  result = WS_ERROR_OUT_OF_MEMORY;
443  goto out;
444  }
445 
446  /* Define the formal arguments to the namespace. */
447  for (li = func->params->head; li; li = li->next) {
448  WsFormalParm *parm = li->data;
449 
450  ws_variable_define(compiler, parm->line, WS_FALSE, parm->name);
451  }
452 
454 
455  /* Linearize it. */
456  for (li = func->block->head; li; li = li->next)
457  ws_stmt_linearize(compiler, li->data);
458 
460 
461  /* Optimize symbolic assembler. This function does nothing if
462  no optimizations were requested. */
463  ws_asm_optimize(compiler);
464 
465  /* Print the resulting symbolic assembler if requested. */
466  if (compiler->params.print_symbolic_assembler)
467  ws_asm_print(compiler);
468 
470 
471  /* Generate byte-code */
472 
473  ws_buffer_init(&compiler->byte_code);
474  ws_asm_linearize(compiler);
475 
477 
478  /* Disassemble the output if requested. */
479  if (compiler->params.print_assembler)
480  ws_asm_dasm(compiler, ws_buffer_ptr(&compiler->byte_code),
481  ws_buffer_len(&compiler->byte_code));
482 
483  /* Calculate the number of local variables */
484  num_locals = compiler->next_vindex - func->params->num_items;
485 
486  /* Add the function to the byte-code module. */
487  if (!ws_bc_add_function(compiler->bc, &findex,
488  func->externp ? func->name : NULL,
489  func->params->num_items,
490  num_locals,
491  ws_buffer_len(&compiler->byte_code),
492  ws_buffer_ptr(&compiler->byte_code))) {
493  result = WS_ERROR_OUT_OF_MEMORY;
494  goto out;
495  }
496 
497  /* Cleanup and prepare for the next function. */
498 
499  ws_buffer_uninit(&compiler->byte_code);
500 
501  ws_hash_destroy(compiler->variables_hash);
502  compiler->variables_hash = NULL;
503 
504  ws_f_destroy(compiler->pool_asm);
505  compiler->pool_asm = NULL;
506  }
507 
508  /* Linearize the byte-code structure. */
509  if (!ws_bc_encode(compiler->bc, output_return, output_len_return))
510  result = WS_ERROR_OUT_OF_MEMORY;
511 
512 out:
513 
514  /* Cleanup. */
515 
516  ws_f_destroy(compiler->pool_stree);
517  compiler->pool_stree = NULL;
518 
519  ws_hash_destroy(compiler->pragma_use_hash);
520  compiler->pragma_use_hash = NULL;
521 
522  /* Free functions. */
523  for (i = 0; i < compiler->num_functions; i++)
524  ws_free(compiler->functions[i].name);
525  ws_free(compiler->functions);
526 
527  ws_hash_destroy(compiler->functions_hash);
528  compiler->functions_hash = NULL;
529 
530  ws_bc_free(compiler->bc);
531  compiler->bc = NULL;
532 
533  compiler->input = NULL;
534 
535  ws_f_destroy(compiler->pool_asm);
536  compiler->pool_asm = NULL;
537 
538  ws_hash_destroy(compiler->variables_hash);
539  compiler->variables_hash = NULL;
540 
541  ws_buffer_uninit(&compiler->byte_code);
542 
543  /* All done. */
544  return result;
545 }
WsList * block
Definition: wsstree.h:202
WsHashPtr functions_hash
Definition: wsint.h:242
size_t lexer_active_list_size
Definition: wsint.h:215
WsHashPtr pragma_use_hash
Definition: wsint.h:234
struct WsListItemRec * next
Definition: wsstree.h:79
WsFastMalloc * ws_f_create(size_t block_size)
Definition: wsfalloc.c:74
unsigned int no_opt_sort_bc_functions
Definition: ws.h:125
unsigned int print_symbolic_assembler
Definition: ws.h:154
int ws_yy_parse(WsCompiler *compiler)
WsUInt32 num_errors
Definition: wsint.h:253
unsigned long WsUInt32
Definition: wsint.h:122
void ws_free(void *ptr)
Definition: wsalloc.c:139
void ws_hash_destroy(WsHashPtr hash)
Definition: wshash.c:116
WsBc * ws_bc_alloc(WsBcStringEncoding string_encoding)
Definition: wsbc.c:84
WsUInt32 num_local_functions
Definition: wsint.h:257
void ws_f_destroy(WsFastMalloc *pool)
Definition: wsfalloc.c:87
WsStream * input
Definition: wsint.h:196
WsUInt32 num_warnings
Definition: wsint.h:254
static int sort_functions_cmp(const void *a, const void *b)
Definition: ws.c:554
unsigned int use_latin1_strings
Definition: ws.h:109
size_t ws_buffer_len(WsBuffer *buffer)
Definition: wsbuffer.c:139
WsAsmIns * asm_head
Definition: wsint.h:224
#define WS_CHECK_COMPILE_ERROR()
Definition: ws.c:78
WsAsmIns * asm_tail
Definition: wsint.h:225
WsResult
Definition: ws.h:203
WsUInt32 num_functions
Definition: wsint.h:237
WsListItem * head
Definition: wsstree.h:88
WsList * params
Definition: wsstree.h:201
WsBool ws_bc_encode(WsBc *bc, unsigned char **data_return, size_t *data_len_return)
Definition: wsbc.c:132
WsUInt32 linenum
Definition: wsint.h:201
unsigned char WsUInt8
Definition: wsint.h:116
char * name
Definition: seewbmp.c:156
WsBool externp
Definition: wsstree.h:198
WsUInt32 next_vindex
Definition: wsint.h:245
const char * input_name
Definition: wsint.h:200
WsUInt32 errors
Definition: wsint.h:261
Definition: ws.h:206
void * data
Definition: wsstree.h:80
WsBcStringEncoding
Definition: wsbc.h:90
WsHashPtr ws_pragma_use_hash_create(void)
Definition: wsstree.c:214
WsBc * bc
Definition: wsint.h:218
void ws_bc_free(WsBc *bc)
Definition: wsbc.c:97
unsigned int print_assembler
Definition: ws.h:157
void ws_buffer_init(WsBuffer *buffer)
Definition: wsbuffer.c:74
void ws_asm_dasm(WsCompilerPtr compiler, const unsigned char *code, size_t len)
Definition: wsasm.c:185
WsHashPtr ws_function_hash_create(void)
Definition: wsstree.c:312
void ** lexer_active_list
Definition: wsint.h:214
Definition: seewbmp.c:154
WsUInt32 usage_count
Definition: wsstree.h:206
void ws_buffer_uninit(WsBuffer *buffer)
Definition: wsbuffer.c:81
WsUInt32 last_syntax_error_line
Definition: wsint.h:265
WsUInt32 next_label
Definition: wsint.h:221
WsHashPtr variables_hash
Definition: wsint.h:246
WsFunctionHash * ws_function_hash(WsCompilerPtr compiler, char *name)
Definition: wsstree.c:318
void ws_asm_linearize(WsCompiler *compiler)
Definition: wsasm.c:341
void ws_asm_optimize(WsCompilerPtr compiler)
Definition: wsopt.c:362
WsHashPtr ws_variable_hash_create(void)
Definition: wsstree.c:154
WsFunction * functions
Definition: wsint.h:238
WsUInt8 findex
Definition: wsstree.h:197
WsNamespace * ws_variable_define(WsCompilerPtr compiler, WsUInt32 line, WsBool variablep, char *name)
Definition: wsstree.c:160
WsUInt32 num_extern_functions
Definition: wsint.h:256
void ws_asm_print(WsCompiler *compiler)
Definition: wsasm.c:105
WsCompilerParams params
Definition: wsint.h:193
WsFastMalloc * pool_stree
Definition: wsint.h:204
WsBool ws_bc_add_function(WsBc *bc, WsUInt8 *index_return, char *name, WsUInt8 num_arguments, WsUInt8 num_locals, WsUInt32 code_size, unsigned char *code)
Definition: wsbc.c:1056
char * name
Definition: wsstree.h:199
void ws_info(WsCompilerPtr compiler, char *message,...)
Definition: wserror.c:74
unsigned char * ws_buffer_ptr(WsBuffer *buffer)
Definition: wsbuffer.c:133
WsBuffer byte_code
Definition: wsint.h:229
WsFastMalloc * pool_asm
Definition: wsint.h:207
WsUInt32 usage_count
Definition: wsstree.h:222
WsUInt8 findex
Definition: wsstree.h:220
void ws_stmt_linearize(WsCompiler *compiler, WsStatement *stmt)
Definition: wsstree.c:1157
WsUInt32 num_items
Definition: wsstree.h:90

◆ sort_functions_cmp()

static int sort_functions_cmp ( const void *  a,
const void *  b 
)
static

Definition at line 554 of file ws.c.

References WsFunctionRec::findex, and WsFunctionRec::usage_count.

Referenced by compile_stream().

555 {
556  WsFunction *fa = (WsFunction *) a;
557  WsFunction *fb = (WsFunction *) b;
558 
559  if (fa->usage_count > fb->usage_count)
560  return -1;
561  if (fa->usage_count < fb->usage_count)
562  return 1;
563 
564  if (fa->findex < fb->findex)
565  return -1;
566 
567  return 1;
568 }
WsUInt32 usage_count
Definition: wsstree.h:206
WsUInt8 findex
Definition: wsstree.h:197

◆ std_io()

static void std_io ( const char *  data,
size_t  len,
void *  context 
)
static

Definition at line 548 of file ws.c.

Referenced by ws_create().

549 {
550  fwrite(data, 1, len, (FILE *) context);
551 }
Definition: parse.c:65

◆ ws_compile_data()

WsResult ws_compile_data ( WsCompilerPtr  compiler,
const char *  input_name,
const unsigned char *  input,
size_t  input_len,
unsigned char **  output_return,
size_t *  output_len_return 
)

Definition at line 206 of file ws.c.

References compile_stream(), WS_ERROR_OUT_OF_MEMORY, ws_stream_close(), and ws_stream_new_data_input().

Referenced by convert_wmlscript_to_wmlscriptc(), and main().

210 {
211  WsResult result;
212  WsStream *stream;
213 
214  /* Initialize the input stream. */
215  stream = ws_stream_new_data_input(input, input_len);
216  if (stream == NULL)
217  return WS_ERROR_OUT_OF_MEMORY;
218 
219  result = compile_stream(compiler, input_name, stream, output_return,
220  output_len_return);
221 
222  ws_stream_close(stream);
223 
224  return result;
225 }
WsStream * ws_stream_new_data_input(const unsigned char *data, size_t data_len)
WsResult
Definition: ws.h:203
void ws_stream_close(WsStream *stream)
Definition: wsstream.c:117
static WsResult compile_stream(WsCompilerPtr compiler, const char *input_name, WsStream *input, unsigned char **output_return, size_t *output_len_return)
Definition: ws.c:316

◆ ws_compile_file()

WsResult ws_compile_file ( WsCompilerPtr  compiler,
const char *  input_name,
FILE *  input,
FILE *  output 
)

Definition at line 177 of file ws.c.

References compile_stream(), ws_bc_data_free(), WS_ERROR_IO, WS_ERROR_OUT_OF_MEMORY, WS_FALSE, WS_OK, ws_stream_close(), and ws_stream_new_file().

Referenced by main().

179 {
180  WsResult result;
181  WsStream *stream;
182  unsigned char *bc;
183  size_t bc_len;
184 
185  /* Initialize the input stream. */
186  stream = ws_stream_new_file(input, WS_FALSE, WS_FALSE);
187  if (stream == NULL)
188  return WS_ERROR_OUT_OF_MEMORY;
189 
190  result = compile_stream(compiler, input_name, stream, &bc, &bc_len);
191 
192  ws_stream_close(stream);
193 
194  if (result == WS_OK) {
195  /* Store the result to the file. */
196  if (fwrite(bc, 1, bc_len, output) != bc_len)
197  result = WS_ERROR_IO;
198 
199  ws_bc_data_free(bc);
200  }
201 
202  return result;
203 }
WsResult
Definition: ws.h:203
void ws_stream_close(WsStream *stream)
Definition: wsstream.c:117
Definition: ws.h:206
void ws_bc_data_free(unsigned char *data)
Definition: wsbc.c:426
WsStream * ws_stream_new_file(FILE *fp, WsBool output, WsBool close)
static WsResult compile_stream(WsCompilerPtr compiler, const char *input_name, WsStream *input, unsigned char **output_return, size_t *output_len_return)
Definition: ws.c:316

◆ ws_create()

WsCompilerPtr ws_create ( WsCompilerParams params)

Definition at line 135 of file ws.c.

References COMPILER_MAGIC, WsCompilerRec::magic, WsCompilerRec::params, std_io(), WsCompilerParamsRec::stderr_cb, WsCompilerParamsRec::stderr_cb_context, WsCompilerParamsRec::stdout_cb, WsCompilerParamsRec::stdout_cb_context, and ws_calloc().

Referenced by convert_wmlscript_to_wmlscriptc(), and main().

136 {
137  WsCompilerPtr compiler = ws_calloc(1, sizeof(*compiler));
138 
139  if (compiler == NULL)
140  return NULL;
141 
142  /* Store user params if specified. */
143  if (params)
144  compiler->params = *params;
145 
146  /* Basic initialization. */
147 
148  compiler->magic = COMPILER_MAGIC;
149 
150  if (compiler->params.stdout_cb == NULL) {
151  compiler->params.stdout_cb = std_io;
152  compiler->params.stdout_cb_context = stdout;
153  }
154  if (compiler->params.stderr_cb == NULL) {
155  compiler->params.stderr_cb = std_io;
156  compiler->params.stderr_cb_context = stderr;
157  }
158 
159  return compiler;
160 }
void * ws_calloc(size_t num, size_t size)
Definition: wsalloc.c:83
WsUInt32 magic
Definition: wsint.h:190
void * stdout_cb_context
Definition: ws.h:165
static void std_io(const char *data, size_t len, void *context)
Definition: ws.c:548
WsIOProc stdout_cb
Definition: ws.h:164
WsCompilerParams params
Definition: wsint.h:193
WsIOProc stderr_cb
Definition: ws.h:168
void * stderr_cb_context
Definition: ws.h:169
#define COMPILER_MAGIC
Definition: wsint.h:185

◆ ws_destroy()

void ws_destroy ( WsCompilerPtr  compiler)

Definition at line 163 of file ws.c.

References ws_free().

Referenced by main().

164 {
165  if (compiler == NULL)
166  return;
167 
168  ws_free(compiler);
169 
170 #if WS_MEM_DEBUG
171  if (ws_has_leaks())
172  ws_dump_blocks();
173 #endif /* WS_MEM_DEBUG */
174 }
void ws_free(void *ptr)
Definition: wsalloc.c:139

◆ ws_free_byte_code()

void ws_free_byte_code ( unsigned char *  byte_code)

Definition at line 228 of file ws.c.

References ws_bc_data_free().

Referenced by main().

229 {
230  ws_bc_data_free(byte_code);
231 }
void ws_bc_data_free(unsigned char *data)
Definition: wsbc.c:426

◆ ws_lexer_free_block()

void ws_lexer_free_block ( WsCompiler compiler,
void *  ptr 
)

Definition at line 281 of file ws.c.

References WsCompilerRec::lexer_active_list, WsCompilerRec::lexer_active_list_size, ws_fatal(), and ws_free().

Referenced by ws_expr_assign(), ws_expr_call(), ws_expr_postfix_var(), ws_expr_symbol(), ws_expr_unary_var(), ws_lexer_free_utf8(), ws_pragma_use(), and yyparse().

282 {
283  int i;
284 
285  if (ptr == NULL)
286  return;
287 
288  for (i = compiler->lexer_active_list_size - 1; i >= 0; i--) {
289  if (compiler->lexer_active_list[i] == ptr) {
290  memmove(&compiler->lexer_active_list[i],
291  &compiler->lexer_active_list[i + 1],
292  (compiler->lexer_active_list_size - i - 1) * sizeof(void *));
293  compiler->lexer_active_list_size--;
294 
295  ws_free(ptr);
296  return;
297  }
298  }
299 
300  ws_fatal("ws_lexer_free_block(): unknown block 0x%lx",
301  (unsigned long) ptr);
302 }
void ws_fatal(char *fmt,...)
Definition: wserror.c:91
size_t lexer_active_list_size
Definition: wsint.h:215
void ws_free(void *ptr)
Definition: wsalloc.c:139
void ** lexer_active_list
Definition: wsint.h:214

◆ ws_lexer_free_utf8()

void ws_lexer_free_utf8 ( WsCompiler compiler,
WsUtf8String string 
)

Definition at line 305 of file ws.c.

References WsUtf8StringRec::data, and ws_lexer_free_block().

Referenced by ws_expr_const_string(), ws_pragma_meta_body_free(), ws_pragma_use(), and yyparse().

306 {
307  if (string == NULL)
308  return;
309 
310  ws_lexer_free_block(compiler, string->data);
311  ws_lexer_free_block(compiler, string);
312 }
unsigned char * data
Definition: wsutf8.h:84
void ws_lexer_free_block(WsCompiler *compiler, void *ptr)
Definition: ws.c:281

◆ ws_lexer_register_block()

WsBool ws_lexer_register_block ( WsCompiler compiler,
void *  ptr 
)

Definition at line 248 of file ws.c.

References WsCompilerRec::lexer_active_list, WsCompilerRec::lexer_active_list_size, WS_FALSE, ws_realloc(), and WS_TRUE.

Referenced by ws_lexer_register_utf8(), and ws_yy_lex().

249 {
250  void **n;
251 
252  if (ptr == NULL)
253  return WS_TRUE;
254 
255  n = ws_realloc(compiler->lexer_active_list,
256  ((compiler->lexer_active_list_size + 1) * sizeof(void *)));
257  if (n == NULL)
258  return WS_FALSE;
259 
260  compiler->lexer_active_list = n;
261  compiler->lexer_active_list[compiler->lexer_active_list_size++] = ptr;
262 
263  return WS_TRUE;
264 }
size_t lexer_active_list_size
Definition: wsint.h:215
Definition: wsint.h:131
void * ws_realloc(void *ptr, size_t size)
Definition: wsalloc.c:89
void ** lexer_active_list
Definition: wsint.h:214

◆ ws_lexer_register_utf8()

WsBool ws_lexer_register_utf8 ( WsCompiler compiler,
WsUtf8String string 
)

Definition at line 267 of file ws.c.

References WsUtf8StringRec::data, WsCompilerRec::lexer_active_list_size, WS_FALSE, ws_lexer_register_block(), and WS_TRUE.

Referenced by ws_yy_lex().

268 {
269  if (!ws_lexer_register_block(compiler, string))
270  return WS_FALSE;
271 
272  if (!ws_lexer_register_block(compiler, string->data)) {
273  compiler->lexer_active_list_size--;
274  return WS_FALSE;
275  }
276 
277  return WS_TRUE;
278 }
size_t lexer_active_list_size
Definition: wsint.h:215
Definition: wsint.h:131
unsigned char * data
Definition: wsutf8.h:84
WsBool ws_lexer_register_block(WsCompiler *compiler, void *ptr)
Definition: ws.c:248

◆ ws_result_to_string()

const char* ws_result_to_string ( WsResult  result)

Definition at line 234 of file ws.c.

References code, and result_codes.

Referenced by convert_wmlscript_to_wmlscriptc(), and main().

235 {
236  int i;
237 
238  for (i = 0; result_codes[i].description; i++) {
239  if (result_codes[i].code == result)
240  return result_codes[i].description;
241  }
242 
243  return "unknown result code";
244 }
static struct @111 result_codes[]
WsResult code
Definition: ws.c:99

Variable Documentation

◆ code

WsResult code

Definition at line 99 of file ws.c.

Referenced by ws_result_to_string().

◆ description

char* description

Definition at line 100 of file ws.c.

Referenced by describe_code().

◆ result_codes

struct { ... } result_codes[]
Initial value:
= {
{ WS_OK, "success" },
{ WS_ERROR_OUT_OF_MEMORY, "out of memory" },
{ WS_ERROR_SYNTAX, "syntax error" },
{ WS_ERROR_SEMANTIC, "compile error" },
{ WS_ERROR_IO, "IO error" },
{ WS_ERROR, "error" },
{ 0, NULL },
}
Definition: ws.h:206
Definition: ws.h:222

Referenced by ws_result_to_string().

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