Subversion Repositories tendra.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

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