Subversion Repositories tendra.SVN

Rev

Rev 5 | Details | Compare with Previous | 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
33
 
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:-
42
 
43
        (1) Its Recipients shall ensure that this Notice is
44
        reproduced upon any copies or amended versions of it;
45
 
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;
49
 
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;
53
 
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
/**********************************************************************
62
$Author: release $
63
$Date: 1998/01/17 15:55:46 $
64
$Revision: 1.1.1.1 $
65
$Log: mark_scope.c,v $
66
 * Revision 1.1.1.1  1998/01/17  15:55:46  release
67
 * First version to be checked into rolling release.
68
 *
69
 * Revision 1.8  1998/01/09  09:30:07  pwe
70
 * prep restructure
71
 *
72
 * Revision 1.7  1997/10/28  10:12:38  pwe
73
 * local location support
74
 *
75
 * Revision 1.6  1997/10/23  09:21:26  pwe
76
 * ANDF-DE V1.7 and extra diags
77
 *
78
 * Revision 1.5  1997/08/23  13:27:24  pwe
79
 * initial ANDF-DE
80
 *
81
 * Revision 1.4  1997/04/02  12:55:05  currie
82
 * includes before ifdef
83
 *
84
Revision 1.3  1997/03/20 17:04:53  currie
85
Dwarf2 diags
86
 
87
Revision 1.2  1997/02/18 12:55:52  currie
88
NEW DIAG STRUCTURE
89
 
90
 * Revision 1.1  1995/04/06  10:42:55  currie
91
 * Initial revision
92
 *
93
***********************************************************************/
94
 
95
 
96
#include "config.h"
97
#include "common_types.h"
98
#include "expmacs.h"
99
#include "tags.h"
100
#include "xalloc.h"
101
#include "externs.h"
102
#include "dg_aux.h"
103
#include "mark_scope.h"
104
 
105
 
106
#ifdef NEWDIAGS
107
 
108
int doing_mark_scope = 0;
109
 
6 7u83 110
void
111
mark_scope(exp e)
2 7u83 112
{
113
	/* called by read_diag_id_scope; dgf(e) holds DIAG_INFO_ID */
6 7u83 114
	dg_info d = dgf(e);
115
	dg_info *ptr;
116
	exp id;
117
	if (!d || d->key != DGA_NAME ||
118
	    d->data.i_nam.dnam->key != DGN_OBJECT) {
119
		return;
120
	}
121
	id = son(d->data.i_nam.dnam->data.n_obj.obtain_val);
122
	if (name(id) == cont_tag) {
123
		id = son(id);
124
	}
125
	if (name(id) != name_tag) {
126
		return;
127
	}
128
	id = son(id);
129
	if (isparam(id)) {
130
		return;
131
	}
132
	ptr = &(d->more);
133
	d = nildiag;
134
	while (*ptr && (*ptr)->key != DGA_SCOPE) {
135
		ptr = &((*ptr)->more);
136
	}
137
	if (!*ptr && name(e) == seq_tag && name(son(son(e))) == ass_tag &&
138
	    last(son(son(e))) && name(bro(son(e))) != ident_tag) {
139
		ptr = &dgf(bro(son(e)));
140
		while (*ptr && (*ptr)->key != DGA_SCOPE) {
141
			ptr = &((*ptr)->more);
142
		}
143
	}
144
	if (*ptr) {
145
		d = *ptr;
146
		*ptr = d->more;
147
	} else {
148
		d = f_lexical_block_dg(no_dg_idname_option,
149
				       no_dg_sourcepos_option);
150
		d->data.i_scope.begin_st = (long)(-1);
151
		doing_mark_scope = 1;
152
	}
153
	/* if (isglob(id)) */ {
154
		d->more = dgf(e);
155
		dgf(e) = d;
156
	}
2 7u83 157
#if 0
6 7u83 158
	else {
159
		exp def = son(id);
160
		if (dgf(def) && dgf(def)->key == DGA_SRC)
161
			dgf(e)->data.i_nam.dnam->whence =
162
			    dgf(def)->data.i_src.startpos;
163
		d->more = dgf(id);
164
		dgf(id) = d;
165
	}
2 7u83 166
#endif
6 7u83 167
	return;
2 7u83 168
}
169
 
6 7u83 170
 
171
void
172
mark_scope2(exp e)
2 7u83 173
{
174
	/* called by read_diag_type_scope; dgf(e) holds DIAG_INFO_ID */
6 7u83 175
	dg_info d = dgf(e);
176
	dg_info *ptr;
177
	if (!d || d->key != DGA_NAME || d->data.i_nam.dnam->key != DGN_TYPE) {
178
		return;
179
	}
180
	ptr = &(d->more);
181
	d = nildiag;
182
	while (*ptr && (*ptr)->key != DGA_SCOPE) {
183
		ptr = &((*ptr)->more);
184
	}
185
	if (*ptr) {
186
		d = *ptr;
187
		*ptr = d->more;
188
	} else {
189
		d = f_lexical_block_dg(no_dg_idname_option,
190
				       no_dg_sourcepos_option);
191
		d->data.i_scope.begin_st = (long)(-1);
192
		doing_mark_scope = 1;
193
	}
194
	d->more = dgf(e);
195
	dgf(e) = d;
196
	return;
2 7u83 197
}
198
 
6 7u83 199
 
200
void
201
correct_mark_scope(exp e)
2 7u83 202
{
6 7u83 203
	dg_info d = nildiag;
204
	dg_info *ptr = &(dgf(bro(son(e))));
205
	while (*ptr && (*ptr)->key != DGA_SCOPE) {
206
		ptr = &((*ptr)->more);
207
	}
208
	if (*ptr) {
209
		d = *ptr;
210
		*ptr = d->more;
211
	}
212
	if (d) {
213
		d->more = dgf(e);
214
		dgf(e) = d;
215
	}
216
	return;
2 7u83 217
}
218
 
219
 
220
#else
221
 
222
 
223
/* PROCEDURES */
224
 
6 7u83 225
static exp
226
previous_scope(exp e)
2 7u83 227
{
6 7u83 228
	if (!last(e) || bro(e) == nilexp) {
229
		return nilexp;
230
	}
2 7u83 231
 
6 7u83 232
	if (name(bro(e)) == diagnose_tag && (props(bro(e)) & 0x7) == 1) {
233
		return previous_scope(bro(e));
234
	}
2 7u83 235
 
6 7u83 236
	if (name(bro(e)) == diagnose_tag) {
237
		return bro(e);
238
	}
2 7u83 239
 
6 7u83 240
	if (name(bro(e)) == ident_tag && last(bro(e))) {
241
		if (bro(bro(e)) == nilexp) {
242
			return nilexp;
243
		}
2 7u83 244
 
6 7u83 245
		if (name(bro(bro(e))) == diagnose_tag &&
246
		    (props(bro(bro(e))) & 0x7) == 1) {
247
			return previous_scope(bro(bro(e)));
248
		}
2 7u83 249
 
6 7u83 250
		if (name(bro(bro(e))) == diagnose_tag) {
251
			return bro(bro(e));
252
		}
2 7u83 253
 
6 7u83 254
		return nilexp;
255
	}
2 7u83 256
 
6 7u83 257
	return nilexp;
2 7u83 258
}
259
 
260
 
6 7u83 261
static int
262
param_scope(exp e)
2 7u83 263
{
6 7u83 264
	diag_info *d = dno(e);
265
	if (d->key == DIAG_INFO_ID) {
266
		return isparam(son(d->data.id_scope.access));
267
	}
268
	return 0;
2 7u83 269
}
270
 
6 7u83 271
 
272
static int
273
needs_hiding(exp a, exp b)
2 7u83 274
{
6 7u83 275
	diag_info *da = dno(a);
276
	diag_info *db = dno(b);
2 7u83 277
 
6 7u83 278
	if (da->key != db->key) {
279
		return 0;
280
	}
2 7u83 281
 
6 7u83 282
	switch (da->key) {
283
	case DIAG_INFO_ID:
284
		return !strcmp(da->data.id_scope.nme.ints.chars,
285
			       db->data.id_scope.nme.ints.chars);
286
	case DIAG_INFO_TYPE:
287
		return !strcmp(da->data.type_scope.nme.ints.chars,
288
			       db->data.type_scope.nme.ints.chars);
289
	case DIAG_INFO_TAG:
290
		return !strcmp(da->data.tag_scope.nme.ints.chars,
291
			       db->data.tag_scope.nme.ints.chars);
292
	default:
293
		return 0;
294
	}
2 7u83 295
}
296
 
6 7u83 297
 
298
void
299
mark_scope(exp e)
2 7u83 300
{
6 7u83 301
	exp scope = e;
2 7u83 302
 
6 7u83 303
	if (param_scope(e)) {
304
		return;
305
	}
2 7u83 306
 
6 7u83 307
	while (1) {
308
		scope = previous_scope(scope);
2 7u83 309
 
6 7u83 310
		if (scope == nilexp || param_scope(scope) ||
311
		    needs_hiding(e, scope)) {
312
			props(e) = (prop)(props(e) | 0x80);
313
			return;
314
		}
2 7u83 315
 
6 7u83 316
		if (props(scope) & 0x80) {
317
			return;
318
		}
2 7u83 319
 
6 7u83 320
	}
2 7u83 321
}
322
 
323
#endif