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