Subversion Repositories tendra.SVN

Rev

Rev 2 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
/*
2
    		 Crown Copyright (c) 1997
3
 
4
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
12
 
13
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
15
 
16
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
19
 
20
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
22
        these conditions;
23
 
24
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
27
        it may be put.
28
*/
29
 
30
 
31
/*** basic.c --- Basic ADT.
32
 *
33
 ** Author: Steve Folkes <smf@hermes.mod.uk>
34
 *
35
 *** Commentary:
36
 *
37
 * This file implements the basic manipulation routines.
38
 *
39
 *** Change Log:
40
 * $Log: basic.c,v $
41
 * Revision 1.1.1.1  1998/01/17  15:57:45  release
42
 * First version to be checked into rolling release.
43
 *
44
 * Revision 1.2  1994/12/15  09:58:01  smf
45
 * Brought into line with OSSG C Coding Standards Document, as per
46
 * "CR94_178.sid+tld-update".
47
 *
48
 * Revision 1.1.1.1  1994/07/25  16:04:31  smf
49
 * Initial import of SID 1.8 non shared files.
50
 *
51
**/
52
 
53
/****************************************************************************/
54
 
55
#include "basic.h"
56
#include "action.h"
57
#include "grammar.h"
58
#include "name.h"
59
#include "rstack.h"
60
#include "rule.h"
61
#include "type.h"
62
 
63
/*--------------------------------------------------------------------------*/
64
 
65
BasicP
66
basic_create PROTO_N ((grammar, ignored))
67
	     PROTO_T (GrammarP grammar X
68
		      BoolT    ignored)
69
{
70
    BasicP basic = ALLOCATE (BasicT);
71
 
72
    basic->terminal        = grammar_next_terminal (grammar);
73
    types_init (basic_result (basic));
74
    basic->result_code     = NIL (GenericP);
75
    basic->ignored         = ignored;
76
    return (basic);
77
}
78
 
79
#ifdef FS_FAST
80
#undef basic_terminal
81
#endif /* defined (FS_FAST) */
82
unsigned
83
basic_terminal PROTO_N ((basic))
84
	       PROTO_T (BasicP basic)
85
{
86
    return (basic->terminal);
87
}
88
#ifdef FS_FAST
89
#define basic_terminal(b) ((b)->terminal)
90
#endif /* defined (FS_FAST) */
91
 
92
#ifdef FS_FAST
93
#undef basic_result
94
#endif /* defined (FS_FAST) */
95
TypeTupleP
96
basic_result PROTO_N ((basic))
97
	     PROTO_T (BasicP basic)
98
{
99
    return (&(basic->result));
100
}
101
#ifdef FS_FAST
102
#define basic_result(b) (&((b)->result))
103
#endif /* defined (FS_FAST) */
104
 
105
#ifdef FS_FAST
106
#undef basic_get_result_code
107
#endif /* defined (FS_FAST) */
108
GenericP
109
basic_get_result_code PROTO_N ((basic))
110
		      PROTO_T (BasicP basic)
111
{
112
    return (basic->result_code);
113
}
114
#ifdef FS_FAST
115
#define basic_get_result_code(b) ((b)->result_code)
116
#endif /* defined (FS_FAST) */
117
 
118
#ifdef FS_FAST
119
#undef basic_set_result_code
120
#endif /* defined (FS_FAST) */
121
void
122
basic_set_result_code PROTO_N ((basic, code))
123
		      PROTO_T (BasicP   basic X
124
			       GenericP code)
125
{
126
    basic->result_code = code;
127
}
128
#ifdef FS_FAST
129
#define basic_set_result_code(b, c) ((b)->result_code = (c))
130
#endif /* defined (FS_FAST) */
131
 
132
#ifdef FS_FAST
133
#undef basic_get_ignored
134
#endif /* defined (FS_FAST) */
135
BoolT
136
basic_get_ignored PROTO_N ((basic))
137
		  PROTO_T (BasicP basic)
138
{
139
    return (basic->ignored);
140
}
141
#ifdef FS_FAST
142
#define basic_get_ignored(b) ((b)->ignored)
143
#endif /* defined (FS_FAST) */
144
 
145
void
146
basic_iter_for_table PROTO_N ((basic, full, proc, closure))
147
		     PROTO_T (BasicP   basic X
148
			      BoolT    full X
149
			      void   (*proc) PROTO_S ((EntryP, GenericP)) X
150
			      GenericP closure)
151
{
152
    if (full) {
153
	types_iter_for_table (basic_result (basic), proc, closure);
154
    }
155
}
156
 
157
void
158
write_basics PROTO_N ((ostream, closure))
159
	     PROTO_T (OStreamP      ostream X
160
		      BasicClosureP closure)
161
{
162
    BitVecP  bitvec   = closure->bitvec;
163
    TableP   table    = grammar_table (closure->grammar);
164
    unsigned terminal = bitvec_first_bit (bitvec);
165
    unsigned num_bits = bitvec_num_bits (bitvec);
166
 
167
    while (num_bits) {
168
	EntryP entry = table_get_basic_by_number (table, terminal);
169
 
170
	if (entry) {
171
	    write_char (ostream, '\'');
172
	    write_key (ostream, entry_key (entry));
173
	    write_char (ostream, '\'');
174
	} else {
175
	    write_unsigned (ostream, terminal);
176
	}
177
	if (num_bits > 2) {
178
	    write_cstring (ostream, ", ");
179
	} else if (num_bits == 2) {
180
	    write_cstring (ostream, " & ");
181
	}
182
	num_bits --;
183
	(void) bitvec_next_bit (bitvec, &terminal);
184
    }
185
}
186
 
187
/*
188
 * Local variables(smf):
189
 * eval: (include::add-path-entry "../os-interface" "../library")
190
 * eval: (include::add-path-entry "../generated")
191
 * end:
192
**/