toplev.c (set_float_handler): Make static.
[gcc.git] / gcc / java / lex.h
1 /* Language lexer definitions for the GNU compiler for the Java(TM) language.
2 Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
3 Contributed by Alexandre Petit-Bianco (apbianco@cygnus.com)
4
5 This file is part of GNU CC.
6
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.
21
22 Java and all Java-based marks are trademarks or registered trademarks
23 of Sun Microsystems, Inc. in the United States and other countries.
24 The Free Software Foundation is independent of Sun Microsystems, Inc. */
25
26 #ifndef GCC_JAVA_LEX_H
27 #define GCC_JAVA_LEX_H
28
29 /* Extern global variables declarations */
30 extern FILE *finput;
31 extern int lineno;
32
33 /* A Unicode character, as read from the input file */
34 typedef unsigned short unicode_t;
35
36 #ifdef HAVE_ICONV
37 #include <iconv.h>
38 #endif /* HAVE_ICONV */
39
40 /* Default encoding to use if no encoding is specified. */
41 #define DEFAULT_ENCODING "UTF-8"
42
43 /* Debug macro to print-out what we match */
44 #ifdef JAVA_LEX_DEBUG
45 #ifdef JAVA_LEX_DEBUG_CHAR
46 #define JAVA_LEX_CHAR(c) printf ("java_lex:%d: char '%c'.%d\n", \
47 lineno, (c < 128 ? c : '.'), c);
48 #else
49 #define JAVA_LEX_CHAR(c)
50 #endif
51 #define JAVA_LEX_KW(c) printf ("java_lex:%d: keyword: '%s'\n", lineno,c)
52 #define JAVA_LEX_ID(s) printf ("java_lex:%d: ID: '%s'\n", \
53 lineno, \
54 (all_ascii ? s : "<U>"))
55 #define JAVA_LEX_LIT(s, r) printf ("java_lex:%d: literal '%s'_%d\n", \
56 lineno, s, r)
57 #define JAVA_LEX_CHAR_LIT(s) printf ("java_lex:%d: literal '%d'\n", lineno, s)
58 #define JAVA_LEX_STR_LIT(s) { \
59 int i; \
60 printf ("java_lex:%d: literal '%s'\n", \
61 lineno, s); \
62 }
63 #define JAVA_LEX_SEP(c) printf ("java_lex:%d: separator '%c'\n",lineno,c)
64 #define JAVA_LEX_OP(c) printf ("java_lex:%d: operator '%s'\n", lineno,c)
65 #else
66 #define JAVA_LEX_CHAR(c)
67 #define JAVA_LEX_KW(c)
68 #define JAVA_LEX_ID(s)
69 #define JAVA_LEX_LIT(s,r)
70 #define JAVA_LEX_CHAR_LIT(s)
71 #define JAVA_LEX_STR_LIT(s)
72 #define JAVA_LEX_SEP(c)
73 #define JAVA_LEX_OP(s)
74 #endif
75
76 /* Line information containers */
77 struct java_line {
78 unicode_t *line; /* The line's unicode */
79 char *unicode_escape_p; /* The matching char was a unicode escape */
80 unicode_t ahead[1]; /* Character ahead */
81 char unicode_escape_ahead_p; /* Character ahead is a unicode escape */
82 int max; /* buffer's max size */
83 int size; /* number of unicodes */
84 int current; /* Current position, unicode based */
85 int char_col; /* Current position, input char based */
86 int lineno; /* Its line number */
87 int white_space_only; /* If it contains only white spaces */
88 };
89 #define JAVA_COLUMN_DELTA(p) \
90 (ctxp->c_line->unicode_escape_p [ctxp->c_line->current+(p)] ? 6 : \
91 (ctxp->c_line->line [ctxp->c_line->current+(p)] == '\t' ? 8 : 1))
92
93 struct java_error {
94 struct java_line *line;
95 int error;
96 };
97
98 typedef struct _java_lc {
99 int line;
100 int prev_col;
101 int col;
102 } java_lc;
103
104 typedef struct java_lexer
105 {
106 /* The file from which we're reading. */
107 FILE *finput;
108
109 /* Number of consecutive backslashes we've read. */
110 int bs_count;
111
112 /* If nonzero, a value that was pushed back. */
113 unicode_t unget_value;
114
115 /* If nonzero, we've hit EOF. Used only by java_get_unicode(). */
116 int hit_eof : 1;
117
118 #ifdef HAVE_ICONV
119 /* Nonzero if we've read any bytes. We only recognize the
120 byte-order-marker (BOM) as the first word. */
121 int read_anything : 1;
122
123 /* Nonzero if we have to byte swap. */
124 int byte_swap : 1;
125
126 /* Nonzero if we're using the fallback decoder. */
127 int use_fallback : 1;
128
129 /* The handle for the iconv converter we're using. */
130 iconv_t handle;
131
132 /* Bytes we've read from the file but have not sent to iconv. */
133 char buffer[1024];
134
135 /* Index of first valid character in buffer, -1 if no valid
136 characters. */
137 int first;
138
139 /* Index of last valid character in buffer, plus one. -1 if no
140 valid characters in buffer. */
141 int last;
142
143 /* This is a buffer of characters already converted by iconv. We
144 use `char' here because we're assuming that iconv() converts to
145 UCS-2, and then we convert it ourselves. */
146 unsigned char out_buffer[1024];
147
148 /* Index of first valid output character. -1 if no valid
149 characters. */
150 int out_first;
151
152 /* Index of last valid output character, plus one. -1 if no valid
153 characters. */
154 int out_last;
155
156 #endif /* HAVE_ICONV */
157 } java_lexer;
158
159 /* Destroy a lexer object. */
160 extern void java_destroy_lexer PARAMS ((java_lexer *));
161
162 #define JAVA_LINE_MAX 80
163
164 /* Build a location compound integer */
165 #define BUILD_LOCATION() ((ctxp->elc.line << 12) | (ctxp->elc.col & 0xfff))
166
167 /* Those macros are defined differently if we compile jc1-lite
168 (JC1_LITE defined) or jc1. */
169 #ifdef JC1_LITE
170
171 #define DCONST0 0
172 #define REAL_VALUE_TYPE int
173 #define GET_IDENTIFIER(S) xstrdup ((S))
174 #define REAL_VALUE_ATOF(LIT,MODE) 0
175 #define REAL_VALUE_ISINF(VALUE) 0
176 #define REAL_VALUE_ISNAN(VALUE) 0
177 #define SET_REAL_VALUE_ATOF(TARGET,SOURCE)
178 #define FLOAT_TYPE_NODE 0
179 #define DOUBLE_TYPE_NODE 0
180 #define SET_MODIFIER_CTX(TOKEN) java_lval->value = (TOKEN)
181 #define GET_TYPE_PRECISION(NODE) 4
182 #define BUILD_OPERATOR(TOKEN) return TOKEN
183 #define BUILD_OPERATOR2(TOKEN) return ASSIGN_ANY_TK
184 #define SET_LVAL_NODE(NODE)
185 #define SET_LVAL_NODE_TYPE(NODE, TYPE)
186 #define BUILD_ID_WFL(EXP) (EXP)
187 #define JAVA_FLOAT_RANGE_ERROR(S) {}
188 #define JAVA_INTEGRAL_RANGE_ERROR(S) {}
189
190 #else
191
192 #define DCONST0 dconst0
193 #define GET_IDENTIFIER(S) get_identifier ((S))
194 #define SET_REAL_VALUE_ATOF(TARGET,SOURCE) (TARGET) = (SOURCE)
195 #define FLOAT_TYPE_NODE float_type_node
196 #define DOUBLE_TYPE_NODE double_type_node
197 /* Set modifier_ctx according to TOKEN */
198 #define SET_MODIFIER_CTX(TOKEN) \
199 { \
200 ctxp->modifier_ctx [(TOKEN)-PUBLIC_TK] = build_wfl_node (NULL_TREE); \
201 java_lval->value = (TOKEN)-PUBLIC_TK; \
202 }
203 /* Type precision for long */
204 #define GET_TYPE_PRECISION(NODE) TYPE_PRECISION (long_type_node) / 8;
205 /* Build an operator tree node and return TOKEN */
206 #define BUILD_OPERATOR(TOKEN) \
207 { \
208 java_lval->operator.token = (TOKEN); \
209 java_lval->operator.location = BUILD_LOCATION(); \
210 return (TOKEN); \
211 }
212
213 /* Build an operator tree node but return ASSIGN_ANY_TK */
214 #define BUILD_OPERATOR2(TOKEN) \
215 { \
216 java_lval->operator.token = (TOKEN); \
217 java_lval->operator.location = BUILD_LOCATION(); \
218 return ASSIGN_ANY_TK; \
219 }
220 /* Set java_lval->node and TREE_TYPE(java_lval->node) in macros */
221 #define SET_LVAL_NODE(NODE) java_lval->node = (NODE)
222 #define SET_LVAL_NODE_TYPE(NODE,TYPE) \
223 { \
224 java_lval->node = (NODE); \
225 TREE_TYPE (java_lval->node) = (TYPE); \
226 }
227 /* Wrap identifier around a wfl */
228 #define BUILD_ID_WFL(EXP) build_wfl_node ((EXP))
229 /* Special ways to report error on numeric literals */
230 #define JAVA_FLOAT_RANGE_ERROR(m) \
231 { \
232 char msg [1024]; \
233 int i = ctxp->c_line->current; \
234 ctxp->c_line->current = number_beginning; \
235 sprintf (msg, "Floating point literal exceeds range of `%s'", (m)); \
236 java_lex_error (msg, 0); \
237 ctxp->c_line->current = i; \
238 }
239 #define JAVA_INTEGRAL_RANGE_ERROR(m) \
240 { \
241 int i = ctxp->c_line->current; \
242 ctxp->c_line->current = number_beginning; \
243 java_lex_error (m, 0); \
244 ctxp->c_line->current = i; \
245 }
246
247 #endif /* Definitions for jc1 compilation only */
248
249 /* Macros to decode character ranges */
250 #define RANGE(c, l, h) (((c) >= l && (c) <= h))
251 #define JAVA_WHITE_SPACE_P(c) (c == ' ' || c == '\t' || c == '\f')
252 #define JAVA_START_CHAR_P(c) ((c < 128 \
253 && (RANGE (c, 'A', 'Z') \
254 || RANGE (c, 'a', 'z') \
255 || c == '_' \
256 || c == '$')) \
257 || (c >= 128 && java_start_char_p (c)))
258 #define JAVA_PART_CHAR_P(c) ((c < 128 \
259 && (RANGE (c, 'A', 'Z') \
260 || RANGE (c, 'a', 'z') \
261 || RANGE (c, '0', '9') \
262 || c == '_' \
263 || c == '$' \
264 || c == 0x0000 \
265 || RANGE (c, 0x01, 0x08) \
266 || RANGE (c, 0x0e, 0x1b) \
267 || c == 0x7f)) \
268 || (c >= 128 && java_part_char_p (c)))
269 #define JAVA_ASCII_DIGIT(c) RANGE (c, '0', '9')
270 #define JAVA_ASCII_OCTDIGIT(c) RANGE (c, '0', '7')
271 #define JAVA_ASCII_HEXDIGIT(c) (RANGE (c, '0', '9') || \
272 RANGE (c, 'a', 'f') || \
273 RANGE (c, 'A', 'F'))
274 #define JAVA_ASCII_FPCHAR(c) (RANGE (c, 'd', 'f') || RANGE (c, 'D', 'F') || \
275 c == '.' || JAVA_ASCII_DIGIT (c))
276 #define JAVA_FP_SUFFIX(c) (c == 'D' || c == 'd' || c == 'f' || c == 'F')
277 #define JAVA_FP_EXP(c) (c == 'E' || c == 'F')
278 #define JAVA_FP_PM(c) (c == '-' || c == '+')
279 #define JAVA_ASCII_LETTER(c) (RANGE (c, 'a', 'z') || RANGE (c, 'A', 'Z'))
280
281 /* Constants */
282 #define JAVA_READ_BUFFER 256
283 #define JAVA_CHAR_ERROR -2
284 #define UEOF -1
285
286 #endif /* ! GCC_JAVA_LEX_H */