Subversion Repositories tendra.SVN

Rev

Go to most recent revision | Details | 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
#include "config.h"
32
#include "c_types.h"
33
#include "exp_ops.h"
34
#include "str_ops.h"
35
#include "error.h"
36
#include "extra.h"
37
#include "catalog.h"
38
#include "option.h"
39
#include "hash.h"
40
#include "lex.h"
41
#include "literal.h"
42
#include "syntax.h"
43
#include "ustring.h"
44
#include "xalloc.h"
45
 
46
 
47
/*
48
    ERROR CATALOGUE
49
 
50
    The error catalogue definition is automatically generated.  It consists
51
    of an array of ERR_DATA structures, ERR_CATALOG.
52
*/
53
 
54
#include "errors3.h"
55
 
56
 
57
/*
58
    NUMBER OF ERRORS
59
 
60
    This value gives the number of errors in the error catalogue.
61
*/
62
 
63
#define CATALOG_SIZE	array_size ( ERR_CATALOG )
64
unsigned catalog_size = ( unsigned ) CATALOG_SIZE ;
65
 
66
 
67
/*
68
    ERROR NAME HASH TABLE
69
 
70
    This hash table is used to hold the names of the various errors in
71
    the error catalogue.
72
*/
73
 
74
typedef struct err_hash_tag {
75
    int number ;
76
    ERR_DATA *entry ;
77
    struct err_hash_tag *next ;
78
} ERR_HASH ;
79
 
80
#define HASH_ERROR	128
81
static ERR_HASH *error_hash [ HASH_ERROR + 1 ] ;
82
static ERR_HASH *all_error_hash = NULL ;
83
 
84
 
85
/*
86
    INITIALISE THE ERROR NAME HASH TABLE
87
 
88
    This routine initialises the error hash table.
89
*/
90
 
91
static void init_err_hash
92
    PROTO_Z ()
93
{
94
    int i ;
95
    ERR_DATA *cat = ERR_CATALOG ;
96
    ERR_HASH *err = xmalloc_nof ( ERR_HASH, CATALOG_SIZE ) ;
97
    all_error_hash = err ;
98
    for ( i = 0 ; i <= HASH_ERROR ; i++ ) error_hash [i] = NULL ;
99
    for ( i = 0 ; i < CATALOG_SIZE ; i++ ) {
100
	unsigned long h ;
101
	CONST char *s = cat->name ;
102
	if ( s ) {
103
	    h = hash ( ustrlit ( s ) ) ;
104
	    h %= HASH_ERROR ;
105
	} else {
106
	    h = HASH_ERROR ;
107
	}
108
	err->number = i ;
109
	err->entry = cat ;
110
	err->next = error_hash [h] ;
111
	error_hash [h] = err ;
112
	cat++ ;
113
	err++ ;
114
    }
115
    return ;
116
}
117
 
118
 
119
/*
120
    FIND AN ERROR NUMBER
121
 
122
    This routine finds the error number corresponding to the string literal
123
    expression s.  n gives a likely value to try first.  It returns -1 if
124
    s is not the name of a known error.
125
*/
126
 
127
int find_error_no
128
    PROTO_N ( ( s, n ) )
129
    PROTO_T ( STRING s X int n )
130
{
131
    unsigned kind = DEREF_unsigned ( str_simple_kind ( s ) ) ;
132
    if ( kind == STRING_NONE ) {
133
	ERR_HASH *err ;
134
	unsigned long h ;
135
	string text = DEREF_string ( str_simple_text ( s ) ) ;
136
	ulong len = DEREF_ulong ( str_simple_len ( s ) ) ;
137
	if ( n >= 0 && n < CATALOG_SIZE ) {
138
	    string nm = ustrlit ( ERR_CATALOG [n].name ) ;
139
	    if ( nm && ustreq ( text, nm ) ) {
140
		if ( len == ( ulong ) ustrlen ( nm ) ) return ( n ) ;
141
	    }
142
	}
143
	if ( all_error_hash == NULL ) init_err_hash () ;
144
	h = hash ( text ) ;
145
	h %= HASH_ERROR ;
146
	for ( err = error_hash [h] ; err != NULL ; err = err->next ) {
147
	    string nm = ustrlit ( err->entry->name ) ;
148
	    if ( nm && ustreq ( text, nm ) ) {
149
		if ( len == ( ulong ) ustrlen ( nm ) ) {
150
		    return ( err->number ) ;
151
		}
152
	    }
153
	}
154
    }
155
    return ( -1 ) ;
156
}
157
 
158
 
159
/*
160
    SET AN ERROR SEVERITY LEVEL
161
 
162
    This routine sets the severity level of error number n to the error
163
    severity corresponding to the option number opt.
164
*/
165
 
166
void set_error_sev
167
    PROTO_N ( ( n, opt ) )
168
    PROTO_T ( int n X int opt )
169
{
170
    if ( n >= 0 && n < CATALOG_SIZE ) {
171
	ERR_CATALOG [n].usage = opt ;
172
    }
173
    return ;
174
}
175
 
176
 
177
/*
178
    LOOK UP A LANGUAGE DEPENDENT TERM
179
 
180
    Certain technical terms vary slightly between C and C++.  This routine
181
    looks up the term corresponding to the lexical token number t in the
182
    current language.  The default is the normal lexical token name.
183
*/
184
 
185
string find_vocab
186
    PROTO_N ( ( t ) )
187
    PROTO_T ( int t )
188
{
189
    CONST char *s = token_names [t] ;
190
#if LANGUAGE_C
191
    switch ( t ) {
192
	case lex_class : s = "struct/union" ; break ;
193
    }
194
#endif
195
    return ( ustrlit ( s ) ) ;
196
}
197
 
198
 
199
/*
200
    INITIALISE THE ERROR CATALOGUE
201
 
202
    This routine initialises the error catalogue.
203
*/
204
 
205
void init_catalog
206
    PROTO_Z ()
207
{
208
    ASSERT ( OPT_error == 0 ) ;
209
    return ;
210
}
211
 
212
 
213
/*
214
    TERMINATE THE ERROR CATALOGUE
215
 
216
    This routine terminates the error catalogue.
217
*/
218
 
219
void term_catalog
220
    PROTO_Z ()
221
{
222
    xfree_nof ( all_error_hash ) ;
223
    all_error_hash = NULL ;
224
    return ;
225
}