Subversion Repositories tendra.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
/*
7 7u83 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
 */
31
/*
2 7u83 32
    		 Crown Copyright (c) 1997
7 7u83 33
 
2 7u83 34
    This TenDRA(r) Computer Program is subject to Copyright
35
    owned by the United Kingdom Secretary of State for Defence
36
    acting through the Defence Evaluation and Research Agency
37
    (DERA).  It is made available to Recipients with a
38
    royalty-free licence for its use, reproduction, transfer
39
    to other parties and amendment for any purpose not excluding
40
    product development provided that any such use et cetera
41
    shall be deemed to be acceptance of the following conditions:-
7 7u83 42
 
2 7u83 43
        (1) Its Recipients shall ensure that this Notice is
44
        reproduced upon any copies or amended versions of it;
7 7u83 45
 
2 7u83 46
        (2) Any amended version of it shall be clearly marked to
47
        show both the nature of and the organisation responsible
48
        for the relevant amendment or amendments;
7 7u83 49
 
2 7u83 50
        (3) Its onward transfer from a recipient to another
51
        party shall be deemed to be that party's acceptance of
52
        these conditions;
7 7u83 53
 
2 7u83 54
        (4) DERA gives no warranty or assurance as to its
55
        quality or suitability for any purpose and DERA accepts
56
        no liability whatsoever in relation to any use to which
57
        it may be put.
58
*/
59
 
60
 
61
#ifndef C_TYPES_INCLUDED
62
#define C_TYPES_INCLUDED
63
 
64
 
65
/*
7 7u83 66
 * CLEAN UP NAMESPACE
67
 *
68
 * Certain symbols need to be undefined on some systems. It is convenient to
69
 * do this here as this header is usually included directly after any system
70
 * headers.
71
 */
2 7u83 72
 
73
#ifdef FLOAT
74
#undef FLOAT
75
#endif
76
 
77
#ifdef ulong
78
#undef ulong
79
#endif
80
 
81
 
82
/*
7 7u83 83
 * BASIC TYPES
84
 *
85
 * All characters and strings within the program are represented in terms of
86
 * the type character. In particular, the type string is defined to be
87
 * chararacter *. ulong is defined as a macro to avoid duplicate definitions
88
 * in the system headers.
89
 */
2 7u83 90
 
7 7u83 91
typedef unsigned char character;
2 7u83 92
#define ulong ulong_type
93
#define CONST_S CONST
94
 
95
 
96
/*
7 7u83 97
 * CONST TOKENS
98
 *
99
 * The tokens generated by the calculus toolset use const to indicate run-time
100
 * constant expression tokens. Older versions of the TenDRA C producer which
101
 * do not understand const tokens may suppress them by defining
102
 * NO_CONST_TOKEN.
103
 */
2 7u83 104
 
105
#ifdef NO_CONST_TOKEN
106
#define const
107
#endif
108
 
109
 
110
/*
7 7u83 111
 *  MAIN TYPE SYSTEM
112
 *
113
 *  The main type system is generated using the calculus tool. See c_class.alg
114
 *  for more details.
115
 */
2 7u83 116
 
117
#include "c_class.h"
118
 
119
 
120
/*
7 7u83 121
 * DEBUG MEMORY ALLOCATION ROUTINES
122
 *
123
 * In debug mode an alternative memory allocation scheme allowing for run-time
124
 * type information is implemented.
125
 */
2 7u83 126
 
127
#ifdef RUNTIME
128
#if c_class_IMPLEMENTATION
7 7u83 129
extern c_class *debug_c_class(unsigned, unsigned);
2 7u83 130
#undef GEN_c_class
7 7u83 131
#define GEN_c_class(A, B)	debug_c_class((unsigned)(A), (B))
132
#define TYPEID(A)		((A)[-1].ag_tag)
133
#define TYPEID_free		((unsigned)42)
2 7u83 134
#endif
135
#endif
136
 
137
 
138
/*
7 7u83 139
 * SYNONYMS FOR CALCULUS CONSTRUCTS
140
 *
141
 * These macros give synonyms for various constructs defined within the
142
 * calculus plus some other useful constructs.
143
 */
2 7u83 144
 
145
#define btype_struct		btype_struct_
146
#define btype_union		btype_union_
147
#define btype_enum		btype_enum_
148
#define cinfo_struct		cinfo_struct_
149
#define cinfo_union		cinfo_union_
150
#define destroy			destroy_c_class
7 7u83 151
#define null_tag		((unsigned)0xffff)
152
#define NULL_string		((string)NULL)
2 7u83 153
 
154
#if LANGUAGE_C
155
#define cv_lang			cv_c
156
#define dspec_lang		dspec_c
157
#define btype_lang		btype_struct
158
#define ERR_ALTERNATE		1
159
#else
160
#define cv_lang			cv_cpp
161
#define dspec_lang		dspec_cpp
162
#define btype_lang		btype_class
163
#endif
164
 
165
 
166
/*
7 7u83 167
 * DISTINGUISHED LINKAGE VALUES
168
 *
169
 * These values are used as distinguished linkage numbers for use in the
170
 * output routines. Unassigned linkage numbers are given the value LINK_NONE.
171
 * External linkage numbers are or-ed with the value LINK_EXTERN to
172
 * distinguish them from internal linkage numbers.
173
 */
2 7u83 174
 
175
#if FS_NUMBER_SUFFIX
7 7u83 176
#define LINK_NONE		((ulong)0xffffffffUL)
177
#define LINK_EXTERN		((ulong)0x80000000UL)
178
#define LINK_ZERO		((ulong)0xfffffffeUL)
179
#define LINK_TOKDEF		((ulong)0xfffffffdUL)
2 7u83 180
#else
7 7u83 181
#define LINK_NONE		((ulong)0xffffffff)
182
#define LINK_EXTERN		((ulong)0x80000000)
183
#define LINK_ZERO		((ulong)0xfffffffe)
184
#define LINK_TOKDEF		((ulong)0xfffffffd)
2 7u83 185
#endif
186
 
187
 
7 7u83 188
/**
189
 * TYPE REPRESENTING A CHECKING SCOPE
190
 *
191
 * This type is used to represent a checking scope, describing which checks
192
 * should be applied in a particular part of the program. It consists of an
193
 * array of option states - one for each option which can be set - plus a
194
 * pointer to the enclosing checking scope. A scope may have an associated
195
 * name. Also a list of all scopes is maintained.
196
 */
2 7u83 197
 
7 7u83 198
typedef unsigned char OPTION;
2 7u83 199
 
200
typedef struct opt_tag {
7 7u83 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;
2 7u83 209
 
210
 
7 7u83 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
 */
2 7u83 219
 
220
typedef struct pptok_tag {
7 7u83 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;
231
		FLOAT flt;
232
		NAMESPACE ns;
233
		STRING strlit;
234
		TYPE type;
235
		struct {
236
			/* Identifier */
237
			HASHID hash;
238
			IDENTIFIER use;
239
		} id;
240
		struct {
241
			/* String */
242
			string start;
243
			string end;
244
		} str;
245
		struct {
246
			/* Macro parameter */
247
			HASHID hash;
248
			unsigned long no;
249
		} par;
250
		struct {
251
			/* Location */
252
			unsigned long line;
253
			PTR(POSITION)posn;
254
		} loc;
255
		struct {
256
			/* Token application */
257
			IDENTIFIER id;
258
			struct pptok_tag *args;
259
		} tok;
260
	} pp_data;
261
	unsigned long pp_space;
262
	OPTIONS *pp_opts;
263
} PPTOKEN;
2 7u83 264
 
265
 
7 7u83 266
/**
267
 * TYPE REPRESENTING A SERIES OF BITS
268
 *
269
 * A bitstream consists of an array of characters comprising the bits
270
 * themselves, plus the current offset (in bytes and bits) of the end of these
271
 * bits. A pointer to the previous bitstream is used to chain bitstreams
272
 * together.
2 7u83 273
*/
274
 
275
typedef struct bits_tag {
7 7u83 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;
2 7u83 284
 
285
 
7 7u83 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
 */
2 7u83 292
 
293
typedef struct buff_tag {
7 7u83 294
	string start;
295
	string posn;
296
	string end;
297
	FILE *file;
298
} BUFFER;
2 7u83 299
 
7 7u83 300
#define NULL_buff	{ NULL, NULL, NULL, NULL }
2 7u83 301
 
302
 
303
#endif