1 /* Language lexer definitions for the GNU compiler for the Java(TM) language.
2 Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
3 Contributed by Alexandre Petit-Bianco (apbianco@cygnus.com)
5 This file is part of GNU CC.
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)
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.
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.
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. */
26 #ifndef GCC_JAVA_LEX_H
27 #define GCC_JAVA_LEX_H
29 #include <setjmp.h> /* set_float_handler argument uses it */
31 /* Extern global variables declarations */
35 /* A Unicode character, as read from the input file */
36 typedef unsigned short unicode_t
;
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 */
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);
51 #define JAVA_LEX_CHAR(c)
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", \
56 (all_ascii ? s : "<U>"))
57 #define JAVA_LEX_LIT(s, r) printf ("java_lex:%d: literal '%s'_%d\n", \
59 #define JAVA_LEX_CHAR_LIT(s) printf ("java_lex:%d: literal '%d'\n", lineno, s)
60 #define JAVA_LEX_STR_LIT(s) { \
62 printf ("java_lex:%d: literal '%s'\n", \
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)
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)
78 /* Line information containers */
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))
96 struct java_line
*line
;
100 typedef struct _java_lc
{
106 typedef struct java_lexer
108 /* The file from which we're reading. */
111 /* Number of consecutive backslashes we've read. */
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(). */
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. */
128 /* Nonzero if we're using the fallback decoder. */
129 int use_fallback
: 1;
131 /* The handle for the iconv converter we're using. */
134 /* Bytes we've read from the file but have not sent to iconv. */
137 /* Index of first valid character in buffer, -1 if no valid
141 /* Index of last valid character in buffer, plus one. -1 if no
142 valid characters in buffer. */
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
154 /* Index of last valid output character, plus one. -1 if no valid
158 #endif /* HAVE_ICONV */
161 /* Destroy a lexer object. */
162 extern void java_destroy_lexer
PARAMS ((java_lexer
*));
164 #define JAVA_LINE_MAX 80
166 /* Build a location compound integer */
167 #define BUILD_LOCATION() ((ctxp->elc.line << 12) | (ctxp->elc.col & 0xfff))
169 /* Those macros are defined differently if we compile jc1-lite
170 (JC1_LITE defined) or jc1. */
174 #define REAL_VALUE_TYPE int
175 #define SET_FLOAT_HANDLER(H)
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) {}
195 extern void set_float_handler
PARAMS ((jmp_buf));
196 #define SET_FLOAT_HANDLER(H) set_float_handler ((H))
197 #define DCONST0 dconst0
198 #define GET_IDENTIFIER(S) get_identifier ((S))
199 #define SET_REAL_VALUE_ATOF(TARGET,SOURCE) (TARGET) = (SOURCE)
200 #define FLOAT_TYPE_NODE float_type_node
201 #define DOUBLE_TYPE_NODE double_type_node
202 /* Set modifier_ctx according to TOKEN */
203 #define SET_MODIFIER_CTX(TOKEN) \
205 ctxp->modifier_ctx [(TOKEN)-PUBLIC_TK] = build_wfl_node (NULL_TREE); \
206 java_lval->value = (TOKEN)-PUBLIC_TK; \
208 /* Type precision for long */
209 #define GET_TYPE_PRECISION(NODE) TYPE_PRECISION (long_type_node) / 8;
210 /* Build an operator tree node and return TOKEN */
211 #define BUILD_OPERATOR(TOKEN) \
213 java_lval->operator.token = (TOKEN); \
214 java_lval->operator.location = BUILD_LOCATION(); \
218 /* Build an operator tree node but return ASSIGN_ANY_TK */
219 #define BUILD_OPERATOR2(TOKEN) \
221 java_lval->operator.token = (TOKEN); \
222 java_lval->operator.location = BUILD_LOCATION(); \
223 return ASSIGN_ANY_TK; \
225 /* Set java_lval->node and TREE_TYPE(java_lval->node) in macros */
226 #define SET_LVAL_NODE(NODE) java_lval->node = (NODE)
227 #define SET_LVAL_NODE_TYPE(NODE,TYPE) \
229 java_lval->node = (NODE); \
230 TREE_TYPE (java_lval->node) = (TYPE); \
232 /* Wrap identifier around a wfl */
233 #define BUILD_ID_WFL(EXP) build_wfl_node ((EXP))
234 /* Special ways to report error on numeric literals */
235 #define JAVA_FLOAT_RANGE_ERROR(m) \
238 int i = ctxp->c_line->current; \
239 ctxp->c_line->current = number_beginning; \
240 sprintf (msg, "Floating point literal exceeds range of `%s'", (m)); \
241 java_lex_error (msg, 0); \
242 ctxp->c_line->current = i; \
244 #define JAVA_INTEGRAL_RANGE_ERROR(m) \
246 int i = ctxp->c_line->current; \
247 ctxp->c_line->current = number_beginning; \
248 java_lex_error (m, 0); \
249 ctxp->c_line->current = i; \
252 #endif /* Definitions for jc1 compilation only */
254 /* Macros to decode character ranges */
255 #define RANGE(c, l, h) (((c) >= l && (c) <= h))
256 #define JAVA_WHITE_SPACE_P(c) (c == ' ' || c == '\t' || c == '\f')
257 #define JAVA_START_CHAR_P(c) ((c < 128 \
258 && (RANGE (c, 'A', 'Z') \
259 || RANGE (c, 'a', 'z') \
262 || (c >= 128 && java_start_char_p (c)))
263 #define JAVA_PART_CHAR_P(c) ((c < 128 \
264 && (RANGE (c, 'A', 'Z') \
265 || RANGE (c, 'a', 'z') \
266 || RANGE (c, '0', '9') \
270 || RANGE (c, 0x01, 0x08) \
271 || RANGE (c, 0x0e, 0x1b) \
273 || (c >= 128 && java_part_char_p (c)))
274 #define JAVA_ASCII_DIGIT(c) RANGE (c, '0', '9')
275 #define JAVA_ASCII_OCTDIGIT(c) RANGE (c, '0', '7')
276 #define JAVA_ASCII_HEXDIGIT(c) (RANGE (c, '0', '9') || \
277 RANGE (c, 'a', 'f') || \
279 #define JAVA_ASCII_FPCHAR(c) (RANGE (c, 'd', 'f') || RANGE (c, 'D', 'F') || \
280 c == '.' || JAVA_ASCII_DIGIT (c))
281 #define JAVA_FP_SUFFIX(c) (c == 'D' || c == 'd' || c == 'f' || c == 'F')
282 #define JAVA_FP_EXP(c) (c == 'E' || c == 'F')
283 #define JAVA_FP_PM(c) (c == '-' || c == '+')
284 #define JAVA_ASCII_LETTER(c) (RANGE (c, 'a', 'z') || RANGE (c, 'A', 'Z'))
287 #define JAVA_READ_BUFFER 256
288 #define JAVA_CHAR_ERROR -2
291 #endif /* ! GCC_JAVA_LEX_H */