void ws_lexer_free_utf8(WsCompiler *compiler, WsUtf8String *string) { if (string == NULL) return; ws_lexer_free_block(compiler, string->data); ws_lexer_free_block(compiler, string); }
void ws_pragma_use(WsCompilerPtr compiler, WsUInt32 line, char *identifier, WsUtf8String *url) { WsPragmaUse *u = ws_calloc(1, sizeof(*u)); WsPragmaUse *uold; /* Do we already know this pragma? */ uold = ws_hash_get(compiler->pragma_use_hash, identifier); if (uold) { ws_src_error(compiler, line, "redefinition of pragma `%s'", identifier); ws_src_error(compiler, uold->line, "`%s' previously defined here", identifier); goto error_cleanup; } if (u == NULL) goto error; u->line = line; /* Insert the URL to the byte-code module. */ if (!ws_bc_add_const_utf8_string(compiler->bc, &u->urlindex, url->data, url->len)) goto error; /* Add it to the use pragma hash. */ if (!ws_hash_put(compiler->pragma_use_hash, identifier, u)) goto error; /* Cleanup. */ ws_lexer_free_block(compiler, identifier); ws_lexer_free_utf8(compiler, url); return; /* Error handling. */ error: ws_error_memory(compiler); error_cleanup: ws_free(u); ws_lexer_free_block(compiler, identifier); ws_lexer_free_utf8(compiler, url); }
WsExpression *ws_expr_call(WsCompiler *compiler, WsUInt32 line, int type, char *base, char *name, WsList *arguments) { WsExpression *expr = expr_alloc(compiler, WS_EXPR_CALL, line); if (expr) { expr->u.call.type = type; expr->u.call.base = ws_f_strdup(compiler->pool_stree, base); expr->u.call.name = ws_f_strdup(compiler->pool_stree, name); expr->u.call.arguments = arguments; if ((base && expr->u.call.base == NULL) || (name && expr->u.call.name == NULL)) ws_error_memory(compiler); } ws_lexer_free_block(compiler, base); ws_lexer_free_block(compiler, name); return expr; }
WsExpression *ws_expr_unary_var(WsCompilerPtr compiler, WsUInt32 line, WsBool addp, char *variable) { WsExpression *expr = expr_alloc(compiler, WS_EXPR_UNARY_VAR, line); if (expr) { expr->u.unary_var.addp = addp; expr->u.unary_var.variable = ws_f_strdup(compiler->pool_stree, variable); if (expr->u.unary_var.variable == NULL) ws_error_memory(compiler); } ws_lexer_free_block(compiler, variable); return expr; }
WsExpression *ws_expr_symbol(WsCompiler *compiler, WsUInt32 line, char *identifier) { WsExpression *expr = expr_alloc(compiler, WS_EXPR_SYMBOL, line); if (expr) { expr->u.symbol = ws_f_strdup(compiler->pool_stree, identifier); if (expr->u.symbol == NULL) ws_error_memory(compiler); } ws_lexer_free_block(compiler, identifier); return expr; }
WsExpression *ws_expr_assign(WsCompilerPtr compiler, WsUInt32 line, char *identifier, int op, WsExpression *expr) { WsExpression *e = expr_alloc(compiler, WS_EXPR_ASSIGN, line); if (e) { e->u.assign.identifier = ws_f_strdup(compiler->pool_stree, identifier); if (e->u.assign.identifier == NULL) ws_error_memory(compiler); e->u.assign.op = op; e->u.assign.expr = expr; } /* Free the identifier symbol since it allocated from the system heap. */ ws_lexer_free_block(compiler, identifier); return e; }