1 /* Language lexer definitions for the GNU compiler for the Java(TM) language.
2 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
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)
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, 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, 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
32 /* Extern global variables declarations */
35 /* A Unicode character, as read from the input file */
36 typedef unsigned short unicode_t
;
42 #if defined HAVE_ICONV
44 #endif /* HAVE_ICONV */
46 /* Default encoding to use if no encoding is specified. */
47 #define DEFAULT_ENCODING "UTF-8"
49 typedef struct java_lc_s
GTY(()) {
50 int line
; /* line number (1-based) */
51 int col
; /* column number number (1-based) */
56 /* The file from which we're reading. */
59 /* Number of consecutive backslashes we've read. */
62 /* Next available Unicode character.
63 * This is post-Unicode-escape-processing. -1 if EOF. */
66 /* True if next_unicode is next available character, or EOF. */
69 /* Number of source columns of the previous Unicode character (next_unicode).
70 If next_unicode==-2, then this is the number of columns of the previous
71 Unicode character (most recent result of java_{get,peek}_unicode). */
74 /* If nonzero, a value that was pushed back. This is a unicode character,
75 but (unlike next_unicode) is pre-'\uXXXX'-processing. It is also used
76 when a '\r' is *not* followed by a '\n'. */
77 unicode_t unget_value
;
79 /* Name of the character encoding we're using. */
82 /* Current source position. */
85 #ifndef USE_MAPPED_LOCATION
86 java_lc token_start
; /* Error's line column info */
90 /* Nonzero if we've read any bytes. We only recognize the
91 byte-order-marker (BOM) as the first word. */
92 unsigned int read_anything
: 1;
94 /* Nonzero if we have to byte swap. */
95 unsigned int byte_swap
: 1;
97 /* Nonzero if we're using the fallback decoder. */
98 unsigned int use_fallback
: 1;
100 /* The handle for the iconv converter we're using. */
103 /* Bytes we've read from the file but have not sent to iconv. */
106 /* Index of first valid character in buffer, -1 if no valid
110 /* Index of last valid character in buffer, plus one. -1 if no
111 valid characters in buffer. */
114 /* This is a buffer of characters already converted by iconv. We
115 use `char' here because we're assuming that iconv() converts to
116 UCS-2, and then we convert it ourselves. */
117 unsigned char out_buffer
[1024];
119 /* Index of first valid output character. -1 if no valid
123 /* Index of last valid output character, plus one. -1 if no valid
127 #endif /* HAVE_ICONV */
129 typedef struct java_lexer java_lexer
;
131 /* Destroy a lexer object. */
132 extern void java_destroy_lexer (java_lexer
*);
134 #define JAVA_LINE_MAX 80
136 /* Build a location compound integer */
137 #ifdef USE_MAPPED_LOCATION
138 #define BUILD_LOCATION() input_location
140 #define BUILD_LOCATION() ((ctxp->lexer->token_start.line << 12) \
141 | (ctxp->lexer->token_start.col & 0xfff))
144 /* Those macros are defined differently if we compile jc1-lite
145 (JC1_LITE defined) or jc1. */
149 #define REAL_VALUE_TYPE int
150 #define GET_IDENTIFIER(S) xstrdup ((S))
151 #define REAL_VALUE_ATOF(LIT,MODE) 0
152 #define REAL_VALUE_ISINF(VALUE) 0
153 #define REAL_VALUE_ISNAN(VALUE) 0
154 #define SET_REAL_VALUE_ATOF(TARGET,SOURCE)
155 #define FLOAT_TYPE_NODE 0
156 #define DOUBLE_TYPE_NODE 0
157 #define SET_MODIFIER_CTX(TOKEN) java_lval->value = (TOKEN)
158 #define GET_TYPE_PRECISION(NODE) 4
159 #define BUILD_OPERATOR(TOKEN) return TOKEN
160 #define BUILD_OPERATOR2(TOKEN) return ASSIGN_ANY_TK
161 #define SET_LVAL_NODE(NODE)
162 #define BUILD_ID_WFL(EXP) (EXP)
163 #define JAVA_FLOAT_RANGE_ERROR(S) {}
164 #define JAVA_RANGE_ERROR(S) do { } while (0)
168 #define DCONST0 dconst0
169 #define GET_IDENTIFIER(S) get_identifier ((S))
170 #define SET_REAL_VALUE_ATOF(TARGET,SOURCE) (TARGET) = (SOURCE)
171 #define FLOAT_TYPE_NODE float_type_node
172 #define DOUBLE_TYPE_NODE double_type_node
173 /* Set modifier_ctx according to TOKEN */
174 #define SET_MODIFIER_CTX(TOKEN) \
176 ctxp->modifier_ctx [(TOKEN)-PUBLIC_TK] = build_wfl_node (NULL_TREE); \
177 java_lval->value = (TOKEN)-PUBLIC_TK; \
179 /* Type precision for long */
180 #define GET_TYPE_PRECISION(NODE) TYPE_PRECISION (long_type_node) / 8;
181 /* Build an operator tree node and return TOKEN */
182 #define BUILD_OPERATOR(TOKEN) \
184 java_lval->operator.token = (TOKEN); \
185 java_lval->operator.location = BUILD_LOCATION(); \
189 /* Build an operator tree node but return ASSIGN_ANY_TK */
190 #define BUILD_OPERATOR2(TOKEN) \
192 java_lval->operator.token = (TOKEN); \
193 java_lval->operator.location = BUILD_LOCATION(); \
194 return ASSIGN_ANY_TK; \
196 /* Set java_lval->node and TREE_TYPE(java_lval->node) in macros */
197 #define SET_LVAL_NODE(NODE) java_lval->node = (NODE)
198 /* Wrap identifier around a wfl */
199 #define BUILD_ID_WFL(EXP) build_wfl_node ((EXP))
200 /* Special ways to report error on numeric literals */
201 #define JAVA_FLOAT_RANGE_ERROR(m) \
203 char *msg = xmalloc (100 + strlen (m)); \
204 sprintf (msg, "Floating point literal exceeds range of `%s'", (m)); \
205 JAVA_RANGE_ERROR(msg); \
208 #define JAVA_RANGE_ERROR(msg) \
210 int save_col = ctxp->lexer->position.col; \
211 ctxp->lexer->position.col = number_beginning; \
212 java_lex_error (msg, 0); \
213 ctxp->lexer->position.col = save_col; \
216 #endif /* Definitions for jc1 compilation only */
218 /* Macros to decode character ranges */
219 #define RANGE(c, l, h) (((c) >= l && (c) <= h))
220 #define JAVA_WHITE_SPACE_P(c) (c == ' ' || c == '\t' || c == '\f')
221 #define JAVA_START_CHAR_P(c) ((c < 128 \
222 && (ISIDST (c) || c == '$')) \
223 || (c >= 128 && java_start_char_p (c)))
224 #define JAVA_PART_CHAR_P(c) ((c < 128 \
228 || RANGE (c, 0x01, 0x08) \
229 || RANGE (c, 0x0e, 0x1b) \
231 || (c >= 128 && java_part_char_p (c)))
232 #define JAVA_ASCII_DIGIT(c) ISDIGIT (c)
233 #define JAVA_ASCII_OCTDIGIT(c) RANGE (c, '0', '7')
234 #define JAVA_ASCII_HEXDIGIT(c) ISXDIGIT (c)
235 #define JAVA_ASCII_FPCHAR(c) (RANGE (c, 'd', 'f') || RANGE (c, 'D', 'F') || \
236 c == '.' || JAVA_ASCII_DIGIT (c))
237 #define JAVA_FP_SUFFIX(c) (c == 'D' || c == 'd' || c == 'f' || c == 'F')
238 #define JAVA_FP_EXP(c) (c == 'E' || c == 'F')
239 #define JAVA_FP_PM(c) (c == '-' || c == '+')
240 #define JAVA_ASCII_LETTER(c) ISALPHA (c)
243 #define JAVA_READ_BUFFER 256
244 #define JAVA_CHAR_ERROR -2
247 #endif /* ! GCC_JAVA_LEX_H */