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-2005 The TenDRA Project <http://www.tendra.org/>.
-
 
3
 * All rights reserved.
-
 
4
 *
-
 
5
 * Redistribution and use in source and binary forms, with or without
-
 
6
 * modification, are permitted provided that the following conditions are met:
-
 
7
 *
-
 
8
 * 1. Redistributions of source code must retain the above copyright notice,
-
 
9
 *    this list of conditions and the following disclaimer.
-
 
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
-
 
11
 *    this list of conditions and the following disclaimer in the documentation
-
 
12
 *    and/or other materials provided with the distribution.
-
 
13
 * 3. Neither the name of The TenDRA Project nor the names of its contributors
-
 
14
 *    may be used to endorse or promote products derived from this software
-
 
15
 *    without specific, prior written permission.
-
 
16
 *
-
 
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
-
 
18
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-
 
19
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-
 
20
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
-
 
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-
 
22
 * EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-
 
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-
 
24
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-
 
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-
 
26
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-
 
27
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
28
 *
-
 
29
 * $Id$
-
 
30
 */
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 57... Line 87...
57
#include "action.h"
87
#include "action.h"
58
#include "types.h"
88
#include "types.h"
59
 
89
 
60
/*--------------------------------------------------------------------------*/
90
/*--------------------------------------------------------------------------*/
61
 
91
 
62
static void			rule_compute_mutations_3
92
static void			rule_compute_mutations_3(EntryP, GenericP);
63
	PROTO_S ((EntryP, GenericP));
-
 
64
 
93
 
65
static void
94
static void
66
rule_compute_mutations_4 PROTO_N ((rule, alt, from_rule))
95
rule_compute_mutations_4(RuleP rule, AltP alt, RuleP from_rule)
67
			 PROTO_T (RuleP rule X
-
 
68
				  AltP  alt X
-
 
69
				  RuleP from_rule)
-
 
70
{
96
{
71
    BoolT  propogate = FALSE;
97
    BoolT  propogate = FALSE;
72
    ItemP  item;
98
    ItemP  item;
73
 
99
 
74
    for (item = alt_item_head (alt); item; item = item_next (item)) {
100
    for (item = alt_item_head(alt); item; item = item_next(item)) {
75
	switch (item_type (item)) EXHAUSTIVE {
101
	switch (item_type(item))EXHAUSTIVE {
76
	  case ET_RULE:
102
	  case ET_RULE:
77
	    if (entry_get_rule (item_entry (item)) == from_rule) {
103
	    if (entry_get_rule(item_entry(item)) == from_rule) {
78
		if (types_compute_mutations (rule_param (rule),
104
		if (types_compute_mutations(rule_param(rule),
79
					     item_param (item),
105
					    item_param(item),
80
					     rule_param (from_rule))) {
106
					    rule_param(from_rule))) {
81
		    propogate = TRUE;
107
		    propogate = TRUE;
82
		}
108
		}
83
	    }
109
	    }
84
	    break;
110
	    break;
85
	  case ET_ACTION:
111
	  case ET_ACTION:
Line 92... Line 118...
92
	  case ET_NAME:
118
	  case ET_NAME:
93
	    UNREACHED;
119
	    UNREACHED;
94
	}
120
	}
95
    }
121
    }
96
    if (propogate) {
122
    if (propogate) {
97
	entry_list_iter (rule_reverse_list (rule), rule_compute_mutations_3,
123
	entry_list_iter(rule_reverse_list(rule), rule_compute_mutations_3,
98
			 (GenericP) rule);
124
			(GenericP)rule);
99
    }
125
    }
100
}
126
}
101
 
127
 
102
static void
128
static void
103
rule_compute_mutations_3 PROTO_N ((entry, gclosure))
129
rule_compute_mutations_3(EntryP entry, GenericP gclosure)
104
			 PROTO_T (EntryP   entry X
-
 
105
				  GenericP gclosure)
-
 
106
{
130
{
107
    RuleP rule      = entry_get_rule (entry);
131
    RuleP rule      = entry_get_rule(entry);
108
    RuleP from_rule = (RuleP) gclosure;
132
    RuleP from_rule = (RuleP)gclosure;
109
    AltP  alt;
133
    AltP  alt;
110
 
134
 
111
    if ((alt = rule_get_handler (rule)) != NIL (AltP)) {
135
    if ((alt = rule_get_handler(rule)) != NIL(AltP)) {
112
	rule_compute_mutations_4 (rule, alt, from_rule);
136
	rule_compute_mutations_4(rule, alt, from_rule);
113
    }
137
    }
114
    for (alt = rule_alt_head (rule); alt; alt = alt_next (alt)) {
138
    for (alt = rule_alt_head(rule); alt; alt = alt_next(alt)) {
115
	rule_compute_mutations_4 (rule, alt, from_rule);
139
	rule_compute_mutations_4(rule, alt, from_rule);
116
    }
140
    }
117
}
141
}
118
 
142
 
119
static void
143
static void
120
rule_compute_mutations_2 PROTO_N ((rule, alt))
144
rule_compute_mutations_2(RuleP rule, AltP alt)
121
			 PROTO_T (RuleP rule X
-
 
122
				  AltP  alt)
-
 
123
{
145
{
124
    BoolT   propogate = FALSE;
146
    BoolT   propogate = FALSE;
125
    ItemP   item;
147
    ItemP   item;
126
    ActionP action;
148
    ActionP action;
127
 
149
 
128
    for (item = alt_item_head (alt); item; item = item_next (item)) {
150
    for (item = alt_item_head(alt); item; item = item_next(item)) {
129
	switch (item_type (item)) EXHAUSTIVE {
151
	switch (item_type(item))EXHAUSTIVE {
130
	  case ET_ACTION:
152
	  case ET_ACTION:
131
	  case ET_PREDICATE:
153
	  case ET_PREDICATE:
132
	    action = entry_get_action (item_entry (item));
154
	    action = entry_get_action(item_entry(item));
133
	    if (types_compute_mutations (rule_param (rule), item_param (item),
155
	    if (types_compute_mutations(rule_param(rule), item_param(item),
134
					 action_param (action))) {
156
					action_param(action))) {
135
		propogate = TRUE;
157
		propogate = TRUE;
136
	    }
158
	    }
137
	    break;
159
	    break;
138
	  case ET_RENAME:
160
	  case ET_RENAME:
139
	  case ET_BASIC:
161
	  case ET_BASIC:
Line 142... Line 164...
142
	  case ET_NON_LOCAL:
164
	  case ET_NON_LOCAL:
143
	  case ET_TYPE:
165
	  case ET_TYPE:
144
	  case ET_NAME:
166
	  case ET_NAME:
145
	    UNREACHED;
167
	    UNREACHED;
146
	}
168
	}
147
	if (types_compute_assign_mutations (rule_param (rule),
169
	if (types_compute_assign_mutations(rule_param(rule),
148
					    item_param (item))) {
170
					   item_param(item))) {
149
	    propogate = TRUE;
171
	    propogate = TRUE;
150
	}
172
	}
151
    }
173
    }
152
    if (propogate) {
174
    if (propogate) {
153
	entry_list_iter (rule_reverse_list (rule), rule_compute_mutations_3,
175
	entry_list_iter(rule_reverse_list(rule), rule_compute_mutations_3,
154
			 (GenericP) rule);
176
			(GenericP)rule);
155
    }
177
    }
156
}
178
}
157
 
179
 
158
static void
180
static void
159
rule_compute_mutations_1 PROTO_N ((rule))
181
rule_compute_mutations_1(RuleP rule)
160
			 PROTO_T (RuleP rule)
-
 
161
{
182
{
162
    AltP alt;
183
    AltP alt;
163
 
184
 
164
    if ((alt = rule_get_handler (rule)) != NIL (AltP)) {
185
    if ((alt = rule_get_handler(rule)) != NIL(AltP)) {
165
	rule_compute_mutations_2 (rule, alt);
186
	rule_compute_mutations_2(rule, alt);
166
    }
187
    }
167
    for (alt = rule_alt_head (rule); alt; alt = alt_next (alt)) {
188
    for (alt = rule_alt_head(rule); alt; alt = alt_next(alt)) {
168
	rule_compute_mutations_2 (rule, alt);
189
	rule_compute_mutations_2(rule, alt);
169
    }
190
    }
170
}
191
}
171
 
192
 
172
/*--------------------------------------------------------------------------*/
193
/*--------------------------------------------------------------------------*/
173
 
194
 
174
void
195
void
175
rule_compute_mutations PROTO_N ((entry, gclosure))
196
rule_compute_mutations(EntryP entry, GenericP gclosure)
176
		       PROTO_T (EntryP   entry X
-
 
177
				GenericP gclosure)
-
 
178
{
197
{
179
    UNUSED (gclosure);
198
    UNUSED(gclosure);
180
    if (entry_is_rule (entry)) {
199
    if (entry_is_rule(entry)) {
181
	RuleP rule = entry_get_rule (entry);
200
	RuleP rule = entry_get_rule(entry);
182
 
201
 
183
	rule_compute_mutations_1 (rule);
202
	rule_compute_mutations_1(rule);
184
    }
203
    }
185
}
204
}
186

205

187
/*
206
/*
188
 * Local variables(smf):
207
 * Local variables(smf):