1 /* Language lexer for the GNU compiler for the Java(TM) language.
2 Copyright (C) 1997, 1998 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 /* It defines java_lex (yylex) that reads a Java ASCII source file
27 possibly containing Unicode escape sequence or utf8 encoded characters
28 and returns a token for everything found but comments, white spaces
29 and line terminators. When necessary, it also fills the java_lval
30 (yylval) union. It's implemented to be called by a re-entrant parser
33 The lexical analysis conforms to the Java grammar described in "The
34 Java(TM) Language Specification. J. Gosling, B. Joy, G. Steele.
35 Addison Wesley 1996" (http://java.sun.com/docs/books/jls/html/3.doc.html) */
45 #ifdef inline /* javaop.h redefines inline as static */
55 extern struct obstack *expression_obstack;
61 int java_lang_imported = 0;
64 if (!java_lang_imported)
66 tree node = build_tree_list
67 (build_expr_wfl (get_identifier ("java.lang"), NULL, 0, 0), NULL_TREE);
68 read_import_dir (TREE_PURPOSE (node));
69 TREE_CHAIN (node) = ctxp->import_demand_list;
70 ctxp->import_demand_list = node;
71 java_lang_imported = 1;
75 wfl_operator = build_expr_wfl (NULL_TREE, ctxp->filename, 0, 0);
77 label_id = get_identifier ("$L");
79 wfl_append = build_expr_wfl (get_identifier ("append"), NULL, 0, 0);
80 if (!wfl_string_buffer)
82 build_expr_wfl (get_identifier ("java.lang.StringBuffer"), NULL, 0, 0);
84 wfl_to_string = build_expr_wfl (get_identifier ("toString"), NULL, 0, 0);
86 ctxp->static_initialized = ctxp->non_static_initialized =
87 ctxp->incomplete_class = NULL_TREE;
89 bzero (ctxp->modifier_ctx, 11*sizeof (ctxp->modifier_ctx[0]));
90 bzero (current_jcf, sizeof (JCF));
91 ctxp->current_parsed_class = NULL;
92 ctxp->package = NULL_TREE;
95 ctxp->filename = input_filename;
96 ctxp->lineno = lineno = 0;
99 ctxp->unget_utf8_value = 0;
100 ctxp->minus_seen = 0;
101 ctxp->java_error_flag = 0;
105 java_sprint_unicode (line, i)
106 struct java_line *line;
109 static char buffer [10];
110 if (line->unicode_escape_p [i] || line->line [i] > 128)
111 sprintf (buffer, "\\u%04x", line->line [i]);
114 buffer [0] = line->line [i];
121 java_sneak_unicode ()
123 return (ctxp->c_line->line [ctxp->c_line->current]);
127 java_unget_unicode ()
129 if (!ctxp->c_line->current)
130 fatal ("can't unget unicode - java_unget_unicode");
131 ctxp->c_line->current--;
132 ctxp->c_line->char_col -= JAVA_COLUMN_DELTA (0);
136 java_allocate_new_line ()
138 unicode_t ahead = (ctxp->c_line ? ctxp->c_line->ahead[0] : '\0');
139 char ahead_escape_p = (ctxp->c_line ?
140 ctxp->c_line->unicode_escape_ahead_p : 0);
142 if (ctxp->c_line && !ctxp->c_line->white_space_only)
146 free (ctxp->p_line->unicode_escape_p);
147 free (ctxp->p_line->line);
150 ctxp->p_line = ctxp->c_line;
151 ctxp->c_line = NULL; /* Reallocated */
156 ctxp->c_line = (struct java_line *)xmalloc (sizeof (struct java_line));
157 ctxp->c_line->max = JAVA_LINE_MAX;
158 ctxp->c_line->line = (unicode_t *)xmalloc
159 (sizeof (unicode_t)*ctxp->c_line->max);
160 ctxp->c_line->unicode_escape_p =
161 (char *)xmalloc (sizeof (char)*ctxp->c_line->max);
162 ctxp->c_line->white_space_only = 0;
165 ctxp->c_line->line [0] = ctxp->c_line->size = 0;
166 ctxp->c_line->char_col = ctxp->c_line->current = 0;
169 ctxp->c_line->line [ctxp->c_line->size] = ahead;
170 ctxp->c_line->unicode_escape_p [ctxp->c_line->size] = ahead_escape_p;
171 ctxp->c_line->size++;
173 ctxp->c_line->ahead [0] = 0;
174 ctxp->c_line->unicode_escape_ahead_p = 0;
175 ctxp->c_line->lineno = ++lineno;
176 ctxp->c_line->white_space_only = 1;
185 if (ctxp->unget_utf8_value)
187 int to_return = ctxp->unget_utf8_value;
188 ctxp->unget_utf8_value = 0;
200 if (c & (0xe0 == 0xc0))
203 if (c1 & (0xc0 == 0x80))
204 return (unicode_t)(((c &0x1f) << 6) + (c1 & 0x3f));
206 else if (c & (0xf0 == 0xe0))
209 if (c1 & (0xc0 == 0x80))
212 if (c2 & (0xc0 == 0x80))
213 return (unicode_t)(((c & 0xf) << 12) +
214 (( c1 & 0x3f) << 6) + (c2 & 0x3f));
217 java_lex_error ("Bad utf8 encoding", 0);
223 java_store_unicode (l, c, unicode_escape_p)
226 int unicode_escape_p;
228 if (l->size == l->max)
230 l->max += JAVA_LINE_MAX;
231 l->line = (unicode_t *)realloc (l->line, sizeof (unicode_t)*l->max);
232 l->unicode_escape_p = (char *)realloc (l->unicode_escape_p,
233 sizeof (char)*l->max);
235 l->line [l->size] = c;
236 l->unicode_escape_p [l->size++] = unicode_escape_p;
240 java_read_unicode (term_context, unicode_escape_p)
242 int *unicode_escape_p;
247 c = java_read_char ();
248 *unicode_escape_p = 0;
251 return ((term_context ? c :
252 java_lineterminator (c) ? '\n' : (unicode_t)c));
254 /* Count the number of preceeding '\' */
255 for (base = ftell (finput), i = base-2; c == '\\';)
257 fseek (finput, i--, SEEK_SET);
258 c = java_read_char (); /* Will fail if reading utf8 stream. FIXME */
260 fseek (finput, base, SEEK_SET);
261 if ((base-i-3)%2 == 0) /* If odd number of \ seen */
263 c = java_read_char ();
266 unsigned short unicode = 0;
268 /* Next should be 4 hex digits, otherwise it's an error.
269 The hex value is converted into the unicode, pushed into
270 the Unicode stream. */
271 for (shift = 12; shift >= 0; shift -= 4)
273 if ((c = java_read_char ()) == UEOF)
275 if (c >= '0' && c <= '9')
276 unicode |= (unicode_t)((c-'0') << shift);
277 else if ((c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))
278 unicode |= (unicode_t)((10+(c | 0x20)-'a') << shift);
281 ("Non hex digit in Unicode escape sequence", 0);
283 *unicode_escape_p = 1;
284 return (term_context ? unicode :
285 (java_lineterminator (c) ? '\n' : unicode));
289 return (unicode_t)'\\';
295 /* It's time to read a line when... */
296 if (!ctxp->c_line || ctxp->c_line->current == ctxp->c_line->size)
299 java_allocate_new_line ();
300 if (ctxp->c_line->line[0] != '\n')
303 int unicode_escape_p;
304 c = java_read_unicode (0, &unicode_escape_p);
305 java_store_unicode (ctxp->c_line, c, unicode_escape_p);
306 if (ctxp->c_line->white_space_only
307 && !JAVA_WHITE_SPACE_P (c) && c!='\n')
308 ctxp->c_line->white_space_only = 0;
309 if ((c == '\n') || (c == UEOF))
313 ctxp->c_line->char_col += JAVA_COLUMN_DELTA (0);
314 JAVA_LEX_CHAR (ctxp->c_line->line [ctxp->c_line->current]);
315 return ctxp->c_line->line [ctxp->c_line->current++];
319 java_lineterminator (c)
322 int unicode_escape_p;
323 if (c == '\n') /* CR */
325 if ((c = java_read_unicode (1, &unicode_escape_p)) != '\r')
327 ctxp->c_line->ahead [0] = c;
328 ctxp->c_line->unicode_escape_ahead_p = unicode_escape_p;
332 else if (c == '\r') /* LF */
334 if ((c = java_read_unicode (1, &unicode_escape_p)) != '\n')
336 ctxp->c_line->ahead [0] = c;
337 ctxp->c_line->unicode_escape_ahead_p = unicode_escape_p;
345 /* Parse the end of a C style comment */
347 java_parse_end_comment ()
351 for (c = java_get_unicode ();; c = java_get_unicode ())
356 java_lex_error ("Comment not terminated at end of input", 0);
358 switch (c = java_get_unicode ())
361 java_lex_error ("Comment not terminated at end of input", 0);
364 case '*': /* reparse only '*' */
365 java_unget_unicode ();
371 /* Parse the documentation section. Keywords must be at the beginning
372 of a documentation comment line (ignoring white space and any `*'
373 character). Parsed keyword(s): @DEPRECATED. */
376 java_parse_doc_section (c)
379 int valid_tag = 0, seen_star;
381 while (JAVA_WHITE_SPACE_P (c) || (c == '*') || c == '\n')
394 c = java_get_unicode();
398 java_lex_error ("Comment not terminated at end of input", 0);
400 if (seen_star && (c == '/'))
401 return 1; /* Goto step1 in caller */
403 /* We're parsing @deprecated */
404 if (valid_tag && (c == '@'))
409 while (tag_index < 10 && c != UEOF && c != ' ' && c != '\n')
411 c = java_get_unicode ();
412 tag [tag_index++] = c;
416 java_lex_error ("Comment not terminated at end of input", 0);
418 java_unget_unicode ();
419 tag [tag_index] = '\0';
421 if (!strcmp (tag, "deprecated"))
422 ctxp->deprecated = 1;
427 /* This function to be used only by JAVA_ID_CHAR_P (), otherwise it
428 will return a wrong result. */
430 java_letter_or_digit_p (c)
433 return _JAVA_LETTER_OR_DIGIT_P (c);
437 java_parse_escape_sequence ()
442 switch (c = java_get_unicode ())
445 return (unicode_t)0x8;
447 return (unicode_t)0x9;
449 return (unicode_t)0xa;
451 return (unicode_t)0xc;
453 return (unicode_t)0xd;
455 return (unicode_t)0x22;
457 return (unicode_t)0x27;
459 return (unicode_t)0x5c;
460 case '0': case '1': case '2': case '3': case '4':
461 case '5': case '6': case '7': case '8': case '9':
464 int octal_escape_index = 0;
466 for (; octal_escape_index < 3 && RANGE (c, '0', '9');
467 c = java_get_unicode ())
468 octal_escape [octal_escape_index++] = c;
470 java_unget_unicode ();
472 if ((octal_escape_index == 3) && (octal_escape [0] > '3'))
474 java_lex_error ("Literal octal escape out of range", 0);
475 return JAVA_CHAR_ERROR;
480 for (char_lit=0, i = 0, shift = 3*(octal_escape_index-1);
481 i < octal_escape_index; i++, shift -= 3)
482 char_lit |= (octal_escape [i] - '0') << shift;
489 return '\n'; /* ULT, caught latter as a specific error */
491 java_lex_error ("Illegal character in escape sequence", 0);
492 return JAVA_CHAR_ERROR;
504 unicode_t c, first_unicode;
505 int ascii_index, all_ascii;
508 /* Translation of the Unicode escape in the raw stream of Unicode
509 characters. Takes care of line terminator. */
511 /* Skip white spaces: SP, TAB and FF or ULT */
512 for (c = java_get_unicode ();
513 c == '\n' || JAVA_WHITE_SPACE_P (c); c = java_get_unicode ())
516 ctxp->elc.line = ctxp->c_line->lineno;
517 ctxp->elc.col = ctxp->c_line->char_col-2;
520 ctxp->elc.col = (ctxp->elc.col < 0 ? 0 : ctxp->elc.col);
522 if (c == 0x1a) /* CTRL-Z */
524 if ((c = java_get_unicode ()) == UEOF)
525 return 0; /* Ok here */
527 java_unget_unicode (); /* Caught latter at the end the function */
529 /* Handle EOF here */
530 if (c == UEOF) /* Should probably do something here... */
533 /* Take care of eventual comments. */
536 switch (c = java_get_unicode ())
539 for (c = java_get_unicode ();;c = java_get_unicode ())
542 java_lex_error ("Comment not terminated at end of input", 0);
543 if (c == '\n') /* ULT */
549 if ((c = java_get_unicode ()) == '*')
551 if ((c = java_get_unicode ()) == '/')
552 goto step1; /* Empy documentation comment */
553 else if (java_parse_doc_section (c))
557 java_unget_unicode ();
559 java_parse_end_comment ();
563 java_unget_unicode ();
569 ctxp->elc.line = ctxp->c_line->lineno;
570 ctxp->elc.col = ctxp->c_line->char_col - JAVA_COLUMN_DELTA (-1);
571 if (ctxp->elc.col < 0)
572 fatal ("ctxp->elc.col < 0 - java_lex");
574 /* Numeric literals */
575 if (JAVA_ASCII_DIGIT (c) || (c == '.'))
577 /* This section of code is borrowed from gcc/c-lex.c */
578 #define TOTAL_PARTS ((HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR) * 2 + 2)
579 int parts[TOTAL_PARTS];
580 HOST_WIDE_INT high, low;
581 /* End borrowed section */
582 char literal_token [256];
583 int literal_index = 0, radix = 10, long_suffix = 0, overflow = 0, bytes;
585 int number_beginning = ctxp->c_line->current;
587 /* We might have a . separator instead of a FP like .[0-9]* */
590 unicode_t peep = java_sneak_unicode ();
592 if (!JAVA_ASCII_DIGIT (peep))
595 BUILD_OPERATOR (DOT_TK);
599 for (i = 0; i < TOTAL_PARTS; i++)
604 c = java_get_unicode ();
605 if (c == 'x' || c == 'X')
608 c = java_get_unicode ();
610 else if (JAVA_ASCII_DIGIT (c))
614 /* Push the '.' back and prepare for a FP parsing... */
615 java_unget_unicode ();
620 /* We have a zero literal: 0, 0{f,F}, 0{d,D} */
621 JAVA_LEX_LIT ("0", 10);
625 SET_LVAL_NODE_TYPE (integer_zero_node, long_type_node);
628 SET_LVAL_NODE_TYPE (build_real (float_type_node, dconst0),
632 SET_LVAL_NODE_TYPE (build_real (double_type_node, dconst0),
636 java_unget_unicode ();
637 SET_LVAL_NODE_TYPE (integer_zero_node, int_type_node);
642 /* Parse the first part of the literal, until we find something
643 which is not a number. */
644 while ((radix == 10 && JAVA_ASCII_DIGIT (c)) ||
645 (radix == 16 && JAVA_ASCII_HEXDIGIT (c)) ||
646 (radix == 8 && JAVA_ASCII_OCTDIGIT (c)))
648 /* We store in a string (in case it turns out to be a FP) and in
649 PARTS if we have to process a integer literal. */
650 int numeric = (RANGE (c, '0', '9') ? c-'0' : 10 +(c|0x20)-'a');
653 literal_token [literal_index++] = c;
654 /* This section of code if borrowed from gcc/c-lex.c */
655 for (count = 0; count < TOTAL_PARTS; count++)
657 parts[count] *= radix;
660 parts[count] += (parts[count-1] >> HOST_BITS_PER_CHAR);
661 parts[count-1] &= (1 << HOST_BITS_PER_CHAR) - 1;
666 if (parts [TOTAL_PARTS-1] != 0)
668 /* End borrowed section. */
669 c = java_get_unicode ();
672 /* If we have something from the FP char set but not a digit, parse
674 if (JAVA_ASCII_FPCHAR (c) && !JAVA_ASCII_DIGIT (c))
677 int seen_digit = (literal_index ? 1 : 0);
678 int seen_exponent = 0;
679 int fflag = 0; /* 1 for {f,F}, 0 for {d,D}. FP literal are
680 double unless specified. */
682 java_lex_error ("Can't express non-decimal FP literal", 0);
691 literal_token [literal_index++ ] = c;
692 c = java_get_unicode ();
695 java_lex_error ("Invalid character in FP literal", 0);
698 if (c == 'e' || c == 'E')
702 /* {E,e} must have seen at list a digit */
704 java_lex_error ("Invalid FP literal", 0);
708 literal_token [literal_index++] = c;
709 c = java_get_unicode ();
712 java_lex_error ("Invalid character in FP literal", 0);
714 if ( c == 'f' || c == 'F' || c == 'd' || c == 'D')
716 fflag = ((c == 'd') || (c == 'D')) ? 0 : 1;
717 stage = 4; /* So we fall through */
720 if ((c=='-' || c =='+') && stage < 3)
723 literal_token [literal_index++] = c;
724 c = java_get_unicode ();
727 if ((stage == 0 && JAVA_ASCII_FPCHAR (c)) ||
728 (stage == 1 && JAVA_ASCII_FPCHAR (c) && !(c == '.')) ||
729 (stage == 2 && (JAVA_ASCII_DIGIT (c) || JAVA_FP_PM (c))) ||
730 (stage == 3 && JAVA_ASCII_DIGIT (c)))
732 if (JAVA_ASCII_DIGIT (c))
734 literal_token [literal_index++ ] = c;
735 c = java_get_unicode ();
740 REAL_VALUE_TYPE value;
742 tree type = (fflag ? FLOAT_TYPE_NODE : DOUBLE_TYPE_NODE);
745 if (stage != 4) /* Don't push back fF/dD */
746 java_unget_unicode ();
748 /* An exponent (if any) must have seen a digit. */
749 if (seen_exponent && !seen_digit)
750 java_lex_error ("Invalid FP literal", 0);
752 literal_token [literal_index] = '\0';
753 JAVA_LEX_LIT (literal_token, radix);
755 if (setjmp (handler))
757 JAVA_FLOAT_RANGE_ERROR ((fflag ? "float" : "double"));
762 SET_FLOAT_HANDLER (handler);
764 (value, REAL_VALUE_ATOF (literal_token,
767 if (REAL_VALUE_ISINF (value))
768 JAVA_FLOAT_RANGE_ERROR ((fflag ? "float" : "double"));
770 if (REAL_VALUE_ISNAN (value))
771 JAVA_FLOAT_RANGE_ERROR ((fflag ? "float" : "double"));
773 SET_LVAL_NODE_TYPE (build_real (type, value), type);
774 SET_FLOAT_HANDLER (NULL_PTR);
779 } /* JAVA_ASCCI_FPCHAR (c) */
781 /* Here we get back to converting the integral literal. */
782 if (c == 'L' || c == 'l')
784 else if (radix == 16 && JAVA_ASCII_LETTER (c))
785 java_lex_error ("Digit out of range in hexadecimal literal", 0);
786 else if (radix == 8 && JAVA_ASCII_DIGIT (c))
787 java_lex_error ("Digit out of range in octal literal", 0);
788 else if (radix == 16 && !literal_index)
789 java_lex_error ("No digit specified for hexadecimal literal", 0);
791 java_unget_unicode ();
793 #ifdef JAVA_LEX_DEBUG
794 literal_token [literal_index] = '\0'; /* So JAVA_LEX_LIT is safe. */
795 JAVA_LEX_LIT (literal_token, radix);
797 /* This section of code is borrowed from gcc/c-lex.c */
800 bytes = GET_TYPE_PRECISION (long_type_node);
801 for (i = bytes; i < TOTAL_PARTS; i++)
809 for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR; i++)
811 high |= ((HOST_WIDE_INT) parts[i + (HOST_BITS_PER_WIDE_INT
812 / HOST_BITS_PER_CHAR)]
813 << (i * HOST_BITS_PER_CHAR));
814 low |= (HOST_WIDE_INT) parts[i] << (i * HOST_BITS_PER_CHAR);
816 /* End borrowed section. */
821 /* 9223372036854775808L is valid if operand of a '-'. Otherwise
822 9223372036854775807L is the biggest `long' literal that can be
823 expressed using a 10 radix. For other radixes, everything that
824 fits withing 64 bits is OK. */
825 int hb = (high >> 31);
826 if (overflow || (hb && low && radix == 10) ||
827 (hb && high & 0x7fffffff && radix == 10) ||
828 (hb && !(high & 0x7fffffff) && !ctxp->minus_seen && radix == 10))
829 JAVA_INTEGRAL_RANGE_ERROR ("Numeric overflow for `long' literal");
833 /* 2147483648 is valid if operand of a '-'. Otherwise,
834 2147483647 is the biggest `int' literal that can be
835 expressed using a 10 radix. For other radixes, everything
836 that fits within 32 bits is OK. */
837 int hb = (low >> 31) & 0x1;
838 if (overflow || high || (hb && low & 0x7fffffff && radix == 10) ||
839 (hb && !(low & 0x7fffffff) && !ctxp->minus_seen && radix == 10))
840 JAVA_INTEGRAL_RANGE_ERROR ("Numeric overflow for `int' literal");
842 ctxp->minus_seen = 0;
843 SET_LVAL_NODE_TYPE (build_int_2 (low, high),
844 (long_suffix ? long_type_node : int_type_node));
848 ctxp->minus_seen = 0;
849 /* Character literals */
853 if ((c = java_get_unicode ()) == '\\')
854 char_lit = java_parse_escape_sequence ();
858 c = java_get_unicode ();
860 if ((c == '\n') || (c == UEOF))
861 java_lex_error ("Character literal not terminated at end of line", 0);
863 java_lex_error ("Syntax error in character literal", 0);
865 if (c == JAVA_CHAR_ERROR)
866 char_lit = 0; /* We silently convert it to zero */
868 JAVA_LEX_CHAR_LIT (char_lit);
869 SET_LVAL_NODE_TYPE (build_int_2 (char_lit, 0), char_type_node);
873 /* String literals */
879 for (no_error = 1, c = java_get_unicode ();
880 c != '"' && c != '\n'; c = java_get_unicode ())
883 c = java_parse_escape_sequence ();
884 no_error &= (c != JAVA_CHAR_ERROR ? 1 : 0);
886 java_unicode_2_utf8 (c);
888 if (c == '\n' || c == UEOF) /* ULT */
890 lineno--; /* Refer to the line the terminator was seen */
891 java_lex_error ("String not terminated at end of line.", 0);
895 obstack_1grow (&temporary_obstack, '\0');
896 string = obstack_finish (&temporary_obstack);
898 if (!no_error || (c != '"'))
899 java_lval->node = error_mark_node; /* Requires futher testing FIXME */
902 tree s = make_node (STRING_CST);
903 TREE_STRING_LENGTH (s) = strlen (string);
904 TREE_STRING_POINTER (s) =
905 obstack_alloc (expression_obstack, TREE_STRING_LENGTH (s)+1);
906 strcpy (TREE_STRING_POINTER (s), string);
910 return STRING_LIT_TK;
918 BUILD_OPERATOR (OP_TK);
924 if (ctxp->ccb_indent == 1)
925 ctxp->first_ccb_indent1 = lineno;
931 if (ctxp->ccb_indent == 1)
932 ctxp->last_ccb_indent1 = lineno;
936 BUILD_OPERATOR (OSB_TK);
948 BUILD_OPERATOR (DOT_TK);
956 if ((c = java_get_unicode ()) == '=')
958 BUILD_OPERATOR (EQ_TK);
962 /* Equals is used in two different locations. In the
963 variable_declarator: rule, it has to be seen as '=' as opposed
964 to being seen as an ordinary assignment operator in
965 assignment_operators: rule. */
966 java_unget_unicode ();
967 BUILD_OPERATOR (ASSIGN_TK);
971 switch ((c = java_get_unicode ()))
974 BUILD_OPERATOR (GTE_TK);
976 switch ((c = java_get_unicode ()))
979 if ((c = java_get_unicode ()) == '=')
981 BUILD_OPERATOR2 (ZRS_ASSIGN_TK);
985 java_unget_unicode ();
986 BUILD_OPERATOR (ZRS_TK);
989 BUILD_OPERATOR2 (SRS_ASSIGN_TK);
991 java_unget_unicode ();
992 BUILD_OPERATOR (SRS_TK);
995 java_unget_unicode ();
996 BUILD_OPERATOR (GT_TK);
1000 switch ((c = java_get_unicode ()))
1003 BUILD_OPERATOR (LTE_TK);
1005 if ((c = java_get_unicode ()) == '=')
1007 BUILD_OPERATOR2 (LS_ASSIGN_TK);
1011 java_unget_unicode ();
1012 BUILD_OPERATOR (LS_TK);
1015 java_unget_unicode ();
1016 BUILD_OPERATOR (LT_TK);
1020 switch ((c = java_get_unicode ()))
1023 BUILD_OPERATOR (BOOL_AND_TK);
1025 BUILD_OPERATOR2 (AND_ASSIGN_TK);
1027 java_unget_unicode ();
1028 BUILD_OPERATOR (AND_TK);
1032 switch ((c = java_get_unicode ()))
1035 BUILD_OPERATOR (BOOL_OR_TK);
1037 BUILD_OPERATOR2 (OR_ASSIGN_TK);
1039 java_unget_unicode ();
1040 BUILD_OPERATOR (OR_TK);
1044 switch ((c = java_get_unicode ()))
1047 BUILD_OPERATOR (INCR_TK);
1049 BUILD_OPERATOR2 (PLUS_ASSIGN_TK);
1051 java_unget_unicode ();
1052 BUILD_OPERATOR (PLUS_TK);
1056 switch ((c = java_get_unicode ()))
1059 BUILD_OPERATOR (DECR_TK);
1061 BUILD_OPERATOR2 (MINUS_ASSIGN_TK);
1063 java_unget_unicode ();
1064 ctxp->minus_seen = 1;
1065 BUILD_OPERATOR (MINUS_TK);
1069 if ((c = java_get_unicode ()) == '=')
1071 BUILD_OPERATOR2 (MULT_ASSIGN_TK);
1075 java_unget_unicode ();
1076 BUILD_OPERATOR (MULT_TK);
1080 if ((c = java_get_unicode ()) == '=')
1082 BUILD_OPERATOR2 (DIV_ASSIGN_TK);
1086 java_unget_unicode ();
1087 BUILD_OPERATOR (DIV_TK);
1091 if ((c = java_get_unicode ()) == '=')
1093 BUILD_OPERATOR2 (XOR_ASSIGN_TK);
1097 java_unget_unicode ();
1098 BUILD_OPERATOR (XOR_TK);
1102 if ((c = java_get_unicode ()) == '=')
1104 BUILD_OPERATOR2 (REM_ASSIGN_TK);
1108 java_unget_unicode ();
1109 BUILD_OPERATOR (REM_TK);
1113 if ((c = java_get_unicode()) == '=')
1115 BUILD_OPERATOR (NEQ_TK);
1119 java_unget_unicode ();
1120 BUILD_OPERATOR (NEG_TK);
1125 BUILD_OPERATOR (REL_QM_TK);
1128 BUILD_OPERATOR (REL_CL_TK);
1130 BUILD_OPERATOR (NOT_TK);
1133 /* Keyword, boolean literal or null literal */
1134 for (first_unicode = c, all_ascii = 1, ascii_index = 0;
1135 JAVA_ID_CHAR_P (c); c = java_get_unicode ())
1137 java_unicode_2_utf8 (c);
1138 if (all_ascii && c >= 128)
1143 obstack_1grow (&temporary_obstack, '\0');
1144 string = obstack_finish (&temporary_obstack);
1145 java_unget_unicode ();
1147 /* If we have something all ascii, we consider a keyword, a boolean
1148 literal, a null literal or an all ASCII identifier. Otherwise,
1149 this is an identifier (possibly not respecting formation rule). */
1152 struct java_keyword *kw;
1153 if ((kw=java_keyword (string, ascii_index)))
1155 JAVA_LEX_KW (string);
1158 case PUBLIC_TK: case PROTECTED_TK: case STATIC_TK:
1159 case ABSTRACT_TK: case FINAL_TK: case NATIVE_TK:
1160 case SYNCHRONIZED_TK: case TRANSIENT_TK: case VOLATILE_TK:
1162 SET_MODIFIER_CTX (kw->token);
1165 SET_LVAL_NODE (float_type_node);
1168 SET_LVAL_NODE (double_type_node);
1171 SET_LVAL_NODE (boolean_type_node);
1174 SET_LVAL_NODE (byte_type_node);
1177 SET_LVAL_NODE (short_type_node);
1180 SET_LVAL_NODE (int_type_node);
1183 SET_LVAL_NODE (long_type_node);
1186 SET_LVAL_NODE (char_type_node);
1189 /* Keyword based literals */
1192 SET_LVAL_NODE ((kw->token == TRUE_TK ?
1193 boolean_true_node : boolean_false_node));
1196 SET_LVAL_NODE (null_pointer_node);
1199 /* Some keyword we want to retain information on the location
1212 BUILD_OPERATOR (kw->token);
1220 /* We may have and ID here */
1221 if (JAVA_ID_CHAR_P(first_unicode) && !JAVA_DIGIT_P (first_unicode))
1223 JAVA_LEX_ID (string);
1224 java_lval->node = BUILD_ID_WFL (GET_IDENTIFIER (string));
1228 /* Everything else is an invalid character in the input */
1230 char lex_error_buffer [128];
1231 sprintf (lex_error_buffer, "Invalid character '%s' in input",
1232 java_sprint_unicode (ctxp->c_line, ctxp->c_line->current));
1233 java_lex_error (lex_error_buffer, 1);
1239 java_unicode_2_utf8 (unicode)
1242 if (RANGE (unicode, 0x01, 0x7f))
1243 obstack_1grow (&temporary_obstack, (char)unicode);
1244 else if (RANGE (unicode, 0x80, 0x7ff) || unicode == 0)
1246 obstack_1grow (&temporary_obstack,
1247 (unsigned char)(0xc0 | ((0x7c0 & unicode) >> 6)));
1248 obstack_1grow (&temporary_obstack,
1249 (unsigned char)(0x80 | (unicode & 0x3f)));
1251 else /* Range 0x800-0xffff */
1253 obstack_1grow (&temporary_obstack,
1254 (unsigned char)(0xe0 | (unicode & 0xf000) >> 12));
1255 obstack_1grow (&temporary_obstack,
1256 (unsigned char)(0x80 | (unicode & 0x0fc0) >> 6));
1257 obstack_1grow (&temporary_obstack,
1258 (unsigned char)(0x80 | (unicode & 0x003f) >> 12));
1264 build_wfl_node (node)
1267 return build_expr_wfl (node, ctxp->filename, ctxp->elc.line, ctxp->elc.col);
1272 java_lex_error (msg, forward)
1277 ctxp->elc.line = ctxp->c_line->lineno;
1278 ctxp->elc.col = ctxp->c_line->char_col-1+forward;
1280 /* Might be caught in the middle of some error report */
1281 ctxp->java_error_flag = 0;
1297 if (next != '\r' && next != EOF)
1308 java_get_line_col (filename, line, col)
1315 /* Dumb implementation. Doesn't try to cache or optimize things. */
1316 /* First line of the file is line 1, first column is 1 */
1318 /* COL <= 0 means, at the CR/LF in LINE */
1321 int c, ccol, cline = 1;
1322 int current_line_col = 0;
1324 if (!(fp = fopen (filename, "r")))
1325 fatal ("Can't open file - java_display_line_col");
1327 while (cline != line)
1332 static char msg[] = "<<file too short - unexpected EOF>>";
1333 obstack_grow (&temporary_obstack, msg, sizeof(msg)-1);
1336 if (java_is_eol (fp, c))
1340 /* Gather the chars of the current line in a buffer */
1344 if (c < 0 || java_is_eol (fp, c))
1346 obstack_1grow (&temporary_obstack, c);
1351 obstack_1grow (&temporary_obstack, '\n');
1354 col = current_line_col;
1356 /* Place the '^' a the right position */
1357 for (ccol = 1; ccol <= col; ccol++)
1358 obstack_1grow (&temporary_obstack, ' ');
1359 obstack_grow0 (&temporary_obstack, "^", 1);
1362 return obstack_finish (&temporary_obstack);