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 – /branches/tendra5/src/producers/common/construct/destroy.c – Rev 5 and 6

Subversion Repositories tendra.SVN

Rev

Rev 5 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5 Rev 6
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
*/
29
 
59
 
30
 
60
 
31
#include "config.h"
61
#include "config.h"
32
#include "c_types.h"
62
#include "c_types.h"
33
#include "exp_ops.h"
63
#include "exp_ops.h"
34
#include "id_ops.h"
64
#include "id_ops.h"
35
#include "member_ops.h"
65
#include "member_ops.h"
Line 38... Line 68...
38
#include "type_ops.h"
68
#include "type_ops.h"
39
#include "error.h"
69
#include "error.h"
40
#include "destroy.h"
70
#include "destroy.h"
41
#include "exception.h"
71
#include "exception.h"
42
#include "macro.h"
72
#include "macro.h"
43
 
73
 
44
 
74
 
45
/*
75
/*
46
    FREE A LOCAL IDENTIFIER
76
    FREE A LOCAL IDENTIFIER
47
 
77
 
48
    This routine frees the local identifier id.
78
    This routine frees the local identifier id.
49
*/
79
*/
50
 
80
 
51
static void free_id
81
static void
52
    PROTO_N ( ( id, force ) )
-
 
53
    PROTO_T ( IDENTIFIER id X int force )
82
free_id(IDENTIFIER id, int force)
54
{
83
{
55
    if ( IS_NULL_id ( id ) ) return ;
84
	if (IS_NULL_id(id)) {
-
 
85
		return;
-
 
86
	}
56
    switch ( TAG_id ( id ) ) {
87
	switch (TAG_id(id)) {
57
	case id_variable_tag : {
88
	case id_variable_tag: {
58
	    DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
89
		DECL_SPEC ds = DEREF_dspec(id_storage(id));
59
	    if ( ds & dspec_auto ) {
90
		if (ds & dspec_auto) {
60
		EXP e = DEREF_exp ( id_variable_init ( id ) ) ;
91
			EXP e = DEREF_exp(id_variable_init(id));
61
		EXP d = DEREF_exp ( id_variable_term ( id ) ) ;
92
			EXP d = DEREF_exp(id_variable_term(id));
62
		if ( !IS_NULL_exp ( e ) ) free_exp ( e, force ) ;
93
			if (!IS_NULL_exp(e)) {
-
 
94
				free_exp(e, force);
-
 
95
			}
63
		if ( !IS_NULL_exp ( d ) ) free_exp ( d, force ) ;
96
			if (!IS_NULL_exp(d)) {
-
 
97
				free_exp(d, force);
-
 
98
			}
64
		COPY_exp ( id_variable_init ( id ), NULL_exp ) ;
99
			COPY_exp(id_variable_init(id), NULL_exp);
65
		COPY_exp ( id_variable_term ( id ), NULL_exp ) ;
100
			COPY_exp(id_variable_term(id), NULL_exp);
66
	    }
101
		}
67
	    break ;
102
		break;
68
	}
103
	}
69
	case id_label_tag : {
104
	case id_label_tag: {
70
	    LIST ( VARIABLE ) v = DEREF_list ( id_label_vars ( id ) ) ;
105
		LIST(VARIABLE)v = DEREF_list(id_label_vars(id));
71
	    DESTROY_list ( v, SIZE_var ) ;
106
		DESTROY_list(v, SIZE_var);
72
	    COPY_list ( id_label_vars ( id ), NULL_list ( VARIABLE ) ) ;
107
		COPY_list(id_label_vars(id), NULL_list(VARIABLE));
73
	    COPY_exp ( id_label_stmt ( id ), NULL_exp ) ;
108
		COPY_exp(id_label_stmt(id), NULL_exp);
74
	    COPY_exp ( id_label_gotos ( id ), NULL_exp ) ;
109
		COPY_exp(id_label_gotos(id), NULL_exp);
75
	    break ;
110
		break;
76
	}
111
	}
77
    }
112
	}
78
    return ;
113
	return;
79
}
114
}
80
 
115
 
81
 
116
 
82
/*
117
/*
83
    FREE A NAMESPACE
118
    FREE A NAMESPACE
84
 
119
 
85
    This routine frees the block namespace ns.
120
    This routine frees the block namespace ns.
86
*/
121
*/
87
 
122
 
88
void free_nspace
123
void
89
    PROTO_N ( ( ns ) )
-
 
90
    PROTO_T ( NAMESPACE ns )
124
free_nspace(NAMESPACE ns)
91
{
125
{
92
    if ( !IS_NULL_nspace ( ns ) ) {
126
	if (!IS_NULL_nspace(ns)) {
93
	MEMBER mem = DEREF_member ( nspace_last ( ns ) ) ;
127
		MEMBER mem = DEREF_member(nspace_last(ns));
94
	while ( !IS_NULL_member ( mem ) ) {
128
		while (!IS_NULL_member(mem)) {
95
	    IDENTIFIER id ;
129
			IDENTIFIER id;
96
	    IDENTIFIER alt ;
130
			IDENTIFIER alt;
97
	    DESTROY_member_small ( destroy, id, alt, mem, mem ) ;
131
			DESTROY_member_small(destroy, id, alt, mem, mem);
98
	    UNUSED ( id ) ;
132
			UNUSED(id);
99
	    UNUSED ( alt ) ;
133
			UNUSED(alt);
-
 
134
		}
-
 
135
		COPY_member(nspace_last(ns), NULL_member);
-
 
136
		COPY_member(nspace_prev(ns), NULL_member);
100
	}
137
	}
101
	COPY_member ( nspace_last ( ns ), NULL_member ) ;
-
 
102
	COPY_member ( nspace_prev ( ns ), NULL_member ) ;
-
 
103
    }
-
 
104
    return ;
138
	return;
105
}
139
}
106
 
140
 
107
 
141
 
108
/*
142
/*
109
    FREE AN OFFSET
143
    FREE AN OFFSET
110
 
144
 
111
    This routine frees the offset off.  Note that member and base offsets
145
    This routine frees the offset off.  Note that member and base offsets
112
    are linked directly to the classes they represent and so are not
146
    are linked directly to the classes they represent and so are not
113
    destroyed here.
147
    destroyed here.
114
*/
148
*/
115
 
149
 
116
void free_offset
150
void
117
    PROTO_N ( ( off, force ) )
-
 
118
    PROTO_T ( OFFSET off X int force )
151
free_offset(OFFSET off, int force)
119
{
152
{
120
    if ( IS_NULL_off ( off ) ) return ;
153
	if (IS_NULL_off(off)) {
-
 
154
		return;
-
 
155
	}
121
    ASSERT ( ORDER_off == 13 ) ;
156
	ASSERT(ORDER_off == 13);
122
    switch ( TAG_off ( off ) ) {
157
	switch (TAG_off(off)) {
123
	case off_zero_tag : {
158
	case off_zero_tag: {
124
	    TYPE t ;
159
		TYPE t;
125
	    DESTROY_off_zero ( destroy, t, off ) ;
160
		DESTROY_off_zero(destroy, t, off);
126
	    UNUSED ( t ) ;
161
		UNUSED(t);
127
	    break ;
162
		break;
128
	}
163
	}
129
	case off_type_tag : {
164
	case off_type_tag: {
130
	    TYPE t ;
165
		TYPE t;
131
	    DESTROY_off_type ( destroy, t, off ) ;
166
		DESTROY_off_type(destroy, t, off);
132
	    UNUSED ( t ) ;
167
		UNUSED(t);
133
	    break ;
168
		break;
134
	}
169
	}
135
	case off_extra_tag : {
170
	case off_extra_tag: {
136
	    int n ;
171
		int n;
137
	    TYPE t ;
172
		TYPE t;
138
	    DESTROY_off_extra ( destroy, t, n, off ) ;
173
		DESTROY_off_extra(destroy, t, n, off);
139
	    UNUSED ( n ) ;
174
		UNUSED(n);
140
	    UNUSED ( t ) ;
175
		UNUSED(t);
141
	    break ;
176
		break;
142
	}
177
	}
143
	case off_array_tag : {
178
	case off_array_tag: {
144
	    TYPE t ;
179
		TYPE t;
145
	    unsigned n ;
180
		unsigned n;
146
	    DESTROY_off_array ( destroy, t, n, off ) ;
181
		DESTROY_off_array(destroy, t, n, off);
147
	    UNUSED ( n ) ;
182
		UNUSED(n);
148
	    UNUSED ( t ) ;
183
		UNUSED(t);
149
	    break ;
184
		break;
150
	}
185
	}
151
	case off_ptr_mem_tag : {
186
	case off_ptr_mem_tag: {
152
	    EXP a ;
187
		EXP a;
153
	    DESTROY_off_ptr_mem ( destroy, a, off ) ;
188
		DESTROY_off_ptr_mem(destroy, a, off);
154
	    free_exp ( a, force ) ;
189
		free_exp(a, force);
155
	    break ;
-
 
156
	}
-
 
157
	case off_negate_tag : {
-
 
158
	    OFFSET a ;
-
 
159
	    DESTROY_off_negate ( destroy, a, off ) ;
-
 
160
	    free_offset ( a, force ) ;
-
 
161
	    break ;
190
		break;
162
	}
191
	}
163
	case off_mult_tag : {
192
	case off_negate_tag: {
164
	    EXP b ;
-
 
165
	    OFFSET a ;
193
		OFFSET a;
166
	    DESTROY_off_mult ( destroy, a, b, off ) ;
194
		DESTROY_off_negate(destroy, a, off);
167
	    free_offset ( a, force ) ;
195
		free_offset(a, force);
168
	    free_exp ( b, force ) ;
-
 
169
	    break ;
196
		break;
170
	}
197
	}
171
	case off_ptr_diff_tag : {
198
	case off_mult_tag: {
172
	    EXP a, b ;
199
		EXP b;
-
 
200
		OFFSET a;
173
	    DESTROY_off_ptr_diff ( destroy, a, b, off ) ;
201
		DESTROY_off_mult(destroy, a, b, off);
174
	    free_exp ( a, force ) ;
202
		free_offset(a, force);
175
	    free_exp ( b, force ) ;
203
		free_exp(b, force);
176
	    break ;
204
		break;
177
	}
205
	}
178
	case off_base_tag :
206
	case off_ptr_diff_tag: {
179
	case off_deriv_tag :
207
		EXP a, b;
180
	case off_member_tag :
208
		DESTROY_off_ptr_diff(destroy, a, b, off);
181
	case off_plus_tag :
209
		free_exp(a, force);
182
	case off_token_tag : {
210
		free_exp(b, force);
183
	    /* Don't free these cases */
-
 
184
	    break ;
211
		break;
185
	}
212
	}
-
 
213
	case off_base_tag:
-
 
214
	case off_deriv_tag:
-
 
215
	case off_member_tag:
-
 
216
	case off_plus_tag:
-
 
217
	case off_token_tag: {
-
 
218
		/* Don't free these cases */
-
 
219
		break;
-
 
220
	}
186
    }
221
	}
187
    return ;
222
	return;
188
}
223
}
189
 
224
 
190
 
225
 
191
/*
226
/*
192
    DESTROY A LIST OF EXPRESSIONS
227
    DESTROY A LIST OF EXPRESSIONS
193
 
228
 
194
    This routine frees the list of expressions p.
229
    This routine frees the list of expressions p.
195
*/
230
*/
196
 
231
 
197
void free_exp_list
232
void
198
    PROTO_N ( ( p, force ) )
-
 
199
    PROTO_T ( LIST ( EXP ) p X int force )
233
free_exp_list(LIST(EXP)p, int force)
200
{
234
{
201
    while ( !IS_NULL_list ( p ) ) {
235
	while (!IS_NULL_list(p)) {
202
	EXP e ;
236
		EXP e;
203
	DESTROY_CONS_exp ( destroy, e, p, p ) ;
237
		DESTROY_CONS_exp(destroy, e, p, p);
204
	free_exp ( e, force ) ;
238
		free_exp(e, force);
205
    }
239
	}
206
    return ;
240
	return;
207
}
241
}
208
 
242
 
209
 
243
 
210
/*
244
/*
211
    FREE AN EXPRESSION
245
    FREE AN EXPRESSION
212
 
246
 
213
    This routine frees the expression e.  It is possible for the same
247
    This routine frees the expression e.  It is possible for the same
214
    sub-expression to be reused twice in an expression, so freed expressions
248
    sub-expression to be reused twice in an expression, so freed expressions
215
    are marked by having their type set to the rule type.  This exploits
249
    are marked by having their type set to the rule type.  This exploits
216
    some knowledge about about how destroy_c_class works.
250
    some knowledge about about how destroy_c_class works.
800
	}
848
	}
801
	case exp_token_tag : {
849
	case exp_dummy_tag: {
-
 
850
		int v;
-
 
851
		ulong n;
802
	    IDENTIFIER id ;
852
		int cnt;
803
	    LIST ( TOKEN ) p ;
853
		OFFSET off;
804
	    DESTROY_exp_token ( destroy, t, a, id, p, e ) ;
854
		DESTROY_exp_dummy(destroy, t, a, n, off, v, cnt, e);
-
 
855
		free_exp(a, force1);
-
 
856
		free_offset(off, force1);
805
	    UNUSED ( id ) ;
857
		UNUSED(cnt);
806
	    UNUSED ( p ) ;
858
		UNUSED(n);
807
	    UNUSED ( a ) ;
859
		UNUSED(v);
808
	    break ;
860
		break;
809
	}
861
	}
810
	case exp_dummy_tag : {
-
 
811
	    int v ;
-
 
812
	    ulong n ;
-
 
813
	    int cnt ;
-
 
814
	    OFFSET off ;
-
 
815
	    DESTROY_exp_dummy ( destroy, t, a, n, off, v, cnt, e ) ;
-
 
816
	    free_exp ( a, force1 ) ;
-
 
817
	    free_offset ( off, force1 ) ;
-
 
818
	    UNUSED ( cnt ) ;
-
 
819
	    UNUSED ( n ) ;
-
 
820
	    UNUSED ( v ) ;
-
 
821
	    break ;
-
 
822
	}
862
	}
823
    }
-
 
824
    UNUSED ( t ) ;
863
	UNUSED(t);
825
    return ;
864
	return;
826
}
865
}
827
 
866
 
828
 
867
 
829
/*
868
/*
830
    FREE A FUNCTION DEFINITION
869
    FREE A FUNCTION DEFINITION
831
 
870
 
832
    This routine frees the definition of the function id, replacing it
871
    This routine frees the definition of the function id, replacing it
833
    by a dummy definition.
872
    by a dummy definition.
834
*/
873
*/
835
 
874
 
836
void free_function
875
void
837
    PROTO_N ( ( id ) )
-
 
838
    PROTO_T ( IDENTIFIER id )
876
free_function(IDENTIFIER id)
839
{
877
{
840
    EXP e = DEREF_exp ( id_function_etc_defn ( id ) ) ;
878
	EXP e = DEREF_exp(id_function_etc_defn(id));
841
    if ( !IS_NULL_exp ( e ) ) {
879
	if (!IS_NULL_exp(e)) {
842
	TYPE t = DEREF_type ( id_function_etc_type ( id ) ) ;
880
		TYPE t = DEREF_type(id_function_etc_type(id));
843
	free_exp ( e, 0 ) ;
881
		free_exp(e, 0);
844
	MAKE_exp_value ( t, e ) ;
882
		MAKE_exp_value(t, e);
845
	COPY_exp ( id_function_etc_defn ( id ), e ) ;
883
		COPY_exp(id_function_etc_defn(id), e);
846
    }
884
	}
847
    return ;
885
	return;
848
}
886
}