Warning: Undefined variable $n in /usr/local/www/websvn.planix.org/include/diff_util.php on line 243

Warning: Undefined variable $n in /usr/local/www/websvn.planix.org/include/diff_util.php on line 247

Warning: Undefined variable $m in /usr/local/www/websvn.planix.org/include/diff_util.php on line 251
WebSVN – tendra.SVN – Diff – /trunk/src/producers/common/utility/option.c – Rev 2 and 7

Subversion Repositories tendra.SVN

Rev

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

Rev 2 Rev 7
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
#include "config.h"
61
#include "config.h"
32
#include <limits.h>
62
#include <limits.h>
33
#if FS_STDARG
63
#if FS_STDARG
34
#include <stdarg.h>
64
#include <stdarg.h>
35
#else
65
#else
Line 59... Line 89...
59
#include "preproc.h"
89
#include "preproc.h"
60
#include "redeclare.h"
90
#include "redeclare.h"
61
#include "syntax.h"
91
#include "syntax.h"
62
#include "ustring.h"
92
#include "ustring.h"
63
#include "xalloc.h"
93
#include "xalloc.h"
64
 
94
 
65
 
95
 
66
/*
96
/*
67
    OPTION CATALOGUE
97
    OPTION CATALOGUE
68
 
98
 
69
    This table gives the catalogue of all options.  Each entry consists
99
    This table gives the catalogue of all options.  Each entry consists
70
    of an option name plus the default value of the option in the
100
    of an option name plus the default value of the option in the
71
    various standard compilation modes.  The main body is automatically
101
    various standard compilation modes.  The main body is automatically
Line 79... Line 109...
79
#define OPT_VALUE_error		1, { OPTION_DISALLOW, OPTION_DISALLOW }
109
#define OPT_VALUE_error		1, { OPTION_DISALLOW, OPTION_DISALLOW }
80
#define OPT_VALUE_whatever	1, { OPTION_WHATEVER, OPTION_WHATEVER }
110
#define OPT_VALUE_whatever	1, { OPTION_WHATEVER, OPTION_WHATEVER }
81
#define OPT_VALUE_new		1, { OPTION_WARN, OPTION_DISALLOW }
111
#define OPT_VALUE_new		1, { OPTION_WARN, OPTION_DISALLOW }
82
#define OPT_VALUE_wall		1, { OPTION_ALLOW, OPTION_WARN }
112
#define OPT_VALUE_wall		1, { OPTION_ALLOW, OPTION_WARN }
83
 
113
 
84
OPT_DATA OPT_CATALOG [] = {
114
OPT_DATA OPT_CATALOG[] = {
85
#include "opts.h"
115
#include "opts.h"
86
    { NULL, OPT_VALUE_off }
116
	{ NULL, OPT_VALUE_off }
87
} ;
117
};
88
 
118
 
89
#define CATALOG_SIZE		array_size ( OPT_CATALOG )
119
#define CATALOG_SIZE		array_size(OPT_CATALOG)
90
 
120
 
91
 
121
 
92
/*
122
/*
93
    OPTION VALUE CATALOGUE
123
    OPTION VALUE CATALOGUE
94
 
124
 
Line 100... Line 130...
100
    implementation limits are NO_LIMIT, indicating that there is no
130
    implementation limits are NO_LIMIT, indicating that there is no
101
    built-in limit.
131
    built-in limit.
102
*/
132
*/
103
 
133
 
104
#if LANGUAGE_CPP
134
#if LANGUAGE_CPP
105
#define LIMIT( A, B )		( ( unsigned long ) ( A ) )
135
#define LIMIT(A, B)		((unsigned long)(A))
106
#else
136
#else
107
#define LIMIT( A, B )		( ( unsigned long ) ( B ) )
137
#define LIMIT(A, B)		((unsigned long)(B))
108
#endif
138
#endif
109
#define NO_LIMIT		ULONG_MAX
139
#define NO_LIMIT		ULONG_MAX
110
#define STR_LIMIT		( ULONG_MAX >> 3 )
140
#define STR_LIMIT		(ULONG_MAX >> 3)
111
 
141
 
112
OPT_VALUE_DATA OPT_VALUE_CATALOG [] = {
142
OPT_VALUE_DATA OPT_VALUE_CATALOG[] = {
113
    /* Implementation quantities (from Annex B) */
143
	/* Implementation quantities (from Annex B) */
114
    { "statement_depth", &crt_loc, NO_LIMIT, LIMIT ( 256, 15 ), 0, 1 },
144
	{ "statement_depth", &crt_loc, NO_LIMIT, LIMIT(256, 15), 0, 1 },
115
    { "hash_if_depth", &preproc_loc, NO_LIMIT, LIMIT ( 256, 8 ), 0, 1 },
145
	{ "hash_if_depth", &preproc_loc, NO_LIMIT, LIMIT(256, 8), 0, 1 },
116
    { "declarator_max", &crt_loc, NO_LIMIT, LIMIT ( 256, 12 ), 0, 0 },
146
	{ "declarator_max", &crt_loc, NO_LIMIT, LIMIT(256, 12), 0, 0 },
117
    { "paren_depth", &crt_loc, NO_LIMIT, LIMIT ( 256, 32 ), 0, 1 },
147
	{ "paren_depth", &crt_loc, NO_LIMIT, LIMIT(256, 32), 0, 1 },
118
    { "name_limit", &crt_loc, NO_LIMIT, LIMIT ( 1024, 31 ), 0, 0 },
148
	{ "name_limit", &crt_loc, NO_LIMIT, LIMIT(1024, 31), 0, 0 },
119
    { "extern_name_limit", &crt_loc, NO_LIMIT, LIMIT ( 1024, 6 ), 0, 0 },
149
	{ "extern_name_limit", &crt_loc, NO_LIMIT, LIMIT(1024, 6), 0, 0 },
120
    { "external_ids", &crt_loc, NO_LIMIT, LIMIT ( 65536, 511 ), 0, 0 },
150
	{ "external_ids", &crt_loc, NO_LIMIT, LIMIT(65536, 511), 0, 0 },
121
    { "block_ids", &crt_loc, NO_LIMIT, LIMIT ( 1024, 127 ), 0, 0 },
151
	{ "block_ids", &crt_loc, NO_LIMIT, LIMIT(1024, 127), 0, 0 },
122
    { "macro_ids", &preproc_loc, NO_LIMIT, LIMIT ( 65536, 1024 ), 0, 1 },
152
	{ "macro_ids", &preproc_loc, NO_LIMIT, LIMIT(65536, 1024), 0, 1 },
123
    { "func_pars", &crt_loc, NO_LIMIT, LIMIT ( 256, 31 ), 0, 0 },
153
	{ "func_pars", &crt_loc, NO_LIMIT, LIMIT(256, 31), 0, 0 },
124
    { "func_args", &crt_loc, NO_LIMIT, LIMIT ( 256, 31 ), 0, 0 },
154
	{ "func_args", &crt_loc, NO_LIMIT, LIMIT(256, 31), 0, 0 },
125
    { "macro_pars", &preproc_loc, NO_LIMIT, LIMIT ( 256, 31 ), 0, 0 },
155
	{ "macro_pars", &preproc_loc, NO_LIMIT, LIMIT(256, 31), 0, 0 },
126
    { "macro_args", &crt_loc, NO_LIMIT, LIMIT ( 256, 31 ), 0, 0 },
156
	{ "macro_args", &crt_loc, NO_LIMIT, LIMIT(256, 31), 0, 0 },
127
    { "line_length", &crt_loc, NO_LIMIT, LIMIT ( 65536, 509 ), 0, 0 },
157
	{ "line_length", &crt_loc, NO_LIMIT, LIMIT(65536, 509), 0, 0 },
128
    { "string_length", &crt_loc, STR_LIMIT, LIMIT ( 65536, 509 ), 0, 0 },
158
	{ "string_length", &crt_loc, STR_LIMIT, LIMIT(65536, 509), 0, 0 },
129
    { "sizeof_object", &crt_loc, NO_LIMIT, LIMIT ( 262144, 32767 ), 0, 0 },
159
	{ "sizeof_object", &crt_loc, NO_LIMIT, LIMIT(262144, 32767), 0, 0 },
130
    { "include_depth", &preproc_loc, 256, LIMIT ( 256, 8 ), 0, 1 },
160
	{ "include_depth", &preproc_loc, 256, LIMIT(256, 8), 0, 1 },
131
    { "switch_cases", &crt_loc, NO_LIMIT, LIMIT ( 16384, 257 ), 0, 0 },
161
	{ "switch_cases", &crt_loc, NO_LIMIT, LIMIT(16384, 257), 0, 0 },
132
    { "data_members", &crt_loc, NO_LIMIT, LIMIT ( 16384, 127 ), 0, 0 },
162
	{ "data_members", &crt_loc, NO_LIMIT, LIMIT(16384, 127), 0, 0 },
133
    { "enum_consts", &crt_loc, NO_LIMIT, LIMIT ( 4096, 127 ), 0, 0 },
163
	{ "enum_consts", &crt_loc, NO_LIMIT, LIMIT(4096, 127), 0, 0 },
134
    { "nested_class", &crt_loc, NO_LIMIT, LIMIT ( 256, 15 ), 0, 1 },
164
	{ "nested_class", &crt_loc, NO_LIMIT, LIMIT(256, 15), 0, 1 },
135
    { "atexit_funcs", &crt_loc, NO_LIMIT, LIMIT ( 32, 32 ), 0, 0 },
165
	{ "atexit_funcs", &crt_loc, NO_LIMIT, LIMIT(32, 32), 0, 0 },
136
    { "base_classes", &crt_loc, NO_LIMIT, LIMIT ( 16384, 0 ), 0, 0 },
166
	{ "base_classes", &crt_loc, NO_LIMIT, LIMIT(16384, 0), 0, 0 },
137
    { "direct_bases", &crt_loc, NO_LIMIT, LIMIT ( 1024, 0 ), 0, 0 },
167
	{ "direct_bases", &crt_loc, NO_LIMIT, LIMIT(1024, 0), 0, 0 },
138
    { "class_members", &crt_loc, NO_LIMIT, LIMIT ( 4096, 0 ), 0, 0 },
168
	{ "class_members", &crt_loc, NO_LIMIT, LIMIT(4096, 0), 0, 0 },
139
    { "virtual_funcs", &crt_loc, NO_LIMIT, LIMIT ( 16384, 0 ), 0, 0 },
169
	{ "virtual_funcs", &crt_loc, NO_LIMIT, LIMIT(16384, 0), 0, 0 },
140
    { "virtual_bases", &crt_loc, NO_LIMIT, LIMIT ( 1024, 0 ), 0, 0 },
170
	{ "virtual_bases", &crt_loc, NO_LIMIT, LIMIT(1024, 0), 0, 0 },
141
    { "static_members", &crt_loc, NO_LIMIT, LIMIT ( 1024, 0 ), 0, 0 },
171
	{ "static_members", &crt_loc, NO_LIMIT, LIMIT(1024, 0), 0, 0 },
142
    { "friends", &crt_loc, NO_LIMIT, LIMIT ( 4096, 0 ), 0, 0 },
172
	{ "friends", &crt_loc, NO_LIMIT, LIMIT(4096, 0), 0, 0 },
143
    { "access_declarations", &crt_loc, NO_LIMIT, LIMIT ( 4096, 0 ), 0, 0 },
173
	{ "access_declarations", &crt_loc, NO_LIMIT, LIMIT(4096, 0), 0, 0 },
144
    { "ctor_initializers", &crt_loc, NO_LIMIT, LIMIT ( 6144, 0 ), 0, 0 },
174
	{ "ctor_initializers", &crt_loc, NO_LIMIT, LIMIT(6144, 0), 0, 0 },
145
    { "scope_qualifiers", &crt_loc, NO_LIMIT, LIMIT ( 256, 0 ), 0, 0 },
175
	{ "scope_qualifiers", &crt_loc, NO_LIMIT, LIMIT(256, 0), 0, 0 },
146
    { "external_specs", &crt_loc, NO_LIMIT, LIMIT ( 1024, 0 ), 0, 1 },
176
	{ "external_specs", &crt_loc, NO_LIMIT, LIMIT(1024, 0), 0, 1 },
147
    { "template_pars", &crt_loc, NO_LIMIT, LIMIT ( 1024, 0 ), 0, 0 },
177
	{ "template_pars", &crt_loc, NO_LIMIT, LIMIT(1024, 0), 0, 0 },
148
    { "instance_depth", &crt_loc, 17, LIMIT ( 17, 0 ), 0, 1 },
178
	{ "instance_depth", &crt_loc, 17, LIMIT(17, 0), 0, 1 },
149
    { "exception_handlers", &crt_loc, NO_LIMIT, LIMIT ( 256, 0 ), 0, 0 },
179
	{ "exception_handlers", &crt_loc, NO_LIMIT, LIMIT(256, 0), 0, 0 },
150
    { "exception_specs", &crt_loc, NO_LIMIT, LIMIT ( 256, 0 ), 0, 0 },
180
	{ "exception_specs", &crt_loc, NO_LIMIT, LIMIT(256, 0), 0, 0 },
151
 
181
 
152
    /* Other quantities */
182
	/* Other quantities */
153
    { "cast_explicit", &crt_loc, CAST_EXPLICIT, 0, 0, 0 },
183
	{ "cast_explicit", &crt_loc, CAST_EXPLICIT, 0, 0, 0 },
154
    { "maximum_error", &crt_loc, 32, 1, 0, 0 },
184
	{ "maximum_error", &crt_loc, 32, 1, 0, 0 },
155
    { "tab_width", &crt_loc, 8, 1, 0, 0 },
185
	{ "tab_width", &crt_loc, 8, 1, 0, 0 },
156
    { NULL, NULL, 0, 0, 0, 0 }
186
	{ NULL, NULL, 0, 0, 0, 0 }
157
} ;
187
};
158
 
188
 
159
#define VALUE_CAT_SIZE		array_size ( OPT_VALUE_CATALOG )
189
#define VALUE_CAT_SIZE		array_size(OPT_VALUE_CATALOG)
160
 
190
 
161
 
191
 
162
/*
192
/*
163
    ERROR TYPE CATALOGUE
193
    ERROR TYPE CATALOGUE
164
 
194
 
165
    This table gives the names of all the types used in the error catalogue
195
    This table gives the names of all the types used in the error catalogue
166
    together with the code letter used to encode them.
196
    together with the code letter used to encode them.
167
*/
197
*/
168
 
198
 
169
typedef struct {
199
typedef struct {
170
    CONST char *name ;
200
	CONST char *name;
171
    int number ;
201
	int number;
172
} OPT_TYPE_DATA ;
202
} OPT_TYPE_DATA;
173
 
203
 
174
static OPT_TYPE_DATA OPT_TYPE_CATALOG [] = {
204
static OPT_TYPE_DATA OPT_TYPE_CATALOG[] = {
175
    { "ACCESS", ERR_KEY_ACCESS },
205
	{ "ACCESS", ERR_KEY_ACCESS },
176
    { "BASE_TYPE", ERR_KEY_BASE_TYPE },
206
	{ "BASE_TYPE", ERR_KEY_BASE_TYPE },
177
    { "CLASS_TYPE", ERR_KEY_CLASS_TYPE },
207
	{ "CLASS_TYPE", ERR_KEY_CLASS_TYPE },
178
    { "CV_SPEC", ERR_KEY_CV_SPEC },
208
	{ "CV_SPEC", ERR_KEY_CV_SPEC },
179
    { "DECL_SPEC", ERR_KEY_DECL_SPEC },
209
	{ "DECL_SPEC", ERR_KEY_DECL_SPEC },
180
    { "FLOAT", ERR_KEY_FLOAT },
210
	{ "FLOAT", ERR_KEY_FLOAT },
181
    { "HASHID", ERR_KEY_HASHID },
211
	{ "HASHID", ERR_KEY_HASHID },
182
    { "IDENTIFIER", ERR_KEY_IDENTIFIER },
212
	{ "IDENTIFIER", ERR_KEY_IDENTIFIER },
183
    { "LEX", ERR_KEY_LEX },
213
	{ "LEX", ERR_KEY_LEX },
184
    { "LONG_ID", ERR_KEY_LONG_ID },
214
	{ "LONG_ID", ERR_KEY_LONG_ID },
185
    { "NAMESPACE", ERR_KEY_NAMESPACE },
215
	{ "NAMESPACE", ERR_KEY_NAMESPACE },
186
    { "NAT", ERR_KEY_NAT },
216
	{ "NAT", ERR_KEY_NAT },
187
    { "PPTOKEN_P", ERR_KEY_PPTOKEN_P },
217
	{ "PPTOKEN_P", ERR_KEY_PPTOKEN_P },
188
    { "PTR_LOC", ERR_KEY_PTR_LOC },
218
	{ "PTR_LOC", ERR_KEY_PTR_LOC },
189
    { "QUALIFIER", ERR_KEY_QUALIFIER },
219
	{ "QUALIFIER", ERR_KEY_QUALIFIER },
190
    { "STRING", ERR_KEY_STRING },
220
	{ "STRING", ERR_KEY_STRING },
191
    { "TYPE", ERR_KEY_TYPE },
221
	{ "TYPE", ERR_KEY_TYPE },
192
    { "cint", ERR_KEY_cint },
222
	{ "cint", ERR_KEY_cint },
193
    { "cstring", ERR_KEY_cstring },
223
	{ "cstring", ERR_KEY_cstring },
194
    { "string", ERR_KEY_string },
224
	{ "string", ERR_KEY_string },
195
    { "ucint", ERR_KEY_ucint },
225
	{ "ucint", ERR_KEY_ucint },
196
    { "ulong", ERR_KEY_ulong },
226
	{ "ulong", ERR_KEY_ulong },
197
    { "unsigned", ERR_KEY_unsigned },
227
	{ "unsigned", ERR_KEY_unsigned },
198
    { "plural", ERR_KEY_plural }
228
	{ "plural", ERR_KEY_plural }
199
} ;
229
};
200
 
230
 
201
#define TYPE_CAT_SIZE		array_size ( OPT_TYPE_CATALOG )
231
#define TYPE_CAT_SIZE		array_size(OPT_TYPE_CATALOG)
202
 
232
 
203
 
233
 
204
/*
234
/*
205
    OPTION NAME HASH TABLE
235
    OPTION NAME HASH TABLE
206
 
236
 
207
    This hash table is used to hold the names of the various options in
237
    This hash table is used to hold the names of the various options in
208
    the option catalogue.
238
    the option catalogue.
209
*/
239
*/
210
 
240
 
211
typedef struct opt_hash_tag {
241
typedef struct opt_hash_tag {
212
    int number ;
242
	int number;
213
    OPT_DATA *entry ;
243
	OPT_DATA *entry;
214
    struct opt_hash_tag *next ;
244
	struct opt_hash_tag *next;
215
} OPT_HASH ;
245
} OPT_HASH;
216
 
246
 
217
#define HASH_OPTION		128
247
#define HASH_OPTION	128
218
static OPT_HASH *option_hash [ HASH_OPTION + 1 ] ;
248
static OPT_HASH *option_hash[HASH_OPTION + 1];
219
static OPT_HASH *all_option_hash = NULL ;
249
static OPT_HASH *all_option_hash = NULL;
220
 
250
 
221
 
251
 
222
/*
252
/*
223
    INITIALISE THE OPTION HASH TABLE
253
    INITIALISE THE OPTION HASH TABLE
224
 
254
 
225
    This routine sets up the option hash table.
255
    This routine sets up the option hash table.
226
*/
256
*/
227
 
257
 
228
static void init_opt_hash
258
static void
229
    PROTO_Z ()
259
init_opt_hash(void)
230
{
260
{
231
    int i ;
261
	int i;
232
    OPT_DATA *cat = OPT_CATALOG ;
262
	OPT_DATA *cat = OPT_CATALOG;
233
    OPT_HASH *opt = xmalloc_nof ( OPT_HASH, CATALOG_SIZE ) ;
263
	OPT_HASH *opt = xmalloc_nof(OPT_HASH, CATALOG_SIZE);
234
    for ( i = 0 ; i <= HASH_OPTION ; i++ ) {
264
	for (i = 0; i <= HASH_OPTION; i++) {
235
	option_hash [i] = NULL ;
265
		option_hash[i] = NULL;
236
    }
266
	}
237
    all_option_hash = opt ;
267
	all_option_hash = opt;
238
    for ( i = 0 ; i < CATALOG_SIZE ; i++ ) {
268
	for (i = 0; i < CATALOG_SIZE; i++) {
239
	unsigned long h ;
269
		unsigned long h;
240
	string s = ustrlit ( cat->name ) ;
270
		string s = ustrlit(cat->name);
241
	if ( s ) {
271
		if (s) {
242
	    h = hash ( s ) ;
272
			h = hash(s);
243
	    h %= HASH_OPTION ;
273
			h %= HASH_OPTION;
244
	} else {
274
		} else {
245
	    h = HASH_OPTION ;
275
			h = HASH_OPTION;
246
	}
276
		}
247
	opt->number = i ;
277
		opt->number = i;
248
	opt->entry = cat ;
278
		opt->entry = cat;
249
	opt->next = option_hash [h] ;
279
		opt->next = option_hash[h];
250
	option_hash [h] = opt ;
280
		option_hash[h] = opt;
251
	cat++ ;
281
		cat++;
252
	opt++ ;
282
		opt++;
253
    }
283
	}
254
    return ;
284
	return;
255
}
285
}
256
 
286
 
257
 
287
 
258
/*
288
/*
259
    FIND AN OPTION NUMBER
289
    FIND AN OPTION NUMBER
260
 
290
 
261
    This routine finds the option number corresponding to the string
291
    This routine finds the option number corresponding to the string
262
    literal expression s.  n gives a likely value to try first.  It
292
    literal expression s.  n gives a likely value to try first.  It
263
    returns -1 if s is not the name of a known option.
293
    returns -1 if s is not the name of a known option.
264
*/
294
*/
265
 
295
 
266
int find_option_no
296
int
267
    PROTO_N ( ( s, n ) )
-
 
268
    PROTO_T ( STRING s X int n )
297
find_option_no(STRING s, int n)
269
{
298
{
270
    unsigned kind = DEREF_unsigned ( str_simple_kind ( s ) ) ;
299
	unsigned kind = DEREF_unsigned(str_simple_kind(s));
271
    if ( kind == STRING_NONE ) {
300
	if (kind == STRING_NONE) {
272
	OPT_HASH *opt ;
301
		OPT_HASH *opt;
273
	unsigned long h ;
302
		unsigned long h;
274
	string text = DEREF_string ( str_simple_text ( s ) ) ;
303
		string text = DEREF_string(str_simple_text(s));
275
	ulong len = DEREF_ulong ( str_simple_len ( s ) ) ;
304
		ulong len = DEREF_ulong(str_simple_len(s));
276
	if ( n >= 0 && n < CATALOG_SIZE ) {
305
		if (n >= 0 && n < CATALOG_SIZE) {
277
	    string nm = ustrlit ( OPT_CATALOG [n].name ) ;
306
			string nm = ustrlit(OPT_CATALOG[n].name);
278
	    if ( nm && ustreq ( text, nm ) ) {
307
			if (nm && ustreq(text, nm)) {
279
		if ( len == ( ulong ) ustrlen ( nm ) ) return ( n ) ;
308
				if (len == (ulong)ustrlen(nm)) {
-
 
309
					return (n);
280
	    }
310
				}
-
 
311
			}
281
	}
312
		}
282
	if ( all_option_hash == NULL ) init_opt_hash () ;
313
		if (all_option_hash == NULL) {
-
 
314
			init_opt_hash();
-
 
315
		}
283
	h = hash ( text ) ;
316
		h = hash(text);
284
	h %= HASH_OPTION ;
317
		h %= HASH_OPTION;
285
	for ( opt = option_hash [h] ; opt != NULL ; opt = opt->next ) {
318
		for (opt = option_hash[h]; opt != NULL; opt = opt->next) {
286
	    string nm = ustrlit ( opt->entry->name ) ;
319
			string nm = ustrlit(opt->entry->name);
287
	    if ( nm && ustreq ( text, nm ) ) {
320
			if (nm && ustreq(text, nm)) {
288
		if ( len == ( ulong ) ustrlen ( nm ) ) {
321
				if (len == (ulong)ustrlen(nm)) {
289
		    return ( opt->number ) ;
322
					return (opt->number);
290
		}
323
				}
291
	    }
324
			}
292
	}
325
		}
293
    }
326
	}
294
    return ( -1 ) ;
327
	return (-1);
295
}
328
}
296
 
329
 
297
 
330
 
298
/*
331
/*
299
    FIND A VALUE OPTION NUMBER
332
    FIND A VALUE OPTION NUMBER
300
 
333
 
Line 302... Line 335...
302
    string literal expression s.  n gives a likely value to try first.
335
    string literal expression s.  n gives a likely value to try first.
303
    It returns -1 if s is not the name of a known value option.  Note
336
    It returns -1 if s is not the name of a known value option.  Note
304
    that there are not enough cases to warrant a hash table.
337
    that there are not enough cases to warrant a hash table.
305
*/
338
*/
306
 
339
 
307
int find_value_no
340
int
308
    PROTO_N ( ( s, n ) )
-
 
309
    PROTO_T ( STRING s X int n )
341
find_value_no(STRING s, int n)
310
{
342
{
311
    unsigned kind = DEREF_unsigned ( str_simple_kind ( s ) ) ;
343
	unsigned kind = DEREF_unsigned(str_simple_kind(s));
312
    if ( kind == STRING_NONE ) {
344
	if (kind == STRING_NONE) {
313
	int i ;
345
		int i;
314
	OPT_VALUE_DATA *p = OPT_VALUE_CATALOG ;
346
		OPT_VALUE_DATA *p = OPT_VALUE_CATALOG;
315
	string text = DEREF_string ( str_simple_text ( s ) ) ;
347
		string text = DEREF_string(str_simple_text(s));
316
	ulong len = DEREF_ulong ( str_simple_len ( s ) ) ;
348
		ulong len = DEREF_ulong(str_simple_len(s));
317
	if ( n >= 0 && n < VALUE_CAT_SIZE ) {
349
		if (n >= 0 && n < VALUE_CAT_SIZE) {
318
	    string nm = ustrlit ( p [n].name ) ;
350
			string nm = ustrlit(p[n].name);
319
	    if ( nm && ustreq ( text, nm ) ) {
351
			if (nm && ustreq(text, nm)) {
320
		if ( len == ( ulong ) ustrlen ( nm ) ) return ( n ) ;
352
				if (len == (ulong)ustrlen(nm)) {
-
 
353
					return (n);
321
	    }
354
				}
-
 
355
			}
322
	}
356
		}
323
	for ( i = 0 ; i < VALUE_CAT_SIZE ; i++ ) {
357
		for (i = 0; i < VALUE_CAT_SIZE; i++) {
324
	    string nm = ustrlit ( p->name ) ;
358
			string nm = ustrlit(p->name);
325
	    if ( nm && ustreq ( text, nm ) ) {
359
			if (nm && ustreq(text, nm)) {
326
		if ( len == ( ulong ) ustrlen ( nm ) ) return ( i ) ;
360
				if (len == (ulong)ustrlen(nm)) {
-
 
361
					return (i);
327
	    }
362
				}
-
 
363
			}
328
	    p++ ;
364
			p++;
-
 
365
		}
329
	}
366
	}
330
    }
-
 
331
    return ( -1 ) ;
367
	return (-1);
332
}
368
}
333
 
369
 
334
 
370
 
335
/*
371
/*
336
    FIND A ERROR TYPE NUMBER
372
    FIND A ERROR TYPE NUMBER
337
 
373
 
338
    This routine finds the encoding character for the type corresponding
374
    This routine finds the encoding character for the type corresponding
339
    to the string literal expression s.  It returns -1 if s is not the
375
    to the string literal expression s.  It returns -1 if s is not the
340
    name of a known value option.  Note that there are not enough cases
376
    name of a known value option.  Note that there are not enough cases
341
    to warrant a hash table.
377
    to warrant a hash table.
342
*/
378
*/
343
 
379
 
344
int find_type_no
380
int
345
    PROTO_N ( ( s ) )
-
 
346
    PROTO_T ( STRING s )
381
find_type_no(STRING s)
347
{
382
{
348
    unsigned kind = DEREF_unsigned ( str_simple_kind ( s ) ) ;
383
	unsigned kind = DEREF_unsigned(str_simple_kind(s));
349
    if ( kind == STRING_NONE ) {
384
	if (kind == STRING_NONE) {
350
	int i ;
385
		int i;
351
	OPT_TYPE_DATA *p = OPT_TYPE_CATALOG ;
386
		OPT_TYPE_DATA *p = OPT_TYPE_CATALOG;
352
	string text = DEREF_string ( str_simple_text ( s ) ) ;
387
		string text = DEREF_string(str_simple_text(s));
353
	ulong len = DEREF_ulong ( str_simple_len ( s ) ) ;
388
		ulong len = DEREF_ulong(str_simple_len(s));
354
	for ( i = 0 ; i < TYPE_CAT_SIZE ; i++ ) {
389
		for (i = 0; i < TYPE_CAT_SIZE; i++) {
355
	    string nm = ustrlit ( p->name ) ;
390
			string nm = ustrlit(p->name);
356
	    if ( nm && ustreq ( text, nm ) ) {
391
			if (nm && ustreq(text, nm)) {
357
		if ( len == ( ulong ) ustrlen ( nm ) ) {
392
				if (len == (ulong)ustrlen(nm)) {
358
		    return ( p->number ) ;
393
					return (p->number);
359
		}
394
				}
360
	    }
395
			}
361
	    p++ ;
396
			p++;
362
	}
397
		}
363
    }
398
	}
364
    return ( -1 ) ;
399
	return (-1);
365
}
400
}
366
 
401
 
367
 
402
 
368
/*
403
/*
369
    CURRENT OPTION STATE
404
    CURRENT OPTION STATE
370
 
405
 
371
    The variable crt_opts is used to record the current option state.
406
    The variable crt_opts is used to record the current option state.
372
    In addition a list of all scopes defined, all_opts, is maintained.
407
    In addition a list of all scopes defined, all_opts, is maintained.
373
    The variable crt_opt shadows crt_opts->opt and gives a user-accessible
408
    The variable crt_opt shadows crt_opts->opt and gives a user-accessible
374
    array of option values.
409
    array of option values.
375
*/
410
*/
376
 
411
 
377
OPTIONS *crt_opts = NULL ;
412
OPTIONS *crt_opts = NULL;
378
OPTIONS *real_opts = NULL ;
413
OPTIONS *real_opts = NULL;
379
static OPTIONS *all_opts = NULL ;
414
static OPTIONS *all_opts = NULL;
380
OPTION *crt_opt = NULL ;
415
OPTION *crt_opt = NULL;
381
 
416
 
382
 
417
 
383
/*
418
/*
384
    SET AN ERROR TO AN OPTION LEVEL
419
    SET AN ERROR TO AN OPTION LEVEL
385
 
420
 
386
    This routine modifies the severity level of the error err using the
421
    This routine modifies the severity level of the error err using the
387
    option n.  Whether the severity is set to that of option n depends
422
    option n.  Whether the severity is set to that of option n depends
388
    on the value of set; it is always set if set is zero, only set if
423
    on the value of set; it is always set if set is zero, only set if
389
    option n is more severe if set is positive, and only set if option
424
    option n is more severe if set is positive, and only set if option
390
    n is less severe if set is negative.
425
    n is less severe if set is negative.
391
*/
426
*/
392
 
427
 
393
ERROR set_severity
428
ERROR
394
    PROTO_N ( ( err, n, set ) )
-
 
395
    PROTO_T ( ERROR err X int n X int set )
429
set_severity(ERROR err, int n, int set)
396
{
-
 
397
    if ( !IS_NULL_err ( err ) ) {
-
 
398
	OPTION opt = crt_opts->opt [n] ;
-
 
399
	int e = error_severity [ opt ] ;
-
 
400
	if ( set != 0 ) {
-
 
401
	    /* Compare with previous severity */
-
 
402
	    int c = DEREF_int ( err_severity ( err ) ) ;
-
 
403
	    if ( set > 0 ) {
-
 
404
		if ( e < c ) e = c ;
-
 
405
	    } else {
-
 
406
		if ( e > c ) e = c ;
-
 
407
	    }
-
 
408
	}
-
 
409
	if ( e == ERROR_NONE ) {
-
 
410
	    /* Option off - return null error */
-
 
411
	    destroy_error ( err, 1 ) ;
-
 
412
	    err = NULL_err ;
-
 
413
	} else {
-
 
414
	    /* Set severity level */
-
 
415
	    COPY_int ( err_severity ( err ), e ) ;
-
 
416
	}
-
 
417
    }
-
 
418
    return ( err ) ;
-
 
419
}
-
 
420
 
-
 
421
 
-
 
422
/*
-
 
423
    PERFORM ACTIONS FOR AN OPTION
-
 
424
 
-
 
425
    This routine performs any actions associated with setting the value
-
 
426
    of option n to opt.  The flag end is true if this call is at the
-
 
427
    end of a scope to restore the old value of option n.
-
 
428
*/
-
 
429
 
-
 
430
static void action_option
-
 
431
    PROTO_N ( ( n, opt, end ) )
-
 
432
    PROTO_T ( int n X unsigned opt X int end )
-
 
433
{
430
{
-
 
431
	if (!IS_NULL_err(err)) {
-
 
432
		OPTION opt = crt_opts->opt[n];
-
 
433
		int e = error_severity[opt];
434
    switch ( n ) {
434
		if (set != 0) {
-
 
435
			/* Compare with previous severity */
-
 
436
			int c = DEREF_int(err_severity(err));
435
	case OPT_none : {
437
			if (set > 0) {
-
 
438
				if (e < c) {
-
 
439
					e = c;
-
 
440
				}
-
 
441
			} else {
-
 
442
				if (e > c) {
-
 
443
					e = c;
-
 
444
				}
-
 
445
			}
-
 
446
		}
-
 
447
		if (e == ERROR_NONE) {
436
	    error_severity [ OPTION_OFF ] = default_severity [ opt ] ;
448
			/* Option off - return null error */
-
 
449
			destroy_error(err, 1);
-
 
450
			err = NULL_err;
437
	    break ;
451
		} else {
-
 
452
			/* Set severity level */
-
 
453
			COPY_int(err_severity(err), e);
-
 
454
		}
438
	}
455
	}
564
}
611
}
565
 
612
 
566
 
613
 
567
/*
614
/*
568
    SET AN OPTION LEVEL
615
    SET AN OPTION LEVEL
Line 571... Line 618...
571
    OPTION_OFF (for 'off' or 'allow'), OPTION_WARN (for 'warning') or
618
    OPTION_OFF (for 'off' or 'allow'), OPTION_WARN (for 'warning') or
572
    OPTION_ON (for 'on' or 'disallow').  Note that special action needs
619
    OPTION_ON (for 'on' or 'disallow').  Note that special action needs
573
    to be taken if n represents a set of options such as conv or discard
620
    to be taken if n represents a set of options such as conv or discard
574
    where the set value is the logical or of the values of the set
621
    where the set value is the logical or of the values of the set
575
    members.
622
    members.
576
*/
623
*/
577
 
624
 
578
void set_option
625
void
579
    PROTO_N ( ( n, opt ) )
-
 
580
    PROTO_T ( int n X unsigned opt )
626
set_option(int n, unsigned opt)
581
{
627
{
582
    if ( n != -1 ) {
628
	if (n != -1) {
583
	/* Set the option level */
629
		/* Set the option level */
584
	switch ( n ) {
630
		switch (n) {
585
	    case OPT_conv : {
631
		case OPT_conv: {
586
		/* All conversion options */
632
			/* All conversion options */
587
		set_option ( OPT_conv_int_int_expl, opt ) ;
633
			set_option(OPT_conv_int_int_expl, opt);
588
		set_option ( OPT_conv_int_int_impl, opt ) ;
634
			set_option(OPT_conv_int_int_impl, opt);
589
		set_option ( OPT_conv_int_ptr_expl, opt ) ;
635
			set_option(OPT_conv_int_ptr_expl, opt);
590
		set_option ( OPT_conv_ptr_ptr_expl, opt ) ;
-
 
591
		break ;
-
 
592
	    }
-
 
593
	    case OPT_conv_int_int : {
-
 
594
		/* All integer conversion options */
-
 
595
		set_option ( OPT_conv_int_int_expl, opt ) ;
-
 
596
		set_option ( OPT_conv_int_int_impl, opt ) ;
-
 
597
		break ;
-
 
598
	    }
-
 
599
	    case OPT_conv_int_ptr : {
-
 
600
		/* All integer to pointer conversion options */
-
 
601
		set_option ( OPT_conv_int_ptr_expl, opt ) ;
-
 
602
		break ;
-
 
603
	    }
-
 
604
	    case OPT_conv_ptr_ptr : {
-
 
605
		/* All pointer conversion options */
-
 
606
		set_option ( OPT_conv_ptr_ptr_expl, opt ) ;
636
			set_option(OPT_conv_ptr_ptr_expl, opt);
607
		break ;
-
 
608
	    }
-
 
609
	    case OPT_discard : {
-
 
610
		/* All discard options */
-
 
611
		set_option ( OPT_discard_func, opt ) ;
-
 
612
		set_option ( OPT_discard_static, opt ) ;
-
 
613
		set_option ( OPT_discard_value, opt ) ;
-
 
614
		break ;
-
 
615
	    }
-
 
616
	    case OPT_discard_exp : {
-
 
617
		/* Expression discard options */
-
 
618
		set_option ( OPT_discard_func, opt ) ;
-
 
619
		set_option ( OPT_discard_value, opt ) ;
-
 
620
		break ;
637
			break;
621
	    }
-
 
622
	    case OPT_func_impl : {
-
 
623
		/* These options are negated */
-
 
624
		if ( opt == OPTION_ON ) {
-
 
625
		    opt = OPTION_OFF ;
-
 
626
		} else if ( opt == OPTION_OFF ) {
-
 
627
		    opt = OPTION_ON ;
-
 
628
		}
638
		}
629
		goto default_lab ;
639
		case OPT_conv_int_int: {
-
 
640
			/* All integer conversion options */
-
 
641
			set_option(OPT_conv_int_int_expl, opt);
-
 
642
			set_option(OPT_conv_int_int_impl, opt);
-
 
643
			break;
630
	    }
644
		}
-
 
645
		case OPT_conv_int_ptr: {
-
 
646
			/* All integer to pointer conversion options */
-
 
647
			set_option(OPT_conv_int_ptr_expl, opt);
631
	    default :
648
			break;
-
 
649
		}
632
	    default_lab : {
650
		case OPT_conv_ptr_ptr: {
633
		/* Simple options */
651
			/* All pointer conversion options */
634
		OPTIONS *p = crt_opts ;
652
			set_option(OPT_conv_ptr_ptr_expl, opt);
-
 
653
			break;
-
 
654
		}
635
		if ( OPT_CATALOG [n].scoped ) {
655
		case OPT_discard: {
636
		    /* Scoped options */
656
			/* All discard options */
637
		    int sev = ( int ) p->set [n] ;
657
			set_option(OPT_discard_func, opt);
638
		    OPTION new_opt = ( OPTION ) opt ;
658
			set_option(OPT_discard_static, opt);
639
		    OPTION old_opt = p->opt [n] ;
659
			set_option(OPT_discard_value, opt);
-
 
660
			break;
-
 
661
		}
640
		    if ( new_opt != old_opt ) {
662
		case OPT_discard_exp: {
641
			/* Option value changed */
663
			/* Expression discard options */
642
			p->opt [n] = new_opt ;
664
			set_option(OPT_discard_func, opt);
643
			action_option ( n, opt, 0 ) ;
665
			set_option(OPT_discard_value, opt);
-
 
666
			break;
644
		    }
667
		}
645
		    if ( sev != ERROR_WHATEVER ) {
668
		case OPT_func_impl: {
646
			/* Option already set in this scope */
669
			/* These options are negated */
647
			string s = ustrlit ( OPT_CATALOG [n].name ) ;
670
			if (opt == OPTION_ON) {
648
			ERROR err = ERR_pragma_scope_set ( s ) ;
-
 
649
			if ( !IS_NULL_err ( err ) ) {
671
				opt = OPTION_OFF;
650
			    COPY_int ( err_severity ( err ), sev ) ;
672
			} else if (opt == OPTION_OFF) {
651
			    report ( preproc_loc, err ) ;
673
				opt = OPTION_ON;
652
			}
674
			}
-
 
675
			goto default_lab;
-
 
676
		}
-
 
677
		default:
-
 
678
default_lab: {
-
 
679
		     /* Simple options */
-
 
680
		     OPTIONS *p = crt_opts;
-
 
681
		     if (OPT_CATALOG[n].scoped) {
-
 
682
			     /* Scoped options */
-
 
683
			     int sev = (int)p->set[n];
-
 
684
			     OPTION new_opt = (OPTION)opt;
-
 
685
			     OPTION old_opt = p->opt[n];
-
 
686
			     if (new_opt != old_opt) {
-
 
687
				     /* Option value changed */
-
 
688
				     p->opt[n] = new_opt;
-
 
689
				     action_option(n, opt, 0);
653
		    }
690
			     }
-
 
691
			     if (sev != ERROR_WHATEVER) {
-
 
692
				     /* Option already set in this scope */
-
 
693
				     string s = ustrlit(OPT_CATALOG[n].name);
-
 
694
				     ERROR err = ERR_pragma_scope_set(s);
-
 
695
				     if (!IS_NULL_err(err)) {
-
 
696
					     COPY_int(err_severity(err), sev);
-
 
697
					     report(preproc_loc, err);
-
 
698
				     }
-
 
699
			     }
654
		    p->set [n] = ERROR_SERIOUS ;
700
			     p->set[n] = ERROR_SERIOUS;
655
		} else {
701
		     } else {
656
		    /* Unscoped options */
702
			     /* Unscoped options */
657
		    p->opt [n] = ( OPTION ) opt ;
703
			     p->opt[n] = (OPTION)opt;
658
		    action_option ( n, opt, 0 ) ;
704
			     action_option(n, opt, 0);
659
		    p->set [n] = ERROR_SERIOUS ;
705
			     p->set[n] = ERROR_SERIOUS;
660
		}
706
		     }
661
		break ;
707
		     break;
662
	    }
708
	     }
663
	}
709
		}
664
    }
710
	}
665
    return ;
711
	return;
666
}
712
}
667
 
713
 
668
 
714
 
669
/*
715
/*
670
    PERFORM ACTIONS FOR AN OPTION VALUE
716
    PERFORM ACTIONS FOR AN OPTION VALUE
671
 
717
 
672
    This routine performs any actions associated with setting option value
718
    This routine performs any actions associated with setting option value
673
    n to v.  The flag end is true if this call is at the end of a scope to
719
    n to v.  The flag end is true if this call is at the end of a scope to
674
    restore the old value of option n.
720
    restore the old value of option n.
675
*/
721
*/
676
 
722
 
677
static void action_value
723
static void
678
    PROTO_N ( ( n, v ) )
-
 
679
    PROTO_T ( int n X unsigned long v )
724
action_value(int n, unsigned long v)
680
{
725
{
681
    switch ( n ) {
726
	switch (n) {
682
	case OPT_VAL_include_depth : {
727
	case OPT_VAL_include_depth: {
683
	    set_incl_depth ( v ) ;
728
		set_incl_depth(v);
684
	    break ;
-
 
685
	}
-
 
686
	case OPT_VAL_name_limit : {
-
 
687
	    if ( v < max_id_length ) max_id_length = v ;
-
 
688
	    break ;
729
		break;
689
	}
730
	}
-
 
731
	case OPT_VAL_name_limit: {
-
 
732
		if (v < max_id_length) {
-
 
733
			max_id_length = v;
-
 
734
		}
-
 
735
		break;
-
 
736
	}
690
	case OPT_VAL_maximum_error : {
737
	case OPT_VAL_maximum_error: {
691
	    max_errors = v ;
738
		max_errors = v;
-
 
739
		break;
-
 
740
	}
-
 
741
	case OPT_VAL_tab_width: {
-
 
742
		if (v != 0) {
-
 
743
			tab_width = v;
-
 
744
		}
692
	    break ;
745
		break;
693
	}
746
	}
694
	case OPT_VAL_tab_width : {
-
 
695
	    if ( v != 0 ) tab_width = v ;
-
 
696
	    break ;
-
 
697
	}
747
	}
698
    }
-
 
699
    return ;
748
	return;
700
}
749
}
701
 
750
 
702
 
751
 
703
/*
752
/*
704
    SET OPTION VALUE
753
    SET OPTION VALUE
705
 
754
 
706
    This routine sets the option value for option n to the integer literal
755
    This routine sets the option value for option n to the integer literal
707
    expression e or the value v.  Note that option values are not scoped.
756
    expression e or the value v.  Note that option values are not scoped.
708
*/
757
*/
709
 
758
 
710
void set_value
759
void
711
    PROTO_N ( ( n, e, v ) )
-
 
712
    PROTO_T ( int n X EXP e X unsigned long v )
760
set_value(int n, EXP e, unsigned long v)
713
{
761
{
714
    if ( !IS_NULL_exp ( e ) ) {
762
	if (!IS_NULL_exp(e)) {
715
	NAT m ;
763
		NAT m;
716
	if ( !IS_exp_int_lit ( e ) ) return ;
764
		if (!IS_exp_int_lit(e)) {
-
 
765
			return;
-
 
766
		}
717
	m = DEREF_nat ( exp_int_lit_nat ( e ) ) ;
767
		m = DEREF_nat(exp_int_lit_nat(e));
718
	v = get_nat_value ( m ) ;
768
		v = get_nat_value(m);
719
    }
769
	}
720
    if ( n != -1 ) {
770
	if (n != -1) {
721
	OPT_VALUE_CATALOG [n].max_value = v ;
771
		OPT_VALUE_CATALOG[n].max_value = v;
722
	OPT_VALUE_CATALOG [n].min_value = v ;
772
		OPT_VALUE_CATALOG[n].min_value = v;
723
	action_value ( n, v ) ;
773
		action_value(n, v);
724
    }
774
	}
725
    return ;
775
	return;
726
}
776
}
727
 
777
 
728
 
778
 
729
/*
779
/*
730
    CHECK AN OPTION VALUE
780
    CHECK AN OPTION VALUE
Line 732... Line 782...
732
    This routine checks whether the value v is less than the maximum
782
    This routine checks whether the value v is less than the maximum
733
    permitted value for the option n.  It returns true if so.  Extra
783
    permitted value for the option n.  It returns true if so.  Extra
734
    arguments for use in error reporting may be provided.
784
    arguments for use in error reporting may be provided.
735
*/
785
*/
736
 
786
 
737
int check_value
787
int
738
    PROTO_V ( ( int n, unsigned long v, ... ) ) /* VARARGS */
788
check_value(int n, unsigned long v, ...) /* VARARGS */
739
{
789
{
740
    va_list args ;
790
	va_list args;
741
    unsigned long u ;
791
	unsigned long u;
742
    OPT_VALUE_DATA *p ;
792
	OPT_VALUE_DATA *p;
743
#if FS_STDARG
793
#if FS_STDARG
744
    va_start ( args, v ) ;
794
	va_start(args, v);
745
#else
795
#else
746
    int n ;
796
	int n;
747
    unsigned long v ;
797
	unsigned long v;
748
    va_start ( args ) ;
798
	va_start(args);
749
    n = va_arg ( args, int ) ;
799
	n = va_arg(args, int);
750
    v = va_arg ( args, unsigned long ) ;
800
	v = va_arg(args, unsigned long);
751
#endif
801
#endif
752
 
802
 
753
    /* Check against implementation limit */
803
	/* Check against implementation limit */
754
    p = OPT_VALUE_CATALOG + n ;
804
	p = OPT_VALUE_CATALOG + n;
755
    u = p->max_value ;
805
	u = p->max_value;
756
    if ( v > u ) {
806
	if (v > u) {
757
	int err = 1 ;
807
		int err = 1;
758
	if ( p->incr ) {
808
		if (p->incr) {
759
	    if ( v > u + 1 ) err = 0 ;
809
			if (v > u + 1) {
-
 
810
				err = 0;
-
 
811
			}
760
	    p->incr = 2 ;
812
			p->incr = 2;
761
	}
813
		}
762
	if ( err ) {
814
		if (err) {
763
	    LOCATION *loc = p->loc ;
815
			LOCATION *loc = p->loc;
764
	    switch ( n ) {
816
			switch (n) {
765
		case OPT_VAL_include_depth : {
817
			case OPT_VAL_include_depth: {
766
		    /* Include depth too great */
818
				/* Include depth too great */
767
		    print_error ( loc, ERR_cpp_include_depth ( v ) ) ;
819
				print_error(loc, ERR_cpp_include_depth(v));
768
		    break ;
820
				break;
769
		}
821
			}
770
		case OPT_VAL_name_limit : {
822
			case OPT_VAL_name_limit: {
771
		    /* Name length too great */
823
				/* Name length too great */
772
		    HASHID nm = va_arg ( args, HASHID ) ;
824
				HASHID nm = va_arg(args, HASHID);
773
		    print_error ( loc, ERR_lex_name_limit ( nm, v, u ) ) ;
825
				print_error(loc, ERR_lex_name_limit(nm, v, u));
774
		    break ;
826
				break;
775
		}
827
			}
776
		case OPT_VAL_instance_depth : {
828
			case OPT_VAL_instance_depth: {
777
		    /* Instantiation depth too great */
829
				/* Instantiation depth too great */
778
		    print_error ( loc, ERR_temp_inst_depth ( v ) ) ;
830
				print_error(loc, ERR_temp_inst_depth(v));
-
 
831
				break;
-
 
832
			}
-
 
833
			default : {
-
 
834
				/* Other limit exceeded */
-
 
835
				string s = ustrlit(p->name);
-
 
836
				print_error(loc, ERR_limits_max(s, v, u));
779
		    break ;
837
				break;
-
 
838
			}
-
 
839
			}
780
		}
840
		}
781
		default : {
841
		va_end(args);
782
		    /* Other limit exceeded */
-
 
783
		    string s = ustrlit ( p->name ) ;
-
 
784
		    print_error ( loc, ERR_limits_max ( s, v, u ) ) ;
-
 
785
		    break ;
842
		return (0);
786
		}
-
 
787
	    }
-
 
788
	}
843
	}
789
	va_end ( args ) ;
-
 
790
	return ( 0 ) ;
-
 
791
    }
-
 
792
 
844
 
793
    /* Check against minimum implementation limit */
845
	/* Check against minimum implementation limit */
794
    u = p->min_value ;
846
	u = p->min_value;
795
    if ( v > u ) {
847
	if (v > u) {
796
	if ( p->incr ) {
848
		if (p->incr) {
797
	    p->incr = 2 ;
849
			p->incr = 2;
798
	} else {
850
		} else {
799
	    LOCATION *loc = p->loc ;
851
			LOCATION *loc = p->loc;
800
	    string s = ustrlit ( p->name ) ;
852
			string s = ustrlit(p->name);
801
	    print_error ( loc, ERR_limits_min ( s, v, u ) ) ;
853
			print_error(loc, ERR_limits_min(s, v, u));
-
 
854
		}
802
	}
855
	}
803
    }
-
 
804
    va_end ( args ) ;
856
	va_end(args);
805
    return ( 1 ) ;
857
	return (1);
806
}
858
}
807
 
859
 
808
 
860
 
809
/*
861
/*
810
    INCREMENT AN OPTION VALUE
862
    INCREMENT AN OPTION VALUE
811
 
863
 
812
    This routine increments the current value of the option value n,
864
    This routine increments the current value of the option value n,
813
    applying check_value to the result.
865
    applying check_value to the result.
814
*/
866
*/
815
 
867
 
816
int incr_value
868
int
817
    PROTO_N ( ( n ) )
-
 
818
    PROTO_T ( int n )
869
incr_value(int n)
819
{
870
{
820
    OPT_VALUE_DATA *p = OPT_VALUE_CATALOG + n ;
871
	OPT_VALUE_DATA *p = OPT_VALUE_CATALOG + n;
821
    unsigned long v = ++( p->crt_value ) ;
872
	unsigned long v = ++(p->crt_value);
822
    ASSERT ( p->incr ) ;
873
	ASSERT(p->incr);
823
    return ( check_value ( n, v ) ) ;
874
	return (check_value(n, v));
824
}
875
}
825
 
876
 
826
 
877
 
827
/*
878
/*
828
    DECREMENT AN OPTION VALUE
879
    DECREMENT AN OPTION VALUE
829
 
880
 
830
    This routine decrements the current value of the option value n.
881
    This routine decrements the current value of the option value n.
831
*/
882
*/
832
 
883
 
833
void decr_value
884
void
834
    PROTO_N ( ( n ) )
-
 
835
    PROTO_T ( int n )
885
decr_value(int n)
836
{
886
{
837
    OPT_VALUE_DATA *p = OPT_VALUE_CATALOG + n ;
887
	OPT_VALUE_DATA *p = OPT_VALUE_CATALOG + n;
838
    unsigned long v = p->crt_value ;
888
	unsigned long v = p->crt_value;
839
    if ( v ) {
889
	if (v) {
840
	if ( p->incr == 2 ) {
890
		if (p->incr == 2) {
841
	    /* Report maximum value attained */
891
			/* Report maximum value attained */
842
	    LOCATION *loc = p->loc ;
892
			LOCATION *loc = p->loc;
843
	    string s = ustrlit ( p->name ) ;
893
			string s = ustrlit(p->name);
844
	    unsigned long u = p->min_value ;
894
			unsigned long u = p->min_value;
845
	    print_error ( loc, ERR_limits_min ( s, v, u ) ) ;
895
			print_error(loc, ERR_limits_min(s, v, u));
846
	    p->incr = 1 ;
896
			p->incr = 1;
-
 
897
		}
-
 
898
		p->crt_value = v - 1;
847
	}
899
	}
848
	p->crt_value = v - 1 ;
-
 
849
    }
-
 
850
    return ;
900
	return;
851
}
901
}
852
 
902
 
853
 
903
 
854
/*
904
/*
855
    SET LINKAGE OPTION
905
    SET LINKAGE OPTION
856
 
906
 
857
    This routine sets the current external linkage option to ds.
907
    This routine sets the current external linkage option to ds.
858
*/
908
*/
859
 
909
 
860
void set_link_opt
910
void
861
    PROTO_N ( ( ds ) )
-
 
862
    PROTO_T ( DECL_SPEC ds )
911
set_link_opt(DECL_SPEC ds)
863
{
912
{
864
    OPTIONS *p = crt_opts ;
913
	OPTIONS *p = crt_opts;
865
    if ( p ) {
914
	if (p) {
866
	DECL_SPEC ods = p->lnk_opt [1] ;
915
		DECL_SPEC ods = p->lnk_opt[1];
867
	if ( ods != dspec_ignore ) {
916
		if (ods != dspec_ignore) {
868
	    /* Option already set in this scope */
917
			/* Option already set in this scope */
869
	    string s = ustrlit ( "link_extern" ) ;
918
			string s = ustrlit("link_extern");
870
	    ERROR err = ERR_pragma_scope_set ( s ) ;
919
			ERROR err = ERR_pragma_scope_set(s);
871
	    if ( !IS_NULL_err ( err ) ) {
920
			if (!IS_NULL_err(err)) {
872
		report ( preproc_loc, err ) ;
921
				report(preproc_loc, err);
873
	    }
922
			}
-
 
923
		}
-
 
924
		p->lnk_opt[1] = ds;
-
 
925
		crt_linkage = ds;
-
 
926
		new_linkage = ds;
874
	}
927
	}
875
	p->lnk_opt [1] = ds ;
-
 
876
	crt_linkage = ds ;
-
 
877
	new_linkage = ds ;
-
 
878
    }
-
 
879
    return ;
928
	return;
880
}
929
}
881
 
930
 
882
 
931
 
883
/*
932
/*
884
    FIND A NAMED CHECKING SCOPE
933
    FIND A NAMED CHECKING SCOPE
885
 
934
 
886
    This routine searches for a checking scope named nm, returning the
935
    This routine searches for a checking scope named nm, returning the
887
    corresponding table of options.  If nm has not been defined then the
936
    corresponding table of options.  If nm has not been defined then the
888
    null pointer is returned.
937
    null pointer is returned.
889
*/
938
*/
890
 
939
 
891
static OPTIONS *find_option
940
static OPTIONS *
892
    PROTO_N ( ( nm ) )
-
 
893
    PROTO_T ( HASHID nm )
941
find_option(HASHID nm)
894
{
942
{
895
    OPTIONS *p ;
943
	OPTIONS *p;
896
    for ( p = all_opts ; p != NULL ; p = p->next ) {
944
	for (p = all_opts; p != NULL; p = p->next) {
897
	if ( EQ_hashid ( nm, p->name ) ) return ( p ) ;
945
		if (EQ_hashid(nm, p->name)) {
-
 
946
			return (p);
898
    }
947
		}
-
 
948
	}
899
    return ( NULL ) ;
949
	return (NULL);
900
}
950
}
901
 
951
 
902
 
952
 
903
/*
953
/*
904
    CREATE A NEW OPTION
954
    CREATE A NEW OPTION
905
 
955
 
906
    This routine creates a new option scope named nm with initial
956
    This routine creates a new option scope named nm with initial
907
    values taken either from the existing scope q or, if this is the
957
    values taken either from the existing scope q or, if this is the
908
    null pointer, the nth entry of the options catalogue above.
958
    null pointer, the nth entry of the options catalogue above.
909
*/
959
*/
910
 
960
 
911
static OPTIONS *new_option
961
static OPTIONS *
912
    PROTO_N ( ( nm, q, n ) )
-
 
913
    PROTO_T ( HASHID nm X OPTIONS *q X int n )
962
new_option(HASHID nm, OPTIONS *q, int n)
914
{
963
{
915
    /* Allocate space for new scope */
964
	/* Allocate space for new scope */
916
    int i ;
965
	int i;
917
    OPTIONS *p = xmalloc_nof ( OPTIONS, 1 ) ;
966
	OPTIONS *p = xmalloc_nof(OPTIONS, 1);
918
    OPTION *po = xmalloc_nof ( OPTION, 2 * CATALOG_SIZE ) ;
967
	OPTION *po = xmalloc_nof(OPTION, 2 * CATALOG_SIZE);
919
    OPTION *ps = po + CATALOG_SIZE ;
968
	OPTION *ps = po + CATALOG_SIZE;
920
    p->opt = po ;
969
	p->opt = po;
921
    p->set = ps ;
970
	p->set = ps;
922
    p->val_opt [0] = no_declarations ;
971
	p->val_opt[0] = no_declarations;
923
    p->lnk_opt [0] = crt_linkage ;
972
	p->lnk_opt[0] = crt_linkage;
924
    p->lnk_opt [1] = dspec_ignore ;
973
	p->lnk_opt[1] = dspec_ignore;
925
    p->prev = NULL ;
974
	p->prev = NULL;
926
    p->name = NULL_hashid ;
975
	p->name = NULL_hashid;
927
    p->next = all_opts ;
976
	p->next = all_opts;
928
    all_opts = p ;
977
	all_opts = p;
929
 
978
 
930
    /* Check scope name */
979
	/* Check scope name */
931
    if ( !IS_NULL_hashid ( nm ) ) {
980
	if (!IS_NULL_hashid(nm)) {
932
	if ( find_option ( nm ) ) {
981
		if (find_option(nm)) {
933
	    report ( preproc_loc, ERR_pragma_scope_redef ( nm ) ) ;
982
			report(preproc_loc, ERR_pragma_scope_redef(nm));
934
	}
983
		}
935
	p->name = nm ;
984
		p->name = nm;
936
    }
985
	}
937
 
986
 
938
    /* Set up scope */
987
	/* Set up scope */
939
    if ( q ) {
988
	if (q) {
940
	/* Copy existing scope */
989
		/* Copy existing scope */
941
	OPTION *qo = q->opt ;
990
		OPTION *qo = q->opt;
942
	for ( i = 0 ; i < CATALOG_SIZE ; i++ ) {
991
		for (i = 0; i < CATALOG_SIZE; i++) {
943
	    *( po++ ) = *( qo++ ) ;
992
			*(po++) = *(qo++);
944
	    *( ps++ ) = ERROR_WHATEVER ;
993
			*(ps++) = ERROR_WHATEVER;
945
	}
994
		}
946
    } else {
995
	} else {
947
	/* Use standard scope */
996
		/* Use standard scope */
948
	OPT_DATA *cat = OPT_CATALOG ;
997
		OPT_DATA *cat = OPT_CATALOG;
949
	for ( i = 0 ; i < CATALOG_SIZE ; i++ ) {
998
		for (i = 0; i < CATALOG_SIZE; i++) {
950
	    /* Use the nth entry from the catalogue */
999
			/* Use the nth entry from the catalogue */
951
	    *( po++ ) = cat->def [n] ;
1000
			*(po++) = cat->def[n];
952
	    *( ps++ ) = ERROR_SERIOUS ;
1001
			*(ps++) = ERROR_SERIOUS;
953
	    cat++ ;
1002
			cat++;
954
	}
1003
		}
955
    }
1004
	}
956
    return ( p ) ;
1005
	return (p);
957
}
1006
}
958
 
1007
 
959
 
1008
 
960
/*
1009
/*
961
    BEGIN A CHECKING SCOPE
1010
    BEGIN A CHECKING SCOPE
962
 
1011
 
963
    This routine begins a new checking scope.
1012
    This routine begins a new checking scope.
964
*/
1013
*/
965
 
1014
 
966
void begin_option
1015
void
967
    PROTO_N ( ( id ) )
-
 
968
    PROTO_T ( IDENTIFIER id )
1016
begin_option(IDENTIFIER id)
969
{
1017
{
970
    OPTIONS *p ;
1018
	OPTIONS *p;
971
    HASHID nm = NULL_hashid ;
1019
	HASHID nm = NULL_hashid;
-
 
1020
	if (!IS_NULL_id(id)) {
972
    if ( !IS_NULL_id ( id ) ) nm = DEREF_hashid ( id_name ( id ) ) ;
1021
		nm = DEREF_hashid(id_name(id));
-
 
1022
	}
973
    p = new_option ( nm, real_opts, 0 ) ;
1023
	p = new_option(nm, real_opts, 0);
974
    p->prev = real_opts ;
1024
	p->prev = real_opts;
975
    crt_opts = p ;
1025
	crt_opts = p;
976
    real_opts = p ;
1026
	real_opts = p;
977
    crt_opt = p->opt ;
1027
	crt_opt = p->opt;
978
    return ;
1028
	return;
979
}
1029
}
980
 
1030
 
981
 
1031
 
982
/*
1032
/*
983
    END A CHECKING SCOPE
1033
    END A CHECKING SCOPE
984
 
1034
 
985
    This routine ends the current checking scope.
1035
    This routine ends the current checking scope.
986
*/
1036
*/
987
 
1037
 
988
void end_option
1038
void
989
    PROTO_N ( ( expl ) )
-
 
990
    PROTO_T ( int expl )
1039
end_option(int expl)
991
{
1040
{
992
    OPTIONS *p = real_opts ;
1041
	OPTIONS *p = real_opts;
993
    if ( p ) {
1042
	if (p) {
994
	OPTIONS *q = p->prev ;
1043
		OPTIONS *q = p->prev;
995
	DECL_SPEC ds = p->lnk_opt [0] ;
1044
		DECL_SPEC ds = p->lnk_opt[0];
996
	if ( expl && p->val_opt [0] == no_declarations ) {
1045
		if (expl && p->val_opt[0] == no_declarations) {
997
	    if ( IS_NULL_hashid ( p->name ) && !preproc_only ) {
1046
			if (IS_NULL_hashid(p->name) && !preproc_only) {
998
		report ( preproc_loc, ERR_dcl_dcl_none () ) ;
1047
				report(preproc_loc, ERR_dcl_dcl_none());
999
	    }
1048
			}
1000
	}
1049
		}
1001
	crt_linkage = ds ;
1050
		crt_linkage = ds;
1002
	new_linkage = ds ;
1051
		new_linkage = ds;
1003
	if ( q ) {
1052
		if (q) {
1004
	    int i ;
1053
			int i;
1005
	    crt_opts = q ;
1054
			crt_opts = q;
1006
	    real_opts = q ;
1055
			real_opts = q;
1007
	    crt_opt = q->opt ;
1056
			crt_opt = q->opt;
1008
	    for ( i = 0 ; i < CATALOG_SIZE ; i++ ) {
1057
			for (i = 0; i < CATALOG_SIZE; i++) {
1009
		if ( p->set [i] != ERROR_WHATEVER ) {
1058
				if (p->set[i]!= ERROR_WHATEVER) {
1010
		    /* Restore old option value */
1059
					/* Restore old option value */
1011
		    OPTION opt_old = p->opt [i] ;
1060
					OPTION opt_old = p->opt[i];
1012
		    OPTION opt_new = q->opt [i] ;
1061
					OPTION opt_new = q->opt[i];
1013
		    if ( opt_new != opt_old ) {
1062
					if (opt_new != opt_old) {
1014
			if ( OPT_CATALOG [i].scoped ) {
1063
						if (OPT_CATALOG[i].scoped) {
-
 
1064
							action_option(i,
1015
			    action_option ( i, ( unsigned ) opt_new, 1 ) ;
1065
							  (unsigned)opt_new, 1);
1016
			} else {
1066
						} else {
1017
			    q->opt [i] = opt_old ;
1067
							q->opt[i] = opt_old;
1018
			    q->set [i] = 1 ;
1068
							q->set[i] = 1;
-
 
1069
						}
-
 
1070
					}
-
 
1071
				}
1019
			}
1072
			}
1020
		    }
1073
			return;
1021
		}
1074
		}
1022
	    }
-
 
1023
	    return ;
-
 
1024
	}
1075
	}
1025
    }
-
 
1026
    report ( preproc_loc, ERR_pragma_scope_end () ) ;
1076
	report(preproc_loc, ERR_pragma_scope_end());
1027
    return ;
1077
	return;
1028
}
1078
}
1029
 
1079
 
1030
 
1080
 
1031
/*
1081
/*
1032
    USE A CHECKING SCOPE
1082
    USE A CHECKING SCOPE
1033
 
1083
 
1034
    This routine brings the set of checks given by p into the current
1084
    This routine brings the set of checks given by p into the current
1035
    checking scope.  e indicates the error severity with which to report
1085
    checking scope.  e indicates the error severity with which to report
1036
    reset options.
1086
    reset options.
1037
*/
1087
*/
1038
 
1088
 
1039
void use_mode
1089
void
1040
    PROTO_N ( ( p, e ) )
-
 
1041
    PROTO_T ( OPTIONS *p X int e )
1090
use_mode(OPTIONS *p, int e)
1042
{
-
 
1043
    int i ;
-
 
1044
    OPTIONS *q = real_opts ;
-
 
1045
    DECL_SPEC ds = p->lnk_opt [1] ;
-
 
1046
    if ( ds != dspec_ignore ) {
-
 
1047
	DECL_SPEC ods = q->lnk_opt [1] ;
-
 
1048
	if ( ods != dspec_ignore ) {
-
 
1049
	    /* Option already set in this scope */
-
 
1050
	    string s = ustrlit ( "link_extern" ) ;
-
 
1051
	    ERROR err = ERR_pragma_scope_set ( s ) ;
-
 
1052
	    if ( !IS_NULL_err ( err ) ) {
-
 
1053
		COPY_int ( err_severity ( err ), e ) ;
-
 
1054
		report ( preproc_loc, err ) ;
-
 
1055
	    }
-
 
1056
	}
-
 
1057
	q->lnk_opt [1] = ds ;
-
 
1058
	crt_linkage = ds ;
-
 
1059
	new_linkage = ds ;
-
 
1060
    }
-
 
1061
    for ( i = 0 ; i < CATALOG_SIZE ; i++ ) {
-
 
1062
	if ( p->set [i] != ERROR_WHATEVER && OPT_CATALOG [i].scoped ) {
-
 
1063
	    OPTION new_opt = p->opt [i] ;
-
 
1064
	    OPTION old_opt = q->opt [i] ;
-
 
1065
	    if ( new_opt != old_opt ) {
-
 
1066
		/* Option value changed */
-
 
1067
		q->opt [i] = new_opt ;
-
 
1068
		action_option ( i, ( unsigned ) new_opt, 0 ) ;
-
 
1069
	    }
-
 
1070
	    if ( q->set [i] != ERROR_WHATEVER && e != ERROR_NONE ) {
-
 
1071
		/* Option already set in this scope */
-
 
1072
		string s = ustrlit ( OPT_CATALOG [i].name ) ;
-
 
1073
		ERROR err = ERR_pragma_scope_set ( s ) ;
-
 
1074
		if ( !IS_NULL_err ( err ) ) {
-
 
1075
		    COPY_int ( err_severity ( err ), e ) ;
-
 
1076
		    report ( preproc_loc, err ) ;
-
 
1077
		}
-
 
1078
	    }
-
 
1079
	    q->set [i] = ERROR_SERIOUS ;
-
 
1080
	}
-
 
1081
    }
-
 
1082
    return ;
-
 
1083
}
-
 
1084
 
-
 
1085
 
-
 
1086
/*
-
 
1087
    SET CURRENT CHECKING SCOPE
-
 
1088
 
-
 
1089
    This routine sets the current checking scope to p.  It is used in
-
 
1090
    context switching in macro expansion.
-
 
1091
*/
-
 
1092
 
-
 
1093
void set_mode
-
 
1094
    PROTO_N ( ( p ) )
-
 
1095
    PROTO_T ( OPTIONS *p )
-
 
1096
{
1091
{
-
 
1092
	int i;
-
 
1093
	OPTIONS *q = real_opts;
-
 
1094
	DECL_SPEC ds = p->lnk_opt[1];
-
 
1095
	if (ds != dspec_ignore) {
-
 
1096
		DECL_SPEC ods = q->lnk_opt[1];
-
 
1097
		if (ods != dspec_ignore) {
-
 
1098
			/* Option already set in this scope */
-
 
1099
			string s = ustrlit("link_extern");
-
 
1100
			ERROR err = ERR_pragma_scope_set(s);
-
 
1101
			if (!IS_NULL_err(err)) {
-
 
1102
				COPY_int(err_severity(err), e);
-
 
1103
				report(preproc_loc, err);
-
 
1104
			}
-
 
1105
		}
-
 
1106
		q->lnk_opt[1] = ds;
-
 
1107
		crt_linkage = ds;
-
 
1108
		new_linkage = ds;
-
 
1109
	}
-
 
1110
	for (i = 0; i < CATALOG_SIZE; i++) {
-
 
1111
		if (p->set[i]!= ERROR_WHATEVER && OPT_CATALOG[i].scoped) {
-
 
1112
			OPTION new_opt = p->opt[i];
-
 
1113
			OPTION old_opt = q->opt[i];
-
 
1114
			if (new_opt != old_opt) {
-
 
1115
				/* Option value changed */
-
 
1116
				q->opt[i] = new_opt;
-
 
1117
				action_option(i,(unsigned)new_opt, 0);
-
 
1118
			}
-
 
1119
			if (q->set[i]!= ERROR_WHATEVER && e != ERROR_NONE) {
-
 
1120
				/* Option already set in this scope */
-
 
1121
				string s = ustrlit(OPT_CATALOG[i].name);
-
 
1122
				ERROR err = ERR_pragma_scope_set(s);
-
 
1123
				if (!IS_NULL_err(err)) {
-
 
1124
					COPY_int(err_severity(err), e);
-
 
1125
					report(preproc_loc, err);
-
 
1126
				}
-
 
1127
			}
-
 
1128
			q->set[i] = ERROR_SERIOUS;
-
 
1129
		}
-
 
1130
	}
-
 
1131
	return;
-
 
1132
}
-
 
1133
 
-
 
1134
 
-
 
1135
/*
-
 
1136
    SET CURRENT CHECKING SCOPE
-
 
1137
 
-
 
1138
    This routine sets the current checking scope to p.  It is used in
-
 
1139
    context switching in macro expansion.
-
 
1140
*/
-
 
1141
 
-
 
1142
void
-
 
1143
set_mode(OPTIONS *p)
-
 
1144
{
1097
    if ( p ) {
1145
	if (p) {
1098
	crt_opts = p ;
1146
		crt_opts = p;
1099
	crt_opt = p->opt ;
1147
		crt_opt = p->opt;
1100
    }
1148
	}
1101
    return ;
1149
	return;
1102
}
1150
}
1103
 
1151
 
1104
 
1152
 
1105
/*
1153
/*
1106
    USE A NAMED CHECKING SCOPE
1154
    USE A NAMED CHECKING SCOPE
1107
 
1155
 
1108
    This routine brings the named checking scope id back into scope.  The
1156
    This routine brings the named checking scope id back into scope.  The
1109
    opt argument describes how the resetting of these options are to be
1157
    opt argument describes how the resetting of these options are to be
1110
    handled.
1158
    handled.
1111
*/
1159
*/
1112
 
1160
 
1113
void use_option
1161
void
1114
    PROTO_N ( ( id, opt ) )
-
 
1115
    PROTO_T ( IDENTIFIER id X unsigned opt )
1162
use_option(IDENTIFIER id, unsigned opt)
1116
{
-
 
1117
    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
-
 
1118
    OPTIONS *p = find_option ( nm ) ;
-
 
1119
    if ( p == NULL ) {
-
 
1120
	report ( preproc_loc, ERR_pragma_scope_undef ( nm ) ) ;
-
 
1121
	return ;
-
 
1122
    }
-
 
1123
    use_mode ( p, error_severity [ opt ] ) ;
-
 
1124
    return ;
-
 
1125
}
-
 
1126
 
-
 
1127
 
-
 
1128
/*
-
 
1129
    ASSOCIATE A CHECKING SCOPE WITH A DIRECTORY
-
 
1130
 
-
 
1131
    This routine associates the named checking scope id with the named
-
 
1132
    include file directory dir.
-
 
1133
*/
-
 
1134
 
-
 
1135
void directory_option
-
 
1136
    PROTO_N ( ( dir, id ) )
-
 
1137
    PROTO_T ( IDENTIFIER dir X IDENTIFIER id )
-
 
1138
{
1163
{
-
 
1164
	HASHID nm = DEREF_hashid(id_name(id));
-
 
1165
	OPTIONS *p = find_option(nm);
-
 
1166
	if (p == NULL) {
-
 
1167
		report(preproc_loc, ERR_pragma_scope_undef(nm));
-
 
1168
		return;
-
 
1169
	}
-
 
1170
	use_mode(p, error_severity[opt]);
-
 
1171
	return;
-
 
1172
}
-
 
1173
 
-
 
1174
 
-
 
1175
/*
-
 
1176
    ASSOCIATE A CHECKING SCOPE WITH A DIRECTORY
-
 
1177
 
-
 
1178
    This routine associates the named checking scope id with the named
-
 
1179
    include file directory dir.
-
 
1180
*/
-
 
1181
 
-
 
1182
void
-
 
1183
directory_option(IDENTIFIER dir, IDENTIFIER id)
-
 
1184
{
1139
    string s ;
1185
	string s;
1140
    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
1186
	HASHID nm = DEREF_hashid(id_name(id));
1141
    OPTIONS *p = find_option ( nm ) ;
1187
	OPTIONS *p = find_option(nm);
1142
    if ( p == NULL ) {
1188
	if (p == NULL) {
1143
	report ( preproc_loc, ERR_pragma_scope_undef ( nm ) ) ;
1189
		report(preproc_loc, ERR_pragma_scope_undef(nm));
1144
    }
1190
	}
1145
    nm = DEREF_hashid ( id_name ( dir ) ) ;
1191
	nm = DEREF_hashid(id_name(dir));
1146
    s = DEREF_string ( hashid_name_etc_text ( nm ) ) ;
1192
	s = DEREF_string(hashid_name_etc_text(nm));
1147
    directory_mode ( s, p ) ;
1193
	directory_mode(s, p);
1148
    return ;
1194
	return;
1149
}
1195
}
1150
 
1196
 
1151
 
1197
 
1152
/*
1198
/*
1153
    INITIALISE OPTIONS
1199
    INITIALISE OPTIONS
1154
 
1200
 
1155
    This routine initialises the outer checking scope at the checking
1201
    This routine initialises the outer checking scope at the checking
1156
    level indicated by level and sets up the option hash table.
1202
    level indicated by level and sets up the option hash table.
1157
*/
1203
*/
1158
 
1204
 
1159
void init_option
1205
void
1160
    PROTO_N ( ( level ) )
-
 
1161
    PROTO_T ( int level )
1206
init_option(int level)
1162
{
1207
{
1163
    int i ;
1208
	int i;
1164
    string s ;
1209
	string s;
1165
    HASHID nm ;
1210
	HASHID nm;
1166
    OPTION *po ;
1211
	OPTION *po;
1167
    OPTIONS *p1, *p2 ;
1212
	OPTIONS *p1, *p2;
1168
    OPT_DATA *cat = OPT_CATALOG ;
1213
	OPT_DATA *cat = OPT_CATALOG;
1169
    OPT_VALUE_DATA *vcat = OPT_VALUE_CATALOG ;
1214
	OPT_VALUE_DATA *vcat = OPT_VALUE_CATALOG;
1170
 
1215
 
1171
    /* Mark basic options */
1216
	/* Mark basic options */
1172
    cat [ OPT_none ].scoped = 0 ;
1217
	cat[OPT_none].scoped = 0;
1173
    cat [ OPT_warning ].scoped = 0 ;
1218
	cat[OPT_warning].scoped = 0;
1174
    cat [ OPT_error ].scoped = 0 ;
1219
	cat[OPT_error].scoped = 0;
1175
    cat [ OPT_whatever ].scoped = 0 ;
1220
	cat[OPT_whatever].scoped = 0;
1176
 
1221
 
1177
    /* Mark unscoped options */
1222
	/* Mark unscoped options */
1178
    cat [ OPT_const_internal ].scoped = 0 ;
1223
	cat[OPT_const_internal].scoped = 0;
1179
    cat [ OPT_cpplus_comment ].scoped = 0 ;
1224
	cat[OPT_cpplus_comment].scoped = 0;
1180
    cat [ OPT_digraph ].scoped = 0 ;
1225
	cat[OPT_digraph].scoped = 0;
1181
    cat [ OPT_dollar_ident ].scoped = 0 ;
1226
	cat[OPT_dollar_ident].scoped = 0;
1182
    cat [ OPT_ellipsis_ident ].scoped = 0 ;
1227
	cat[OPT_ellipsis_ident].scoped = 0;
1183
    cat [ OPT_inline_internal ].scoped = 0 ;
1228
	cat[OPT_inline_internal].scoped = 0;
1184
    cat [ OPT_iso_keyword ].scoped = 0 ;
1229
	cat[OPT_iso_keyword].scoped = 0;
1185
    cat [ OPT_lint_comment ].scoped = 0 ;
1230
	cat[OPT_lint_comment].scoped = 0;
1186
    cat [ OPT_trigraph ].scoped = 0 ;
1231
	cat[OPT_trigraph].scoped = 0;
1187
 
1232
 
1188
    /* A few other initialisations */
1233
	/* A few other initialisations */
1189
    max_id_length = vcat [ OPT_VAL_name_limit ].min_value ;
1234
	max_id_length = vcat[OPT_VAL_name_limit].min_value;
1190
 
1235
 
1191
    /* Set up default compilation modes */
1236
	/* Set up default compilation modes */
1192
    s = ustrlit ( "__DEFAULT__" ) ;
1237
	s = ustrlit("__DEFAULT__");
1193
    nm = lookup_name ( s, hash ( s ), 0, lex_identifier ) ;
1238
	nm = lookup_name(s, hash(s), 0, lex_identifier);
1194
    p1 = new_option ( nm, NIL ( OPTIONS ), 0 ) ;
1239
	p1 = new_option(nm, NIL(OPTIONS), 0);
1195
    s = ustrlit ( "__ALL__" ) ;
1240
	s = ustrlit("__ALL__");
1196
    nm = lookup_name ( s, hash ( s ), 0, lex_identifier ) ;
1241
	nm = lookup_name(s, hash(s), 0, lex_identifier);
1197
    p2 = new_option ( nm, NIL ( OPTIONS ), 1 ) ;
1242
	p2 = new_option(nm, NIL(OPTIONS), 1);
1198
 
1243
 
1199
    /* Bring option into scope */
1244
	/* Bring option into scope */
1200
    if ( level == 1 ) p1 = p2 ;
1245
	if (level == 1) {
-
 
1246
		p1 = p2;
-
 
1247
	}
1201
    p1 = new_option ( NULL_hashid, p1, 0 ) ;
1248
	p1 = new_option(NULL_hashid, p1, 0);
1202
    crt_opts = p1 ;
1249
	crt_opts = p1;
1203
    real_opts = p1 ;
1250
	real_opts = p1;
1204
    po = p1->opt ;
1251
	po = p1->opt;
1205
    crt_opt = po ;
1252
	crt_opt = po;
1206
    for ( i = 0 ; i < CATALOG_SIZE ; i++ ) {
1253
	for (i = 0; i < CATALOG_SIZE; i++) {
1207
	OPTION e = *( po++ ) ;
1254
		OPTION e = *(po++);
1208
	action_option ( i, ( unsigned ) e, 0 ) ;
1255
		action_option(i, (unsigned)e, 0);
1209
    }
1256
	}
1210
    for ( i = 0 ; i < VALUE_CAT_SIZE ; i++ ) {
1257
	for (i = 0; i < VALUE_CAT_SIZE; i++) {
1211
	action_value ( i, vcat->max_value ) ;
1258
		action_value(i, vcat->max_value);
1212
	vcat++ ;
1259
		vcat++;
1213
    }
1260
	}
1214
    return ;
1261
	return;
1215
}
1262
}
1216
 
1263
 
1217
 
1264
 
1218
/*
1265
/*
1219
    TERMINATE OPTIONS
1266
    TERMINATE OPTIONS
Line 1221... Line 1268...
1221
    This routine calls end_option for all unterminated checking scopes.
1268
    This routine calls end_option for all unterminated checking scopes.
1222
    It also reports any implementation limits which have been exceeded
1269
    It also reports any implementation limits which have been exceeded
1223
    but not previously reported.
1270
    but not previously reported.
1224
*/
1271
*/
1225
 
1272
 
1226
void term_option
1273
void
1227
    PROTO_Z ()
1274
term_option(void)
1228
{
1275
{
1229
    if ( real_opts ) {
1276
	if (real_opts) {
1230
	int i ;
1277
		int i;
1231
	int expl = 1 ;
1278
		int expl = 1;
1232
	OPT_VALUE_DATA *p = OPT_VALUE_CATALOG ;
1279
		OPT_VALUE_DATA *p = OPT_VALUE_CATALOG;
1233
	for ( i = 0 ; i < VALUE_CAT_SIZE ; i++ ) {
1280
		for (i = 0; i < VALUE_CAT_SIZE; i++) {
1234
	    if ( p->incr == 2 ) {
1281
			if (p->incr == 2) {
1235
		/* Implementation limit exceeded */
1282
				/* Implementation limit exceeded */
1236
		string s = ustrlit ( p->name ) ;
1283
				string s = ustrlit(p->name);
1237
		unsigned long v = p->crt_value ;
1284
				unsigned long v = p->crt_value;
1238
		unsigned long u = p->min_value ;
1285
				unsigned long u = p->min_value;
1239
		report ( preproc_loc, ERR_limits_min ( s, v, u ) ) ;
1286
				report(preproc_loc, ERR_limits_min(s, v, u));
1240
		p->incr = 1 ;
1287
				p->incr = 1;
1241
	    }
1288
			}
1242
	    p++ ;
1289
			p++;
1243
	}
1290
		}
1244
	while ( real_opts->prev ) {
1291
		while (real_opts->prev) {
1245
	    end_option ( expl ) ;
1292
			end_option(expl);
1246
	    expl = 0 ;
1293
			expl = 0;
1247
	}
1294
		}
1248
	if ( expl && no_declarations == 0 && !preproc_only ) {
1295
		if (expl && no_declarations == 0 && !preproc_only) {
1249
	    report ( preproc_loc, ERR_dcl_dcl_none () ) ;
1296
			report(preproc_loc, ERR_dcl_dcl_none());
-
 
1297
		}
1250
	}
1298
	}
1251
    }
-
 
1252
    xfree_nof ( all_option_hash ) ;
1299
	xfree_nof(all_option_hash);
1253
    all_option_hash = NULL ;
1300
	all_option_hash = NULL;
1254
    return ;
1301
	return;
1255
}
1302
}