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

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

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/construct/check.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
*/
Line 53... Line 83...
53
#include "literal.h"
83
#include "literal.h"
54
#include "merge.h"
84
#include "merge.h"
55
#include "namespace.h"
85
#include "namespace.h"
56
#include "syntax.h"
86
#include "syntax.h"
57
#include "tokdef.h"
87
#include "tokdef.h"
58
 
88
 
59
 
89
 
60
/*
90
/*
61
    ARE TWO OFFSETS EQUAL?
91
    ARE TWO OFFSETS EQUAL?
62
 
92
 
63
    This routine checks whether the offsets a and b are equal.  The co
93
    This routine checks whether the offsets a and b are equal.  The co
64
    argument is passed through to eq_exp.
94
    argument is passed through to eq_exp.
65
*/
95
*/
66
 
96
 
67
int eq_offset
97
int
68
    PROTO_N ( ( a, b, co ) )
-
 
69
    PROTO_T ( OFFSET a X OFFSET b X int co )
98
eq_offset(OFFSET a, OFFSET b, int co)
70
{
99
{
71
    unsigned taga, tagb ;
100
	unsigned taga, tagb;
72
 
101
 
73
    /* Check for obvious equality */
102
	/* Check for obvious equality */
74
    if ( EQ_off ( a, b ) ) return ( 1 ) ;
103
	if (EQ_off(a, b)) {
-
 
104
		return (1);
-
 
105
	}
75
    if ( IS_NULL_off ( a ) ) return ( 0 ) ;
106
	if (IS_NULL_off(a)) {
-
 
107
		return (0);
-
 
108
	}
76
    if ( IS_NULL_off ( b ) ) return ( 0 ) ;
109
	if (IS_NULL_off(b)) {
-
 
110
		return (0);
-
 
111
	}
77
 
112
 
78
    /* Check tags */
113
	/* Check tags */
79
    taga = TAG_off ( a ) ;
114
	taga = TAG_off(a);
80
    tagb = TAG_off ( b ) ;
115
	tagb = TAG_off(b);
81
    if ( taga != tagb ) return ( 0 ) ;
116
	if (taga != tagb) {
-
 
117
		return (0);
-
 
118
	}
82
 
119
 
83
    /* Check individual cases */
120
	/* Check individual cases */
84
    ASSERT ( ORDER_off == 13 ) ;
121
	ASSERT(ORDER_off == 13);
85
    switch ( TAG_off ( a ) ) {
122
	switch (TAG_off(a)) {
86
	case off_zero_tag : {
123
	case off_zero_tag: {
87
	    /* Zero offsets */
124
		/* Zero offsets */
88
	    TYPE ta = DEREF_type ( off_zero_type ( a ) ) ;
125
		TYPE ta = DEREF_type(off_zero_type(a));
89
	    TYPE tb = DEREF_type ( off_zero_type ( b ) ) ;
126
		TYPE tb = DEREF_type(off_zero_type(b));
90
	    return ( eq_type_offset ( ta, tb ) ) ;
127
		return (eq_type_offset(ta, tb));
91
	}
128
	}
92
	case off_type_tag : {
129
	case off_type_tag: {
93
	    /* Type offsets */
130
		/* Type offsets */
94
	    TYPE ta = DEREF_type ( off_type_type ( a ) ) ;
131
		TYPE ta = DEREF_type(off_type_type(a));
95
	    TYPE tb = DEREF_type ( off_type_type ( b ) ) ;
132
		TYPE tb = DEREF_type(off_type_type(b));
96
	    return ( eq_type_offset ( ta, tb ) ) ;
133
		return (eq_type_offset(ta, tb));
97
	}
134
	}
98
	case off_extra_tag : {
135
	case off_extra_tag: {
99
	    /* Extra allocator offsets */
136
		/* Extra allocator offsets */
100
	    TYPE ta = DEREF_type ( off_extra_type ( a ) ) ;
137
		TYPE ta = DEREF_type(off_extra_type(a));
101
	    TYPE tb = DEREF_type ( off_extra_type ( b ) ) ;
138
		TYPE tb = DEREF_type(off_extra_type(b));
102
	    int na = DEREF_int ( off_extra_scale ( a ) ) ;
139
		int na = DEREF_int(off_extra_scale(a));
103
	    int nb = DEREF_int ( off_extra_scale ( b ) ) ;
140
		int nb = DEREF_int(off_extra_scale(b));
104
	    return ( na == nb && eq_type_offset ( ta, tb ) ) ;
141
		return (na == nb && eq_type_offset(ta, tb));
105
	}
142
	}
106
	case off_array_tag : {
143
	case off_array_tag: {
107
	    /* Array offsets */
144
		/* Array offsets */
108
	    TYPE ta = DEREF_type ( off_array_type ( a ) ) ;
145
		TYPE ta = DEREF_type(off_array_type(a));
109
	    TYPE tb = DEREF_type ( off_array_type ( b ) ) ;
146
		TYPE tb = DEREF_type(off_array_type(b));
110
	    unsigned na = DEREF_unsigned ( off_array_arg ( a ) ) ;
147
		unsigned na = DEREF_unsigned(off_array_arg(a));
111
	    unsigned nb = DEREF_unsigned ( off_array_arg ( b ) ) ;
148
		unsigned nb = DEREF_unsigned(off_array_arg(b));
112
	    return ( na == nb && eq_type_offset ( ta, tb ) ) ;
149
		return (na == nb && eq_type_offset(ta, tb));
113
	}
150
	}
114
	case off_base_tag : {
151
	case off_base_tag: {
115
	    /* Base class offsets */
152
		/* Base class offsets */
116
	    GRAPH ga = DEREF_graph ( off_base_graph ( a ) ) ;
153
		GRAPH ga = DEREF_graph(off_base_graph(a));
117
	    GRAPH gb = DEREF_graph ( off_base_graph ( b ) ) ;
154
		GRAPH gb = DEREF_graph(off_base_graph(b));
118
	    return ( eq_graph ( ga, gb ) ) ;
155
		return (eq_graph(ga, gb));
119
	}
156
	}
120
	case off_deriv_tag : {
157
	case off_deriv_tag: {
121
	    /* Derived class offsets */
158
		/* Derived class offsets */
122
	    GRAPH ga = DEREF_graph ( off_deriv_graph ( a ) ) ;
159
		GRAPH ga = DEREF_graph(off_deriv_graph(a));
123
	    GRAPH gb = DEREF_graph ( off_deriv_graph ( b ) ) ;
160
		GRAPH gb = DEREF_graph(off_deriv_graph(b));
124
	    return ( eq_graph ( ga, gb ) ) ;
161
		return (eq_graph(ga, gb));
-
 
162
	}
-
 
163
	case off_member_tag: {
-
 
164
		/* Member offsets */
-
 
165
		IDENTIFIER ia = DEREF_id(off_member_id(a));
-
 
166
		IDENTIFIER ib = DEREF_id(off_member_id(b));
-
 
167
		return (EQ_id(ia, ib));
-
 
168
	}
-
 
169
	case off_ptr_mem_tag: {
-
 
170
		/* Pointer member offsets */
-
 
171
		EXP xa = DEREF_exp(off_ptr_mem_arg(a));
-
 
172
		EXP xb = DEREF_exp(off_ptr_mem_arg(b));
-
 
173
		return (eq_exp(xa, xb, co));
125
	}
174
	}
126
	case off_member_tag : {
175
	case off_negate_tag: {
127
	    /* Member offsets */
176
		/* Offset negation */
128
	    IDENTIFIER ia = DEREF_id ( off_member_id ( a ) ) ;
177
		OFFSET sa = DEREF_off(off_negate_arg(a));
129
	    IDENTIFIER ib = DEREF_id ( off_member_id ( b ) ) ;
178
		OFFSET sb = DEREF_off(off_negate_arg(b));
130
	    return ( EQ_id ( ia, ib ) ) ;
179
		return (eq_offset(sa, sb, co));
-
 
180
	}
-
 
181
	case off_plus_tag: {
-
 
182
		/* Offset addition */
-
 
183
		OFFSET sa = DEREF_off(off_plus_arg1(a));
-
 
184
		OFFSET sb = DEREF_off(off_plus_arg1(b));
-
 
185
		OFFSET ta = DEREF_off(off_plus_arg2(a));
-
 
186
		OFFSET tb = DEREF_off(off_plus_arg2(b));
-
 
187
		if (eq_offset(sa, sb, co) && eq_offset(ta, tb, co)) {
-
 
188
			return (1);
-
 
189
		}
-
 
190
		if (co && eq_offset(sa, tb, 1) && eq_offset(ta, sb, 1)) {
-
 
191
			return (1);
-
 
192
		}
-
 
193
		return (0);
131
	}
194
	}
132
	case off_ptr_mem_tag : {
195
	case off_mult_tag: {
133
	    /* Pointer member offsets */
196
		/* Offset multiplication */
-
 
197
		OFFSET sa = DEREF_off(off_mult_arg1(a));
-
 
198
		OFFSET sb = DEREF_off(off_mult_arg1(b));
134
	    EXP xa = DEREF_exp ( off_ptr_mem_arg ( a ) ) ;
199
		EXP za = DEREF_exp(off_mult_arg2(a));
135
	    EXP xb = DEREF_exp ( off_ptr_mem_arg ( b ) ) ;
200
		EXP zb = DEREF_exp(off_mult_arg2(b));
136
	    return ( eq_exp ( xa, xb, co ) ) ;
201
		return (eq_offset(sa, sb, co) && eq_exp(za, zb, co));
137
	}
202
	}
138
	case off_negate_tag : {
203
	case off_ptr_diff_tag: {
139
	    /* Offset negation */
204
		/* Pointer difference */
-
 
205
		EXP xa = DEREF_exp(off_ptr_diff_ptr1(a));
-
 
206
		EXP xb = DEREF_exp(off_ptr_diff_ptr1(b));
140
	    OFFSET sa = DEREF_off ( off_negate_arg ( a ) ) ;
207
		EXP za = DEREF_exp(off_ptr_diff_ptr2(a));
141
	    OFFSET sb = DEREF_off ( off_negate_arg ( b ) ) ;
208
		EXP zb = DEREF_exp(off_ptr_diff_ptr2(b));
142
	    return ( eq_offset ( sa, sb, co ) ) ;
209
		return (eq_exp(xa, xb, co) && eq_exp(za, zb, co));
143
	}
210
	}
144
	case off_plus_tag : {
211
	case off_token_tag: {
145
	    /* Offset addition */
212
		/* Token application */
146
	    OFFSET sa = DEREF_off ( off_plus_arg1 ( a ) ) ;
213
		IDENTIFIER ia = DEREF_id(off_token_tok(a));
147
	    OFFSET sb = DEREF_off ( off_plus_arg1 ( b ) ) ;
214
		IDENTIFIER ib = DEREF_id(off_token_tok(b));
148
	    OFFSET ta = DEREF_off ( off_plus_arg2 ( a ) ) ;
215
		LIST(TOKEN)pa = DEREF_list(off_token_args(a));
149
	    OFFSET tb = DEREF_off ( off_plus_arg2 ( b ) ) ;
216
		LIST(TOKEN)pb = DEREF_list(off_token_args(b));
150
	    if ( eq_offset ( sa, sb, co ) && eq_offset ( ta, tb, co ) ) {
217
		return (eq_token_args(ia, ib, pa, pb));
151
		return ( 1 ) ;
-
 
152
	    }
-
 
153
	    if ( co && eq_offset ( sa, tb, 1 ) && eq_offset ( ta, sb, 1 ) ) {
-
 
154
		return ( 1 ) ;
-
 
155
	    }
-
 
156
	    return ( 0 ) ;
-
 
157
	}
218
	}
158
	case off_mult_tag : {
-
 
159
	    /* Offset multiplication */
-
 
160
	    OFFSET sa = DEREF_off ( off_mult_arg1 ( a ) ) ;
-
 
161
	    OFFSET sb = DEREF_off ( off_mult_arg1 ( b ) ) ;
-
 
162
	    EXP za = DEREF_exp ( off_mult_arg2 ( a ) ) ;
-
 
163
	    EXP zb = DEREF_exp ( off_mult_arg2 ( b ) ) ;
-
 
164
	    return ( eq_offset ( sa, sb, co ) && eq_exp ( za, zb, co ) ) ;
-
 
165
	}
219
	}
166
	case off_ptr_diff_tag : {
-
 
167
	    /* Pointer difference */
-
 
168
	    EXP xa = DEREF_exp ( off_ptr_diff_ptr1 ( a ) ) ;
-
 
169
	    EXP xb = DEREF_exp ( off_ptr_diff_ptr1 ( b ) ) ;
-
 
170
	    EXP za = DEREF_exp ( off_ptr_diff_ptr2 ( a ) ) ;
-
 
171
	    EXP zb = DEREF_exp ( off_ptr_diff_ptr2 ( b ) ) ;
-
 
172
	    return ( eq_exp ( xa, xb, co ) && eq_exp ( za, zb, co ) ) ;
-
 
173
	}
-
 
174
	case off_token_tag : {
-
 
175
	    /* Token application */
-
 
176
	    IDENTIFIER ia = DEREF_id ( off_token_tok ( a ) ) ;
-
 
177
	    IDENTIFIER ib = DEREF_id ( off_token_tok ( b ) ) ;
-
 
178
	    LIST ( TOKEN ) pa = DEREF_list ( off_token_args ( a ) ) ;
-
 
179
	    LIST ( TOKEN ) pb = DEREF_list ( off_token_args ( b ) ) ;
-
 
180
	    return ( eq_token_args ( ia, ib, pa, pb ) ) ;
-
 
181
	}
-
 
182
    }
-
 
183
    return ( 0 ) ;
220
	return (0);
184
}
221
}
185
 
222
 
186
 
223
 
187
/*
224
/*
188
    ARE TWO LISTS OF EXPRESSIONS EQUAL?
225
    ARE TWO LISTS OF EXPRESSIONS EQUAL?
189
 
226
 
190
    This routine checks whether the expression lists p and q are equal,
227
    This routine checks whether the expression lists p and q are equal,
191
    in the sense that each of their components is equal.  The co argument
228
    in the sense that each of their components is equal.  The co argument
192
    is passed through to eq_exp.
229
    is passed through to eq_exp.
193
*/
230
*/
194
 
231
 
195
static int eq_exp_list
232
static int
196
    PROTO_N ( ( p, q, co ) )
-
 
197
    PROTO_T ( LIST ( EXP ) p X LIST ( EXP ) q X int co )
233
eq_exp_list(LIST(EXP)p, LIST(EXP)q, int co)
198
{
234
{
199
    unsigned np = LENGTH_list ( p ) ;
235
	unsigned np = LENGTH_list(p);
200
    unsigned nq = LENGTH_list ( q ) ;
236
	unsigned nq = LENGTH_list(q);
201
    if ( np != nq ) return ( 0 ) ;
237
	if (np != nq) {
-
 
238
		return (0);
-
 
239
	}
202
    while ( !IS_NULL_list ( p ) ) {
240
	while (!IS_NULL_list(p)) {
203
	EXP a = DEREF_exp ( HEAD_list ( p ) ) ;
241
		EXP a = DEREF_exp(HEAD_list(p));
204
	EXP b = DEREF_exp ( HEAD_list ( q ) ) ;
242
		EXP b = DEREF_exp(HEAD_list(q));
205
	if ( !eq_exp ( a, b, co ) ) return ( 0 ) ;
243
		if (!eq_exp(a, b, co)) {
-
 
244
			return (0);
-
 
245
		}
206
	p = TAIL_list ( p ) ;
246
		p = TAIL_list(p);
207
	q = TAIL_list ( q ) ;
247
		q = TAIL_list(q);
208
    }
248
	}
209
    return ( 1 ) ;
249
	return (1);
210
}
250
}
211
 
251
 
212
 
252
 
213
/*
253
/*
214
    CHECK EXPRESSION EQUALITY
254
    CHECK EXPRESSION EQUALITY
215
 
255
 
216
    This is an auxiliary routine for eq_exp which checks whether the
256
    This is an auxiliary routine for eq_exp which checks whether the
217
    expressions a and b, which have the same tag value, are equal.
257
    expressions a and b, which have the same tag value, are equal.
398
	}
688
	}
399
	case exp_minus_tag :
-
 
400
	case exp_div_tag :
689
	case exp_op_tag: {
401
	case exp_rem_tag :
690
		/* Undetermined expressions */
402
	case exp_lshift_tag :
691
		int ca = DEREF_int(exp_op_lex(a));
403
	case exp_rshift_tag : {
-
 
404
	    /* Non-commutative binary expressions */
692
		int cb = DEREF_int(exp_op_lex(b));
405
	    EXP ra = DEREF_exp ( exp_plus_etc_arg1 ( a ) ) ;
693
		EXP ra = DEREF_exp(exp_op_arg1(a));
406
	    EXP rb = DEREF_exp ( exp_plus_etc_arg1 ( b ) ) ;
694
		EXP rb = DEREF_exp(exp_op_arg1(b));
407
	    EXP sa = DEREF_exp ( exp_plus_etc_arg2 ( a ) ) ;
695
		EXP sa = DEREF_exp(exp_op_arg2(a));
408
	    EXP sb = DEREF_exp ( exp_plus_etc_arg2 ( b ) ) ;
696
		EXP sb = DEREF_exp(exp_op_arg2(b));
-
 
697
		if (ca != cb) {
-
 
698
			return (0);
-
 
699
		}
409
	    return ( eq_exp ( ra, rb, co ) && eq_exp ( sa, sb, co ) ) ;
700
		return (eq_exp(ra, rb, co) && eq_exp(sa, sb, co));
410
	}
701
	}
411
	case exp_test_tag : {
702
	case exp_opn_tag: {
412
	    /* Test expressions */
703
		/* Undetermined expressions */
413
	    NTEST ca = DEREF_ntest ( exp_test_tst ( a ) ) ;
704
		int ca = DEREF_int(exp_opn_lex(a));
414
	    NTEST cb = DEREF_ntest ( exp_test_tst ( b ) ) ;
705
		int cb = DEREF_int(exp_opn_lex(b));
415
	    EXP sa = DEREF_exp ( exp_test_arg ( a ) ) ;
706
		LIST(EXP)pa = DEREF_list(exp_opn_args(a));
416
	    EXP sb = DEREF_exp ( exp_test_arg ( b ) ) ;
707
		LIST(EXP)pb = DEREF_list(exp_opn_args(b));
417
	    if ( ca != cb ) return ( 0 ) ;
708
		if (ca != cb) {
-
 
709
			return (0);
-
 
710
		}
418
	    return ( eq_exp ( sa, sb, co ) ) ;
711
		return (eq_exp_list(pa, pb, co));
419
	}
712
	}
420
	case exp_compare_tag : {
713
	case exp_assembler_tag: {
421
	    /* Comparison expressions */
714
		/* Assembler expressions */
422
	    NTEST ca = DEREF_ntest ( exp_compare_tst ( a ) ) ;
715
		STRING ca = DEREF_str(exp_assembler_op(a));
423
	    NTEST cb = DEREF_ntest ( exp_compare_tst ( b ) ) ;
716
		STRING cb = DEREF_str(exp_assembler_op(b));
424
	    EXP ra = DEREF_exp ( exp_compare_arg1 ( a ) ) ;
-
 
425
	    EXP rb = DEREF_exp ( exp_compare_arg1 ( b ) ) ;
717
		if (EQ_str(ca, cb) || eq_string_lit(ca, cb)) {
426
	    EXP sa = DEREF_exp ( exp_compare_arg2 ( a ) ) ;
718
			LIST(EXP)pa = DEREF_list(exp_assembler_args(a));
427
	    EXP sb = DEREF_exp ( exp_compare_arg2 ( b ) ) ;
719
			LIST(EXP)pb = DEREF_list(exp_assembler_args(b));
428
	    if ( ca != cb ) return ( 0 ) ;
-
 
429
	    if ( eq_exp ( ra, rb, co ) && eq_exp ( sa, sb, co ) ) {
-
 
430
		return ( 1 ) ;
720
			return (eq_exp_list(pa, pb, co));
431
	    }
-
 
432
	    if ( co && ( ca == ntest_eq || ca == ntest_not_eq ) ) {
-
 
433
		/* Commutative comparisons */
-
 
434
		if ( eq_exp ( ra, sb, 1 ) && eq_exp ( sa, rb, 1 ) ) {
-
 
435
		    return ( 1 ) ;
-
 
436
		}
721
		}
437
	    }
-
 
438
	    return ( 0 ) ;
-
 
439
	}
-
 
440
	case exp_cast_tag : {
-
 
441
	    /* Cast expressions */
-
 
442
	    EXP sa = DEREF_exp ( exp_cast_arg ( a ) ) ;
-
 
443
	    EXP sb = DEREF_exp ( exp_cast_arg ( b ) ) ;
-
 
444
	    unsigned va = DEREF_unsigned ( exp_cast_conv ( a ) ) ;
-
 
445
	    unsigned vb = DEREF_unsigned ( exp_cast_conv ( b ) ) ;
-
 
446
	    return ( va == vb && eq_exp ( sa, sb, co ) ) ;
-
 
447
	}
-
 
448
	case exp_base_cast_tag : {
-
 
449
	    /* Base cast expressions */
-
 
450
	    EXP ra = DEREF_exp ( exp_base_cast_arg ( a ) ) ;
-
 
451
	    EXP rb = DEREF_exp ( exp_base_cast_arg ( b ) ) ;
-
 
452
	    OFFSET za = DEREF_off ( exp_base_cast_off ( a ) ) ;
-
 
453
	    OFFSET zb = DEREF_off ( exp_base_cast_off ( b ) ) ;
-
 
454
	    unsigned va = DEREF_unsigned ( exp_base_cast_conv ( a ) ) ;
-
 
455
	    unsigned vb = DEREF_unsigned ( exp_base_cast_conv ( b ) ) ;
-
 
456
	    if ( va != vb ) return ( 0 ) ;
-
 
457
	    return ( eq_exp ( ra, rb, co ) && eq_offset ( za, zb, co ) ) ;
-
 
458
	}
-
 
459
	case exp_dyn_cast_tag : {
-
 
460
	    /* Dynamic cast expressions */
-
 
461
	    EXP sa = DEREF_exp ( exp_dyn_cast_arg ( a ) ) ;
-
 
462
	    EXP sb = DEREF_exp ( exp_dyn_cast_arg ( b ) ) ;
-
 
463
	    EXP ra = DEREF_exp ( exp_dyn_cast_except ( a ) ) ;
-
 
464
	    EXP rb = DEREF_exp ( exp_dyn_cast_except ( b ) ) ;
-
 
465
	    return ( eq_exp ( sa, sb, co ) && eq_exp ( ra, rb, co ) ) ;
-
 
466
	}
-
 
467
	case exp_add_ptr_tag : {
-
 
468
	    /* Pointer addition expressions */
-
 
469
	    EXP ra = DEREF_exp ( exp_add_ptr_ptr ( a ) ) ;
-
 
470
	    EXP rb = DEREF_exp ( exp_add_ptr_ptr ( b ) ) ;
-
 
471
	    OFFSET za = DEREF_off ( exp_add_ptr_off ( a ) ) ;
-
 
472
	    OFFSET zb = DEREF_off ( exp_add_ptr_off ( b ) ) ;
-
 
473
	    return ( eq_exp ( ra, rb, co ) && eq_offset ( za, zb, co ) ) ;
-
 
474
	}
-
 
475
	case exp_offset_size_tag : {
-
 
476
	    /* Offset size expressions */
-
 
477
	    OFFSET xa = DEREF_off ( exp_offset_size_off ( a ) ) ;
-
 
478
	    OFFSET xb = DEREF_off ( exp_offset_size_off ( b ) ) ;
-
 
479
	    TYPE sa = DEREF_type ( exp_offset_size_step ( a ) ) ;
-
 
480
	    TYPE sb = DEREF_type ( exp_offset_size_step ( b ) ) ;
-
 
481
	    return ( eq_offset ( xa, xb, co ) && eq_type_offset ( sa, sb ) ) ;
-
 
482
	}
-
 
483
	case exp_constr_tag : {
-
 
484
	    /* Constructors */
-
 
485
	    EXP sa = DEREF_exp ( exp_constr_call ( a ) ) ;
-
 
486
	    EXP sb = DEREF_exp ( exp_constr_call ( b ) ) ;
-
 
487
	    return ( eq_exp ( sa, sb, co ) ) ;
-
 
488
	}
-
 
489
	case exp_destr_tag : {
-
 
490
	    /* Destructors */
-
 
491
	    EXP sa = DEREF_exp ( exp_destr_call ( a ) ) ;
-
 
492
	    EXP sb = DEREF_exp ( exp_destr_call ( b ) ) ;
-
 
493
	    return ( eq_exp ( sa, sb, co ) ) ;
-
 
494
	}
-
 
495
	case exp_alloc_tag : {
-
 
496
	    /* Allocators */
-
 
497
	    EXP sa = DEREF_exp ( exp_alloc_call ( a ) ) ;
-
 
498
	    EXP sb = DEREF_exp ( exp_alloc_call ( b ) ) ;
-
 
499
	    EXP ra = DEREF_exp ( exp_alloc_init ( a ) ) ;
-
 
500
	    EXP rb = DEREF_exp ( exp_alloc_init ( b ) ) ;
-
 
501
	    return ( eq_exp ( sa, sb, co ) && eq_exp ( ra, rb, co ) ) ;
-
 
502
	}
-
 
503
	case exp_dealloc_tag : {
-
 
504
	    /* Deallocators */
-
 
505
	    EXP sa = DEREF_exp ( exp_dealloc_call ( a ) ) ;
-
 
506
	    EXP sb = DEREF_exp ( exp_dealloc_call ( b ) ) ;
-
 
507
	    EXP ra = DEREF_exp ( exp_dealloc_term ( a ) ) ;
-
 
508
	    EXP rb = DEREF_exp ( exp_dealloc_term ( b ) ) ;
-
 
509
	    return ( eq_exp ( sa, sb, co ) && eq_exp ( ra, rb, co ) ) ;
-
 
510
	}
-
 
511
	case exp_rtti_tag : {
-
 
512
	    /* Run-time type information */
-
 
513
	    EXP sa = DEREF_exp ( exp_rtti_arg ( a ) ) ;
-
 
514
	    EXP sb = DEREF_exp ( exp_rtti_arg ( b ) ) ;
-
 
515
	    EXP ra = DEREF_exp ( exp_rtti_except ( a ) ) ;
-
 
516
	    EXP rb = DEREF_exp ( exp_rtti_except ( b ) ) ;
-
 
517
	    int ia = DEREF_int ( exp_rtti_op ( a ) ) ;
-
 
518
	    int ib = DEREF_int ( exp_rtti_op ( b ) ) ;
-
 
519
	    if ( ia != ib ) return ( 0 ) ;
-
 
520
	    return ( eq_exp ( sa, sb, co ) && eq_exp ( ra, rb, co ) ) ;
-
 
521
	}
-
 
522
	case exp_rtti_type_tag : {
-
 
523
	    /* Run-time type information */
-
 
524
	    TYPE sa = DEREF_type ( exp_rtti_type_arg ( a ) ) ;
-
 
525
	    TYPE sb = DEREF_type ( exp_rtti_type_arg ( b ) ) ;
-
 
526
	    int ia = DEREF_int ( exp_rtti_type_op ( a ) ) ;
-
 
527
	    int ib = DEREF_int ( exp_rtti_type_op ( b ) ) ;
-
 
528
	    if ( ia != ib ) return ( 0 ) ;
-
 
529
	    if ( eq_type ( sa, sb ) == 1 ) return ( 1 ) ;
-
 
530
	    return ( 0 ) ;
-
 
531
	}
-
 
532
	case exp_rtti_no_tag : {
-
 
533
	    /* Link-time type information */
-
 
534
	    TYPE sa = DEREF_type ( exp_rtti_no_arg ( a ) ) ;
-
 
535
	    TYPE sb = DEREF_type ( exp_rtti_no_arg ( b ) ) ;
-
 
536
	    if ( eq_type ( sa, sb ) == 1 ) return ( 1 ) ;
-
 
537
	    return ( 0 ) ;
-
 
538
	}
-
 
539
	case exp_dynamic_tag : {
-
 
540
	    /* Dynamic initialisers */
-
 
541
	    EXP sa = DEREF_exp ( exp_dynamic_arg ( a ) ) ;
-
 
542
	    EXP sb = DEREF_exp ( exp_dynamic_arg ( b ) ) ;
-
 
543
	    return ( eq_exp ( sa, sb, co ) ) ;
-
 
544
	}
-
 
545
	case exp_aggregate_tag : {
-
 
546
	    /* Aggregate initialisers */
-
 
547
	    LIST ( EXP ) pa = DEREF_list ( exp_aggregate_args ( a ) ) ;
-
 
548
	    LIST ( EXP ) pb = DEREF_list ( exp_aggregate_args ( b ) ) ;
-
 
549
	    return ( eq_exp_list ( pa, pb, co ) ) ;
-
 
550
	}
-
 
551
	case exp_initialiser_tag : {
-
 
552
	    /* Function style initialisers */
-
 
553
	    LIST ( EXP ) pa = DEREF_list ( exp_initialiser_args ( a ) ) ;
-
 
554
	    LIST ( EXP ) pb = DEREF_list ( exp_initialiser_args ( b ) ) ;
-
 
555
	    return ( eq_exp_list ( pa, pb, co ) ) ;
-
 
556
	}
-
 
557
	case exp_nof_tag : {
-
 
558
	    /* Array initialisers */
-
 
559
	    EXP ra = DEREF_exp ( exp_nof_start ( a ) ) ;
-
 
560
	    EXP rb = DEREF_exp ( exp_nof_start ( b ) ) ;
-
 
561
	    EXP sa = DEREF_exp ( exp_nof_pad ( a ) ) ;
-
 
562
	    EXP sb = DEREF_exp ( exp_nof_pad ( b ) ) ;
-
 
563
	    NAT na = DEREF_nat ( exp_nof_size ( a ) ) ;
-
 
564
	    NAT nb = DEREF_nat ( exp_nof_size ( b ) ) ;
-
 
565
	    EXP ua = DEREF_exp ( exp_nof_end ( a ) ) ;
-
 
566
	    EXP ub = DEREF_exp ( exp_nof_end ( b ) ) ;
-
 
567
	    if ( !EQ_nat ( na, nb ) ) {
-
 
568
		if ( !eq_nat ( na, nb ) ) return ( 0 ) ;
-
 
569
	    }
722
		break;
570
	    if ( !eq_exp ( sa, sb, co ) ) return ( 0 ) ;
-
 
571
	    return ( eq_exp ( ra, rb, co ) && eq_exp ( ua, ub, co ) ) ;
-
 
572
	}
-
 
573
	case exp_comma_tag : {
-
 
574
	    /* Comma expressions */
-
 
575
	    LIST ( EXP ) pa = DEREF_list ( exp_comma_args ( a ) ) ;
-
 
576
	    LIST ( EXP ) pb = DEREF_list ( exp_comma_args ( b ) ) ;
-
 
577
	    return ( eq_exp_list ( pa, pb, co ) ) ;
-
 
578
	}
-
 
579
	case exp_set_tag :
-
 
580
	case exp_unused_tag : {
-
 
581
	    /* Flow analysis expressions */
-
 
582
	    EXP sa = DEREF_exp ( exp_set_etc_arg ( a ) ) ;
-
 
583
	    EXP sb = DEREF_exp ( exp_set_etc_arg ( b ) ) ;
-
 
584
	    return ( eq_exp ( sa, sb, co ) ) ;
-
 
585
	}
-
 
586
	case exp_if_stmt_tag : {
-
 
587
	    /* Conditional expressions */
-
 
588
	    EXP ca = DEREF_exp ( exp_if_stmt_cond ( a ) ) ;
-
 
589
	    EXP cb = DEREF_exp ( exp_if_stmt_cond ( b ) ) ;
-
 
590
	    EXP ra = DEREF_exp ( exp_if_stmt_true_code ( a ) ) ;
-
 
591
	    EXP rb = DEREF_exp ( exp_if_stmt_true_code ( b ) ) ;
-
 
592
	    EXP sa = DEREF_exp ( exp_if_stmt_false_code ( a ) ) ;
-
 
593
	    EXP sb = DEREF_exp ( exp_if_stmt_false_code ( b ) ) ;
-
 
594
	    if ( !eq_exp ( ca, cb, co ) ) return ( 0 ) ;
-
 
595
	    return ( eq_exp ( ra, rb, co ) && eq_exp ( sa, sb, co ) ) ;
-
 
596
	}
-
 
597
	case exp_exception_tag : {
-
 
598
	    /* Throw expressions */
-
 
599
	    EXP sa = DEREF_exp ( exp_exception_arg ( a ) ) ;
-
 
600
	    EXP sb = DEREF_exp ( exp_exception_arg ( b ) ) ;
-
 
601
	    return ( eq_exp ( sa, sb, co ) ) ;
-
 
602
	}
723
	}
603
	case exp_thrown_tag : {
724
	case exp_location_tag: {
604
	    /* Thrown expressions */
725
		/* Location expressions */
605
	    TYPE ta = DEREF_type ( exp_type ( a ) ) ;
-
 
606
	    TYPE tb = DEREF_type ( exp_type ( b ) ) ;
-
 
607
	    if ( eq_type ( ta, tb ) == 1 ) return ( 1 ) ;
-
 
608
	    return ( 0 ) ;
-
 
609
	}
-
 
610
	case exp_op_tag : {
-
 
611
	    /* Undetermined expressions */
-
 
612
	    int ca = DEREF_int ( exp_op_lex ( a ) ) ;
-
 
613
	    int cb = DEREF_int ( exp_op_lex ( b ) ) ;
-
 
614
	    EXP ra = DEREF_exp ( exp_op_arg1 ( a ) ) ;
-
 
615
	    EXP rb = DEREF_exp ( exp_op_arg1 ( b ) ) ;
-
 
616
	    EXP sa = DEREF_exp ( exp_op_arg2 ( a ) ) ;
726
		EXP sa = DEREF_exp(exp_location_arg(a));
617
	    EXP sb = DEREF_exp ( exp_op_arg2 ( b ) ) ;
727
		EXP sb = DEREF_exp(exp_location_arg(b));
618
	    if ( ca != cb ) return ( 0 ) ;
-
 
619
	    return ( eq_exp ( ra, rb, co ) && eq_exp ( sa, sb, co ) ) ;
-
 
620
	}
-
 
621
	case exp_opn_tag : {
-
 
622
	    /* Undetermined expressions */
-
 
623
	    int ca = DEREF_int ( exp_opn_lex ( a ) ) ;
-
 
624
	    int cb = DEREF_int ( exp_opn_lex ( b ) ) ;
-
 
625
	    LIST ( EXP ) pa = DEREF_list ( exp_opn_args ( a ) ) ;
-
 
626
	    LIST ( EXP ) pb = DEREF_list ( exp_opn_args ( b ) ) ;
-
 
627
	    if ( ca != cb ) return ( 0 ) ;
-
 
628
	    return ( eq_exp_list ( pa, pb, co ) ) ;
-
 
629
	}
-
 
630
	case exp_assembler_tag : {
-
 
631
	    /* Assembler expressions */
-
 
632
	    STRING ca = DEREF_str ( exp_assembler_op ( a ) ) ;
-
 
633
	    STRING cb = DEREF_str ( exp_assembler_op ( b ) ) ;
-
 
634
	    if ( EQ_str ( ca, cb ) || eq_string_lit ( ca, cb ) ) {
-
 
635
		LIST ( EXP ) pa = DEREF_list ( exp_assembler_args ( a ) ) ;
-
 
636
		LIST ( EXP ) pb = DEREF_list ( exp_assembler_args ( b ) ) ;
-
 
637
		return ( eq_exp_list ( pa, pb, co ) ) ;
728
		return (eq_exp(sa, sb, co));
638
	    }
-
 
639
	    break ;
-
 
640
	}
729
	}
641
	case exp_location_tag : {
730
	case exp_token_tag: {
642
	    /* Location expressions */
731
		/* Token application */
-
 
732
		IDENTIFIER ia = DEREF_id(exp_token_tok(a));
-
 
733
		IDENTIFIER ib = DEREF_id(exp_token_tok(b));
643
	    EXP sa = DEREF_exp ( exp_location_arg ( a ) ) ;
734
		LIST(TOKEN)pa = DEREF_list(exp_token_args(a));
644
	    EXP sb = DEREF_exp ( exp_location_arg ( b ) ) ;
735
		LIST(TOKEN)pb = DEREF_list(exp_token_args(b));
645
	    return ( eq_exp ( sa, sb, co ) ) ;
736
		return (eq_token_args(ia, ib, pa, pb));
646
	}
737
	}
647
	case exp_token_tag : {
738
	case exp_dummy_tag: {
648
	    /* Token application */
739
		/* Dummy expressions */
649
	    IDENTIFIER ia = DEREF_id ( exp_token_tok ( a ) ) ;
740
		EXP sa = DEREF_exp(exp_dummy_value(a));
650
	    IDENTIFIER ib = DEREF_id ( exp_token_tok ( b ) ) ;
741
		EXP sb = DEREF_exp(exp_dummy_value(b));
651
	    LIST ( TOKEN ) pa = DEREF_list ( exp_token_args ( a ) ) ;
-
 
652
	    LIST ( TOKEN ) pb = DEREF_list ( exp_token_args ( b ) ) ;
-
 
653
	    return ( eq_token_args ( ia, ib, pa, pb ) ) ;
742
		return (eq_exp(sa, sb, co));
654
	}
743
	}
-
 
744
	case exp_reach_tag:
-
 
745
	case exp_unreach_tag:
-
 
746
	case exp_sequence_tag:
-
 
747
	case exp_solve_stmt_tag:
-
 
748
	case exp_decl_stmt_tag:
-
 
749
	case exp_while_stmt_tag:
655
	case exp_dummy_tag : {
750
	case exp_do_stmt_tag:
-
 
751
	case exp_switch_stmt_tag:
-
 
752
	case exp_hash_if_tag:
656
	    /* Dummy expressions */
753
	case exp_return_stmt_tag:
-
 
754
	case exp_goto_stmt_tag:
-
 
755
	case exp_label_stmt_tag:
657
	    EXP sa = DEREF_exp ( exp_dummy_value ( a ) ) ;
756
	case exp_try_block_tag:
-
 
757
	case exp_handler_tag:
658
	    EXP sb = DEREF_exp ( exp_dummy_value ( b ) ) ;
758
	case exp_uncompiled_tag:
-
 
759
	case exp_fail_tag: {
659
	    return ( eq_exp ( sa, sb, co ) ) ;
760
		/* Statements are never equal */
-
 
761
		return (0);
660
	}
762
	}
661
	case exp_reach_tag :
-
 
662
	case exp_unreach_tag :
-
 
663
	case exp_sequence_tag :
-
 
664
	case exp_solve_stmt_tag :
-
 
665
	case exp_decl_stmt_tag :
-
 
666
	case exp_while_stmt_tag :
-
 
667
	case exp_do_stmt_tag :
-
 
668
	case exp_switch_stmt_tag :
-
 
669
	case exp_hash_if_tag :
-
 
670
	case exp_return_stmt_tag :
-
 
671
	case exp_goto_stmt_tag :
-
 
672
	case exp_label_stmt_tag :
-
 
673
	case exp_try_block_tag :
-
 
674
	case exp_handler_tag :
-
 
675
	case exp_uncompiled_tag :
-
 
676
	case exp_fail_tag : {
-
 
677
	    /* Statements are never equal */
-
 
678
	    return ( 0 ) ;
-
 
679
	}
763
	}
680
    }
-
 
681
    return ( 0 ) ;
764
	return (0);
682
}
765
}
683
 
766
 
684
 
767
 
685
/*
768
/*
686
    UNIFY TWO EXPRESSIONS
769
    UNIFY TWO EXPRESSIONS
Line 689... Line 772...
689
    necessary.  It returns true if a value is assigned to a token.  Note
772
    necessary.  It returns true if a value is assigned to a token.  Note
690
    that it is necessary to consider integer constant tokens as well as
773
    that it is necessary to consider integer constant tokens as well as
691
    expression tokens.
774
    expression tokens.
692
*/
775
*/
693
 
776
 
694
static int unify_exp
777
static int
695
    PROTO_N ( ( a, b ) )
-
 
696
    PROTO_T ( EXP a X EXP b )
778
unify_exp(EXP a, EXP b)
697
{
779
{
698
    IDENTIFIER id ;
780
	IDENTIFIER id;
699
    LIST ( TOKEN ) args ;
781
	LIST(TOKEN)args;
700
    switch ( TAG_exp ( a ) ) {
782
	switch (TAG_exp(a)) {
701
	case exp_token_tag : {
783
	case exp_token_tag: {
702
	    id = DEREF_id ( exp_token_tok ( a ) ) ;
784
		id = DEREF_id(exp_token_tok(a));
703
	    args = DEREF_list ( exp_token_args ( a ) ) ;
785
		args = DEREF_list(exp_token_args(a));
704
	    break ;
786
		break;
705
	}
787
	}
706
	case exp_int_lit_tag : {
788
	case exp_int_lit_tag: {
707
	    NAT n = DEREF_nat ( exp_int_lit_nat ( a ) ) ;
789
		NAT n = DEREF_nat(exp_int_lit_nat(a));
708
	    if ( !IS_nat_token ( n ) ) return ( 0 ) ;
790
		if (!IS_nat_token(n)) {
-
 
791
			return (0);
-
 
792
		}
709
	    id = DEREF_id ( nat_token_tok ( n ) ) ;
793
		id = DEREF_id(nat_token_tok(n));
710
	    args = DEREF_list ( nat_token_args ( n ) ) ;
794
		args = DEREF_list(nat_token_args(n));
711
	    break ;
795
		break;
712
	}
796
	}
713
	default : {
797
	default:
714
	    return ( 0 ) ;
798
		return (0);
715
	}
799
	}
716
    }
-
 
717
    if ( IS_NULL_list ( args ) && defining_token ( id ) ) {
800
	if (IS_NULL_list(args) && defining_token(id)) {
718
	return ( define_exp_token ( id, b, 1 ) ) ;
801
		return (define_exp_token(id, b, 1));
719
    }
802
	}
720
    return ( 0 ) ;
803
	return (0);
721
}
804
}
722
 
805
 
723
 
806
 
724
/*
807
/*
725
    ARE TWO EXPRESSIONS EQUAL?
808
    ARE TWO EXPRESSIONS EQUAL?
726
 
809
 
727
    This routine checks whether the expressions a and b are equal.  If
810
    This routine checks whether the expressions a and b are equal.  If
728
    co is true then commutivity and other such relations are taken
811
    co is true then commutivity and other such relations are taken
729
    into account.
812
    into account.
730
*/
813
*/
731
 
814
 
732
int eq_exp
815
int
733
    PROTO_N ( ( a, b, co ) )
-
 
734
    PROTO_T ( EXP a X EXP b X int co )
816
eq_exp(EXP a, EXP b, int co)
735
{
817
{
736
    /* Check for obvious equality */
818
	/* Check for obvious equality */
737
    unsigned ta, tb ;
819
	unsigned ta, tb;
738
    if ( EQ_exp ( a, b ) ) return ( 1 ) ;
820
	if (EQ_exp(a, b)) {
-
 
821
		return (1);
-
 
822
	}
739
    if ( IS_NULL_exp ( a ) ) return ( 0 ) ;
823
	if (IS_NULL_exp(a)) {
-
 
824
		return (0);
-
 
825
	}
740
    if ( IS_NULL_exp ( b ) ) return ( 0 ) ;
826
	if (IS_NULL_exp(b)) {
-
 
827
		return (0);
-
 
828
	}
741
 
829
 
742
    /* Allow for parentheses */
830
	/* Allow for parentheses */
743
    ta = TAG_exp ( a ) ;
831
	ta = TAG_exp(a);
744
    while ( ta == exp_paren_tag || ta == exp_copy_tag ) {
832
	while (ta == exp_paren_tag || ta == exp_copy_tag) {
745
	a = DEREF_exp ( exp_paren_etc_arg ( a ) ) ;
833
		a = DEREF_exp(exp_paren_etc_arg(a));
746
	ta = TAG_exp ( a ) ;
834
		ta = TAG_exp(a);
747
    }
835
	}
748
    tb = TAG_exp ( b ) ;
836
	tb = TAG_exp(b);
749
    while ( tb == exp_paren_tag || tb == exp_copy_tag ) {
837
	while (tb == exp_paren_tag || tb == exp_copy_tag) {
750
	b = DEREF_exp ( exp_paren_etc_arg ( b ) ) ;
838
		b = DEREF_exp(exp_paren_etc_arg(b));
751
	tb = TAG_exp ( b ) ;
839
		tb = TAG_exp(b);
752
    }
840
	}
753
 
841
 
754
    /* Check equality of expressions */
842
	/* Check equality of expressions */
755
    if ( ta == tb && eq_exp_aux ( a, b, co ) ) return ( 1 ) ;
843
	if (ta == tb && eq_exp_aux(a, b, co)) {
-
 
844
		return (1);
-
 
845
	}
756
    if ( force_tokdef || force_template || expand_tokdef ) {
846
	if (force_tokdef || force_template || expand_tokdef) {
757
	TYPE sa = DEREF_type ( exp_type ( a ) ) ;
847
		TYPE sa = DEREF_type(exp_type(a));
758
	TYPE sb = DEREF_type ( exp_type ( b ) ) ;
848
		TYPE sb = DEREF_type(exp_type(b));
759
	if ( eq_type ( sa, sb ) == 1 ) {
849
		if (eq_type(sa, sb) == 1) {
760
	    if ( unify_exp ( a, b ) ) return ( 1 ) ;
850
			if (unify_exp(a, b)) {
-
 
851
				return (1);
-
 
852
			}
761
	    if ( unify_exp ( b, a ) ) return ( 1 ) ;
853
			if (unify_exp(b, a)) {
-
 
854
				return (1);
-
 
855
			}
762
	}
856
		}
763
    }
857
	}
764
    return ( 0 ) ;
858
	return (0);
765
}
859
}
766
 
860
 
767
 
861
 
768
/*
862
/*
769
    ARE TWO EXPRESSIONS PRECISELY EQUAL?
863
    ARE TWO EXPRESSIONS PRECISELY EQUAL?
770
 
864
 
771
    This routine is similar to eq_exp, but it disallows token and template
865
    This routine is similar to eq_exp, but it disallows token and template
772
    unification and does not allow for commutivity relations.
866
    unification and does not allow for commutivity relations.
773
*/
867
*/
774
 
868
 
775
int eq_exp_exact
869
int
776
    PROTO_N ( ( a, b ) )
-
 
777
    PROTO_T ( EXP a X EXP b )
870
eq_exp_exact(EXP a, EXP b)
778
{
871
{
779
    int eq ;
872
	int eq;
780
    int tok = force_tokdef ;
873
	int tok = force_tokdef;
781
    int templ = force_template ;
874
	int templ = force_template;
782
    force_tokdef = 0 ;
875
	force_tokdef = 0;
783
    force_template = 0 ;
876
	force_template = 0;
784
    eq = eq_exp ( a, b, 0 ) ;
877
	eq = eq_exp(a, b, 0);
785
    force_template = templ ;
878
	force_template = templ;
786
    force_tokdef = tok ;
879
	force_tokdef = tok;
787
    return ( eq ) ;
880
	return (eq);
788
}
881
}
789
 
882
 
790
 
883
 
791
/*
884
/*
792
    ARE TWO TOKENS EQUAL?
885
    ARE TWO TOKENS EQUAL?
793
 
886
 
794
    This routine checks whether the tokens a and b are equal.
887
    This routine checks whether the tokens a and b are equal.
795
*/
888
*/
796
 
889
 
797
int eq_token
890
int
798
    PROTO_N ( ( a, b ) )
-
 
799
    PROTO_T ( TOKEN a X TOKEN b )
891
eq_token(TOKEN a, TOKEN b)
800
{
892
{
801
    unsigned na, nb ;
893
	unsigned na, nb;
802
    if ( EQ_tok ( a, b ) ) return ( 1 ) ;
-
 
803
    if ( IS_NULL_tok ( a ) ) return ( 0 ) ;
-
 
804
    if ( IS_NULL_tok ( b ) ) return ( 0 ) ;
-
 
805
    na = TAG_tok ( a ) ;
-
 
806
    nb = TAG_tok ( b ) ;
894
	if (EQ_tok(a, b)) {
807
    if ( na != nb ) return ( 0 ) ;
-
 
808
    switch ( na ) {
895
		return (1);
809
	case tok_exp_tag : {
-
 
810
	    EXP va = DEREF_exp ( tok_exp_value ( a ) ) ;
-
 
811
	    EXP vb = DEREF_exp ( tok_exp_value ( b ) ) ;
-
 
812
	    return ( eq_exp ( va, vb, 0 ) ) ;
-
 
813
	}
896
	}
814
	case tok_stmt_tag : {
897
	if (IS_NULL_tok(a)) {
815
	    EXP va = DEREF_exp ( tok_stmt_value ( a ) ) ;
-
 
816
	    EXP vb = DEREF_exp ( tok_stmt_value ( b ) ) ;
-
 
817
	    return ( eq_exp ( va, vb, 0 ) ) ;
898
		return (0);
818
	}
899
	}
-
 
900
	if (IS_NULL_tok(b)) {
-
 
901
		return (0);
-
 
902
	}
-
 
903
	na = TAG_tok(a);
-
 
904
	nb = TAG_tok(b);
-
 
905
	if (na != nb) {
-
 
906
		return (0);
-
 
907
	}
-
 
908
	switch (na) {
-
 
909
	case tok_exp_tag: {
-
 
910
		EXP va = DEREF_exp(tok_exp_value(a));
-
 
911
		EXP vb = DEREF_exp(tok_exp_value(b));
-
 
912
		return (eq_exp(va, vb, 0));
-
 
913
	}
-
 
914
	case tok_stmt_tag: {
-
 
915
		EXP va = DEREF_exp(tok_stmt_value(a));
-
 
916
		EXP vb = DEREF_exp(tok_stmt_value(b));
-
 
917
		return (eq_exp(va, vb, 0));
-
 
918
	}
819
	case tok_nat_tag :
919
	case tok_nat_tag:
820
	case tok_snat_tag : {
920
	case tok_snat_tag: {
821
	    NAT va = DEREF_nat ( tok_nat_etc_value ( a ) ) ;
921
		NAT va = DEREF_nat(tok_nat_etc_value(a));
822
	    NAT vb = DEREF_nat ( tok_nat_etc_value ( b ) ) ;
922
		NAT vb = DEREF_nat(tok_nat_etc_value(b));
823
	    if ( compare_nat ( va, vb ) == 0 ) return ( 1 ) ;
923
		if (compare_nat(va, vb) == 0) {
-
 
924
			return (1);
-
 
925
		}
824
	    break ;
926
		break;
-
 
927
	}
-
 
928
	case tok_type_tag: {
-
 
929
		TYPE va = DEREF_type(tok_type_value(a));
-
 
930
		TYPE vb = DEREF_type(tok_type_value(b));
-
 
931
		if (eq_type(va, vb) == 1) {
-
 
932
			return (1);
-
 
933
		}
-
 
934
		return (0);
825
	}
935
	}
826
	case tok_type_tag : {
936
	case tok_member_tag: {
827
	    TYPE va = DEREF_type ( tok_type_value ( a ) ) ;
937
		OFFSET va = DEREF_off(tok_member_value(a));
828
	    TYPE vb = DEREF_type ( tok_type_value ( b ) ) ;
938
		OFFSET vb = DEREF_off(tok_member_value(b));
829
	    if ( eq_type ( va, vb ) == 1 ) return ( 1 ) ;
939
		return (eq_offset(va, vb, 0));
830
	    return ( 0 ) ;
-
 
831
	}
940
	}
832
	case tok_member_tag : {
941
	case tok_class_tag: {
833
	    OFFSET va = DEREF_off ( tok_member_value ( a ) ) ;
942
		IDENTIFIER ia = DEREF_id(tok_class_value(a));
834
	    OFFSET vb = DEREF_off ( tok_member_value ( b ) ) ;
943
		IDENTIFIER ib = DEREF_id(tok_class_value(b));
835
	    return ( eq_offset ( va, vb, 0 ) ) ;
944
		return (EQ_id(ia, ib));
836
	}
945
	}
837
	case tok_class_tag : {
-
 
838
	    IDENTIFIER ia = DEREF_id ( tok_class_value ( a ) ) ;
-
 
839
	    IDENTIFIER ib = DEREF_id ( tok_class_value ( b ) ) ;
-
 
840
	    return ( EQ_id ( ia, ib ) ) ;
-
 
841
	}
946
	}
842
    }
-
 
843
    return ( 0 ) ;
947
	return (0);
844
}
948
}
845
 
949
 
846
 
950
 
847
/*
951
/*
848
    ARE TWO TOKEN APPLICATIONS EQUAL?
952
    ARE TWO TOKEN APPLICATIONS EQUAL?
849
 
953
 
850
    This routine checks whether the token applications ia ( pa ) and
954
    This routine checks whether the token applications ia ( pa ) and
851
    ib ( pb ) are equal.
955
    ib ( pb ) are equal.
852
*/
956
*/
853
 
957
 
854
int eq_token_args
958
int
855
    PROTO_N ( ( ia, ib, pa, pb ) )
-
 
856
    PROTO_T ( IDENTIFIER ia X IDENTIFIER ib X
959
eq_token_args(IDENTIFIER ia, IDENTIFIER ib, LIST(TOKEN)pa, LIST(TOKEN)pb)
857
	      LIST ( TOKEN ) pa X LIST ( TOKEN ) pb )
-
 
858
{
960
{
859
    if ( !EQ_id ( ia, ib ) ) {
961
	if (!EQ_id(ia, ib)) {
860
	/* Check that tokens are the same */
962
		/* Check that tokens are the same */
861
	ia = DEREF_id ( id_alias ( ia ) ) ;
963
		ia = DEREF_id(id_alias(ia));
862
	ib = DEREF_id ( id_alias ( ib ) ) ;
964
		ib = DEREF_id(id_alias(ib));
863
	if ( !EQ_id ( ia, ib ) ) {
965
		if (!EQ_id(ia, ib)) {
864
	    if ( !force_merge || !merge_type ( ia, ib ) ) {
966
			if (!force_merge || !merge_type(ia, ib)) {
865
		return ( 0 ) ;
967
				return (0);
866
	    }
968
			}
867
	}
969
		}
868
    }
970
	}
869
    if ( EQ_list ( pa, pb ) ) return ( 1 ) ;
971
	if (EQ_list(pa, pb)) {
-
 
972
		return (1);
-
 
973
	}
870
    if ( LENGTH_list ( pa ) != LENGTH_list ( pb ) ) return ( 0 ) ;
974
	if (LENGTH_list(pa)!= LENGTH_list(pb)) {
-
 
975
		return (0);
-
 
976
	}
871
    while ( !IS_NULL_list ( pa ) ) {
977
	while (!IS_NULL_list(pa)) {
872
	TOKEN a, b ;
978
		TOKEN a, b;
873
	if ( EQ_list ( pa, pb ) ) return ( 1 ) ;
979
		if (EQ_list(pa, pb)) {
-
 
980
			return (1);
-
 
981
		}
874
	a = DEREF_tok ( HEAD_list ( pa ) ) ;
982
		a = DEREF_tok(HEAD_list(pa));
875
	b = DEREF_tok ( HEAD_list ( pb ) ) ;
983
		b = DEREF_tok(HEAD_list(pb));
876
	if ( !eq_token ( a, b ) ) return ( 0 ) ;
984
		if (!eq_token(a, b)) {
-
 
985
			return (0);
-
 
986
		}
877
	pb = TAIL_list ( pb ) ;
987
		pb = TAIL_list(pb);
878
	pa = TAIL_list ( pa ) ;
988
		pa = TAIL_list(pa);
879
    }
989
	}
880
    return ( 1 ) ;
990
	return (1);
881
}
991
}
882
 
992
 
883
 
993
 
884
/*
994
/*
885
    IS A TOKEN APPLICATION A CONSTANT?
995
    IS A TOKEN APPLICATION A CONSTANT?
886
 
996
 
887
    This routine checks whether the token id applied to the arguments args
997
    This routine checks whether the token id applied to the arguments args
888
    is a constant.
998
    is a constant.
889
*/
999
*/
890
 
1000
 
891
static int is_const_token
1001
static int
892
    PROTO_N ( ( id, args, c ) )
-
 
893
    PROTO_T ( IDENTIFIER id X LIST ( TOKEN ) args X int c )
1002
is_const_token(IDENTIFIER id, LIST(TOKEN)args, int c)
894
{
1003
{
895
    TOKEN tok = DEREF_tok ( id_token_sort ( id ) ) ;
1004
	TOKEN tok = DEREF_tok(id_token_sort(id));
896
    if ( IS_tok_proc ( tok ) ) {
1005
	if (IS_tok_proc(tok)) {
897
	/* Allow for procedure tokens */
1006
		/* Allow for procedure tokens */
898
	tok = DEREF_tok ( tok_proc_res ( tok ) ) ;
1007
		tok = DEREF_tok(tok_proc_res(tok));
899
    }
1008
	}
900
    switch ( TAG_tok ( tok ) ) {
1009
	switch (TAG_tok(tok)) {
901
	case tok_exp_tag : {
1010
	case tok_exp_tag: {
902
	    /* Check for constant expression tokens */
1011
		/* Check for constant expression tokens */
903
	    int cn = DEREF_int ( tok_exp_constant ( tok ) ) ;
1012
		int cn = DEREF_int(tok_exp_constant(tok));
904
	    if ( cn ) {
1013
		if (cn) {
905
		/* Constant token */
1014
			/* Constant token */
906
		return ( 1 ) ;
1015
			return (1);
907
	    }
1016
		}
908
	    if ( c >= 0 ) {
1017
		if (c >= 0) {
909
		/* Constant expression expected */
1018
			/* Constant expression expected */
910
		report ( crt_loc, ERR_token_const ( id ) ) ;
1019
			report(crt_loc, ERR_token_const(id));
911
	    }
1020
		}
912
	    if ( option ( OPT_token_const ) == OPTION_DISALLOW ) {
1021
		if (option(OPT_token_const) == OPTION_DISALLOW) {
913
		/* Non-constant tokens not allowed */
1022
			/* Non-constant tokens not allowed */
914
		return ( 0 ) ;
1023
			return (0);
915
	    }
1024
		}
916
	    break ;
1025
		break;
917
	}
1026
	}
918
	case tok_nat_tag : {
1027
	case tok_nat_tag: {
919
	    /* Integer constants */
1028
		/* Integer constants */
920
	    return ( 1 ) ;
1029
		return (1);
921
	}
1030
	}
922
	case tok_stmt_tag : {
1031
	case tok_stmt_tag: {
923
	    /* Statements are not constant */
1032
		/* Statements are not constant */
924
	    return ( 0 ) ;
1033
		return (0);
925
	}
1034
	}
926
    }
1035
	}
927
 
1036
 
928
    /* Check all token arguments */
1037
	/* Check all token arguments */
929
    while ( !IS_NULL_list ( args ) ) {
1038
	while (!IS_NULL_list(args)) {
930
	TOKEN a = DEREF_tok ( HEAD_list ( args ) ) ;
1039
		TOKEN a = DEREF_tok(HEAD_list(args));
931
	if ( !IS_NULL_tok ( a ) ) {
1040
		if (!IS_NULL_tok(a)) {
932
	    switch ( TAG_tok ( a ) ) {
1041
			switch (TAG_tok(a)) {
933
		case tok_exp_tag : {
1042
			case tok_exp_tag: {
934
		    EXP e = DEREF_exp ( tok_exp_value ( a ) ) ;
1043
				EXP e = DEREF_exp(tok_exp_value(a));
935
		    if ( !is_const_exp ( e, c ) ) return ( 0 ) ;
1044
				if (!is_const_exp(e, c)) {
-
 
1045
					return (0);
-
 
1046
				}
936
		    break ;
1047
				break;
937
		}
1048
			}
938
		case tok_stmt_tag : {
1049
			case tok_stmt_tag: {
939
		    EXP e = DEREF_exp ( tok_stmt_value ( a ) ) ;
1050
				EXP e = DEREF_exp(tok_stmt_value(a));
940
		    if ( !is_const_exp ( e, c ) ) return ( 0 ) ;
1051
				if (!is_const_exp(e, c)) {
-
 
1052
					return (0);
-
 
1053
				}
941
		    break ;
1054
				break;
942
		}
1055
			}
943
		case tok_member_tag : {
1056
			case tok_member_tag: {
944
		    OFFSET off = DEREF_off ( tok_member_value ( a ) ) ;
1057
				OFFSET off = DEREF_off(tok_member_value(a));
945
		    if ( !is_const_offset ( off, c, 1 ) ) return ( 0 ) ;
1058
				if (!is_const_offset(off, c, 1)) {
-
 
1059
					return (0);
-
 
1060
				}
946
		    break ;
1061
				break;
947
		}
1062
			}
948
	    }
1063
			}
949
	}
1064
		}
950
	args = TAIL_list ( args ) ;
1065
		args = TAIL_list(args);
951
    }
1066
	}
952
    return ( 1 ) ;
1067
	return (1);
953
}
1068
}
954
 
1069
 
955
 
1070
 
956
/*
1071
/*
957
    IS AN OFFSET A CONSTANT?
1072
    IS AN OFFSET A CONSTANT?
958
 
1073
 
959
    This routine checks whether the offset off is a constant offset.  virt
1074
    This routine checks whether the offset off is a constant offset.  virt
960
    is true if virtual base classes are to be taken into account.
1075
    is true if virtual base classes are to be taken into account.
961
*/
1076
*/
962
 
1077
 
963
int is_const_offset
1078
int
964
    PROTO_N ( ( off, c, virt ) )
-
 
965
    PROTO_T ( OFFSET off X int c X int virt )
1079
is_const_offset(OFFSET off, int c, int virt)
966
{
1080
{
967
    ASSERT ( ORDER_off == 13 ) ;
1081
	ASSERT(ORDER_off == 13);
968
    switch ( TAG_off ( off ) ) {
1082
	switch (TAG_off(off)) {
969
	case off_zero_tag :
1083
	case off_zero_tag:
970
	case off_type_tag :
1084
	case off_type_tag:
971
	case off_extra_tag :
1085
	case off_extra_tag:
972
	case off_array_tag :
1086
	case off_array_tag:
973
	case off_member_tag : {
1087
	case off_member_tag: {
974
	    /* Constant offsets */
1088
		/* Constant offsets */
975
	    return ( 1 ) ;
-
 
976
	}
-
 
977
	case off_base_tag : {
-
 
978
	    /* Base class offsets */
-
 
979
	    if ( virt ) {
-
 
980
		GRAPH gr = DEREF_graph ( off_base_graph ( off ) ) ;
-
 
981
		DECL_SPEC acc = DEREF_dspec ( graph_access ( gr ) ) ;
-
 
982
		if ( !( acc & dspec_mutable ) ) return ( 1 ) ;
-
 
983
	    } else {
-
 
984
		return ( 1 ) ;
-
 
985
	    }
-
 
986
	    break ;
-
 
987
	}
-
 
988
	case off_deriv_tag : {
-
 
989
	    /* Derived class offsets */
-
 
990
	    if ( virt ) {
-
 
991
		GRAPH gr = DEREF_graph ( off_deriv_graph ( off ) ) ;
-
 
992
		DECL_SPEC acc = DEREF_dspec ( graph_access ( gr ) ) ;
-
 
993
		if ( !( acc & dspec_mutable ) ) return ( 1 ) ;
-
 
994
	    } else {
-
 
995
		return ( 1 ) ;
1089
		return (1);
996
	    }
-
 
997
	    break ;
-
 
998
	}
-
 
999
	case off_ptr_mem_tag : {
-
 
1000
	    /* Pointer member offsets */
-
 
1001
	    EXP a = DEREF_exp ( off_ptr_mem_arg ( off ) ) ;
-
 
1002
	    return ( is_const_exp ( a, c ) ) ;
-
 
1003
	}
-
 
1004
	case off_negate_tag : {
-
 
1005
	    /* Offset negation */
-
 
1006
	    OFFSET off1 = DEREF_off ( off_negate_arg ( off ) ) ;
-
 
1007
	    return ( is_const_offset ( off1, c, 1 ) ) ;
-
 
1008
	}
1090
	}
-
 
1091
	case off_base_tag: {
-
 
1092
		/* Base class offsets */
-
 
1093
		if (virt) {
-
 
1094
			GRAPH gr = DEREF_graph(off_base_graph(off));
-
 
1095
			DECL_SPEC acc = DEREF_dspec(graph_access(gr));
-
 
1096
			if (!(acc & dspec_mutable)) {
-
 
1097
				return (1);
-
 
1098
			}
-
 
1099
		} else {
-
 
1100
			return (1);
-
 
1101
		}
-
 
1102
		break;
-
 
1103
	}
-
 
1104
	case off_deriv_tag: {
-
 
1105
		/* Derived class offsets */
-
 
1106
		if (virt) {
-
 
1107
			GRAPH gr = DEREF_graph(off_deriv_graph(off));
-
 
1108
			DECL_SPEC acc = DEREF_dspec(graph_access(gr));
-
 
1109
			if (!(acc & dspec_mutable)) {
-
 
1110
				return (1);
-
 
1111
			}
-
 
1112
		} else {
-
 
1113
			return (1);
-
 
1114
		}
-
 
1115
		break;
-
 
1116
	}
-
 
1117
	case off_ptr_mem_tag: {
-
 
1118
		/* Pointer member offsets */
-
 
1119
		EXP a = DEREF_exp(off_ptr_mem_arg(off));
-
 
1120
		return (is_const_exp(a, c));
-
 
1121
	}
-
 
1122
	case off_negate_tag: {
-
 
1123
		/* Offset negation */
-
 
1124
		OFFSET off1 = DEREF_off(off_negate_arg(off));
-
 
1125
		return (is_const_offset(off1, c, 1));
-
 
1126
	}
1009
	case off_plus_tag : {
1127
	case off_plus_tag: {
1010
	    /* Offset addition */
1128
		/* Offset addition */
1011
	    OFFSET off1 = DEREF_off ( off_plus_arg1 ( off ) ) ;
1129
		OFFSET off1 = DEREF_off(off_plus_arg1(off));
1012
	    OFFSET off2 = DEREF_off ( off_plus_arg2 ( off ) ) ;
1130
		OFFSET off2 = DEREF_off(off_plus_arg2(off));
1013
	    if ( !is_const_offset ( off1, c, 1 ) ) return ( 0 ) ;
1131
		if (!is_const_offset(off1, c, 1)) {
-
 
1132
			return (0);
-
 
1133
		}
1014
	    return ( is_const_offset ( off2, c, 1 ) ) ;
1134
		return (is_const_offset(off2, c, 1));
1015
	}
1135
	}
1016
	case off_mult_tag : {
1136
	case off_mult_tag: {
1017
	    /* Offset multiplication */
1137
		/* Offset multiplication */
1018
	    OFFSET off1 = DEREF_off ( off_mult_arg1 ( off ) ) ;
1138
		OFFSET off1 = DEREF_off(off_mult_arg1(off));
1019
	    EXP a = DEREF_exp ( off_mult_arg2 ( off ) ) ;
1139
		EXP a = DEREF_exp(off_mult_arg2(off));
1020
	    if ( !is_const_offset ( off1, c, 1 ) ) return ( 0 ) ;
1140
		if (!is_const_offset(off1, c, 1)) {
-
 
1141
			return (0);
-
 
1142
		}
1021
	    return ( is_const_exp ( a, c ) ) ;
1143
		return (is_const_exp(a, c));
1022
	}
1144
	}
1023
	case off_ptr_diff_tag : {
1145
	case off_ptr_diff_tag: {
1024
	    /* Pointer difference */
1146
		/* Pointer difference */
1025
	    EXP a = DEREF_exp ( off_ptr_diff_ptr1 ( off ) ) ;
1147
		EXP a = DEREF_exp(off_ptr_diff_ptr1(off));
1026
	    EXP b = DEREF_exp ( off_ptr_diff_ptr2 ( off ) ) ;
1148
		EXP b = DEREF_exp(off_ptr_diff_ptr2(off));
1027
	    if ( is_const_exp ( a, c ) && is_const_exp ( b, c ) ) {
1149
		if (is_const_exp(a, c) && is_const_exp(b, c)) {
1028
		/* Only allow pointers from same array */
1150
			/* Only allow pointers from same array */
1029
		EXP pa = NULL_exp ;
1151
			EXP pa = NULL_exp;
1030
		EXP pb = NULL_exp ;
1152
			EXP pb = NULL_exp;
1031
		IGNORE find_exp_linkage ( a, &pa, 1 ) ;
1153
			IGNORE find_exp_linkage(a, &pa, 1);
1032
		IGNORE find_exp_linkage ( b, &pb, 1 ) ;
1154
			IGNORE find_exp_linkage(b, &pb, 1);
1033
		if ( !IS_NULL_exp ( pa ) && !IS_exp_string_lit ( pa ) ) {
1155
			if (!IS_NULL_exp(pa) && !IS_exp_string_lit(pa)) {
1034
		    return ( eq_exp ( pa, pb, 0 ) ) ;
1156
				return (eq_exp(pa, pb, 0));
-
 
1157
			}
1035
		}
1158
		}
-
 
1159
		break;
1036
	    }
1160
	}
1037
	    break ;
1161
	case off_token_tag: {
-
 
1162
		/* All member tokens are constant */
-
 
1163
		IDENTIFIER id = DEREF_id(off_token_tok(off));
-
 
1164
		LIST(TOKEN)args = DEREF_list(off_token_args(off));
-
 
1165
		return (is_const_token(id, args, c));
1038
	}
1166
	}
1039
	case off_token_tag : {
-
 
1040
	    /* All member tokens are constant */
-
 
1041
	    IDENTIFIER id = DEREF_id ( off_token_tok ( off ) ) ;
-
 
1042
	    LIST ( TOKEN ) args = DEREF_list ( off_token_args ( off ) ) ;
-
 
1043
	    return ( is_const_token ( id, args, c ) ) ;
-
 
1044
	}
1167
	}
1045
    }
-
 
1046
    return ( 0 ) ;
1168
	return (0);
1047
}
1169
}
1048
 
1170
 
1049
 
1171
 
1050
/*
1172
/*
1051
    IS AN EXPRESSION AN ADDRESS CONSTANT?
1173
    IS AN EXPRESSION AN ADDRESS CONSTANT?
1052
 
1174
 
1053
    This routine checks whether the address of e is a constant expression.
1175
    This routine checks whether the address of e is a constant expression.
1054
    c will be nonzero.
1176
    c will be nonzero.
1055
*/
1177
*/
1056
 
1178
 
1057
static int is_const_addr
1179
static int
1058
    PROTO_N ( ( e, c ) )
-
 
1059
    PROTO_T ( EXP e X int c )
1180
is_const_addr(EXP e, int c)
1060
{
1181
{
1061
    if ( IS_NULL_exp ( e ) ) return ( 1 ) ;
1182
	if (IS_NULL_exp(e)) {
1062
    switch ( TAG_exp ( e ) ) {
-
 
1063
	case exp_identifier_tag : {
-
 
1064
	    /* Identifier expressions */
-
 
1065
	    IDENTIFIER id = DEREF_id ( exp_identifier_id ( e ) ) ;
-
 
1066
	    DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
-
 
1067
	    if ( !( ds & dspec_auto ) ) {
-
 
1068
		TYPE t = DEREF_type ( exp_type ( e ) ) ;
-
 
1069
		if ( !IS_type_ref ( t ) ) return ( 1 ) ;
-
 
1070
	    }
-
 
1071
	    break ;
1183
		return (1);
1072
	}
1184
	}
-
 
1185
	switch (TAG_exp(e)) {
-
 
1186
	case exp_identifier_tag: {
-
 
1187
		/* Identifier expressions */
-
 
1188
		IDENTIFIER id = DEREF_id(exp_identifier_id(e));
-
 
1189
		DECL_SPEC ds = DEREF_dspec(id_storage(id));
-
 
1190
		if (!(ds & dspec_auto)) {
-
 
1191
			TYPE t = DEREF_type(exp_type(e));
-
 
1192
			if (!IS_type_ref(t)) {
-
 
1193
				return (1);
-
 
1194
			}
-
 
1195
		}
-
 
1196
		break;
-
 
1197
	}
1073
	case exp_indir_tag : {
1198
	case exp_indir_tag: {
1074
	    /* Indirection expressions */
1199
		/* Indirection expressions */
1075
	    EXP a = DEREF_exp ( exp_indir_ptr ( e ) ) ;
1200
		EXP a = DEREF_exp(exp_indir_ptr(e));
1076
	    return ( is_const_exp ( a, c ) ) ;
1201
		return (is_const_exp(a, c));
1077
	}
1202
	}
1078
	case exp_member_tag :
1203
	case exp_member_tag:
1079
	case exp_string_lit_tag :
1204
	case exp_string_lit_tag:
1080
	case exp_rtti_type_tag : {
1205
	case exp_rtti_type_tag: {
1081
	    /* lvalue expressions */
1206
		/* lvalue expressions */
1082
	    return ( 1 ) ;
1207
		return (1);
1083
	}
1208
	}
1084
	case exp_token_tag : {
1209
	case exp_token_tag: {
1085
	    /* Tokenised expressions */
1210
		/* Tokenised expressions */
1086
	    return ( is_const_exp ( e, c ) ) ;
1211
		return (is_const_exp(e, c));
1087
	}
1212
	}
1088
	case exp_comma_tag : {
1213
	case exp_comma_tag: {
1089
	    /* Comma expressions (not allowed) */
1214
		/* Comma expressions (not allowed) */
1090
	    if ( c < 0 ) {
1215
		if (c < 0) {
1091
		LIST ( EXP ) p = DEREF_list ( exp_comma_args ( e ) ) ;
1216
			LIST(EXP)p = DEREF_list(exp_comma_args(e));
1092
		while ( !IS_NULL_list ( p ) ) {
1217
			while (!IS_NULL_list(p)) {
1093
		    EXP a = DEREF_exp ( HEAD_list ( p ) ) ;
1218
				EXP a = DEREF_exp(HEAD_list(p));
1094
		    p = TAIL_list ( p ) ;
1219
				p = TAIL_list(p);
1095
		    if ( IS_NULL_list ( p ) ) {
1220
				if (IS_NULL_list(p)) {
1096
			return ( is_const_addr ( a, c ) ) ;
1221
					return (is_const_addr(a, c));
1097
		    }
1222
				}
1098
		    if ( !is_const_exp ( a, c ) ) break ;
1223
				if (!is_const_exp(a, c)) {
-
 
1224
					break;
-
 
1225
				}
1099
		}
1226
			}
1100
	    }
1227
		}
1101
	    break ;
1228
		break;
1102
	}
1229
	}
1103
	case exp_if_stmt_tag : {
1230
	case exp_if_stmt_tag: {
1104
	    /* Conditional expressions */
1231
		/* Conditional expressions */
1105
	    EXP d = DEREF_exp ( exp_if_stmt_cond ( e ) ) ;
1232
		EXP d = DEREF_exp(exp_if_stmt_cond(e));
1106
	    EXP a = DEREF_exp ( exp_if_stmt_true_code ( e ) ) ;
1233
		EXP a = DEREF_exp(exp_if_stmt_true_code(e));
1107
	    EXP b = DEREF_exp ( exp_if_stmt_false_code ( e ) ) ;
1234
		EXP b = DEREF_exp(exp_if_stmt_false_code(e));
1108
	    if ( !is_const_exp ( d, c ) ) break ;
1235
		if (!is_const_exp(d, c)) {
-
 
1236
			break;
-
 
1237
		}
1109
	    if ( !is_const_addr ( a, c ) ) break ;
1238
		if (!is_const_addr(a, c)) {
-
 
1239
			break;
-
 
1240
		}
1110
	    return ( is_const_addr ( b, c ) ) ;
1241
		return (is_const_addr(b, c));
1111
	}
1242
	}
1112
    }
1243
	}
1113
    return ( 0 ) ;
1244
	return (0);
1114
}
1245
}
1115
 
1246
 
1116
 
1247
 
1117
/*
1248
/*
1118
    IS AN EXPRESSION CONSTANT?
1249
    IS AN EXPRESSION CONSTANT?
1119
 
1250
 
1120
    This routine checks whether e is a constant expression.  Note that
1251
    This routine checks whether e is a constant expression.  Note that
1121
    most integer constant expressions are dealt with in a bottom-up
1252
    most integer constant expressions are dealt with in a bottom-up
1122
    fashion by means of the constant evaluation routines.  Other
1253
    fashion by means of the constant evaluation routines.  Other
1123
    constants are dealt with in a top-down fashion by this routine.  If
1254
    constants are dealt with in a top-down fashion by this routine.  If
1124
    c is 0 then only valid integer constant expressions are allowed; c
1255
    c is 0 then only valid integer constant expressions are allowed; c
1125
    is -1 then only a check is intended.
1256
    is -1 then only a check is intended.
1393
/*
1561
/*
1394
    DOES AN EXPRESSION CONTAIN AN OVERFLOW?
1562
    DOES AN EXPRESSION CONTAIN AN OVERFLOW?
1395
 
1563
 
1396
    Certain evaluations on integer constant expressions are only valid
1564
    Certain evaluations on integer constant expressions are only valid
1397
    if it can be shown that the operands cannot raise an exception.
1565
    if it can be shown that the operands cannot raise an exception.
Line 1399... Line 1567...
1399
    evaluation of a does not overflow.  This routine returns true if
1567
    evaluation of a does not overflow.  This routine returns true if
1400
    the evaluation of the expression a may raise an overflow exception
1568
    the evaluation of the expression a may raise an overflow exception
1401
    or contains some other side effect.
1569
    or contains some other side effect.
1402
*/
1570
*/
1403
 
1571
 
1404
int overflow_exp
1572
int
1405
    PROTO_N ( ( a ) )
-
 
1406
    PROTO_T ( EXP a )
1573
overflow_exp(EXP a)
1407
{
1574
{
1408
    if ( IS_NULL_exp ( a ) ) return ( 0 ) ;
1575
	if (IS_NULL_exp(a)) {
1409
    switch ( TAG_exp ( a ) ) {
-
 
1410
	case exp_int_lit_tag : {
-
 
1411
	    /* Check integer constant expressions */
-
 
1412
	    NAT n = DEREF_nat ( exp_int_lit_nat ( a ) ) ;
-
 
1413
	    unsigned etag = DEREF_unsigned ( exp_int_lit_etag ( a ) ) ;
-
 
1414
	    switch ( etag ) {
-
 
1415
		case exp_char_lit_tag :
-
 
1416
		case exp_offset_size_tag : {
-
 
1417
		    /* These never overflow */
-
 
1418
		    return ( 0 ) ;
1576
		return (0);
1419
		}
-
 
1420
	    }
-
 
1421
	    return ( is_calc_nat ( n ) ) ;
-
 
1422
	}
-
 
1423
	case exp_identifier_tag :
-
 
1424
	case exp_member_tag :
-
 
1425
	case exp_char_lit_tag :
-
 
1426
	case exp_value_tag :
-
 
1427
	case exp_null_tag :
-
 
1428
	case exp_zero_tag : {
-
 
1429
	    return ( 0 ) ;
-
 
1430
	}
1577
	}
-
 
1578
	switch (TAG_exp(a)) {
-
 
1579
	case exp_int_lit_tag: {
-
 
1580
		/* Check integer constant expressions */
-
 
1581
		NAT n = DEREF_nat(exp_int_lit_nat(a));
-
 
1582
		unsigned etag = DEREF_unsigned(exp_int_lit_etag(a));
-
 
1583
		switch (etag) {
-
 
1584
		case exp_char_lit_tag:
-
 
1585
		case exp_offset_size_tag: {
-
 
1586
			/* These never overflow */
-
 
1587
			return (0);
-
 
1588
		}
-
 
1589
		}
-
 
1590
		return (is_calc_nat(n));
-
 
1591
	}
-
 
1592
	case exp_identifier_tag:
-
 
1593
	case exp_member_tag:
-
 
1594
	case exp_char_lit_tag:
-
 
1595
	case exp_value_tag:
-
 
1596
	case exp_null_tag:
-
 
1597
	case exp_zero_tag: {
-
 
1598
		return (0);
-
 
1599
	}
1431
	case exp_string_lit_tag : {
1600
	case exp_string_lit_tag: {
1432
	    /* String literals deliberately excluded */
1601
		/* String literals deliberately excluded */
1433
	    return ( 1 ) ;
1602
		return (1);
1434
	}
1603
	}
1435
	case exp_paren_tag :
1604
	case exp_paren_tag:
1436
	case exp_copy_tag : {
1605
	case exp_copy_tag: {
1437
	    EXP b = DEREF_exp ( exp_paren_etc_arg ( a ) ) ;
1606
		EXP b = DEREF_exp(exp_paren_etc_arg(a));
-
 
1607
		return (overflow_exp(b));
-
 
1608
	}
-
 
1609
	case exp_address_tag: {
-
 
1610
		EXP b = DEREF_exp(exp_address_arg(a));
-
 
1611
		return (overflow_exp(b));
-
 
1612
	}
-
 
1613
	case exp_address_mem_tag: {
-
 
1614
		EXP b = DEREF_exp(exp_address_mem_arg(a));
-
 
1615
		return (overflow_exp(b));
-
 
1616
	}
-
 
1617
	case exp_cast_tag: {
-
 
1618
		/* Cast expressions */
-
 
1619
		unsigned c = DEREF_unsigned(exp_cast_conv(a));
-
 
1620
		if (c == CONV_ELLIPSIS) {
-
 
1621
			EXP b = DEREF_exp(exp_cast_arg(a));
1438
	    return ( overflow_exp ( b ) ) ;
1622
			return (overflow_exp(b));
-
 
1623
		}
-
 
1624
		break;
1439
	}
1625
	}
1440
	case exp_address_tag : {
1626
	case exp_comma_tag: {
1441
	    EXP b = DEREF_exp ( exp_address_arg ( a ) ) ;
1627
		LIST(EXP)p = DEREF_list(exp_comma_args(a));
-
 
1628
		while (!IS_NULL_list(p)) {
-
 
1629
			EXP b = DEREF_exp(HEAD_list(p));
1442
	    return ( overflow_exp ( b ) ) ;
1630
			if (overflow_exp(b)) {
-
 
1631
				return (1);
-
 
1632
			}
-
 
1633
			p = TAIL_list(p);
-
 
1634
		}
-
 
1635
		return (0);
1443
	}
1636
	}
1444
	case exp_address_mem_tag : {
1637
	case exp_aggregate_tag: {
1445
	    EXP b = DEREF_exp ( exp_address_mem_arg ( a ) ) ;
1638
		LIST(EXP)p = DEREF_list(exp_aggregate_args(a));
1446
	    return ( overflow_exp ( b ) ) ;
-
 
1447
	}
-
 
1448
	case exp_cast_tag : {
1639
		while (!IS_NULL_list(p)) {
1449
	    /* Cast expressions */
-
 
1450
	    unsigned c = DEREF_unsigned ( exp_cast_conv ( a ) ) ;
1640
			EXP b = DEREF_exp(HEAD_list(p));
1451
	    if ( c == CONV_ELLIPSIS ) {
1641
			if (overflow_exp(b)) {
1452
		EXP b = DEREF_exp ( exp_cast_arg ( a ) ) ;
1642
				return (1);
-
 
1643
			}
1453
		return ( overflow_exp ( b ) ) ;
1644
			p = TAIL_list(p);
1454
	    }
1645
		}
1455
	    break ;
1646
		return (0);
1456
	}
1647
	}
1457
	case exp_comma_tag : {
1648
	case exp_nof_tag: {
1458
	    LIST ( EXP ) p = DEREF_list ( exp_comma_args ( a ) ) ;
1649
		EXP b = DEREF_exp(exp_nof_start(a));
1459
	    while ( !IS_NULL_list ( p ) ) {
1650
		EXP c = DEREF_exp(exp_nof_pad(a));
1460
		EXP b = DEREF_exp ( HEAD_list ( p ) ) ;
1651
		EXP d = DEREF_exp(exp_nof_end(a));
1461
		if ( overflow_exp ( b ) ) return ( 1 ) ;
1652
		NAT n = DEREF_nat(exp_nof_size(a));
1462
		p = TAIL_list ( p ) ;
1653
		if (overflow_exp(b)) {
1463
	    }
-
 
1464
	    return ( 0 ) ;
1654
			return (1);
1465
	}
1655
		}
1466
	case exp_aggregate_tag : {
1656
		if (overflow_exp(c)) {
1467
	    LIST ( EXP ) p = DEREF_list ( exp_aggregate_args ( a ) ) ;
-
 
1468
	    while ( !IS_NULL_list ( p ) ) {
1657
			return (1);
1469
		EXP b = DEREF_exp ( HEAD_list ( p ) ) ;
-
 
-
 
1658
		}
1470
		if ( overflow_exp ( b ) ) return ( 1 ) ;
1659
		if (overflow_exp(d)) {
1471
		p = TAIL_list ( p ) ;
1660
			return (1);
1472
	    }
1661
		}
1473
	    return ( 0 ) ;
1662
		return (is_calc_nat(n));
1474
	}
1663
	}
1475
	case exp_nof_tag : {
-
 
1476
	    EXP b = DEREF_exp ( exp_nof_start ( a ) ) ;
-
 
1477
	    EXP c = DEREF_exp ( exp_nof_pad ( a ) ) ;
-
 
1478
	    EXP d = DEREF_exp ( exp_nof_end ( a ) ) ;
-
 
1479
	    NAT n = DEREF_nat ( exp_nof_size ( a ) ) ;
-
 
1480
	    if ( overflow_exp ( b ) ) return ( 1 ) ;
-
 
1481
	    if ( overflow_exp ( c ) ) return ( 1 ) ;
-
 
1482
	    if ( overflow_exp ( d ) ) return ( 1 ) ;
-
 
1483
	    return ( is_calc_nat ( n ) ) ;
-
 
1484
	}
1664
	}
1485
    }
-
 
1486
    return ( 1 ) ;
1665
	return (1);
1487
}
1666
}
1488
 
1667
 
1489
 
1668
 
1490
/*
1669
/*
1491
    FIND THE LINKAGE OF AN EXPRESSION
1670
    FIND THE LINKAGE OF AN EXPRESSION
Line 1493... Line 1672...
1493
    This routine checks the linkage of the expression a.  If vol is true
1672
    This routine checks the linkage of the expression a.  If vol is true
1494
    then the result is or-ed with dspec_implicit if a is derived from
1673
    then the result is or-ed with dspec_implicit if a is derived from
1495
    an implicitly volatile external identifier and or-ed with dspec_pure
1674
    an implicitly volatile external identifier and or-ed with dspec_pure
1496
    if a is derived from an implicitly const string literal.  The
1675
    if a is derived from an implicitly const string literal.  The
1497
    component of a which determines the linkage is returned via pa.
1676
    component of a which determines the linkage is returned via pa.
1611
    IS AN OFFSET ZERO?
1791
    IS AN OFFSET ZERO?
1612
 
1792
 
1613
    This routine checks whether the offset off is zero.  The only
1793
    This routine checks whether the offset off is zero.  The only
1614
    non-trivial case is for base class offsets where the single
1794
    non-trivial case is for base class offsets where the single
1615
    inheritance (zero offset) cases are marked using dspec_ignore.
1795
    inheritance (zero offset) cases are marked using dspec_ignore.
1616
*/
1796
*/
1617
 
1797
 
1618
int is_zero_offset
1798
int
1619
    PROTO_N ( ( off ) )
-
 
1620
    PROTO_T ( OFFSET off )
1799
is_zero_offset(OFFSET off)
1621
{
1800
{
1622
    if ( IS_NULL_off ( off ) ) return ( 1 ) ;
1801
	if (IS_NULL_off(off)) {
-
 
1802
		return (1);
-
 
1803
	}
1623
    ASSERT ( ORDER_off == 13 ) ;
1804
	ASSERT(ORDER_off == 13);
1624
    switch ( TAG_off ( off ) ) {
1805
	switch (TAG_off(off)) {
1625
	case off_zero_tag : {
1806
	case off_zero_tag: {
1626
	    /* Zero offsets */
1807
		/* Zero offsets */
1627
	    return ( 1 ) ;
1808
		return (1);
1628
	}
1809
	}
1629
	case off_array_tag : {
1810
	case off_array_tag: {
1630
	    /* Array offsets */
1811
		/* Array offsets */
1631
	    unsigned n = DEREF_unsigned ( off_array_arg ( off ) ) ;
1812
		unsigned n = DEREF_unsigned(off_array_arg(off));
1632
	    if ( n == 0 ) return ( 1 ) ;
1813
		if (n == 0) {
-
 
1814
			return (1);
-
 
1815
		}
1633
	    break ;
1816
		break;
1634
	}
1817
	}
1635
	case off_base_tag : {
1818
	case off_base_tag: {
1636
	    /* Base class offsets */
1819
		/* Base class offsets */
1637
	    GRAPH gr = DEREF_graph ( off_base_graph ( off ) ) ;
1820
		GRAPH gr = DEREF_graph(off_base_graph(off));
1638
	    DECL_SPEC acc = DEREF_dspec ( graph_access ( gr ) ) ;
1821
		DECL_SPEC acc = DEREF_dspec(graph_access(gr));
1639
	    if ( acc & dspec_ignore ) return ( 1 ) ;
1822
		if (acc & dspec_ignore) {
-
 
1823
			return (1);
-
 
1824
		}
1640
	    break ;
1825
		break;
1641
	}
1826
	}
1642
	case off_deriv_tag : {
1827
	case off_deriv_tag: {
1643
	    /* Derived class offsets */
1828
		/* Derived class offsets */
1644
	    GRAPH gr = DEREF_graph ( off_deriv_graph ( off ) ) ;
1829
		GRAPH gr = DEREF_graph(off_deriv_graph(off));
1645
	    DECL_SPEC acc = DEREF_dspec ( graph_access ( gr ) ) ;
1830
		DECL_SPEC acc = DEREF_dspec(graph_access(gr));
1646
	    if ( acc & dspec_ignore ) return ( 1 ) ;
1831
		if (acc & dspec_ignore) {
-
 
1832
			return (1);
-
 
1833
		}
1647
	    break ;
1834
		break;
1648
	}
1835
	}
1649
	case off_negate_tag : {
1836
	case off_negate_tag: {
1650
	    /* Offset negations */
1837
		/* Offset negations */
1651
	    OFFSET a = DEREF_off ( off_negate_arg ( off ) ) ;
1838
		OFFSET a = DEREF_off(off_negate_arg(off));
1652
	    return ( is_zero_offset ( a ) ) ;
1839
		return (is_zero_offset(a));
1653
	}
1840
	}
1654
	case off_plus_tag : {
1841
	case off_plus_tag: {
1655
	    /* Offset additions */
1842
		/* Offset additions */
1656
	    OFFSET a = DEREF_off ( off_plus_arg1 ( off ) ) ;
1843
		OFFSET a = DEREF_off(off_plus_arg1(off));
1657
	    OFFSET b = DEREF_off ( off_plus_arg2 ( off ) ) ;
1844
		OFFSET b = DEREF_off(off_plus_arg2(off));
1658
	    return ( is_zero_offset ( a ) && is_zero_offset ( b ) ) ;
1845
		return (is_zero_offset(a) && is_zero_offset(b));
-
 
1846
	}
-
 
1847
	case off_mult_tag: {
-
 
1848
		/* Offset multiplications */
-
 
1849
		OFFSET a = DEREF_off(off_mult_arg1(off));
-
 
1850
		return (is_zero_offset(a));
1659
	}
1851
	}
1660
	case off_mult_tag : {
-
 
1661
	    /* Offset multiplications */
-
 
1662
	    OFFSET a = DEREF_off ( off_mult_arg1 ( off ) ) ;
-
 
1663
	    return ( is_zero_offset ( a ) ) ;
-
 
1664
	}
1852
	}
1665
    }
-
 
1666
    return ( 0 ) ;
1853
	return (0);
1667
}
1854
}
1668
 
1855
 
1669
 
1856
 
1670
/*
1857
/*
1671
    IS THE TYPE OF AN OFFSET STATICALLY DETERMINED?
1858
    IS THE TYPE OF AN OFFSET STATICALLY DETERMINED?
1672
 
1859
 
1673
    This routine checks whether the type of a pointer plus the offset off
1860
    This routine checks whether the type of a pointer plus the offset off
1674
    can be statically determined.  It returns 2 if the type is known
1861
    can be statically determined.  It returns 2 if the type is known
1675
    independent of the value of the pointer, 1 if it is known if the
1862
    independent of the value of the pointer, 1 if it is known if the
1676
    type of the pointer is known, and 0 otherwise.
1863
    type of the pointer is known, and 0 otherwise.
1677
*/
1864
*/
1678
 
1865
 
1679
static int know_offset
1866
static int
1680
    PROTO_N ( ( off ) )
-
 
1681
    PROTO_T ( OFFSET off )
1867
know_offset(OFFSET off)
1682
{
1868
{
1683
    if ( !IS_NULL_off ( off ) ) {
1869
	if (!IS_NULL_off(off)) {
1684
	switch ( TAG_off ( off ) ) {
1870
		switch (TAG_off(off)) {
1685
	    case off_base_tag :
1871
		case off_base_tag:
1686
	    case off_deriv_tag :
1872
		case off_deriv_tag:
1687
	    case off_ptr_mem_tag : {
1873
		case off_ptr_mem_tag: {
1688
		/* Base class offsets */
1874
			/* Base class offsets */
1689
		return ( 0 ) ;
1875
			return (0);
1690
	    }
1876
		}
1691
	    case off_member_tag : {
1877
		case off_member_tag: {
1692
		/* Member offsets */
1878
			/* Member offsets */
1693
		return ( 2 ) ;
1879
			return (2);
1694
	    }
1880
		}
1695
	    case off_plus_tag : {
1881
		case off_plus_tag: {
1696
		/* Check for derived member offsets */
1882
			/* Check for derived member offsets */
1697
		off = DEREF_off ( off_plus_arg2 ( off ) ) ;
1883
			off = DEREF_off(off_plus_arg2(off));
1698
		if ( IS_off_member ( off ) ) return ( 2 ) ;
1884
			if (IS_off_member(off)) {
-
 
1885
				return (2);
-
 
1886
			}
1699
		break ;
1887
			break;
-
 
1888
		}
1700
	    }
1889
		}
1701
	}
1890
	}
1702
    }
-
 
1703
    return ( 1 ) ;
1891
	return (1);
1704
}
1892
}
1705
 
1893
 
1706
 
1894
 
1707
/*
1895
/*
1708
    IS THE TYPE OF AN EXPRESSION STATICALLY DETERMINED?
1896
    IS THE TYPE OF AN EXPRESSION STATICALLY DETERMINED?
1709
 
1897
 
1710
    This routine checks whether the expression of class type or pointer to
1898
    This routine checks whether the expression of class type or pointer to
1711
    class type, e, is derived from an object so that its type can be
1899
    class type, e, is derived from an object so that its type can be
1712
    statically determined.  It is used to check whether the virtual call
1900
    statically determined.  It is used to check whether the virtual call
1713
    mechanism and virtual base class conversions can be bypassed for e.
1901
    mechanism and virtual base class conversions can be bypassed for e.
1714
    A value of 2 is returned for non-obvious known types.
1902
    A value of 2 is returned for non-obvious known types.
1715
*/
1903
*/
1716
 
1904
 
1717
int know_type
1905
int
1718
    PROTO_N ( ( e ) )
-
 
1719
    PROTO_T ( EXP e )
1906
know_type(EXP e)
1720
{
1907
{
1721
    if ( !IS_NULL_exp ( e ) ) {
1908
	if (!IS_NULL_exp(e)) {
1722
	unsigned tag = TAG_exp ( e ) ;
1909
		unsigned tag = TAG_exp(e);
1723
	switch ( tag ) {
1910
		switch (tag) {
1724
	    case exp_address_tag : {
1911
		case exp_address_tag: {
1725
		EXP a = DEREF_exp ( exp_address_arg ( e ) ) ;
1912
			EXP a = DEREF_exp(exp_address_arg(e));
1726
		tag = TAG_exp ( a ) ;
1913
			tag = TAG_exp(a);
1727
		if ( tag == exp_identifier_tag ) {
1914
			if (tag == exp_identifier_tag) {
1728
		    return ( 1 ) ;
1915
				return (1);
1729
		}
1916
			}
1730
		if ( tag == exp_indir_tag ) {
1917
			if (tag == exp_indir_tag) {
1731
		    EXP b = DEREF_exp ( exp_indir_ptr ( a ) ) ;
1918
				EXP b = DEREF_exp(exp_indir_ptr(a));
1732
		    return ( know_type ( b ) ) ;
1919
				return (know_type(b));
-
 
1920
			}
-
 
1921
			if (tag == exp_dummy_tag) {
-
 
1922
				EXP b = DEREF_exp(exp_dummy_value(a));
-
 
1923
				if (IS_NULL_exp(b)) {
-
 
1924
					int v = DEREF_int(exp_dummy_virt(a));
-
 
1925
					if (!v) {
-
 
1926
						return (1);
-
 
1927
					}
-
 
1928
				}
-
 
1929
			}
-
 
1930
			break;
1733
		}
1931
		}
1734
		if ( tag == exp_dummy_tag ) {
1932
		case exp_indir_tag: {
1735
		    EXP b = DEREF_exp ( exp_dummy_value ( a ) ) ;
1933
			EXP a = DEREF_exp(exp_indir_ptr(e));
1736
		    if ( IS_NULL_exp ( b ) ) {
-
 
1737
			int v = DEREF_int ( exp_dummy_virt ( a ) ) ;
-
 
1738
			if ( !v ) return ( 1 ) ;
1934
			return (know_type(a));
1739
		    }
-
 
1740
		}
1935
		}
1741
		break ;
-
 
1742
	    }
-
 
1743
	    case exp_indir_tag : {
1936
		case exp_add_ptr_tag: {
1744
		EXP a = DEREF_exp ( exp_indir_ptr ( e ) ) ;
1937
			OFFSET off = DEREF_off(exp_add_ptr_off(e));
1745
		return ( know_type ( a ) ) ;
1938
			int k = know_offset(off);
-
 
1939
			if (k == 2) {
-
 
1940
				return (1);
1746
	    }
1941
			}
1747
	    case exp_add_ptr_tag : {
1942
			if (k == 1) {
1748
		OFFSET off = DEREF_off ( exp_add_ptr_off ( e ) ) ;
1943
				EXP a = DEREF_exp(exp_add_ptr_ptr(e));
1749
		int k = know_offset ( off ) ;
1944
				return (know_type(a));
1750
		if ( k == 2 ) {
1945
			}
1751
		    return ( 1 ) ;
1946
			break;
1752
		}
1947
		}
1753
		if ( k == 1 ) {
1948
		case exp_contents_tag: {
1754
		    EXP a = DEREF_exp ( exp_add_ptr_ptr ( e ) ) ;
1949
			e = DEREF_exp(exp_contents_ptr(e));
1755
		    return ( know_type ( a ) ) ;
1950
			if (IS_exp_identifier(e)) {
-
 
1951
				goto identifier_lab;
-
 
1952
			}
-
 
1953
			break;
1756
		}
1954
		}
1757
		break ;
-
 
1758
	    }
-
 
1759
	    case exp_contents_tag : {
-
 
1760
		e = DEREF_exp ( exp_contents_ptr ( e ) ) ;
-
 
1761
		if ( IS_exp_identifier ( e ) ) goto identifier_lab ;
-
 
1762
		break ;
-
 
1763
	    }
-
 
1764
	    case exp_identifier_tag :
1955
		case exp_identifier_tag:
1765
	    identifier_lab : {
1956
identifier_lab: {
1766
		IDENTIFIER id = DEREF_id ( exp_identifier_id ( e ) ) ;
1957
			 IDENTIFIER id = DEREF_id(exp_identifier_id(e));
1767
		HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
1958
			 HASHID nm = DEREF_hashid(id_name(id));
1768
		if ( EQ_KEYWORD ( nm, lex_this_Hname ) ) {
1959
			 if (EQ_KEYWORD(nm, lex_this_Hname)) {
1769
		    /* A 'this' expression */
1960
				 /* A 'this' expression */
1770
		    NAMESPACE ns = DEREF_nspace ( id_parent ( id ) ) ;
1961
				 NAMESPACE ns = DEREF_nspace(id_parent(id));
1771
		    id = DEREF_id ( nspace_name ( ns ) ) ;
1962
				 id = DEREF_id(nspace_name(ns));
1772
		    nm = DEREF_hashid ( id_name ( id ) ) ;
1963
				 nm = DEREF_hashid(id_name(id));
1773
		    if ( IS_hashid_constr ( nm ) ) {
1964
				 if (IS_hashid_constr(nm)) {
1774
			/* Function is a constructor */
1965
					 /* Function is a constructor */
1775
			return ( 2 ) ;
1966
					 return (2);
1776
		    }
1967
				 }
1777
		    if ( IS_hashid_destr ( nm ) ) {
1968
				 if (IS_hashid_destr(nm)) {
1778
			/* Function is a destructor */
1969
					 /* Function is a destructor */
1779
			return ( 2 ) ;
1970
					 return (2);
1780
		    }
1971
				 }
-
 
1972
			 }
-
 
1973
			 break;
-
 
1974
		 }
1781
		}
1975
		}
1782
		break ;
-
 
1783
	    }
-
 
1784
	}
1976
	}
1785
    }
-
 
1786
    return ( 0 ) ;
1977
	return (0);
1787
}
1978
}