Subversion Repositories tendra.SVN

Rev

Rev 5 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5 Rev 6
Line -... Line 1...
-
 
1
/*
-
 
2
 * Copyright (c) 2002-2006 The TenDRA Project <http://www.tendra.org/>.
-
 
3
 * All rights reserved.
-
 
4
 *
-
 
5
 * Redistribution and use in source and binary forms, with or without
-
 
6
 * modification, are permitted provided that the following conditions are met:
-
 
7
 *
-
 
8
 * 1. Redistributions of source code must retain the above copyright notice,
-
 
9
 *    this list of conditions and the following disclaimer.
-
 
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
-
 
11
 *    this list of conditions and the following disclaimer in the documentation
-
 
12
 *    and/or other materials provided with the distribution.
-
 
13
 * 3. Neither the name of The TenDRA Project nor the names of its contributors
-
 
14
 *    may be used to endorse or promote products derived from this software
-
 
15
 *    without specific, prior written permission.
-
 
16
 *
-
 
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
-
 
18
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-
 
19
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-
 
20
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
-
 
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-
 
22
 * EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-
 
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-
 
24
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-
 
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-
 
26
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-
 
27
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
28
 *
-
 
29
 * $Id$
-
 
30
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1997
32
    		 Crown Copyright (c) 1997
3
    
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
36
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
37
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
38
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
39
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
40
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
41
    shall be deemed to be acceptance of the following conditions:-
12
    
42
 
13
        (1) Its Recipients shall ensure that this Notice is
43
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
44
        reproduced upon any copies or amended versions of it;
15
    
45
 
16
        (2) Any amended version of it shall be clearly marked to
46
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
47
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
48
        for the relevant amendment or amendments;
19
    
49
 
20
        (3) Its onward transfer from a recipient to another
50
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
51
        party shall be deemed to be that party's acceptance of
22
        these conditions;
52
        these conditions;
23
    
53
 
24
        (4) DERA gives no warranty or assurance as to its
54
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
55
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
56
        no liability whatsoever in relation to any use to which
27
        it may be put.
57
        it may be put.
28
*/
58
*/
29
 
59
 
30
 
60
 
31
#ifndef C_TYPES_INCLUDED
61
#ifndef C_TYPES_INCLUDED
32
#define C_TYPES_INCLUDED
62
#define C_TYPES_INCLUDED
33
 
63
 
34
 
64
 
35
/*
65
/*
36
    CLEAN UP NAMESPACE
66
 * CLEAN UP NAMESPACE
37
 
67
 *
38
    Certain symbols need to be undefined on some systems.  It is convenient
68
 * Certain symbols need to be undefined on some systems. It is convenient to
39
    to do this here as this header is usually included directly after any
69
 * do this here as this header is usually included directly after any system
40
    system headers.
70
 * headers.
41
*/
71
 */
42
 
72
 
43
#ifdef FLOAT
73
#ifdef FLOAT
44
#undef FLOAT
74
#undef FLOAT
45
#endif
75
#endif
46
 
76
 
47
#ifdef ulong
77
#ifdef ulong
48
#undef ulong
78
#undef ulong
49
#endif
79
#endif
50
 
80
 
51
 
81
 
52
/*
82
/*
53
    BASIC TYPES
83
 * BASIC TYPES
54
 
84
 *
55
    All characters and strings within the program are represented in terms
85
 * All characters and strings within the program are represented in terms of
56
    of the type character.  In particular, the type string is defined to
86
 * the type character. In particular, the type string is defined to be
57
    be chararacter *.  ulong is defined as a macro to avoid duplicate
87
 * chararacter *. ulong is defined as a macro to avoid duplicate definitions
58
    definitions in the system headers.
88
 * in the system headers.
59
*/
89
 */
60
 
90
 
61
typedef unsigned char character ;
91
typedef unsigned char character;
62
#define ulong ulong_type
92
#define ulong ulong_type
63
#define CONST_S CONST
93
#define CONST_S CONST
64
 
94
 
65
 
95
 
66
/*
96
/*
67
    CONST TOKENS
97
 * CONST TOKENS
68
 
98
 *
69
    The tokens generated by the calculus toolset use const to indicate
99
 * The tokens generated by the calculus toolset use const to indicate run-time
70
    run-time constant expression tokens.  Older versions of the TenDRA
100
 * constant expression tokens. Older versions of the TenDRA C producer which
71
    C producer which do not understand const tokens may suppress them
101
 * do not understand const tokens may suppress them by defining
72
    by defining NO_CONST_TOKEN.
102
 * NO_CONST_TOKEN.
73
*/
103
 */
74
 
104
 
75
#ifdef NO_CONST_TOKEN
105
#ifdef NO_CONST_TOKEN
76
#define const
106
#define const
77
#endif
107
#endif
78
 
108
 
79
 
109
 
80
/*
110
/*
81
    MAIN TYPE SYSTEM
111
 *  MAIN TYPE SYSTEM
82
 
112
 *
83
    The main type system is generated using the calculus tool.  See
113
 *  The main type system is generated using the calculus tool. See c_class.alg
84
    c_class.alg for more details.
114
 *  for more details.
85
*/
115
 */
86
 
116
 
87
#include "c_class.h"
117
#include "c_class.h"
88
 
-
 
89
 
-
 
90
/*
-
 
91
    DEBUG MEMORY ALLOCATION ROUTINES
-
 
92
 
118
 
-
 
119
 
-
 
120
/*
-
 
121
 * DEBUG MEMORY ALLOCATION ROUTINES
-
 
122
 *
93
    In debug mode an alternative memory allocation scheme allowing for
123
 * In debug mode an alternative memory allocation scheme allowing for run-time
94
    run-time type information is implemented.
124
 * type information is implemented.
95
*/
125
 */
96
 
126
 
97
#ifdef RUNTIME
127
#ifdef RUNTIME
98
#if c_class_IMPLEMENTATION
128
#if c_class_IMPLEMENTATION
99
extern c_class *debug_c_class PROTO_S ( ( unsigned, unsigned ) ) ;
129
extern c_class *debug_c_class(unsigned, unsigned);
100
#undef GEN_c_class
130
#undef GEN_c_class
101
#define GEN_c_class( A, B )	debug_c_class ( ( unsigned ) ( A ), ( B ) )
131
#define GEN_c_class(A, B)	debug_c_class((unsigned)(A), (B))
102
#define TYPEID( A )		( ( A ) [-1].ag_tag )
132
#define TYPEID(A)		((A)[-1].ag_tag)
103
#define TYPEID_free		( ( unsigned ) 42 )
133
#define TYPEID_free		((unsigned)42)
104
#endif
134
#endif
105
#endif
135
#endif
106
 
136
 
107
 
137
 
108
/*
138
/*
109
    SYNONYMS FOR CALCULUS CONSTRUCTS
139
 * SYNONYMS FOR CALCULUS CONSTRUCTS
110
 
140
 *
111
    These macros give synonyms for various constructs defined within the
141
 * These macros give synonyms for various constructs defined within the
112
    calculus plus some other useful constructs.
142
 * calculus plus some other useful constructs.
113
*/
143
 */
114
 
144
 
115
#define btype_struct		btype_struct_
145
#define btype_struct		btype_struct_
116
#define btype_union		btype_union_
146
#define btype_union		btype_union_
117
#define btype_enum		btype_enum_
147
#define btype_enum		btype_enum_
118
#define cinfo_struct		cinfo_struct_
148
#define cinfo_struct		cinfo_struct_
119
#define cinfo_union		cinfo_union_
149
#define cinfo_union		cinfo_union_
120
#define destroy			destroy_c_class
150
#define destroy			destroy_c_class
121
#define null_tag		( ( unsigned ) 0xffff )
151
#define null_tag		((unsigned)0xffff)
122
#define NULL_string		( ( string ) NULL )
152
#define NULL_string		((string)NULL)
123
 
153
 
124
#if LANGUAGE_C
154
#if LANGUAGE_C
125
#define cv_lang			cv_c
155
#define cv_lang			cv_c
126
#define dspec_lang		dspec_c
156
#define dspec_lang		dspec_c
127
#define btype_lang		btype_struct
157
#define btype_lang		btype_struct
Line 132... Line 162...
132
#define btype_lang		btype_class
162
#define btype_lang		btype_class
133
#endif
163
#endif
134
 
164
 
135
 
165
 
136
/*
166
/*
137
    DISTINGUISHED LINKAGE VALUES
167
 * DISTINGUISHED LINKAGE VALUES
138
 
168
 *
139
    These values are used as distinguished linkage numbers for use in
169
 * These values are used as distinguished linkage numbers for use in the
140
    the output routines.  Unassigned linkage numbers are given the value
170
 * output routines. Unassigned linkage numbers are given the value LINK_NONE.
141
    LINK_NONE.  External linkage numbers are or-ed with the value
171
 * External linkage numbers are or-ed with the value LINK_EXTERN to
142
    LINK_EXTERN to distinguish them from internal linkage numbers.
172
 * distinguish them from internal linkage numbers.
143
*/
173
 */
144
 
174
 
145
#if FS_NUMBER_SUFFIX
175
#if FS_NUMBER_SUFFIX
146
#define LINK_NONE		( ( ulong ) 0xffffffffUL )
176
#define LINK_NONE		((ulong)0xffffffffUL)
147
#define LINK_EXTERN		( ( ulong ) 0x80000000UL )
177
#define LINK_EXTERN		((ulong)0x80000000UL)
148
#define LINK_ZERO		( ( ulong ) 0xfffffffeUL )
178
#define LINK_ZERO		((ulong)0xfffffffeUL)
149
#define LINK_TOKDEF		( ( ulong ) 0xfffffffdUL )
179
#define LINK_TOKDEF		((ulong)0xfffffffdUL)
150
#else
180
#else
151
#define LINK_NONE		( ( ulong ) 0xffffffff )
181
#define LINK_NONE		((ulong)0xffffffff)
152
#define LINK_EXTERN		( ( ulong ) 0x80000000 )
182
#define LINK_EXTERN		((ulong)0x80000000)
153
#define LINK_ZERO		( ( ulong ) 0xfffffffe )
183
#define LINK_ZERO		((ulong)0xfffffffe)
154
#define LINK_TOKDEF		( ( ulong ) 0xfffffffd )
184
#define LINK_TOKDEF		((ulong)0xfffffffd)
155
#endif
185
#endif
156
 
186
 
157
 
187
 
158
/*
188
/**
159
    TYPE REPRESENTING A CHECKING SCOPE
189
 * TYPE REPRESENTING A CHECKING SCOPE
160
 
190
 *
161
    This type is used to represent a checking scope, describing which
191
 * This type is used to represent a checking scope, describing which checks
162
    checks should be applied in a particular part of the program.  It
192
 * should be applied in a particular part of the program. It consists of an
163
    consists of an array of option states - one for each option which
193
 * array of option states - one for each option which can be set - plus a
164
    can be set - plus a pointer to the enclosing checking scope.  A
194
 * pointer to the enclosing checking scope. A scope may have an associated
165
    scope may have an associated name.  Also a list of all scopes is
195
 * name. Also a list of all scopes is maintained.
166
    maintained.
-
 
167
*/
196
 */
168
 
197
 
169
typedef unsigned char OPTION ;
198
typedef unsigned char OPTION;
-
 
199
 
-
 
200
typedef struct opt_tag {
-
 
201
	OPTION *opt;
-
 
202
	OPTION *set;
-
 
203
	DECL_SPEC lnk_opt[2];
-
 
204
	unsigned long val_opt[1];
-
 
205
	struct opt_tag *prev;
-
 
206
	HASHID name;
-
 
207
	struct opt_tag *next;
-
 
208
} OPTIONS;
170
 
209
 
-
 
210
 
-
 
211
/**
-
 
212
 * TYPE REPRESENTING A PREPROCESSING TOKEN
-
 
213
 *
-
 
214
 * This type represents a preprocessing token. This consists of a token value,
-
 
215
 * corresponding to the macros defined in syntax.h, plus any associated data.
-
 
216
 * In some instances the space field is used to indicate that the token is
-
 
217
 * preceded by a white-space. The next field points to the next token.
-
 
218
 */
-
 
219
 
171
typedef struct opt_tag {
220
typedef struct pptok_tag {
-
 
221
	int tok;
-
 
222
	struct pptok_tag *next;
-
 
223
	union {
-
 
224
		/* Associated data */
-
 
225
		int sint;
-
 
226
		string text;
-
 
227
		unsigned uint;
-
 
228
		character buff[8];
-
 
229
		EXP exp;
-
 
230
		NAT nat;
172
    OPTION *opt ;
231
		FLOAT flt;
-
 
232
		NAMESPACE ns;
-
 
233
		STRING strlit;
-
 
234
		TYPE type;
-
 
235
		struct {
-
 
236
			/* Identifier */
-
 
237
			HASHID hash;
173
    OPTION *set ;
238
			IDENTIFIER use;
-
 
239
		} id;
-
 
240
		struct {
-
 
241
			/* String */
-
 
242
			string start;
-
 
243
			string end;
-
 
244
		} str;
-
 
245
		struct {
174
    DECL_SPEC lnk_opt [2] ;
246
			/* Macro parameter */
-
 
247
			HASHID hash;
175
    unsigned long val_opt [1] ;
248
			unsigned long no;
-
 
249
		} par;
-
 
250
		struct {
-
 
251
			/* Location */
176
    struct opt_tag *prev ;
252
			unsigned long line;
-
 
253
			PTR(POSITION)posn;
-
 
254
		} loc;
-
 
255
		struct {
-
 
256
			/* Token application */
177
    HASHID name ;
257
			IDENTIFIER id;
178
    struct opt_tag *next ;
258
			struct pptok_tag *args;
-
 
259
		} tok;
-
 
260
	} pp_data;
-
 
261
	unsigned long pp_space;
-
 
262
	OPTIONS *pp_opts;
179
} OPTIONS ;
263
} PPTOKEN;
180
 
264
 
181
 
265
 
182
/*
266
/**
183
    TYPE REPRESENTING A PREPROCESSING TOKEN
267
 * TYPE REPRESENTING A SERIES OF BITS
184
 
-
 
185
    This type represents a preprocessing token.  This consists of a token
-
 
186
    value, corresponding to the macros defined in syntax.h, plus any
-
 
187
    associated data.  In some instances the space field is used to indicate
-
 
188
    that the token is preceded by a white-space.  The next field points
-
 
189
    to the next token.
-
 
190
*/
-
 
191
 
-
 
192
typedef struct pptok_tag {
-
 
193
    int tok ;
-
 
194
    struct pptok_tag *next ;
-
 
195
    union {
-
 
196
	/* Associated data */
-
 
197
	int sint ;
-
 
198
	string text ;
-
 
199
	unsigned uint ;
-
 
200
	character buff [8] ;
-
 
201
	EXP exp ;
-
 
202
	NAT nat ;
-
 
203
	FLOAT flt ;
-
 
204
	NAMESPACE ns ;
-
 
205
	STRING strlit ;
-
 
206
	TYPE type ;
-
 
207
	struct {
-
 
208
	    /* Identifier */
-
 
209
	    HASHID hash ;
-
 
210
	    IDENTIFIER use ;
-
 
211
	} id ;
-
 
212
	struct {
-
 
213
	    /* String */
-
 
214
	    string start ;
-
 
215
	    string end ;
-
 
216
	} str ;
-
 
217
	struct {
-
 
218
	    /* Macro parameter */
-
 
219
	    HASHID hash ;
-
 
220
	    unsigned long no ;
-
 
221
	} par ;
-
 
222
	struct {
-
 
223
	    /* Location */
-
 
224
	    unsigned long line ;
-
 
225
	    PTR ( POSITION ) posn ;
-
 
226
	} loc ;
-
 
227
	struct {
-
 
228
	    /* Token application */
-
 
229
	    IDENTIFIER id ;
-
 
230
	    struct pptok_tag *args ;
-
 
231
	} tok ;
-
 
232
    } pp_data ;
-
 
233
    unsigned long pp_space ;
-
 
234
    OPTIONS *pp_opts ;
-
 
235
} PPTOKEN ;
-
 
236
 
-
 
237
 
-
 
238
/*
268
 *
239
    TYPE REPRESENTING A SERIES OF BITS
-
 
240
 
-
 
241
    A bitstream consists of an array of characters comprising the
269
 * A bitstream consists of an array of characters comprising the bits
242
    bits themselves, plus the current offset (in bytes and bits) of the
270
 * themselves, plus the current offset (in bytes and bits) of the end of these
243
    end of these bits.  A pointer to the previous bitstream is used to
271
 * bits. A pointer to the previous bitstream is used to chain bitstreams
244
    chain bitstreams together.
-
 
245
*/
-
 
246
 
-
 
247
typedef struct bits_tag {
-
 
248
    string text ;
272
 * together.
249
    unsigned bytes ;
-
 
250
    unsigned bits ;
-
 
251
    unsigned size ;
-
 
252
    FILE *file ;
-
 
253
    gen_ptr link ;
-
 
254
    struct bits_tag *prev ;
-
 
255
} BITSTREAM ;
-
 
256
 
-
 
257
 
-
 
258
/*
-
 
259
    TYPE REPRESENTING A CHARACTER BUFFER
-
 
260
 
-
 
261
    A character buffer consists of an array of characters and a pointer
-
 
262
    to the current position in the buffer.
-
 
263
*/
273
*/
-
 
274
 
-
 
275
typedef struct bits_tag {
-
 
276
	string text;
-
 
277
	unsigned bytes;
-
 
278
	unsigned bits;
-
 
279
	unsigned size;
-
 
280
	FILE *file;
-
 
281
	gen_ptr link;
-
 
282
	struct bits_tag *prev;
-
 
283
} BITSTREAM;
-
 
284
 
-
 
285
 
-
 
286
/**
-
 
287
 * TYPE REPRESENTING A CHARACTER BUFFER
-
 
288
 *
-
 
289
 * A character buffer consists of an array of characters and a pointer to the
-
 
290
 * current position in the buffer.
-
 
291
 */
264
 
292
 
265
typedef struct buff_tag {
293
typedef struct buff_tag {
266
    string start ;
294
	string start;
267
    string posn ;
295
	string posn;
268
    string end ;
296
	string end;
269
    FILE *file ;
297
	FILE *file;
270
} BUFFER ;
298
} BUFFER;
271
 
299
 
272
#define NULL_buff		{ NULL, NULL, NULL, NULL }
300
#define NULL_buff	{ NULL, NULL, NULL, NULL }
273
 
301
 
274
 
302
 
275
#endif
303
#endif