📄 wsstree.h
字号:
/* ==================================================================== * The Kannel Software License, Version 1.0 * * Copyright (c) 2001-2004 Kannel Group * Copyright (c) 1998-2001 WapIT Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Kannel Group (http://www.kannel.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Kannel" and "Kannel Group" must not be used to * endorse or promote products derived from this software without * prior written permission. For written permission, please * contact org@kannel.org. * * 5. Products derived from this software may not be called "Kannel", * nor may "Kannel" appear in their name, without prior written * permission of the Kannel Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE KANNEL GROUP OR ITS CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Kannel Group. For more information on * the Kannel Group, please see <http://www.kannel.org/>. * * Portions of this software are based upon software originally written at * WapIT Ltd., Helsinki, Finland for the Kannel project. */ /* * * wsstree.h * * Author: Markku Rossi <mtr@iki.fi> * * Copyright (c) 1999-2000 WAPIT OY LTD. * All rights reserved. * * Syntax tree creation, manipulation and byte-code assembler * generation. * */#ifndef WSSTREE_H#define WSSTREE_H/********************* Linked list for syntax tree items ****************//* A list item. */struct WsListItemRec{ struct WsListItemRec *next; void *data;};typedef struct WsListItemRec WsListItem;/* The linked list object. */struct WsListRec{ WsListItem *head; WsListItem *tail; WsUInt32 num_items; /* These are used in blocks to record the first and last line information. They might also be used in other grammar constructs. */ WsUInt32 first_line; WsUInt32 last_line;};typedef struct WsListRec WsList;/* Create a new syntax tree linked list for the compiler `compiler'. The list is allocated from the `compiler->pool_stree' fast malloc pool. */WsList *ws_list_new(WsCompilerPtr compiler);/* Append the item `value' to the end of the list `list'. The item is allocated from the `compiler->pool_stree' fast malloc pool. */void ws_list_append(WsCompilerPtr compiler, WsList *list, void *value);/********************* Namespace for arguments and locals ***************//* A namespace record. */struct WsNamespaceRec{ /* The line where this argument or local variable is declared. */ WsUInt32 line; /* The index of this variable. */ WsUInt8 vindex;};typedef struct WsNamespaceRec WsNamespace;/* Create a new variable hash. */WsHashPtr ws_variable_hash_create(void);/* Define the new local variable or argument `name' to the local variables namespace. The argument `line' specifies the location where the variable `name' is defined. The argument `variablep' is WS_TRUE for local variables and WS_FALSE for arguments. The function performs all necessary initializations and sanity checks needed. It will also report errors, etc. The function returns NULL if there were any errors. */WsNamespace *ws_variable_define(WsCompilerPtr compiler, WsUInt32 line, WsBool variablep, char *name);/* Lookup the variable `name' from the variables namespace. The function returns NULL if the variable `name' is undefined. The function does not report any errors. */WsNamespace *ws_variable_lookup(WsCompilerPtr compiler, char *name);/********************* Top-level declarations ***************************//* An external compilation unit pragma. */struct WsPragmaUseRec{ /* The line number of the pragma. */ WsUInt32 line; /* The byte-code pool constant index of the external compilation unit URL. */ WsUInt16 urlindex;};typedef struct WsPragmaUseRec WsPragmaUse;/* Create a hash for the external compilation unit pragmas. */WsHashPtr ws_pragma_use_hash_create(void);/* Add a new external compilation unit pragma to the compiler `compiler'. The function inserts the URL string `url' to the byte-code structure of the compiler `compiler'. It updates the external compilation unit hash to have mapping from the identifier `identifier' to the URL `url' (or its constant index). The function reports errors if the identifier `identifier' does already have a mapping the external compilation unit namespace. */void ws_pragma_use(WsCompilerPtr compiler, WsUInt32 line, char *identifier, WsUtf8String *url);/* MetaBody handling of the `use meta' pragmas. */struct WsPragmaMetaBodyRec{ WsUtf8String *property_name; WsUtf8String *content; WsUtf8String *scheme;};typedef struct WsPragmaMetaBodyRec WsPragmaMetaBody;/* Create a meta body pragma. */WsPragmaMetaBody *ws_pragma_meta_body(WsCompilerPtr compiler, WsUtf8String *property_name, WsUtf8String *content, WsUtf8String *scheme);/* Free the MetaBody `mb'. */void ws_pragma_meta_body_free(WsCompilerPtr compiler, WsPragmaMetaBody *mb);/* A top-level function declaration. */struct WsFunctionRec{ WsUInt8 findex; WsBool externp; char *name; WsUInt32 line; WsList *params; WsList *block; /* The usage count of this function. This is used when sorting the functions by their usage count. */ WsUInt32 usage_count;};typedef struct WsFunctionRec WsFunction;/* Function hash item. The function hash contains mapping from the function names and their usage counts to the actual function declaration. */struct WsFunctionHashRec{ /* Does this mapping have a function declaration. */ WsBool defined; /* If declared, this is the index. */ WsUInt8 findex; WsUInt32 usage_count;};typedef struct WsFunctionHashRec WsFunctionHash;/* Create a new hash for functions. */WsHashPtr ws_function_hash_create(void);/* Returns a pointer to the function hash item for the function name `name'. The function creates a new hash slot if the name `name' is currently unknown. The function returns NULL if the memory allocation failed. */WsFunctionHash *ws_function_hash(WsCompilerPtr compiler, char *name);/* Add a new function definition to the compiler `compiler'. The argument `externp' specifies whether the function is extern or not. The argument `name' is the name of the function. The function name is ws_malloc() allocated and must be freed when it is not needed anymore. The argument `line' specifies the definition location of the function. It is the line where the function name was in the source stream. The argument `params' contains the formal parameters of the function and its body is specified in the argument `block'. */void ws_function(WsCompilerPtr compiler, WsBool externp, char *name, WsUInt32 line, WsList *params, WsList *block);/********************* Expressions **************************************//* Expression types. */typedef enum{ 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} WsExpressionType;/* An expression. */struct WsExpressionRec{ WsExpressionType type; WsUInt32 line; union { struct { struct WsExpressionRec *left; struct WsExpressionRec *right; } comma; struct { /* The identifier that is modified. */ char *identifier; /* The type of the assignment. This is the assignment token value: '=', tMULA, tDA, ... */ int op; /* The expression to assign to the identifier `identifier'. */ struct WsExpressionRec *expr; } assign; struct { struct WsExpressionRec *e_cond; struct WsExpressionRec *e_then; struct WsExpressionRec *e_else; } conditional; struct {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -