1 /* Java(TM) language-specific utility routines.
2 Copyright (C) 1996, 97-98, 1999 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
PROTO ((const char *, int));
40 static void put_decl_node
PROTO ((tree
));
41 static void java_dummy_print
PROTO ((const char *));
42 static void lang_print_error
PROTO ((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 /* From gcc/flags.h, and indicates if exceptions are turned on or not. */
115 extern int flag_new_exceptions
;
116 extern int flag_exceptions
;
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.) */
124 static struct { const char *string
; int *variable
; int on_value
;}
127 {"assume-compiled", &flag_assume_compiled
, 1},
128 {"emit-class-file", &flag_emit_class_files
, 1},
129 {"emit-class-files", &flag_emit_class_files
, 1},
130 {"use-divide-subroutine", &flag_use_divide_subroutine
, 1},
135 /* Variable controlling how dependency tracking is enabled in
137 static int dependency_tracking
= 0;
139 /* Flag values for DEPENDENCY_TRACKING. */
140 #define DEPEND_SET_FILE 1
141 #define DEPEND_ENABLE 2
144 * process java-specific compiler command-line options
145 * return 0, but do not complain if the option is not recognised.
148 lang_decode_option (argc
, argv
)
149 int argc
__attribute__ ((__unused__
));
154 #define CLARG "-fclasspath="
155 if (strncmp (p
, CLARG
, sizeof (CLARG
) - 1) == 0)
157 jcf_path_classpath_arg (p
+ sizeof (CLARG
) - 1);
161 #define CLARG "-fCLASSPATH="
162 else if (strncmp (p
, CLARG
, sizeof (CLARG
) - 1) == 0)
164 jcf_path_CLASSPATH_arg (p
+ sizeof (CLARG
) - 1);
168 else if (strncmp (p
, "-I", 2) == 0)
170 jcf_path_include_arg (p
+ 2);
174 #define ARG "-foutput-class-dir="
175 if (strncmp (p
, ARG
, sizeof (ARG
) - 1) == 0)
177 jcf_write_base_directory
= p
+ sizeof (ARG
) - 1;
182 if (p
[0] == '-' && p
[1] == 'f')
184 /* Some kind of -f option.
185 P's value is the option sans `-f'.
186 Search for it in the table of options. */
193 && j
< (int)(sizeof (lang_f_options
) / sizeof (lang_f_options
[0]));
196 if (!strcmp (p
, lang_f_options
[j
].string
))
198 *lang_f_options
[j
].variable
= lang_f_options
[j
].on_value
;
199 /* A goto here would be cleaner,
200 but breaks the vax pcc. */
203 if (p
[0] == 'n' && p
[1] == 'o' && p
[2] == '-'
204 && ! strcmp (p
+3, lang_f_options
[j
].string
))
206 *lang_f_options
[j
].variable
= ! lang_f_options
[j
].on_value
;
214 if (strcmp (p
, "-Wall") == 0)
221 if (strcmp (p
, "-Wunsupported-jdk11") == 0)
223 flag_static_local_jdk1_1
= 1;
227 if (strcmp (p
, "-Wredundant-modifiers") == 0)
233 if (strcmp (p
, "-MD") == 0)
235 jcf_dependency_init (1);
236 dependency_tracking
|= DEPEND_SET_FILE
| DEPEND_ENABLE
;
239 else if (strcmp (p
, "-MMD") == 0)
241 jcf_dependency_init (0);
242 dependency_tracking
|= DEPEND_SET_FILE
| DEPEND_ENABLE
;
245 else if (strcmp (p
, "-M") == 0)
247 jcf_dependency_init (1);
248 dependency_tracking
|= DEPEND_ENABLE
;
251 else if (strcmp (p
, "-MM") == 0)
253 jcf_dependency_init (0);
254 dependency_tracking
|= DEPEND_ENABLE
;
263 init_parse (filename
)
266 /* Open input file. */
268 if (filename
== 0 || !strcmp (filename
, "-"))
273 if (dependency_tracking
)
274 error ("can't do dependency tracking with input from stdin");
278 if (dependency_tracking
)
281 dot
= strrchr (filename
, '.');
283 error ("couldn't determine target name for dependency tracking");
286 char *buf
= (char *) xmalloc (dot
- filename
+
287 3 + sizeof (OBJECT_SUFFIX
));
288 strncpy (buf
, filename
, dot
- filename
);
290 /* If emitting class files, we might have multiple
291 targets. The class generation code takes care of
292 registering them. Otherwise we compute the target
294 if (flag_emit_class_files
)
295 jcf_dependency_set_target (NULL
);
298 strcpy (buf
+ (dot
- filename
), OBJECT_SUFFIX
);
299 jcf_dependency_set_target (buf
);
302 if ((dependency_tracking
& DEPEND_SET_FILE
))
304 strcpy (buf
+ (dot
- filename
), ".d");
305 jcf_dependency_set_dep_file (buf
);
308 jcf_dependency_set_dep_file ("-");
323 jcf_dependency_write ();
326 /* Buffer used by lang_printable_name. */
327 static char *decl_buf
= NULL
;
329 /* Allocated size of decl_buf. */
330 static int decl_buflen
= 0;
332 /* Length of used part of decl_buf; position for next character. */
333 static int decl_bufpos
= 0;
335 /* Append the string STR to decl_buf.
336 It length is given by LEN; -1 means the string is nul-terminated. */
339 put_decl_string (str
, len
)
345 if (decl_bufpos
+ len
>= decl_buflen
)
347 if (decl_buf
== NULL
)
349 decl_buflen
= len
+ 100;
350 decl_buf
= (char *) xmalloc (decl_buflen
);
355 decl_buf
= (char *) xrealloc (decl_buf
, decl_buflen
);
358 strcpy (decl_buf
+ decl_bufpos
, str
);
362 /* Append to decl_buf a printable name for NODE. */
369 if (TREE_CODE (node
) == POINTER_TYPE
)
371 node
= TREE_TYPE (node
);
374 if (TREE_CODE_CLASS (TREE_CODE (node
)) == 'd'
375 && DECL_NAME (node
) != NULL_TREE
)
378 if (DECL_CONTEXT (node
) != NULL_TREE
)
380 put_decl_node (DECL_CONTEXT (node
));
381 put_decl_string (".", 1);
384 if (TREE_CODE (node
) == FUNCTION_DECL
385 && DECL_NAME (node
) == init_identifier_node
386 && !DECL_ARTIFICIAL (node
) && current_class
)
387 put_decl_node (TYPE_NAME (current_class
));
389 put_decl_node (DECL_NAME (node
));
390 if (TREE_CODE (node
) == FUNCTION_DECL
&& TREE_TYPE (node
) != NULL_TREE
)
393 tree args
= TYPE_ARG_TYPES (TREE_TYPE (node
));
394 if (TREE_CODE (TREE_TYPE (node
)) == METHOD_TYPE
)
395 args
= TREE_CHAIN (args
);
396 put_decl_string ("(", 1);
397 for ( ; args
!= end_params_node
; args
= TREE_CHAIN (args
), i
++)
400 put_decl_string (",", 1);
401 put_decl_node (TREE_VALUE (args
));
403 put_decl_string (")", 1);
406 else if (TREE_CODE_CLASS (TREE_CODE (node
)) == 't'
407 && TYPE_NAME (node
) != NULL_TREE
)
409 if (TREE_CODE (node
) == RECORD_TYPE
&& TYPE_ARRAY_P (node
))
411 put_decl_node (TYPE_ARRAY_ELEMENT (node
));
412 put_decl_string("[]", 2);
414 else if (node
== promoted_byte_type_node
)
415 put_decl_string ("byte", 4);
416 else if (node
== promoted_short_type_node
)
417 put_decl_string ("short", 5);
418 else if (node
== promoted_char_type_node
)
419 put_decl_string ("char", 4);
420 else if (node
== promoted_boolean_type_node
)
421 put_decl_string ("boolean", 7);
422 else if (node
== void_type_node
&& was_pointer
)
423 put_decl_string ("null", 4);
425 put_decl_node (TYPE_NAME (node
));
427 else if (TREE_CODE (node
) == IDENTIFIER_NODE
)
428 put_decl_string (IDENTIFIER_POINTER (node
), IDENTIFIER_LENGTH (node
));
430 put_decl_string ("<unknown>", -1);
433 /* Return a user-friendly name for DECL.
434 The resulting string is only valid until the next call.
435 The value of the hook decl_printable_name is this function,
436 which is also called directly by lang_print_error. */
439 lang_printable_name (decl
, v
)
441 int v
__attribute__ ((__unused__
));
444 put_decl_node (decl
);
445 put_decl_string ("", 1);
449 /* Print on stderr the current class and method context. This function
450 is the value of the hook print_error_function, called from toplev.c. */
453 lang_print_error (file
)
456 static tree last_error_function_context
= NULL_TREE
;
457 static tree last_error_function
= NULL
;
459 if (current_function_decl
!= NULL
460 && DECL_CONTEXT (current_function_decl
) != last_error_function_context
)
463 fprintf (stderr
, "%s: ", file
);
465 last_error_function_context
= DECL_CONTEXT (current_function_decl
);
466 fprintf (stderr
, "In class `%s':\n",
467 lang_printable_name (last_error_function_context
, 0));
469 if (last_error_function
!= current_function_decl
)
472 fprintf (stderr
, "%s: ", file
);
474 if (current_function_decl
== NULL
)
475 fprintf (stderr
, "At top level:\n");
478 const char *name
= lang_printable_name (current_function_decl
, 2);
479 fprintf (stderr
, "In method `%s':\n", name
);
482 last_error_function
= current_function_decl
;
491 extern int flag_minimal_debug
;
492 flag_minimal_debug
= 0;
498 decl_printable_name
= lang_printable_name
;
499 print_error_function
= lang_print_error
;
500 lang_expand_expr
= java_lang_expand_expr
;
504 /* Append to Gcc tree node definition arrays */
506 memcpy (tree_code_type
+ (int) LAST_AND_UNUSED_TREE_CODE
,
508 (int)LAST_JAVA_TREE_CODE
- (int)LAST_AND_UNUSED_TREE_CODE
);
509 memcpy (tree_code_length
+ (int) LAST_AND_UNUSED_TREE_CODE
,
510 java_tree_code_length
,
511 (LAST_JAVA_TREE_CODE
-
512 (int)LAST_AND_UNUSED_TREE_CODE
) * sizeof (int));
513 memcpy (tree_code_name
+ (int) LAST_AND_UNUSED_TREE_CODE
,
515 (LAST_JAVA_TREE_CODE
-
516 (int)LAST_AND_UNUSED_TREE_CODE
) * sizeof (char *));
518 using_eh_for_cleanups ();
521 /* This doesn't do anything on purpose. It's used to satisfy the
522 print_error_function hook we don't print error messages with bogus
523 function prototypes. */
527 const char *s
__attribute__ ((__unused__
));
531 /* Called to install the PRINT_ERROR_FUNCTION hook differently
532 according to LEVEL. LEVEL is 1 during early parsing, when function
533 prototypes aren't fully resolved. print_error_function is set so it
534 doesn't print incomplete function prototypes. When LEVEL is 2,
535 function prototypes are fully resolved and can be printed when
538 void lang_init_source (level
)
542 print_error_function
= java_dummy_print
;
544 print_error_function
= lang_print_error
;
550 flag_new_exceptions
= 1;
551 flag_bounds_check
= 1;
565 /* Hooks for print_node. */
568 print_lang_decl (file
, node
, indent
)
569 FILE *file
__attribute ((__unused__
));
570 tree node
__attribute ((__unused__
));
571 int indent
__attribute ((__unused__
));
576 print_lang_type (file
, node
, indent
)
577 FILE *file
__attribute ((__unused__
));
578 tree node
__attribute ((__unused__
));
579 int indent
__attribute ((__unused__
));
584 print_lang_identifier (file
, node
, indent
)
585 FILE *file
__attribute ((__unused__
));
586 tree node
__attribute ((__unused__
));
587 int indent
__attribute ((__unused__
));
592 print_lang_statistics ()
596 /* used by print-tree.c */
599 lang_print_xnode (file
, node
, indent
)
600 FILE *file
__attribute ((__unused__
));
601 tree node
__attribute ((__unused__
));
602 int indent
__attribute ((__unused__
));