1 # Java tests for simple calculator. -*- Autotest -*-
3 # Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 AT_BANNER([[Java Calculator.]])
21 # ------------------------- #
22 # Helping Autotest macros. #
23 # ------------------------- #
26 # _AT_DATA_JAVA_CALC_Y($1, $2, $3, [BISON-DIRECTIVES])
27 # ----------------------------------------------------
28 # Produce `calc.y'. Don't call this macro directly, because it contains
29 # some occurrences of `$1' etc. which will be interpreted by m4. So
30 # you should call it with $1, $2, and $3 as arguments, which is what
31 # AT_DATA_JAVA_CALC_Y does.
32 m4_define([_AT_DATA_JAVA_CALC_Y],
33 [m4_if([$1$2$3], $[1]$[2]$[3], [],
34 [m4_fatal([$0: Invalid arguments: $@])])dnl
36 [[/* Infix notation calculator--calc */
39 %define parser_class_name "Calc"
45 import java.io.StreamTokenizer;
46 import java.io.InputStream;
47 import java.io.InputStreamReader;
48 import java.io.Reader;
49 import java.io.IOException;
52 /* Bison Declarations */
53 %token <Integer> NUM "number"
56 %nonassoc '=' /* comparison */
59 %left NEG /* negation--unary minus */
60 %right '^' /* exponentiation */
79 if ($1.intValue () != $3.intValue ())
80 yyerror ("calc: error: " + $1 + " != " + $3);
82 | exp '+' exp { $$ = new Integer ($1.intValue () + $3.intValue ()); }
83 | exp '-' exp { $$ = new Integer ($1.intValue () - $3.intValue ()); }
84 | exp '*' exp { $$ = new Integer ($1.intValue () * $3.intValue ()); }
85 | exp '/' exp { $$ = new Integer ($1.intValue () / $3.intValue ()); }
86 | '-' exp %prec NEG { $$ = new Integer (-$2.intValue ()); }
87 | exp '^' exp { $$ = new Integer ((int)
88 Math.pow ($1.intValue (),
90 | '(' exp ')' { $$ = $2; }
91 | '(' error ')' { $$ = new Integer (1111); }
92 | '!' { $$ = new Integer (0); return YYERROR; }
93 | '-' error { $$ = new Integer (0); return YYERROR; }
101 class CalcLexer implements Calc.Lexer {
105 public ]AT_LEXPARAM_IF([[YYLexer]], [[CalcLexer]]) (InputStream is)
107 st = new StreamTokenizer (new InputStreamReader (is));
109 st.eolIsSignificant (true);
110 st.whitespaceChars (9, 9);
111 st.whitespaceChars (32, 32);
112 st.wordChars (48, 57);
117 Position yyendpos = new Position (1);
119 public Position getStartPos() {
123 public Position getEndPos() {
127 public void yyerror (Calc.Location l, String s)
130 System.err.println (s);
132 System.err.println (l.begin + ": " + s);
135 public void yyerror (String s)
137 System.err.println (s);
143 public Object getLVal() {
147 public int yylex () throws IOException {
148 int ttype = st.nextToken ();
149 ]AT_LOCATION_IF([[yystartpos = yyendpos;]])[
150 if (ttype == st.TT_EOF)
153 else if (ttype == st.TT_EOL)
155 ]AT_LOCATION_IF([[yyendpos = new Position (yyendpos.lineno () + 1);]])[
159 else if (ttype == st.TT_WORD)
161 yylval = new Integer (st.sval);
184 public Position (int l)
189 public long getHashCode ()
194 public boolean equals (Position l)
196 return l.line == line;
199 public String toString ()
201 return Integer.toString (line);
211 ])# _AT_DATA_JAVA_CALC_Y
214 # AT_DATA_CALC_Y([BISON-OPTIONS])
215 # -------------------------------
217 m4_define([AT_DATA_JAVA_CALC_Y],
218 [_AT_DATA_JAVA_CALC_Y($[1], $[2], $[3], [$1])
223 # AT_JAVA_COMPILE(SOURCE)
224 # -----------------------
225 # Compile SOURCES into Java class files. Skip the test if java or javac is
227 m4_define([AT_JAVA_COMPILE],
229 AT_CHECK([test -n "$CONF_JAVA" || exit 77
230 test -n "$CONF_JAVAC" || exit 77])
231 AT_CHECK([$SHELL ../../../javacomp.sh $1],
232 0, [ignore], [ignore])])
235 # AT_JAVA_PARSER_CHECK(COMMAND, EXIT-STATUS, EXPOUT, EXPERR, [PRE])
236 # -----------------------------------------------------------------
237 m4_define([AT_JAVA_PARSER_CHECK],
238 [AT_CHECK([$5 $SHELL ../../../javaexec.sh $1], [$2], [$3], [$4])])
241 # _AT_CHECK_JAVA_CALC_ERROR(BISON-OPTIONS, INPUT,
242 # [VERBOSE-AND-LOCATED-ERROR-MESSAGE])
243 # ---------------------------------------------------------
244 # Run `calc' on INPUT, and expect a `syntax error' message.
246 # If INPUT starts with a slash, it is used as absolute input file name,
247 # otherwise as contents.
249 # The VERBOSE-AND-LOCATED-ERROR-MESSAGE is stripped of locations
250 # and expected tokens if necessary, and compared with the output.
251 m4_define([_AT_CHECK_JAVA_CALC_ERROR],
252 [m4_bmatch([$2], [^/],
253 [AT_JAVA_PARSER_CHECK([Calc < $2], 0, [], [stderr])],
257 AT_JAVA_PARSER_CHECK([Calc < input], 0, [], [stderr])])
259 # Normalize the observed and expected error messages, depending upon the
261 # 1. Create the reference error message.
265 # 2. If locations are not used, remove them.
266 AT_YYERROR_SEES_LOC_IF([],
267 [[sed 's/^[-0-9.]*: //' expout >at-expout
268 mv at-expout expout]])
269 # 3. If error-verbose is not used, strip the`, unexpected....' part.
270 m4_bmatch([$1], [%error-verbose], [],
271 [[sed 's/syntax error, .*$/syntax error/' expout >at-expout
272 mv at-expout expout]])
274 AT_CHECK([cat stderr], 0, [expout])
277 # _AT_CHECK_JAVA_CALC([BISON-DIRECTIVES], [BISON-CODE])
278 # -----------------------------------------------------
279 # Start a testing chunk which compiles `calc' grammar with
280 # BISON-DIRECTIVES, and performs several tests over the parser.
281 m4_define([_AT_CHECK_JAVA_CALC],
282 [# We use integers to avoid dependencies upon the precision of doubles.
283 AT_SETUP([Calculator $1])
285 AT_BISON_OPTION_PUSHDEFS([$1])
287 AT_DATA_JAVA_CALC_Y([$1
292 AT_BISON_CHECK([-o Calc.java Calc.y])
293 AT_JAVA_COMPILE([Calc.java])
295 # Test the priorities.
311 AT_JAVA_PARSER_CHECK([Calc < input], 0, [], [stderr])
314 # Some syntax errors.
315 _AT_CHECK_JAVA_CALC_ERROR([$1], [0 0],
316 [1: syntax error, unexpected number])
317 _AT_CHECK_JAVA_CALC_ERROR([$1], [1//2],
318 [1: syntax error, unexpected '/', expecting number or '-' or '(' or '!'])
319 _AT_CHECK_JAVA_CALC_ERROR([$1], [error],
320 [1: syntax error, unexpected $undefined])
321 _AT_CHECK_JAVA_CALC_ERROR([$1], [1 = 2 = 3],
322 [1: syntax error, unexpected '='])
323 _AT_CHECK_JAVA_CALC_ERROR([$1], [
325 [2: syntax error, unexpected '+'])
326 # Exercise error messages with EOF: work on an empty file.
327 _AT_CHECK_JAVA_CALC_ERROR([$1], [/dev/null],
328 [1: syntax error, unexpected end of input])
330 # Exercise the error token: without it, we die at the first error,
333 # - have several errors which exercise different shift/discardings
334 # - (): nothing to pop, nothing to discard
335 # - (1 + 1 + 1 +): a lot to pop, nothing to discard
336 # - (* * *): nothing to pop, a lot to discard
337 # - (1 + 2 * *): some to pop and discard
339 # - test the action associated to `error'
341 # - check the lookahead that triggers an error is not discarded
342 # when we enter error recovery. Below, the lookahead causing the
343 # first error is ")", which is needed to recover from the error and
344 # produce the "0" that triggers the "0 != 1" error.
346 _AT_CHECK_JAVA_CALC_ERROR([$1],
347 [() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1],
348 [1: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
349 1: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
350 1: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
351 1: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
352 calc: error: 4444 != 1])
354 # The same, but this time exercising explicitly triggered syntax errors.
355 # POSIX says the lookahead causing the error should not be discarded.
356 _AT_CHECK_JAVA_CALC_ERROR([$1], [(!) + (0 0) = 1],
357 [1: syntax error, unexpected number
358 calc: error: 2222 != 1])
359 _AT_CHECK_JAVA_CALC_ERROR([$1], [(- *) + (0 0) = 1],
360 [1: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
361 1: syntax error, unexpected number
362 calc: error: 2222 != 1])
363 AT_BISON_OPTION_POPDEFS
366 ])# _AT_CHECK_JAVA_CALC
369 # AT_CHECK_JAVA_CALC([BISON-DIRECTIVES])
370 # --------------------------------------
371 # Start a testing chunk which compiles `calc' grammar with
372 # BISON-DIRECTIVES, and performs several tests over the parser.
373 # Run the test with and without %error-verbose.
374 m4_define([AT_CHECK_JAVA_CALC],
375 [_AT_CHECK_JAVA_CALC([$1], [$2])
376 _AT_CHECK_JAVA_CALC([%error-verbose $1], [$2])
377 _AT_CHECK_JAVA_CALC([%locations $1], [$2])
378 _AT_CHECK_JAVA_CALC([%error-verbose %locations $1], [$2])
379 ])# AT_CHECK_JAVA_CALC
382 # ------------------------ #
383 # Simple LALR Calculator. #
384 # ------------------------ #
386 AT_CHECK_JAVA_CALC([], [[
387 public static void main (String args[]) throws IOException
389 CalcLexer l = new CalcLexer (System.in);
390 Calc p = new Calc (l);
395 AT_CHECK_JAVA_CALC([%lex-param { InputStream is } ], [[
396 public static void main (String args[]) throws IOException
398 new Calc (System.in).parse ();
408 AT_BANNER([Java Parameters.])
411 # AT_CHECK_JAVA_MINIMAL([DIRECTIVES], [PARSER_ACTION], [POSITION_CLASS])
412 # ----------------------------------------------------------------------
413 # Check that a mininal parser with DIRECTIVES compiles in Java.
414 # Put the Java code in YYParser.java.
415 m4_define([AT_CHECK_JAVA_MINIMAL],
417 AT_DATA([[YYParser.y]], [
428 class m4_default([$3], [Position]) {}
430 AT_BISON_CHECK([[YYParser.y]])
431 AT_CHECK([[grep '[mb]4_' YYParser.y]], [1], [ignore])
432 AT_JAVA_COMPILE([[YYParser.java]])
436 # AT_CHECK_JAVA_MINIMAL_W_LEXER([1:DIRECTIVES], [2:LEX_THROWS],
437 # [3:YYLEX_ACTION], [4:LEXER_BODY], [5:PARSER_ACTION], [6:STYPE],
438 # [7:POSITION_TYPE], [8:LOCATION_TYPE])
439 # ---------------------------------------------------------------------
440 # Check that a mininal parser with DIRECTIVES and a "%code lexer".
441 # YYLEX is the body of yylex () which throws LEX_THROW.
443 m4_define([AT_CHECK_JAVA_MINIMAL_W_LEXER],
444 [AT_CHECK_JAVA_MINIMAL([$1
448 m4_default([$6], [Object]) yylval;
449 public m4_default([$6], [Object]) getLVal() { return yylval; }
451 public m4_default([$7], [Position]) getStartPos() { return null; }
452 public m4_default([$7], [Position]) getEndPos() { return null; }
454 public void yyerror (m4_default([$8], [Location]) loc, String s)
456 System.err.println (loc + ": " + s);
459 public int yylex ()$2
468 # AT_CHECK_JAVA_GREP([LINE], [COUNT=1])
469 # -------------------------------------
470 # Check that YYParser.java contains exactly COUNT lines matching ^LINE$
472 m4_define([AT_CHECK_JAVA_GREP],
473 [AT_CHECK([grep -c '^$1$' YYParser.java], [], [m4_default([$2], [1])
478 # ------------------------------------- #
479 # Java parser class and package names. #
480 # ------------------------------------- #
482 AT_SETUP([Java parser class and package names])
484 AT_CHECK_JAVA_MINIMAL([])
485 AT_CHECK_JAVA_GREP([[class YYParser]])
487 AT_CHECK_JAVA_MINIMAL([[%name-prefix "Prefix"]])
488 AT_CHECK_JAVA_GREP([[class PrefixParser]])
490 AT_CHECK_JAVA_MINIMAL([[%define api.tokens.prefix "TOK_"]])
491 AT_CHECK_JAVA_GREP([[.*TOK_END.*]])
493 AT_CHECK_JAVA_MINIMAL([[%define parser_class_name "ParserClassName"]])
494 AT_CHECK_JAVA_GREP([[class ParserClassName]])
496 AT_CHECK_JAVA_MINIMAL([[%define package "user_java_package"]])
497 AT_CHECK_JAVA_GREP([[package user_java_package;]])
502 # ----------------------------- #
503 # Java parser class modifiers. #
504 # ----------------------------- #
506 AT_SETUP([Java parser class modifiers])
508 AT_CHECK_JAVA_MINIMAL([[%define abstract]])
509 AT_CHECK_JAVA_GREP([[abstract class YYParser]])
511 AT_CHECK_JAVA_MINIMAL([[%define final]])
512 AT_CHECK_JAVA_GREP([[final class YYParser]])
514 AT_CHECK_JAVA_MINIMAL([[%define strictfp]])
515 AT_CHECK_JAVA_GREP([[strictfp class YYParser]])
517 AT_CHECK_JAVA_MINIMAL([[
520 AT_CHECK_JAVA_GREP([[abstract strictfp class YYParser]])
522 AT_CHECK_JAVA_MINIMAL([[
525 AT_CHECK_JAVA_GREP([[final strictfp class YYParser]])
527 AT_CHECK_JAVA_MINIMAL([[%define public]])
528 AT_CHECK_JAVA_GREP([[public class YYParser]])
530 AT_CHECK_JAVA_MINIMAL([[
533 AT_CHECK_JAVA_GREP([[public abstract class YYParser]])
535 AT_CHECK_JAVA_MINIMAL([[
538 AT_CHECK_JAVA_GREP([[public final class YYParser]])
540 AT_CHECK_JAVA_MINIMAL([[
543 AT_CHECK_JAVA_GREP([[public strictfp class YYParser]])
545 AT_CHECK_JAVA_MINIMAL([[
549 AT_CHECK_JAVA_GREP([[public abstract strictfp class YYParser]])
551 AT_CHECK_JAVA_MINIMAL([[
555 AT_CHECK_JAVA_GREP([[public final strictfp class YYParser]])
557 # FIXME: Can't do a Java compile because javacomp.sh is configured for 1.3
558 AT_CHECK_JAVA_MINIMAL([[
559 %define annotations "/*@Deprecated @SupressWarnings(\"unchecked\") @SupressWarnings({\"unchecked\", \"deprecation\"}) @SupressWarnings(value={\"unchecked\", \"deprecation\"})*/"
561 AT_CHECK_JAVA_GREP([[/\*@Deprecated @SupressWarnings("unchecked") @SupressWarnings({"unchecked", "deprecation"}) @SupressWarnings(value={"unchecked", "deprecation"})\*/ public class YYParser]])
566 # ---------------------------------------- #
567 # Java parser class extends and implements #
568 # ---------------------------------------- #
570 AT_SETUP([Java parser class extends and implements])
572 AT_CHECK_JAVA_MINIMAL([[%define extends "Thread"]])
573 AT_CHECK_JAVA_GREP([[class YYParser extends Thread]])
575 AT_CHECK_JAVA_MINIMAL([[%define implements "Cloneable"]])
576 AT_CHECK_JAVA_GREP([[class YYParser implements Cloneable]])
578 AT_CHECK_JAVA_MINIMAL([[
579 %define extends "Thread"
580 %define implements "Cloneable"]])
581 AT_CHECK_JAVA_GREP([[class YYParser extends Thread implements Cloneable]])
586 # -------------------------------- #
587 # Java %parse-param and %lex-param #
588 # -------------------------------- #
590 AT_SETUP([Java %parse-param and %lex-param])
592 AT_CHECK_JAVA_MINIMAL([])
593 AT_CHECK_JAVA_GREP([[ *public YYParser (Lexer yylexer) *]])
595 AT_CHECK_JAVA_MINIMAL([[%parse-param {int parse_param1}]])
596 AT_CHECK_JAVA_GREP([[ *protected final int parse_param1;]])
597 AT_CHECK_JAVA_GREP([[ *public YYParser (Lexer yylexer, *int parse_param1) *]])
598 AT_CHECK_JAVA_GREP([[ *this.parse_param1 = parse_param1;]])
600 AT_CHECK_JAVA_MINIMAL([[
601 %parse-param {int parse_param1}
602 %parse-param {long parse_param2}]])
603 AT_CHECK_JAVA_GREP([[ *protected final int parse_param1;]])
604 AT_CHECK_JAVA_GREP([[ *protected final long parse_param2;]])
605 AT_CHECK_JAVA_GREP([[ *public YYParser (Lexer yylexer, *int parse_param1, *long parse_param2) *]])
606 AT_CHECK_JAVA_GREP([[ *this.parse_param1 = parse_param1;]])
607 AT_CHECK_JAVA_GREP([[ *this.parse_param2 = parse_param2;]])
609 AT_CHECK_JAVA_MINIMAL_W_LEXER([], [], [[return EOF;]])
610 AT_CHECK_JAVA_GREP([[ *public YYParser () *]])
611 AT_CHECK_JAVA_GREP([[ *protected YYParser (Lexer yylexer) *]])
613 AT_CHECK_JAVA_MINIMAL_W_LEXER([[%parse-param {int parse_param1}]],
615 AT_CHECK_JAVA_GREP([[ *protected final int parse_param1;]])
616 AT_CHECK_JAVA_GREP([[ *public YYParser (int parse_param1) *]])
617 AT_CHECK_JAVA_GREP([[ *protected YYParser (Lexer yylexer, *int parse_param1) *]])
618 AT_CHECK_JAVA_GREP([[ *this.parse_param1 = parse_param1;]], [2])
620 AT_CHECK_JAVA_MINIMAL_W_LEXER([[
621 %parse-param {int parse_param1}
622 %parse-param {long parse_param2}]],
624 AT_CHECK_JAVA_GREP([[ *protected final int parse_param1;]])
625 AT_CHECK_JAVA_GREP([[ *protected final long parse_param2;]])
626 AT_CHECK_JAVA_GREP([[ *public YYParser (int parse_param1, *long parse_param2) *]])
627 AT_CHECK_JAVA_GREP([[ *protected YYParser (Lexer yylexer, *int parse_param1, *long parse_param2) *]])
628 AT_CHECK_JAVA_GREP([[ *this.parse_param1 = parse_param1;]], [2])
629 AT_CHECK_JAVA_GREP([[ *this.parse_param2 = parse_param2;]], [2])
631 AT_CHECK_JAVA_MINIMAL_W_LEXER([[%lex-param {char lex_param1}]],
632 [], [[return EOF;]], [[YYLexer (char lex_param1) {}]])
633 AT_CHECK_JAVA_GREP([[ *public YYParser (char lex_param1) *]])
634 AT_CHECK_JAVA_GREP([[.* = new YYLexer *(lex_param1);]])
636 AT_CHECK_JAVA_MINIMAL_W_LEXER([[
637 %lex-param {char lex_param1}
638 %lex-param {short lex_param2}]],
639 [], [[return EOF;]], [[YYLexer (char lex_param1, short lex_param2) {}]])
640 AT_CHECK_JAVA_GREP([[ *public YYParser (char lex_param1, *short lex_param2) *]])
641 AT_CHECK_JAVA_GREP([[.* = new YYLexer *(lex_param1, *lex_param2);]])
643 AT_CHECK_JAVA_MINIMAL_W_LEXER([[
644 %parse-param {int parse_param1}
645 %parse-param {long parse_param2}
646 %lex-param {char lex_param1}
647 %lex-param {short lex_param2}]],
648 [], [[return EOF;]], [[YYLexer (char lex_param1, short lex_param2) {}]])
649 AT_CHECK_JAVA_GREP([[ *protected final int parse_param1;]])
650 AT_CHECK_JAVA_GREP([[ *protected final long parse_param2;]])
651 AT_CHECK_JAVA_GREP([[ *public YYParser (char lex_param1, *short lex_param2, *int parse_param1, *long parse_param2) *]])
652 AT_CHECK_JAVA_GREP([[.* = new YYLexer *(lex_param1, *lex_param2);]])
653 AT_CHECK_JAVA_GREP([[ *protected YYParser (Lexer yylexer, *int parse_param1, *long parse_param2) *]])
654 AT_CHECK_JAVA_GREP([[ *this.parse_param1 = parse_param1;]], [2])
655 AT_CHECK_JAVA_GREP([[ *this.parse_param2 = parse_param2;]], [2])
660 # ------------------------- #
661 # Java throw specifications #
662 # ------------------------- #
664 AT_SETUP([Java throws specifications])
666 # %define throws - 0 1 2
667 # %define lex-throws - 0 1 2
670 m4_define([AT_JT_lex_throws_define], [m4_case(AT_JT_lex_throws,
672 0, [[%define lex_throws ""]],
673 1, [[%define lex_throws "InterruptedException"]],
674 2, [[%define lex_throws "InterruptedException, IllegalAccessException"]])])
676 m4_define([AT_JT_yylex_throws], [m4_case(AT_JT_lex_throws,
677 -1, [[ throws java.io.IOException]],
679 1, [[ throws InterruptedException]],
680 2, [[ throws InterruptedException, IllegalAccessException]])])
682 m4_define([AT_JT_yylex_action], [m4_case(AT_JT_lex_throws,
683 -1, [[throw new java.io.IOException();]],
685 1, [[throw new InterruptedException();]],
686 2, [[throw new IllegalAccessException();]])])
689 m4_define([AT_JT_throws_define], [m4_case(AT_JT_throws,
691 0, [[%define throws ""]],
692 1, [[%define throws "ClassNotFoundException"]],
693 2, [[%define throws "ClassNotFoundException, InstantiationException"]])])
695 m4_define([AT_JT_yyaction_throws], [m4_case(AT_JT_throws,
698 1, [[ throws ClassNotFoundException]],
699 2, [[ throws ClassNotFoundException, InstantiationException]])])
701 m4_define([AT_JT_parse_throws_2], [m4_case(AT_JT_throws,
704 1, [[, ClassNotFoundException]],
705 2, [[, ClassNotFoundException, InstantiationException]])])
707 m4_define([AT_JT_parse_throws],
708 [m4_if(m4_quote(AT_JT_yylex_throws), [],
709 [AT_JT_yyaction_throws],
710 [AT_JT_yylex_throws[]AT_JT_parse_throws_2])])
712 m4_define([AT_JT_initial_action], [m4_case(AT_JT_throws,
715 1, [[%initial-action {if (true) throw new ClassNotFoundException();}]],
716 2, [[%initial-action {if (true) throw new InstantiationException();}]])])
718 m4_define([AT_JT_parse_action], [m4_case(AT_JT_throws,
721 1, [[throw new ClassNotFoundException();]],
722 2, [[throw new ClassNotFoundException();]])])
724 m4_for([AT_JT_lexer], 0, 1, 1,
725 [m4_for([AT_JT_lex_throws], -1, 2, 1,
726 [m4_for([AT_JT_throws], -1, 2, 1,
727 [m4_if(AT_JT_lexer, 0,
728 [AT_CHECK_JAVA_MINIMAL([
730 AT_JT_lex_throws_define
731 AT_JT_initial_action],
732 [AT_JT_parse_action])],
733 [AT_CHECK_JAVA_MINIMAL_W_LEXER([
735 AT_JT_lex_throws_define
736 AT_JT_initial_action],
737 [AT_JT_yylex_throws],
738 [AT_JT_yylex_action],
740 [AT_JT_parse_action])])
741 AT_CHECK_JAVA_GREP([[ *int yylex ()]AT_JT_yylex_throws *[;]])
742 AT_CHECK_JAVA_GREP([[ *private int yyaction ([^)]*)]AT_JT_yyaction_throws[ *]])
743 AT_CHECK_JAVA_GREP([[ *public boolean parse ()]AT_JT_parse_throws[ *]])
749 # ------------------------------------- #
750 # Java constructor init and init_throws #
751 # ------------------------------------- #
753 AT_SETUP([Java constructor init and init_throws])
755 AT_CHECK_JAVA_MINIMAL([[
756 %define extends "Thread"
757 %code init { super("Test Thread"); if (true) throw new InterruptedException(); }
758 %define init_throws "InterruptedException"
759 %lex-param {int lex_param}]])
760 AT_CHECK([[grep -q 'super("Test Thread"); if (true) throw new InterruptedException();' YYParser.java]])
762 AT_CHECK_JAVA_MINIMAL_W_LEXER([[
763 %define extends "Thread"
764 %code init { super("Test Thread"); if (true) throw new InterruptedException(); }
765 %define init_throws "InterruptedException"]], [], [[return EOF;]])
766 AT_CHECK([[grep -q 'super("Test Thread"); if (true) throw new InterruptedException();' YYParser.java]])
771 # --------------------------------------------- #
772 # Java stype, position_class and location_class #
773 # --------------------------------------------- #
775 AT_SETUP([Java stype, position_class and location_class])
777 AT_CHECK_JAVA_MINIMAL([[
778 %define stype "java.awt.Color"
779 %type<java.awt.Color> start;
780 %define location_type "MyLoc"
781 %define position_type "MyPos"
782 %code { class MyPos {} }]], [[$$ = $<java.awt.Color>1;]], [[MyPos]])
783 AT_CHECK([[grep 'java.awt.Color' YYParser.java]], [0], [ignore])
784 AT_CHECK([[$EGREP -v ' */?\*' YYParser.java | grep 'Position']], [1], [ignore])
785 AT_CHECK([[$EGREP -v ' */?\*' YYParser.java | grep 'Location']], [1], [ignore])
787 AT_CHECK_JAVA_MINIMAL_W_LEXER([[
788 %define stype "java.awt.Color"
789 %type<java.awt.Color> start;
790 %define location_type "MyLoc"
791 %define position_type "MyPos"
792 %code { class MyPos {} }]], [], [[return EOF;]], [],
793 [[$$ = $<java.awt.Color>1;]],
794 [[java.awt.Color]], [[MyPos]], [[MyLoc]])
795 AT_CHECK([[grep 'java.awt.Color' YYParser.java]], [0], [ignore])
796 AT_CHECK([[$EGREP -v ' */?\*' YYParser.java | grep 'Position']], [1], [ignore])
797 AT_CHECK([[$EGREP -v ' */?\*' YYParser.java | grep 'Location']], [1], [ignore])