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