1 /* Program to write C++-suitable header files from a Java(TM) .class
2 file. This is similar to SUN's javah.
4 Copyright (C) 1996, 1998, 1999, 2000 Free Software Foundation, Inc.
6 This program 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 This program 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 /* Written by Per Bothner <bothner@cygnus.com>, February 1996. */
34 #include "java-tree.h"
35 #include "java-opcodes.h"
43 /* The output file. */
46 /* Nonzero on failure. */
47 static int found_error = 0;
49 /* Nonzero if we're generating JNI output. */
50 static int flag_jni = 0;
52 /* Directory to place resulting files in. Set by -d option. */
53 const char *output_directory = "";
55 /* Directory to place temporary file. Set by -td option. Currently unused. */
56 const char *temp_directory = "/tmp";
58 /* Number of friend functions we have to declare. */
59 static int friend_count;
61 /* A class can optionally have a `friend' function declared. If
62 non-NULL, this is that function. */
63 static char **friend_specs = NULL;
65 /* Number of lines we are prepending before the class. */
66 static int prepend_count;
68 /* We can prepend extra lines before the class's start. */
69 static char **prepend_specs = NULL;
71 /* Number of lines we are appending at the end of the class. */
74 /* We can append extra lines just before the class's end. */
75 static char **add_specs = NULL;
77 /* Number of lines we are appending after the class. */
78 static int append_count;
80 /* We can append extra lines after the class's end. */
81 static char **append_specs = NULL;
87 struct JCF *current_jcf;
89 /* This holds access information for the last field we examined. They
90 let us generate "private:", "public:", and "protected:" properly.
91 If 0 then we haven't previously examined any field. */
92 static JCF_u2 last_access;
94 #define ACC_VISIBILITY (ACC_PUBLIC | ACC_PRIVATE | ACC_PROTECTED)
96 /* Pass this macro the flags for a class and for a method. It will
97 return true if the method should be considered `final'. */
98 #define METHOD_IS_FINAL(Class, Method) \
99 (((Class) & ACC_FINAL) || ((Method) & (ACC_FINAL | ACC_PRIVATE)))
101 /* Pass this macro the flags for a method. It will return true if the
103 #define METHOD_IS_NATIVE(Method) \
104 ((Method) & ACC_NATIVE)
106 /* We keep a linked list of all method names we have seen. This lets
107 us determine if a method name and a field name are in conflict. */
112 unsigned char *signature;
114 struct method_name *next;
117 /* List of method names we've seen. */
118 static struct method_name *method_name_list;
120 static void print_field_info PARAMS ((FILE*, JCF*, int, int, JCF_u2));
121 static void print_mangled_classname PARAMS ((FILE*, JCF*, const char*, int));
122 static int print_cxx_classname PARAMS ((FILE*, const char*, JCF*, int));
123 static void print_method_info PARAMS ((FILE*, JCF*, int, int, JCF_u2));
124 static void print_c_decl PARAMS ((FILE*, JCF*, int, int, int, const char *,
126 static void print_stub_or_jni PARAMS ((FILE*, JCF*, int, int, int,
128 static void print_full_cxx_name PARAMS ((FILE*, JCF*, int, int, int,
130 static void decompile_method PARAMS ((FILE*, JCF*, int));
131 static void add_class_decl PARAMS ((FILE*, JCF*, JCF_u2));
133 static int java_float_finite PARAMS ((jfloat));
134 static int java_double_finite PARAMS ((jdouble));
135 static void print_name PARAMS ((FILE *, JCF *, int));
136 static void print_base_classname PARAMS ((FILE *, JCF *, int));
137 static int utf8_cmp PARAMS ((const unsigned char *, int, const char *));
138 static const char *cxx_keyword_subst PARAMS ((const unsigned char *, int));
139 static void generate_access PARAMS ((FILE *, JCF_u2));
140 static int name_is_method_p PARAMS ((const unsigned char *, int));
141 static char *get_field_name PARAMS ((JCF *, int, JCF_u2));
142 static void print_field_name PARAMS ((FILE *, JCF *, int, JCF_u2));
143 static const unsigned char *super_class_name PARAMS ((JCF *, int *));
144 static void print_include PARAMS ((FILE *, const unsigned char *, int));
145 static const unsigned char *decode_signature_piece
146 PARAMS ((FILE *, const unsigned char *, const unsigned char *, int *));
147 static void print_class_decls PARAMS ((FILE *, JCF *, int));
148 static void usage PARAMS ((void)) ATTRIBUTE_NORETURN;
149 static void help PARAMS ((void)) ATTRIBUTE_NORETURN;
150 static void version PARAMS ((void)) ATTRIBUTE_NORETURN;
151 static int overloaded_jni_method_exists_p PARAMS ((const unsigned char *, int,
154 JCF_u2 current_field_name;
155 JCF_u2 current_field_value;
156 JCF_u2 current_field_signature;
157 JCF_u2 current_field_flags;
159 #define HANDLE_START_FIELD(ACCESS_FLAGS, NAME, SIGNATURE, ATTRIBUTE_COUNT) \
160 ( current_field_name = (NAME), current_field_signature = (SIGNATURE), \
161 current_field_flags = (ACCESS_FLAGS), current_field_value = 0)
163 /* We pass over fields twice. The first time we just note the types
164 of the fields and then the start of the methods. Then we go back
165 and parse the fields for real. This is ugly. */
166 static int field_pass;
167 /* Likewise we pass over methods twice. The first time we generate
168 class decl information; the second time we generate actual method
170 static int method_pass;
172 #define HANDLE_END_FIELD() \
175 if (out && ! stubs && ! flag_jni) \
176 print_field_info (out, jcf, current_field_name, \
177 current_field_signature, \
178 current_field_flags); \
180 else if (! stubs && ! flag_jni) \
181 add_class_decl (out, jcf, current_field_signature);
183 #define HANDLE_CONSTANTVALUE(VALUEINDEX) current_field_value = (VALUEINDEX)
185 static int method_declared = 0;
186 static int method_access = 0;
187 static int method_printed = 0;
188 #define HANDLE_METHOD(ACCESS_FLAGS, NAME, SIGNATURE, ATTRIBUTE_COUNT) \
191 decompiled = 0; method_printed = 0; \
193 print_method_info (out, jcf, NAME, SIGNATURE, ACCESS_FLAGS); \
196 print_method_info (NULL, jcf, NAME, SIGNATURE, ACCESS_FLAGS); \
197 else if (! stubs) add_class_decl (out, jcf, SIGNATURE);
199 #define HANDLE_CODE_ATTRIBUTE(MAX_STACK, MAX_LOCALS, CODE_LENGTH) \
200 if (out && method_declared) decompile_method (out, jcf, CODE_LENGTH);
202 static int decompiled = 0;
203 #define HANDLE_END_METHOD() \
204 if (out && method_printed) fputs (decompiled || stubs ? "\n" : ";\n", out);
206 #include "jcf-reader.c"
208 /* Some useful constants. */
209 #define F_NAN_MASK 0x7f800000
210 #if (1 == HOST_FLOAT_WORDS_BIG_ENDIAN)
211 #define D_NAN_MASK 0x000000007ff00000LL
213 #define D_NAN_MASK 0x7ff0000000000000LL
216 /* Return 1 if F is not Inf or NaN. */
218 java_float_finite (f)
224 /* We happen to know that F_NAN_MASK will match all NaN values, and
225 also positive and negative infinity. That's why we only need one
226 test here. See The Java Language Specification, section 20.9. */
227 return (u.i & F_NAN_MASK) != F_NAN_MASK;
230 /* Return 1 if D is not Inf or NaN. */
232 java_double_finite (d)
238 /* Now check for all NaNs. */
239 return (u.l & D_NAN_MASK) != D_NAN_MASK;
243 DEFUN(print_name, (stream, jcf, name_index),
244 FILE* stream AND JCF* jcf AND int name_index)
246 if (JPOOL_TAG (jcf, name_index) != CONSTANT_Utf8)
247 fprintf (stream, "<not a UTF8 constant>");
249 jcf_print_utf8 (stream, JPOOL_UTF_DATA (jcf, name_index),
250 JPOOL_UTF_LENGTH (jcf, name_index));
253 /* Print base name of class. The base name is everything after the
257 print_base_classname (stream, jcf, index)
262 int name_index = JPOOL_USHORT1 (jcf, index);
264 const unsigned char *s, *p, *limit;
266 s = JPOOL_UTF_DATA (jcf, name_index);
267 len = JPOOL_UTF_LENGTH (jcf, name_index);
272 int c = UTF8_GET (s, limit);
279 int ch = UTF8_GET (p, limit);
281 fputs ("::", stream);
283 jcf_print_char (stream, ch);
287 /* Return 0 if NAME is equal to STR, nonzero otherwise. */
290 utf8_cmp (str, length, name)
291 const unsigned char *str;
295 const unsigned char *limit = str + length;
298 for (i = 0; name[i]; ++i)
300 int ch = UTF8_GET (str, limit);
308 /* If NAME is the name of a C++ keyword, then return an override name.
309 This is a name that can be used in place of the keyword.
310 Otherwise, return NULL. FIXME: for now, we only handle those
311 keywords we know to be a problem for libgcj. */
314 cxx_keyword_subst (str, length)
315 const unsigned char *str;
318 if (! utf8_cmp (str, length, "delete"))
319 return "__dummy_delete";
320 else if (! utf8_cmp (str, length, "enum"))
321 return "__dummy_enum";
325 /* Generate an access control keyword based on FLAGS. */
328 generate_access (stream, flags)
332 if ((flags & ACC_VISIBILITY) == last_access)
334 last_access = (flags & ACC_VISIBILITY);
339 fputs ("public: // actually package-private\n", stream);
342 fputs ("public:\n", stream);
345 fputs ("private:\n", stream);
348 fputs ("public: // actually protected\n", stream);
352 fprintf (stream, "#error unrecognized visibility %d\n",
353 (flags & ACC_VISIBILITY));
358 /* See if NAME is already the name of a method. */
360 name_is_method_p (name, length)
361 const unsigned char *name;
364 struct method_name *p;
366 for (p = method_name_list; p != NULL; p = p->next)
368 if (p->length == length && ! memcmp (p->name, name, length))
374 /* If there is already a method named NAME, whose signature is not
375 SIGNATURE, then return true. Otherwise return false. */
377 overloaded_jni_method_exists_p (name, length, signature, sig_length)
378 const unsigned char *name;
380 const char *signature;
383 struct method_name *p;
385 for (p = method_name_list; p != NULL; p = p->next)
387 if (p->length == length
388 && ! memcmp (p->name, name, length)
389 && (p->sig_length != sig_length
390 || memcmp (p->signature, signature, sig_length)))
396 /* Get name of a field. This handles renamings due to C++ clash. */
398 get_field_name (jcf, name_index, flags)
403 unsigned char *name = JPOOL_UTF_DATA (jcf, name_index);
404 int length = JPOOL_UTF_LENGTH (jcf, name_index);
406 const char *tmpconstptr;
409 if (name_is_method_p (name, length))
411 /* This field name matches a method. So override the name with
412 a dummy name. This is yucky, but it isn't clear what else to
413 do. FIXME: if the field is static, then we'll be in real
415 if ((flags & ACC_STATIC))
417 fprintf (stderr, "static field has same name as method\n");
422 override = xmalloc (length + 3);
423 memcpy (override, name, length);
424 strcpy (override + length, "__");
426 else if ((tmpconstptr = cxx_keyword_subst (name, length)) != NULL)
428 /* Must malloc OVERRIDE. */
429 override = xstrdup (tmpconstptr);
437 /* Print a field name. Convenience function for use with
440 print_field_name (stream, jcf, name_index, flags)
446 char *override = get_field_name (jcf, name_index, flags);
450 fputs (override, stream);
454 jcf_print_utf8 (stream, JPOOL_UTF_DATA (jcf, name_index),
455 JPOOL_UTF_LENGTH (jcf, name_index));
459 DEFUN(print_field_info, (stream, jcf, name_index, sig_index, flags),
460 FILE *stream AND JCF* jcf
461 AND int name_index AND int sig_index AND JCF_u2 flags)
463 char *override = NULL;
465 generate_access (stream, flags);
466 if (JPOOL_TAG (jcf, name_index) != CONSTANT_Utf8)
468 fprintf (stream, "<not a UTF8 constant>");
474 if ((flags & ACC_STATIC))
475 fputs ("static ", out);
477 if ((flags & ACC_FINAL))
479 if (current_field_value > 0)
484 switch (JPOOL_TAG (jcf, current_field_value))
486 case CONSTANT_Integer:
489 int most_negative = 0;
490 fputs ("const jint ", out);
491 print_field_name (out, jcf, name_index, 0);
493 num = JPOOL_INT (jcf, current_field_value);
494 /* We single out the most negative number to print
495 specially. This avoids later warnings from g++. */
496 if (num == (jint) 0x80000000)
501 format_int (buffer, (jlong) num, 10);
502 fprintf (out, "%sL%s;\n", buffer, most_negative ? " - 1" : "");
508 int most_negative = 0;
509 fputs ("const jlong ", out);
510 print_field_name (out, jcf, name_index, 0);
512 num = JPOOL_LONG (jcf, current_field_value);
513 /* We single out the most negative number to print
514 specially.. This avoids later warnings from g++. */
515 if (num == (jlong) 0x8000000000000000LL)
520 format_int (buffer, num, 10);
521 fprintf (out, "%sLL%s;\n", buffer, most_negative ? " - 1" :"");
526 jfloat fnum = JPOOL_FLOAT (jcf, current_field_value);
527 fputs ("const jfloat ", out);
528 print_field_name (out, jcf, name_index, 0);
529 if (! java_float_finite (fnum))
532 fprintf (out, " = %.10g;\n", fnum);
535 case CONSTANT_Double:
537 jdouble dnum = JPOOL_DOUBLE (jcf, current_field_value);
538 fputs ("const jdouble ", out);
539 print_field_name (out, jcf, name_index, 0);
540 if (! java_double_finite (dnum))
543 fprintf (out, " = %.17g;\n", dnum);
547 /* We can't print this as a constant, but we can still
548 print something sensible. */
558 override = get_field_name (jcf, name_index, flags);
559 print_c_decl (out, jcf, name_index, sig_index, 0, override, flags);
567 DEFUN(print_method_info, (stream, jcf, name_index, sig_index, flags),
568 FILE *stream AND JCF* jcf
569 AND int name_index AND int sig_index AND JCF_u2 flags)
571 const unsigned char *str;
572 int length, is_init = 0;
573 const char *override = NULL;
576 method_access = flags;
577 if (stream && JPOOL_TAG (jcf, name_index) != CONSTANT_Utf8)
578 fprintf (stream, "<not a UTF8 constant>");
579 str = JPOOL_UTF_DATA (jcf, name_index);
580 length = JPOOL_UTF_LENGTH (jcf, name_index);
581 if (str[0] == '<' || str[0] == '$')
583 /* Ignore internally generated methods like <clinit> and
584 $finit$. However, treat <init> as a constructor. */
585 if (! utf8_cmp (str, length, "<init>"))
587 else if (! METHOD_IS_FINAL (jcf->access_flags, flags)
588 && ! (flags & ACC_STATIC))
590 /* FIXME: i18n bug here. Order of prints should not be
592 fprintf (stderr, "ignored method `");
593 jcf_print_utf8 (stderr, str, length);
594 fprintf (stderr, "' marked virtual\n");
603 struct method_name *nn;
605 nn = (struct method_name *) xmalloc (sizeof (struct method_name));
606 nn->name = (char *) xmalloc (length);
607 memcpy (nn->name, str, length);
609 nn->next = method_name_list;
610 nn->sig_length = JPOOL_UTF_LENGTH (jcf, sig_index);
611 nn->signature = (char *) xmalloc (nn->sig_length);
612 memcpy (nn->signature, JPOOL_UTF_DATA (jcf, sig_index),
614 method_name_list = nn;
617 /* If we're not printing, then the rest of this function doesn't
618 matter. This happens during the first method pass in JNI mode.
623 /* We can't generate a method whose name is a C++ reserved word. We
624 can't just ignore the function, because that will cause incorrect
625 code to be generated if the function is virtual (not only for
626 calls to this function for for other functions after it in the
627 vtbl). So we give it a dummy name instead. */
628 override = cxx_keyword_subst (str, length);
631 /* If the method is static or final, we can safely skip it. If
632 we don't skip it then we'll have problems since the mangling
633 will be wrong. FIXME. */
634 if (METHOD_IS_FINAL (jcf->access_flags, flags)
635 || (flags & ACC_STATIC))
639 if (! stubs && ! flag_jni)
643 generate_access (stream, flags);
646 if ((flags & ACC_STATIC))
647 fputs ("static ", out);
648 else if (! METHOD_IS_FINAL (jcf->access_flags, flags))
650 /* Don't print `virtual' if we have a constructor. */
652 fputs ("virtual ", out);
654 print_c_decl (out, jcf, name_index, sig_index, is_init, override, flags);
656 if ((flags & ACC_ABSTRACT))
663 if (METHOD_IS_NATIVE (flags))
666 print_stub_or_jni (out, jcf, name_index, sig_index,
667 is_init, override, flags);
672 /* Try to decompile a method body. Right now we just try to handle a
673 simple case that we can do. Expand as desired. */
675 decompile_method (out, jcf, code_len)
680 const unsigned char *codes = jcf->read_ptr;
682 uint16 name_and_type, name;
684 /* If the method is synchronized, don't touch it. */
685 if ((method_access & ACC_SYNCHRONIZED))
689 && codes[0] == OPCODE_aload_0
690 && codes[1] == OPCODE_getfield
691 && (codes[4] == OPCODE_areturn
692 || codes[4] == OPCODE_dreturn
693 || codes[4] == OPCODE_freturn
694 || codes[4] == OPCODE_ireturn
695 || codes[4] == OPCODE_lreturn))
697 /* Found code like `return FIELD'. */
698 fputs (" { return ", out);
699 index = (codes[2] << 8) | codes[3];
700 /* FIXME: ensure that tag is CONSTANT_Fieldref. */
701 /* FIXME: ensure that the field's class is this class. */
702 name_and_type = JPOOL_USHORT2 (jcf, index);
703 /* FIXME: ensure that tag is CONSTANT_NameAndType. */
704 name = JPOOL_USHORT1 (jcf, name_and_type);
705 print_name (out, jcf, name);
709 else if (code_len == 2
710 && codes[0] == OPCODE_aload_0
711 && codes[1] == OPCODE_areturn)
713 /* Found `return this'. */
714 fputs (" { return this; }", out);
717 else if (code_len == 1 && codes[0] == OPCODE_return)
719 /* Found plain `return'. */
723 else if (code_len == 2
724 && codes[0] == OPCODE_aconst_null
725 && codes[1] == OPCODE_areturn)
727 /* Found `return null'. We don't want to depend on NULL being
729 fputs (" { return 0; }", out);
734 /* Print one piece of a signature. Returns pointer to next parseable
735 character on success, NULL on error. */
736 static const unsigned char *
737 decode_signature_piece (stream, signature, limit, need_space)
739 const unsigned char *signature, *limit;
745 switch (signature[0])
748 /* More spaghetti. */
751 for (signature++; (signature < limit
753 && *signature <= '9'); signature++)
758 ctype = "jbyteArray";
761 ctype = "jcharArray";
764 ctype = "jdoubleArray";
767 ctype = "jfloatArray";
773 ctype = "jshortArray";
776 ctype = "jlongArray";
779 ctype = "jbooleanArray";
782 /* We have a nested array. */
785 fputs ("JArray<", stream);
789 /* We have to generate a reference to JArray here, so that
790 our output matches what the compiler does. */
792 /* Space between `<' and `:' to avoid C++ digraphs. */
794 fputs ("JArray< ::", stream);
795 while (signature < limit && *signature != ';')
797 int ch = UTF8_GET (signature, limit);
801 fputs ("::", stream);
803 jcf_print_char (stream, ch);
807 fputs (" *> *", stream);
812 /* Unparseable signature. */
816 /* If the previous iterations left us with something to print,
817 print it. For JNI, we always print `jobjectArray' in the
819 if (flag_jni && ctype == NULL)
821 ctype = "jobjectArray";
824 /* The `printit' case will advance SIGNATURE for us. If we
825 don't go there, we must advance past the `;' ourselves. */
833 /* This shouldn't happen. */
836 case 'B': ctype = "jbyte"; goto printit;
837 case 'C': ctype = "jchar"; goto printit;
838 case 'D': ctype = "jdouble"; goto printit;
839 case 'F': ctype = "jfloat"; goto printit;
840 case 'I': ctype = "jint"; goto printit;
841 case 'J': ctype = "jlong"; goto printit;
842 case 'S': ctype = "jshort"; goto printit;
843 case 'Z': ctype = "jboolean"; goto printit;
844 case 'V': ctype = "void"; goto printit;
848 /* We know about certain types and special-case their
850 FIXME: something like java.lang.Exception should be
851 printed as `jthrowable', because it is a subclass. This
852 means that gcjh must read the entire hierarchy and
854 if (! strncmp (signature, "Ljava/lang/String;",
855 sizeof ("Ljava/lang/String;") -1))
857 else if (! strncmp (signature, "Ljava/lang/Class;",
858 sizeof ("Ljava/lang/Class;") - 1))
860 else if (! strncmp (signature, "Ljava/lang/Throwable;",
861 sizeof ("Ljava/lang/Throwable;") - 1))
862 ctype = "jthrowable";
863 else if (! strncmp (signature, "Ljava/lang/ref/WeakReference;",
864 sizeof ("Ljava/lang/ref/WeakReference;") - 1))
869 while (*signature && *signature != ';')
874 /* Print a leading "::" so we look in the right namespace. */
875 fputs ("::", stream);
877 while (*signature && *signature != ';')
879 int ch = UTF8_GET (signature, limit);
880 /* `$' is the separator for an inner class. */
881 if (ch == '/' || ch == '$')
882 fputs ("::", stream);
884 jcf_print_char (stream, ch);
886 fputs (" *", stream);
887 if (*signature == ';')
893 jcf_print_char (stream, *signature++);
898 fputs (ctype, stream);
904 while (array_depth-- > 0)
905 fputs ("> *", stream);
912 DEFUN(print_c_decl, (stream, jcf, name_index, signature_index, is_init,
913 name_override, flags),
914 FILE* stream AND JCF* jcf
915 AND int name_index AND int signature_index
916 AND int is_init AND const char *name_override AND int flags)
918 if (JPOOL_TAG (jcf, signature_index) != CONSTANT_Utf8)
920 fprintf (stream, "<not a UTF8 constant>");
925 int length = JPOOL_UTF_LENGTH (jcf, signature_index);
926 const unsigned char *str0 = JPOOL_UTF_DATA (jcf, signature_index);
927 register const unsigned char *str = str0;
928 const unsigned char *limit = str + length;
930 int is_method = str[0] == '(';
931 const unsigned char *next;
933 /* If printing a method, skip to the return signature and print
934 that first. However, there is no return value if this is a
936 if (is_method && ! is_init)
946 /* If printing a field or an ordinary method, then print the
947 "return value" now. */
948 if (! is_method || ! is_init)
950 next = decode_signature_piece (stream, str, limit, &need_space);
953 fprintf (stderr, "unparseable signature: `%s'\n", str0);
959 /* Now print the name of the thing. */
962 print_full_cxx_name (stream, jcf, name_index,
963 signature_index, is_init, name_override,
968 /* Print the unqualified method name followed by the signature. */
970 DEFUN(print_full_cxx_name, (stream, jcf, name_index, signature_index,
971 is_init, name_override, flags),
972 FILE* stream AND JCF* jcf
973 AND int name_index AND int signature_index AND int is_init
974 AND const char *name_override AND int flags)
976 int length = JPOOL_UTF_LENGTH (jcf, signature_index);
977 const unsigned char *str0 = JPOOL_UTF_DATA (jcf, signature_index);
978 register const unsigned char *str = str0;
979 const unsigned char *limit = str + length;
981 int is_method = str[0] == '(';
982 const unsigned char *next;
985 fputs (name_override, stream);
988 /* Declare constructors specially. */
990 print_base_classname (stream, jcf, jcf->this_class);
992 print_name (stream, jcf, name_index);
997 unsigned char *signature = JPOOL_UTF_DATA (jcf, signature_index);
998 int sig_len = JPOOL_UTF_LENGTH (jcf, signature_index);
999 if (overloaded_jni_method_exists_p (JPOOL_UTF_DATA (jcf, name_index),
1000 JPOOL_UTF_LENGTH (jcf, name_index),
1001 signature, sig_len))
1003 /* If this method is overloaded by another native method,
1004 then include the argument information in the mangled
1006 unsigned char *limit = signature + sig_len;
1007 fputs ("__", stream);
1008 while (signature < limit)
1010 int ch = UTF8_GET (signature, limit);
1021 fputs ("_1", stream);
1023 fputs ("_2", stream);
1025 fputs ("_3", stream);
1027 fputs ("_", stream);
1028 else if ((ch >= '0' && ch <= '9')
1029 || (ch >= 'a' && ch <= 'z')
1030 || (ch >= 'A' && ch <= 'Z'))
1034 /* "Unicode" character. FIXME: upper or lower case
1036 fprintf (stream, "_0%04x", ch);
1044 /* Have a method or a constructor. Print signature pieces
1046 fputs (" (", stream);
1050 /* In JNI mode, add extra arguments. */
1053 /* FIXME: it would be nice to know if we are printing a decl
1054 or a definition, and only print `env' for the latter. */
1055 fputs ("JNIEnv *env", stream);
1057 fputs ((flags & ACC_STATIC) ? ", jclass" : ", jobject", stream);
1060 fputs (", ", stream);
1063 while (str < limit && *str != ')')
1065 next = decode_signature_piece (stream, str, limit, &need_space);
1068 fprintf (stderr, "unparseable signature: `%s'\n", str0);
1073 if (next < limit && *next != ')')
1074 fputs (", ", stream);
1078 fputs (")", stream);
1082 /* This is a helper for print_stub_or_jni. */
1084 DEFUN (print_name_for_stub_or_jni, (stream, jcf, name_index, signature_index,
1085 is_init, name_override, flags),
1086 FILE *stream AND JCF *jcf
1087 AND int name_index AND int signature_index
1088 AND int is_init AND const char *name_override AND int flags)
1090 const char *const prefix = flag_jni ? "Java_" : "\n";
1091 print_cxx_classname (stream, prefix, jcf, jcf->this_class);
1092 fputs (flag_jni ? "_" : "::", stream);
1093 print_full_cxx_name (stream, jcf, name_index,
1094 signature_index, is_init, name_override,
1099 DEFUN(print_stub_or_jni, (stream, jcf, name_index, signature_index, is_init,
1100 name_override, flags),
1101 FILE* stream AND JCF* jcf
1102 AND int name_index AND int signature_index
1103 AND int is_init AND const char *name_override AND int flags)
1105 if (JPOOL_TAG (jcf, signature_index) != CONSTANT_Utf8)
1107 fprintf (stream, "<not a UTF8 constant>");
1112 int length = JPOOL_UTF_LENGTH (jcf, signature_index);
1113 const unsigned char *str0 = JPOOL_UTF_DATA (jcf, signature_index);
1114 register const unsigned char *str = str0;
1115 const unsigned char *limit = str + length;
1117 int is_method = str[0] == '(';
1118 const unsigned char *next;
1120 /* Don't print fields in the JNI case. */
1121 if (! is_method && flag_jni)
1124 if (flag_jni && ! stubs)
1125 fputs ("extern ", stream);
1127 /* If printing a method, skip to the return signature and print
1128 that first. However, there is no return value if this is a
1130 if (is_method && ! is_init)
1140 /* If printing a field or an ordinary method, then print the
1141 "return value" now. Note that a constructor can't be native,
1142 so we don't bother checking this in the JNI case. */
1143 if (! is_method || ! is_init)
1145 next = decode_signature_piece (stream, str, limit, &need_space);
1148 fprintf (stderr, "unparseable signature: `%s'\n", str0);
1154 /* When printing a JNI header we need to respect the space. In
1155 other cases we're just going to insert a newline anyway. */
1157 fputs (need_space && ! stubs ? " " : "\n", stream);
1159 /* Now print the name of the thing. */
1160 print_name_for_stub_or_jni (stream, jcf, name_index,
1161 signature_index, is_init, name_override,
1164 /* Print the body. */
1168 fputs ("\n{\n (*env)->FatalError (\"", stream);
1170 fputs ("\n{\n JvFail (\"", stream);
1171 print_name_for_stub_or_jni (stream, jcf, name_index,
1172 signature_index, is_init,
1175 fputs (" not implemented\");\n}\n\n", stream);
1181 DEFUN(print_mangled_classname, (stream, jcf, prefix, index),
1182 FILE *stream AND JCF *jcf AND const char *prefix AND int index)
1184 int name_index = JPOOL_USHORT1 (jcf, index);
1185 fputs (prefix, stream);
1186 jcf_print_utf8_replace (out,
1187 JPOOL_UTF_DATA (jcf, name_index),
1188 JPOOL_UTF_LENGTH (jcf, name_index),
1192 /* Print PREFIX, then a class name in C++ format. If the name refers
1193 to an array, ignore it and don't print PREFIX. Returns 1 if
1194 something was printed, 0 otherwise. */
1196 print_cxx_classname (stream, prefix, jcf, index)
1202 int name_index = JPOOL_USHORT1 (jcf, index);
1204 const unsigned char *s, *p, *limit;
1206 s = JPOOL_UTF_DATA (jcf, name_index);
1207 len = JPOOL_UTF_LENGTH (jcf, name_index);
1210 /* Explicitly omit arrays here. */
1212 c = UTF8_GET (p, limit);
1216 fputs (prefix, stream);
1218 /* Print a leading "::" so we look in the right namespace. */
1220 fputs ("::", stream);
1224 c = UTF8_GET (s, limit);
1226 fputs (flag_jni ? "_" : "::", stream);
1228 jcf_print_char (stream, c);
1234 int written_class_count = 0;
1236 /* Return name of superclass. If LEN is not NULL, fill it with length
1238 static const unsigned char *
1239 super_class_name (derived_jcf, len)
1243 int supername_index = JPOOL_USHORT1 (derived_jcf, derived_jcf->super_class);
1244 int supername_length = JPOOL_UTF_LENGTH (derived_jcf, supername_index);
1245 const unsigned char *supername =
1246 JPOOL_UTF_DATA (derived_jcf, supername_index);
1249 *len = supername_length;
1256 /* We keep track of all the `#include's we generate, so we can avoid
1261 struct include *next;
1264 /* List of all includes. */
1265 static struct include *all_includes = NULL;
1267 /* Generate a #include. */
1269 print_include (out, utf8, len)
1271 const unsigned char *utf8;
1274 struct include *incl;
1280 len = strlen (utf8);
1282 for (incl = all_includes; incl; incl = incl->next)
1284 /* We check the length because we might have a proper prefix. */
1285 if (len == (int) strlen (incl->name)
1286 && ! strncmp (incl->name, utf8, len))
1290 incl = (struct include *) xmalloc (sizeof (struct include));
1291 incl->name = xmalloc (len + 1);
1292 strncpy (incl->name, utf8, len);
1293 incl->name[len] = '\0';
1294 incl->next = all_includes;
1295 all_includes = incl;
1297 fputs ("#include <", out);
1298 jcf_print_utf8_replace (out, utf8, len,
1300 flag_jni ? '_' : '/');
1301 fputs (".h>\n", out);
1306 /* This is used to represent part of a package or class name. */
1309 /* The text of this part of the name. */
1311 /* True if this represents a class. */
1313 /* Linked list of all classes and packages inside this one. */
1314 struct namelet *subnamelets;
1315 /* Pointer to next sibling. */
1316 struct namelet *next;
1319 static void add_namelet PARAMS ((const unsigned char *,
1320 const unsigned char *, struct namelet *));
1321 static void print_namelet PARAMS ((FILE *, struct namelet *, int));
1323 /* The special root namelet. */
1324 static struct namelet root =
1332 /* This extracts the next name segment from the full UTF-8 encoded
1333 package or class name and links it into the tree. It does this
1336 add_namelet (name, name_limit, parent)
1337 const unsigned char *name, *name_limit;
1338 struct namelet *parent;
1340 const unsigned char *p;
1341 struct namelet *n = NULL, *np;
1343 /* We want to skip the standard namespaces that we assume the
1344 runtime already knows about. We only do this at the top level,
1345 though, hence the check for `root'. */
1346 if (parent == &root)
1348 #define JAVALANG "java/lang/"
1349 #define JAVAIO "java/io/"
1350 #define JAVAUTIL "java/util/"
1351 if ((name_limit - name >= (int) sizeof (JAVALANG) - 1
1352 && ! strncmp (name, JAVALANG, sizeof (JAVALANG) - 1))
1353 || (name_limit - name >= (int) sizeof (JAVAUTIL) - 1
1354 && ! strncmp (name, JAVAUTIL, sizeof (JAVAUTIL) - 1))
1355 || (name_limit - name >= (int) sizeof (JAVAIO) - 1
1356 && ! strncmp (name, JAVAIO, sizeof (JAVAIO) - 1)))
1360 for (p = name; p < name_limit && *p != '/' && *p != '$'; ++p)
1363 /* Search for this name beneath the PARENT node. */
1364 for (np = parent->subnamelets; np != NULL; np = np->next)
1366 /* We check the length because we might have a proper prefix. */
1367 if ((int) strlen (np->name) == p - name &&
1368 ! strncmp (name, np->name, p - name))
1377 n = (struct namelet *) xmalloc (sizeof (struct namelet));
1378 n->name = xmalloc (p - name + 1);
1379 strncpy (n->name, name, p - name);
1380 n->name[p - name] = '\0';
1381 n->is_class = (p == name_limit || *p == '$');
1382 n->subnamelets = NULL;
1383 n->next = parent->subnamelets;
1384 parent->subnamelets = n;
1387 /* We recurse if there is more text, and if the trailing piece does
1388 not represent an inner class. */
1389 if (p < name_limit && *p != '$')
1390 add_namelet (p + 1, name_limit, n);
1393 /* Print a single namelet. Destroys namelets while printing. */
1395 print_namelet (out, name, depth)
1397 struct namelet *name;
1405 for (i = 0; i < depth; ++i)
1407 fprintf (out, "%s %s", name->is_class ? "class" : "namespace",
1409 if (name->is_class && name->subnamelets == NULL)
1415 for (i = 0; i < depth; ++i)
1421 c = name->subnamelets;
1424 struct namelet *next = c->next;
1425 print_namelet (out, c, depth + 2);
1433 for (i = 0; i < depth; ++i)
1436 /* Only print a `;' when printing a class. C++ is evil. */
1446 /* This is called to add some classes to the list of classes for which
1447 we need decls. The signature argument can be a function
1450 add_class_decl (out, jcf, signature)
1455 const unsigned char *s = JPOOL_UTF_DATA (jcf, signature);
1456 int len = JPOOL_UTF_LENGTH (jcf, signature);
1458 /* Name of class we are processing. */
1459 int name_index = JPOOL_USHORT1 (jcf, jcf->this_class);
1460 int tlen = JPOOL_UTF_LENGTH (jcf, name_index);
1461 const char *tname = JPOOL_UTF_DATA (jcf, name_index);
1463 for (i = 0; i < len; ++i)
1465 int start, saw_dollar;
1467 /* If we see an array, then we include the array header. */
1470 print_include (out, "gcj/array", -1);
1474 /* We're looking for `L<stuff>;' -- everything else is
1480 for (start = ++i; i < len && s[i] != ';'; ++i)
1482 if (! saw_dollar && s[i] == '$' && out)
1485 /* If this class represents an inner class, then
1486 generate a `#include' for the outer class. However,
1487 don't generate the include if the outer class is the
1488 class we are processing. */
1489 if (i - start < tlen || strncmp (&s[start], tname, i - start))
1490 print_include (out, &s[start], i - start);
1495 /* If we saw an inner class, then the generated #include will
1496 declare the class. So in this case we needn't bother. */
1498 add_namelet (&s[start], &s[i], &root);
1502 /* Print declarations for all classes required by this class. Any
1503 class or package in the `java' package is assumed to be handled
1504 statically in libjava; we don't generate declarations for these.
1505 This makes the generated headers a bit easier to read. */
1507 print_class_decls (out, jcf, self)
1512 /* Make sure to always add the current class to the list of things
1513 that should be declared. */
1514 int name_index = JPOOL_USHORT1 (jcf, self);
1516 const unsigned char *s;
1518 s = JPOOL_UTF_DATA (jcf, name_index);
1519 len = JPOOL_UTF_LENGTH (jcf, name_index);
1520 add_namelet (s, s + len, &root);
1522 if (root.subnamelets)
1524 fputs ("extern \"Java\"\n{\n", out);
1525 /* We use an initial offset of 0 because the root namelet
1526 doesn't cause anything to print. */
1527 print_namelet (out, &root, 0);
1528 fputs ("};\n\n", out);
1535 DEFUN(process_file, (jcf, out),
1536 JCF *jcf AND FILE *out)
1539 uint32 field_start, method_end, method_start;
1545 if (jcf_parse_preamble (jcf) != 0)
1547 fprintf (stderr, "Not a valid Java .class file.\n");
1552 /* Parse and possibly print constant pool */
1553 code = jcf_parse_constant_pool (jcf);
1556 fprintf (stderr, "error while parsing constant pool\n");
1560 code = verify_constant_pool (jcf);
1563 fprintf (stderr, "error in constant pool entry #%d\n", code);
1568 jcf_parse_class (jcf);
1570 if (written_class_count++ == 0 && out)
1572 const char *cstart, *cstart2, *mode, *cend, *what, *jflag;
1587 mode = " -*- c++ -*-";
1593 fprintf (out, "%s DO NOT EDIT THIS FILE - it is machine generated%s%s\n\n",
1594 cstart, mode, cend);
1597 fprintf (out, "%s This file was created by `gcjh -stubs%s'.%s\n\
1599 %s This file is intended to give you a head start on implementing native\n\
1600 %s methods using %s.\n\
1601 %s Be aware: running `gcjh -stubs %s' once more for this class may\n\
1602 %s overwrite any edits you have made to this file.%s\n\n",
1603 cstart, jflag, mode,
1619 print_mangled_classname (out, jcf, "#ifndef __", jcf->this_class);
1620 fprintf (out, "__\n");
1622 print_mangled_classname (out, jcf, "#define __", jcf->this_class);
1623 fprintf (out, "__\n\n");
1627 fprintf (out, "#include <jni.h>\n\n");
1628 fprintf (out, "#ifdef __cplusplus\n");
1629 fprintf (out, "extern \"C\"\n");
1630 fprintf (out, "{\n");
1631 fprintf (out, "#endif\n");
1635 /* We do this to ensure that inline methods won't be
1636 `outlined' by g++. This works as long as method and
1637 fields are not added by the user. */
1638 fprintf (out, "#pragma interface\n");
1640 if (jcf->super_class)
1643 const unsigned char *supername =
1644 super_class_name (jcf, &super_length);
1647 print_include (out, supername, super_length);
1653 /* Strip off the ".class" portion of the name when printing
1654 the include file name. */
1655 int len = strlen (jcf->classname);
1656 if (len > 6 && ! strcmp (&jcf->classname[len - 6], ".class"))
1658 print_include (out, jcf->classname, len);
1662 /* We want to parse the methods first. But we need to find where
1663 they start. So first we skip the fields, then parse the methods.
1664 Then we parse the fields and skip the methods. This is ugly, but
1665 not too bad since we need two full passes to get class decl
1666 information anyway. */
1668 field_start = JCF_TELL (jcf);
1669 jcf_parse_fields (jcf);
1671 method_start = JCF_TELL (jcf);
1673 jcf_parse_methods (jcf);
1678 if (out && ! flag_jni)
1681 print_class_decls (out, jcf, jcf->this_class);
1683 for (i = 0; i < prepend_count; ++i)
1684 fprintf (out, "%s\n", prepend_specs[i]);
1685 if (prepend_count > 0)
1690 if (! print_cxx_classname (out, "class ", jcf, jcf->this_class))
1692 fprintf (stderr, "class is of array type\n");
1696 if (jcf->super_class)
1698 if (! print_cxx_classname (out, " : public ",
1699 jcf, jcf->super_class))
1701 fprintf (stderr, "base class is of array type\n");
1707 fputs ("\n{\n", out);
1711 /* Now go back for second pass over methods and fields. */
1712 JCF_SEEK (jcf, method_start);
1714 jcf_parse_methods (jcf);
1715 method_end = JCF_TELL (jcf);
1718 JCF_SEEK (jcf, field_start);
1719 jcf_parse_fields (jcf);
1720 JCF_SEEK (jcf, method_end);
1722 jcf_parse_final_attributes (jcf);
1728 fprintf (out, "\n#ifdef __cplusplus\n");
1729 fprintf (out, "}\n");
1730 fprintf (out, "#endif\n");
1734 /* Generate friend decl if we still must. */
1735 for (i = 0; i < friend_count; ++i)
1736 fprintf (out, " friend %s\n", friend_specs[i]);
1738 /* Generate extra declarations. */
1741 for (i = 0; i < add_count; ++i)
1742 fprintf (out, " %s\n", add_specs[i]);
1745 fputs ("};\n", out);
1747 if (append_count > 0)
1749 for (i = 0; i < append_count; ++i)
1750 fprintf (out, "%s\n", append_specs[i]);
1753 print_mangled_classname (out, jcf,
1754 "\n#endif /* __", jcf->this_class);
1755 fprintf (out, "__ */\n");
1761 /* This is used to mark options with no short value. */
1762 #define LONG_OPT(Num) ((Num) + 128)
1764 #define OPT_classpath LONG_OPT (0)
1765 #define OPT_CLASSPATH LONG_OPT (1)
1766 #define OPT_HELP LONG_OPT (2)
1767 #define OPT_TEMP LONG_OPT (3)
1768 #define OPT_VERSION LONG_OPT (4)
1769 #define OPT_PREPEND LONG_OPT (5)
1770 #define OPT_FRIEND LONG_OPT (6)
1771 #define OPT_ADD LONG_OPT (7)
1772 #define OPT_APPEND LONG_OPT (8)
1773 #define OPT_M LONG_OPT (9)
1774 #define OPT_MM LONG_OPT (10)
1775 #define OPT_MG LONG_OPT (11)
1776 #define OPT_MD LONG_OPT (12)
1777 #define OPT_MMD LONG_OPT (13)
1779 static struct option options[] =
1781 { "classpath", required_argument, NULL, OPT_classpath },
1782 { "CLASSPATH", required_argument, NULL, OPT_CLASSPATH },
1783 { "help", no_argument, NULL, OPT_HELP },
1784 { "stubs", no_argument, &stubs, 1 },
1785 { "td", required_argument, NULL, OPT_TEMP },
1786 { "verbose", no_argument, NULL, 'v' },
1787 { "version", no_argument, NULL, OPT_VERSION },
1788 { "prepend", required_argument, NULL, OPT_PREPEND },
1789 { "friend", required_argument, NULL, OPT_FRIEND },
1790 { "add", required_argument, NULL, OPT_ADD },
1791 { "append", required_argument, NULL, OPT_APPEND },
1792 { "M", no_argument, NULL, OPT_M },
1793 { "MM", no_argument, NULL, OPT_MM },
1794 { "MG", no_argument, NULL, OPT_MG },
1795 { "MD", no_argument, NULL, OPT_MD },
1796 { "MMD", no_argument, NULL, OPT_MMD },
1797 { "jni", no_argument, &flag_jni, 1 },
1798 { NULL, no_argument, NULL, 0 }
1804 fprintf (stderr, "Try `gcjh --help' for more information.\n");
1811 printf ("Usage: gcjh [OPTION]... CLASS...\n\n");
1812 printf ("Generate C++ header files from .class files\n\n");
1813 printf (" -stubs Generate an implementation stub file\n");
1814 printf (" -jni Generate a JNI header or stub\n");
1816 printf (" -add TEXT Insert TEXT into class body\n");
1817 printf (" -append TEXT Insert TEXT after class declaration\n");
1818 printf (" -friend TEXT Insert TEXT as `friend' declaration\n");
1819 printf (" -prepend TEXT Insert TEXT before start of class\n");
1821 printf (" --classpath PATH Set path to find .class files\n");
1822 printf (" --CLASSPATH PATH Set path to find .class files\n");
1823 printf (" -IDIR Append directory to class path\n");
1824 printf (" -d DIRECTORY Set output directory name\n");
1825 printf (" -o FILE Set output file name\n");
1826 printf (" -td DIRECTORY Set temporary directory name\n");
1828 printf (" --help Print this help, then exit\n");
1829 printf (" --version Print version number, then exit\n");
1830 printf (" -v, --verbose Print extra information while running\n");
1832 printf (" -M Print all dependencies to stdout;\n");
1833 printf (" suppress ordinary output\n");
1834 printf (" -MM Print non-system dependencies to stdout;\n");
1835 printf (" suppress ordinary output\n");
1836 printf (" -MD Print all dependencies to stdout\n");
1837 printf (" -MMD Print non-system dependencies to stdout\n");
1838 /* We omit -MG until it is implemented. */
1840 printf ("For bug reporting instructions, please see:\n");
1841 printf ("<URL:http://www.gnu.org/software/gcc/faq.html#bugreport>.\n");
1848 printf ("gcjh (%s)\n\n", version_string);
1849 printf ("Copyright (C) 1998, 1999 Free Software Foundation, Inc.\n");
1850 printf ("This is free software; see the source for copying conditions. There is NO\n");
1851 printf ("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n");
1856 DEFUN(main, (argc, argv),
1857 int argc AND char** argv)
1861 char *output_file = NULL;
1862 int emit_dependencies = 0, suppress_output = 0;
1867 fprintf (stderr, "gcjh: no classes specified\n");
1873 /* We use getopt_long_only to allow single `-' long options. For
1874 some of our options this is more natural. */
1875 while ((opt = getopt_long_only (argc, argv, "I:d:o:v", options, NULL)) != -1)
1880 /* Already handled. */
1884 output_file = optarg;
1888 output_directory = optarg;
1892 jcf_path_include_arg (optarg);
1900 jcf_path_classpath_arg (optarg);
1904 jcf_path_CLASSPATH_arg (optarg);
1912 temp_directory = optarg;
1920 if (prepend_count == 0)
1921 prepend_specs = (char**) ALLOC (argc * sizeof (char*));
1922 prepend_specs[prepend_count++] = optarg;
1926 if (friend_count == 0)
1927 friend_specs = (char**) ALLOC (argc * sizeof (char*));
1928 friend_specs[friend_count++] = optarg;
1933 add_specs = (char**) ALLOC (argc * sizeof (char*));
1934 add_specs[add_count++] = optarg;
1938 if (append_count == 0)
1939 append_specs = (char**) ALLOC (argc * sizeof (char*));
1940 append_specs[append_count++] = optarg;
1944 emit_dependencies = 1;
1945 suppress_output = 1;
1946 jcf_dependency_init (1);
1950 emit_dependencies = 1;
1951 suppress_output = 1;
1952 jcf_dependency_init (0);
1956 fprintf (stderr, "gcjh: `%s' option is unimplemented\n", argv[argi]);
1960 emit_dependencies = 1;
1961 jcf_dependency_init (1);
1965 emit_dependencies = 1;
1966 jcf_dependency_init (0);
1977 fprintf (stderr, "gcjh: no classes specified\n");
1983 if (output_file && emit_dependencies)
1985 fprintf (stderr, "gcjh: can't specify both -o and -MD\n");
1989 for (argi = optind; argi < argc; argi++)
1991 char *classname = argv[argi];
1992 char *current_output_file;
1993 const char *classfile_name;
1996 fprintf (stderr, "Processing %s\n", classname);
1998 jcf_dependency_reset ();
1999 classfile_name = find_class (classname, strlen (classname), &jcf, 0);
2000 if (classfile_name == NULL)
2002 fprintf (stderr, "%s: no such class\n", classname);
2006 fprintf (stderr, "Found in %s\n", classfile_name);
2009 if (strcmp (output_file, "-") == 0)
2011 else if (out == NULL)
2013 out = fopen (output_file, "w");
2017 perror (output_file);
2020 current_output_file = output_file;
2024 int dir_len = strlen (output_directory);
2025 int i, classname_length = strlen (classname);
2026 current_output_file = (char*) ALLOC (dir_len + classname_length + 5);
2027 strcpy (current_output_file, output_directory);
2028 if (dir_len > 0 && output_directory[dir_len-1] != '/')
2029 current_output_file[dir_len++] = '/';
2030 for (i = 0; classname[i] != '\0'; i++)
2032 char ch = classname[i];
2035 if (flag_jni && ch == '/')
2037 current_output_file[dir_len++] = ch;
2039 if (emit_dependencies)
2041 if (suppress_output)
2043 jcf_dependency_set_dep_file ("-");
2048 /* We use `.hd' and not `.d' to avoid clashes with
2049 dependency tracking from straight compilation. */
2050 strcpy (current_output_file + dir_len, ".hd");
2051 jcf_dependency_set_dep_file (current_output_file);
2054 strcpy (current_output_file + dir_len,
2055 stubs ? (flag_jni ? ".c" : ".cc") : ".h");
2056 jcf_dependency_set_target (current_output_file);
2057 if (! suppress_output)
2059 out = fopen (current_output_file, "w");
2062 perror (current_output_file);
2067 process_file (&jcf, out);
2069 if (current_output_file != output_file)
2070 free (current_output_file);
2071 jcf_dependency_write ();
2074 if (out != NULL && out != stdout)