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

wsint.h

Go to the documentation of this file.
00001 /* ==================================================================== 
00002  * The Kannel Software License, Version 1.0 
00003  * 
00004  * Copyright (c) 2001-2008 Kannel Group  
00005  * Copyright (c) 1998-2001 WapIT Ltd.   
00006  * All rights reserved. 
00007  * 
00008  * Redistribution and use in source and binary forms, with or without 
00009  * modification, are permitted provided that the following conditions 
00010  * are met: 
00011  * 
00012  * 1. Redistributions of source code must retain the above copyright 
00013  *    notice, this list of conditions and the following disclaimer. 
00014  * 
00015  * 2. Redistributions in binary form must reproduce the above copyright 
00016  *    notice, this list of conditions and the following disclaimer in 
00017  *    the documentation and/or other materials provided with the 
00018  *    distribution. 
00019  * 
00020  * 3. The end-user documentation included with the redistribution, 
00021  *    if any, must include the following acknowledgment: 
00022  *       "This product includes software developed by the 
00023  *        Kannel Group (http://www.kannel.org/)." 
00024  *    Alternately, this acknowledgment may appear in the software itself, 
00025  *    if and wherever such third-party acknowledgments normally appear. 
00026  * 
00027  * 4. The names "Kannel" and "Kannel Group" must not be used to 
00028  *    endorse or promote products derived from this software without 
00029  *    prior written permission. For written permission, please  
00030  *    contact org@kannel.org. 
00031  * 
00032  * 5. Products derived from this software may not be called "Kannel", 
00033  *    nor may "Kannel" appear in their name, without prior written 
00034  *    permission of the Kannel Group. 
00035  * 
00036  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 
00037  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
00038  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
00039  * DISCLAIMED.  IN NO EVENT SHALL THE KANNEL GROUP OR ITS CONTRIBUTORS 
00040  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,  
00041  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT  
00042  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR  
00043  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,  
00044  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE  
00045  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,  
00046  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
00047  * ==================================================================== 
00048  * 
00049  * This software consists of voluntary contributions made by many 
00050  * individuals on behalf of the Kannel Group.  For more information on  
00051  * the Kannel Group, please see <http://www.kannel.org/>. 
00052  * 
00053  * Portions of this software are based upon software originally written at  
00054  * WapIT Ltd., Helsinki, Finland for the Kannel project.  
00055  */ 
00056 
00057 /*
00058  *
00059  * wsint.h
00060  *
00061  * Author: Markku Rossi <mtr@iki.fi>
00062  *
00063  * Copyright (c) 1999-2000 WAPIT OY LTD.
00064  *       All rights reserved.
00065  *
00066  * Operating system specific environment and general helper utilities
00067  * for the WMLScript tools.
00068  *
00069  */
00070 
00071 #ifndef WSINT_H
00072 #define WSINT_H
00073 
00074 #include "gw-config.h"
00075 
00076 #include <stdio.h>
00077 #include <stdlib.h>
00078 #include <string.h>
00079 #include <stdarg.h>
00080 #include <errno.h>
00081 #include <math.h>
00082 
00083 #if HAVE_UNISTD_H
00084 #include <unistd.h>
00085 #endif /* HAVE_UNISTD_H */
00086 
00087 #include "gwlib/gwassert.h"
00088 
00089 /********************* Types and definitions ****************************/
00090 
00091 /* Platform dependent line terminator.  This is used in diagnostic and
00092    error messages to terminate output lines. */
00093 
00094 #ifdef WIN32
00095 #define WS_LINE_TERMINATOR "\r\n"
00096 #else /* not WIN32 */
00097 #define WS_LINE_TERMINATOR "\n"
00098 #endif /* not WIN32 */
00099 
00100 /* Data types. */
00101 
00102 #define WS_INT8_MIN -128
00103 #define WS_INT8_MAX  127
00104 
00105 #define WS_INT16_MIN    -32768
00106 #define WS_INT16_MAX     32767
00107 
00108 #define WS_INT32_MIN    -2147483648
00109 #define WS_INT32_MAX     2147483647
00110 
00111 /* Integer types. */
00112 
00113 typedef unsigned char WsByte;
00114 
00115 typedef signed char WsInt8;
00116 typedef unsigned char WsUInt8;
00117 
00118 typedef signed short WsInt16;
00119 typedef unsigned short WsUInt16;
00120 
00121 typedef signed long WsInt32;
00122 typedef unsigned long WsUInt32;
00123 
00124 /* Internally we use as good floating point numbers as possible.  This
00125    way we avoid losing data in constant folding, etc. */
00126 typedef double WsFloat;
00127 
00128 typedef enum
00129 {
00130     WS_FALSE,
00131     WS_TRUE
00132 } WsBool;
00133 
00134 
00135 /* Error flags. */
00136 
00137 /* Out of memory. */
00138 #define WS_ERROR_B_MEMORY   0x01
00139 
00140 /* The input program was syntactically incorrect. */
00141 #define WS_ERROR_B_SYNTAX   0x02
00142 
00143 /* The input program was semantically incorrect.  We managed to parse
00144    it, but it contained some semantical errors.  For example, a local
00145    variable was defined twice. */
00146 #define WS_ERROR_B_SEMANTIC 0x04
00147 
00148 /********************* Include sub-module headers ***********************/
00149 
00150 #include "ws.h"
00151 #include "wserror.h"
00152 #include "wsutf8.h"
00153 #include "wsieee754.h"
00154 #include "wsbuffer.h"
00155 #include "wsencode.h"
00156 #include "wsalloc.h"
00157 #include "wsfalloc.h"
00158 #include "wsstream.h"
00159 #include "wshash.h"
00160 #include "wsbc.h"
00161 
00162 #include "wsstree.h"
00163 #include "wsasm.h"
00164 #include "wsopt.h"
00165 #include "wsstdlib.h"
00166 
00167 /********************* The compiler handle ******************************/
00168 
00169 #if WS_DEBUG
00170 /* The currently active compiler.  Just for debugging purposes. */
00171 extern WsCompilerPtr global_compiler;
00172 #endif /* WS_DEBUG */
00173 
00174 /* A structure to register the currently active `continue-break'
00175    labels.  These are allocated from the syntax-tree pool. */
00176 struct WsContBreakRec
00177 {
00178     struct WsContBreakRec *next;
00179     WsAsmIns *l_cont;
00180     WsAsmIns *l_break;
00181 };
00182 
00183 typedef struct WsContBreakRec WsContBreak;
00184 
00185 #define COMPILER_MAGIC (0xfefe0101)
00186 struct WsCompilerRec
00187 {
00188     /* A magic number of assure that a correct compiler handle is passed
00189        to the parser and lexer functions. */
00190     WsUInt32 magic;
00191 
00192     /* User-specifiable parameters. */
00193     WsCompilerParams params;
00194 
00195     /* Current input stream. */
00196     WsStream *input;
00197 
00198     /* The source file name and line number of the current input
00199        stream. */
00200     const char *input_name;
00201     WsUInt32 linenum;
00202 
00203     /* Fast-malloc pool for the syntax tree items. */
00204     WsFastMalloc *pool_stree;
00205 
00206     /* Fast-malloc pool for the symbolic assembler instructions. */
00207     WsFastMalloc *pool_asm;
00208 
00209     /* List of active memory blocks, allocated by the lexer.  When lexer
00210        allocates string or symbol tokens, their dynamically allocated
00211        data is registered to this list.  The parser removes the items
00212        when needed, but if the parsing fails, the items can be freed
00213        from this list during the cleanup. */
00214     void **lexer_active_list;
00215     size_t lexer_active_list_size;
00216 
00217     /* The byte-code object. */
00218     WsBc *bc;
00219 
00220     /* The next label for the assembler generation. */
00221     WsUInt32 next_label;
00222 
00223     /* The assembler code, currently begin constructed on this compiler. */
00224     WsAsmIns *asm_head;
00225     WsAsmIns *asm_tail;
00226 
00227     /* Buffer holding the linearized byte-code for the current symbolic
00228        assembler. */
00229     WsBuffer byte_code;
00230 
00231     /* The syntax tree items, found from the source stream. */
00232 
00233     /* External compilation unit pragmas. */
00234     WsHashPtr pragma_use_hash;
00235 
00236     /* Functions. */
00237     WsUInt32 num_functions;
00238     WsFunction *functions;
00239 
00240     /* A mapping from function names to their declarations in
00241        `functions'. */
00242     WsHashPtr functions_hash;
00243 
00244     /* A namespace for function arguments and local variables. */
00245     WsUInt32 next_vindex;
00246     WsHashPtr variables_hash;
00247 
00248     /* Registry for the currently active `continue-break' labels. */
00249     WsContBreak *cont_break;
00250 
00251     /* Statistics about the compilation. */
00252 
00253     WsUInt32 num_errors;
00254     WsUInt32 num_warnings;
00255 
00256     WsUInt32 num_extern_functions;
00257     WsUInt32 num_local_functions;
00258 
00259     /* Bitmask to record occurred errors.  This is used in error
00260        generation and reporting to make sane error messages. */
00261     WsUInt32 errors;
00262 
00263     /* The latest line where a syntax error occurred.  The compiler do
00264        not print multiple syntax errors from the same line. */
00265     WsUInt32 last_syntax_error_line;
00266 };
00267 
00268 typedef struct WsCompilerRec WsCompiler;
00269 
00270 /********************* Lexer and parser *********************************/
00271 
00272 /* The lexer. */
00273 extern int yylex();
00274 
00275 /* Register the lexer allocated block `ptr' to the compiler's list of
00276    active blocks. */
00277 WsBool ws_lexer_register_block(WsCompiler *compiler, void *ptr);
00278 
00279 /* Register the lexer allocated UTF-8 string `string' to the
00280    compiler's list of active blocks. */
00281 WsBool ws_lexer_register_utf8(WsCompiler *compiler, WsUtf8String *string);
00282 
00283 /* Unregister the block `ptr' from the compiler's list of active
00284    blocks and free it.  It is a fatal error if the block `ptr' does
00285    not exist on the list. */
00286 void ws_lexer_free_block(WsCompiler *compiler, void *ptr);
00287 
00288 /* Unregister an UTF-8 string `string' from the compiler's list of
00289    active blocks and free it. */
00290 void ws_lexer_free_utf8(WsCompiler *compiler, WsUtf8String *string);
00291 
00292 /* The parser. */
00293 int ws_yy_parse(void *context);
00294 
00295 #endif /* not WSINT_H */
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.