xref: /openbsd/gnu/usr.bin/gcc/gcc/java/parse-scan.y (revision c87b03e5)
1*c87b03e5Sespie /* Parser grammar for quick source code scan of Java(TM) language programs.
2*c87b03e5Sespie    Copyright (C) 1998, 1999, 2000, 2002 Free Software Foundation, Inc.
3*c87b03e5Sespie    Contributed by Alexandre Petit-Bianco (apbianco@cygnus.com)
4*c87b03e5Sespie 
5*c87b03e5Sespie This file is part of GNU CC.
6*c87b03e5Sespie 
7*c87b03e5Sespie GNU CC is free software; you can redistribute it and/or modify
8*c87b03e5Sespie it under the terms of the GNU General Public License as published by
9*c87b03e5Sespie the Free Software Foundation; either version 2, or (at your option)
10*c87b03e5Sespie any later version.
11*c87b03e5Sespie 
12*c87b03e5Sespie GNU CC is distributed in the hope that it will be useful,
13*c87b03e5Sespie but WITHOUT ANY WARRANTY; without even the implied warranty of
14*c87b03e5Sespie MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*c87b03e5Sespie GNU General Public License for more details.
16*c87b03e5Sespie 
17*c87b03e5Sespie You should have received a copy of the GNU General Public License
18*c87b03e5Sespie along with GNU CC; see the file COPYING.  If not, write to
19*c87b03e5Sespie the Free Software Foundation, 59 Temple Place - Suite 330,
20*c87b03e5Sespie Boston, MA 02111-1307, USA.
21*c87b03e5Sespie 
22*c87b03e5Sespie Java and all Java-based marks are trademarks or registered trademarks
23*c87b03e5Sespie of Sun Microsystems, Inc. in the United States and other countries.
24*c87b03e5Sespie The Free Software Foundation is independent of Sun Microsystems, Inc.  */
25*c87b03e5Sespie 
26*c87b03e5Sespie /* This file parses Java source code. Action can be further completed
27*c87b03e5Sespie to achieve a desired behavior. This file isn't part of the Java
28*c87b03e5Sespie language gcc front end.
29*c87b03e5Sespie 
30*c87b03e5Sespie The grammar conforms to the Java grammar described in "The Java(TM)
31*c87b03e5Sespie Language Specification. J. Gosling, B. Joy, G. Steele. Addison Wesley
32*c87b03e5Sespie 1996, ISBN 0-201-63451-1"
33*c87b03e5Sespie 
34*c87b03e5Sespie Some rules have been modified to support JDK1.1 inner classes
35*c87b03e5Sespie definitions and other extensions.  */
36*c87b03e5Sespie 
37*c87b03e5Sespie %{
38*c87b03e5Sespie #define JC1_LITE
39*c87b03e5Sespie 
40*c87b03e5Sespie #include "config.h"
41*c87b03e5Sespie #include "system.h"
42*c87b03e5Sespie 
43*c87b03e5Sespie #include "obstack.h"
44*c87b03e5Sespie #include "toplev.h"
45*c87b03e5Sespie 
46*c87b03e5Sespie #define obstack_chunk_alloc xmalloc
47*c87b03e5Sespie #define obstack_chunk_free free
48*c87b03e5Sespie 
49*c87b03e5Sespie extern char *input_filename;
50*c87b03e5Sespie extern FILE *finput, *out;
51*c87b03e5Sespie 
52*c87b03e5Sespie /* Obstack for the lexer.  */
53*c87b03e5Sespie struct obstack temporary_obstack;
54*c87b03e5Sespie 
55*c87b03e5Sespie /* The current parser context.  */
56*c87b03e5Sespie static struct parser_ctxt *ctxp;
57*c87b03e5Sespie 
58*c87b03e5Sespie /* Error and warning counts, current line number, because they're used
59*c87b03e5Sespie    elsewhere  */
60*c87b03e5Sespie int java_error_count;
61*c87b03e5Sespie int java_warning_count;
62*c87b03e5Sespie int lineno;
63*c87b03e5Sespie 
64*c87b03e5Sespie /* Tweak default rules when necessary.  */
65*c87b03e5Sespie static int absorber;
66*c87b03e5Sespie #define USE_ABSORBER absorber = 0
67*c87b03e5Sespie 
68*c87b03e5Sespie /* Keep track of the current package name.  */
69*c87b03e5Sespie static const char *package_name;
70*c87b03e5Sespie 
71*c87b03e5Sespie /* Keep track of whether things have be listed before.  */
72*c87b03e5Sespie static int previous_output;
73*c87b03e5Sespie 
74*c87b03e5Sespie /* Record modifier uses  */
75*c87b03e5Sespie static int modifier_value;
76*c87b03e5Sespie 
77*c87b03e5Sespie /* Record (almost) cyclomatic complexity.  */
78*c87b03e5Sespie static int complexity;
79*c87b03e5Sespie 
80*c87b03e5Sespie /* Keeps track of number of bracket pairs after a variable declarator
81*c87b03e5Sespie    id.  */
82*c87b03e5Sespie static int bracket_count;
83*c87b03e5Sespie 
84*c87b03e5Sespie /* Numbers anonymous classes */
85*c87b03e5Sespie static int anonymous_count;
86*c87b03e5Sespie 
87*c87b03e5Sespie /* This is used to record the current class context.  */
88*c87b03e5Sespie struct class_context
89*c87b03e5Sespie {
90*c87b03e5Sespie   char *name;
91*c87b03e5Sespie   struct class_context *next;
92*c87b03e5Sespie };
93*c87b03e5Sespie 
94*c87b03e5Sespie /* The global class context.  */
95*c87b03e5Sespie static struct class_context *current_class_context;
96*c87b03e5Sespie 
97*c87b03e5Sespie /* A special constant used to represent an anonymous context.  */
98*c87b03e5Sespie static const char *anonymous_context = "ANONYMOUS";
99*c87b03e5Sespie 
100*c87b03e5Sespie /* Count of method depth.  */
101*c87b03e5Sespie static int method_depth;
102*c87b03e5Sespie 
103*c87b03e5Sespie /* Record a method declaration  */
104*c87b03e5Sespie struct method_declarator {
105*c87b03e5Sespie   const char *method_name;
106*c87b03e5Sespie   const char *args;
107*c87b03e5Sespie };
108*c87b03e5Sespie #define NEW_METHOD_DECLARATOR(D,N,A)					     \
109*c87b03e5Sespie {									     \
110*c87b03e5Sespie   (D) = 								     \
111*c87b03e5Sespie     (struct method_declarator *)xmalloc (sizeof (struct method_declarator)); \
112*c87b03e5Sespie   (D)->method_name = (N);						     \
113*c87b03e5Sespie   (D)->args = (A);							     \
114*c87b03e5Sespie }
115*c87b03e5Sespie 
116*c87b03e5Sespie /* Two actions for this grammar */
117*c87b03e5Sespie static int make_class_name_recursive PARAMS ((struct obstack *stack,
118*c87b03e5Sespie 					      struct class_context *ctx));
119*c87b03e5Sespie static char *get_class_name PARAMS ((void));
120*c87b03e5Sespie static void report_class_declaration PARAMS ((const char *));
121*c87b03e5Sespie static void report_main_declaration PARAMS ((struct method_declarator *));
122*c87b03e5Sespie static void push_class_context PARAMS ((const char *));
123*c87b03e5Sespie static void pop_class_context PARAMS ((void));
124*c87b03e5Sespie 
125*c87b03e5Sespie void report PARAMS ((void));
126*c87b03e5Sespie 
127*c87b03e5Sespie #include "lex.h"
128*c87b03e5Sespie #include "parse.h"
129*c87b03e5Sespie %}
130*c87b03e5Sespie 
131*c87b03e5Sespie %union {
132*c87b03e5Sespie   char *node;
133*c87b03e5Sespie   struct method_declarator *declarator;
134*c87b03e5Sespie   int value;			/* For modifiers */
135*c87b03e5Sespie }
136*c87b03e5Sespie 
137*c87b03e5Sespie %{
138*c87b03e5Sespie extern int flag_assert;
139*c87b03e5Sespie 
140*c87b03e5Sespie #include "lex.c"
141*c87b03e5Sespie %}
142*c87b03e5Sespie 
143*c87b03e5Sespie %pure_parser
144*c87b03e5Sespie 
145*c87b03e5Sespie /* Things defined here have to match the order of what's in the
146*c87b03e5Sespie    binop_lookup table.  */
147*c87b03e5Sespie 
148*c87b03e5Sespie %token   PLUS_TK         MINUS_TK        MULT_TK         DIV_TK    REM_TK
149*c87b03e5Sespie %token   LS_TK           SRS_TK          ZRS_TK
150*c87b03e5Sespie %token   AND_TK          XOR_TK          OR_TK
151*c87b03e5Sespie %token   BOOL_AND_TK BOOL_OR_TK
152*c87b03e5Sespie %token   EQ_TK NEQ_TK GT_TK GTE_TK LT_TK LTE_TK
153*c87b03e5Sespie 
154*c87b03e5Sespie /* This maps to the same binop_lookup entry than the token above */
155*c87b03e5Sespie 
156*c87b03e5Sespie %token   PLUS_ASSIGN_TK  MINUS_ASSIGN_TK MULT_ASSIGN_TK DIV_ASSIGN_TK
157*c87b03e5Sespie %token   REM_ASSIGN_TK
158*c87b03e5Sespie %token   LS_ASSIGN_TK    SRS_ASSIGN_TK   ZRS_ASSIGN_TK
159*c87b03e5Sespie %token   AND_ASSIGN_TK   XOR_ASSIGN_TK   OR_ASSIGN_TK
160*c87b03e5Sespie 
161*c87b03e5Sespie 
162*c87b03e5Sespie /* Modifier TOKEN have to be kept in this order. Don't scramble it */
163*c87b03e5Sespie 
164*c87b03e5Sespie %token   PUBLIC_TK       PRIVATE_TK         PROTECTED_TK
165*c87b03e5Sespie %token   STATIC_TK       FINAL_TK           SYNCHRONIZED_TK
166*c87b03e5Sespie %token   VOLATILE_TK     TRANSIENT_TK       NATIVE_TK
167*c87b03e5Sespie %token   PAD_TK          ABSTRACT_TK        MODIFIER_TK
168*c87b03e5Sespie %token   STRICT_TK
169*c87b03e5Sespie 
170*c87b03e5Sespie /* Keep those two in order, too */
171*c87b03e5Sespie %token   DECR_TK INCR_TK
172*c87b03e5Sespie 
173*c87b03e5Sespie /* From now one, things can be in any order */
174*c87b03e5Sespie 
175*c87b03e5Sespie %token   DEFAULT_TK      IF_TK              THROW_TK
176*c87b03e5Sespie %token   BOOLEAN_TK      DO_TK              IMPLEMENTS_TK
177*c87b03e5Sespie %token   THROWS_TK       BREAK_TK           IMPORT_TK
178*c87b03e5Sespie %token   ELSE_TK         INSTANCEOF_TK      RETURN_TK
179*c87b03e5Sespie %token   VOID_TK         CATCH_TK           INTERFACE_TK
180*c87b03e5Sespie %token   CASE_TK         EXTENDS_TK         FINALLY_TK
181*c87b03e5Sespie %token   SUPER_TK        WHILE_TK           CLASS_TK
182*c87b03e5Sespie %token   SWITCH_TK       CONST_TK           TRY_TK
183*c87b03e5Sespie %token   FOR_TK          NEW_TK             CONTINUE_TK
184*c87b03e5Sespie %token   GOTO_TK         PACKAGE_TK         THIS_TK
185*c87b03e5Sespie %token   ASSERT_TK
186*c87b03e5Sespie 
187*c87b03e5Sespie %token   BYTE_TK         SHORT_TK           INT_TK            LONG_TK
188*c87b03e5Sespie %token   CHAR_TK         INTEGRAL_TK
189*c87b03e5Sespie 
190*c87b03e5Sespie %token   FLOAT_TK        DOUBLE_TK          FP_TK
191*c87b03e5Sespie 
192*c87b03e5Sespie %token   ID_TK
193*c87b03e5Sespie 
194*c87b03e5Sespie %token   REL_QM_TK         REL_CL_TK NOT_TK  NEG_TK
195*c87b03e5Sespie 
196*c87b03e5Sespie %token   ASSIGN_ANY_TK   ASSIGN_TK
197*c87b03e5Sespie %token   OP_TK  CP_TK  OCB_TK  CCB_TK  OSB_TK  CSB_TK  SC_TK  C_TK DOT_TK
198*c87b03e5Sespie 
199*c87b03e5Sespie %token   STRING_LIT_TK   CHAR_LIT_TK        INT_LIT_TK        FP_LIT_TK
200*c87b03e5Sespie %token   TRUE_TK         FALSE_TK           BOOL_LIT_TK       NULL_TK
201*c87b03e5Sespie 
202*c87b03e5Sespie %type <node> ID_TK identifier name simple_name qualified_name type
203*c87b03e5Sespie  	     primitive_type reference_type array_type formal_parameter_list
204*c87b03e5Sespie 	     formal_parameter class_or_interface_type class_type interface_type
205*c87b03e5Sespie %type <declarator> method_declarator
206*c87b03e5Sespie %type <value>      MODIFIER_TK
207*c87b03e5Sespie 
208*c87b03e5Sespie %%
209*c87b03e5Sespie /* 19.2 Production from 2.3: The Syntactic Grammar  */
210*c87b03e5Sespie goal:
211*c87b03e5Sespie 	compilation_unit
212*c87b03e5Sespie ;
213*c87b03e5Sespie 
214*c87b03e5Sespie /* 19.3 Productions from 3: Lexical structure  */
215*c87b03e5Sespie literal:
216*c87b03e5Sespie 	INT_LIT_TK
217*c87b03e5Sespie |	FP_LIT_TK
218*c87b03e5Sespie |	BOOL_LIT_TK
219*c87b03e5Sespie |	CHAR_LIT_TK
220*c87b03e5Sespie |       STRING_LIT_TK
221*c87b03e5Sespie |       NULL_TK
222*c87b03e5Sespie ;
223*c87b03e5Sespie 
224*c87b03e5Sespie /* 19.4 Productions from 4: Types, Values and Variables  */
225*c87b03e5Sespie type:
226*c87b03e5Sespie 	primitive_type
227*c87b03e5Sespie |	reference_type
228*c87b03e5Sespie ;
229*c87b03e5Sespie 
230*c87b03e5Sespie primitive_type:
231*c87b03e5Sespie 	INTEGRAL_TK
232*c87b03e5Sespie 		{
233*c87b03e5Sespie 		  /* use preset global here. FIXME */
234*c87b03e5Sespie 		  $$ = xstrdup ("int");
235*c87b03e5Sespie 		}
236*c87b03e5Sespie |	FP_TK
237*c87b03e5Sespie 		{
238*c87b03e5Sespie 		  /* use preset global here. FIXME */
239*c87b03e5Sespie 		  $$ = xstrdup ("double");
240*c87b03e5Sespie 		}
241*c87b03e5Sespie |	BOOLEAN_TK
242*c87b03e5Sespie 		{
243*c87b03e5Sespie 		  /* use preset global here. FIXME */
244*c87b03e5Sespie 		  $$ = xstrdup ("boolean");
245*c87b03e5Sespie 		}
246*c87b03e5Sespie ;
247*c87b03e5Sespie 
248*c87b03e5Sespie reference_type:
249*c87b03e5Sespie 	class_or_interface_type
250*c87b03e5Sespie |	array_type
251*c87b03e5Sespie ;
252*c87b03e5Sespie 
253*c87b03e5Sespie class_or_interface_type:
254*c87b03e5Sespie 	name
255*c87b03e5Sespie ;
256*c87b03e5Sespie 
257*c87b03e5Sespie class_type:
258*c87b03e5Sespie 	class_or_interface_type	/* Default rule */
259*c87b03e5Sespie ;
260*c87b03e5Sespie 
261*c87b03e5Sespie interface_type:
262*c87b03e5Sespie 	 class_or_interface_type
263*c87b03e5Sespie ;
264*c87b03e5Sespie 
265*c87b03e5Sespie array_type:
266*c87b03e5Sespie 	primitive_type dims
267*c87b03e5Sespie 		{
268*c87b03e5Sespie 	          while (bracket_count-- > 0)
269*c87b03e5Sespie 		    $$ = concat ("[", $1, NULL);
270*c87b03e5Sespie 		}
271*c87b03e5Sespie |	name dims
272*c87b03e5Sespie 		{
273*c87b03e5Sespie 	          while (bracket_count-- > 0)
274*c87b03e5Sespie 		    $$ = concat ("[", $1, NULL);
275*c87b03e5Sespie 		}
276*c87b03e5Sespie ;
277*c87b03e5Sespie 
278*c87b03e5Sespie /* 19.5 Productions from 6: Names  */
279*c87b03e5Sespie name:
280*c87b03e5Sespie 	simple_name		/* Default rule */
281*c87b03e5Sespie |	qualified_name		/* Default rule */
282*c87b03e5Sespie ;
283*c87b03e5Sespie 
284*c87b03e5Sespie simple_name:
285*c87b03e5Sespie 	identifier		/* Default rule */
286*c87b03e5Sespie ;
287*c87b03e5Sespie 
288*c87b03e5Sespie qualified_name:
289*c87b03e5Sespie 	name DOT_TK identifier
290*c87b03e5Sespie 		{
291*c87b03e5Sespie 		  $$ = concat ($1, ".", $3, NULL);
292*c87b03e5Sespie 		}
293*c87b03e5Sespie ;
294*c87b03e5Sespie 
295*c87b03e5Sespie identifier:
296*c87b03e5Sespie 	ID_TK
297*c87b03e5Sespie ;
298*c87b03e5Sespie 
299*c87b03e5Sespie /* 19.6: Production from 7: Packages  */
300*c87b03e5Sespie compilation_unit:
301*c87b03e5Sespie |	package_declaration
302*c87b03e5Sespie |	import_declarations
303*c87b03e5Sespie |	type_declarations
304*c87b03e5Sespie |       package_declaration import_declarations
305*c87b03e5Sespie |       package_declaration type_declarations
306*c87b03e5Sespie |       import_declarations type_declarations
307*c87b03e5Sespie |       package_declaration import_declarations type_declarations
308*c87b03e5Sespie ;
309*c87b03e5Sespie 
310*c87b03e5Sespie import_declarations:
311*c87b03e5Sespie 	import_declaration
312*c87b03e5Sespie |	import_declarations import_declaration
313*c87b03e5Sespie ;
314*c87b03e5Sespie 
315*c87b03e5Sespie type_declarations:
316*c87b03e5Sespie 	type_declaration
317*c87b03e5Sespie | 	type_declarations type_declaration
318*c87b03e5Sespie ;
319*c87b03e5Sespie 
320*c87b03e5Sespie package_declaration:
321*c87b03e5Sespie 	PACKAGE_TK name SC_TK
322*c87b03e5Sespie 		{ package_name = $2; }
323*c87b03e5Sespie ;
324*c87b03e5Sespie 
325*c87b03e5Sespie import_declaration:
326*c87b03e5Sespie 	single_type_import_declaration
327*c87b03e5Sespie |	type_import_on_demand_declaration
328*c87b03e5Sespie ;
329*c87b03e5Sespie 
330*c87b03e5Sespie single_type_import_declaration:
331*c87b03e5Sespie 	IMPORT_TK name SC_TK
332*c87b03e5Sespie ;
333*c87b03e5Sespie 
334*c87b03e5Sespie type_import_on_demand_declaration:
335*c87b03e5Sespie 	IMPORT_TK name DOT_TK MULT_TK SC_TK
336*c87b03e5Sespie ;
337*c87b03e5Sespie 
338*c87b03e5Sespie type_declaration:
339*c87b03e5Sespie 	class_declaration
340*c87b03e5Sespie |	interface_declaration
341*c87b03e5Sespie |	empty_statement
342*c87b03e5Sespie ;
343*c87b03e5Sespie 
344*c87b03e5Sespie /* 19.7 Shortened from the original:
345*c87b03e5Sespie    modifiers: modifier | modifiers modifier
346*c87b03e5Sespie    modifier: any of public...  */
347*c87b03e5Sespie modifiers:
348*c87b03e5Sespie 	MODIFIER_TK
349*c87b03e5Sespie 		{
350*c87b03e5Sespie 		  if ($1 == PUBLIC_TK)
351*c87b03e5Sespie 		    modifier_value++;
352*c87b03e5Sespie                   if ($1 == STATIC_TK)
353*c87b03e5Sespie                     modifier_value++;
354*c87b03e5Sespie 	          USE_ABSORBER;
355*c87b03e5Sespie 		}
356*c87b03e5Sespie |	modifiers MODIFIER_TK
357*c87b03e5Sespie 		{
358*c87b03e5Sespie 		  if ($2 == PUBLIC_TK)
359*c87b03e5Sespie 		    modifier_value++;
360*c87b03e5Sespie                   if ($2 == STATIC_TK)
361*c87b03e5Sespie                     modifier_value++;
362*c87b03e5Sespie 		  USE_ABSORBER;
363*c87b03e5Sespie 		}
364*c87b03e5Sespie ;
365*c87b03e5Sespie 
366*c87b03e5Sespie /* 19.8.1 Production from $8.1: Class Declaration */
367*c87b03e5Sespie class_declaration:
368*c87b03e5Sespie 	modifiers CLASS_TK identifier super interfaces
369*c87b03e5Sespie 		{
370*c87b03e5Sespie 		  report_class_declaration($3);
371*c87b03e5Sespie 		  modifier_value = 0;
372*c87b03e5Sespie                 }
373*c87b03e5Sespie 	class_body
374*c87b03e5Sespie |	CLASS_TK identifier super interfaces
375*c87b03e5Sespie 		{ report_class_declaration($2); }
376*c87b03e5Sespie 	class_body
377*c87b03e5Sespie ;
378*c87b03e5Sespie 
379*c87b03e5Sespie super:
380*c87b03e5Sespie |	EXTENDS_TK class_type
381*c87b03e5Sespie ;
382*c87b03e5Sespie 
383*c87b03e5Sespie interfaces:
384*c87b03e5Sespie |	IMPLEMENTS_TK interface_type_list
385*c87b03e5Sespie ;
386*c87b03e5Sespie 
387*c87b03e5Sespie interface_type_list:
388*c87b03e5Sespie 	interface_type
389*c87b03e5Sespie 		{ USE_ABSORBER; }
390*c87b03e5Sespie |	interface_type_list C_TK interface_type
391*c87b03e5Sespie 		{ USE_ABSORBER; }
392*c87b03e5Sespie ;
393*c87b03e5Sespie 
394*c87b03e5Sespie class_body:
395*c87b03e5Sespie 	OCB_TK CCB_TK
396*c87b03e5Sespie 		{ pop_class_context (); }
397*c87b03e5Sespie |	OCB_TK class_body_declarations CCB_TK
398*c87b03e5Sespie 		{ pop_class_context (); }
399*c87b03e5Sespie ;
400*c87b03e5Sespie 
401*c87b03e5Sespie class_body_declarations:
402*c87b03e5Sespie 	class_body_declaration
403*c87b03e5Sespie |	class_body_declarations class_body_declaration
404*c87b03e5Sespie ;
405*c87b03e5Sespie 
406*c87b03e5Sespie class_body_declaration:
407*c87b03e5Sespie 	class_member_declaration
408*c87b03e5Sespie |	static_initializer
409*c87b03e5Sespie |	constructor_declaration
410*c87b03e5Sespie |	block			/* Added, JDK1.1, instance initializer */
411*c87b03e5Sespie ;
412*c87b03e5Sespie 
413*c87b03e5Sespie class_member_declaration:
414*c87b03e5Sespie 	field_declaration
415*c87b03e5Sespie |	method_declaration
416*c87b03e5Sespie |	class_declaration	/* Added, JDK1.1 inner classes */
417*c87b03e5Sespie |	interface_declaration	/* Added, JDK1.1 inner classes */
418*c87b03e5Sespie |	empty_statement
419*c87b03e5Sespie ;
420*c87b03e5Sespie 
421*c87b03e5Sespie /* 19.8.2 Productions from 8.3: Field Declarations  */
422*c87b03e5Sespie field_declaration:
423*c87b03e5Sespie 	type variable_declarators SC_TK
424*c87b03e5Sespie 		{ USE_ABSORBER; }
425*c87b03e5Sespie |	modifiers type variable_declarators SC_TK
426*c87b03e5Sespie 		{ modifier_value = 0; }
427*c87b03e5Sespie ;
428*c87b03e5Sespie 
429*c87b03e5Sespie variable_declarators:
430*c87b03e5Sespie 	/* Should we use build_decl_list () instead ? FIXME */
431*c87b03e5Sespie 	variable_declarator	/* Default rule */
432*c87b03e5Sespie |	variable_declarators C_TK variable_declarator
433*c87b03e5Sespie ;
434*c87b03e5Sespie 
435*c87b03e5Sespie variable_declarator:
436*c87b03e5Sespie 	variable_declarator_id
437*c87b03e5Sespie |	variable_declarator_id ASSIGN_TK variable_initializer
438*c87b03e5Sespie ;
439*c87b03e5Sespie 
440*c87b03e5Sespie variable_declarator_id:
441*c87b03e5Sespie 	identifier
442*c87b03e5Sespie 		{ bracket_count = 0; USE_ABSORBER; }
443*c87b03e5Sespie |	variable_declarator_id OSB_TK CSB_TK
444*c87b03e5Sespie 		{ ++bracket_count; }
445*c87b03e5Sespie ;
446*c87b03e5Sespie 
447*c87b03e5Sespie variable_initializer:
448*c87b03e5Sespie 	expression
449*c87b03e5Sespie |	array_initializer
450*c87b03e5Sespie ;
451*c87b03e5Sespie 
452*c87b03e5Sespie /* 19.8.3 Productions from 8.4: Method Declarations  */
453*c87b03e5Sespie method_declaration:
454*c87b03e5Sespie 	method_header
455*c87b03e5Sespie 		{ ++method_depth; }
456*c87b03e5Sespie 	method_body
457*c87b03e5Sespie 		{ --method_depth; }
458*c87b03e5Sespie ;
459*c87b03e5Sespie 
460*c87b03e5Sespie method_header:
461*c87b03e5Sespie 	type method_declarator throws
462*c87b03e5Sespie 		{ USE_ABSORBER; }
463*c87b03e5Sespie |	VOID_TK method_declarator throws
464*c87b03e5Sespie |	modifiers type method_declarator throws
465*c87b03e5Sespie 		{ modifier_value = 0; }
466*c87b03e5Sespie |	modifiers VOID_TK method_declarator throws
467*c87b03e5Sespie 		{
468*c87b03e5Sespie                   report_main_declaration ($3);
469*c87b03e5Sespie 		  modifier_value = 0;
470*c87b03e5Sespie 		}
471*c87b03e5Sespie ;
472*c87b03e5Sespie 
473*c87b03e5Sespie method_declarator:
474*c87b03e5Sespie 	identifier OP_TK CP_TK
475*c87b03e5Sespie 		{
476*c87b03e5Sespie 		  struct method_declarator *d;
477*c87b03e5Sespie 		  NEW_METHOD_DECLARATOR (d, $1, NULL);
478*c87b03e5Sespie 		  $$ = d;
479*c87b03e5Sespie 		}
480*c87b03e5Sespie |	identifier OP_TK formal_parameter_list CP_TK
481*c87b03e5Sespie 		{
482*c87b03e5Sespie 		  struct method_declarator *d;
483*c87b03e5Sespie 		  NEW_METHOD_DECLARATOR (d, $1, $3);
484*c87b03e5Sespie 		  $$ = d;
485*c87b03e5Sespie 		}
486*c87b03e5Sespie |	method_declarator OSB_TK CSB_TK
487*c87b03e5Sespie ;
488*c87b03e5Sespie 
489*c87b03e5Sespie formal_parameter_list:
490*c87b03e5Sespie 	formal_parameter
491*c87b03e5Sespie |	formal_parameter_list C_TK formal_parameter
492*c87b03e5Sespie 		{
493*c87b03e5Sespie 		  $$ = concat ($1, ",", $3, NULL);
494*c87b03e5Sespie 		}
495*c87b03e5Sespie ;
496*c87b03e5Sespie 
497*c87b03e5Sespie formal_parameter:
498*c87b03e5Sespie 	type variable_declarator_id
499*c87b03e5Sespie 		{
500*c87b03e5Sespie 		  USE_ABSORBER;
501*c87b03e5Sespie 		  if (bracket_count)
502*c87b03e5Sespie 		    {
503*c87b03e5Sespie 		      int i;
504*c87b03e5Sespie 		      char *n = xmalloc (bracket_count + 1 + strlen ($$));
505*c87b03e5Sespie 		      for (i = 0; i < bracket_count; ++i)
506*c87b03e5Sespie 			n[i] = '[';
507*c87b03e5Sespie 		      strcpy (n + bracket_count, $$);
508*c87b03e5Sespie 		      $$ = n;
509*c87b03e5Sespie 		    }
510*c87b03e5Sespie 		  else
511*c87b03e5Sespie 		    $$ = $1;
512*c87b03e5Sespie 		}
513*c87b03e5Sespie |	modifiers type variable_declarator_id /* Added, JDK1.1 final locals */
514*c87b03e5Sespie 		{
515*c87b03e5Sespie 		  if (bracket_count)
516*c87b03e5Sespie 		    {
517*c87b03e5Sespie 		      int i;
518*c87b03e5Sespie 		      char *n = xmalloc (bracket_count + 1 + strlen ($$));
519*c87b03e5Sespie 		      for (i = 0; i < bracket_count; ++i)
520*c87b03e5Sespie 			n[i] = '[';
521*c87b03e5Sespie 		      strcpy (n + bracket_count, $$);
522*c87b03e5Sespie 		      $$ = n;
523*c87b03e5Sespie 		    }
524*c87b03e5Sespie 		  else
525*c87b03e5Sespie 		    $$ = $2;
526*c87b03e5Sespie 		}
527*c87b03e5Sespie ;
528*c87b03e5Sespie 
529*c87b03e5Sespie throws:
530*c87b03e5Sespie |	THROWS_TK class_type_list
531*c87b03e5Sespie ;
532*c87b03e5Sespie 
533*c87b03e5Sespie class_type_list:
534*c87b03e5Sespie 	class_type
535*c87b03e5Sespie 		{ USE_ABSORBER; }
536*c87b03e5Sespie |	class_type_list C_TK class_type
537*c87b03e5Sespie 		{ USE_ABSORBER; }
538*c87b03e5Sespie ;
539*c87b03e5Sespie 
540*c87b03e5Sespie method_body:
541*c87b03e5Sespie 	block
542*c87b03e5Sespie |	SC_TK
543*c87b03e5Sespie ;
544*c87b03e5Sespie 
545*c87b03e5Sespie /* 19.8.4 Productions from 8.5: Static Initializers  */
546*c87b03e5Sespie static_initializer:
547*c87b03e5Sespie 	static block
548*c87b03e5Sespie ;
549*c87b03e5Sespie 
550*c87b03e5Sespie static:				/* Test lval.sub_token here */
551*c87b03e5Sespie 	MODIFIER_TK
552*c87b03e5Sespie 		{ USE_ABSORBER; }
553*c87b03e5Sespie ;
554*c87b03e5Sespie 
555*c87b03e5Sespie /* 19.8.5 Productions from 8.6: Constructor Declarations  */
556*c87b03e5Sespie /* NOTE FOR FURTHER WORK ON CONSTRUCTORS:
557*c87b03e5Sespie    - If a forbidded modifier is found, the the error is either the use of
558*c87b03e5Sespie      a forbidded modifier for a constructor OR bogus attempt to declare a
559*c87b03e5Sespie      method without having specified the return type. FIXME */
560*c87b03e5Sespie constructor_declaration:
561*c87b03e5Sespie 	constructor_declarator throws constructor_body
562*c87b03e5Sespie |	modifiers constructor_declarator throws constructor_body
563*c87b03e5Sespie 		{ modifier_value = 0; }
564*c87b03e5Sespie /* extra SC_TK, FIXME */
565*c87b03e5Sespie |	constructor_declarator throws constructor_body SC_TK
566*c87b03e5Sespie /* extra SC_TK, FIXME */
567*c87b03e5Sespie |	modifiers constructor_declarator throws constructor_body SC_TK
568*c87b03e5Sespie 		{ modifier_value = 0; }
569*c87b03e5Sespie /* I'm not happy with the SC_TK addition. It isn't in the grammer and should
570*c87b03e5Sespie    probably be matched by and empty statement. But it doesn't work. FIXME */
571*c87b03e5Sespie ;
572*c87b03e5Sespie 
573*c87b03e5Sespie constructor_declarator:
574*c87b03e5Sespie 	simple_name OP_TK CP_TK
575*c87b03e5Sespie 		{ USE_ABSORBER; }
576*c87b03e5Sespie |	simple_name OP_TK formal_parameter_list CP_TK
577*c87b03e5Sespie 		{ USE_ABSORBER; }
578*c87b03e5Sespie ;
579*c87b03e5Sespie 
580*c87b03e5Sespie constructor_body:
581*c87b03e5Sespie 	OCB_TK CCB_TK
582*c87b03e5Sespie |	OCB_TK explicit_constructor_invocation CCB_TK
583*c87b03e5Sespie |	OCB_TK block_statements CCB_TK
584*c87b03e5Sespie |       OCB_TK explicit_constructor_invocation block_statements CCB_TK
585*c87b03e5Sespie ;
586*c87b03e5Sespie 
587*c87b03e5Sespie /* Error recovery for that rule moved down expression_statement: rule.  */
588*c87b03e5Sespie explicit_constructor_invocation:
589*c87b03e5Sespie 	this_or_super OP_TK CP_TK SC_TK
590*c87b03e5Sespie |	this_or_super OP_TK argument_list CP_TK SC_TK
591*c87b03e5Sespie         /* Added, JDK1.1 inner classes. Modified because the rule
592*c87b03e5Sespie 	   'primary' couldn't work.  */
593*c87b03e5Sespie |	name DOT_TK SUPER_TK OP_TK argument_list CP_TK SC_TK
594*c87b03e5Sespie 		{ USE_ABSORBER; }
595*c87b03e5Sespie |	name DOT_TK SUPER_TK OP_TK CP_TK SC_TK
596*c87b03e5Sespie 		{ USE_ABSORBER; }
597*c87b03e5Sespie ;
598*c87b03e5Sespie 
599*c87b03e5Sespie this_or_super:			/* Added, simplifies error diagnostics */
600*c87b03e5Sespie 	THIS_TK
601*c87b03e5Sespie |	SUPER_TK
602*c87b03e5Sespie ;
603*c87b03e5Sespie 
604*c87b03e5Sespie /* 19.9 Productions from 9: Interfaces  */
605*c87b03e5Sespie /* 19.9.1 Productions from 9.1: Interfaces Declarations  */
606*c87b03e5Sespie interface_declaration:
607*c87b03e5Sespie 	INTERFACE_TK identifier
608*c87b03e5Sespie 		{ report_class_declaration ($2); modifier_value = 0; }
609*c87b03e5Sespie 	interface_body
610*c87b03e5Sespie |	modifiers INTERFACE_TK identifier
611*c87b03e5Sespie 		{ report_class_declaration ($3); modifier_value = 0; }
612*c87b03e5Sespie 	interface_body
613*c87b03e5Sespie |	INTERFACE_TK identifier extends_interfaces
614*c87b03e5Sespie 		{ report_class_declaration ($2); modifier_value = 0; }
615*c87b03e5Sespie 	interface_body
616*c87b03e5Sespie |	modifiers INTERFACE_TK identifier extends_interfaces
617*c87b03e5Sespie 		{ report_class_declaration ($3); modifier_value = 0; }
618*c87b03e5Sespie 	interface_body
619*c87b03e5Sespie ;
620*c87b03e5Sespie 
621*c87b03e5Sespie extends_interfaces:
622*c87b03e5Sespie 	EXTENDS_TK interface_type
623*c87b03e5Sespie |	extends_interfaces C_TK interface_type
624*c87b03e5Sespie ;
625*c87b03e5Sespie 
626*c87b03e5Sespie interface_body:
627*c87b03e5Sespie 	OCB_TK CCB_TK
628*c87b03e5Sespie 		{ pop_class_context (); }
629*c87b03e5Sespie |	OCB_TK interface_member_declarations CCB_TK
630*c87b03e5Sespie 		{ pop_class_context (); }
631*c87b03e5Sespie ;
632*c87b03e5Sespie 
633*c87b03e5Sespie interface_member_declarations:
634*c87b03e5Sespie 	interface_member_declaration
635*c87b03e5Sespie |	interface_member_declarations interface_member_declaration
636*c87b03e5Sespie ;
637*c87b03e5Sespie 
638*c87b03e5Sespie interface_member_declaration:
639*c87b03e5Sespie 	constant_declaration
640*c87b03e5Sespie |	abstract_method_declaration
641*c87b03e5Sespie |	class_declaration	/* Added, JDK1.1 inner classes */
642*c87b03e5Sespie |	interface_declaration	/* Added, JDK1.1 inner classes */
643*c87b03e5Sespie ;
644*c87b03e5Sespie 
645*c87b03e5Sespie constant_declaration:
646*c87b03e5Sespie 	field_declaration
647*c87b03e5Sespie ;
648*c87b03e5Sespie 
649*c87b03e5Sespie abstract_method_declaration:
650*c87b03e5Sespie 	method_header SC_TK
651*c87b03e5Sespie ;
652*c87b03e5Sespie 
653*c87b03e5Sespie /* 19.10 Productions from 10: Arrays  */
654*c87b03e5Sespie array_initializer:
655*c87b03e5Sespie 	OCB_TK CCB_TK
656*c87b03e5Sespie |	OCB_TK variable_initializers CCB_TK
657*c87b03e5Sespie |	OCB_TK C_TK CCB_TK
658*c87b03e5Sespie |	OCB_TK variable_initializers C_TK CCB_TK
659*c87b03e5Sespie ;
660*c87b03e5Sespie 
661*c87b03e5Sespie variable_initializers:
662*c87b03e5Sespie 	variable_initializer
663*c87b03e5Sespie |	variable_initializers C_TK variable_initializer
664*c87b03e5Sespie ;
665*c87b03e5Sespie 
666*c87b03e5Sespie /* 19.11 Production from 14: Blocks and Statements  */
667*c87b03e5Sespie block:
668*c87b03e5Sespie 	OCB_TK CCB_TK
669*c87b03e5Sespie |	OCB_TK block_statements CCB_TK
670*c87b03e5Sespie ;
671*c87b03e5Sespie 
672*c87b03e5Sespie block_statements:
673*c87b03e5Sespie 	block_statement
674*c87b03e5Sespie |	block_statements block_statement
675*c87b03e5Sespie ;
676*c87b03e5Sespie 
677*c87b03e5Sespie block_statement:
678*c87b03e5Sespie 	local_variable_declaration_statement
679*c87b03e5Sespie |	statement
680*c87b03e5Sespie |	class_declaration	/* Added, JDK1.1 inner classes */
681*c87b03e5Sespie ;
682*c87b03e5Sespie 
683*c87b03e5Sespie local_variable_declaration_statement:
684*c87b03e5Sespie 	local_variable_declaration SC_TK /* Can't catch missing ';' here */
685*c87b03e5Sespie ;
686*c87b03e5Sespie 
687*c87b03e5Sespie local_variable_declaration:
688*c87b03e5Sespie 	type variable_declarators
689*c87b03e5Sespie 		{ USE_ABSORBER; }
690*c87b03e5Sespie |	modifiers type variable_declarators /* Added, JDK1.1 final locals */
691*c87b03e5Sespie 		{ modifier_value = 0; }
692*c87b03e5Sespie ;
693*c87b03e5Sespie 
694*c87b03e5Sespie statement:
695*c87b03e5Sespie 	statement_without_trailing_substatement
696*c87b03e5Sespie |	labeled_statement
697*c87b03e5Sespie |	if_then_statement
698*c87b03e5Sespie |	if_then_else_statement
699*c87b03e5Sespie |	while_statement
700*c87b03e5Sespie |	for_statement
701*c87b03e5Sespie ;
702*c87b03e5Sespie 
703*c87b03e5Sespie statement_nsi:
704*c87b03e5Sespie 	statement_without_trailing_substatement
705*c87b03e5Sespie |	labeled_statement_nsi
706*c87b03e5Sespie |	if_then_else_statement_nsi
707*c87b03e5Sespie |	while_statement_nsi
708*c87b03e5Sespie |	for_statement_nsi
709*c87b03e5Sespie ;
710*c87b03e5Sespie 
711*c87b03e5Sespie statement_without_trailing_substatement:
712*c87b03e5Sespie 	block
713*c87b03e5Sespie |	empty_statement
714*c87b03e5Sespie |	expression_statement
715*c87b03e5Sespie |	switch_statement
716*c87b03e5Sespie |	do_statement
717*c87b03e5Sespie |	break_statement
718*c87b03e5Sespie |	continue_statement
719*c87b03e5Sespie |	return_statement
720*c87b03e5Sespie |	synchronized_statement
721*c87b03e5Sespie |	throw_statement
722*c87b03e5Sespie |	try_statement
723*c87b03e5Sespie |	assert_statement
724*c87b03e5Sespie ;
725*c87b03e5Sespie 
726*c87b03e5Sespie empty_statement:
727*c87b03e5Sespie 	SC_TK
728*c87b03e5Sespie ;
729*c87b03e5Sespie 
730*c87b03e5Sespie label_decl:
731*c87b03e5Sespie 	identifier REL_CL_TK
732*c87b03e5Sespie 		{ USE_ABSORBER; }
733*c87b03e5Sespie ;
734*c87b03e5Sespie 
735*c87b03e5Sespie labeled_statement:
736*c87b03e5Sespie 	label_decl statement
737*c87b03e5Sespie ;
738*c87b03e5Sespie 
739*c87b03e5Sespie labeled_statement_nsi:
740*c87b03e5Sespie 	label_decl statement_nsi
741*c87b03e5Sespie ;
742*c87b03e5Sespie 
743*c87b03e5Sespie /* We concentrate here a bunch of error handling rules that we couldn't write
744*c87b03e5Sespie    earlier, because expression_statement catches a missing ';'.  */
745*c87b03e5Sespie expression_statement:
746*c87b03e5Sespie 	statement_expression SC_TK
747*c87b03e5Sespie ;
748*c87b03e5Sespie 
749*c87b03e5Sespie statement_expression:
750*c87b03e5Sespie 	assignment
751*c87b03e5Sespie |	pre_increment_expression
752*c87b03e5Sespie |	pre_decrement_expression
753*c87b03e5Sespie |	post_increment_expression
754*c87b03e5Sespie |	post_decrement_expression
755*c87b03e5Sespie |	method_invocation
756*c87b03e5Sespie |	class_instance_creation_expression
757*c87b03e5Sespie ;
758*c87b03e5Sespie 
759*c87b03e5Sespie if_then_statement:
760*c87b03e5Sespie 	IF_TK OP_TK expression CP_TK statement { ++complexity; }
761*c87b03e5Sespie ;
762*c87b03e5Sespie 
763*c87b03e5Sespie if_then_else_statement:
764*c87b03e5Sespie 	IF_TK OP_TK expression CP_TK statement_nsi ELSE_TK statement
765*c87b03e5Sespie 	{ ++complexity; }
766*c87b03e5Sespie ;
767*c87b03e5Sespie 
768*c87b03e5Sespie if_then_else_statement_nsi:
769*c87b03e5Sespie 	IF_TK OP_TK expression CP_TK statement_nsi ELSE_TK statement_nsi
770*c87b03e5Sespie 	{ ++complexity; }
771*c87b03e5Sespie ;
772*c87b03e5Sespie 
773*c87b03e5Sespie switch_statement:
774*c87b03e5Sespie 	SWITCH_TK OP_TK expression CP_TK switch_block
775*c87b03e5Sespie ;
776*c87b03e5Sespie 
777*c87b03e5Sespie switch_block:
778*c87b03e5Sespie 	OCB_TK CCB_TK
779*c87b03e5Sespie |	OCB_TK switch_labels CCB_TK
780*c87b03e5Sespie |	OCB_TK switch_block_statement_groups CCB_TK
781*c87b03e5Sespie |	OCB_TK switch_block_statement_groups switch_labels CCB_TK
782*c87b03e5Sespie ;
783*c87b03e5Sespie 
784*c87b03e5Sespie switch_block_statement_groups:
785*c87b03e5Sespie 	switch_block_statement_group
786*c87b03e5Sespie |	switch_block_statement_groups switch_block_statement_group
787*c87b03e5Sespie ;
788*c87b03e5Sespie 
789*c87b03e5Sespie switch_block_statement_group:
790*c87b03e5Sespie 	switch_labels block_statements { ++complexity; }
791*c87b03e5Sespie ;
792*c87b03e5Sespie 
793*c87b03e5Sespie 
794*c87b03e5Sespie switch_labels:
795*c87b03e5Sespie 	switch_label
796*c87b03e5Sespie |	switch_labels switch_label
797*c87b03e5Sespie ;
798*c87b03e5Sespie 
799*c87b03e5Sespie switch_label:
800*c87b03e5Sespie 	CASE_TK constant_expression REL_CL_TK
801*c87b03e5Sespie |	DEFAULT_TK REL_CL_TK
802*c87b03e5Sespie ;
803*c87b03e5Sespie 
804*c87b03e5Sespie while_expression:
805*c87b03e5Sespie 	WHILE_TK OP_TK expression CP_TK { ++complexity; }
806*c87b03e5Sespie ;
807*c87b03e5Sespie 
808*c87b03e5Sespie while_statement:
809*c87b03e5Sespie 	while_expression statement
810*c87b03e5Sespie ;
811*c87b03e5Sespie 
812*c87b03e5Sespie while_statement_nsi:
813*c87b03e5Sespie 	while_expression statement_nsi
814*c87b03e5Sespie ;
815*c87b03e5Sespie 
816*c87b03e5Sespie do_statement_begin:
817*c87b03e5Sespie 	DO_TK
818*c87b03e5Sespie ;
819*c87b03e5Sespie 
820*c87b03e5Sespie do_statement:
821*c87b03e5Sespie 	do_statement_begin statement WHILE_TK OP_TK expression CP_TK SC_TK
822*c87b03e5Sespie 	{ ++complexity; }
823*c87b03e5Sespie ;
824*c87b03e5Sespie 
825*c87b03e5Sespie for_statement:
826*c87b03e5Sespie 	for_begin SC_TK expression SC_TK for_update CP_TK statement
827*c87b03e5Sespie |	for_begin SC_TK SC_TK for_update CP_TK statement
828*c87b03e5Sespie ;
829*c87b03e5Sespie 
830*c87b03e5Sespie for_statement_nsi:
831*c87b03e5Sespie 	for_begin SC_TK expression SC_TK for_update CP_TK statement_nsi
832*c87b03e5Sespie |	for_begin SC_TK SC_TK for_update CP_TK statement_nsi
833*c87b03e5Sespie ;
834*c87b03e5Sespie 
835*c87b03e5Sespie for_header:
836*c87b03e5Sespie 	FOR_TK OP_TK
837*c87b03e5Sespie ;
838*c87b03e5Sespie 
839*c87b03e5Sespie for_begin:
840*c87b03e5Sespie 	for_header for_init { ++complexity; }
841*c87b03e5Sespie ;
842*c87b03e5Sespie for_init:			/* Can be empty */
843*c87b03e5Sespie |	statement_expression_list
844*c87b03e5Sespie |	local_variable_declaration
845*c87b03e5Sespie ;
846*c87b03e5Sespie 
847*c87b03e5Sespie for_update:			/* Can be empty */
848*c87b03e5Sespie |	statement_expression_list
849*c87b03e5Sespie ;
850*c87b03e5Sespie 
851*c87b03e5Sespie statement_expression_list:
852*c87b03e5Sespie 	statement_expression
853*c87b03e5Sespie |	statement_expression_list C_TK statement_expression
854*c87b03e5Sespie ;
855*c87b03e5Sespie 
856*c87b03e5Sespie break_statement:
857*c87b03e5Sespie 	BREAK_TK SC_TK
858*c87b03e5Sespie |	BREAK_TK identifier SC_TK
859*c87b03e5Sespie ;
860*c87b03e5Sespie 
861*c87b03e5Sespie /* `continue' with a label is considered for complexity but ordinary
862*c87b03e5Sespie    continue is not.  */
863*c87b03e5Sespie continue_statement:
864*c87b03e5Sespie 	CONTINUE_TK SC_TK
865*c87b03e5Sespie 	|       CONTINUE_TK identifier SC_TK { ++complexity; }
866*c87b03e5Sespie ;
867*c87b03e5Sespie 
868*c87b03e5Sespie return_statement:
869*c87b03e5Sespie 	RETURN_TK SC_TK
870*c87b03e5Sespie |	RETURN_TK expression SC_TK
871*c87b03e5Sespie ;
872*c87b03e5Sespie 
873*c87b03e5Sespie throw_statement:
874*c87b03e5Sespie 	THROW_TK expression SC_TK { ++complexity; }
875*c87b03e5Sespie ;
876*c87b03e5Sespie 
877*c87b03e5Sespie assert_statement:
878*c87b03e5Sespie 	ASSERT_TK expression REL_CL_TK expression SC_TK
879*c87b03e5Sespie |	ASSERT_TK expression SC_TK
880*c87b03e5Sespie |	ASSERT_TK error
881*c87b03e5Sespie 		{yyerror ("Missing term"); RECOVER;}
882*c87b03e5Sespie |	ASSERT_TK expression error
883*c87b03e5Sespie 		{yyerror ("';' expected"); RECOVER;}
884*c87b03e5Sespie ;
885*c87b03e5Sespie synchronized_statement:
886*c87b03e5Sespie 	synchronized OP_TK expression CP_TK block
887*c87b03e5Sespie |	synchronized OP_TK expression CP_TK error
888*c87b03e5Sespie ;
889*c87b03e5Sespie 
890*c87b03e5Sespie synchronized:			/* Test lval.sub_token here */
891*c87b03e5Sespie 	MODIFIER_TK
892*c87b03e5Sespie 		{ USE_ABSORBER; }
893*c87b03e5Sespie ;
894*c87b03e5Sespie 
895*c87b03e5Sespie try_statement:
896*c87b03e5Sespie 	TRY_TK block catches
897*c87b03e5Sespie |	TRY_TK block finally
898*c87b03e5Sespie |	TRY_TK block catches finally
899*c87b03e5Sespie ;
900*c87b03e5Sespie 
901*c87b03e5Sespie catches:
902*c87b03e5Sespie 	catch_clause
903*c87b03e5Sespie |	catches catch_clause
904*c87b03e5Sespie ;
905*c87b03e5Sespie 
906*c87b03e5Sespie catch_clause:
907*c87b03e5Sespie 	CATCH_TK OP_TK formal_parameter CP_TK block { ++complexity; }
908*c87b03e5Sespie ;
909*c87b03e5Sespie 
910*c87b03e5Sespie finally:
911*c87b03e5Sespie 	FINALLY_TK block { ++complexity; }
912*c87b03e5Sespie ;
913*c87b03e5Sespie 
914*c87b03e5Sespie /* 19.12 Production from 15: Expressions  */
915*c87b03e5Sespie primary:
916*c87b03e5Sespie 	primary_no_new_array
917*c87b03e5Sespie |	array_creation_expression
918*c87b03e5Sespie ;
919*c87b03e5Sespie 
920*c87b03e5Sespie primary_no_new_array:
921*c87b03e5Sespie 	literal
922*c87b03e5Sespie |	THIS_TK
923*c87b03e5Sespie |	OP_TK expression CP_TK
924*c87b03e5Sespie |	class_instance_creation_expression
925*c87b03e5Sespie |	field_access
926*c87b03e5Sespie |	method_invocation
927*c87b03e5Sespie |	array_access
928*c87b03e5Sespie |	type_literals
929*c87b03e5Sespie         /* Added, JDK1.1 inner classes. Documentation is wrong
930*c87b03e5Sespie            refering to a 'ClassName' (class_name) rule that doesn't
931*c87b03e5Sespie            exist. Used name instead.  */
932*c87b03e5Sespie |	name DOT_TK THIS_TK
933*c87b03e5Sespie 		{ USE_ABSORBER; }
934*c87b03e5Sespie ;
935*c87b03e5Sespie 
936*c87b03e5Sespie type_literals:
937*c87b03e5Sespie 	name DOT_TK CLASS_TK
938*c87b03e5Sespie 		{ USE_ABSORBER; }
939*c87b03e5Sespie |	array_type DOT_TK CLASS_TK
940*c87b03e5Sespie 		{ USE_ABSORBER; }
941*c87b03e5Sespie |	primitive_type DOT_TK CLASS_TK
942*c87b03e5Sespie 		{ USE_ABSORBER; }
943*c87b03e5Sespie |	VOID_TK DOT_TK CLASS_TK
944*c87b03e5Sespie 		{ USE_ABSORBER; }
945*c87b03e5Sespie ;
946*c87b03e5Sespie 
947*c87b03e5Sespie class_instance_creation_expression:
948*c87b03e5Sespie 	NEW_TK class_type OP_TK argument_list CP_TK
949*c87b03e5Sespie |	NEW_TK class_type OP_TK CP_TK
950*c87b03e5Sespie |	anonymous_class_creation
951*c87b03e5Sespie |	something_dot_new identifier OP_TK CP_TK
952*c87b03e5Sespie |	something_dot_new identifier OP_TK CP_TK class_body
953*c87b03e5Sespie |	something_dot_new identifier OP_TK argument_list CP_TK
954*c87b03e5Sespie |	something_dot_new identifier OP_TK argument_list CP_TK class_body
955*c87b03e5Sespie ;
956*c87b03e5Sespie 
957*c87b03e5Sespie anonymous_class_creation:
958*c87b03e5Sespie 	NEW_TK class_type OP_TK CP_TK
959*c87b03e5Sespie 		{ report_class_declaration (anonymous_context); }
960*c87b03e5Sespie 	class_body
961*c87b03e5Sespie |	NEW_TK class_type OP_TK argument_list CP_TK
962*c87b03e5Sespie 		{ report_class_declaration (anonymous_context); }
963*c87b03e5Sespie 	class_body
964*c87b03e5Sespie ;
965*c87b03e5Sespie 
966*c87b03e5Sespie something_dot_new:		/* Added, not part of the specs. */
967*c87b03e5Sespie 	name DOT_TK NEW_TK
968*c87b03e5Sespie 		{ USE_ABSORBER; }
969*c87b03e5Sespie |	primary DOT_TK NEW_TK
970*c87b03e5Sespie ;
971*c87b03e5Sespie 
972*c87b03e5Sespie argument_list:
973*c87b03e5Sespie 	expression
974*c87b03e5Sespie |	argument_list C_TK expression
975*c87b03e5Sespie |	argument_list C_TK error
976*c87b03e5Sespie ;
977*c87b03e5Sespie 
978*c87b03e5Sespie array_creation_expression:
979*c87b03e5Sespie 	NEW_TK primitive_type dim_exprs
980*c87b03e5Sespie |	NEW_TK class_or_interface_type dim_exprs
981*c87b03e5Sespie |	NEW_TK primitive_type dim_exprs dims
982*c87b03e5Sespie |	NEW_TK class_or_interface_type dim_exprs dims
983*c87b03e5Sespie         /* Added, JDK1.1 anonymous array. Initial documentation rule
984*c87b03e5Sespie            modified */
985*c87b03e5Sespie |	NEW_TK class_or_interface_type dims array_initializer
986*c87b03e5Sespie |	NEW_TK primitive_type dims array_initializer
987*c87b03e5Sespie ;
988*c87b03e5Sespie 
989*c87b03e5Sespie dim_exprs:
990*c87b03e5Sespie 	dim_expr
991*c87b03e5Sespie |	dim_exprs dim_expr
992*c87b03e5Sespie ;
993*c87b03e5Sespie 
994*c87b03e5Sespie dim_expr:
995*c87b03e5Sespie 	OSB_TK expression CSB_TK
996*c87b03e5Sespie ;
997*c87b03e5Sespie 
998*c87b03e5Sespie dims:
999*c87b03e5Sespie 	OSB_TK CSB_TK
1000*c87b03e5Sespie 		{ bracket_count = 1; }
1001*c87b03e5Sespie |	dims OSB_TK CSB_TK
1002*c87b03e5Sespie 		{ bracket_count++; }
1003*c87b03e5Sespie ;
1004*c87b03e5Sespie 
1005*c87b03e5Sespie field_access:
1006*c87b03e5Sespie 	primary DOT_TK identifier
1007*c87b03e5Sespie |	SUPER_TK DOT_TK identifier
1008*c87b03e5Sespie ;
1009*c87b03e5Sespie 
1010*c87b03e5Sespie /* We include method invocation in the complexity measure on the
1011*c87b03e5Sespie    theory that most method calls are virtual and therefore involve a
1012*c87b03e5Sespie    decision point.  */
1013*c87b03e5Sespie method_invocation:
1014*c87b03e5Sespie 	name OP_TK CP_TK
1015*c87b03e5Sespie 		{ USE_ABSORBER; ++complexity; }
1016*c87b03e5Sespie |	name OP_TK argument_list CP_TK
1017*c87b03e5Sespie 		{ USE_ABSORBER; ++complexity; }
1018*c87b03e5Sespie |	primary DOT_TK identifier OP_TK CP_TK { ++complexity; }
1019*c87b03e5Sespie |	primary DOT_TK identifier OP_TK argument_list CP_TK { ++complexity; }
1020*c87b03e5Sespie |	SUPER_TK DOT_TK identifier OP_TK CP_TK { ++complexity; }
1021*c87b03e5Sespie |	SUPER_TK DOT_TK identifier OP_TK argument_list CP_TK { ++complexity; }
1022*c87b03e5Sespie ;
1023*c87b03e5Sespie 
1024*c87b03e5Sespie array_access:
1025*c87b03e5Sespie 	name OSB_TK expression CSB_TK
1026*c87b03e5Sespie 		{ USE_ABSORBER; }
1027*c87b03e5Sespie |	primary_no_new_array OSB_TK expression CSB_TK
1028*c87b03e5Sespie ;
1029*c87b03e5Sespie 
1030*c87b03e5Sespie postfix_expression:
1031*c87b03e5Sespie 	primary
1032*c87b03e5Sespie |	name
1033*c87b03e5Sespie 		{ USE_ABSORBER; }
1034*c87b03e5Sespie |	post_increment_expression
1035*c87b03e5Sespie |	post_decrement_expression
1036*c87b03e5Sespie ;
1037*c87b03e5Sespie 
1038*c87b03e5Sespie post_increment_expression:
1039*c87b03e5Sespie 	postfix_expression INCR_TK
1040*c87b03e5Sespie ;
1041*c87b03e5Sespie 
1042*c87b03e5Sespie post_decrement_expression:
1043*c87b03e5Sespie 	postfix_expression DECR_TK
1044*c87b03e5Sespie ;
1045*c87b03e5Sespie 
1046*c87b03e5Sespie unary_expression:
1047*c87b03e5Sespie 	pre_increment_expression
1048*c87b03e5Sespie |	pre_decrement_expression
1049*c87b03e5Sespie |	PLUS_TK unary_expression
1050*c87b03e5Sespie |	MINUS_TK unary_expression
1051*c87b03e5Sespie |	unary_expression_not_plus_minus
1052*c87b03e5Sespie ;
1053*c87b03e5Sespie 
1054*c87b03e5Sespie pre_increment_expression:
1055*c87b03e5Sespie 	INCR_TK unary_expression
1056*c87b03e5Sespie ;
1057*c87b03e5Sespie 
1058*c87b03e5Sespie pre_decrement_expression:
1059*c87b03e5Sespie 	DECR_TK unary_expression
1060*c87b03e5Sespie ;
1061*c87b03e5Sespie 
1062*c87b03e5Sespie unary_expression_not_plus_minus:
1063*c87b03e5Sespie 	postfix_expression
1064*c87b03e5Sespie |	NOT_TK unary_expression
1065*c87b03e5Sespie |	NEG_TK unary_expression
1066*c87b03e5Sespie |	cast_expression
1067*c87b03e5Sespie ;
1068*c87b03e5Sespie 
1069*c87b03e5Sespie cast_expression:		/* Error handling here is potentially weak */
1070*c87b03e5Sespie 	OP_TK primitive_type dims CP_TK unary_expression
1071*c87b03e5Sespie |	OP_TK primitive_type CP_TK unary_expression
1072*c87b03e5Sespie |	OP_TK expression CP_TK unary_expression_not_plus_minus
1073*c87b03e5Sespie |	OP_TK name dims CP_TK unary_expression_not_plus_minus
1074*c87b03e5Sespie ;
1075*c87b03e5Sespie 
1076*c87b03e5Sespie multiplicative_expression:
1077*c87b03e5Sespie 	unary_expression
1078*c87b03e5Sespie |	multiplicative_expression MULT_TK unary_expression
1079*c87b03e5Sespie |	multiplicative_expression DIV_TK unary_expression
1080*c87b03e5Sespie |	multiplicative_expression REM_TK unary_expression
1081*c87b03e5Sespie ;
1082*c87b03e5Sespie 
1083*c87b03e5Sespie additive_expression:
1084*c87b03e5Sespie 	multiplicative_expression
1085*c87b03e5Sespie |	additive_expression PLUS_TK multiplicative_expression
1086*c87b03e5Sespie |	additive_expression MINUS_TK multiplicative_expression
1087*c87b03e5Sespie ;
1088*c87b03e5Sespie 
1089*c87b03e5Sespie shift_expression:
1090*c87b03e5Sespie 	additive_expression
1091*c87b03e5Sespie |	shift_expression LS_TK additive_expression
1092*c87b03e5Sespie |	shift_expression SRS_TK additive_expression
1093*c87b03e5Sespie |	shift_expression ZRS_TK additive_expression
1094*c87b03e5Sespie ;
1095*c87b03e5Sespie 
1096*c87b03e5Sespie relational_expression:
1097*c87b03e5Sespie 	shift_expression
1098*c87b03e5Sespie |	relational_expression LT_TK shift_expression
1099*c87b03e5Sespie |	relational_expression GT_TK shift_expression
1100*c87b03e5Sespie |	relational_expression LTE_TK shift_expression
1101*c87b03e5Sespie |	relational_expression GTE_TK shift_expression
1102*c87b03e5Sespie |	relational_expression INSTANCEOF_TK reference_type
1103*c87b03e5Sespie ;
1104*c87b03e5Sespie 
1105*c87b03e5Sespie equality_expression:
1106*c87b03e5Sespie 	relational_expression
1107*c87b03e5Sespie |	equality_expression EQ_TK relational_expression
1108*c87b03e5Sespie |	equality_expression NEQ_TK relational_expression
1109*c87b03e5Sespie ;
1110*c87b03e5Sespie 
1111*c87b03e5Sespie and_expression:
1112*c87b03e5Sespie 	equality_expression
1113*c87b03e5Sespie |	and_expression AND_TK equality_expression
1114*c87b03e5Sespie ;
1115*c87b03e5Sespie 
1116*c87b03e5Sespie exclusive_or_expression:
1117*c87b03e5Sespie 	and_expression
1118*c87b03e5Sespie |	exclusive_or_expression XOR_TK and_expression
1119*c87b03e5Sespie ;
1120*c87b03e5Sespie 
1121*c87b03e5Sespie inclusive_or_expression:
1122*c87b03e5Sespie 	exclusive_or_expression
1123*c87b03e5Sespie |	inclusive_or_expression OR_TK exclusive_or_expression
1124*c87b03e5Sespie ;
1125*c87b03e5Sespie 
1126*c87b03e5Sespie conditional_and_expression:
1127*c87b03e5Sespie 	inclusive_or_expression
1128*c87b03e5Sespie |	conditional_and_expression BOOL_AND_TK inclusive_or_expression
1129*c87b03e5Sespie 	{ ++complexity; }
1130*c87b03e5Sespie ;
1131*c87b03e5Sespie 
1132*c87b03e5Sespie conditional_or_expression:
1133*c87b03e5Sespie 	conditional_and_expression
1134*c87b03e5Sespie |	conditional_or_expression BOOL_OR_TK conditional_and_expression
1135*c87b03e5Sespie 	{ ++complexity; }
1136*c87b03e5Sespie ;
1137*c87b03e5Sespie 
1138*c87b03e5Sespie conditional_expression:		/* Error handling here is weak */
1139*c87b03e5Sespie 	conditional_or_expression
1140*c87b03e5Sespie |	conditional_or_expression REL_QM_TK expression REL_CL_TK conditional_expression
1141*c87b03e5Sespie 	{ ++complexity; }
1142*c87b03e5Sespie ;
1143*c87b03e5Sespie 
1144*c87b03e5Sespie assignment_expression:
1145*c87b03e5Sespie 	conditional_expression
1146*c87b03e5Sespie |	assignment
1147*c87b03e5Sespie ;
1148*c87b03e5Sespie 
1149*c87b03e5Sespie assignment:
1150*c87b03e5Sespie 	left_hand_side assignment_operator assignment_expression
1151*c87b03e5Sespie ;
1152*c87b03e5Sespie 
1153*c87b03e5Sespie left_hand_side:
1154*c87b03e5Sespie 	name
1155*c87b03e5Sespie 		{ USE_ABSORBER; }
1156*c87b03e5Sespie |	field_access
1157*c87b03e5Sespie |	array_access
1158*c87b03e5Sespie ;
1159*c87b03e5Sespie 
1160*c87b03e5Sespie assignment_operator:
1161*c87b03e5Sespie 	ASSIGN_ANY_TK
1162*c87b03e5Sespie |	ASSIGN_TK
1163*c87b03e5Sespie ;
1164*c87b03e5Sespie 
1165*c87b03e5Sespie expression:
1166*c87b03e5Sespie 	assignment_expression
1167*c87b03e5Sespie ;
1168*c87b03e5Sespie 
1169*c87b03e5Sespie constant_expression:
1170*c87b03e5Sespie 	expression
1171*c87b03e5Sespie ;
1172*c87b03e5Sespie 
1173*c87b03e5Sespie %%
1174*c87b03e5Sespie 
1175*c87b03e5Sespie /* Create a new parser context */
1176*c87b03e5Sespie 
1177*c87b03e5Sespie void
1178*c87b03e5Sespie java_push_parser_context ()
1179*c87b03e5Sespie {
1180*c87b03e5Sespie   struct parser_ctxt *new =
1181*c87b03e5Sespie     (struct parser_ctxt *) xcalloc (1, sizeof (struct parser_ctxt));
1182*c87b03e5Sespie 
1183*c87b03e5Sespie   new->next = ctxp;
1184*c87b03e5Sespie   ctxp = new;
1185*c87b03e5Sespie }
1186*c87b03e5Sespie 
1187*c87b03e5Sespie static void
push_class_context(name)1188*c87b03e5Sespie push_class_context (name)
1189*c87b03e5Sespie     const char *name;
1190*c87b03e5Sespie {
1191*c87b03e5Sespie   struct class_context *ctx;
1192*c87b03e5Sespie 
1193*c87b03e5Sespie   ctx = (struct class_context *) xmalloc (sizeof (struct class_context));
1194*c87b03e5Sespie   ctx->name = (char *) name;
1195*c87b03e5Sespie   ctx->next = current_class_context;
1196*c87b03e5Sespie   current_class_context = ctx;
1197*c87b03e5Sespie }
1198*c87b03e5Sespie 
1199*c87b03e5Sespie static void
pop_class_context()1200*c87b03e5Sespie pop_class_context ()
1201*c87b03e5Sespie {
1202*c87b03e5Sespie   struct class_context *ctx;
1203*c87b03e5Sespie 
1204*c87b03e5Sespie   if (current_class_context == NULL)
1205*c87b03e5Sespie     return;
1206*c87b03e5Sespie 
1207*c87b03e5Sespie   ctx = current_class_context->next;
1208*c87b03e5Sespie   if (current_class_context->name != anonymous_context)
1209*c87b03e5Sespie     free (current_class_context->name);
1210*c87b03e5Sespie   free (current_class_context);
1211*c87b03e5Sespie 
1212*c87b03e5Sespie   current_class_context = ctx;
1213*c87b03e5Sespie   if (current_class_context == NULL)
1214*c87b03e5Sespie     anonymous_count = 0;
1215*c87b03e5Sespie }
1216*c87b03e5Sespie 
1217*c87b03e5Sespie /* Recursively construct the class name.  This is just a helper
1218*c87b03e5Sespie    function for get_class_name().  */
1219*c87b03e5Sespie static int
make_class_name_recursive(stack,ctx)1220*c87b03e5Sespie make_class_name_recursive (stack, ctx)
1221*c87b03e5Sespie      struct obstack *stack;
1222*c87b03e5Sespie      struct class_context *ctx;
1223*c87b03e5Sespie {
1224*c87b03e5Sespie   if (! ctx)
1225*c87b03e5Sespie     return 0;
1226*c87b03e5Sespie 
1227*c87b03e5Sespie   make_class_name_recursive (stack, ctx->next);
1228*c87b03e5Sespie 
1229*c87b03e5Sespie   /* Replace an anonymous context with the appropriate counter value.  */
1230*c87b03e5Sespie   if (ctx->name == anonymous_context)
1231*c87b03e5Sespie     {
1232*c87b03e5Sespie       char buf[50];
1233*c87b03e5Sespie       ++anonymous_count;
1234*c87b03e5Sespie       sprintf (buf, "%d", anonymous_count);
1235*c87b03e5Sespie       ctx->name = xstrdup (buf);
1236*c87b03e5Sespie     }
1237*c87b03e5Sespie 
1238*c87b03e5Sespie   obstack_grow (stack, ctx->name, strlen (ctx->name));
1239*c87b03e5Sespie   obstack_1grow (stack, '$');
1240*c87b03e5Sespie 
1241*c87b03e5Sespie   return ISDIGIT (ctx->name[0]);
1242*c87b03e5Sespie }
1243*c87b03e5Sespie 
1244*c87b03e5Sespie /* Return a newly allocated string holding the name of the class.  */
1245*c87b03e5Sespie static char *
get_class_name()1246*c87b03e5Sespie get_class_name ()
1247*c87b03e5Sespie {
1248*c87b03e5Sespie   char *result;
1249*c87b03e5Sespie   int last_was_digit;
1250*c87b03e5Sespie   struct obstack name_stack;
1251*c87b03e5Sespie 
1252*c87b03e5Sespie   obstack_init (&name_stack);
1253*c87b03e5Sespie 
1254*c87b03e5Sespie   /* Duplicate the logic of parse.y:maybe_make_nested_class_name().  */
1255*c87b03e5Sespie   last_was_digit = make_class_name_recursive (&name_stack,
1256*c87b03e5Sespie 					      current_class_context->next);
1257*c87b03e5Sespie 
1258*c87b03e5Sespie   if (! last_was_digit
1259*c87b03e5Sespie       && method_depth
1260*c87b03e5Sespie       && current_class_context->name != anonymous_context)
1261*c87b03e5Sespie     {
1262*c87b03e5Sespie       char buf[50];
1263*c87b03e5Sespie       ++anonymous_count;
1264*c87b03e5Sespie       sprintf (buf, "%d", anonymous_count);
1265*c87b03e5Sespie       obstack_grow (&name_stack, buf, strlen (buf));
1266*c87b03e5Sespie       obstack_1grow (&name_stack, '$');
1267*c87b03e5Sespie     }
1268*c87b03e5Sespie 
1269*c87b03e5Sespie   if (current_class_context->name == anonymous_context)
1270*c87b03e5Sespie     {
1271*c87b03e5Sespie       char buf[50];
1272*c87b03e5Sespie       ++anonymous_count;
1273*c87b03e5Sespie       sprintf (buf, "%d", anonymous_count);
1274*c87b03e5Sespie       current_class_context->name = xstrdup (buf);
1275*c87b03e5Sespie       obstack_grow0 (&name_stack, buf, strlen (buf));
1276*c87b03e5Sespie     }
1277*c87b03e5Sespie   else
1278*c87b03e5Sespie     obstack_grow0 (&name_stack, current_class_context->name,
1279*c87b03e5Sespie 		   strlen (current_class_context->name));
1280*c87b03e5Sespie 
1281*c87b03e5Sespie   result = xstrdup (obstack_finish (&name_stack));
1282*c87b03e5Sespie   obstack_free (&name_stack, NULL);
1283*c87b03e5Sespie 
1284*c87b03e5Sespie   return result;
1285*c87b03e5Sespie }
1286*c87b03e5Sespie 
1287*c87b03e5Sespie /* Actions defined here */
1288*c87b03e5Sespie 
1289*c87b03e5Sespie static void
report_class_declaration(name)1290*c87b03e5Sespie report_class_declaration (name)
1291*c87b03e5Sespie      const char * name;
1292*c87b03e5Sespie {
1293*c87b03e5Sespie   extern int flag_dump_class, flag_list_filename;
1294*c87b03e5Sespie 
1295*c87b03e5Sespie   push_class_context (name);
1296*c87b03e5Sespie   if (flag_dump_class)
1297*c87b03e5Sespie     {
1298*c87b03e5Sespie       char *name = get_class_name ();
1299*c87b03e5Sespie 
1300*c87b03e5Sespie       if (!previous_output)
1301*c87b03e5Sespie 	{
1302*c87b03e5Sespie 	  if (flag_list_filename)
1303*c87b03e5Sespie 	    fprintf (out, "%s: ", input_filename);
1304*c87b03e5Sespie 	  previous_output = 1;
1305*c87b03e5Sespie 	}
1306*c87b03e5Sespie 
1307*c87b03e5Sespie       if (package_name)
1308*c87b03e5Sespie 	fprintf (out, "%s.%s ", package_name, name);
1309*c87b03e5Sespie       else
1310*c87b03e5Sespie 	fprintf (out, "%s ", name);
1311*c87b03e5Sespie 
1312*c87b03e5Sespie       free (name);
1313*c87b03e5Sespie     }
1314*c87b03e5Sespie }
1315*c87b03e5Sespie 
1316*c87b03e5Sespie static void
report_main_declaration(declarator)1317*c87b03e5Sespie report_main_declaration (declarator)
1318*c87b03e5Sespie      struct method_declarator *declarator;
1319*c87b03e5Sespie {
1320*c87b03e5Sespie   extern int flag_find_main;
1321*c87b03e5Sespie 
1322*c87b03e5Sespie   if (flag_find_main
1323*c87b03e5Sespie       && modifier_value == 2
1324*c87b03e5Sespie       && !strcmp (declarator->method_name, "main")
1325*c87b03e5Sespie       && declarator->args
1326*c87b03e5Sespie       && declarator->args [0] == '['
1327*c87b03e5Sespie       && (! strcmp (declarator->args+1, "String")
1328*c87b03e5Sespie 	  || ! strcmp (declarator->args + 1, "java.lang.String"))
1329*c87b03e5Sespie       && current_class_context)
1330*c87b03e5Sespie     {
1331*c87b03e5Sespie       if (!previous_output)
1332*c87b03e5Sespie 	{
1333*c87b03e5Sespie 	  char *name = get_class_name ();
1334*c87b03e5Sespie 	  if (package_name)
1335*c87b03e5Sespie 	    fprintf (out, "%s.%s ", package_name, name);
1336*c87b03e5Sespie 	  else
1337*c87b03e5Sespie 	    fprintf (out, "%s", name);
1338*c87b03e5Sespie 	  free (name);
1339*c87b03e5Sespie 	  previous_output = 1;
1340*c87b03e5Sespie 	}
1341*c87b03e5Sespie     }
1342*c87b03e5Sespie }
1343*c87b03e5Sespie 
1344*c87b03e5Sespie void
report()1345*c87b03e5Sespie report ()
1346*c87b03e5Sespie {
1347*c87b03e5Sespie   extern int flag_complexity;
1348*c87b03e5Sespie   if (flag_complexity)
1349*c87b03e5Sespie     fprintf (out, "%s %d\n", input_filename, complexity);
1350*c87b03e5Sespie }
1351*c87b03e5Sespie 
1352*c87b03e5Sespie /* Reset global status used by the report functions.  */
1353*c87b03e5Sespie 
reset_report()1354*c87b03e5Sespie void reset_report ()
1355*c87b03e5Sespie {
1356*c87b03e5Sespie   previous_output = 0;
1357*c87b03e5Sespie   package_name = NULL;
1358*c87b03e5Sespie   current_class_context = NULL;
1359*c87b03e5Sespie   complexity = 0;
1360*c87b03e5Sespie }
1361*c87b03e5Sespie 
1362*c87b03e5Sespie void
yyerror(msg)1363*c87b03e5Sespie yyerror (msg)
1364*c87b03e5Sespie      const char *msg ATTRIBUTE_UNUSED;
1365*c87b03e5Sespie {
1366*c87b03e5Sespie   fprintf (stderr, "%s: %d: %s\n", input_filename, lineno, msg);
1367*c87b03e5Sespie   exit (1);
1368*c87b03e5Sespie }
1369