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 /* When non zero, assume the runtime uses a hash table to map an
117 object to its synchronization structure. */
118 int flag_hash_synchronization
;
120 /* When non zero, assume all native functions are implemented with
124 /* From gcc/flags.h, and indicates if exceptions are turned on or not. */
126 extern int flag_new_exceptions
;
127 extern int flag_exceptions
;
129 /* Table of language-dependent -f options.
130 STRING is the option name. VARIABLE is the address of the variable.
131 ON_VALUE is the value to store in VARIABLE
132 if `-fSTRING' is seen as an option.
133 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
135 static struct { const char *string
; int *variable
; int on_value
;}
138 {"emit-class-file", &flag_emit_class_files
, 1},
139 {"emit-class-files", &flag_emit_class_files
, 1},
140 {"use-divide-subroutine", &flag_use_divide_subroutine
, 1},
141 {"use-boehm-gc", &flag_use_boehm_gc
, 1},
142 {"hash-synchronization", &flag_hash_synchronization
, 1},
143 {"jni", &flag_jni
, 1}
148 /* Variable controlling how dependency tracking is enabled in
150 static int dependency_tracking
= 0;
152 /* Flag values for DEPENDENCY_TRACKING. */
153 #define DEPEND_SET_FILE 1
154 #define DEPEND_ENABLE 2
157 * process java-specific compiler command-line options
158 * return 0, but do not complain if the option is not recognised.
161 lang_decode_option (argc
, argv
)
162 int argc
__attribute__ ((__unused__
));
167 #define CLARG "-fassume-compiled="
168 if (strncmp (p
, CLARG
, sizeof (CLARG
) - 1) == 0)
170 add_assume_compiled (p
+ sizeof (CLARG
) - 1, 0);
174 #define CLARG "-fno-assume-compiled="
175 if (strncmp (p
, CLARG
, sizeof (CLARG
) - 1) == 0)
177 add_assume_compiled (p
+ sizeof (CLARG
) - 1, 1);
181 #define CLARG "-fassume-compiled"
182 if (strncmp (p
, CLARG
, sizeof (CLARG
) - 1) == 0)
184 add_assume_compiled ("", 0);
188 #define CLARG "-fno-assume-compiled"
189 if (strncmp (p
, CLARG
, sizeof (CLARG
) - 1) == 0)
191 add_assume_compiled ("", 1);
195 #define CLARG "-fclasspath="
196 if (strncmp (p
, CLARG
, sizeof (CLARG
) - 1) == 0)
198 jcf_path_classpath_arg (p
+ sizeof (CLARG
) - 1);
202 #define CLARG "-fCLASSPATH="
203 if (strncmp (p
, CLARG
, sizeof (CLARG
) - 1) == 0)
205 jcf_path_CLASSPATH_arg (p
+ sizeof (CLARG
) - 1);
209 else if (strncmp (p
, "-I", 2) == 0)
211 jcf_path_include_arg (p
+ 2);
215 #define ARG "-foutput-class-dir="
216 if (strncmp (p
, ARG
, sizeof (ARG
) - 1) == 0)
218 jcf_write_base_directory
= p
+ sizeof (ARG
) - 1;
223 if (p
[0] == '-' && p
[1] == 'f')
225 /* Some kind of -f option.
226 P's value is the option sans `-f'.
227 Search for it in the table of options. */
234 && j
< (int)(sizeof (lang_f_options
) / sizeof (lang_f_options
[0]));
237 if (!strcmp (p
, lang_f_options
[j
].string
))
239 *lang_f_options
[j
].variable
= lang_f_options
[j
].on_value
;
240 /* A goto here would be cleaner,
241 but breaks the vax pcc. */
244 if (p
[0] == 'n' && p
[1] == 'o' && p
[2] == '-'
245 && ! strcmp (p
+3, lang_f_options
[j
].string
))
247 *lang_f_options
[j
].variable
= ! lang_f_options
[j
].on_value
;
255 if (strcmp (p
, "-Wall") == 0)
259 /* When -Wall given, enable -Wunused. We do this because the C
260 compiler does it, and people expect it. */
265 if (strcmp (p
, "-Wunsupported-jdk11") == 0)
267 flag_static_local_jdk1_1
= 1;
271 if (strcmp (p
, "-Wredundant-modifiers") == 0)
277 if (strcmp (p
, "-MD") == 0)
279 jcf_dependency_init (1);
280 dependency_tracking
|= DEPEND_SET_FILE
| DEPEND_ENABLE
;
283 else if (strcmp (p
, "-MMD") == 0)
285 jcf_dependency_init (0);
286 dependency_tracking
|= DEPEND_SET_FILE
| DEPEND_ENABLE
;
289 else if (strcmp (p
, "-M") == 0)
291 jcf_dependency_init (1);
292 dependency_tracking
|= DEPEND_ENABLE
;
295 else if (strcmp (p
, "-MM") == 0)
297 jcf_dependency_init (0);
298 dependency_tracking
|= DEPEND_ENABLE
;
307 init_parse (filename
)
308 const char *filename
;
310 /* Open input file. */
312 if (filename
== 0 || !strcmp (filename
, "-"))
317 if (dependency_tracking
)
318 error ("can't do dependency tracking with input from stdin");
322 if (dependency_tracking
)
325 dot
= strrchr (filename
, '.');
327 error ("couldn't determine target name for dependency tracking");
330 char *buf
= (char *) xmalloc (dot
- filename
+
331 3 + sizeof (OBJECT_SUFFIX
));
332 strncpy (buf
, filename
, dot
- filename
);
334 /* If emitting class files, we might have multiple
335 targets. The class generation code takes care of
336 registering them. Otherwise we compute the target
338 if (flag_emit_class_files
)
339 jcf_dependency_set_target (NULL
);
342 strcpy (buf
+ (dot
- filename
), OBJECT_SUFFIX
);
343 jcf_dependency_set_target (buf
);
346 if ((dependency_tracking
& DEPEND_SET_FILE
))
348 strcpy (buf
+ (dot
- filename
), ".d");
349 jcf_dependency_set_dep_file (buf
);
352 jcf_dependency_set_dep_file ("-");
367 jcf_dependency_write ();
370 /* Buffer used by lang_printable_name. */
371 static char *decl_buf
= NULL
;
373 /* Allocated size of decl_buf. */
374 static int decl_buflen
= 0;
376 /* Length of used part of decl_buf; position for next character. */
377 static int decl_bufpos
= 0;
379 /* Append the string STR to decl_buf.
380 It length is given by LEN; -1 means the string is nul-terminated. */
383 put_decl_string (str
, len
)
389 if (decl_bufpos
+ len
>= decl_buflen
)
391 if (decl_buf
== NULL
)
393 decl_buflen
= len
+ 100;
394 decl_buf
= (char *) xmalloc (decl_buflen
);
399 decl_buf
= (char *) xrealloc (decl_buf
, decl_buflen
);
402 strcpy (decl_buf
+ decl_bufpos
, str
);
406 /* Append to decl_buf a printable name for NODE. */
413 if (TREE_CODE (node
) == POINTER_TYPE
)
415 node
= TREE_TYPE (node
);
418 if (TREE_CODE_CLASS (TREE_CODE (node
)) == 'd'
419 && DECL_NAME (node
) != NULL_TREE
)
422 if (DECL_CONTEXT (node
) != NULL_TREE
)
424 put_decl_node (DECL_CONTEXT (node
));
425 put_decl_string (".", 1);
428 if (TREE_CODE (node
) == FUNCTION_DECL
429 && DECL_INIT_P (node
)
430 && !DECL_ARTIFICIAL (node
) && current_class
)
431 put_decl_node (TYPE_NAME (current_class
));
433 put_decl_node (DECL_NAME (node
));
434 if (TREE_CODE (node
) == FUNCTION_DECL
&& TREE_TYPE (node
) != NULL_TREE
)
437 tree args
= TYPE_ARG_TYPES (TREE_TYPE (node
));
438 if (TREE_CODE (TREE_TYPE (node
)) == METHOD_TYPE
)
439 args
= TREE_CHAIN (args
);
440 put_decl_string ("(", 1);
441 for ( ; args
!= end_params_node
; args
= TREE_CHAIN (args
), i
++)
444 put_decl_string (",", 1);
445 put_decl_node (TREE_VALUE (args
));
447 put_decl_string (")", 1);
450 else if (TREE_CODE_CLASS (TREE_CODE (node
)) == 't'
451 && TYPE_NAME (node
) != NULL_TREE
)
453 if (TREE_CODE (node
) == RECORD_TYPE
&& TYPE_ARRAY_P (node
))
455 put_decl_node (TYPE_ARRAY_ELEMENT (node
));
456 put_decl_string("[]", 2);
458 else if (node
== promoted_byte_type_node
)
459 put_decl_string ("byte", 4);
460 else if (node
== promoted_short_type_node
)
461 put_decl_string ("short", 5);
462 else if (node
== promoted_char_type_node
)
463 put_decl_string ("char", 4);
464 else if (node
== promoted_boolean_type_node
)
465 put_decl_string ("boolean", 7);
466 else if (node
== void_type_node
&& was_pointer
)
467 put_decl_string ("null", 4);
469 put_decl_node (TYPE_NAME (node
));
471 else if (TREE_CODE (node
) == IDENTIFIER_NODE
)
472 put_decl_string (IDENTIFIER_POINTER (node
), IDENTIFIER_LENGTH (node
));
474 put_decl_string ("<unknown>", -1);
477 /* Return a user-friendly name for DECL.
478 The resulting string is only valid until the next call.
479 The value of the hook decl_printable_name is this function,
480 which is also called directly by lang_print_error. */
483 lang_printable_name (decl
, v
)
485 int v
__attribute__ ((__unused__
));
488 put_decl_node (decl
);
489 put_decl_string ("", 1);
493 /* Print on stderr the current class and method context. This function
494 is the value of the hook print_error_function, called from toplev.c. */
497 lang_print_error (file
)
500 static tree last_error_function_context
= NULL_TREE
;
501 static tree last_error_function
= NULL
;
503 if (current_function_decl
!= NULL
504 && DECL_CONTEXT (current_function_decl
) != last_error_function_context
)
507 fprintf (stderr
, "%s: ", file
);
509 last_error_function_context
= DECL_CONTEXT (current_function_decl
);
510 fprintf (stderr
, "In class `%s':\n",
511 lang_printable_name (last_error_function_context
, 0));
513 if (last_error_function
!= current_function_decl
)
516 fprintf (stderr
, "%s: ", file
);
518 if (current_function_decl
== NULL
)
519 fprintf (stderr
, "At top level:\n");
522 const char *name
= lang_printable_name (current_function_decl
, 2);
523 fprintf (stderr
, "In method `%s':\n", name
);
526 last_error_function
= current_function_decl
;
535 extern int flag_minimal_debug
;
536 flag_minimal_debug
= 0;
542 decl_printable_name
= lang_printable_name
;
543 print_error_function
= lang_print_error
;
544 lang_expand_expr
= java_lang_expand_expr
;
548 /* Append to Gcc tree node definition arrays */
550 memcpy (tree_code_type
+ (int) LAST_AND_UNUSED_TREE_CODE
,
552 (int)LAST_JAVA_TREE_CODE
- (int)LAST_AND_UNUSED_TREE_CODE
);
553 memcpy (tree_code_length
+ (int) LAST_AND_UNUSED_TREE_CODE
,
554 java_tree_code_length
,
555 (LAST_JAVA_TREE_CODE
-
556 (int)LAST_AND_UNUSED_TREE_CODE
) * sizeof (int));
557 memcpy (tree_code_name
+ (int) LAST_AND_UNUSED_TREE_CODE
,
559 (LAST_JAVA_TREE_CODE
-
560 (int)LAST_AND_UNUSED_TREE_CODE
) * sizeof (char *));
562 using_eh_for_cleanups ();
565 /* This doesn't do anything on purpose. It's used to satisfy the
566 print_error_function hook we don't print error messages with bogus
567 function prototypes. */
571 const char *s
__attribute__ ((__unused__
));
575 /* Called to install the PRINT_ERROR_FUNCTION hook differently
576 according to LEVEL. LEVEL is 1 during early parsing, when function
577 prototypes aren't fully resolved. print_error_function is set so it
578 doesn't print incomplete function prototypes. When LEVEL is 2,
579 function prototypes are fully resolved and can be printed when
582 void lang_init_source (level
)
586 print_error_function
= java_dummy_print
;
588 print_error_function
= lang_print_error
;
594 flag_new_exceptions
= 1;
595 flag_bounds_check
= 1;
609 /* Hooks for print_node. */
612 print_lang_decl (file
, node
, indent
)
613 FILE *file
__attribute ((__unused__
));
614 tree node
__attribute ((__unused__
));
615 int indent
__attribute ((__unused__
));
620 print_lang_type (file
, node
, indent
)
621 FILE *file
__attribute ((__unused__
));
622 tree node
__attribute ((__unused__
));
623 int indent
__attribute ((__unused__
));
628 print_lang_identifier (file
, node
, indent
)
629 FILE *file
__attribute ((__unused__
));
630 tree node
__attribute ((__unused__
));
631 int indent
__attribute ((__unused__
));
636 print_lang_statistics ()
640 /* used by print-tree.c */
643 lang_print_xnode (file
, node
, indent
)
644 FILE *file
__attribute ((__unused__
));
645 tree node
__attribute ((__unused__
));
646 int indent
__attribute ((__unused__
));
650 /* Return the typed-based alias set for T, which may be an expression
651 or a type. Return -1 if we don't do anything special. */
654 lang_get_alias_set (t
)