Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
wsint.h
Go to the documentation of this file.
1 /* ====================================================================
2  * The Kannel Software License, Version 1.0
3  *
4  * Copyright (c) 2001-2016 Kannel Group
5  * Copyright (c) 1998-2001 WapIT Ltd.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Kannel Group (http://www.kannel.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Kannel" and "Kannel Group" must not be used to
28  * endorse or promote products derived from this software without
29  * prior written permission. For written permission, please
30  * contact org@kannel.org.
31  *
32  * 5. Products derived from this software may not be called "Kannel",
33  * nor may "Kannel" appear in their name, without prior written
34  * permission of the Kannel Group.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE KANNEL GROUP OR ITS CONTRIBUTORS
40  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
41  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
42  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
43  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
44  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
45  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
46  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47  * ====================================================================
48  *
49  * This software consists of voluntary contributions made by many
50  * individuals on behalf of the Kannel Group. For more information on
51  * the Kannel Group, please see <http://www.kannel.org/>.
52  *
53  * Portions of this software are based upon software originally written at
54  * WapIT Ltd., Helsinki, Finland for the Kannel project.
55  */
56 
57 /*
58  *
59  * wsint.h
60  *
61  * Author: Markku Rossi <mtr@iki.fi>
62  *
63  * Copyright (c) 1999-2000 WAPIT OY LTD.
64  * All rights reserved.
65  *
66  * Operating system specific environment and general helper utilities
67  * for the WMLScript tools.
68  *
69  */
70 
71 #ifndef WSINT_H
72 #define WSINT_H
73 
74 #include "gw-config.h"
75 
76 #include <stdio.h>
77 #include <stdlib.h>
78 #include <string.h>
79 #include <stdarg.h>
80 #include <errno.h>
81 #include <math.h>
82 
83 #if HAVE_UNISTD_H
84 #include <unistd.h>
85 #endif /* HAVE_UNISTD_H */
86 
87 #include "gwlib/gwassert.h"
88 
89 /********************* Types and definitions ****************************/
90 
91 /* Platform dependent line terminator. This is used in diagnostic and
92  error messages to terminate output lines. */
93 
94 #ifdef WIN32
95 #define WS_LINE_TERMINATOR "\r\n"
96 #else /* not WIN32 */
97 #define WS_LINE_TERMINATOR "\n"
98 #endif /* not WIN32 */
99 
100 /* Data types. */
101 
102 #define WS_INT8_MIN -128
103 #define WS_INT8_MAX 127
104 
105 #define WS_INT16_MIN -32768
106 #define WS_INT16_MAX 32767
107 
108 #define WS_INT32_MIN -2147483648
109 #define WS_INT32_MAX 2147483647
110 
111 /* Integer types. */
112 
113 typedef unsigned char WsByte;
114 
115 typedef signed char WsInt8;
116 typedef unsigned char WsUInt8;
117 
118 typedef signed short WsInt16;
119 typedef unsigned short WsUInt16;
120 
121 typedef signed long WsInt32;
122 typedef unsigned long WsUInt32;
123 
124 /* Internally we use as good floating point numbers as possible. This
125  way we avoid losing data in constant folding, etc. */
126 typedef double WsFloat;
127 
128 typedef enum
129 {
132 } WsBool;
133 
134 
135 /* Error flags. */
136 
137 /* Out of memory. */
138 #define WS_ERROR_B_MEMORY 0x01
139 
140 /* The input program was syntactically incorrect. */
141 #define WS_ERROR_B_SYNTAX 0x02
142 
143 /* The input program was semantically incorrect. We managed to parse
144  it, but it contained some semantical errors. For example, a local
145  variable was defined twice. */
146 #define WS_ERROR_B_SEMANTIC 0x04
147 
148 /********************* Include sub-module headers ***********************/
149 
150 #include "ws.h"
151 #include "wserror.h"
152 #include "wsutf8.h"
153 #include "wsieee754.h"
154 #include "wsbuffer.h"
155 #include "wsencode.h"
156 #include "wsalloc.h"
157 #include "wsfalloc.h"
158 #include "wsstream.h"
159 #include "wshash.h"
160 #include "wsbc.h"
161 
162 #include "wsstree.h"
163 #include "wsasm.h"
164 #include "wsopt.h"
165 #include "wsstdlib.h"
166 
167 /********************* The compiler handle ******************************/
168 
169 #if WS_DEBUG
170 /* The currently active compiler. Just for debugging purposes. */
171 extern WsCompilerPtr global_compiler;
172 #endif /* WS_DEBUG */
173 
174 /* A structure to register the currently active `continue-break'
175  labels. These are allocated from the syntax-tree pool. */
177 {
181 };
182 
184 
185 #define COMPILER_MAGIC (0xfefe0101)
187 {
188  /* A magic number of assure that a correct compiler handle is passed
189  to the parser and lexer functions. */
191 
192  /* User-specifiable parameters. */
194 
195  /* Current input stream. */
197 
198  /* The source file name and line number of the current input
199  stream. */
200  const char *input_name;
202 
203  /* Fast-malloc pool for the syntax tree items. */
205 
206  /* Fast-malloc pool for the symbolic assembler instructions. */
208 
209  /* List of active memory blocks, allocated by the lexer. When lexer
210  allocates string or symbol tokens, their dynamically allocated
211  data is registered to this list. The parser removes the items
212  when needed, but if the parsing fails, the items can be freed
213  from this list during the cleanup. */
216 
217  /* The byte-code object. */
219 
220  /* The next label for the assembler generation. */
222 
223  /* The assembler code, currently begin constructed on this compiler. */
226 
227  /* Buffer holding the linearized byte-code for the current symbolic
228  assembler. */
230 
231  /* The syntax tree items, found from the source stream. */
232 
233  /* External compilation unit pragmas. */
235 
236  /* Functions. */
239 
240  /* A mapping from function names to their declarations in
241  `functions'. */
243 
244  /* A namespace for function arguments and local variables. */
247 
248  /* Registry for the currently active `continue-break' labels. */
250 
251  /* Statistics about the compilation. */
252 
255 
258 
259  /* Bitmask to record occurred errors. This is used in error
260  generation and reporting to make sane error messages. */
262 
263  /* The latest line where a syntax error occurred. The compiler do
264  not print multiple syntax errors from the same line. */
266 };
267 
268 typedef struct WsCompilerRec WsCompiler;
269 
270 /********************* Lexer and parser *********************************/
271 
272 #define YYPARSE_PARAM pctx
273 #define YYLEX_PARAM pctx
274 
275 /* The lexer. */
276 extern int yylex();
277 
278 /* Register the lexer allocated block `ptr' to the compiler's list of
279  active blocks. */
280 WsBool ws_lexer_register_block(WsCompiler *compiler, void *ptr);
281 
282 /* Register the lexer allocated UTF-8 string `string' to the
283  compiler's list of active blocks. */
285 
286 /* Unregister the block `ptr' from the compiler's list of active
287  blocks and free it. It is a fatal error if the block `ptr' does
288  not exist on the list. */
289 void ws_lexer_free_block(WsCompiler *compiler, void *ptr);
290 
291 /* Unregister an UTF-8 string `string' from the compiler's list of
292  active blocks and free it. */
293 void ws_lexer_free_utf8(WsCompiler *compiler, WsUtf8String *string);
294 
295 /* The parser. */
296 int ws_yy_parse(void *context);
297 
298 #endif /* not WSINT_H */
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
Definition: wsint.h:131
WsUInt32 num_errors
Definition: wsint.h:253
Definition: parse.c:65
unsigned long WsUInt32
Definition: wsint.h:122
WsUInt32 num_local_functions
Definition: wsint.h:257
double WsFloat
Definition: wsint.h:126
WsUInt32 magic
Definition: wsint.h:190
WsStream * input
Definition: wsint.h:196
WsUInt32 num_warnings
Definition: wsint.h:254
struct WsContBreakRec * next
Definition: wsint.h:178
WsAsmIns * asm_head
Definition: wsint.h:224
WsAsmIns * asm_tail
Definition: wsint.h:225
void ws_lexer_free_block(WsCompiler *compiler, void *ptr)
Definition: ws.c:281
WsUInt32 num_functions
Definition: wsint.h:237
signed short WsInt16
Definition: wsint.h:118
int yylex()
WsUInt32 linenum
Definition: wsint.h:201
unsigned char WsUInt8
Definition: wsint.h:116
WsAsmIns * l_cont
Definition: wsint.h:179
WsUInt32 next_vindex
Definition: wsint.h:245
const char * input_name
Definition: wsint.h:200
WsUInt32 errors
Definition: wsint.h:261
WsBc * bc
Definition: wsint.h:218
unsigned short WsUInt16
Definition: wsint.h:119
WsContBreak * cont_break
Definition: wsint.h:249
void ** lexer_active_list
Definition: wsint.h:214
void ws_lexer_free_utf8(WsCompiler *compiler, WsUtf8String *string)
Definition: ws.c:305
int ws_yy_parse(void *context)
WsBool ws_lexer_register_utf8(WsCompiler *compiler, WsUtf8String *string)
Definition: ws.c:267
WsUInt32 last_syntax_error_line
Definition: wsint.h:265
WsUInt32 next_label
Definition: wsint.h:221
WsHashPtr variables_hash
Definition: wsint.h:246
signed char WsInt8
Definition: wsint.h:115
WsBool
Definition: wsint.h:128
WsFunction * functions
Definition: wsint.h:238
WsUInt32 num_extern_functions
Definition: wsint.h:256
WsCompilerParams params
Definition: wsint.h:193
WsAsmIns * l_break
Definition: wsint.h:180
signed long WsInt32
Definition: wsint.h:121
WsFastMalloc * pool_stree
Definition: wsint.h:204
WsBool ws_lexer_register_block(WsCompiler *compiler, void *ptr)
Definition: ws.c:248
Definition: wsbc.h:186
unsigned char WsByte
Definition: wsint.h:113
WsBuffer byte_code
Definition: wsint.h:229
WsFastMalloc * pool_asm
Definition: wsint.h:207
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.