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-2005 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
#include "config.h"
62
#include "c_types.h"
63
#include "ctype_ops.h"
64
#include "etype_ops.h"
65
#include "ftype_ops.h"
66
#include "hashid_ops.h"
67
#include "id_ops.h"
68
#include "itype_ops.h"
69
#include "member_ops.h"
70
#include "type_ops.h"
71
#include "error.h"
72
#include "option.h"
73
#include "basetype.h"
74
#include "char.h"
75
#include "chktype.h"
76
#include "hash.h"
77
#include "lex.h"
78
#include "namespace.h"
79
#include "symbols.h"
80
#include "syntax.h"
81
#include "token.h"
82
#include "ustring.h"
83
#include "xalloc.h"
84
 
85
 
86
/*
87
    HASH TABLES
88
 
89
    The hash tables consist of an array of hash identifiers, one for each
90
    hash value.  All the hash table entries with the same hash value are
91
    chained into a list using their next field.  There are two hash tables,
92
    one for strings and one for types.
93
*/
94
 
7 7u83 95
HASHID *hash_table;
96
static HASHID *hash_type_table;
2 7u83 97
 
98
 
99
/*
100
    IDENTIFIER NAME HASHING FUNCTION
101
 
102
    This routine calculates the hash value associated with the identifier
103
    name s.  The main parser routine, read_token, calculates the hash values
104
    of the identifiers it reads on the fly and stores them in token_hash.
105
    Therefore any changes to this routine should also be reflected in
106
    read_token.
107
*/
108
 
7 7u83 109
unsigned long
110
hash(string s)
2 7u83 111
{
7 7u83 112
	character c;
113
	unsigned long h = 0;
114
	while (c = *(s++), c != 0) {
115
		h = HASH_POWER * h + (unsigned long)c;
116
	}
117
	return(h % HASH_SIZE);
2 7u83 118
}
119
 
120
 
121
/*
122
    TYPE NAME HASHING FUNCTION
123
 
124
    This routine calculates the hash value associated with the type t.
125
    This is used in the look-up for the conversion function identifier
126
    'operator t'.
127
*/
128
 
7 7u83 129
static unsigned long
130
hash_type(TYPE t)
2 7u83 131
{
7 7u83 132
	unsigned long h = 0;
133
	while (!IS_NULL_type(t)) {
134
		unsigned long sub = 0;
135
		unsigned long tag = (unsigned long)TAG_type(t);
136
		CV_SPEC qual = DEREF_cv(type_qual(t));
137
		switch (tag) {
138
		case type_integer_tag: {
139
			INT_TYPE it = DEREF_itype(type_integer_rep(t));
140
			if (IS_itype_basic(it)) {
141
				BUILTIN_TYPE no =
142
				    DEREF_ntype(itype_basic_no(it));
143
				sub = (unsigned long)no;
144
			}
145
			t = NULL_type;
146
			break;
2 7u83 147
		}
7 7u83 148
		case type_floating_tag: {
149
			FLOAT_TYPE ft = DEREF_ftype(type_floating_rep(t));
150
			if (IS_ftype_basic(ft)) {
151
				BUILTIN_TYPE no =
152
				    DEREF_ntype(ftype_basic_no(ft));
153
				sub = (unsigned long)no;
154
			}
155
			t = NULL_type;
156
			break;
2 7u83 157
		}
7 7u83 158
		case type_ptr_tag:
159
		case type_ref_tag:
160
			t = DEREF_type(type_ptr_etc_sub(t));
161
			break;
162
		case type_ptr_mem_tag: {
163
			CLASS_TYPE ct = DEREF_ctype(type_ptr_mem_of(t));
164
			IDENTIFIER cid = DEREF_id(ctype_name(ct));
165
			HASHID cnm = DEREF_hashid(id_name(cid));
166
			sub = DEREF_ulong(hashid_hash(cnm));
167
			t = DEREF_type(type_ptr_mem_sub(t));
168
			break;
169
		}
170
		case type_func_tag: {
171
			LIST(TYPE)p = DEREF_list(type_func_ptypes(t));
172
			sub = (unsigned long)LENGTH_list(p);
173
			t = DEREF_type(type_func_ret(t));
174
			break;
175
		}
176
		case type_array_tag:
177
			t = DEREF_type(type_array_sub(t));
178
			break;
179
		case type_bitfield_tag:
180
			t = find_bitfield_type(t);
181
			break;
182
		case type_compound_tag: {
183
			CLASS_TYPE ct = DEREF_ctype(type_compound_defn(t));
184
			IDENTIFIER cid = DEREF_id(ctype_name(ct));
185
			HASHID cnm = DEREF_hashid(id_name(cid));
186
			sub = DEREF_ulong(hashid_hash(cnm));
187
			t = NULL_type;
188
			break;
189
		}
190
		case type_enumerate_tag: {
191
			ENUM_TYPE et = DEREF_etype(type_enumerate_defn(t));
192
			IDENTIFIER eid = DEREF_id(etype_name(et));
193
			HASHID enm = DEREF_hashid(id_name(eid));
194
			sub = DEREF_ulong(hashid_hash(enm));
195
			t = NULL_type;
196
			break;
197
		}
198
		default :
199
			t = NULL_type;
200
			break;
201
		}
202
		h += (64 * sub + 4 * tag + (unsigned long)qual);
2 7u83 203
	}
7 7u83 204
	return(h % HASH_TYPE_SIZE);
2 7u83 205
}
206
 
207
 
208
/*
209
    INITIALISE A HASH TABLE ENTRY
210
 
211
    This routine initialises the hash table entry nm by creating a dummy
212
    identifier with lexical token value tok for it to point to.
213
*/
214
 
7 7u83 215
static void
216
init_hashid(HASHID nm, int tok)
2 7u83 217
{
7 7u83 218
	IDENTIFIER id;
219
	MAKE_id_dummy(nm, dspec_none, NULL_nspace, crt_loc, id);
220
	COPY_ulong(id_no(id), (unsigned long)tok);
221
	COPY_id(hashid_id(nm), id);
222
	COPY_id(hashid_cache(nm), id);
223
	return;
2 7u83 224
}
225
 
226
 
227
/*
228
    LOOK UP AN IDENTIFIER NAME IN THE HASH TABLE
229
 
230
    This routine looks up the identifier name s in the hash table, creating
231
    it if it does not already exist.  h gives the value of hash ( s ) (which
232
    gets checked by an assertion).  The argument tok is set to lex_unknown to
233
    indicate that the identifier has just been read by read_token, otherwise
234
    it gives the underlying default lexical token.
235
*/
236
 
7 7u83 237
HASHID
238
lookup_name(string s, unsigned long h, int ext, int tok)
2 7u83 239
{
7 7u83 240
	unsigned tag;
241
	unsigned long len;
242
	HASHID prev = NULL_hashid;
243
	HASHID nm = hash_table[h];
244
	ASSERT(h == hash(s));
2 7u83 245
 
7 7u83 246
	/* Search through existing entries */
247
	while (!IS_NULL_hashid(nm)) {
248
		string t = DEREF_string(hashid_name_etc_text(nm));
249
		int c = ustrcmp(t, s);
250
		if (c == 0) {
251
			/* Name matches */
252
			return(nm);
253
		}
254
		if (c > 0) {
255
			break;
256
		}
257
		prev = nm;
258
		nm = DEREF_hashid(hashid_next(nm));
2 7u83 259
	}
260
 
7 7u83 261
	/* Create new hash table entry */
262
	len = (unsigned long)ustrlen(s);
263
	if (tok == lex_unknown) {
264
		s = xustrncpy(s, (gen_size)len);
265
		tok = lex_identifier;
2 7u83 266
	}
7 7u83 267
	tag = hashid_name_tag;
268
	if (ext) {
269
		/* Check for extended identifiers */
270
		string t = s;
271
		while (t = ustrchr(t, char_backslash), t != NULL) {
272
			t++;
273
			if (*t == char_u) {
274
				/* '\uxxxx' counts as one character */
275
				len -= 5;
276
			} else {
277
				/* '\Uxxxxxxxx' counts as one character */
278
				len -= 9;
279
			}
280
		}
281
		tag = hashid_ename_tag;
282
	}
283
	MAKE_hashid_name_etc(tag, nm, h, s, nm);
284
	if (IS_NULL_hashid(prev)) {
285
		hash_table[h] = nm;
286
	} else {
287
		COPY_hashid(hashid_next(prev), nm);
288
	}
289
	init_hashid(nm, tok);
290
	if (len >= max_id_length) {
291
		/* Check name length */
292
		IGNORE check_value(OPT_VAL_name_limit, len, nm);
293
	}
294
	return(nm);
2 7u83 295
}
296
 
297
 
298
/*
299
    CREATE A SPECIAL FUNCTION NAME
300
 
301
    This routine creates a constructor, destructor or conversion function
302
    name (as indicated by tag) for the non-class type t named id.
303
*/
304
 
7 7u83 305
static HASHID
306
lookup_special(TYPE t, IDENTIFIER id, unsigned tag)
2 7u83 307
{
7 7u83 308
	unsigned long h = hash_type(t);
309
	HASHID prev = hash_type_table[h];
310
	HASHID nm = prev;
2 7u83 311
 
7 7u83 312
	/* Search through existing entries */
313
	while (!IS_NULL_hashid(nm)) {
314
		if (TAG_hashid(nm) == tag) {
315
			TYPE s = DEREF_type(hashid_constr_etc_type(nm));
316
			if (eq_type(s, t)) {
317
				COPY_id(hashid_constr_etc_tid(nm), id);
318
				return(nm);
319
			}
320
		}
321
		nm = DEREF_hashid(hashid_next(nm));
2 7u83 322
	}
323
 
7 7u83 324
	/* Create new hash table entry */
325
	ASSERT(h < HASH_SIZE);
326
	MAKE_hashid_constr_etc(tag, prev, h, t, id, nm);
327
	init_hashid(nm, lex_identifier);
328
	hash_type_table[h] = nm;
329
	return(nm);
2 7u83 330
}
331
 
332
 
333
/*
334
    CREATE THE CONSTRUCTOR FOR A TYPE
335
 
336
    This routine creates the hash table entry for the constructor of type t
337
    and name id.
338
*/
339
 
7 7u83 340
HASHID
341
lookup_constr(TYPE t, IDENTIFIER id)
2 7u83 342
{
7 7u83 343
	HASHID nm;
344
	if (IS_type_compound(t)) {
345
		CLASS_TYPE ct = DEREF_ctype(type_compound_defn(t));
346
		IDENTIFIER cid = DEREF_id(ctype_constr(ct));
347
		if (IS_NULL_id(cid)) {
348
			/* Create class contructor */
349
			NAMESPACE ns = DEREF_nspace(ctype_member(ct));
350
			MAKE_hashid_constr(NULL_hashid, 0, t, id, nm);
351
			init_hashid(nm, lex_identifier);
352
			cid = DEREF_id(hashid_id(nm));
353
			COPY_nspace(id_parent(cid), ns);
354
			COPY_id(ctype_constr(ct), cid);
355
			IGNORE search_member(ns, nm, 1);
356
		} else {
357
			nm = DEREF_hashid(id_name(cid));
358
		}
2 7u83 359
	} else {
7 7u83 360
		nm = lookup_special(t, id, hashid_constr_tag);
2 7u83 361
	}
7 7u83 362
	return(nm);
2 7u83 363
}
364
 
365
 
366
/*
367
    CREATE THE DESTRUCTOR FOR A TYPE
368
 
369
    This routine creates the hash table entry for the destructor of type t
370
    and name id.
371
*/
372
 
7 7u83 373
HASHID
374
lookup_destr(TYPE t, IDENTIFIER id)
2 7u83 375
{
7 7u83 376
	HASHID nm;
377
	if (IS_type_compound(t)) {
378
		CLASS_TYPE ct = DEREF_ctype(type_compound_defn(t));
379
		IDENTIFIER cid = DEREF_id(ctype_destr(ct));
380
		if (IS_NULL_id(cid)) {
381
			/* Create class destructor */
382
			NAMESPACE ns = DEREF_nspace(ctype_member(ct));
383
			MAKE_hashid_destr(NULL_hashid, 1, t, id, nm);
384
			init_hashid(nm, lex_identifier);
385
			cid = DEREF_id(hashid_id(nm));
386
			COPY_nspace(id_parent(cid), ns);
387
			COPY_id(ctype_destr(ct), cid);
388
			IGNORE search_member(ns, nm, 1);
389
		} else {
390
			nm = DEREF_hashid(id_name(cid));
391
		}
2 7u83 392
	} else {
7 7u83 393
		nm = lookup_special(t, id, hashid_destr_tag);
2 7u83 394
	}
7 7u83 395
	return(nm);
2 7u83 396
}
397
 
398
 
399
/*
400
    LOOK UP A CONVERSION FUNCTION NAME
401
 
402
    This routine returns the hash table entry for the conversion function
403
    corresponding to the type t.
404
*/
405
 
7 7u83 406
HASHID
407
lookup_conv(TYPE t)
2 7u83 408
{
7 7u83 409
	HASHID nm = lookup_special(t, NULL_id, hashid_conv_tag);
410
	return(nm);
2 7u83 411
}
412
 
413
 
414
/*
415
    OVERLOADED OPERATOR LOOK-UP TABLE
416
 
417
    This table gives the hash table entries for the overloaded operator
418
    function names, 'operator +' etc.  It gives a straight look-up depending
419
    on the lexical token number of the operator.  All ISO keyword and
420
    digraphs are represented in their primary form.
421
*/
422
 
7 7u83 423
HASHID *hash_ops_table;
2 7u83 424
 
425
 
426
/*
427
    CREATE AN OPERATOR HASH TABLE ENTRY
428
 
429
    This routine creates a hash table entry for 'operator op' when op has
430
    lexical token number t.
431
*/
432
 
7 7u83 433
static HASHID
434
make_op(int t)
2 7u83 435
{
7 7u83 436
	HASHID nm;
437
	unsigned long h = (unsigned long)t;
438
	MAKE_hashid_op(NULL_hashid, (h % HASH_SIZE), t, nm);
439
	init_hashid(nm, lex_identifier);
440
	return(nm);
2 7u83 441
}
442
 
443
 
444
/*
445
    LOOK UP AN ANONYMOUS IDENTIFIER
446
 
447
    This routine creates a hash table entry for an anonymous identifier.
448
    Note that each anonymous identifier gives a distinct hash table entry.
449
*/
450
 
7 7u83 451
HASHID
452
lookup_anon(void)
2 7u83 453
{
7 7u83 454
	HASHID nm;
455
	static unsigned long anon_no = 0;
456
	unsigned long a = anon_no++;
457
	MAKE_hashid_anon(NULL_hashid, (a % HASH_SIZE), a, nm);
458
	init_hashid(nm, lex_identifier);
459
	return(nm);
2 7u83 460
}
461
 
462
 
463
/*
464
    EXPAND AN IDENTIFIER NAME
465
 
466
    This routine expands the identifier name nm.  For example, if t is
467
    a tokenised type defined to be int, then 'operator t' expands to
468
    'operator int'.  ct gives the expansion type for constructors and
469
    destructors.
470
*/
471
 
7 7u83 472
HASHID
473
expand_name(HASHID nm, CLASS_TYPE ct)
2 7u83 474
{
7 7u83 475
	switch (TAG_hashid(nm)) {
476
	case hashid_constr_tag:
477
		/* Constructor names */
478
		if (!IS_NULL_ctype(ct)) {
479
			IDENTIFIER id = DEREF_id(ctype_constr(ct));
480
			nm = DEREF_hashid(id_name(id));
481
		} else {
482
			TYPE t = DEREF_type(hashid_constr_type(nm));
483
			TYPE s = expand_type(t, 1);
484
			if (!EQ_type(t, s)) {
485
				nm = lookup_constr(s, NULL_id);
486
			}
2 7u83 487
		}
7 7u83 488
		break;
489
	case hashid_destr_tag:
490
		/* Destructor names */
491
		if (!IS_NULL_ctype(ct)) {
492
			IDENTIFIER id = DEREF_id(ctype_destr(ct));
493
			nm = DEREF_hashid(id_name(id));
494
		} else {
495
			TYPE t = DEREF_type(hashid_destr_type(nm));
496
			TYPE s = expand_type(t, 1);
497
			if (!EQ_type(t, s)) {
498
				nm = lookup_destr(s, NULL_id);
499
			}
2 7u83 500
		}
7 7u83 501
		break;
502
	case hashid_conv_tag: {
503
		/* Conversion function names */
504
		TYPE t = DEREF_type(hashid_conv_type(nm));
505
		TYPE s = expand_type(t, 1);
506
		if (!EQ_type(t, s)) {
507
			nm = lookup_conv(s);
508
		}
509
		break;
2 7u83 510
	}
511
	}
7 7u83 512
	return(nm);
2 7u83 513
}
514
 
515
 
516
/*
517
    FIND NEXT VERSION OF AN EXPANDED IDENTIFIER NAME
518
 
519
    There is a complication in the expansion of conversion function names
520
    in that when types are identified more than one name may refer to the
521
    same type.  This routine finds the next such possible name returning
522
    the null identifier name to indicate that there are no more.
523
*/
524
 
7 7u83 525
HASHID
526
next_expand_name(HASHID nm)
2 7u83 527
{
7 7u83 528
	if (IS_hashid_conv(nm)) {
529
		int started = 0;
530
		TYPE t = DEREF_type(hashid_conv_type(nm));
531
		unsigned long h = hash_type(t);
532
		HASHID pnm = hash_type_table[h];
533
		while (!IS_NULL_hashid(pnm)) {
534
			if (EQ_hashid(pnm, nm)) {
535
				started = 1;
536
			} else if (started && IS_hashid_conv(pnm)) {
537
				TYPE s = DEREF_type(hashid_conv_type(pnm));
538
				if (eq_type(s, t)) return(pnm);
539
			}
540
			pnm = DEREF_hashid(hashid_next(pnm));
541
		}
2 7u83 542
	}
7 7u83 543
	return(NULL_hashid);
2 7u83 544
}
545
 
546
 
547
/*
548
    FIND A HASH IDENTIFIER NUMBER
549
 
550
    This routine finds the lexical token number associated with the hash
551
    identifier nm.  For a keyword, whether active or not, this is the
552
    associated value from syntax.h, otherwise it is lex_identifier.
553
*/
554
 
7 7u83 555
int
556
find_hashid(HASHID nm)
2 7u83 557
{
7 7u83 558
	unsigned long lex;
559
	IDENTIFIER id = DEREF_id(hashid_id(nm));
560
	while (!IS_id_dummy(id)) {
561
		/* Scan to last hidden value */
562
		id = DEREF_id(id_alias(id));
563
	}
564
	lex = DEREF_ulong(id_no(id));
565
	return((int)lex);
2 7u83 566
}
567
 
568
 
569
/*
570
    FIND AN UNDERLYING IDENTIFIER
571
 
572
    This routine finds the dummy identifier underlying id.
573
*/
574
 
7 7u83 575
IDENTIFIER
576
underlying_id(IDENTIFIER id)
2 7u83 577
{
7 7u83 578
	HASHID nm = DEREF_hashid(id_name(id));
579
	id = DEREF_id(hashid_id(nm));
580
	while (!IS_id_dummy(id)) {
581
		/* Scan to last hidden value */
582
		id = DEREF_id(id_alias(id));
583
	}
584
	return(id);
2 7u83 585
}
586
 
587
 
588
/*
589
    SET THE LOCATION OF A COMPLEX IDENTIFIER
590
 
591
    The precise location of the last use of a hash identifier is stored
592
    in the loc field of its associated dummy identifier.  For simple
593
    identifiers this is set in read_token, however for more complex
594
    cases this routine sets the location of id to be the location of pid.
595
*/
596
 
7 7u83 597
void
598
set_hashid_loc(IDENTIFIER id, IDENTIFIER pid)
2 7u83 599
{
7 7u83 600
	if (!IS_NULL_id(pid)) {
601
		LOCATION loc;
602
		if (!IS_id_dummy(id)) {
603
			id = underlying_id(id);
604
		}
605
		if (!IS_id_dummy(pid)) {
606
			pid = underlying_id(pid);
607
		}
608
		DEREF_loc(id_loc(pid), loc);
609
		COPY_loc(id_loc(id), loc);
610
	}
611
	return;
2 7u83 612
}
613
 
614
 
615
/*
616
    MODIFY AN IDENTIFIER NAME
617
 
618
    This routine modifies the name of the identifier id by adding a prime
619
    to it.  This is intended primarily for debugging purposes.
620
*/
621
 
7 7u83 622
void
623
prime_name(IDENTIFIER id)
2 7u83 624
{
7 7u83 625
	if (!IS_NULL_id(id)) {
626
		HASHID nm = DEREF_hashid(id_name(id));
627
		if (IS_hashid_name(nm)) {
628
			string s = DEREF_string(hashid_name_text(nm));
629
			s = xustrcat(s, ustrlit("'"));
630
			nm = lookup_name(s, hash(s), 0, lex_identifier);
631
		}
632
		COPY_hashid(id_name(id), nm);
2 7u83 633
	}
7 7u83 634
	return;
2 7u83 635
}
636
 
637
 
638
/*
639
    KEYWORD HASH TABLE ENTRIES
640
 
641
    The table hash_keyword gives the hash table entries for the keywords.
642
    These are numbered from LAST_KEYWORD to FIRST_KEYWORD.  The array
643
    should be accessed through the macro KEYWORD defined in hash.h, which
644
    includes the appropriate offset.
645
*/
646
 
7 7u83 647
HASHID hash_keyword[LAST_KEYWORD - FIRST_KEYWORD + 1];
648
IDENTIFIER underlying_op = NULL_id;
2 7u83 649
 
650
 
651
/*
652
    INITIALISE THE HASH TABLE
653
 
654
    This routine allocates space for the hash table and sets all its entries
655
    to NULL.  It also sets up the operator look-up table.
656
*/
657
 
7 7u83 658
void
659
init_hash(void)
2 7u83 660
{
7 7u83 661
	int n;
662
	unsigned long i;
2 7u83 663
 
7 7u83 664
	/* Set up identifier hash table */
665
	hash_table = xmalloc_nof(HASHID, HASH_SIZE);
666
	for (i = 0; i < HASH_SIZE; i++) {
667
		hash_table[i] = NULL_hashid;
668
	}
2 7u83 669
 
7 7u83 670
	/* Set up type hash table */
671
	hash_type_table = xmalloc_nof(HASHID, HASH_TYPE_SIZE);
672
	for (i = 0; i < HASH_TYPE_SIZE; i++) {
673
		hash_type_table[i] = NULL_hashid;
674
	}
2 7u83 675
 
7 7u83 676
	/* Set up operator look-up table */
677
	hash_ops_table = xmalloc_nof(HASHID, LAST_TOKEN + 1);
678
	for (n = 0; n <= LAST_TOKEN; n++) {
679
		hash_ops_table[n] = NULL_hashid;
680
	}
2 7u83 681
 
7 7u83 682
	/* Allocate hash table entries for all symbols */
683
	for (n = FIRST_C_SYMBOL; n <= LAST_C_SYMBOL; n++) {
684
		hash_ops_table[n] = make_op(n);
685
	}
686
	for (n = FIRST_CPP_SYMBOL; n <= LAST_CPP_SYMBOL; n++) {
687
		hash_ops_table[n] = make_op(n);
688
	}
689
	for (n = FIRST_EXTRA_SYMBOL; n <= LAST_EXTRA_SYMBOL; n++) {
690
		hash_ops_table[n] = make_op(n);
691
	}
692
	hash_ops_table[lex_array_Hop] = make_op(lex_array_Hop);
693
	hash_ops_table[lex_cond_Hop] = make_op(lex_cond_Hop);
694
	hash_ops_table[lex_delete] = make_op(lex_delete);
695
	hash_ops_table[lex_delete_Harray] = make_op(lex_delete_Harray);
696
	hash_ops_table[lex_func_Hop] = make_op(lex_func_Hop);
697
	hash_ops_table[lex_new] = make_op(lex_new);
698
	hash_ops_table[lex_new_Harray] = make_op(lex_new_Harray);
699
	hash_ops_table[lex_alignof] = make_op(lex_alignof);
700
	hash_ops_table[lex_sizeof] = make_op(lex_sizeof);
701
	hash_ops_table[lex_typeid] = make_op(lex_typeid);
702
	hash_ops_table[lex_vtable] = make_op(lex_vtable);
2 7u83 703
 
7 7u83 704
	/* Map secondary representations to primary representations */
705
	for (n = FIRST_DIGRAPH; n <= LAST_DIGRAPH; n++) {
706
		int m = primary_form(n);
707
		hash_ops_table[n] = hash_ops_table[m];
708
	}
709
	for (n = FIRST_ISO_KEYWORD; n <= LAST_ISO_KEYWORD; n++) {
710
		int m = primary_form(n);
711
		hash_ops_table[n] = hash_ops_table[m];
712
	}
2 7u83 713
 
7 7u83 714
	/* This is necessary for the definition of KEYWORD */
715
	ASSERT(FIRST_KEYWORD == lex_auto);
716
	return;
2 7u83 717
}