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-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 74... Line 104...
74
#include "table.h"
104
#include "table.h"
75
 
105
 
76
/*--------------------------------------------------------------------------*/
106
/*--------------------------------------------------------------------------*/
77
 
107
 
78
void
108
void
79
rule_compute_first_set_1 PROTO_N ((rule))
109
rule_compute_first_set_1(RuleP rule)
80
			 PROTO_T (RuleP rule)
-
 
81
{
110
{
82
    AltP     alt;
111
    AltP     alt;
83
    unsigned priority = 0;
112
    unsigned priority = 0;
84
 
113
 
85
    if (rule_has_computed_first_set (rule)) {
114
    if (rule_has_computed_first_set(rule)) {
86
	return;
115
	return;
87
    } else if (rule_is_computing_first_set (rule)) {
116
    } else if (rule_is_computing_first_set(rule)) {
88
	E_cannot_compute_first_set (rule);
117
	E_cannot_compute_first_set(rule);
89
	return;
118
	return;
90
    }
119
    }
91
    rule_computing_first_set (rule);
120
    rule_computing_first_set(rule);
92
    for (alt = rule_alt_head (rule); alt; alt = alt_next (alt)) {
121
    for (alt = rule_alt_head(rule); alt; alt = alt_next(alt)) {
93
	BoolT see_through = TRUE;
122
	BoolT see_through = TRUE;
94
	BoolT no_action   = TRUE;
123
	BoolT no_action   = TRUE;
95
	ItemP item        = alt_item_head (alt);
124
	ItemP item        = alt_item_head(alt);
96
	ItemP initial     = item;
125
	ItemP initial     = item;
97
 
126
 
98
	for (; see_through && (item != NIL (ItemP)); item = item_next (item)) {
127
	for (; see_through && (item != NIL(ItemP)); item = item_next(item)) {
99
	    switch (item_type (item)) EXHAUSTIVE {
128
	    switch (item_type(item))EXHAUSTIVE {
100
	      case ET_PREDICATE:
129
	      case ET_PREDICATE:
101
		if (item != initial) {
130
		if (item != initial) {
102
		    E_see_to_predicate (entry_key (item_entry (item)), rule);
131
		    E_see_to_predicate(entry_key(item_entry(item)), rule);
103
		}
132
		}
104
		entry_list_add_if_missing (rule_predicate_first (rule),
133
		entry_list_add_if_missing(rule_predicate_first(rule),
105
					   item_entry (item));
134
					  item_entry(item));
106
		see_through = FALSE;
135
		see_through = FALSE;
107
		break;
136
		break;
108
	      case ET_RENAME:
137
	      case ET_RENAME:
109
	      case ET_ACTION:
138
	      case ET_ACTION:
110
		no_action = FALSE;
139
		no_action = FALSE;
111
		break;
140
		break;
112
	      case ET_RULE: {
141
	      case ET_RULE: {
113
		  EntryP     entry      = item_entry (item);
142
		  EntryP     entry      = item_entry(item);
114
		  RuleP      item_rule  = entry_get_rule (entry);
143
		  RuleP      item_rule  = entry_get_rule(entry);
115
		  EntryListP pred_first = rule_predicate_first (item_rule);
144
		  EntryListP pred_first = rule_predicate_first(item_rule);
116
		  unsigned   item_priority;
145
		  unsigned   item_priority;
117
 
146
 
118
		  rule_compute_first_set_1 (item_rule);
147
		  rule_compute_first_set_1(item_rule);
119
		  if ((item != initial) &&
148
		  if ((item != initial) &&
120
		      (!entry_list_is_empty (pred_first))) {
149
		     (!entry_list_is_empty(pred_first))) {
121
		      E_see_to_rule_predicate (item_rule, rule);
150
		      E_see_to_rule_predicate(item_rule, rule);
122
		  }
151
		  }
123
		  bitvec_or (rule_first_set (rule),
152
		  bitvec_or(rule_first_set(rule), rule_first_set(item_rule));
124
			     rule_first_set (item_rule));
-
 
125
		  entry_list_append (rule_predicate_first (rule), pred_first);
153
		  entry_list_append(rule_predicate_first(rule), pred_first);
126
		  see_through   = rule_is_see_through (item_rule);
154
		  see_through   = rule_is_see_through(item_rule);
127
		  item_priority = rule_get_priority (item_rule);
155
		  item_priority = rule_get_priority(item_rule);
128
		  if ((item_priority > priority) && no_action) {
156
		  if ((item_priority > priority) && no_action) {
129
		      priority = item_priority;
157
		      priority = item_priority;
130
		  }
158
		  }
131
	      }
159
	      }
132
		break;
160
		break;
133
	      case ET_BASIC: {
161
	      case ET_BASIC: {
134
		  BasicP basic = entry_get_basic (item_entry (item));
162
		  BasicP basic = entry_get_basic(item_entry(item));
135
 
163
 
136
		  bitvec_set (rule_first_set (rule), basic_terminal (basic));
164
		  bitvec_set(rule_first_set(rule), basic_terminal(basic));
137
		  see_through = FALSE;
165
		  see_through = FALSE;
138
	      }
166
	      }
139
		break;
167
		break;
140
	      case ET_NON_LOCAL:
168
	      case ET_NON_LOCAL:
141
	      case ET_NAME:
169
	      case ET_NAME:
142
	      case ET_TYPE:
170
	      case ET_TYPE:
143
		UNREACHED;
171
		UNREACHED;
144
	    }
172
	    }
145
	}
173
	}
146
	if (see_through) {
174
	if (see_through) {
147
	    rule_see_through (rule);
175
	    rule_see_through(rule);
148
	}
176
	}
149
    }
177
    }
150
    if (rule_has_empty_alt (rule)) {
178
    if (rule_has_empty_alt(rule)) {
151
	rule_see_through (rule);
179
	rule_see_through(rule);
152
    }
180
    }
153
    rule_set_priority (rule, priority + 1);
181
    rule_set_priority(rule, priority + 1);
154
    if (rule_is_see_through (rule) && bitvec_is_full (rule_first_set (rule))) {
182
    if (rule_is_see_through(rule) && bitvec_is_full(rule_first_set(rule))) {
155
	E_redundant_see_through_alt (rule);
183
	E_redundant_see_through_alt(rule);
156
    }
184
    }
157
    rule_computed_first_set (rule);
185
    rule_computed_first_set(rule);
158
}
186
}
159
 
187
 
160
void
188
void
161
rule_compute_first_set PROTO_N ((entry, gclosure))
189
rule_compute_first_set(EntryP entry, GenericP gclosure)
162
		       PROTO_T (EntryP   entry X
-
 
163
				GenericP gclosure)
-
 
164
{
190
{
165
    UNUSED (gclosure);
191
    UNUSED(gclosure);
166
    if (entry_is_rule (entry)) {
192
    if (entry_is_rule(entry)) {
167
	RuleP rule = entry_get_rule (entry);
193
	RuleP rule = entry_get_rule(entry);
168
 
194
 
169
	rule_compute_first_set_1 (rule);
195
	rule_compute_first_set_1(rule);
170
    }
196
    }
171
}
197
}
172

198

173
/*
199
/*
174
 * Local variables(smf):
200
 * Local variables(smf):