00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include "keyword.h"
00038 #include "flags.h"
00039 #include "chartables.h"
00040
00041
00042 static char *java_sprint_unicode PARAMS ((struct java_line *, int));
00043 static void java_unicode_2_utf8 PARAMS ((unicode_t));
00044 static void java_lex_error PARAMS ((const char *, int));
00045 #ifndef JC1_LITE
00046 static int java_is_eol PARAMS ((FILE *, int));
00047 static tree build_wfl_node PARAMS ((tree));
00048 #endif
00049 static void java_store_unicode PARAMS ((struct java_line *, unicode_t, int));
00050 static int java_parse_escape_sequence PARAMS ((void));
00051 static int java_start_char_p PARAMS ((unicode_t));
00052 static int java_part_char_p PARAMS ((unicode_t));
00053 static int java_parse_doc_section PARAMS ((int));
00054 static void java_parse_end_comment PARAMS ((int));
00055 static int java_get_unicode PARAMS ((void));
00056 static int java_read_unicode PARAMS ((java_lexer *, int *));
00057 static int java_read_unicode_collapsing_terminators PARAMS ((java_lexer *,
00058 int *));
00059 static void java_store_unicode PARAMS ((struct java_line *, unicode_t, int));
00060 static int java_read_char PARAMS ((java_lexer *));
00061 static void java_allocate_new_line PARAMS ((void));
00062 static void java_unget_unicode PARAMS ((void));
00063 static unicode_t java_sneak_unicode PARAMS ((void));
00064 #ifndef JC1_LITE
00065 static int utf8_cmp PARAMS ((const unsigned char *, int, const char *));
00066 #endif
00067
00068 java_lexer *java_new_lexer PARAMS ((FILE *, const char *));
00069 #ifndef JC1_LITE
00070 static void error_if_numeric_overflow PARAMS ((tree));
00071 #endif
00072
00073 #ifdef HAVE_ICONV
00074
00075 static int byteswap_init = 0;
00076
00077
00078
00079
00080
00081 static int need_byteswap = 0;
00082 #endif
00083
00084 void
00085 java_init_lex (finput, encoding)
00086 FILE *finput;
00087 const char *encoding;
00088 {
00089 #ifndef JC1_LITE
00090 int java_lang_imported = 0;
00091
00092 if (!java_lang_id)
00093 java_lang_id = get_identifier ("java.lang");
00094 if (!java_lang_cloneable)
00095 java_lang_cloneable = get_identifier ("java.lang.Cloneable");
00096 if (!java_io_serializable)
00097 java_io_serializable = get_identifier ("java.io.Serializable");
00098 if (!inst_id)
00099 inst_id = get_identifier ("inst$");
00100 if (!wpv_id)
00101 wpv_id = get_identifier ("write_parm_value$");
00102
00103 if (!java_lang_imported)
00104 {
00105 tree node = build_tree_list
00106 (build_expr_wfl (java_lang_id, NULL, 0, 0), NULL_TREE);
00107 read_import_dir (TREE_PURPOSE (node));
00108 TREE_CHAIN (node) = ctxp->import_demand_list;
00109 ctxp->import_demand_list = node;
00110 java_lang_imported = 1;
00111 }
00112
00113 if (!wfl_operator)
00114 wfl_operator = build_expr_wfl (NULL_TREE, ctxp->filename, 0, 0);
00115 if (!label_id)
00116 label_id = get_identifier ("$L");
00117 if (!wfl_append)
00118 wfl_append = build_expr_wfl (get_identifier ("append"), NULL, 0, 0);
00119 if (!wfl_string_buffer)
00120 wfl_string_buffer =
00121 build_expr_wfl (get_identifier (flag_emit_class_files
00122 ? "java.lang.StringBuffer"
00123 : "gnu.gcj.runtime.StringBuffer"),
00124 NULL, 0, 0);
00125 if (!wfl_to_string)
00126 wfl_to_string = build_expr_wfl (get_identifier ("toString"), NULL, 0, 0);
00127
00128 CPC_INITIALIZER_LIST (ctxp) = CPC_STATIC_INITIALIZER_LIST (ctxp) =
00129 CPC_INSTANCE_INITIALIZER_LIST (ctxp) = NULL_TREE;
00130
00131 memset ((PTR) ctxp->modifier_ctx, 0, 11*sizeof (ctxp->modifier_ctx[0]));
00132 memset ((PTR) current_jcf, 0, sizeof (JCF));
00133 ctxp->current_parsed_class = NULL;
00134 ctxp->package = NULL_TREE;
00135 #endif
00136
00137 ctxp->filename = input_filename;
00138 ctxp->lineno = lineno = 0;
00139 ctxp->p_line = NULL;
00140 ctxp->c_line = NULL;
00141 ctxp->java_error_flag = 0;
00142 ctxp->lexer = java_new_lexer (finput, encoding);
00143 }
00144
00145 static char *
00146 java_sprint_unicode (line, i)
00147 struct java_line *line;
00148 int i;
00149 {
00150 static char buffer [10];
00151 if (line->unicode_escape_p [i] || line->line [i] > 128)
00152 sprintf (buffer, "\\u%04x", line->line [i]);
00153 else
00154 {
00155 buffer [0] = line->line [i];
00156 buffer [1] = '\0';
00157 }
00158 return buffer;
00159 }
00160
00161 static unicode_t
00162 java_sneak_unicode ()
00163 {
00164 return (ctxp->c_line->line [ctxp->c_line->current]);
00165 }
00166
00167 static void
00168 java_unget_unicode ()
00169 {
00170 if (!ctxp->c_line->current)
00171
00172 abort ();
00173
00174 ctxp->c_line->current--;
00175 ctxp->c_line->char_col -= JAVA_COLUMN_DELTA (0);
00176 }
00177
00178 static void
00179 java_allocate_new_line ()
00180 {
00181 unicode_t ahead = (ctxp->c_line ? ctxp->c_line->ahead[0] : '\0');
00182 char ahead_escape_p = (ctxp->c_line ?
00183 ctxp->c_line->unicode_escape_ahead_p : 0);
00184
00185 if (ctxp->c_line && !ctxp->c_line->white_space_only)
00186 {
00187 if (ctxp->p_line)
00188 {
00189 free (ctxp->p_line->unicode_escape_p);
00190 free (ctxp->p_line->line);
00191 free (ctxp->p_line);
00192 }
00193 ctxp->p_line = ctxp->c_line;
00194 ctxp->c_line = NULL;
00195 }
00196
00197 if (!ctxp->c_line)
00198 {
00199 ctxp->c_line = (struct java_line *)xmalloc (sizeof (struct java_line));
00200 ctxp->c_line->max = JAVA_LINE_MAX;
00201 ctxp->c_line->line = (unicode_t *)xmalloc
00202 (sizeof (unicode_t)*ctxp->c_line->max);
00203 ctxp->c_line->unicode_escape_p =
00204 (char *)xmalloc (sizeof (char)*ctxp->c_line->max);
00205 ctxp->c_line->white_space_only = 0;
00206 }
00207
00208 ctxp->c_line->line [0] = ctxp->c_line->size = 0;
00209 ctxp->c_line->char_col = ctxp->c_line->current = 0;
00210 if (ahead)
00211 {
00212 ctxp->c_line->line [ctxp->c_line->size] = ahead;
00213 ctxp->c_line->unicode_escape_p [ctxp->c_line->size] = ahead_escape_p;
00214 ctxp->c_line->size++;
00215 }
00216 ctxp->c_line->ahead [0] = 0;
00217 ctxp->c_line->unicode_escape_ahead_p = 0;
00218 ctxp->c_line->lineno = ++lineno;
00219 ctxp->c_line->white_space_only = 1;
00220 }
00221
00222
00223
00224 java_lexer *
00225 java_new_lexer (finput, encoding)
00226 FILE *finput;
00227 const char *encoding;
00228 {
00229 java_lexer *lex = (java_lexer *) xmalloc (sizeof (java_lexer));
00230 int enc_error = 0;
00231
00232 lex->finput = finput;
00233 lex->bs_count = 0;
00234 lex->unget_value = 0;
00235 lex->hit_eof = 0;
00236
00237 #ifdef HAVE_ICONV
00238 lex->handle = iconv_open ("UCS-2", encoding);
00239 if (lex->handle != (iconv_t) -1)
00240 {
00241 lex->first = -1;
00242 lex->last = -1;
00243 lex->out_first = -1;
00244 lex->out_last = -1;
00245 lex->read_anything = 0;
00246 lex->use_fallback = 0;
00247
00248
00249
00250
00251
00252 if (! byteswap_init)
00253 {
00254 iconv_t handle;
00255
00256 byteswap_init = 1;
00257
00258 handle = iconv_open ("UCS-2", "UTF-8");
00259 if (handle != (iconv_t) -1)
00260 {
00261 unicode_t result;
00262 unsigned char in[3];
00263 char *inp, *outp;
00264 size_t inc, outc, r;
00265
00266
00267 in[0] = 0xef;
00268 in[1] = 0xbb;
00269 in[2] = 0xbf;
00270
00271 inp = in;
00272 inc = 3;
00273 outp = (char *) &result;
00274 outc = 2;
00275
00276 r = iconv (handle, (ICONV_CONST char **) &inp, &inc,
00277 &outp, &outc);
00278 iconv_close (handle);
00279
00280 if (r != (size_t) -1 && inc == 0 && outc == 0)
00281 need_byteswap = (result != 0xfeff);
00282 }
00283 }
00284
00285 lex->byte_swap = need_byteswap;
00286 }
00287 else
00288 #endif
00289 {
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299 if (strcmp (encoding, DEFAULT_ENCODING) && strcmp (encoding, "646"))
00300 enc_error = 1;
00301 #ifdef HAVE_ICONV
00302 else
00303 lex->use_fallback = 1;
00304 #endif
00305 }
00306
00307 if (enc_error)
00308 fatal_error ("unknown encoding: `%s'\nThis might mean that your locale's encoding is not supported\nby your system's iconv(3) implementation. If you aren't trying\nto use a particular encoding for your input file, try the\n`--encoding=UTF-8' option", encoding);
00309
00310 return lex;
00311 }
00312
00313 void
00314 java_destroy_lexer (lex)
00315 java_lexer *lex;
00316 {
00317 #ifdef HAVE_ICONV
00318 if (! lex->use_fallback)
00319 iconv_close (lex->handle);
00320 #endif
00321 free (lex);
00322 }
00323
00324 static int
00325 java_read_char (lex)
00326 java_lexer *lex;
00327 {
00328 if (lex->unget_value)
00329 {
00330 unicode_t r = lex->unget_value;
00331 lex->unget_value = 0;
00332 return r;
00333 }
00334
00335 #ifdef HAVE_ICONV
00336 if (! lex->use_fallback)
00337 {
00338 size_t ir, inbytesleft, in_save, out_count, out_save;
00339 char *inp, *outp;
00340 unicode_t result;
00341
00342
00343 if (lex->out_first == -1 || lex->out_first >= lex->out_last)
00344 {
00345 lex->out_first = 0;
00346 lex->out_last = 0;
00347
00348 while (1)
00349 {
00350
00351
00352
00353
00354 if (lex->first == 0 || lex->first >= lex->last)
00355 {
00356 int r;
00357
00358 if (lex->first >= lex->last)
00359 {
00360 lex->first = 0;
00361 lex->last = 0;
00362 }
00363 if (feof (lex->finput))
00364 return UEOF;
00365 r = fread (&lex->buffer[lex->last], 1,
00366 sizeof (lex->buffer) - lex->last,
00367 lex->finput);
00368 lex->last += r;
00369 }
00370
00371 inbytesleft = lex->last - lex->first;
00372 out_count = sizeof (lex->out_buffer) - lex->out_last;
00373
00374 if (inbytesleft == 0)
00375 {
00376
00377 return UEOF;
00378 }
00379
00380 in_save = inbytesleft;
00381 out_save = out_count;
00382 inp = &lex->buffer[lex->first];
00383 outp = &lex->out_buffer[lex->out_last];
00384 ir = iconv (lex->handle, (ICONV_CONST char **) &inp,
00385 &inbytesleft, &outp, &out_count);
00386
00387
00388
00389 if (! lex->read_anything && out_save - out_count >= 2)
00390 {
00391 unicode_t uc = * (unicode_t *) &lex->out_buffer[0];
00392 if (uc == 0xfeff)
00393 {
00394 lex->byte_swap = 0;
00395 lex->out_first += 2;
00396 }
00397 else if (uc == 0xfffe)
00398 {
00399 lex->byte_swap = 1;
00400 lex->out_first += 2;
00401 }
00402 lex->read_anything = 1;
00403 }
00404
00405 if (lex->byte_swap)
00406 {
00407 unsigned int i;
00408 for (i = 0; i < out_save - out_count; i += 2)
00409 {
00410 char t = lex->out_buffer[lex->out_last + i];
00411 lex->out_buffer[lex->out_last + i]
00412 = lex->out_buffer[lex->out_last + i + 1];
00413 lex->out_buffer[lex->out_last + i + 1] = t;
00414 }
00415 }
00416
00417 lex->first += in_save - inbytesleft;
00418 lex->out_last += out_save - out_count;
00419
00420
00421 if (out_count != out_save)
00422 break;
00423
00424 if (ir == (size_t) -1)
00425 {
00426 if (errno == EINVAL)
00427 {
00428
00429
00430
00431
00432 memmove (&lex->buffer[0], &lex->buffer[lex->first],
00433 lex->last - lex->first);
00434 lex->last -= lex->first;
00435 lex->first = 0;
00436 }
00437 else
00438 {
00439
00440 java_lex_error ("unrecognized character in input stream",
00441 0);
00442 return UEOF;
00443 }
00444 }
00445 }
00446 }
00447
00448 if (lex->out_first == -1 || lex->out_first >= lex->out_last)
00449 {
00450
00451 return UEOF;
00452 }
00453
00454
00455 result = * ((unicode_t *) &lex->out_buffer[lex->out_first]);
00456 lex->out_first += 2;
00457 return result;
00458 }
00459 else
00460 #endif
00461 {
00462 int c, c1, c2;
00463 c = getc (lex->finput);
00464
00465 if (c == EOF)
00466 return UEOF;
00467 if (c < 128)
00468 return (unicode_t) c;
00469 else
00470 {
00471 if ((c & 0xe0) == 0xc0)
00472 {
00473 c1 = getc (lex->finput);
00474 if ((c1 & 0xc0) == 0x80)
00475 {
00476 unicode_t r = (unicode_t)(((c & 0x1f) << 6) + (c1 & 0x3f));
00477
00478
00479
00480 if (r == 0 || (r >= 0x80 && r <= 0x7ff))
00481 return r;
00482 }
00483 }
00484 else if ((c & 0xf0) == 0xe0)
00485 {
00486 c1 = getc (lex->finput);
00487 if ((c1 & 0xc0) == 0x80)
00488 {
00489 c2 = getc (lex->finput);
00490 if ((c2 & 0xc0) == 0x80)
00491 {
00492 unicode_t r = (unicode_t)(((c & 0xf) << 12) +
00493 (( c1 & 0x3f) << 6)
00494 + (c2 & 0x3f));
00495
00496
00497 if (r >= 0x800 && r <= 0xffff
00498 && ! (r >= 0xd800 && r <= 0xdfff)
00499 && r != 0xfffe && r != 0xffff)
00500 return r;
00501 }
00502 }
00503 }
00504
00505
00506
00507
00508 java_lex_error ("malformed UTF-8 character", 0);
00509 }
00510 }
00511
00512
00513 return UEOF;
00514 }
00515
00516 static void
00517 java_store_unicode (l, c, unicode_escape_p)
00518 struct java_line *l;
00519 unicode_t c;
00520 int unicode_escape_p;
00521 {
00522 if (l->size == l->max)
00523 {
00524 l->max += JAVA_LINE_MAX;
00525 l->line = (unicode_t *) xrealloc (l->line, sizeof (unicode_t)*l->max);
00526 l->unicode_escape_p = (char *) xrealloc (l->unicode_escape_p,
00527 sizeof (char)*l->max);
00528 }
00529 l->line [l->size] = c;
00530 l->unicode_escape_p [l->size++] = unicode_escape_p;
00531 }
00532
00533 static int
00534 java_read_unicode (lex, unicode_escape_p)
00535 java_lexer *lex;
00536 int *unicode_escape_p;
00537 {
00538 int c;
00539
00540 c = java_read_char (lex);
00541 *unicode_escape_p = 0;
00542
00543 if (c != '\\')
00544 {
00545 lex->bs_count = 0;
00546 return c;
00547 }
00548
00549 ++lex->bs_count;
00550 if ((lex->bs_count) % 2 == 1)
00551 {
00552
00553 c = java_read_char (lex);
00554 if (c == 'u')
00555 {
00556 unicode_t unicode = 0;
00557 int shift = 12;
00558
00559
00560 while ((c = java_read_char (lex)) == 'u')
00561 ;
00562
00563
00564 if (c == UEOF)
00565 return UEOF;
00566 lex->unget_value = c;
00567
00568
00569
00570
00571 for (shift = 12; shift >= 0; shift -= 4)
00572 {
00573 if ((c = java_read_char (lex)) == UEOF)
00574 return UEOF;
00575 if (hex_p (c))
00576 unicode |= (unicode_t)(hex_value (c) << shift);
00577 else
00578 java_lex_error ("Non hex digit in Unicode escape sequence", 0);
00579 }
00580 lex->bs_count = 0;
00581 *unicode_escape_p = 1;
00582 return unicode;
00583 }
00584 lex->unget_value = c;
00585 }
00586 return (unicode_t) '\\';
00587 }
00588
00589 static int
00590 java_read_unicode_collapsing_terminators (lex, unicode_escape_p)
00591 java_lexer *lex;
00592 int *unicode_escape_p;
00593 {
00594 int c = java_read_unicode (lex, unicode_escape_p);
00595
00596 if (c == '\r')
00597 {
00598
00599
00600 int dummy;
00601 c = java_read_unicode (lex, &dummy);
00602 if (c != '\n')
00603 lex->unget_value = c;
00604
00605 c = '\n';
00606 }
00607
00608 return c;
00609 }
00610
00611 static int
00612 java_get_unicode ()
00613 {
00614
00615 if (!ctxp->c_line || ctxp->c_line->current == ctxp->c_line->size)
00616 {
00617 int c;
00618 int found_chars = 0;
00619
00620 if (ctxp->lexer->hit_eof)
00621 return UEOF;
00622
00623 java_allocate_new_line ();
00624 if (ctxp->c_line->line[0] != '\n')
00625 {
00626 for (;;)
00627 {
00628 int unicode_escape_p;
00629 c = java_read_unicode_collapsing_terminators (ctxp->lexer,
00630 &unicode_escape_p);
00631 if (c != UEOF)
00632 {
00633 found_chars = 1;
00634 java_store_unicode (ctxp->c_line, c, unicode_escape_p);
00635 if (ctxp->c_line->white_space_only
00636 && !JAVA_WHITE_SPACE_P (c)
00637 && c != '\n')
00638 ctxp->c_line->white_space_only = 0;
00639 }
00640 if ((c == '\n') || (c == UEOF))
00641 break;
00642 }
00643
00644 if (c == UEOF && ! found_chars)
00645 {
00646 ctxp->lexer->hit_eof = 1;
00647 return UEOF;
00648 }
00649 }
00650 }
00651 ctxp->c_line->char_col += JAVA_COLUMN_DELTA (0);
00652 JAVA_LEX_CHAR (ctxp->c_line->line [ctxp->c_line->current]);
00653 return ctxp->c_line->line [ctxp->c_line->current++];
00654 }
00655
00656
00657
00658 static void
00659 java_parse_end_comment (c)
00660 int c;
00661 {
00662 for ( ;; c = java_get_unicode ())
00663 {
00664 switch (c)
00665 {
00666 case UEOF:
00667 java_lex_error ("Comment not terminated at end of input", 0);
00668 return;
00669 case '*':
00670 switch (c = java_get_unicode ())
00671 {
00672 case UEOF:
00673 java_lex_error ("Comment not terminated at end of input", 0);
00674 return;
00675 case '/':
00676 return;
00677 case '*':
00678 java_unget_unicode ();
00679 }
00680 }
00681 }
00682 }
00683
00684
00685
00686
00687
00688 static int
00689 java_parse_doc_section (c)
00690 int c;
00691 {
00692 int valid_tag = 0, seen_star = 0;
00693
00694 while (JAVA_WHITE_SPACE_P (c) || (c == '*') || c == '\n')
00695 {
00696 switch (c)
00697 {
00698 case '*':
00699 seen_star = 1;
00700 break;
00701 case '\n':
00702 valid_tag = 1;
00703 default:
00704 seen_star = 0;
00705 }
00706 c = java_get_unicode();
00707 }
00708
00709 if (c == UEOF)
00710 java_lex_error ("Comment not terminated at end of input", 0);
00711
00712 if (seen_star && (c == '/'))
00713 return 1;
00714
00715
00716 if (valid_tag && (c == '@'))
00717 {
00718 char tag [11];
00719 int tag_index = 0;
00720
00721 while (tag_index < 10 && c != UEOF && c != ' ' && c != '\n')
00722 {
00723 c = java_get_unicode ();
00724 tag [tag_index++] = c;
00725 }
00726
00727 if (c == UEOF)
00728 java_lex_error ("Comment not terminated at end of input", 0);
00729 tag [tag_index] = '\0';
00730
00731 if (!strcmp (tag, "deprecated"))
00732 ctxp->deprecated = 1;
00733 }
00734 java_unget_unicode ();
00735 return 0;
00736 }
00737
00738
00739
00740
00741 static int
00742 java_start_char_p (c)
00743 unicode_t c;
00744 {
00745 unsigned int hi = c / 256;
00746 const char *const page = type_table[hi];
00747 unsigned long val = (unsigned long) page;
00748 int flags;
00749
00750 if ((val & ~ (LETTER_PART | LETTER_START)) != 0)
00751 flags = page[c & 255];
00752 else
00753 flags = val;
00754
00755 return flags & LETTER_START;
00756 }
00757
00758
00759
00760
00761 static int
00762 java_part_char_p (c)
00763 unicode_t c;
00764 {
00765 unsigned int hi = c / 256;
00766 const char *const page = type_table[hi];
00767 unsigned long val = (unsigned long) page;
00768 int flags;
00769
00770 if ((val & ~ (LETTER_PART | LETTER_START)) != 0)
00771 flags = page[c & 255];
00772 else
00773 flags = val;
00774
00775 return flags & LETTER_PART;
00776 }
00777
00778 static int
00779 java_parse_escape_sequence ()
00780 {
00781 unicode_t char_lit;
00782 int c;
00783
00784 switch (c = java_get_unicode ())
00785 {
00786 case 'b':
00787 return (unicode_t)0x8;
00788 case 't':
00789 return (unicode_t)0x9;
00790 case 'n':
00791 return (unicode_t)0xa;
00792 case 'f':
00793 return (unicode_t)0xc;
00794 case 'r':
00795 return (unicode_t)0xd;
00796 case '"':
00797 return (unicode_t)0x22;
00798 case '\'':
00799 return (unicode_t)0x27;
00800 case '\\':
00801 return (unicode_t)0x5c;
00802 case '0': case '1': case '2': case '3': case '4':
00803 case '5': case '6': case '7':
00804 {
00805 int octal_escape[3];
00806 int octal_escape_index = 0;
00807 int max = 3;
00808 int i, shift;
00809
00810 for (; octal_escape_index < max && RANGE (c, '0', '7');
00811 c = java_get_unicode ())
00812 {
00813 if (octal_escape_index == 0 && c > '3')
00814 {
00815
00816
00817 --max;
00818 }
00819 octal_escape [octal_escape_index++] = c;
00820 }
00821
00822 java_unget_unicode ();
00823
00824 for (char_lit=0, i = 0, shift = 3*(octal_escape_index-1);
00825 i < octal_escape_index; i++, shift -= 3)
00826 char_lit |= (octal_escape [i] - '0') << shift;
00827
00828 return char_lit;
00829 }
00830 default:
00831 java_lex_error ("Invalid character in escape sequence", 0);
00832 return JAVA_CHAR_ERROR;
00833 }
00834 }
00835
00836
00837
00838
00839 #ifndef JC1_LITE
00840 struct jpa_args
00841 {
00842 YYSTYPE *java_lval;
00843 char *literal_token;
00844 int fflag;
00845 int number_beginning;
00846 };
00847
00848 #ifdef REAL_ARITHMETIC
00849 #define IS_ZERO(X) (ereal_cmp (X, dconst0) == 0)
00850 #else
00851 #define IS_ZERO(X) ((X) == 0)
00852 #endif
00853
00854 static void java_perform_atof PARAMS ((PTR));
00855
00856 static void
00857 java_perform_atof (av)
00858 PTR av;
00859 {
00860 struct jpa_args *a = (struct jpa_args *)av;
00861 YYSTYPE *java_lval = a->java_lval;
00862 int number_beginning = a->number_beginning;
00863 REAL_VALUE_TYPE value;
00864 tree type = (a->fflag ? FLOAT_TYPE_NODE : DOUBLE_TYPE_NODE);
00865
00866 SET_REAL_VALUE_ATOF (value,
00867 REAL_VALUE_ATOF (a->literal_token, TYPE_MODE (type)));
00868
00869 if (REAL_VALUE_ISINF (value) || REAL_VALUE_ISNAN (value))
00870 {
00871 JAVA_FLOAT_RANGE_ERROR ((a->fflag ? "float" : "double"));
00872 value = DCONST0;
00873 }
00874 else if (IS_ZERO (value))
00875 {
00876
00877
00878 int really_zero = 1;
00879 char *p = a->literal_token;
00880 if (*p == '-')
00881 ++p;
00882 while (*p && *p != 'e' && *p != 'E')
00883 {
00884 if (*p != '0' && *p != '.')
00885 {
00886 really_zero = 0;
00887 break;
00888 }
00889 ++p;
00890 }
00891 if (! really_zero)
00892 {
00893 int i = ctxp->c_line->current;
00894 ctxp->c_line->current = number_beginning;
00895 java_lex_error ("Floating point literal underflow", 0);
00896 ctxp->c_line->current = i;
00897 }
00898 }
00899
00900 SET_LVAL_NODE_TYPE (build_real (type, value), type);
00901 }
00902 #endif
00903
00904 static int yylex PARAMS ((YYSTYPE *));
00905
00906 static int
00907 #ifdef JC1_LITE
00908 yylex (java_lval)
00909 #else
00910 java_lex (java_lval)
00911 #endif
00912 YYSTYPE *java_lval;
00913 {
00914 int c;
00915 unicode_t first_unicode;
00916 int ascii_index, all_ascii;
00917 char *string;
00918
00919
00920
00921 step1:
00922
00923 for (c = java_get_unicode ();
00924 c == '\n' || JAVA_WHITE_SPACE_P (c); c = java_get_unicode ())
00925 if (c == '\n')
00926 {
00927 ctxp->elc.line = ctxp->c_line->lineno;
00928 ctxp->elc.col = ctxp->c_line->char_col-2;
00929 }
00930
00931 ctxp->elc.col = (ctxp->elc.col < 0 ? 0 : ctxp->elc.col);
00932
00933 if (c == 0x1a)
00934 {
00935 if ((c = java_get_unicode ()) == UEOF)
00936 return 0;
00937 else
00938 java_unget_unicode ();
00939
00940 }
00941
00942 if (c == UEOF)
00943 return 0;
00944
00945
00946 if (c == '/')
00947 {
00948 switch (c = java_get_unicode ())
00949 {
00950 case '/':
00951 for (;;)
00952 {
00953 c = java_get_unicode ();
00954 if (c == UEOF)
00955 {
00956
00957
00958 if (pedantic)
00959 java_lex_error ("Comment not terminated at end of input",
00960 0);
00961 return 0;
00962 }
00963 if (c == '\n')
00964 goto step1;
00965 }
00966 break;
00967
00968 case '*':
00969 if ((c = java_get_unicode ()) == '*')
00970 {
00971 if ((c = java_get_unicode ()) == '/')
00972 goto step1;
00973 else if (java_parse_doc_section (c))
00974 goto step1;
00975 }
00976
00977 java_parse_end_comment ((c = java_get_unicode ()));
00978 goto step1;
00979 break;
00980 default:
00981 java_unget_unicode ();
00982 c = '/';
00983 break;
00984 }
00985 }
00986
00987 ctxp->elc.line = ctxp->c_line->lineno;
00988 ctxp->elc.prev_col = ctxp->elc.col;
00989 ctxp->elc.col = ctxp->c_line->char_col - JAVA_COLUMN_DELTA (-1);
00990 if (ctxp->elc.col < 0)
00991 abort ();
00992
00993
00994 if (JAVA_ASCII_DIGIT (c) || (c == '.'))
00995 {
00996
00997 #define TOTAL_PARTS ((HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR) * 2 + 2)
00998 int parts[TOTAL_PARTS];
00999 HOST_WIDE_INT high, low;
01000
01001 char literal_token [256];
01002 int literal_index = 0, radix = 10, long_suffix = 0, overflow = 0, bytes;
01003 int found_hex_digits = 0, found_non_octal_digits = 0;
01004 int i;
01005 #ifndef JC1_LITE
01006 int number_beginning = ctxp->c_line->current;
01007 tree value;
01008 #endif
01009
01010
01011 if (c == '.')
01012 {
01013 unicode_t peep = java_sneak_unicode ();
01014
01015 if (!JAVA_ASCII_DIGIT (peep))
01016 {
01017 JAVA_LEX_SEP('.');
01018 BUILD_OPERATOR (DOT_TK);
01019 }
01020 }
01021
01022 for (i = 0; i < TOTAL_PARTS; i++)
01023 parts [i] = 0;
01024
01025 if (c == '0')
01026 {
01027 c = java_get_unicode ();
01028 if (c == 'x' || c == 'X')
01029 {
01030 radix = 16;
01031 c = java_get_unicode ();
01032 }
01033 else if (JAVA_ASCII_DIGIT (c))
01034 radix = 8;
01035 else if (c == '.')
01036 {
01037
01038 java_unget_unicode ();
01039 c = '0';
01040 }
01041 else
01042 {
01043
01044 JAVA_LEX_LIT ("0", 10);
01045 switch (c)
01046 {
01047 case 'L': case 'l':
01048 SET_LVAL_NODE (long_zero_node);
01049 return (INT_LIT_TK);
01050 case 'f': case 'F':
01051 SET_LVAL_NODE (float_zero_node);
01052 return (FP_LIT_TK);
01053 case 'd': case 'D':
01054 SET_LVAL_NODE (double_zero_node);
01055 return (FP_LIT_TK);
01056 default:
01057 java_unget_unicode ();
01058 SET_LVAL_NODE (integer_zero_node);
01059 return (INT_LIT_TK);
01060 }
01061 }
01062 }
01063
01064
01065 while ((radix == 16 && JAVA_ASCII_HEXDIGIT (c)) ||
01066 JAVA_ASCII_DIGIT (c))
01067 {
01068
01069
01070 int numeric = hex_value (c);
01071 int count;
01072
01073
01074 if (radix == 16)
01075 found_hex_digits = 1;
01076
01077 else if (radix == 8 && !JAVA_ASCII_OCTDIGIT (c))
01078 found_non_octal_digits = 1;
01079
01080 literal_token [literal_index++] = c;
01081
01082 for (count = 0; count < TOTAL_PARTS; count++)
01083 {
01084 parts[count] *= radix;
01085 if (count)
01086 {
01087 parts[count] += (parts[count-1] >> HOST_BITS_PER_CHAR);
01088 parts[count-1] &= (1 << HOST_BITS_PER_CHAR) - 1;
01089 }
01090 else
01091 parts[0] += numeric;
01092 }
01093 if (parts [TOTAL_PARTS-1] != 0)
01094 overflow = 1;
01095
01096 c = java_get_unicode ();
01097 }
01098
01099
01100
01101 if (JAVA_ASCII_FPCHAR (c) && !JAVA_ASCII_DIGIT (c))
01102 {
01103 int stage = 0;
01104 int seen_digit = (literal_index ? 1 : 0);
01105 int seen_exponent = 0;
01106 int fflag = 0;
01107
01108
01109
01110
01111 if (radix == 16)
01112 java_lex_error ("Can't express non-decimal FP literal", 0);
01113 radix = 10;
01114
01115 for (;;)
01116 {
01117 if (c == '.')
01118 {
01119 if (stage < 1)
01120 {
01121 stage = 1;
01122 literal_token [literal_index++ ] = c;
01123 c = java_get_unicode ();
01124 }
01125 else
01126 java_lex_error ("Invalid character in FP literal", 0);
01127 }
01128
01129 if (c == 'e' || c == 'E')
01130 {
01131 if (stage < 2)
01132 {
01133
01134 if (!seen_digit)
01135 java_lex_error
01136 ("Invalid FP literal, mantissa must have digit", 0);
01137 seen_digit = 0;
01138 seen_exponent = 1;
01139 stage = 2;
01140 literal_token [literal_index++] = c;
01141 c = java_get_unicode ();
01142 }
01143 else
01144 java_lex_error ("Invalid character in FP literal", 0);
01145 }
01146 if ( c == 'f' || c == 'F' || c == 'd' || c == 'D')
01147 {
01148 fflag = ((c == 'd') || (c == 'D')) ? 0 : 1;
01149 stage = 4;
01150 }
01151
01152 if ((c=='-' || c =='+') && stage == 2)
01153 {
01154 stage = 3;
01155 literal_token [literal_index++] = c;
01156 c = java_get_unicode ();
01157 }
01158
01159 if ((stage == 0 && JAVA_ASCII_FPCHAR (c)) ||
01160 (stage == 1 && JAVA_ASCII_FPCHAR (c) && !(c == '.')) ||
01161 (stage == 2 && (JAVA_ASCII_DIGIT (c) || JAVA_FP_PM (c))) ||
01162 (stage == 3 && JAVA_ASCII_DIGIT (c)))
01163 {
01164 if (JAVA_ASCII_DIGIT (c))
01165 seen_digit = 1;
01166 if (stage == 2)
01167 stage = 3;
01168 literal_token [literal_index++ ] = c;
01169 c = java_get_unicode ();
01170 }
01171 else
01172 {
01173 #ifndef JC1_LITE
01174 struct jpa_args a;
01175 #endif
01176 if (stage != 4)
01177 java_unget_unicode ();
01178
01179
01180 if (seen_exponent && !seen_digit)
01181 java_lex_error
01182 ("Invalid FP literal, exponent must have digit", 0);
01183
01184 literal_token [literal_index] = '\0';
01185 JAVA_LEX_LIT (literal_token, radix);
01186
01187 #ifndef JC1_LITE
01188 a.literal_token = literal_token;
01189 a.fflag = fflag;
01190 a.java_lval = java_lval;
01191 a.number_beginning = number_beginning;
01192 if (do_float_handler (java_perform_atof, (PTR) &a))
01193 return FP_LIT_TK;
01194
01195 JAVA_FLOAT_RANGE_ERROR ((fflag ? "float" : "double"));
01196 #else
01197 return FP_LIT_TK;
01198 #endif
01199 }
01200 }
01201 }
01202
01203
01204 if (radix == 16 && ! found_hex_digits)
01205 java_lex_error
01206 ("0x must be followed by at least one hexadecimal digit", 0);
01207 else if (radix == 8 && found_non_octal_digits)
01208 java_lex_error ("Octal literal contains digit out of range", 0);
01209 else if (c == 'L' || c == 'l')
01210 long_suffix = 1;
01211 else
01212 java_unget_unicode ();
01213
01214 #ifdef JAVA_LEX_DEBUG
01215 literal_token [literal_index] = '\0';
01216 JAVA_LEX_LIT (literal_token, radix);
01217 #endif
01218
01219 if (!overflow)
01220 {
01221 bytes = GET_TYPE_PRECISION (long_type_node);
01222 for (i = bytes; i < TOTAL_PARTS; i++)
01223 if (parts [i])
01224 {
01225 overflow = 1;
01226 break;
01227 }
01228 }
01229 high = low = 0;
01230 for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR; i++)
01231 {
01232 high |= ((HOST_WIDE_INT) parts[i + (HOST_BITS_PER_WIDE_INT
01233 / HOST_BITS_PER_CHAR)]
01234 << (i * HOST_BITS_PER_CHAR));
01235 low |= (HOST_WIDE_INT) parts[i] << (i * HOST_BITS_PER_CHAR);
01236 }
01237
01238
01239
01240 if (long_suffix)
01241 {
01242
01243
01244
01245
01246 int hb = (high >> 31);
01247 if (overflow || (hb && low && radix == 10)
01248 || (hb && high & 0x7fffffff && radix == 10))
01249 JAVA_INTEGRAL_RANGE_ERROR ("Numeric overflow for `long' literal");
01250 }
01251 else
01252 {
01253
01254
01255
01256
01257
01258 int hb = (low >> 31) & 0x1;
01259 if (overflow || high || (hb && low & 0x7fffffff && radix == 10))
01260 JAVA_INTEGRAL_RANGE_ERROR ("Numeric overflow for `int' literal");
01261 high = -hb;
01262 }
01263 #ifndef JC1_LITE
01264 value = build_int_2 (low, high);
01265 JAVA_RADIX10_FLAG (value) = radix == 10;
01266 SET_LVAL_NODE_TYPE (value, long_suffix ? long_type_node : int_type_node);
01267 #else
01268 SET_LVAL_NODE_TYPE (build_int_2 (low, high),
01269 long_suffix ? long_type_node : int_type_node);
01270 #endif
01271 return INT_LIT_TK;
01272 }
01273
01274
01275 if (c == '\'')
01276 {
01277 int char_lit;
01278 if ((c = java_get_unicode ()) == '\\')
01279 char_lit = java_parse_escape_sequence ();
01280 else
01281 {
01282 if (c == '\n' || c == '\'')
01283 java_lex_error ("Invalid character literal", 0);
01284 char_lit = c;
01285 }
01286
01287 c = java_get_unicode ();
01288
01289 if ((c == '\n') || (c == UEOF))
01290 java_lex_error ("Character literal not terminated at end of line", 0);
01291 if (c != '\'')
01292 java_lex_error ("Syntax error in character literal", 0);
01293
01294 if (char_lit == JAVA_CHAR_ERROR)
01295 char_lit = 0;
01296
01297 JAVA_LEX_CHAR_LIT (char_lit);
01298 SET_LVAL_NODE_TYPE (build_int_2 (char_lit, 0), char_type_node);
01299 return CHAR_LIT_TK;
01300 }
01301
01302
01303 if (c == '"')
01304 {
01305 int no_error;
01306 char *string;
01307
01308 for (no_error = 1, c = java_get_unicode ();
01309 c != UEOF && c != '"' && c != '\n'; c = java_get_unicode ())
01310 {
01311 if (c == '\\')
01312 c = java_parse_escape_sequence ();
01313 if (c == JAVA_CHAR_ERROR)
01314 {
01315 no_error = 0;
01316 c = 0;
01317 }
01318 java_unicode_2_utf8 (c);
01319 }
01320 if (c == '\n' || c == UEOF)
01321 {
01322 lineno--;
01323 java_lex_error ("String not terminated at end of line", 0);
01324 lineno++;
01325 }
01326
01327 obstack_1grow (&temporary_obstack, '\0');
01328 string = obstack_finish (&temporary_obstack);
01329 #ifndef JC1_LITE
01330 if (!no_error || (c != '"'))
01331 java_lval->node = error_mark_node;
01332
01333 else
01334 java_lval->node = build_string (strlen (string), string);
01335 #endif
01336 obstack_free (&temporary_obstack, string);
01337 return STRING_LIT_TK;
01338 }
01339
01340
01341 switch (c)
01342 {
01343 case '(':
01344 JAVA_LEX_SEP (c);
01345 BUILD_OPERATOR (OP_TK);
01346 case ')':
01347 JAVA_LEX_SEP (c);
01348 return CP_TK;
01349 case '{':
01350 JAVA_LEX_SEP (c);
01351 if (ctxp->ccb_indent == 1)
01352 ctxp->first_ccb_indent1 = lineno;
01353 ctxp->ccb_indent++;
01354 BUILD_OPERATOR (OCB_TK);
01355 case '}':
01356 JAVA_LEX_SEP (c);
01357 ctxp->ccb_indent--;
01358 if (ctxp->ccb_indent == 1)
01359 ctxp->last_ccb_indent1 = lineno;
01360 BUILD_OPERATOR (CCB_TK);
01361 case '[':
01362 JAVA_LEX_SEP (c);
01363 BUILD_OPERATOR (OSB_TK);
01364 case ']':
01365 JAVA_LEX_SEP (c);
01366 return CSB_TK;
01367 case ';':
01368 JAVA_LEX_SEP (c);
01369 return SC_TK;
01370 case ',':
01371 JAVA_LEX_SEP (c);
01372 return C_TK;
01373 case '.':
01374 JAVA_LEX_SEP (c);
01375 BUILD_OPERATOR (DOT_TK);
01376
01377 }
01378
01379
01380 switch (c)
01381 {
01382 case '=':
01383 if ((c = java_get_unicode ()) == '=')
01384 {
01385 BUILD_OPERATOR (EQ_TK);
01386 }
01387 else
01388 {
01389
01390
01391
01392
01393 java_unget_unicode ();
01394 BUILD_OPERATOR (ASSIGN_TK);
01395 }
01396
01397 case '>':
01398 switch ((c = java_get_unicode ()))
01399 {
01400 case '=':
01401 BUILD_OPERATOR (GTE_TK);
01402 case '>':
01403 switch ((c = java_get_unicode ()))
01404 {
01405 case '>':
01406 if ((c = java_get_unicode ()) == '=')
01407 {
01408 BUILD_OPERATOR2 (ZRS_ASSIGN_TK);
01409 }
01410 else
01411 {
01412 java_unget_unicode ();
01413 BUILD_OPERATOR (ZRS_TK);
01414 }
01415 case '=':
01416 BUILD_OPERATOR2 (SRS_ASSIGN_TK);
01417 default:
01418 java_unget_unicode ();
01419 BUILD_OPERATOR (SRS_TK);
01420 }
01421 default:
01422 java_unget_unicode ();
01423 BUILD_OPERATOR (GT_TK);
01424 }
01425
01426 case '<':
01427 switch ((c = java_get_unicode ()))
01428 {
01429 case '=':
01430 BUILD_OPERATOR (LTE_TK);
01431 case '<':
01432 if ((c = java_get_unicode ()) == '=')
01433 {
01434 BUILD_OPERATOR2 (LS_ASSIGN_TK);
01435 }
01436 else
01437 {
01438 java_unget_unicode ();
01439 BUILD_OPERATOR (LS_TK);
01440 }
01441 default:
01442 java_unget_unicode ();
01443 BUILD_OPERATOR (LT_TK);
01444 }
01445
01446 case '&':
01447 switch ((c = java_get_unicode ()))
01448 {
01449 case '&':
01450 BUILD_OPERATOR (BOOL_AND_TK);
01451 case '=':
01452 BUILD_OPERATOR2 (AND_ASSIGN_TK);
01453 default:
01454 java_unget_unicode ();
01455 BUILD_OPERATOR (AND_TK);
01456 }
01457
01458 case '|':
01459 switch ((c = java_get_unicode ()))
01460 {
01461 case '|':
01462 BUILD_OPERATOR (BOOL_OR_TK);
01463 case '=':
01464 BUILD_OPERATOR2 (OR_ASSIGN_TK);
01465 default:
01466 java_unget_unicode ();
01467 BUILD_OPERATOR (OR_TK);
01468 }
01469
01470 case '+':
01471 switch ((c = java_get_unicode ()))
01472 {
01473 case '+':
01474 BUILD_OPERATOR (INCR_TK);
01475 case '=':
01476 BUILD_OPERATOR2 (PLUS_ASSIGN_TK);
01477 default:
01478 java_unget_unicode ();
01479 BUILD_OPERATOR (PLUS_TK);
01480 }
01481
01482 case '-':
01483 switch ((c = java_get_unicode ()))
01484 {
01485 case '-':
01486 BUILD_OPERATOR (DECR_TK);
01487 case '=':
01488 BUILD_OPERATOR2 (MINUS_ASSIGN_TK);
01489 default:
01490 java_unget_unicode ();
01491 BUILD_OPERATOR (MINUS_TK);
01492 }
01493
01494 case '*':
01495 if ((c = java_get_unicode ()) == '=')
01496 {
01497 BUILD_OPERATOR2 (MULT_ASSIGN_TK);
01498 }
01499 else
01500 {
01501 java_unget_unicode ();
01502 BUILD_OPERATOR (MULT_TK);
01503 }
01504
01505 case '/':
01506 if ((c = java_get_unicode ()) == '=')
01507 {
01508 BUILD_OPERATOR2 (DIV_ASSIGN_TK);
01509 }
01510 else
01511 {
01512 java_unget_unicode ();
01513 BUILD_OPERATOR (DIV_TK);
01514 }
01515
01516 case '^':
01517 if ((c = java_get_unicode ()) == '=')
01518 {
01519 BUILD_OPERATOR2 (XOR_ASSIGN_TK);
01520 }
01521 else
01522 {
01523 java_unget_unicode ();
01524 BUILD_OPERATOR (XOR_TK);
01525 }
01526
01527 case '%':
01528 if ((c = java_get_unicode ()) == '=')
01529 {
01530 BUILD_OPERATOR2 (REM_ASSIGN_TK);
01531 }
01532 else
01533 {
01534 java_unget_unicode ();
01535 BUILD_OPERATOR (REM_TK);
01536 }
01537
01538 case '!':
01539 if ((c = java_get_unicode()) == '=')
01540 {
01541 BUILD_OPERATOR (NEQ_TK);
01542 }
01543 else
01544 {
01545 java_unget_unicode ();
01546 BUILD_OPERATOR (NEG_TK);
01547 }
01548
01549 case '?':
01550 JAVA_LEX_OP ("?");
01551 BUILD_OPERATOR (REL_QM_TK);
01552 case ':':
01553 JAVA_LEX_OP (":");
01554 BUILD_OPERATOR (REL_CL_TK);
01555 case '~':
01556 BUILD_OPERATOR (NOT_TK);
01557 }
01558
01559
01560 for (first_unicode = c, all_ascii = 1, ascii_index = 0;
01561 JAVA_PART_CHAR_P (c); c = java_get_unicode ())
01562 {
01563 java_unicode_2_utf8 (c);
01564 if (all_ascii && c >= 128)
01565 all_ascii = 0;
01566 ascii_index++;
01567 }
01568
01569 obstack_1grow (&temporary_obstack, '\0');
01570 string = obstack_finish (&temporary_obstack);
01571 java_unget_unicode ();
01572
01573
01574
01575
01576 if (all_ascii)
01577 {
01578 const struct java_keyword *kw;
01579 if ((kw=java_keyword (string, ascii_index)))
01580 {
01581 JAVA_LEX_KW (string);
01582 switch (kw->token)
01583 {
01584 case PUBLIC_TK: case PROTECTED_TK: case STATIC_TK:
01585 case ABSTRACT_TK: case FINAL_TK: case NATIVE_TK:
01586 case SYNCHRONIZED_TK: case TRANSIENT_TK: case VOLATILE_TK:
01587 case PRIVATE_TK: case STRICT_TK:
01588 SET_MODIFIER_CTX (kw->token);
01589 return MODIFIER_TK;
01590 case FLOAT_TK:
01591 SET_LVAL_NODE (float_type_node);
01592 return FP_TK;
01593 case DOUBLE_TK:
01594 SET_LVAL_NODE (double_type_node);
01595 return FP_TK;
01596 case BOOLEAN_TK:
01597 SET_LVAL_NODE (boolean_type_node);
01598 return BOOLEAN_TK;
01599 case BYTE_TK:
01600 SET_LVAL_NODE (byte_type_node);
01601 return INTEGRAL_TK;
01602 case SHORT_TK:
01603 SET_LVAL_NODE (short_type_node);
01604 return INTEGRAL_TK;
01605 case INT_TK:
01606 SET_LVAL_NODE (int_type_node);
01607 return INTEGRAL_TK;
01608 case LONG_TK:
01609 SET_LVAL_NODE (long_type_node);
01610 return INTEGRAL_TK;
01611 case CHAR_TK:
01612 SET_LVAL_NODE (char_type_node);
01613 return INTEGRAL_TK;
01614
01615
01616 case TRUE_TK:
01617 case FALSE_TK:
01618 SET_LVAL_NODE ((kw->token == TRUE_TK ?
01619 boolean_true_node : boolean_false_node));
01620 return BOOL_LIT_TK;
01621 case NULL_TK:
01622 SET_LVAL_NODE (null_pointer_node);
01623 return NULL_TK;
01624
01625
01626
01627 case CASE_TK:
01628 case DEFAULT_TK:
01629 case SUPER_TK:
01630 case THIS_TK:
01631 case RETURN_TK:
01632 case BREAK_TK:
01633 case CONTINUE_TK:
01634 case TRY_TK:
01635 case CATCH_TK:
01636 case THROW_TK:
01637 case INSTANCEOF_TK:
01638 BUILD_OPERATOR (kw->token);
01639
01640 default:
01641 return kw->token;
01642 }
01643 }
01644 }
01645
01646
01647 if (JAVA_START_CHAR_P (first_unicode))
01648 {
01649 JAVA_LEX_ID (string);
01650 java_lval->node = BUILD_ID_WFL (GET_IDENTIFIER (string));
01651 return ID_TK;
01652 }
01653
01654
01655 {
01656 char lex_error_buffer [128];
01657 sprintf (lex_error_buffer, "Invalid character `%s' in input",
01658 java_sprint_unicode (ctxp->c_line, ctxp->c_line->current));
01659 java_lex_error (lex_error_buffer, 1);
01660 }
01661 return 0;
01662 }
01663
01664 #ifndef JC1_LITE
01665
01666
01667
01668
01669 static void
01670 error_if_numeric_overflow (value)
01671 tree value;
01672 {
01673 if (TREE_CODE (value) == INTEGER_CST && JAVA_RADIX10_FLAG (value))
01674 {
01675 unsigned HOST_WIDE_INT lo, hi;
01676
01677 lo = TREE_INT_CST_LOW (value);
01678 hi = TREE_INT_CST_HIGH (value);
01679 if (TREE_TYPE (value) == long_type_node)
01680 {
01681 int hb = (hi >> 31);
01682 if (hb && !(hi & 0x7fffffff))
01683 java_lex_error ("Numeric overflow for `long' literal", 0);
01684 }
01685 else
01686 {
01687 int hb = (lo >> 31) & 0x1;
01688 if (hb && !(lo & 0x7fffffff))
01689 java_lex_error ("Numeric overflow for `int' literal", 0);
01690 }
01691 }
01692 }
01693 #endif
01694
01695 static void
01696 java_unicode_2_utf8 (unicode)
01697 unicode_t unicode;
01698 {
01699 if (RANGE (unicode, 0x01, 0x7f))
01700 obstack_1grow (&temporary_obstack, (char)unicode);
01701 else if (RANGE (unicode, 0x80, 0x7ff) || unicode == 0)
01702 {
01703 obstack_1grow (&temporary_obstack,
01704 (unsigned char)(0xc0 | ((0x7c0 & unicode) >> 6)));
01705 obstack_1grow (&temporary_obstack,
01706 (unsigned char)(0x80 | (unicode & 0x3f)));
01707 }
01708 else
01709 {
01710 obstack_1grow (&temporary_obstack,
01711 (unsigned char)(0xe0 | (unicode & 0xf000) >> 12));
01712 obstack_1grow (&temporary_obstack,
01713 (unsigned char)(0x80 | (unicode & 0x0fc0) >> 6));
01714 obstack_1grow (&temporary_obstack,
01715 (unsigned char)(0x80 | (unicode & 0x003f)));
01716 }
01717 }
01718
01719 #ifndef JC1_LITE
01720 static tree
01721 build_wfl_node (node)
01722 tree node;
01723 {
01724 node = build_expr_wfl (node, ctxp->filename, ctxp->elc.line, ctxp->elc.col);
01725
01726 TREE_TYPE (node) = NULL_TREE;
01727 return node;
01728 }
01729 #endif
01730
01731 static void
01732 java_lex_error (msg, forward)
01733 const char *msg ATTRIBUTE_UNUSED;
01734 int forward ATTRIBUTE_UNUSED;
01735 {
01736 #ifndef JC1_LITE
01737 ctxp->elc.line = ctxp->c_line->lineno;
01738 ctxp->elc.col = ctxp->c_line->char_col-1+forward;
01739
01740
01741 ctxp->java_error_flag = 0;
01742 java_error (NULL);
01743 java_error (msg);
01744 #endif
01745 }
01746
01747 #ifndef JC1_LITE
01748 static int
01749 java_is_eol (fp, c)
01750 FILE *fp;
01751 int c;
01752 {
01753 int next;
01754 switch (c)
01755 {
01756 case '\r':
01757 next = getc (fp);
01758 if (next != '\n' && next != EOF)
01759 ungetc (next, fp);
01760 return 1;
01761 case '\n':
01762 return 1;
01763 default:
01764 return 0;
01765 }
01766 }
01767 #endif
01768
01769 char *
01770 java_get_line_col (filename, line, col)
01771 const char *filename ATTRIBUTE_UNUSED;
01772 int line ATTRIBUTE_UNUSED, col ATTRIBUTE_UNUSED;
01773 {
01774 #ifdef JC1_LITE
01775 return 0;
01776 #else
01777
01778
01779
01780
01781
01782
01783 FILE *fp;
01784 int c, ccol, cline = 1;
01785 int current_line_col = 0;
01786 int first_non_space = 0;
01787 char *base;
01788
01789 if (!(fp = fopen (filename, "r")))
01790 fatal_io_error ("can't open %s", filename);
01791
01792 while (cline != line)
01793 {
01794 c = getc (fp);
01795 if (c == EOF)
01796 {
01797 static const char msg[] = "<<file too short - unexpected EOF>>";
01798 obstack_grow (&temporary_obstack, msg, sizeof(msg)-1);
01799 goto have_line;
01800 }
01801 if (java_is_eol (fp, c))
01802 cline++;
01803 }
01804
01805
01806 for (;;)
01807 {
01808 c = getc (fp);
01809 if (c < 0 || java_is_eol (fp, c))
01810 break;
01811 if (!first_non_space && !JAVA_WHITE_SPACE_P (c))
01812 first_non_space = current_line_col;
01813 obstack_1grow (&temporary_obstack, c);
01814 current_line_col++;
01815 }
01816 have_line:
01817
01818 obstack_1grow (&temporary_obstack, '\n');
01819
01820 if (col == -1)
01821 {
01822 col = current_line_col;
01823 first_non_space = 0;
01824 }
01825 else if (col == -2)
01826 col = first_non_space;
01827 else
01828 first_non_space = 0;
01829
01830
01831 base = obstack_base (&temporary_obstack);
01832 for (ccol = 1; ccol <= col+3; ccol++)
01833 {
01834
01835 char c = (first_non_space ?
01836 (base [ccol-1] == '\t' ? '\t' : ' ') : ' ');
01837 obstack_1grow (&temporary_obstack, c);
01838 }
01839 obstack_grow0 (&temporary_obstack, "^", 1);
01840
01841 fclose (fp);
01842 return obstack_finish (&temporary_obstack);
01843 #endif
01844 }
01845
01846 #ifndef JC1_LITE
01847 static int
01848 utf8_cmp (str, length, name)
01849 const unsigned char *str;
01850 int length;
01851 const char *name;
01852 {
01853 const unsigned char *limit = str + length;
01854 int i;
01855
01856 for (i = 0; name[i]; ++i)
01857 {
01858 int ch = UTF8_GET (str, limit);
01859 if (ch != name[i])
01860 return ch - name[i];
01861 }
01862
01863 return str == limit ? 0 : 1;
01864 }
01865
01866
01867
01868 static const char *const cxx_keywords[] =
01869 {
01870 "_Complex",
01871 "__alignof",
01872 "__alignof__",
01873 "__asm",
01874 "__asm__",
01875 "__attribute",
01876 "__attribute__",
01877 "__builtin_va_arg",
01878 "__complex",
01879 "__complex__",
01880 "__const",
01881 "__const__",
01882 "__extension__",
01883 "__imag",
01884 "__imag__",
01885 "__inline",
01886 "__inline__",
01887 "__label__",
01888 "__null",
01889 "__real",
01890 "__real__",
01891 "__restrict",
01892 "__restrict__",
01893 "__signed",
01894 "__signed__",
01895 "__typeof",
01896 "__typeof__",
01897 "__volatile",
01898 "__volatile__",
01899 "and",
01900 "and_eq",
01901 "asm",
01902 "auto",
01903 "bitand",
01904 "bitor",
01905 "bool",
01906 "break",
01907 "case",
01908 "catch",
01909 "char",
01910 "class",
01911 "compl",
01912 "const",
01913 "const_cast",
01914 "continue",
01915 "default",
01916 "delete",
01917 "do",
01918 "double",
01919 "dynamic_cast",
01920 "else",
01921 "enum",
01922 "explicit",
01923 "export",
01924 "extern",
01925 "false",
01926 "float",
01927 "for",
01928 "friend",
01929 "goto",
01930 "if",
01931 "inline",
01932 "int",
01933 "long",
01934 "mutable",
01935 "namespace",
01936 "new",
01937 "not",
01938 "not_eq",
01939 "operator",
01940 "or",
01941 "or_eq",
01942 "private",
01943 "protected",
01944 "public",
01945 "register",
01946 "reinterpret_cast",
01947 "return",
01948 "short",
01949 "signed",
01950 "sizeof",
01951 "static",
01952 "static_cast",
01953 "struct",
01954 "switch",
01955 "template",
01956 "this",
01957 "throw",
01958 "true",
01959 "try",
01960 "typedef",
01961 "typeid",
01962 "typename",
01963 "typeof",
01964 "union",
01965 "unsigned",
01966 "using",
01967 "virtual",
01968 "void",
01969 "volatile",
01970 "wchar_t",
01971 "while",
01972 "xor",
01973 "xor_eq"
01974 };
01975
01976
01977
01978 int
01979 cxx_keyword_p (name, length)
01980 const char *name;
01981 int length;
01982 {
01983 int last = ARRAY_SIZE (cxx_keywords);
01984 int first = 0;
01985 int mid = (last + first) / 2;
01986 int old = -1;
01987
01988 for (mid = (last + first) / 2;
01989 mid != old;
01990 old = mid, mid = (last + first) / 2)
01991 {
01992 int kwl = strlen (cxx_keywords[mid]);
01993 int min_length = kwl > length ? length : kwl;
01994 int r = utf8_cmp (name, min_length, cxx_keywords[mid]);
01995
01996 if (r == 0)
01997 {
01998 int i;
01999
02000 for (i = min_length; i < length && name[i] == '$'; ++i)
02001 ;
02002 if (i == length)
02003 return 1;
02004 r = 1;
02005 }
02006
02007 if (r < 0)
02008 last = mid;
02009 else
02010 first = mid;
02011 }
02012 return 0;
02013 }
02014 #endif