Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – tendra.SVN – Blame – /branches/tendra5-amd64/src/utilities/sid/scope.c – Rev 6

Subversion Repositories tendra.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
/*
6 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
6 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:-
6 7u83 42
 
2 7u83 43
        (1) Its Recipients shall ensure that this Notice is
44
        reproduced upon any copies or amended versions of it;
6 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;
6 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;
6 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
/*** scope.c --- Scope stack ADT.
62
 *
63
 ** Author: Steve Folkes <smf@hermes.mod.uk>
64
 *
65
 *** Commentary:
66
 *
67
 * This file implements the scope stack manipulation routines.
68
 *
69
 *** Change Log:
70
 * $Log: scope.c,v $
71
 * Revision 1.1.1.1  1998/01/17  15:57:47  release
72
 * First version to be checked into rolling release.
73
 *
74
 * Revision 1.2  1994/12/15  09:59:02  smf
75
 * Brought into line with OSSG C Coding Standards Document, as per
76
 * "CR94_178.sid+tld-update".
77
 *
78
 * Revision 1.1.1.1  1994/07/25  16:04:42  smf
79
 * Initial import of SID 1.8 non shared files.
80
 *
81
**/
82
 
83
/****************************************************************************/
84
 
85
#include "scope.h"
86
#include "gen-errors.h"
87
#include "rule.h"
88
 
89
/*--------------------------------------------------------------------------*/
90
 
91
void
6 7u83 92
scope_stack_init(ScopeStackP stack)
2 7u83 93
{
6 7u83 94
    stack->head = NIL(ScopeStackFrameP);
2 7u83 95
}
96
 
97
void
6 7u83 98
scope_stack_push(ScopeStackP stack, NStringP scope)
2 7u83 99
{
6 7u83 100
    ScopeStackFrameP frame = ALLOCATE(ScopeStackFrameT);
2 7u83 101
    DStringT         dstring;
102
 
6 7u83 103
    dstring_init(&dstring);
2 7u83 104
    if (frame->head) {
6 7u83 105
	dstring_append_nstring(&dstring, &(stack->head->scope));
2 7u83 106
    }
6 7u83 107
    dstring_append_nstring(&dstring, scope);
108
    dstring_append_cstring(&dstring, "::");
109
    dstring_to_nstring(&dstring, &(frame->scope));
110
    dstring_destroy(&dstring);
2 7u83 111
    frame->next = stack->head;
6 7u83 112
    frame->head = NIL(ScopeMapEntryP);
2 7u83 113
    frame->tail = &(frame->head);
114
    stack->head = frame;
115
}
6 7u83 116
 
2 7u83 117
void
6 7u83 118
scope_stack_pop(ScopeStackP stack)
2 7u83 119
{
120
    ScopeStackFrameP frame = stack->head;
121
    ScopeMapEntryP   entry;
122
    ScopeMapEntryP   next;
123
 
6 7u83 124
    ASSERT(frame);
2 7u83 125
    stack->head = frame->next;
6 7u83 126
    nstring_destroy(&(frame->scope));
2 7u83 127
    for (entry = frame->head; entry; entry = next) {
128
	next = entry->next;
6 7u83 129
	DEALLOCATE(entry);
2 7u83 130
    }
6 7u83 131
    DEALLOCATE(frame);
2 7u83 132
}
133
 
134
EntryP
6 7u83 135
scope_stack_add_rule(ScopeStackP stack, TableP table, NStringP key, RuleP rule,
136
		     BoolT *found_ref)
2 7u83 137
{
138
    *found_ref = FALSE;
139
    if (stack->head) {
140
	DStringT dstring;
141
	NStringT nstring;
142
	EntryP   entry;
143
 
6 7u83 144
	dstring_init(&dstring);
145
	dstring_append_nstring(&dstring, &(stack->head->scope));
146
	dstring_append_nstring(&dstring, key);
147
	dstring_to_nstring(&dstring, &nstring);
148
	dstring_destroy(&dstring);
149
	if ((entry = table_get_rule(table, &nstring)) != NIL(EntryP)) {
2 7u83 150
	    *found_ref = TRUE;
6 7u83 151
	    nstring_destroy(&nstring);
152
	    return(entry);
153
	} else if ((entry = table_add_rule(table, &nstring)) !=
154
		   NIL(EntryP)) {
155
	    EntryP         from = table_add_name(table, key);
156
	    ScopeMapEntryP map  = ALLOCATE(ScopeMapEntryT);
2 7u83 157
 
6 7u83 158
	   (void)scope_stack_check_shadowing(stack, from, rule);
159
	    map->next            = NIL(ScopeMapEntryP);
2 7u83 160
	    map->from            = from;
161
	    map->to              = entry;
162
	    *(stack->head->tail) = map;
163
	    stack->head->tail    = &(map->next);
6 7u83 164
	    return(entry);
2 7u83 165
	} else {
6 7u83 166
	    nstring_destroy(&nstring);
167
	    return(NIL(EntryP));
2 7u83 168
	}
169
    } else {
6 7u83 170
	if (table_get_rule(table, key)) {
2 7u83 171
	    *found_ref = TRUE;
172
	}
6 7u83 173
	return(table_add_rule(table, key));
2 7u83 174
    }
175
}
176
 
177
EntryP
6 7u83 178
scope_stack_add_action(ScopeStackP stack, TableP table, NStringP key,
179
		       RuleP rule, BoolT *found_ref)
2 7u83 180
{
181
    *found_ref = FALSE;
182
    if (stack->head) {
183
	DStringT dstring;
184
	NStringT nstring;
185
	EntryP   entry;
186
 
6 7u83 187
	dstring_init(&dstring);
188
	dstring_append_nstring(&dstring, &(stack->head->scope));
189
	dstring_append_nstring(&dstring, key);
190
	dstring_to_nstring(&dstring, &nstring);
191
	dstring_destroy(&dstring);
192
	if ((entry = table_get_action(table, &nstring)) != NIL(EntryP)) {
2 7u83 193
	    *found_ref = TRUE;
6 7u83 194
	    nstring_destroy(&nstring);
195
	    return(entry);
196
	} else if ((entry = table_add_action(table, &nstring)) !=
197
		   NIL(EntryP)) {
198
	    EntryP         from = table_add_name(table, key);
199
	    ScopeMapEntryP map  = ALLOCATE(ScopeMapEntryT);
2 7u83 200
 
6 7u83 201
	   (void)scope_stack_check_shadowing(stack, from, rule);
202
	    map->next            = NIL(ScopeMapEntryP);
2 7u83 203
	    map->from            = from;
204
	    map->to              = entry;
205
	    *(stack->head->tail) = map;
206
	    stack->head->tail    = &(map->next);
6 7u83 207
	    return(entry);
2 7u83 208
	} else {
6 7u83 209
	    nstring_destroy(&nstring);
210
	    return(NIL(EntryP));
2 7u83 211
	}
212
    } else {
6 7u83 213
	if (table_get_action(table, key)) {
2 7u83 214
	    *found_ref = TRUE;
215
	}
6 7u83 216
	return(table_add_action(table, key));
2 7u83 217
    }
218
}
219
 
220
EntryP
6 7u83 221
scope_stack_add_non_local(ScopeStackP stack, TableP table, NStringP key,
222
			  EntryP type, RuleP rule)
2 7u83 223
{
224
    DStringT dstring;
225
    NStringT nstring;
226
    EntryP   entry;
227
 
6 7u83 228
    ASSERT(stack->head);
229
    dstring_init(&dstring);
230
    dstring_append_nstring(&dstring, &(stack->head->scope));
231
    dstring_append_nstring(&dstring, key);
232
    dstring_to_nstring(&dstring, &nstring);
233
    dstring_destroy(&dstring);
234
    if ((entry = table_add_non_local(table, &nstring, type)) !=
235
	NIL(EntryP)) {
236
	EntryP         from = table_add_name(table, key);
237
	ScopeMapEntryP map  = ALLOCATE(ScopeMapEntryT);
2 7u83 238
 
6 7u83 239
	(void)scope_stack_check_shadowing(stack, from, rule);
240
	map->next            = NIL(ScopeMapEntryP);
2 7u83 241
	map->from            = from;
242
	map->to              = entry;
243
	*(stack->head->tail) = map;
244
	stack->head->tail    = &(map->next);
6 7u83 245
	return(entry);
2 7u83 246
    } else {
6 7u83 247
	nstring_destroy(&nstring);
248
	return(NIL(EntryP));
2 7u83 249
    }
250
}
251
 
252
EntryP
6 7u83 253
scope_stack_get_rule(ScopeStackP stack, TableP table, NStringP key)
2 7u83 254
{
6 7u83 255
    EntryP entry = table_get_entry(table, key);
2 7u83 256
 
257
    if (entry) {
258
	ScopeStackFrameP frame = stack->head;
259
 
260
	for (; frame; frame = frame->next) {
261
	    ScopeMapEntryP map = frame->head;
262
 
263
	    for (; map; map = map->next) {
264
		if (map->from == entry) {
6 7u83 265
		    if (entry_is_rule(map->to)) {
266
			return(map->to);
2 7u83 267
		    } else {
6 7u83 268
			return(NIL(EntryP));
2 7u83 269
		    }
270
		}
271
	    }
272
	}
6 7u83 273
	if (entry_is_rule(entry)) {
274
	    return(entry);
2 7u83 275
	}
276
    }
6 7u83 277
    return(NIL(EntryP));
2 7u83 278
}
279
 
280
EntryP
6 7u83 281
scope_stack_get_action(ScopeStackP stack, TableP table, NStringP key)
2 7u83 282
{
6 7u83 283
    EntryP entry = table_get_entry(table, key);
2 7u83 284
 
285
    if (entry) {
286
	ScopeStackFrameP frame = stack->head;
287
 
288
	for (; frame; frame = frame->next) {
289
	    ScopeMapEntryP map = frame->head;
290
 
291
	    for (; map; map = map->next) {
292
		if (map->from == entry) {
6 7u83 293
		    if (entry_is_action(map->to)) {
294
			return(map->to);
2 7u83 295
		    } else {
6 7u83 296
			return(NIL(EntryP));
2 7u83 297
		    }
298
		}
299
	    }
300
	}
6 7u83 301
	if (entry_is_action(entry)) {
302
	    return(entry);
2 7u83 303
	}
304
    }
6 7u83 305
    return(NIL(EntryP));
2 7u83 306
}
307
 
308
EntryP
6 7u83 309
scope_stack_get_non_local(ScopeStackP stack, TableP table, NStringP key,
310
			  NStringP scope)
2 7u83 311
{
6 7u83 312
    EntryP entry = table_get_entry(table, key);
2 7u83 313
 
314
    if (entry) {
315
	ScopeStackFrameP frame = stack->head;
316
 
317
	for (; frame; frame = frame->next) {
318
	    ScopeMapEntryP map = frame->head;
319
 
320
	    for (; map; map = map->next) {
321
		if (map->from == entry) {
6 7u83 322
		    if (entry_is_non_local(map->to)) {
323
			nstring_copy(scope, &(frame->scope));
324
			return(map->to);
2 7u83 325
		    } else {
6 7u83 326
			return(NIL(EntryP));
2 7u83 327
		    }
328
		}
329
	    }
330
	}
331
    }
6 7u83 332
    return(NIL(EntryP));
2 7u83 333
}
334
 
335
BoolT
6 7u83 336
scope_stack_check_shadowing(ScopeStackP stack, EntryP from, RuleP rule)
2 7u83 337
{
338
    ScopeStackFrameP frame = stack->head;
339
 
340
    for (; frame; frame = frame->next) {
341
	ScopeMapEntryP entry;
342
 
343
	for (entry = frame->head; entry; entry = entry->next) {
344
	    if (entry->from == from) {
6 7u83 345
		E_shadows_non_local(entry_key(from), entry_key(entry->to),
2 7u83 346
				     rule);
6 7u83 347
		return(TRUE);
2 7u83 348
	    }
349
	}
350
    }
6 7u83 351
    if (entry_is_rule(from) || entry_is_action(from) ||
352
	entry_is_basic(from)) {
353
	E_shadows_global(entry_key(from), rule);
354
	return(TRUE);
2 7u83 355
    }
6 7u83 356
    return(FALSE);
2 7u83 357
}
358
 
359
/*
360
 * Local variables(smf):
361
 * eval: (include::add-path-entry "../os-interface" "../library")
362
 * eval: (include::add-path-entry "../generated")
363
 * end:
364
**/