OSDN Git Service

PR c++/27491
[pf3gnuchains/gcc-fork.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, 2002, 2003, 2004
3    Free Software Foundation, Inc.
4    Contributed by Alexandre Petit-Bianco (apbianco@cygnus.com)
5
6 This file is part of GCC.
7
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.
12
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.
17
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.
22
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.  */
26
27 #ifndef GCC_JAVA_LEX_H
28 #define GCC_JAVA_LEX_H
29
30 #include "input.h"
31
32 /* Extern global variables declarations  */
33 extern FILE *finput;
34
35 /* A Unicode character, as read from the input file  */
36 typedef unsigned short unicode_t;
37
38 #ifndef HAVE_ICONV_H
39 #undef HAVE_ICONV
40 #endif
41
42 #if defined HAVE_ICONV
43 #include <iconv.h>
44 #endif /* HAVE_ICONV */
45
46 /* Default encoding to use if no encoding is specified.  */
47 #define DEFAULT_ENCODING "UTF-8"
48
49 typedef struct java_lc_s GTY(()) {
50   int line;             /* line number (1-based) */
51   int col;              /* column number number (1-based) */
52 } java_lc;
53
54 struct java_lexer
55 {
56   /* The file from which we're reading.  */
57   FILE *finput;
58
59   /* Number of consecutive backslashes we've read.  */
60   int bs_count;
61
62   /* Next available Unicode character.
63    * This is post-Unicode-escape-processing. -1 if EOF. */
64   int next_unicode;
65
66   /* True if next_unicode is next available character, or EOF. */
67   bool avail_unicode;
68
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). */
72   int next_columns;
73
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;
78
79   /* Name of the character encoding we're using.  */
80   const char *encoding;
81
82   /* Current source position. */
83   java_lc position;
84
85 #ifndef USE_MAPPED_LOCATION
86   java_lc token_start;               /* Error's line column info */
87 #endif
88
89 #ifdef HAVE_ICONV
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;
93
94   /* Nonzero if we have to byte swap.  */
95   unsigned int byte_swap : 1;
96
97   /* Nonzero if we're using the fallback decoder.  */
98   unsigned int use_fallback : 1;
99
100   /* The handle for the iconv converter we're using.  */
101   iconv_t handle;
102
103   /* Bytes we've read from the file but have not sent to iconv.  */
104   char buffer[1024];
105
106   /* Index of first valid character in buffer, -1 if no valid
107      characters.  */
108   int first;
109
110   /* Index of last valid character in buffer, plus one.  -1 if no
111      valid characters in buffer.  */
112   int last;
113
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];
118
119   /* Index of first valid output character.  -1 if no valid
120      characters.  */
121   int out_first;
122
123   /* Index of last valid output character, plus one.  -1 if no valid
124      characters.  */
125   int out_last;
126
127 #endif /* HAVE_ICONV */
128 };
129 typedef struct java_lexer java_lexer;
130
131 /* Destroy a lexer object.  */
132 extern void java_destroy_lexer (java_lexer *);
133
134 #define JAVA_LINE_MAX 80
135
136 /* Build a location compound integer */
137 #ifdef USE_MAPPED_LOCATION
138 #define BUILD_LOCATION() input_location
139 #else
140 #define BUILD_LOCATION() ((ctxp->lexer->token_start.line << 12) \
141                           | (ctxp->lexer->token_start.col & 0xfff))
142 #endif
143
144 /* Those macros are defined differently if we compile jc1-lite
145    (JC1_LITE defined) or jc1.  */
146 #ifdef JC1_LITE
147
148 #define DCONST0 0
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)
165
166 #else
167
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)                                            \
175   {                                                                        \
176     ctxp->modifier_ctx [(TOKEN)-PUBLIC_TK] = build_wfl_node (NULL_TREE); \
177     java_lval->value = (TOKEN)-PUBLIC_TK;                                  \
178   }
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)                           \
183   {                                                     \
184     java_lval->operator.token = (TOKEN);                \
185     java_lval->operator.location = BUILD_LOCATION();    \
186     return (TOKEN);                                     \
187   }
188
189 /* Build an operator tree node but return ASSIGN_ANY_TK */
190 #define BUILD_OPERATOR2(TOKEN)                          \
191   {                                                     \
192     java_lval->operator.token = (TOKEN);                \
193     java_lval->operator.location = BUILD_LOCATION();    \
194     return ASSIGN_ANY_TK;                               \
195   }
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)                                       \
202   {                                                                     \
203     char *msg = XNEWVEC (char, 100 + strlen (m));                       \
204     sprintf (msg, "Floating point literal exceeds range of `%s'", (m)); \
205     JAVA_RANGE_ERROR(msg);                                              \
206     free (msg);                                                         \
207   }
208 #define JAVA_RANGE_ERROR(msg)                                           \
209   do {                                                                  \
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;                               \
214   } while (0)
215
216 #endif /* Definitions for jc1 compilation only */
217
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                                         \
225                                && (ISIDNUM (c)                                \
226                                    || c == '$'                                \
227                                    || c == 0x0000                             \
228                                    || RANGE (c, 0x01, 0x08)                   \
229                                    || RANGE (c, 0x0e, 0x1b)                   \
230                                    || c == 0x7f))                             \
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)
241
242 /* Constants  */
243 #define JAVA_READ_BUFFER 256
244 #define JAVA_CHAR_ERROR -2
245 #define UEOF -1
246
247 #endif /* ! GCC_JAVA_LEX_H */