]> gcc.gnu.org Git - gcc.git/blame - gcc/java/lang.c
buffer.h: PROTO -> PARAMS.
[gcc.git] / gcc / java / lang.c
CommitLineData
e04a16fb 1/* Java(TM) language-specific utility routines.
df32d2ce 2 Copyright (C) 1996, 97-99, 2000 Free Software Foundation, Inc.
e04a16fb
AG
3
4This file is part of GNU CC.
5
6GNU CC is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU CC is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU CC; see the file COPYING. If not, write to
18the Free Software Foundation, 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA.
20
21Java and all Java-based marks are trademarks or registered trademarks
22of Sun Microsystems, Inc. in the United States and other countries.
23The Free Software Foundation is independent of Sun Microsystems, Inc. */
24
25/* Hacked by Per Bothner <bothner@cygnus.com> February 1996. */
26
e04a16fb 27#include "config.h"
1f43f4b4 28#include "system.h"
e04a16fb
AG
29#include "tree.h"
30#include "input.h"
49f48c71
KG
31#include "rtl.h"
32#include "expr.h"
e04a16fb
AG
33#include "java-tree.h"
34#include "jcf.h"
1f43f4b4 35#include "toplev.h"
fc45c7ef 36#include "flags.h"
235acd35 37#include "xref.h"
e04a16fb 38
df32d2ce
KG
39static void put_decl_string PARAMS ((const char *, int));
40static void put_decl_node PARAMS ((tree));
41static void java_dummy_print PARAMS ((const char *));
42static void lang_print_error PARAMS ((const char *));
c8e7d2e6 43
8603f9c5
TT
44#ifndef OBJECT_SUFFIX
45# define OBJECT_SUFFIX ".o"
46#endif
47
e4de5a10
PB
48/* Table indexed by tree code giving a string containing a character
49 classifying the tree code. Possibilities are
50 t, d, s, c, r, <, 1 and 2. See java/java-tree.def for details. */
51
52#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
53
54char java_tree_code_type[] = {
55 'x',
56#include "java-tree.def"
57};
58#undef DEFTREECODE
59
60/* Table indexed by tree code giving number of expression
61 operands beyond the fixed part of the node structure.
62 Not used for types or decls. */
63
64#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
65
66int java_tree_code_length[] = {
67 0,
68#include "java-tree.def"
69};
70#undef DEFTREECODE
71
72/* Names of tree components.
73 Used for printing out the tree and error messages. */
74#define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
75
d4476be2 76const char *java_tree_code_name[] = {
e4de5a10
PB
77 "@@dummy",
78#include "java-tree.def"
79};
80#undef DEFTREECODE
81
e04a16fb
AG
82int compiling_from_source;
83
f425a887 84const char * const language_string = "GNU Java";
e04a16fb 85
e04a16fb
AG
86/* Nonzero if we should make is_compiled_class always return 1 for
87 appropriate classes that we're referencing. */
88
89int flag_assume_compiled = 1;
90
91int flag_emit_class_files = 0;
92
235acd35
APB
93/* When non zero, we emit xref strings. Values of the flag for xref
94 backends are defined in xref_flag_table, xref.c. */
95
96int flag_emit_xref = 0;
97
c877974e
APB
98/* When non zero, -Wall was turned on. */
99int flag_wall = 0;
100
101/* When non zero, check for redundant modifier uses. */
102int flag_redundant = 0;
103
104/* When non zero, warns about overridings that don't occur. */
105int flag_not_overriding = 0;
106
107/* When non zero, warns that final local are treated as non final. */
108int flag_static_local_jdk1_1 = 0;
109
aa4759c1
AH
110/* When non zero, call a library routine to do integer divisions. */
111int flag_use_divide_subroutine = 1;
112
c877974e 113/* From gcc/flags.h, and indicates if exceptions are turned on or not. */
e04a16fb
AG
114
115extern int flag_new_exceptions;
116extern int flag_exceptions;
117
118/* Table of language-dependent -f options.
119 STRING is the option name. VARIABLE is the address of the variable.
120 ON_VALUE is the value to store in VARIABLE
121 if `-fSTRING' is seen as an option.
122 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
123
4bcde32e
KG
124static struct { const char *string; int *variable; int on_value;}
125lang_f_options[] =
e04a16fb 126{
e04a16fb
AG
127 {"emit-class-file", &flag_emit_class_files, 1},
128 {"emit-class-files", &flag_emit_class_files, 1},
aa4759c1 129 {"use-divide-subroutine", &flag_use_divide_subroutine, 1},
e04a16fb
AG
130};
131
e04a16fb
AG
132JCF *current_jcf;
133
fc45c7ef
TT
134/* Variable controlling how dependency tracking is enabled in
135 init_parse. */
136static int dependency_tracking = 0;
137
138/* Flag values for DEPENDENCY_TRACKING. */
139#define DEPEND_SET_FILE 1
140#define DEPEND_ENABLE 2
141
e04a16fb
AG
142/*
143 * process java-specific compiler command-line options
03d32d1a 144 * return 0, but do not complain if the option is not recognised.
e04a16fb
AG
145 */
146int
147lang_decode_option (argc, argv)
0a2138e2 148 int argc __attribute__ ((__unused__));
e04a16fb
AG
149 char **argv;
150{
151 char *p = argv[0];
71f6a8e2 152
48aedbca
AG
153#define CLARG "-fassume-compiled="
154 if (strncmp (p, CLARG, sizeof (CLARG) - 1) == 0)
155 {
156 add_assume_compiled (p + sizeof (CLARG) - 1, 0);
157 return 1;
158 }
159#undef CLARG
160#define CLARG "-fno-assume-compiled="
161 if (strncmp (p, CLARG, sizeof (CLARG) - 1) == 0)
162 {
163 add_assume_compiled (p + sizeof (CLARG) - 1, 1);
164 return 1;
165 }
166#undef CLARG
167#define CLARG "-fassume-compiled"
168 if (strncmp (p, CLARG, sizeof (CLARG) - 1) == 0)
169 {
170 add_assume_compiled ("", 0);
171 return 1;
172 }
173#undef CLARG
174#define CLARG "-fno-assume-compiled"
175 if (strncmp (p, CLARG, sizeof (CLARG) - 1) == 0)
176 {
177 add_assume_compiled ("", 1);
178 return 1;
179 }
180#undef CLARG
71f6a8e2
TT
181#define CLARG "-fclasspath="
182 if (strncmp (p, CLARG, sizeof (CLARG) - 1) == 0)
183 {
184 jcf_path_classpath_arg (p + sizeof (CLARG) - 1);
185 return 1;
186 }
187#undef CLARG
188#define CLARG "-fCLASSPATH="
48aedbca 189 if (strncmp (p, CLARG, sizeof (CLARG) - 1) == 0)
71f6a8e2
TT
190 {
191 jcf_path_CLASSPATH_arg (p + sizeof (CLARG) - 1);
192 return 1;
193 }
194#undef CLARG
195 else if (strncmp (p, "-I", 2) == 0)
196 {
197 jcf_path_include_arg (p + 2);
198 return 1;
199 }
200
df66b566
TT
201#define ARG "-foutput-class-dir="
202 if (strncmp (p, ARG, sizeof (ARG) - 1) == 0)
203 {
204 jcf_write_base_directory = p + sizeof (ARG) - 1;
205 return 1;
206 }
207#undef ARG
208
e04a16fb
AG
209 if (p[0] == '-' && p[1] == 'f')
210 {
211 /* Some kind of -f option.
212 P's value is the option sans `-f'.
213 Search for it in the table of options. */
214 int found = 0, j;
215
216 p += 2;
217
218 for (j = 0;
0a2138e2
APB
219 !found
220 && j < (int)(sizeof (lang_f_options) / sizeof (lang_f_options[0]));
221 j++)
e04a16fb
AG
222 {
223 if (!strcmp (p, lang_f_options[j].string))
224 {
225 *lang_f_options[j].variable = lang_f_options[j].on_value;
226 /* A goto here would be cleaner,
227 but breaks the vax pcc. */
228 found = 1;
229 }
230 if (p[0] == 'n' && p[1] == 'o' && p[2] == '-'
231 && ! strcmp (p+3, lang_f_options[j].string))
232 {
233 *lang_f_options[j].variable = ! lang_f_options[j].on_value;
234 found = 1;
235 }
236 }
fc45c7ef 237
e04a16fb
AG
238 return found;
239 }
240
c877974e
APB
241 if (strcmp (p, "-Wall") == 0)
242 {
243 flag_wall = 1;
244 flag_redundant = 1;
7f10c2e2
APB
245 return 1;
246 }
247
248 if (strcmp (p, "-Wunsupported-jdk11") == 0)
249 {
c877974e 250 flag_static_local_jdk1_1 = 1;
e8fc7396 251 return 1;
c877974e
APB
252 }
253
4e9dd506 254 if (strcmp (p, "-Wredundant-modifiers") == 0)
7f10c2e2
APB
255 {
256 flag_redundant = 1;
257 return 1;
258 }
259
fc45c7ef
TT
260 if (strcmp (p, "-MD") == 0)
261 {
262 jcf_dependency_init (1);
263 dependency_tracking |= DEPEND_SET_FILE | DEPEND_ENABLE;
264 return 1;
265 }
266 else if (strcmp (p, "-MMD") == 0)
267 {
268 jcf_dependency_init (0);
269 dependency_tracking |= DEPEND_SET_FILE | DEPEND_ENABLE;
270 return 1;
271 }
272 else if (strcmp (p, "-M") == 0)
273 {
274 jcf_dependency_init (1);
275 dependency_tracking |= DEPEND_ENABLE;
276 return 1;
277 }
278 else if (strcmp (p, "-MM") == 0)
279 {
280 jcf_dependency_init (0);
281 dependency_tracking |= DEPEND_ENABLE;
282 return 1;
283 }
284
e04a16fb
AG
285 return 0;
286}
287
288FILE *finput;
289char *
290init_parse (filename)
291 char *filename;
292{
293 /* Open input file. */
294
295 if (filename == 0 || !strcmp (filename, "-"))
296 {
297 finput = stdin;
298 filename = "stdin";
fc45c7ef
TT
299
300 if (dependency_tracking)
301 error ("can't do dependency tracking with input from stdin");
e04a16fb
AG
302 }
303 else
fc45c7ef
TT
304 {
305 if (dependency_tracking)
306 {
307 char *dot;
308 dot = strrchr (filename, '.');
309 if (dot == NULL)
310 error ("couldn't determine target name for dependency tracking");
311 else
312 {
8603f9c5
TT
313 char *buf = (char *) xmalloc (dot - filename +
314 3 + sizeof (OBJECT_SUFFIX));
fc45c7ef
TT
315 strncpy (buf, filename, dot - filename);
316
317 /* If emitting class files, we might have multiple
318 targets. The class generation code takes care of
319 registering them. Otherwise we compute the target
320 name here. */
321 if (flag_emit_class_files)
322 jcf_dependency_set_target (NULL);
323 else
324 {
8603f9c5 325 strcpy (buf + (dot - filename), OBJECT_SUFFIX);
fc45c7ef
TT
326 jcf_dependency_set_target (buf);
327 }
328
329 if ((dependency_tracking & DEPEND_SET_FILE))
330 {
331 strcpy (buf + (dot - filename), ".d");
332 jcf_dependency_set_dep_file (buf);
333 }
334 else
335 jcf_dependency_set_dep_file ("-");
336
337 free (buf);
338 }
339 }
fc45c7ef 340 }
e04a16fb
AG
341 init_lex ();
342
343 return filename;
344}
345
346void
347finish_parse ()
348{
349 fclose (finput);
fc45c7ef 350 jcf_dependency_write ();
e04a16fb
AG
351}
352
353/* Buffer used by lang_printable_name. */
354static char *decl_buf = NULL;
355
356/* Allocated size of decl_buf. */
357static int decl_buflen = 0;
358
359/* Length of used part of decl_buf; position for next character. */
360static int decl_bufpos = 0;
361
362/* Append the string STR to decl_buf.
363 It length is given by LEN; -1 means the string is nul-terminated. */
364
365static void
366put_decl_string (str, len)
c8e7d2e6 367 const char *str;
e04a16fb
AG
368 int len;
369{
370 if (len < 0)
371 len = strlen (str);
372 if (decl_bufpos + len >= decl_buflen)
373 {
374 if (decl_buf == NULL)
375 {
376 decl_buflen = len + 100;
377 decl_buf = (char *) xmalloc (decl_buflen);
378 }
379 else
380 {
381 decl_buflen *= 2;
382 decl_buf = (char *) xrealloc (decl_buf, decl_buflen);
383 }
384 }
385 strcpy (decl_buf + decl_bufpos, str);
386 decl_bufpos += len;
387}
388
389/* Append to decl_buf a printable name for NODE. */
390
391static void
392put_decl_node (node)
393 tree node;
394{
395 int was_pointer = 0;
396 if (TREE_CODE (node) == POINTER_TYPE)
397 {
398 node = TREE_TYPE (node);
399 was_pointer = 1;
400 }
401 if (TREE_CODE_CLASS (TREE_CODE (node)) == 'd'
402 && DECL_NAME (node) != NULL_TREE)
403 {
404#if 0
405 if (DECL_CONTEXT (node) != NULL_TREE)
406 {
407 put_decl_node (DECL_CONTEXT (node));
408 put_decl_string (".", 1);
409 }
410#endif
23a79c61
APB
411 if (TREE_CODE (node) == FUNCTION_DECL
412 && DECL_NAME (node) == init_identifier_node
413 && !DECL_ARTIFICIAL (node) && current_class)
414 put_decl_node (TYPE_NAME (current_class));
415 else
416 put_decl_node (DECL_NAME (node));
e04a16fb
AG
417 if (TREE_CODE (node) == FUNCTION_DECL && TREE_TYPE (node) != NULL_TREE)
418 {
419 int i = 0;
420 tree args = TYPE_ARG_TYPES (TREE_TYPE (node));
421 if (TREE_CODE (TREE_TYPE (node)) == METHOD_TYPE)
422 args = TREE_CHAIN (args);
423 put_decl_string ("(", 1);
de4c7b02 424 for ( ; args != end_params_node; args = TREE_CHAIN (args), i++)
e04a16fb
AG
425 {
426 if (i > 0)
427 put_decl_string (",", 1);
428 put_decl_node (TREE_VALUE (args));
429 }
430 put_decl_string (")", 1);
431 }
432 }
433 else if (TREE_CODE_CLASS (TREE_CODE (node)) == 't'
434 && TYPE_NAME (node) != NULL_TREE)
435 {
436 if (TREE_CODE (node) == RECORD_TYPE && TYPE_ARRAY_P (node))
437 {
438 put_decl_node (TYPE_ARRAY_ELEMENT (node));
439 put_decl_string("[]", 2);
440 }
441 else if (node == promoted_byte_type_node)
442 put_decl_string ("byte", 4);
443 else if (node == promoted_short_type_node)
444 put_decl_string ("short", 5);
445 else if (node == promoted_char_type_node)
446 put_decl_string ("char", 4);
447 else if (node == promoted_boolean_type_node)
448 put_decl_string ("boolean", 7);
449 else if (node == void_type_node && was_pointer)
450 put_decl_string ("null", 4);
451 else
452 put_decl_node (TYPE_NAME (node));
453 }
454 else if (TREE_CODE (node) == IDENTIFIER_NODE)
455 put_decl_string (IDENTIFIER_POINTER (node), IDENTIFIER_LENGTH (node));
456 else
457 put_decl_string ("<unknown>", -1);
458}
459
460/* Return a user-friendly name for DECL.
461 The resulting string is only valid until the next call.
462 The value of the hook decl_printable_name is this function,
463 which is also called directly by lang_print_error. */
464
1b93a502 465const char *
e04a16fb
AG
466lang_printable_name (decl, v)
467 tree decl;
0a2138e2 468 int v __attribute__ ((__unused__));
e04a16fb
AG
469{
470 decl_bufpos = 0;
471 put_decl_node (decl);
472 put_decl_string ("", 1);
473 return decl_buf;
474}
475
476/* Print on stderr the current class and method context. This function
477 is the value of the hook print_error_function, called from toplev.c. */
478
be245ac0 479static void
e04a16fb 480lang_print_error (file)
0070eeda 481 const char *file;
e04a16fb
AG
482{
483 static tree last_error_function_context = NULL_TREE;
484 static tree last_error_function = NULL;
485
486 if (current_function_decl != NULL
487 && DECL_CONTEXT (current_function_decl) != last_error_function_context)
488 {
489 if (file)
490 fprintf (stderr, "%s: ", file);
491
492 last_error_function_context = DECL_CONTEXT (current_function_decl);
493 fprintf (stderr, "In class `%s':\n",
0a2138e2 494 lang_printable_name (last_error_function_context, 0));
e04a16fb
AG
495 }
496 if (last_error_function != current_function_decl)
497 {
498 if (file)
499 fprintf (stderr, "%s: ", file);
500
501 if (current_function_decl == NULL)
502 fprintf (stderr, "At top level:\n");
503 else
504 {
c8e7d2e6 505 const char *name = lang_printable_name (current_function_decl, 2);
e04a16fb
AG
506 fprintf (stderr, "In method `%s':\n", name);
507 }
508
509 last_error_function = current_function_decl;
510 }
511
512}
513
514void
515lang_init ()
516{
e04a16fb
AG
517#if 0
518 extern int flag_minimal_debug;
519 flag_minimal_debug = 0;
520#endif
521
8603f9c5
TT
522 jcf_path_init ();
523 jcf_path_seal ();
524
e04a16fb
AG
525 decl_printable_name = lang_printable_name;
526 print_error_function = lang_print_error;
527 lang_expand_expr = java_lang_expand_expr;
528
e04a16fb 529 flag_exceptions = 1;
e4de5a10
PB
530
531 /* Append to Gcc tree node definition arrays */
532
be245ac0
KG
533 memcpy (tree_code_type + (int) LAST_AND_UNUSED_TREE_CODE,
534 java_tree_code_type,
535 (int)LAST_JAVA_TREE_CODE - (int)LAST_AND_UNUSED_TREE_CODE);
536 memcpy (tree_code_length + (int) LAST_AND_UNUSED_TREE_CODE,
537 java_tree_code_length,
538 (LAST_JAVA_TREE_CODE -
539 (int)LAST_AND_UNUSED_TREE_CODE) * sizeof (int));
540 memcpy (tree_code_name + (int) LAST_AND_UNUSED_TREE_CODE,
541 java_tree_code_name,
542 (LAST_JAVA_TREE_CODE -
543 (int)LAST_AND_UNUSED_TREE_CODE) * sizeof (char *));
e402ca98
PB
544
545 using_eh_for_cleanups ();
e04a16fb
AG
546}
547
548/* This doesn't do anything on purpose. It's used to satisfy the
549 print_error_function hook we don't print error messages with bogus
550 function prototypes. */
551
0070eeda
KG
552static void
553java_dummy_print (s)
554 const char *s __attribute__ ((__unused__));
e04a16fb
AG
555{
556}
557
558/* Called to install the PRINT_ERROR_FUNCTION hook differently
559 according to LEVEL. LEVEL is 1 during early parsing, when function
560 prototypes aren't fully resolved. print_error_function is set so it
561 doesn't print incomplete function prototypes. When LEVEL is 2,
562 function prototypes are fully resolved and can be printed when
563 reporting errors. */
564
565void lang_init_source (level)
566 int level;
567{
e04a16fb
AG
568 if (level == 1)
569 print_error_function = java_dummy_print;
570 else
571 print_error_function = lang_print_error;
572}
573
574void
575lang_init_options ()
576{
577 flag_new_exceptions = 1;
13f9ac51 578 flag_bounds_check = 1;
e04a16fb
AG
579}
580
581void
582lang_finish ()
583{
584}
585
0070eeda 586const char *
e04a16fb
AG
587lang_identify ()
588{
589 return "Java";
590}
591
592/* Hooks for print_node. */
593
594void
595print_lang_decl (file, node, indent)
0a2138e2
APB
596 FILE *file __attribute ((__unused__));
597 tree node __attribute ((__unused__));
598 int indent __attribute ((__unused__));
e04a16fb
AG
599{
600}
601
602void
603print_lang_type (file, node, indent)
0a2138e2
APB
604 FILE *file __attribute ((__unused__));
605 tree node __attribute ((__unused__));
606 int indent __attribute ((__unused__));
e04a16fb
AG
607{
608}
609
610void
611print_lang_identifier (file, node, indent)
0a2138e2
APB
612 FILE *file __attribute ((__unused__));
613 tree node __attribute ((__unused__));
614 int indent __attribute ((__unused__));
e04a16fb
AG
615{
616}
617
618void
619print_lang_statistics ()
620{
621}
622
623/* used by print-tree.c */
624
625void
626lang_print_xnode (file, node, indent)
0a2138e2
APB
627 FILE *file __attribute ((__unused__));
628 tree node __attribute ((__unused__));
629 int indent __attribute ((__unused__));
e04a16fb
AG
630{
631}
This page took 1.276914 seconds and 5 git commands to generate.