Subversion Repositories tendra.SVN

Rev

Rev 2 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
/*** name-entry.c --- Name table entry ADT.
32
 *
33
 ** Author: Steve Folkes <smf@hermes.mod.uk>
34
 *
35
 *** Commentary:
36
 *
37
 * This file implements the name table entry routines used by the TDF
38
 * linker.
39
 *
40
 *** Change Log:
41
 * $Log: name-entry.c,v $
42
 * Revision 1.1.1.1  1998/01/17  15:57:19  release
43
 * First version to be checked into rolling release.
44
 *
45
 * Revision 1.3  1995/09/22  08:39:24  smf
46
 * Fixed problems with incomplete structures (to shut "tcc" up).
47
 * Fixed some problems in "name-key.c" (no real problems, but rewritten to
48
 * reduce the warnings that were output by "tcc" and "gcc").
49
 * Fixed bug CR95_354.tld-common-id-problem (library capsules could be loaded
50
 * more than once).
51
 *
52
 * Revision 1.2  1994/12/12  11:46:35  smf
53
 * Performing changes for 'CR94_178.sid+tld-update' - bringing in line with
54
 * OSSG C Coding Standards.
55
 *
56
 * Revision 1.1.1.1  1994/07/25  16:03:34  smf
57
 * Initial import of TDF linker 3.5 non shared files.
58
 *
59
**/
60
 
61
/****************************************************************************/
62
 
63
#include "name-entry.h"
64
#include "capsule.h"
65
#include "debug.h"
66
#include "gen-errors.h"
67
#include "library.h"
68
#include "name-table.h"
69
#include "ostream.h"
70
#include "shape-entry.h"
71
#include "shape-table.h"
72
#include "tdf.h"
73
#include "unit-table.h"
74
 
75
#include "solve-cycles.h"
76
 
77
/*--------------------------------------------------------------------------*/
78
 
79
NameEntryP
80
name_entry_create_direct PROTO_N ((key, shape_entry))
81
			 PROTO_T (NameKeyP    key X
82
				  ShapeEntryP shape_entry)
83
{
84
    NameEntryP entry = ALLOCATE (NameEntryT);
85
 
86
    entry->next                    = NIL (NameEntryP);
87
    name_key_copy (&(entry->key), key);
88
    entry->type                    = NT_DIRECT;
89
    entry->u.direct.id             = shape_entry_next_id (shape_entry);
90
    entry->u.direct.use            = 0;
91
    entry->u.direct.definition     = NIL (CapsuleP);
92
    entry->u.direct.lib_definition = NIL (LibCapsuleP);
93
    shape_entry_add_to_list (shape_entry, entry);
94
    return (entry);
95
}
96
 
97
NameEntryP
98
name_entry_create_indirect PROTO_N ((key, indirect))
99
			   PROTO_T (NameKeyP   key X
100
				    NameEntryP indirect)
101
{
102
    NameEntryP entry = ALLOCATE (NameEntryT);
103
 
104
    entry->next       = NIL (NameEntryP);
105
    name_key_copy (&(entry->key), key);
106
    entry->type       = NT_INDIRECT;
107
    entry->u.indirect = indirect;
108
    return (entry);
109
}
110
 
111
NameEntryP
112
name_entry_create_place PROTO_N ((key))
113
			PROTO_T (NameKeyP key)
114
{
115
    NameEntryP entry = ALLOCATE (NameEntryT);
116
 
117
    entry->next       = NIL (NameEntryP);
118
    name_key_copy (&(entry->key), key);
119
    entry->type       = NT_PLACEHOLDER;
120
    return (entry);
121
}
122
 
123
void
124
name_entry_make_direct PROTO_N ((entry, shape_entry))
125
		       PROTO_T (NameEntryP  entry X
126
				ShapeEntryP shape_entry)
127
{
128
    ASSERT (name_entry_is_place (entry));
129
    entry->type                    = NT_DIRECT;
130
    entry->u.direct.id             = shape_entry_next_id (shape_entry);
131
    entry->u.direct.use            = 0;
132
    entry->u.direct.definition     = NIL (CapsuleP);
133
    entry->u.direct.lib_definition = NIL (LibCapsuleP);
134
    shape_entry_add_to_list (shape_entry, entry);
135
}
136
 
137
void
138
name_entry_make_indirect PROTO_N ((entry, indirect))
139
			 PROTO_T (NameEntryP entry X
140
				  NameEntryP indirect)
141
{
142
    ASSERT (name_entry_is_place (entry));
143
    entry->type       = NT_INDIRECT;
144
    entry->u.indirect = indirect;
145
}
146
 
147
NameEntryP
148
name_entry_resolve_renames PROTO_N ((entry, shape, report))
149
			   PROTO_T (NameEntryP entry X
150
				    NStringP   shape X
151
				    BoolT      report)
152
{
153
    switch (entry->type) EXHAUSTIVE {
154
      case NT_PLACEHOLDER:
155
      case NT_DIRECT:
156
	return (entry);
157
      case NT_INDIRECT_DONE:
158
	return (name_entry_get_indirect (entry));
159
      case NT_INDIRECT_CYCLING:
160
	if (report) {
161
	    E_rename_cycle (shape, name_entry_key (entry));
162
	}
163
	return (NIL (NameEntryP));
164
      case NT_INDIRECT:
165
	entry->type = NT_INDIRECT_CYCLING;
166
	entry->u.indirect = name_entry_resolve_renames (entry->u.indirect,
167
							shape, report);
168
	entry->type = NT_INDIRECT_DONE;
169
	return (name_entry_get_indirect (entry));
170
    }
171
    UNREACHED;
172
}
173
 
174
NameKeyP
175
name_entry_key PROTO_N ((entry))
176
	       PROTO_T (NameEntryP entry)
177
{
178
    return (&(entry->key));
179
}
180
 
181
NameEntryP
182
name_entry_next PROTO_N ((entry))
183
		PROTO_T (NameEntryP entry)
184
{
185
    return (entry->next);
186
}
187
 
188
NameEntryP *
189
name_entry_next_ref PROTO_N ((entry))
190
		    PROTO_T (NameEntryP entry)
191
{
192
    return (&(entry->next));
193
}
194
 
195
BoolT
196
name_entry_is_direct PROTO_N ((entry))
197
		     PROTO_T (NameEntryP entry)
198
{
199
    return (entry->type == NT_DIRECT);
200
}
201
 
202
BoolT
203
name_entry_is_indirect PROTO_N ((entry))
204
		       PROTO_T (NameEntryP entry)
205
{
206
    return ((entry->type == NT_INDIRECT) ||
207
	    (entry->type == NT_INDIRECT_CYCLING) ||
208
	    (entry->type == NT_INDIRECT_DONE));
209
}
210
 
211
BoolT
212
name_entry_is_place PROTO_N ((entry))
213
		    PROTO_T (NameEntryP entry)
214
{
215
    return (entry->type == NT_PLACEHOLDER);
216
}
217
 
218
unsigned
219
name_entry_id PROTO_N ((entry))
220
	      PROTO_T (NameEntryP entry)
221
{
222
    ASSERT (name_entry_is_direct (entry));
223
    return (entry->u.direct.id);
224
}
225
 
226
void
227
name_entry_merge_use PROTO_N ((entry, use))
228
		     PROTO_T (NameEntryP entry X
229
			      unsigned   use)
230
{
231
    ASSERT (name_entry_is_direct (entry));
232
    entry->u.direct.use |= use;
233
}
234
 
235
unsigned
236
name_entry_get_use PROTO_N ((entry))
237
		   PROTO_T (NameEntryP entry)
238
{
239
    ASSERT (name_entry_is_direct (entry));
240
    return (entry->u.direct.use & (U_DEFD | U_DECD | U_MULT | U_USED));
241
}
242
 
243
void
244
name_entry_hide PROTO_N ((entry))
245
		PROTO_T (NameEntryP entry)
246
{
247
    ASSERT (name_entry_is_direct (entry));
248
    entry->u.direct.use |= U_HIDE;
249
}
250
 
251
void
252
name_entry_unhide PROTO_N ((entry))
253
		  PROTO_T (NameEntryP entry)
254
{
255
    ASSERT (name_entry_is_direct (entry));
256
    entry->u.direct.use &= ~U_HIDE;
257
}
258
 
259
BoolT
260
name_entry_is_hidden PROTO_N ((entry))
261
		     PROTO_T (NameEntryP entry)
262
{
263
    ASSERT (name_entry_is_direct (entry));
264
    return ((entry->u.direct.use & U_HIDE) == U_HIDE);
265
}
266
 
267
void
268
name_entry_set_definition PROTO_N ((entry, capsule))
269
			  PROTO_T (NameEntryP entry X
270
				   CapsuleP   capsule)
271
{
272
    ASSERT (name_entry_is_direct (entry));
273
    entry->u.direct.definition = capsule;
274
}
275
 
276
CapsuleP
277
name_entry_get_definition PROTO_N ((entry))
278
			  PROTO_T (NameEntryP entry)
279
{
280
    ASSERT (name_entry_is_direct (entry));
281
    return (entry->u.direct.definition);
282
}
283
 
284
void
285
name_entry_set_lib_definition PROTO_N ((entry, capsule))
286
			      PROTO_T (NameEntryP  entry X
287
				       LibCapsuleP capsule)
288
{
289
    ASSERT (name_entry_is_direct (entry));
290
    entry->u.direct.lib_definition = capsule;
291
}
292
 
293
LibCapsuleP
294
name_entry_get_lib_definition PROTO_N ((entry))
295
			      PROTO_T (NameEntryP entry)
296
{
297
    ASSERT (name_entry_is_direct (entry));
298
    return (entry->u.direct.lib_definition);
299
}
300
 
301
NameEntryP
302
name_entry_list_next PROTO_N ((entry))
303
		     PROTO_T (NameEntryP entry)
304
{
305
    ASSERT (name_entry_is_direct (entry));
306
    return (entry->u.direct.list_next);
307
}
308
 
309
NameEntryP *
310
name_entry_list_next_ref PROTO_N ((entry))
311
			 PROTO_T (NameEntryP entry)
312
{
313
    ASSERT (name_entry_is_direct (entry));
314
    return (&(entry->u.direct.list_next));
315
}
316
 
317
NameEntryP
318
name_entry_get_indirect PROTO_N ((entry))
319
			PROTO_T (NameEntryP entry)
320
{
321
    ASSERT (name_entry_is_indirect (entry));
322
    return (entry->u.indirect);
323
}
324
 
325
NameEntryP
326
name_entry_deallocate PROTO_N ((entry))
327
		      PROTO_T (NameEntryP entry)
328
{
329
    NameEntryP next = name_entry_next (entry);
330
 
331
    name_key_destroy (name_entry_key (entry));
332
    DEALLOCATE (entry);
333
    return (next);
334
}
335
 
336
/*--------------------------------------------------------------------------*/
337
 
338
void
339
name_entry_do_count PROTO_N ((entry, gclosure))
340
		    PROTO_T (NameEntryP entry X
341
			     GenericP   gclosure)
342
{
343
    unsigned *count_ref = (unsigned *) gclosure;
344
 
345
    if (!(name_entry_is_hidden (entry))) {
346
	(*count_ref) ++;
347
    }
348
}
349
 
350
void
351
name_entry_write_name PROTO_N ((entry, gclosure))
352
		      PROTO_T (NameEntryP entry X
353
			       GenericP   gclosure)
354
{
355
    if (!(name_entry_is_hidden (entry))) {
356
	TDFWriterP writer = (TDFWriterP) gclosure;
357
	NameKeyP   key    = name_entry_key (entry);
358
	unsigned   id     = name_entry_id (entry);
359
 
360
	debug_info_w_name (key, id);
361
	tdf_write_int (writer, id);
362
	tdf_write_name (writer, key);
363
    }
364
}
365
 
366
void
367
name_entry_compute_tld_size PROTO_N ((entry, gclosure))
368
			    PROTO_T (NameEntryP entry X
369
				     GenericP   gclosure)
370
{
371
    unsigned *size_ref = (unsigned *) gclosure;
372
 
373
    if (!name_entry_is_hidden (entry)) {
374
	unsigned use = name_entry_get_use (entry);
375
 
376
	(*size_ref) += tdf_int_size (use);
377
    }
378
}
379
 
380
void
381
name_entry_write_tld PROTO_N ((entry, gclosure))
382
		     PROTO_T (NameEntryP entry X
383
			      GenericP   gclosure)
384
{
385
    TDFWriterP writer = (TDFWriterP) gclosure;
386
 
387
    if (!(name_entry_is_hidden (entry))) {
388
	unsigned use = name_entry_get_use (entry);
389
 
390
	debug_info_w_usage (use, name_entry_key (entry));
391
	tdf_write_int (writer, use);
392
    }
393
}
394
 
395
void
396
name_entry_check_multi_defs PROTO_N ((entry, gclosure))
397
			    PROTO_T (NameEntryP entry X
398
				     GenericP   gclosure)
399
{
400
    NStringP shape_name = (NStringP) gclosure;
401
 
402
    if ((name_entry_get_use (entry) & U_MULT) &&
403
	(name_entry_get_definition (entry) == NIL (CapsuleP))) {
404
	E_no_single_definition (shape_name, name_entry_key (entry));
405
    }
406
}
407
 
408
void
409
name_entry_do_lib_count PROTO_N ((entry, gclosure))
410
			PROTO_T (NameEntryP entry X
411
				 GenericP   gclosure)
412
{
413
    if (name_entry_get_definition (entry)) {
414
	unsigned *num_names_ref = (unsigned *) gclosure;
415
 
416
	(*num_names_ref) ++;
417
    }
418
}
419
 
420
void
421
name_entry_do_lib_write PROTO_N ((entry, gclosure))
422
			PROTO_T (NameEntryP entry X
423
				 GenericP   gclosure)
424
{
425
    CapsuleP definition = name_entry_get_definition (entry);
426
 
427
    if (definition) {
428
	TDFWriterP writer        = (TDFWriterP) gclosure;
429
	NameKeyP   key           = name_entry_key (entry);
430
	unsigned   use           = name_entry_get_use (entry);
431
	unsigned   capsule_index = capsule_get_index (definition);
432
 
433
	debug_info_w_index_entry (key, use, capsule_name (definition),
434
				  capsule_index);
435
	tdf_write_name (writer, key);
436
	tdf_write_int (writer, use);
437
	tdf_write_int (writer, capsule_index);
438
    }
439
}
440
 
441
void
442
name_entry_suppress PROTO_N ((entry, gclosure))
443
		    PROTO_T (NameEntryP entry X
444
			     GenericP   gclosure)
445
{
446
    NStringP shape = (NStringP) gclosure;
447
 
448
    debug_info_l_suppress (shape, name_entry_key (entry));
449
    name_entry_set_lib_definition (entry, NIL (LibCapsuleP));
450
}
451
 
452
void
453
name_entry_builder_suppress PROTO_N ((entry, gclosure))
454
			    PROTO_T (NameEntryP entry X
455
				     GenericP   gclosure)
456
{
457
    NStringP shape = (NStringP) gclosure;
458
 
459
    debug_info_l_suppress (shape, name_entry_key (entry));
460
    name_entry_set_definition (entry, NIL (CapsuleP));
461
}
462
 
463
BoolT
464
name_entry_resolve_undefined PROTO_N ((entry, table, units, shapes, shape_key))
465
			     PROTO_T (NameEntryP  entry X
466
				      NameTableP  table X
467
				      UnitTableP  units X
468
				      ShapeTableP shapes X
469
				      NStringP    shape_key)
470
{
471
    unsigned use = name_entry_get_use (entry);
472
    NameKeyP key = name_entry_key (entry);
473
 
474
    if ((use & U_DEFD) || (!(use & U_USED))) {
475
	debug_info_l_not_needed (key, shape_key, use);
476
	return (FALSE);
477
    } else if (table) {
478
	NameEntryP lib_entry = name_table_get (table, key);
479
 
480
	if (lib_entry) {
481
	    LibCapsuleP lib_def = name_entry_get_lib_definition (lib_entry);
482
	    unsigned    lib_use = name_entry_get_use (lib_entry);
483
 
484
	    if (lib_def && (!lib_capsule_is_loaded (lib_def)) &&
485
		((!(use & U_MULT)) || (lib_use & U_DEFD))) {
486
		CStringP name     = lib_capsule_full_name (lib_def);
487
		NStringP contents = lib_capsule_contents (lib_def);
488
		CapsuleP capsule;
489
 
490
		debug_info_l_found (key, shape_key, use, name);
491
		capsule = capsule_create_string_input (name, contents);
492
		capsule_read (capsule, units, shapes);
493
		capsule_close (capsule);
494
		lib_capsule_loaded (lib_def);
495
		return (TRUE);
496
	    }
497
	}
498
    }
499
    E_no_definition_found (shape_key, key);
500
    debug_info_l_not_found (key, shape_key, use);
501
    return (FALSE);
502
}
503
 
504
void
505
name_entry_hide_defd PROTO_N ((entry, gclosure))
506
		     PROTO_T (NameEntryP entry X
507
			      GenericP   gclosure)
508
{
509
    if (name_entry_get_use (entry) & U_DEFD) {
510
	NStringP shape = (NStringP) gclosure;
511
 
512
	debug_info_l_hide (shape, name_entry_key (entry));
513
	name_entry_hide (entry);
514
    }
515
}
516
 
517
void
518
name_entry_keep PROTO_N ((entry, gclosure))
519
		PROTO_T (NameEntryP entry X
520
			 GenericP   gclosure)
521
{
522
    NStringP shape = (NStringP) gclosure;
523
 
524
    debug_info_l_keep (shape, name_entry_key (entry));
525
    name_entry_unhide (entry);
526
}
527
 
528
void
529
name_entry_suppress_mult PROTO_N ((entry, gclosure))
530
			 PROTO_T (NameEntryP entry X
531
				  GenericP   gclosure)
532
{
533
    if ((name_entry_get_use (entry) & (U_DEFD | U_MULT)) == U_MULT) {
534
	NStringP shape = (NStringP) gclosure;
535
 
536
	debug_info_l_suppress (shape, name_entry_key (entry));
537
	name_entry_set_definition (entry, NIL (CapsuleP));
538
    }
539
}
540
 
541
void
542
name_entry_lib_suppress_mult PROTO_N ((entry, gclosure))
543
			     PROTO_T (NameEntryP entry X
544
				      GenericP   gclosure)
545
{
546
    if ((name_entry_get_use (entry) & (U_DEFD | U_MULT)) == U_MULT) {
547
	NStringP shape = (NStringP) gclosure;
548
 
549
	debug_info_l_suppress (shape, name_entry_key (entry));
550
	name_entry_set_lib_definition (entry, NIL (LibCapsuleP));
551
    }
552
}
553
 
554
void
555
name_entry_show_content PROTO_N ((entry, gclosure))
556
			PROTO_T (NameEntryP entry X
557
				 GenericP   gclosure)
558
{
559
    LibCapsuleP capsule = name_entry_get_lib_definition (entry);
560
 
561
    UNUSED (gclosure);
562
    write_cstring (ostream_output, "  ");
563
    write_name_key (ostream_output, name_entry_key (entry));
564
    write_char (ostream_output, ' ');
565
    write_usage (ostream_output, name_entry_get_use (entry));
566
    write_cstring (ostream_output, " '");
567
    write_cstring (ostream_output, lib_capsule_name (capsule));
568
    write_char (ostream_output, '\'');
569
    write_newline (ostream_output);
570
}
571
 
572
/*
573
 * Local variables(smf):
574
 * eval: (include::add-path-entry "../os-interface" "../library")
575
 * eval: (include::add-path-entry "../generated")
576
 * end:
577
**/