1 /* Java(TM) language-specific utility routines.
2 Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
21 Java and all Java-based marks are trademarks or registered trademarks
22 of Sun Microsystems, Inc. in the United States and other countries.
23 The Free Software Foundation is independent of Sun Microsystems, Inc. */
25 /* Hacked by Per Bothner <bothner@cygnus.com> February 1996. */
33 #include "java-tree.h"
39 static void put_decl_string
PARAMS ((const char *, int));
40 static void put_decl_node
PARAMS ((tree
));
41 static void java_dummy_print
PARAMS ((const char *));
42 static void lang_print_error
PARAMS ((const char *));
45 # define OBJECT_SUFFIX ".o"
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. */
52 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
54 char java_tree_code_type
[] = {
56 #include "java-tree.def"
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. */
64 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
66 int java_tree_code_length
[] = {
68 #include "java-tree.def"
72 /* Names of tree components.
73 Used for printing out the tree and error messages. */
74 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
76 const char *java_tree_code_name
[] = {
78 #include "java-tree.def"
82 int compiling_from_source
;
84 const char * const language_string
= "GNU Java";
86 /* Nonzero if we should make is_compiled_class always return 1 for
87 appropriate classes that we're referencing. */
89 int flag_assume_compiled
= 1;
91 int flag_emit_class_files
= 0;
93 /* When non zero, we emit xref strings. Values of the flag for xref
94 backends are defined in xref_flag_table, xref.c. */
96 int flag_emit_xref
= 0;
98 /* When non zero, -Wall was turned on. */
101 /* When non zero, check for redundant modifier uses. */
102 int flag_redundant
= 0;
104 /* When non zero, warns about overridings that don't occur. */
105 int flag_not_overriding
= 0;
107 /* When non zero, warns that final local are treated as non final. */
108 int flag_static_local_jdk1_1
= 0;
110 /* When non zero, call a library routine to do integer divisions. */
111 int flag_use_divide_subroutine
= 1;
113 /* When non zero, generate code for the Boehm GC. */
114 int flag_use_boehm_gc
= 0;
116 /* From gcc/flags.h, and indicates if exceptions are turned on or not. */
118 extern int flag_new_exceptions
;
119 extern int flag_exceptions
;
121 /* Table of language-dependent -f options.
122 STRING is the option name. VARIABLE is the address of the variable.
123 ON_VALUE is the value to store in VARIABLE
124 if `-fSTRING' is seen as an option.
125 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
127 static struct { const char *string
; int *variable
; int on_value
;}
130 {"emit-class-file", &flag_emit_class_files
, 1},
131 {"emit-class-files", &flag_emit_class_files
, 1},
132 {"use-divide-subroutine", &flag_use_divide_subroutine
, 1},
133 {"use-boehm-gc", &flag_use_boehm_gc
, 1}
138 /* Variable controlling how dependency tracking is enabled in
140 static int dependency_tracking
= 0;
142 /* Flag values for DEPENDENCY_TRACKING. */
143 #define DEPEND_SET_FILE 1
144 #define DEPEND_ENABLE 2
147 * process java-specific compiler command-line options
148 * return 0, but do not complain if the option is not recognised.
151 lang_decode_option (argc
, argv
)
152 int argc
__attribute__ ((__unused__
));
157 #define CLARG "-fassume-compiled="
158 if (strncmp (p
, CLARG
, sizeof (CLARG
) - 1) == 0)
160 add_assume_compiled (p
+ sizeof (CLARG
) - 1, 0);
164 #define CLARG "-fno-assume-compiled="
165 if (strncmp (p
, CLARG
, sizeof (CLARG
) - 1) == 0)
167 add_assume_compiled (p
+ sizeof (CLARG
) - 1, 1);
171 #define CLARG "-fassume-compiled"
172 if (strncmp (p
, CLARG
, sizeof (CLARG
) - 1) == 0)
174 add_assume_compiled ("", 0);
178 #define CLARG "-fno-assume-compiled"
179 if (strncmp (p
, CLARG
, sizeof (CLARG
) - 1) == 0)
181 add_assume_compiled ("", 1);
185 #define CLARG "-fclasspath="
186 if (strncmp (p
, CLARG
, sizeof (CLARG
) - 1) == 0)
188 jcf_path_classpath_arg (p
+ sizeof (CLARG
) - 1);
192 #define CLARG "-fCLASSPATH="
193 if (strncmp (p
, CLARG
, sizeof (CLARG
) - 1) == 0)
195 jcf_path_CLASSPATH_arg (p
+ sizeof (CLARG
) - 1);
199 else if (strncmp (p
, "-I", 2) == 0)
201 jcf_path_include_arg (p
+ 2);
205 #define ARG "-foutput-class-dir="
206 if (strncmp (p
, ARG
, sizeof (ARG
) - 1) == 0)
208 jcf_write_base_directory
= p
+ sizeof (ARG
) - 1;
213 if (p
[0] == '-' && p
[1] == 'f')
215 /* Some kind of -f option.
216 P's value is the option sans `-f'.
217 Search for it in the table of options. */
224 && j
< (int)(sizeof (lang_f_options
) / sizeof (lang_f_options
[0]));
227 if (!strcmp (p
, lang_f_options
[j
].string
))
229 *lang_f_options
[j
].variable
= lang_f_options
[j
].on_value
;
230 /* A goto here would be cleaner,
231 but breaks the vax pcc. */
234 if (p
[0] == 'n' && p
[1] == 'o' && p
[2] == '-'
235 && ! strcmp (p
+3, lang_f_options
[j
].string
))
237 *lang_f_options
[j
].variable
= ! lang_f_options
[j
].on_value
;
245 if (strcmp (p
, "-Wall") == 0)
252 if (strcmp (p
, "-Wunsupported-jdk11") == 0)
254 flag_static_local_jdk1_1
= 1;
258 if (strcmp (p
, "-Wredundant-modifiers") == 0)
264 if (strcmp (p
, "-MD") == 0)
266 jcf_dependency_init (1);
267 dependency_tracking
|= DEPEND_SET_FILE
| DEPEND_ENABLE
;
270 else if (strcmp (p
, "-MMD") == 0)
272 jcf_dependency_init (0);
273 dependency_tracking
|= DEPEND_SET_FILE
| DEPEND_ENABLE
;
276 else if (strcmp (p
, "-M") == 0)
278 jcf_dependency_init (1);
279 dependency_tracking
|= DEPEND_ENABLE
;
282 else if (strcmp (p
, "-MM") == 0)
284 jcf_dependency_init (0);
285 dependency_tracking
|= DEPEND_ENABLE
;
294 init_parse (filename
)
297 /* Open input file. */
299 if (filename
== 0 || !strcmp (filename
, "-"))
304 if (dependency_tracking
)
305 error ("can't do dependency tracking with input from stdin");
309 if (dependency_tracking
)
312 dot
= strrchr (filename
, '.');
314 error ("couldn't determine target name for dependency tracking");
317 char *buf
= (char *) xmalloc (dot
- filename
+
318 3 + sizeof (OBJECT_SUFFIX
));
319 strncpy (buf
, filename
, dot
- filename
);
321 /* If emitting class files, we might have multiple
322 targets. The class generation code takes care of
323 registering them. Otherwise we compute the target
325 if (flag_emit_class_files
)
326 jcf_dependency_set_target (NULL
);
329 strcpy (buf
+ (dot
- filename
), OBJECT_SUFFIX
);
330 jcf_dependency_set_target (buf
);
333 if ((dependency_tracking
& DEPEND_SET_FILE
))
335 strcpy (buf
+ (dot
- filename
), ".d");
336 jcf_dependency_set_dep_file (buf
);
339 jcf_dependency_set_dep_file ("-");
354 jcf_dependency_write ();
357 /* Buffer used by lang_printable_name. */
358 static char *decl_buf
= NULL
;
360 /* Allocated size of decl_buf. */
361 static int decl_buflen
= 0;
363 /* Length of used part of decl_buf; position for next character. */
364 static int decl_bufpos
= 0;
366 /* Append the string STR to decl_buf.
367 It length is given by LEN; -1 means the string is nul-terminated. */
370 put_decl_string (str
, len
)
376 if (decl_bufpos
+ len
>= decl_buflen
)
378 if (decl_buf
== NULL
)
380 decl_buflen
= len
+ 100;
381 decl_buf
= (char *) xmalloc (decl_buflen
);
386 decl_buf
= (char *) xrealloc (decl_buf
, decl_buflen
);
389 strcpy (decl_buf
+ decl_bufpos
, str
);
393 /* Append to decl_buf a printable name for NODE. */
400 if (TREE_CODE (node
) == POINTER_TYPE
)
402 node
= TREE_TYPE (node
);
405 if (TREE_CODE_CLASS (TREE_CODE (node
)) == 'd'
406 && DECL_NAME (node
) != NULL_TREE
)
409 if (DECL_CONTEXT (node
) != NULL_TREE
)
411 put_decl_node (DECL_CONTEXT (node
));
412 put_decl_string (".", 1);
415 if (TREE_CODE (node
) == FUNCTION_DECL
416 && DECL_NAME (node
) == init_identifier_node
417 && !DECL_ARTIFICIAL (node
) && current_class
)
418 put_decl_node (TYPE_NAME (current_class
));
420 put_decl_node (DECL_NAME (node
));
421 if (TREE_CODE (node
) == FUNCTION_DECL
&& TREE_TYPE (node
) != NULL_TREE
)
424 tree args
= TYPE_ARG_TYPES (TREE_TYPE (node
));
425 if (TREE_CODE (TREE_TYPE (node
)) == METHOD_TYPE
)
426 args
= TREE_CHAIN (args
);
427 put_decl_string ("(", 1);
428 for ( ; args
!= end_params_node
; args
= TREE_CHAIN (args
), i
++)
431 put_decl_string (",", 1);
432 put_decl_node (TREE_VALUE (args
));
434 put_decl_string (")", 1);
437 else if (TREE_CODE_CLASS (TREE_CODE (node
)) == 't'
438 && TYPE_NAME (node
) != NULL_TREE
)
440 if (TREE_CODE (node
) == RECORD_TYPE
&& TYPE_ARRAY_P (node
))
442 put_decl_node (TYPE_ARRAY_ELEMENT (node
));
443 put_decl_string("[]", 2);
445 else if (node
== promoted_byte_type_node
)
446 put_decl_string ("byte", 4);
447 else if (node
== promoted_short_type_node
)
448 put_decl_string ("short", 5);
449 else if (node
== promoted_char_type_node
)
450 put_decl_string ("char", 4);
451 else if (node
== promoted_boolean_type_node
)
452 put_decl_string ("boolean", 7);
453 else if (node
== void_type_node
&& was_pointer
)
454 put_decl_string ("null", 4);
456 put_decl_node (TYPE_NAME (node
));
458 else if (TREE_CODE (node
) == IDENTIFIER_NODE
)
459 put_decl_string (IDENTIFIER_POINTER (node
), IDENTIFIER_LENGTH (node
));
461 put_decl_string ("<unknown>", -1);
464 /* Return a user-friendly name for DECL.
465 The resulting string is only valid until the next call.
466 The value of the hook decl_printable_name is this function,
467 which is also called directly by lang_print_error. */
470 lang_printable_name (decl
, v
)
472 int v
__attribute__ ((__unused__
));
475 put_decl_node (decl
);
476 put_decl_string ("", 1);
480 /* Print on stderr the current class and method context. This function
481 is the value of the hook print_error_function, called from toplev.c. */
484 lang_print_error (file
)
487 static tree last_error_function_context
= NULL_TREE
;
488 static tree last_error_function
= NULL
;
490 if (current_function_decl
!= NULL
491 && DECL_CONTEXT (current_function_decl
) != last_error_function_context
)
494 fprintf (stderr
, "%s: ", file
);
496 last_error_function_context
= DECL_CONTEXT (current_function_decl
);
497 fprintf (stderr
, "In class `%s':\n",
498 lang_printable_name (last_error_function_context
, 0));
500 if (last_error_function
!= current_function_decl
)
503 fprintf (stderr
, "%s: ", file
);
505 if (current_function_decl
== NULL
)
506 fprintf (stderr
, "At top level:\n");
509 const char *name
= lang_printable_name (current_function_decl
, 2);
510 fprintf (stderr
, "In method `%s':\n", name
);
513 last_error_function
= current_function_decl
;
522 extern int flag_minimal_debug
;
523 flag_minimal_debug
= 0;
529 decl_printable_name
= lang_printable_name
;
530 print_error_function
= lang_print_error
;
531 lang_expand_expr
= java_lang_expand_expr
;
535 /* Append to Gcc tree node definition arrays */
537 memcpy (tree_code_type
+ (int) LAST_AND_UNUSED_TREE_CODE
,
539 (int)LAST_JAVA_TREE_CODE
- (int)LAST_AND_UNUSED_TREE_CODE
);
540 memcpy (tree_code_length
+ (int) LAST_AND_UNUSED_TREE_CODE
,
541 java_tree_code_length
,
542 (LAST_JAVA_TREE_CODE
-
543 (int)LAST_AND_UNUSED_TREE_CODE
) * sizeof (int));
544 memcpy (tree_code_name
+ (int) LAST_AND_UNUSED_TREE_CODE
,
546 (LAST_JAVA_TREE_CODE
-
547 (int)LAST_AND_UNUSED_TREE_CODE
) * sizeof (char *));
549 using_eh_for_cleanups ();
552 /* This doesn't do anything on purpose. It's used to satisfy the
553 print_error_function hook we don't print error messages with bogus
554 function prototypes. */
558 const char *s
__attribute__ ((__unused__
));
562 /* Called to install the PRINT_ERROR_FUNCTION hook differently
563 according to LEVEL. LEVEL is 1 during early parsing, when function
564 prototypes aren't fully resolved. print_error_function is set so it
565 doesn't print incomplete function prototypes. When LEVEL is 2,
566 function prototypes are fully resolved and can be printed when
569 void lang_init_source (level
)
573 print_error_function
= java_dummy_print
;
575 print_error_function
= lang_print_error
;
581 flag_new_exceptions
= 1;
582 flag_bounds_check
= 1;
596 /* Hooks for print_node. */
599 print_lang_decl (file
, node
, indent
)
600 FILE *file
__attribute ((__unused__
));
601 tree node
__attribute ((__unused__
));
602 int indent
__attribute ((__unused__
));
607 print_lang_type (file
, node
, indent
)
608 FILE *file
__attribute ((__unused__
));
609 tree node
__attribute ((__unused__
));
610 int indent
__attribute ((__unused__
));
615 print_lang_identifier (file
, node
, indent
)
616 FILE *file
__attribute ((__unused__
));
617 tree node
__attribute ((__unused__
));
618 int indent
__attribute ((__unused__
));
623 print_lang_statistics ()
627 /* used by print-tree.c */
630 lang_print_xnode (file
, node
, indent
)
631 FILE *file
__attribute ((__unused__
));
632 tree node
__attribute ((__unused__
));
633 int indent
__attribute ((__unused__
));