Kannel: Open Source WAP and SMS gateway  svn-r5335
wsstree.h File Reference

Go to the source code of this file.

Data Structures

struct  WsListItemRec
 
struct  WsListRec
 
struct  WsNamespaceRec
 
struct  WsPragmaUseRec
 
struct  WsPragmaMetaBodyRec
 
struct  WsFunctionRec
 
struct  WsFunctionHashRec
 
struct  WsExpressionRec
 
struct  WsVarDecRec
 
struct  WsFormalParmRec
 
struct  WsStatementRec
 

Typedefs

typedef struct WsListItemRec WsListItem
 
typedef struct WsListRec WsList
 
typedef struct WsNamespaceRec WsNamespace
 
typedef struct WsPragmaUseRec WsPragmaUse
 
typedef struct WsPragmaMetaBodyRec WsPragmaMetaBody
 
typedef struct WsFunctionRec WsFunction
 
typedef struct WsFunctionHashRec WsFunctionHash
 
typedef struct WsExpressionRec WsExpression
 
typedef struct WsVarDecRec WsVarDec
 
typedef struct WsFormalParmRec WsFormalParm
 
typedef struct WsStatementRec WsStatement
 

Enumerations

enum  WsExpressionType {
  WS_EXPR_COMMA, WS_EXPR_ASSIGN, WS_EXPR_CONDITIONAL, WS_EXPR_LOGICAL,
  WS_EXPR_BINARY, WS_EXPR_UNARY, WS_EXPR_UNARY_VAR, WS_EXPR_POSTFIX_VAR,
  WS_EXPR_CALL, WS_EXPR_SYMBOL, WS_EXPR_CONST_INVALID, WS_EXPR_CONST_TRUE,
  WS_EXPR_CONST_FALSE, WS_EXPR_CONST_INTEGER, WS_EXPR_CONST_FLOAT, WS_EXPR_CONST_STRING
}
 
enum  WsStatementType {
  WS_STMT_BLOCK, WS_STMT_VARIABLE, WS_STMT_EMPTY, WS_STMT_EXPR,
  WS_STMT_IF, WS_STMT_FOR, WS_STMT_WHILE, WS_STMT_CONTINUE,
  WS_STMT_BREAK, WS_STMT_RETURN
}
 

Functions

WsListws_list_new (WsCompilerPtr compiler)
 
void ws_list_append (WsCompilerPtr compiler, WsList *list, void *value)
 
WsHashPtr ws_variable_hash_create (void)
 
WsNamespacews_variable_define (WsCompilerPtr compiler, WsUInt32 line, WsBool variablep, char *name)
 
WsNamespacews_variable_lookup (WsCompilerPtr compiler, char *name)
 
WsHashPtr ws_pragma_use_hash_create (void)
 
void ws_pragma_use (WsCompilerPtr compiler, WsUInt32 line, char *identifier, WsUtf8String *url)
 
WsPragmaMetaBodyws_pragma_meta_body (WsCompilerPtr compiler, WsUtf8String *property_name, WsUtf8String *content, WsUtf8String *scheme)
 
void ws_pragma_meta_body_free (WsCompilerPtr compiler, WsPragmaMetaBody *mb)
 
WsHashPtr ws_function_hash_create (void)
 
WsFunctionHashws_function_hash (WsCompilerPtr compiler, char *name)
 
void ws_function (WsCompilerPtr compiler, WsBool externp, char *name, WsUInt32 line, WsList *params, WsList *block)
 
void ws_expr_linearize (WsCompilerPtr compiler, WsExpression *expr)
 
WsExpressionws_expr_comma (WsCompilerPtr compiler, WsUInt32 line, WsExpression *left, WsExpression *right)
 
WsExpressionws_expr_assign (WsCompilerPtr compiler, WsUInt32 line, char *identifier, int op, WsExpression *expr)
 
WsExpressionws_expr_conditional (WsCompilerPtr compiler, WsUInt32 line, WsExpression *e_cond, WsExpression *e_then, WsExpression *e_else)
 
WsExpressionws_expr_logical (WsCompilerPtr compiler, WsUInt32 line, int type, WsExpression *left, WsExpression *right)
 
WsExpressionws_expr_binary (WsCompilerPtr compiler, WsUInt32 line, int type, WsExpression *left, WsExpression *right)
 
WsExpressionws_expr_unary (WsCompilerPtr compiler, WsUInt32 line, int type, WsExpression *expr)
 
WsExpressionws_expr_unary_var (WsCompilerPtr compiler, WsUInt32 line, WsBool addp, char *variable)
 
WsExpressionws_expr_postfix_var (WsCompilerPtr compiler, WsUInt32 line, WsBool addp, char *variable)
 
WsExpressionws_expr_call (WsCompilerPtr compiler, WsUInt32 linenum, int type, char *base, char *name, WsList *arguments)
 
WsExpressionws_expr_symbol (WsCompilerPtr compiler, WsUInt32 linenum, char *identifier)
 
WsExpressionws_expr_const_invalid (WsCompilerPtr compiler, WsUInt32 linenum)
 
WsExpressionws_expr_const_true (WsCompilerPtr compiler, WsUInt32 linenum)
 
WsExpressionws_expr_const_false (WsCompilerPtr compiler, WsUInt32 linenum)
 
WsExpressionws_expr_const_integer (WsCompilerPtr compiler, WsUInt32 linenum, WsUInt32 ival)
 
WsExpressionws_expr_const_float (WsCompilerPtr compiler, WsUInt32 linenum, WsFloat fval)
 
WsExpressionws_expr_const_string (WsCompilerPtr compiler, WsUInt32 linenum, WsUtf8String *string)
 
WsVarDecws_variable_declaration (WsCompilerPtr compiler, char *name, WsExpression *expr)
 
WsFormalParmws_formal_parameter (WsCompilerPtr compiler, WsUInt32 line, char *name)
 
void ws_stmt_linearize (WsCompilerPtr compiler, WsStatement *stmt)
 
WsStatementws_stmt_block (WsCompilerPtr compiler, WsUInt32 first_line, WsUInt32 last_line, WsList *block)
 
WsStatementws_stmt_variable (WsCompilerPtr compiler, WsUInt32 line, WsList *variables)
 
WsStatementws_stmt_empty (WsCompilerPtr compiler, WsUInt32 line)
 
WsStatementws_stmt_expr (WsCompilerPtr compiler, WsUInt32 line, WsExpression *expr)
 
WsStatementws_stmt_if (WsCompilerPtr compiler, WsUInt32 line, WsExpression *expr, WsStatement *s_then, WsStatement *s_else)
 
WsStatementws_stmt_for (WsCompilerPtr compiler, WsUInt32 line, WsList *init, WsExpression *e1, WsExpression *e2, WsExpression *e3, WsStatement *stmt)
 
WsStatementws_stmt_while (WsCompilerPtr compiler, WsUInt32 line, WsExpression *expr, WsStatement *stmt)
 
WsStatementws_stmt_continue (WsCompilerPtr compiler, WsUInt32 line)
 
WsStatementws_stmt_break (WsCompilerPtr compiler, WsUInt32 line)
 
WsStatementws_stmt_return (WsCompilerPtr compiler, WsUInt32 line, WsExpression *expr)
 

Typedef Documentation

◆ WsExpression

typedef struct WsExpressionRec WsExpression

Definition at line 389 of file wsstree.h.

◆ WsFormalParm

typedef struct WsFormalParmRec WsFormalParm

Definition at line 496 of file wsstree.h.

◆ WsFunction

typedef struct WsFunctionRec WsFunction

Definition at line 209 of file wsstree.h.

◆ WsFunctionHash

Definition at line 225 of file wsstree.h.

◆ WsList

typedef struct WsListRec WsList

Definition at line 99 of file wsstree.h.

◆ WsListItem

typedef struct WsListItemRec WsListItem

Definition at line 83 of file wsstree.h.

◆ WsNamespace

typedef struct WsNamespaceRec WsNamespace

Definition at line 122 of file wsstree.h.

◆ WsPragmaMetaBody

Definition at line 181 of file wsstree.h.

◆ WsPragmaUse

typedef struct WsPragmaUseRec WsPragmaUse

Definition at line 156 of file wsstree.h.

◆ WsStatement

typedef struct WsStatementRec WsStatement

Definition at line 560 of file wsstree.h.

◆ WsVarDec

typedef struct WsVarDecRec WsVarDec

Definition at line 483 of file wsstree.h.

Enumeration Type Documentation

◆ WsExpressionType

Enumerator
WS_EXPR_COMMA 
WS_EXPR_ASSIGN 
WS_EXPR_CONDITIONAL 
WS_EXPR_LOGICAL 
WS_EXPR_BINARY 
WS_EXPR_UNARY 
WS_EXPR_UNARY_VAR 
WS_EXPR_POSTFIX_VAR 
WS_EXPR_CALL 
WS_EXPR_SYMBOL 
WS_EXPR_CONST_INVALID 
WS_EXPR_CONST_TRUE 
WS_EXPR_CONST_FALSE 
WS_EXPR_CONST_INTEGER 
WS_EXPR_CONST_FLOAT 
WS_EXPR_CONST_STRING 

Definition at line 251 of file wsstree.h.

◆ WsStatementType

Enumerator
WS_STMT_BLOCK 
WS_STMT_VARIABLE 
WS_STMT_EMPTY 
WS_STMT_EXPR 
WS_STMT_IF 
WS_STMT_FOR 
WS_STMT_WHILE 
WS_STMT_CONTINUE 
WS_STMT_BREAK 
WS_STMT_RETURN 

Definition at line 506 of file wsstree.h.

Function Documentation

◆ ws_expr_assign()

WsExpression* ws_expr_assign ( WsCompilerPtr  compiler,
WsUInt32  line,
char *  identifier,
int  op,
WsExpression expr 
)

Definition at line 903 of file wsstree.c.

References WsExpressionRec::assign, expr_alloc(), WsCompilerRec::pool_stree, WsExpressionRec::u, ws_error_memory(), WS_EXPR_ASSIGN, ws_f_strdup(), and ws_lexer_free_block().

Referenced by yyparse().

905 {
906  WsExpression *e = expr_alloc(compiler, WS_EXPR_ASSIGN, line);
907 
908  if (e) {
909  e->u.assign.identifier = ws_f_strdup(compiler->pool_stree, identifier);
910  if (e->u.assign.identifier == NULL)
911  ws_error_memory(compiler);
912 
913  e->u.assign.op = op;
914  e->u.assign.expr = expr;
915  }
916 
917  /* Free the identifier symbol since it allocated from the system
918  heap. */
919  ws_lexer_free_block(compiler, identifier);
920 
921  return e;
922 }
void ws_lexer_free_block(WsCompiler *compiler, void *ptr)
Definition: ws.c:281
void * ws_f_strdup(WsFastMalloc *pool, const char *str)
Definition: wsfalloc.c:177
static WsExpression * expr_alloc(WsCompiler *compiler, WsExpressionType type, WsUInt32 line)
Definition: wsstree.c:873
union WsExpressionRec::@118 u
WsFastMalloc * pool_stree
Definition: wsint.h:204
struct WsExpressionRec::@118::@120 assign
void ws_error_memory(WsCompilerPtr compiler)
Definition: wserror.c:107

◆ ws_expr_binary()

WsExpression* ws_expr_binary ( WsCompilerPtr  compiler,
WsUInt32  line,
int  type,
WsExpression left,
WsExpression right 
)

Definition at line 956 of file wsstree.c.

References WsExpressionRec::binary, expr_alloc(), type, WsExpressionRec::u, and WS_EXPR_BINARY.

Referenced by yyparse().

958 {
959  WsExpression *expr = expr_alloc(compiler, WS_EXPR_BINARY, line);
960 
961  if (expr) {
962  expr->u.binary.type = type;
963  expr->u.binary.left = left;
964  expr->u.binary.right = right;
965  }
966 
967  return expr;
968 }
int type
Definition: smsc_cimd2.c:215
struct WsExpressionRec::@118::@123 binary
static WsExpression * expr_alloc(WsCompiler *compiler, WsExpressionType type, WsUInt32 line)
Definition: wsstree.c:873
union WsExpressionRec::@118 u

◆ ws_expr_call()

WsExpression* ws_expr_call ( WsCompilerPtr  compiler,
WsUInt32  linenum,
int  type,
char *  base,
char *  name,
WsList arguments 
)

◆ ws_expr_comma()

WsExpression* ws_expr_comma ( WsCompilerPtr  compiler,
WsUInt32  line,
WsExpression left,
WsExpression right 
)

Definition at line 889 of file wsstree.c.

References WsExpressionRec::comma, expr_alloc(), WsExpressionRec::u, and WS_EXPR_COMMA.

Referenced by yyparse().

891 {
892  WsExpression *expr = expr_alloc(compiler, WS_EXPR_COMMA, line);
893 
894  if (expr) {
895  expr->u.comma.left = left;
896  expr->u.comma.right = right;
897  }
898 
899  return expr;
900 }
static WsExpression * expr_alloc(WsCompiler *compiler, WsExpressionType type, WsUInt32 line)
Definition: wsstree.c:873
union WsExpressionRec::@118 u
struct WsExpressionRec::@118::@119 comma

◆ ws_expr_conditional()

WsExpression* ws_expr_conditional ( WsCompilerPtr  compiler,
WsUInt32  line,
WsExpression e_cond,
WsExpression e_then,
WsExpression e_else 
)

Definition at line 925 of file wsstree.c.

References WsExpressionRec::conditional, expr_alloc(), WsExpressionRec::u, and WS_EXPR_CONDITIONAL.

Referenced by yyparse().

928 {
929  WsExpression *e = expr_alloc(compiler, WS_EXPR_CONDITIONAL, line);
930 
931  if (e) {
932  e->u.conditional.e_cond = e_cond;
933  e->u.conditional.e_then = e_then;
934  e->u.conditional.e_else = e_else;
935  }
936 
937  return e;
938 }
struct WsExpressionRec::@118::@121 conditional
static WsExpression * expr_alloc(WsCompiler *compiler, WsExpressionType type, WsUInt32 line)
Definition: wsstree.c:873
union WsExpressionRec::@118 u

◆ ws_expr_const_false()

WsExpression* ws_expr_const_false ( WsCompilerPtr  compiler,
WsUInt32  linenum 
)

◆ ws_expr_const_float()

WsExpression* ws_expr_const_float ( WsCompilerPtr  compiler,
WsUInt32  linenum,
WsFloat  fval 
)

◆ ws_expr_const_integer()

WsExpression* ws_expr_const_integer ( WsCompilerPtr  compiler,
WsUInt32  linenum,
WsUInt32  ival 
)

◆ ws_expr_const_invalid()

WsExpression* ws_expr_const_invalid ( WsCompilerPtr  compiler,
WsUInt32  linenum 
)

◆ ws_expr_const_string()

WsExpression* ws_expr_const_string ( WsCompilerPtr  compiler,
WsUInt32  linenum,
WsUtf8String string 
)

◆ ws_expr_const_true()

WsExpression* ws_expr_const_true ( WsCompilerPtr  compiler,
WsUInt32  linenum 
)

◆ ws_expr_linearize()

void ws_expr_linearize ( WsCompilerPtr  compiler,
WsExpression expr 
)

◆ ws_expr_logical()

WsExpression* ws_expr_logical ( WsCompilerPtr  compiler,
WsUInt32  line,
int  type,
WsExpression left,
WsExpression right 
)

Definition at line 941 of file wsstree.c.

References expr_alloc(), WsExpressionRec::logical, type, WsExpressionRec::u, and WS_EXPR_LOGICAL.

Referenced by yyparse().

943 {
944  WsExpression *expr = expr_alloc(compiler, WS_EXPR_LOGICAL, line);
945 
946  if (expr) {
947  expr->u.logical.type = type;
948  expr->u.logical.left = left;
949  expr->u.logical.right = right;
950  }
951 
952  return expr;
953 }
int type
Definition: smsc_cimd2.c:215
struct WsExpressionRec::@118::@122 logical
static WsExpression * expr_alloc(WsCompiler *compiler, WsExpressionType type, WsUInt32 line)
Definition: wsstree.c:873
union WsExpressionRec::@118 u

◆ ws_expr_postfix_var()

WsExpression* ws_expr_postfix_var ( WsCompilerPtr  compiler,
WsUInt32  line,
WsBool  addp,
char *  variable 
)

Definition at line 1010 of file wsstree.c.

References expr_alloc(), WsCompilerRec::pool_stree, WsExpressionRec::postfix_var, WsExpressionRec::u, ws_error_memory(), WS_EXPR_POSTFIX_VAR, ws_f_strdup(), and ws_lexer_free_block().

Referenced by yyparse().

1012 {
1013  WsExpression *expr = expr_alloc(compiler, WS_EXPR_POSTFIX_VAR, line);
1014 
1015  if (expr) {
1016  expr->u.postfix_var.addp = addp;
1017  expr->u.postfix_var.variable = ws_f_strdup(compiler->pool_stree,
1018  variable);
1019  if (expr->u.postfix_var.variable == NULL)
1020  ws_error_memory(compiler);
1021  }
1022  ws_lexer_free_block(compiler, variable);
1023 
1024  return expr;
1025 }
void ws_lexer_free_block(WsCompiler *compiler, void *ptr)
Definition: ws.c:281
struct WsExpressionRec::@118::@126 postfix_var
void * ws_f_strdup(WsFastMalloc *pool, const char *str)
Definition: wsfalloc.c:177
static WsExpression * expr_alloc(WsCompiler *compiler, WsExpressionType type, WsUInt32 line)
Definition: wsstree.c:873
union WsExpressionRec::@118 u
WsFastMalloc * pool_stree
Definition: wsint.h:204
void ws_error_memory(WsCompilerPtr compiler)
Definition: wserror.c:107

◆ ws_expr_symbol()

WsExpression* ws_expr_symbol ( WsCompilerPtr  compiler,
WsUInt32  linenum,
char *  identifier 
)

◆ ws_expr_unary()

WsExpression* ws_expr_unary ( WsCompilerPtr  compiler,
WsUInt32  line,
int  type,
WsExpression expr 
)

Definition at line 971 of file wsstree.c.

References expr_alloc(), WsExpressionRec::integer, type, WsExpressionRec::type, WsExpressionRec::u, WsExpressionRec::unary, WS_ASM_UMINUS, WS_EXPR_CONST_INTEGER, and WS_EXPR_UNARY.

Referenced by yyparse().

973 {
974  WsExpression *expr;
975 
976  /* Handle negative integers here as a special case of constant folding,
977  * in order to get -2147483648 right. */
978  if (type == WS_ASM_UMINUS && expression->type == WS_EXPR_CONST_INTEGER) {
979  expression->u.integer.sign = - expression->u.integer.sign;
980  return expression;
981  }
982 
983  expr = expr_alloc(compiler, WS_EXPR_UNARY, line);
984  if (expr) {
985  expr->u.unary.type = type;
986  expr->u.unary.expr = expression;
987  }
988 
989  return expr;
990 }
int type
Definition: smsc_cimd2.c:215
struct WsExpressionRec::@118::@124 unary
static WsExpression * expr_alloc(WsCompiler *compiler, WsExpressionType type, WsUInt32 line)
Definition: wsstree.c:873
union WsExpressionRec::@118 u
#define WS_ASM_UMINUS
Definition: wsasm.h:182
struct WsExpressionRec::@118::@128 integer

◆ ws_expr_unary_var()

WsExpression* ws_expr_unary_var ( WsCompilerPtr  compiler,
WsUInt32  line,
WsBool  addp,
char *  variable 
)

Definition at line 993 of file wsstree.c.

References expr_alloc(), WsCompilerRec::pool_stree, WsExpressionRec::u, WsExpressionRec::unary_var, ws_error_memory(), WS_EXPR_UNARY_VAR, ws_f_strdup(), and ws_lexer_free_block().

Referenced by yyparse().

995 {
996  WsExpression *expr = expr_alloc(compiler, WS_EXPR_UNARY_VAR, line);
997 
998  if (expr) {
999  expr->u.unary_var.addp = addp;
1000  expr->u.unary_var.variable = ws_f_strdup(compiler->pool_stree, variable);
1001  if (expr->u.unary_var.variable == NULL)
1002  ws_error_memory(compiler);
1003  }
1004  ws_lexer_free_block(compiler, variable);
1005 
1006  return expr;
1007 }
void ws_lexer_free_block(WsCompiler *compiler, void *ptr)
Definition: ws.c:281
struct WsExpressionRec::@118::@125 unary_var
void * ws_f_strdup(WsFastMalloc *pool, const char *str)
Definition: wsfalloc.c:177
static WsExpression * expr_alloc(WsCompiler *compiler, WsExpressionType type, WsUInt32 line)
Definition: wsstree.c:873
union WsExpressionRec::@118 u
WsFastMalloc * pool_stree
Definition: wsint.h:204
void ws_error_memory(WsCompilerPtr compiler)
Definition: wserror.c:107

◆ ws_formal_parameter()

WsFormalParm* ws_formal_parameter ( WsCompilerPtr  compiler,
WsUInt32  line,
char *  name 
)

Definition at line 93 of file wsstree.c.

References parm::name, name, WsCompilerRec::pool_stree, ws_error_memory(), and ws_f_malloc().

Referenced by yyparse().

95 {
96  WsFormalParm *parm = ws_f_malloc(compiler->pool_stree, sizeof(*parm));
97 
98  if (parm == NULL)
99  ws_error_memory(compiler);
100  else {
101  parm->line = line;
102  parm->name = name;
103  }
104 
105  return parm;
106 }
char * name
Definition: seewbmp.c:156
char * name
Definition: smsc_cimd2.c:212
Definition: seewbmp.c:154
WsFastMalloc * pool_stree
Definition: wsint.h:204
void * ws_f_malloc(WsFastMalloc *pool, size_t size)
Definition: wsfalloc.c:102
void ws_error_memory(WsCompilerPtr compiler)
Definition: wserror.c:107

◆ ws_function()

void ws_function ( WsCompilerPtr  compiler,
WsBool  externp,
char *  name,
WsUInt32  line,
WsList params,
WsList block 
)

◆ ws_function_hash()

WsFunctionHash* ws_function_hash ( WsCompilerPtr  compiler,
char *  name 
)

Definition at line 318 of file wsstree.c.

References WsCompilerRec::functions_hash, name, ws_calloc(), ws_error_memory(), ws_free(), ws_hash_get(), and ws_hash_put().

Referenced by compile_stream(), ws_expr_linearize(), ws_function(), and yyparse().

319 {
321 
322  if (i)
323  return i;
324 
325  /* Must create a new mapping. */
326 
327  i = ws_calloc(1, sizeof(*i));
328  if (i == NULL) {
329  ws_error_memory(compiler);
330  return NULL;
331  }
332 
333  if (!ws_hash_put(compiler->functions_hash, name, i)) {
334  ws_free(i);
335  ws_error_memory(compiler);
336  return NULL;
337  }
338 
339  return i;
340 }
void * ws_calloc(size_t num, size_t size)
Definition: wsalloc.c:83
WsHashPtr functions_hash
Definition: wsint.h:242
void ws_free(void *ptr)
Definition: wsalloc.c:139
char * name
Definition: smsc_cimd2.c:212
WsBool ws_hash_put(WsHashPtr hash, const char *name, void *data)
Definition: wshash.c:126
void * ws_hash_get(WsHashPtr hash, const char *name)
Definition: wshash.c:167
void ws_error_memory(WsCompilerPtr compiler)
Definition: wserror.c:107

◆ ws_function_hash_create()

WsHashPtr ws_function_hash_create ( void  )

Definition at line 312 of file wsstree.c.

References function_hash_destructor(), and ws_hash_create().

Referenced by compile_stream().

313 {
315 }
static void function_hash_destructor(void *item, void *context)
Definition: wsstree.c:306
WsHashPtr ws_hash_create(WsHashItemDestructor destructor, void *context)
Definition: wshash.c:103

◆ ws_list_append()

void ws_list_append ( WsCompilerPtr  compiler,
WsList list,
void *  value 
)

◆ ws_list_new()

WsList* ws_list_new ( WsCompilerPtr  compiler)

◆ ws_pragma_meta_body()

WsPragmaMetaBody* ws_pragma_meta_body ( WsCompilerPtr  compiler,
WsUtf8String property_name,
WsUtf8String content,
WsUtf8String scheme 
)

Definition at line 271 of file wsstree.c.

References content, WsPragmaMetaBodyRec::content, WsPragmaMetaBodyRec::property_name, WsPragmaMetaBodyRec::scheme, ws_calloc(), and ws_error_memory().

Referenced by yyparse().

275 {
276  WsPragmaMetaBody *mb = ws_calloc(1, sizeof(*mb));
277 
278  if (mb == NULL) {
279  ws_error_memory(compiler);
280  return NULL;
281  }
282 
283  mb->property_name = property_name;
284  mb->content = content;
285  mb->scheme = scheme;
286 
287  return mb;
288 }
void * ws_calloc(size_t num, size_t size)
Definition: wsalloc.c:83
WsUtf8String * scheme
Definition: wsstree.h:178
WsUtf8String * property_name
Definition: wsstree.h:176
WsUtf8String * content
Definition: wsstree.h:177
static Octstr * content
Definition: mtbatch.c:87
void ws_error_memory(WsCompilerPtr compiler)
Definition: wserror.c:107

◆ ws_pragma_meta_body_free()

void ws_pragma_meta_body_free ( WsCompilerPtr  compiler,
WsPragmaMetaBody mb 
)

Definition at line 291 of file wsstree.c.

References WsPragmaMetaBodyRec::content, WsPragmaMetaBodyRec::property_name, WsPragmaMetaBodyRec::scheme, ws_free(), and ws_lexer_free_utf8().

Referenced by yyparse().

292 {
293  if (mb == NULL)
294  return;
295 
296  ws_lexer_free_utf8(compiler, mb->property_name);
297  ws_lexer_free_utf8(compiler, mb->content);
298  ws_lexer_free_utf8(compiler, mb->scheme);
299 
300  ws_free(mb);
301 }
void ws_free(void *ptr)
Definition: wsalloc.c:139
WsUtf8String * scheme
Definition: wsstree.h:178
WsUtf8String * property_name
Definition: wsstree.h:176
WsUtf8String * content
Definition: wsstree.h:177
void ws_lexer_free_utf8(WsCompiler *compiler, WsUtf8String *string)
Definition: ws.c:305

◆ ws_pragma_use()

void ws_pragma_use ( WsCompilerPtr  compiler,
WsUInt32  line,
char *  identifier,
WsUtf8String url 
)

Definition at line 220 of file wsstree.c.

References WsCompilerRec::bc, Octstr::data, error(), Octstr::len, WsPragmaUseRec::line, WsCompilerRec::pragma_use_hash, url, WsPragmaUseRec::urlindex, ws_bc_add_const_utf8_string(), ws_calloc(), ws_error_memory(), ws_free(), ws_hash_get(), ws_hash_put(), ws_lexer_free_block(), ws_lexer_free_utf8(), and ws_src_error().

Referenced by yyparse().

222 {
223  WsPragmaUse *u = ws_calloc(1, sizeof(*u));
224  WsPragmaUse *uold;
225 
226  /* Do we already know this pragma? */
227  uold = ws_hash_get(compiler->pragma_use_hash, identifier);
228  if (uold) {
229  ws_src_error(compiler, line, "redefinition of pragma `%s'", identifier);
230  ws_src_error(compiler, uold->line, "`%s' previously defined here",
231  identifier);
232  goto error_cleanup;
233  }
234 
235  if (u == NULL)
236  goto error;
237 
238  u->line = line;
239 
240  /* Insert the URL to the byte-code module. */
241  if (!ws_bc_add_const_utf8_string(compiler->bc, &u->urlindex, url->data,
242  url->len))
243  goto error;
244 
245  /* Add it to the use pragma hash. */
246  if (!ws_hash_put(compiler->pragma_use_hash, identifier, u))
247  goto error;
248 
249  /* Cleanup. */
250 
251  ws_lexer_free_block(compiler, identifier);
252  ws_lexer_free_utf8(compiler, url);
253 
254  return;
255 
256  /* Error handling. */
257 
258 error:
259 
260  ws_error_memory(compiler);
261 
262 error_cleanup:
263 
264  ws_free(u);
265  ws_lexer_free_block(compiler, identifier);
266  ws_lexer_free_utf8(compiler, url);
267 }
void error(int err, const char *fmt,...)
Definition: log.c:648
void * ws_calloc(size_t num, size_t size)
Definition: wsalloc.c:83
WsHashPtr pragma_use_hash
Definition: wsint.h:234
void ws_free(void *ptr)
Definition: wsalloc.c:139
WsUInt16 urlindex
Definition: wsstree.h:153
WsUInt32 line
Definition: wsstree.h:149
void ws_lexer_free_block(WsCompiler *compiler, void *ptr)
Definition: ws.c:281
WsBc * bc
Definition: wsint.h:218
WsBool ws_bc_add_const_utf8_string(WsBc *bc, WsUInt16 *index_return, const unsigned char *data, size_t len)
Definition: wsbc.c:912
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121
void ws_lexer_free_utf8(WsCompiler *compiler, WsUtf8String *string)
Definition: ws.c:305
static Octstr * url
Definition: test_xmlrpc.c:84
void ws_src_error(WsCompilerPtr compiler, WsUInt32 line, char *message,...)
Definition: wserror.c:145
WsBool ws_hash_put(WsHashPtr hash, const char *name, void *data)
Definition: wshash.c:126
void * ws_hash_get(WsHashPtr hash, const char *name)
Definition: wshash.c:167
void ws_error_memory(WsCompilerPtr compiler)
Definition: wserror.c:107

◆ ws_pragma_use_hash_create()

WsHashPtr ws_pragma_use_hash_create ( void  )

Definition at line 214 of file wsstree.c.

References pragma_use_hash_destructor(), and ws_hash_create().

Referenced by compile_stream().

215 {
217 }
static void pragma_use_hash_destructor(void *item, void *context)
Definition: wsstree.c:208
WsHashPtr ws_hash_create(WsHashItemDestructor destructor, void *context)
Definition: wshash.c:103

◆ ws_stmt_block()

WsStatement* ws_stmt_block ( WsCompilerPtr  compiler,
WsUInt32  first_line,
WsUInt32  last_line,
WsList block 
)

◆ ws_stmt_break()

WsStatement* ws_stmt_break ( WsCompilerPtr  compiler,
WsUInt32  line 
)

◆ ws_stmt_continue()

WsStatement* ws_stmt_continue ( WsCompilerPtr  compiler,
WsUInt32  line 
)

◆ ws_stmt_empty()

WsStatement* ws_stmt_empty ( WsCompilerPtr  compiler,
WsUInt32  line 
)

◆ ws_stmt_expr()

WsStatement* ws_stmt_expr ( WsCompilerPtr  compiler,
WsUInt32  line,
WsExpression expr 
)

◆ ws_stmt_for()

WsStatement* ws_stmt_for ( WsCompilerPtr  compiler,
WsUInt32  line,
WsList init,
WsExpression e1,
WsExpression e2,
WsExpression e3,
WsStatement stmt 
)

Definition at line 1447 of file wsstree.c.

References init, WsStatementRec::s_for, stmt_alloc(), WsStatementRec::u, and WS_STMT_FOR.

Referenced by yyparse().

1450 {
1451  WsStatement *stmt = stmt_alloc(compiler, WS_STMT_FOR, line, line);
1452 
1453  if (stmt) {
1454  stmt->u.s_for.init = init;
1455  stmt->u.s_for.e1 = e1;
1456  stmt->u.s_for.e2 = e2;
1457  stmt->u.s_for.e3 = e3;
1458  stmt->u.s_for.stmt = stmt_body;
1459  }
1460 
1461  return stmt;
1462 }
static WsStatement * stmt_alloc(WsCompiler *compiler, WsStatementType type, WsUInt32 first_line, WsUInt32 last_line)
Definition: wsstree.c:1372
static int init
Definition: gwlib.c:69
union WsStatementRec::@129 u
struct WsStatementRec::@129::@131 s_for

◆ ws_stmt_if()

WsStatement* ws_stmt_if ( WsCompilerPtr  compiler,
WsUInt32  line,
WsExpression expr,
WsStatement s_then,
WsStatement s_else 
)

◆ ws_stmt_linearize()

void ws_stmt_linearize ( WsCompilerPtr  compiler,
WsStatement stmt 
)

◆ ws_stmt_return()

WsStatement* ws_stmt_return ( WsCompilerPtr  compiler,
WsUInt32  line,
WsExpression expr 
)

Definition at line 1491 of file wsstree.c.

References WsStatementRec::expr, stmt_alloc(), WsStatementRec::u, and WS_STMT_RETURN.

Referenced by yyparse().

1493 {
1494  WsStatement *stmt = stmt_alloc(compiler, WS_STMT_RETURN, line, line);
1495 
1496  if (stmt)
1497  stmt->u.expr = expr;
1498 
1499  return stmt;
1500 }
static WsStatement * stmt_alloc(WsCompiler *compiler, WsStatementType type, WsUInt32 first_line, WsUInt32 last_line)
Definition: wsstree.c:1372
WsExpression * expr
Definition: wsstree.h:531
union WsStatementRec::@129 u

◆ ws_stmt_variable()

WsStatement* ws_stmt_variable ( WsCompilerPtr  compiler,
WsUInt32  line,
WsList variables 
)

Definition at line 1401 of file wsstree.c.

References stmt_alloc(), WsStatementRec::u, WsStatementRec::var, and WS_STMT_VARIABLE.

Referenced by yyparse().

1403 {
1404  WsStatement *stmt = stmt_alloc(compiler, WS_STMT_VARIABLE, line, line);
1405 
1406  if (stmt)
1407  stmt->u.var = variables;
1408 
1409  return stmt;
1410 }
static WsStatement * stmt_alloc(WsCompiler *compiler, WsStatementType type, WsUInt32 first_line, WsUInt32 last_line)
Definition: wsstree.c:1372
WsList * var
Definition: wsstree.h:530
union WsStatementRec::@129 u

◆ ws_stmt_while()

WsStatement* ws_stmt_while ( WsCompilerPtr  compiler,
WsUInt32  line,
WsExpression expr,
WsStatement stmt 
)

◆ ws_variable_declaration()

WsVarDec* ws_variable_declaration ( WsCompilerPtr  compiler,
char *  name,
WsExpression expr 
)

Definition at line 78 of file wsstree.c.

References WsVarDecRec::expr, name, WsVarDecRec::name, WsCompilerRec::pool_stree, ws_error_memory(), and ws_f_malloc().

Referenced by yyparse().

80 {
81  WsVarDec *vardec = ws_f_malloc(compiler->pool_stree, sizeof(*vardec));
82 
83  if (vardec == NULL)
84  ws_error_memory(compiler);
85  else {
86  vardec->name = name;
87  vardec->expr = expr;
88  }
89 
90  return vardec;
91 }
char * name
Definition: smsc_cimd2.c:212
WsExpression * expr
Definition: wsstree.h:480
WsFastMalloc * pool_stree
Definition: wsint.h:204
void * ws_f_malloc(WsFastMalloc *pool, size_t size)
Definition: wsfalloc.c:102
void ws_error_memory(WsCompilerPtr compiler)
Definition: wserror.c:107
char * name
Definition: wsstree.h:479

◆ ws_variable_define()

WsNamespace* ws_variable_define ( WsCompilerPtr  compiler,
WsUInt32  line,
WsBool  variablep,
char *  name 
)

Definition at line 160 of file wsstree.c.

References WsNamespaceRec::line, name, WsCompilerRec::next_vindex, WsCompilerRec::variables_hash, WsNamespaceRec::vindex, ws_calloc(), ws_error_memory(), ws_free(), ws_hash_get(), ws_hash_put(), and ws_src_error().

Referenced by compile_stream(), and linearize_variable_init().

162 {
163  WsNamespace *ns;
164 
165  /* Is the symbol already defined? */
166  ns = ws_hash_get(compiler->variables_hash, name);
167  if (ns) {
168  ws_src_error(compiler, line, "redeclaration of `%s'", name);
169  ws_src_error(compiler, ns->line, "`%s' previously declared here", name);
170  return NULL;
171  }
172 
173  /* Can we still define more variables? */
174  if (compiler->next_vindex > 255) {
175  /* No we can't. */
176  ws_src_error(compiler, line, "too many local variables");
177  return NULL;
178  }
179 
180  ns = ws_calloc(1, sizeof(*ns));
181  if (ns == NULL) {
182  ws_error_memory(compiler);
183  return NULL;
184  }
185 
186  ns->line = line;
187  ns->vindex = compiler->next_vindex++;
188 
189  if (!ws_hash_put(compiler->variables_hash, name, ns)) {
190  ws_free(ns);
191  ws_error_memory(compiler);
192  return NULL;
193  }
194 
195  return ns;
196 }
void * ws_calloc(size_t num, size_t size)
Definition: wsalloc.c:83
WsUInt8 vindex
Definition: wsstree.h:119
WsUInt32 line
Definition: wsstree.h:116
void ws_free(void *ptr)
Definition: wsalloc.c:139
WsUInt32 next_vindex
Definition: wsint.h:245
char * name
Definition: smsc_cimd2.c:212
WsHashPtr variables_hash
Definition: wsint.h:246
void ws_src_error(WsCompilerPtr compiler, WsUInt32 line, char *message,...)
Definition: wserror.c:145
WsBool ws_hash_put(WsHashPtr hash, const char *name, void *data)
Definition: wshash.c:126
void * ws_hash_get(WsHashPtr hash, const char *name)
Definition: wshash.c:167
void ws_error_memory(WsCompilerPtr compiler)
Definition: wserror.c:107

◆ ws_variable_hash_create()

WsHashPtr ws_variable_hash_create ( void  )

Definition at line 154 of file wsstree.c.

References variable_hash_destructor(), and ws_hash_create().

Referenced by compile_stream().

155 {
157 }
static void variable_hash_destructor(void *item, void *context)
Definition: wsstree.c:148
WsHashPtr ws_hash_create(WsHashItemDestructor destructor, void *context)
Definition: wshash.c:103

◆ ws_variable_lookup()

WsNamespace* ws_variable_lookup ( WsCompilerPtr  compiler,
char *  name 
)

Definition at line 199 of file wsstree.c.

References name, WsCompilerRec::variables_hash, and ws_hash_get().

Referenced by ws_expr_linearize().

200 {
201  return ws_hash_get(compiler->variables_hash, name);
202 }
char * name
Definition: smsc_cimd2.c:212
WsHashPtr variables_hash
Definition: wsint.h:246
void * ws_hash_get(WsHashPtr hash, const char *name)
Definition: wshash.c:167
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.