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
/*** c-out-key.c --- Output of key ADT objects.
32
 *
33
 ** Author: Steve Folkes <smf@hermes.mod.uk>
34
 *
35
 *** Commentary:
36
 *
37
 * This file implements the identifier key output routines used by SID.
38
 *
39
 *** Change Log:
40
 * $Log: c-out-key.c,v $
41
 * Revision 1.1.1.1  1998/01/17  15:57:43  release
42
 * First version to be checked into rolling release.
43
 *
44
 * Revision 1.2  1994/12/15  09:56:31  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:19  smf
49
 * Initial import of SID 1.8 non shared files.
50
 *
51
**/
52
 
53
/****************************************************************************/
54
 
55
#include "c-out-key.h"
56
#include "action.h"
57
#include "basic.h"
58
#include "name.h"
59
#include "rstack.h"
60
#include "rule.h"
61
#include "syntax.h"
62
#include "type.h"
63
 
64
/*--------------------------------------------------------------------------*/
65
 
66
static void
67
write_c_key PROTO_N ((ostream, contents, length))
68
	    PROTO_T (OStreamP ostream X
69
		     CStringP contents X
70
		     unsigned length)
71
{
72
    while (length --) {
73
	char c;
74
 
75
	switch (c = *contents ++) {
76
	  case '-':
77
	    write_cstring (ostream, "_H");
78
	    break;
79
	  case '_':
80
	    write_cstring (ostream, "__");
81
	    break;
82
	  case ':':
83
	    write_cstring (ostream, "_C");
84
	    break;
85
	  default:
86
	    if ((syntax_is_letter (c)) || (syntax_is_digit (c))) {
87
		write_char (ostream, c);
88
	    } else {
89
		write_cstring (ostream, "_X");
90
		write_unsigned (ostream, (unsigned) (unsigned char) c);
91
		write_char (ostream, '_');
92
	    }
93
	    break;
94
	}
95
    }
96
}
97
 
98
/*--------------------------------------------------------------------------*/
99
 
100
void
101
c_output_mapped_key PROTO_N ((info, entry))
102
		    PROTO_T (COutputInfoP info X
103
			     EntryP       entry)
104
{
105
    OStreamP ostream = c_out_info_ostream (info);
106
    NStringP mapping = entry_get_mapping (entry);
107
    BoolT    strict  = c_out_info_get_numeric_ids (info);
108
 
109
    if (mapping) {
110
	write_nstring (ostream, mapping);
111
    } else {
112
	KeyP     key    = entry_key (entry);
113
	NStringP prefix;
114
 
115
	switch (entry_type (entry)) EXHAUSTIVE {
116
	  case ET_TYPE:
117
	    prefix = c_out_info_type_prefix (info);
118
	    break;
119
	  case ET_RULE:
120
	    prefix = c_out_info_fn_prefix (info);
121
	    break;
122
	  case ET_BASIC:
123
	    prefix = c_out_info_terminal_prefix (info);
124
	    strict = FALSE;
125
	    break;
126
	  case ET_NON_LOCAL:
127
	    prefix = c_out_info_in_prefix (info);
128
	    break;
129
	  case ET_ACTION:
130
	  case ET_NAME:
131
	  case ET_RENAME:
132
	  case ET_PREDICATE:
133
	    UNREACHED;
134
	}
135
	write_nstring (ostream, prefix);
136
	if (key_is_string (key) && (!strict)) {
137
	    NStringP nstring = key_get_string (key);
138
 
139
	    write_c_key (ostream, nstring_contents (nstring),
140
			 nstring_length (nstring));
141
	} else {
142
	    write_unsigned (ostream, key_get_number (key));
143
	}
144
    }
145
}
146
 
147
void
148
c_output_key PROTO_N ((info, key, prefix))
149
	     PROTO_T (COutputInfoP info X
150
		      KeyP         key X
151
		      NStringP     prefix)
152
{
153
    OStreamP ostream = c_out_info_ostream (info);
154
    BoolT    strict  = c_out_info_get_numeric_ids (info);
155
 
156
    write_nstring (ostream, prefix);
157
    if (key_is_string (key) && (!strict)) {
158
	NStringP nstring = key_get_string (key);
159
 
160
	write_c_key (ostream, nstring_contents (nstring),
161
		     nstring_length (nstring));
162
    } else {
163
	write_unsigned (ostream, key_get_number (key));
164
    }
165
}
166
 
167
void
168
c_output_label_key PROTO_N ((info, key, label))
169
		   PROTO_T (COutputInfoP info X
170
			    KeyP         key X
171
			    unsigned     label)
172
{
173
    OStreamP ostream = c_out_info_ostream (info);
174
    NStringP prefix  = c_out_info_label_prefix (info);
175
    BoolT    strict  = c_out_info_get_numeric_ids (info);
176
 
177
    write_nstring (ostream, prefix);
178
    write_unsigned (ostream, label);
179
    write_char (ostream, '_');
180
    if (key_is_string (key) && (!strict)) {
181
	NStringP nstring = key_get_string (key);
182
 
183
	write_c_key (ostream, nstring_contents (nstring),
184
		     nstring_length (nstring));
185
    } else {
186
	write_unsigned (ostream, key_get_number (key));
187
    }
188
}
189
 
190
/*
191
 * Local variables(smf):
192
 * eval: (include::add-path-entry "../os-interface" "../library")
193
 * eval: (include::add-path-entry "../transforms" "../output" "../generated")
194
 * end:
195
**/