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;
152 JCF_u2 current_field_name;
153 JCF_u2 current_field_value;
154 JCF_u2 current_field_signature;
155 JCF_u2 current_field_flags;
157 #define HANDLE_START_FIELD(ACCESS_FLAGS, NAME, SIGNATURE, ATTRIBUTE_COUNT) \
158 ( current_field_name = (NAME), current_field_signature = (SIGNATURE), \
159 current_field_flags = (ACCESS_FLAGS), current_field_value = 0)
161 /* We pass over fields twice. The first time we just note the types
162 of the fields and then the start of the methods. Then we go back
163 and parse the fields for real. This is ugly. */
164 static int field_pass;
165 /* Likewise we pass over methods twice. The first time we generate
166 class decl information; the second time we generate actual method
168 static int method_pass;
170 #define HANDLE_END_FIELD() \
173 if (out && ! stubs && ! flag_jni) \
174 print_field_info (out, jcf, current_field_name, \
175 current_field_signature, \
176 current_field_flags); \
178 else if (! stubs && ! flag_jni) \
179 add_class_decl (out, jcf, current_field_signature);
181 #define HANDLE_CONSTANTVALUE(VALUEINDEX) current_field_value = (VALUEINDEX)
183 static int method_declared = 0;
184 static int method_access = 0;
185 static int method_printed = 0;
186 #define HANDLE_METHOD(ACCESS_FLAGS, NAME, SIGNATURE, ATTRIBUTE_COUNT) \
189 decompiled = 0; method_printed = 0; \
191 print_method_info (out, jcf, NAME, SIGNATURE, ACCESS_FLAGS); \
194 print_method_info (NULL, jcf, NAME, SIGNATURE, ACCESS_FLAGS); \
195 else if (! stubs) add_class_decl (out, jcf, SIGNATURE);
197 #define HANDLE_CODE_ATTRIBUTE(MAX_STACK, MAX_LOCALS, CODE_LENGTH) \
198 if (out && method_declared) decompile_method (out, jcf, CODE_LENGTH);
200 static int decompiled = 0;
201 #define HANDLE_END_METHOD() \
202 if (out && method_printed) fputs (decompiled || stubs ? "\n" : ";\n", out);
204 #include "jcf-reader.c"
206 /* Some useful constants. */
207 #define F_NAN_MASK 0x7f800000
208 #if (1 == HOST_FLOAT_WORDS_BIG_ENDIAN)
209 #define D_NAN_MASK 0x000000007ff00000LL
211 #define D_NAN_MASK 0x7ff0000000000000LL
214 /* Return 1 if F is not Inf or NaN. */
216 java_float_finite (f)
222 /* We happen to know that F_NAN_MASK will match all NaN values, and
223 also positive and negative infinity. That's why we only need one
224 test here. See The Java Language Specification, section 20.9. */
225 return (u.i & F_NAN_MASK) != F_NAN_MASK;
228 /* Return 1 if D is not Inf or NaN. */
230 java_double_finite (d)
236 /* Now check for all NaNs. */
237 return (u.l & D_NAN_MASK) != D_NAN_MASK;
241 DEFUN(print_name, (stream, jcf, name_index),
242 FILE* stream AND JCF* jcf AND int name_index)
244 if (JPOOL_TAG (jcf, name_index) != CONSTANT_Utf8)
245 fprintf (stream, "<not a UTF8 constant>");
247 jcf_print_utf8 (stream, JPOOL_UTF_DATA (jcf, name_index),
248 JPOOL_UTF_LENGTH (jcf, name_index));
251 /* Print base name of class. The base name is everything after the
255 print_base_classname (stream, jcf, index)
260 int name_index = JPOOL_USHORT1 (jcf, index);
262 const unsigned char *s, *p, *limit;
264 s = JPOOL_UTF_DATA (jcf, name_index);
265 len = JPOOL_UTF_LENGTH (jcf, name_index);
270 int c = UTF8_GET (s, limit);
277 int ch = UTF8_GET (p, limit);
279 fputs ("::", stream);
281 jcf_print_char (stream, ch);
285 /* Return 0 if NAME is equal to STR, nonzero otherwise. */
288 utf8_cmp (str, length, name)
289 const unsigned char *str;
293 const unsigned char *limit = str + length;
296 for (i = 0; name[i]; ++i)
298 int ch = UTF8_GET (str, limit);
306 /* If NAME is the name of a C++ keyword, then return an override name.
307 This is a name that can be used in place of the keyword.
308 Otherwise, return NULL. FIXME: for now, we only handle those
309 keywords we know to be a problem for libgcj. */
312 cxx_keyword_subst (str, length)
313 const unsigned char *str;
316 if (! utf8_cmp (str, length, "delete"))
317 return "__dummy_delete";
318 else if (! utf8_cmp (str, length, "enum"))
319 return "__dummy_enum";
323 /* Generate an access control keyword based on FLAGS. */
326 generate_access (stream, flags)
330 if ((flags & ACC_VISIBILITY) == last_access)
332 last_access = (flags & ACC_VISIBILITY);
337 fputs ("public: // actually package-private\n", stream);
340 fputs ("public:\n", stream);
343 fputs ("private:\n", stream);
346 fputs ("public: // actually protected\n", stream);
350 fprintf (stream, "#error unrecognized visibility %d\n",
351 (flags & ACC_VISIBILITY));
356 /* See if NAME is already the name of a method. */
358 name_is_method_p (name, length)
359 const unsigned char *name;
362 struct method_name *p;
364 for (p = method_name_list; p != NULL; p = p->next)
366 if (p->length == length && ! memcmp (p->name, name, length))
372 /* If there is already a method named NAME, whose signature is not
373 SIGNATURE, then return true. Otherwise return false. */
375 overloaded_jni_method_exists_p (name, length, signature, sig_length)
376 const unsigned char *name;
378 const char *signature;
381 struct method_name *p;
383 for (p = method_name_list; p != NULL; p = p->next)
385 if (p->length == length
386 && ! memcmp (p->name, name, length)
387 && (p->sig_length != sig_length
388 || memcmp (p->signature, signature, sig_length)))
394 /* Get name of a field. This handles renamings due to C++ clash. */
396 get_field_name (jcf, name_index, flags)
401 unsigned char *name = JPOOL_UTF_DATA (jcf, name_index);
402 int length = JPOOL_UTF_LENGTH (jcf, name_index);
404 const char *tmpconstptr;
407 if (name_is_method_p (name, length))
409 /* This field name matches a method. So override the name with
410 a dummy name. This is yucky, but it isn't clear what else to
411 do. FIXME: if the field is static, then we'll be in real
413 if ((flags & ACC_STATIC))
415 fprintf (stderr, "static field has same name as method\n");
420 override = xmalloc (length + 3);
421 memcpy (override, name, length);
422 strcpy (override + length, "__");
424 else if ((tmpconstptr = cxx_keyword_subst (name, length)) != NULL)
426 /* Must malloc OVERRIDE. */
427 override = xstrdup (tmpconstptr);
435 /* Print a field name. Convenience function for use with
438 print_field_name (stream, jcf, name_index, flags)
444 char *override = get_field_name (jcf, name_index, flags);
448 fputs (override, stream);
452 jcf_print_utf8 (stream, JPOOL_UTF_DATA (jcf, name_index),
453 JPOOL_UTF_LENGTH (jcf, name_index));
457 DEFUN(print_field_info, (stream, jcf, name_index, sig_index, flags),
458 FILE *stream AND JCF* jcf
459 AND int name_index AND int sig_index AND JCF_u2 flags)
461 char *override = NULL;
463 generate_access (stream, flags);
464 if (JPOOL_TAG (jcf, name_index) != CONSTANT_Utf8)
466 fprintf (stream, "<not a UTF8 constant>");
472 if ((flags & ACC_STATIC))
473 fputs ("static ", out);
475 if ((flags & ACC_FINAL))
477 if (current_field_value > 0)
482 switch (JPOOL_TAG (jcf, current_field_value))
484 case CONSTANT_Integer:
487 int most_negative = 0;
488 fputs ("const jint ", out);
489 print_field_name (out, jcf, name_index, 0);
491 num = JPOOL_INT (jcf, current_field_value);
492 /* We single out the most negative number to print
493 specially. This avoids later warnings from g++. */
494 if (num == (jint) 0x80000000)
499 format_int (buffer, (jlong) num, 10);
500 fprintf (out, "%sL%s;\n", buffer, most_negative ? " - 1" : "");
506 int most_negative = 0;
507 fputs ("const jlong ", out);
508 print_field_name (out, jcf, name_index, 0);
510 num = JPOOL_LONG (jcf, current_field_value);
511 /* We single out the most negative number to print
512 specially.. This avoids later warnings from g++. */
513 if (num == (jlong) 0x8000000000000000LL)
518 format_int (buffer, num, 10);
519 fprintf (out, "%sLL%s;\n", buffer, most_negative ? " - 1" :"");
524 jfloat fnum = JPOOL_FLOAT (jcf, current_field_value);
525 fputs ("const jfloat ", out);
526 print_field_name (out, jcf, name_index, 0);
527 if (! java_float_finite (fnum))
530 fprintf (out, " = %.10g;\n", fnum);
533 case CONSTANT_Double:
535 jdouble dnum = JPOOL_DOUBLE (jcf, current_field_value);
536 fputs ("const jdouble ", out);
537 print_field_name (out, jcf, name_index, 0);
538 if (! java_double_finite (dnum))
541 fprintf (out, " = %.17g;\n", dnum);
545 /* We can't print this as a constant, but we can still
546 print something sensible. */
556 override = get_field_name (jcf, name_index, flags);
557 print_c_decl (out, jcf, name_index, sig_index, 0, override, flags);
565 DEFUN(print_method_info, (stream, jcf, name_index, sig_index, flags),
566 FILE *stream AND JCF* jcf
567 AND int name_index AND int sig_index AND JCF_u2 flags)
569 const unsigned char *str;
570 int length, is_init = 0;
571 const char *override = NULL;
574 method_access = flags;
575 if (stream && JPOOL_TAG (jcf, name_index) != CONSTANT_Utf8)
576 fprintf (stream, "<not a UTF8 constant>");
577 str = JPOOL_UTF_DATA (jcf, name_index);
578 length = JPOOL_UTF_LENGTH (jcf, name_index);
579 if (str[0] == '<' || str[0] == '$')
581 /* Ignore internally generated methods like <clinit> and
582 $finit$. However, treat <init> as a constructor. */
583 if (! utf8_cmp (str, length, "<init>"))
585 else if (! METHOD_IS_FINAL (jcf->access_flags, flags)
586 && ! (flags & ACC_STATIC))
588 /* FIXME: i18n bug here. Order of prints should not be
590 fprintf (stderr, "ignored method `");
591 jcf_print_utf8 (stderr, str, length);
592 fprintf (stderr, "' marked virtual\n");
601 struct method_name *nn;
603 nn = (struct method_name *) xmalloc (sizeof (struct method_name));
604 nn->name = (char *) xmalloc (length);
605 memcpy (nn->name, str, length);
607 nn->next = method_name_list;
608 nn->sig_length = JPOOL_UTF_LENGTH (jcf, sig_index);
609 nn->signature = (char *) xmalloc (nn->sig_length);
610 memcpy (nn->signature, JPOOL_UTF_DATA (jcf, sig_index),
612 method_name_list = nn;
615 /* If we're not printing, then the rest of this function doesn't
616 matter. This happens during the first method pass in JNI mode.
621 /* We can't generate a method whose name is a C++ reserved word. We
622 can't just ignore the function, because that will cause incorrect
623 code to be generated if the function is virtual (not only for
624 calls to this function for for other functions after it in the
625 vtbl). So we give it a dummy name instead. */
626 override = cxx_keyword_subst (str, length);
629 /* If the method is static or final, we can safely skip it. If
630 we don't skip it then we'll have problems since the mangling
631 will be wrong. FIXME. */
632 if (METHOD_IS_FINAL (jcf->access_flags, flags)
633 || (flags & ACC_STATIC))
637 if (! stubs && ! flag_jni)
641 generate_access (stream, flags);
644 if ((flags & ACC_STATIC))
645 fputs ("static ", out);
646 else if (! METHOD_IS_FINAL (jcf->access_flags, flags))
648 /* Don't print `virtual' if we have a constructor. */
650 fputs ("virtual ", out);
652 print_c_decl (out, jcf, name_index, sig_index, is_init, override, flags);
654 if ((flags & ACC_ABSTRACT))
661 if (METHOD_IS_NATIVE (flags))
664 print_stub_or_jni (out, jcf, name_index, sig_index,
665 is_init, override, flags);
670 /* Try to decompile a method body. Right now we just try to handle a
671 simple case that we can do. Expand as desired. */
673 decompile_method (out, jcf, code_len)
678 const unsigned char *codes = jcf->read_ptr;
680 uint16 name_and_type, name;
682 /* If the method is synchronized, don't touch it. */
683 if ((method_access & ACC_SYNCHRONIZED))
687 && codes[0] == OPCODE_aload_0
688 && codes[1] == OPCODE_getfield
689 && (codes[4] == OPCODE_areturn
690 || codes[4] == OPCODE_dreturn
691 || codes[4] == OPCODE_freturn
692 || codes[4] == OPCODE_ireturn
693 || codes[4] == OPCODE_lreturn))
695 /* Found code like `return FIELD'. */
696 fputs (" { return ", out);
697 index = (codes[2] << 8) | codes[3];
698 /* FIXME: ensure that tag is CONSTANT_Fieldref. */
699 /* FIXME: ensure that the field's class is this class. */
700 name_and_type = JPOOL_USHORT2 (jcf, index);
701 /* FIXME: ensure that tag is CONSTANT_NameAndType. */
702 name = JPOOL_USHORT1 (jcf, name_and_type);
703 print_name (out, jcf, name);
707 else if (code_len == 2
708 && codes[0] == OPCODE_aload_0
709 && codes[1] == OPCODE_areturn)
711 /* Found `return this'. */
712 fputs (" { return this; }", out);
715 else if (code_len == 1 && codes[0] == OPCODE_return)
717 /* Found plain `return'. */
721 else if (code_len == 2
722 && codes[0] == OPCODE_aconst_null
723 && codes[1] == OPCODE_areturn)
725 /* Found `return null'. We don't want to depend on NULL being
727 fputs (" { return 0; }", out);
732 /* Print one piece of a signature. Returns pointer to next parseable
733 character on success, NULL on error. */
734 static const unsigned char *
735 decode_signature_piece (stream, signature, limit, need_space)
737 const unsigned char *signature, *limit;
743 switch (signature[0])
746 /* More spaghetti. */
749 for (signature++; (signature < limit
751 && *signature <= '9'); signature++)
756 ctype = "jbyteArray";
759 ctype = "jcharArray";
762 ctype = "jdoubleArray";
765 ctype = "jfloatArray";
771 ctype = "jshortArray";
774 ctype = "jlongArray";
777 ctype = "jbooleanArray";
780 /* We have a nested array. */
783 fputs ("JArray<", stream);
787 /* We have to generate a reference to JArray here, so that
788 our output matches what the compiler does. */
790 /* Space between `<' and `:' to avoid C++ digraphs. */
792 fputs ("JArray< ::", stream);
793 while (signature < limit && *signature != ';')
795 int ch = UTF8_GET (signature, limit);
799 fputs ("::", stream);
801 jcf_print_char (stream, ch);
805 fputs (" *> *", stream);
810 /* Unparseable signature. */
814 /* If the previous iterations left us with something to print,
815 print it. For JNI, we always print `jobjectArray' in the
817 if (flag_jni && ctype == NULL)
819 ctype = "jobjectArray";
822 /* The `printit' case will advance SIGNATURE for us. If we
823 don't go there, we must advance past the `;' ourselves. */
831 /* This shouldn't happen. */
834 case 'B': ctype = "jbyte"; goto printit;
835 case 'C': ctype = "jchar"; goto printit;
836 case 'D': ctype = "jdouble"; goto printit;
837 case 'F': ctype = "jfloat"; goto printit;
838 case 'I': ctype = "jint"; goto printit;
839 case 'J': ctype = "jlong"; goto printit;
840 case 'S': ctype = "jshort"; goto printit;
841 case 'Z': ctype = "jboolean"; goto printit;
842 case 'V': ctype = "void"; goto printit;
846 /* We know about certain types and special-case their
848 FIXME: something like java.lang.Exception should be
849 printed as `jthrowable', because it is a subclass. This
850 means that gcjh must read the entire hierarchy and
852 if (! strncmp (signature, "Ljava/lang/String;",
853 sizeof ("Ljava/lang/String;") -1))
855 else if (! strncmp (signature, "Ljava/lang/Class;",
856 sizeof ("Ljava/lang/Class;") - 1))
858 else if (! strncmp (signature, "Ljava/lang/Throwable;",
859 sizeof ("Ljava/lang/Throwable;") - 1))
860 ctype = "jthrowable";
861 else if (! strncmp (signature, "Ljava/lang/ref/WeakReference;",
862 sizeof ("Ljava/lang/ref/WeakReference;") - 1))
867 while (*signature && *signature != ';')
872 /* Print a leading "::" so we look in the right namespace. */
873 fputs ("::", stream);
875 while (*signature && *signature != ';')
877 int ch = UTF8_GET (signature, limit);
878 /* `$' is the separator for an inner class. */
879 if (ch == '/' || ch == '$')
880 fputs ("::", stream);
882 jcf_print_char (stream, ch);
884 fputs (" *", stream);
885 if (*signature == ';')
891 jcf_print_char (stream, *signature++);
896 fputs (ctype, stream);
902 while (array_depth-- > 0)
903 fputs ("> *", stream);
910 DEFUN(print_c_decl, (stream, jcf, name_index, signature_index, is_init,
911 name_override, flags),
912 FILE* stream AND JCF* jcf
913 AND int name_index AND int signature_index
914 AND int is_init AND const char *name_override AND int flags)
916 if (JPOOL_TAG (jcf, signature_index) != CONSTANT_Utf8)
918 fprintf (stream, "<not a UTF8 constant>");
923 int length = JPOOL_UTF_LENGTH (jcf, signature_index);
924 const unsigned char *str0 = JPOOL_UTF_DATA (jcf, signature_index);
925 register const unsigned char *str = str0;
926 const unsigned char *limit = str + length;
928 int is_method = str[0] == '(';
929 const unsigned char *next;
931 /* If printing a method, skip to the return signature and print
932 that first. However, there is no return value if this is a
934 if (is_method && ! is_init)
944 /* If printing a field or an ordinary method, then print the
945 "return value" now. */
946 if (! is_method || ! is_init)
948 next = decode_signature_piece (stream, str, limit, &need_space);
951 fprintf (stderr, "unparseable signature: `%s'\n", str0);
957 /* Now print the name of the thing. */
960 print_full_cxx_name (stream, jcf, name_index,
961 signature_index, is_init, name_override,
966 /* Print the unqualified method name followed by the signature. */
968 DEFUN(print_full_cxx_name, (stream, jcf, name_index, signature_index,
969 is_init, name_override, flags),
970 FILE* stream AND JCF* jcf
971 AND int name_index AND int signature_index AND int is_init
972 AND const char *name_override AND int flags)
974 int length = JPOOL_UTF_LENGTH (jcf, signature_index);
975 const unsigned char *str0 = JPOOL_UTF_DATA (jcf, signature_index);
976 register const unsigned char *str = str0;
977 const unsigned char *limit = str + length;
979 int is_method = str[0] == '(';
980 const unsigned char *next;
983 fputs (name_override, stream);
986 /* Declare constructors specially. */
988 print_base_classname (stream, jcf, jcf->this_class);
990 print_name (stream, jcf, name_index);
995 unsigned char *signature = JPOOL_UTF_DATA (jcf, signature_index);
996 int sig_len = JPOOL_UTF_LENGTH (jcf, signature_index);
997 if (overloaded_jni_method_exists_p (JPOOL_UTF_DATA (jcf, name_index),
998 JPOOL_UTF_LENGTH (jcf, name_index),
1001 /* If this method is overloaded by another native method,
1002 then include the argument information in the mangled
1004 unsigned char *limit = signature + sig_len;
1005 fputs ("__", stream);
1006 while (signature < limit)
1008 int ch = UTF8_GET (signature, limit);
1019 fputs ("_1", stream);
1021 fputs ("_2", stream);
1023 fputs ("_3", stream);
1025 fputs ("_", stream);
1026 else if ((ch >= '0' && ch <= '9')
1027 || (ch >= 'a' && ch <= 'z')
1028 || (ch >= 'A' && ch <= 'Z'))
1032 /* "Unicode" character. FIXME: upper or lower case
1034 fprintf (stream, "_0%04x", ch);
1042 /* Have a method or a constructor. Print signature pieces
1044 fputs (" (", stream);
1048 /* In JNI mode, add extra arguments. */
1051 /* FIXME: it would be nice to know if we are printing a decl
1052 or a definition, and only print `env' for the latter. */
1053 fputs ("JNIEnv *env", stream);
1055 fputs ((flags & ACC_STATIC) ? ", jclass" : ", jobject", stream);
1058 fputs (", ", stream);
1061 while (str < limit && *str != ')')
1063 next = decode_signature_piece (stream, str, limit, &need_space);
1066 fprintf (stderr, "unparseable signature: `%s'\n", str0);
1071 if (next < limit && *next != ')')
1072 fputs (", ", stream);
1076 fputs (")", stream);
1080 /* This is a helper for print_stub_or_jni. */
1082 DEFUN (print_name_for_stub_or_jni, (stream, jcf, name_index, signature_index,
1083 is_init, name_override, flags),
1084 FILE *stream AND JCF *jcf
1085 AND int name_index AND int signature_index
1086 AND int is_init AND const char *name_override AND int flags)
1088 char *prefix = flag_jni ? "Java_" : "\n";
1089 print_cxx_classname (stream, prefix, jcf, jcf->this_class);
1090 fputs (flag_jni ? "_" : "::", stream);
1091 print_full_cxx_name (stream, jcf, name_index,
1092 signature_index, is_init, name_override,
1097 DEFUN(print_stub_or_jni, (stream, jcf, name_index, signature_index, is_init,
1098 name_override, flags),
1099 FILE* stream AND JCF* jcf
1100 AND int name_index AND int signature_index
1101 AND int is_init AND const char *name_override AND int flags)
1103 if (JPOOL_TAG (jcf, signature_index) != CONSTANT_Utf8)
1105 fprintf (stream, "<not a UTF8 constant>");
1110 int length = JPOOL_UTF_LENGTH (jcf, signature_index);
1111 const unsigned char *str0 = JPOOL_UTF_DATA (jcf, signature_index);
1112 register const unsigned char *str = str0;
1113 const unsigned char *limit = str + length;
1115 int is_method = str[0] == '(';
1116 const unsigned char *next;
1118 /* Don't print fields in the JNI case. */
1119 if (! is_method && flag_jni)
1122 if (flag_jni && ! stubs)
1123 fputs ("extern ", stream);
1125 /* If printing a method, skip to the return signature and print
1126 that first. However, there is no return value if this is a
1128 if (is_method && ! is_init)
1138 /* If printing a field or an ordinary method, then print the
1139 "return value" now. Note that a constructor can't be native,
1140 so we don't bother checking this in the JNI case. */
1141 if (! is_method || ! is_init)
1143 next = decode_signature_piece (stream, str, limit, &need_space);
1146 fprintf (stderr, "unparseable signature: `%s'\n", str0);
1152 /* When printing a JNI header we need to respect the space. In
1153 other cases we're just going to insert a newline anyway. */
1155 fputs (need_space && ! stubs ? " " : "\n", stream);
1157 /* Now print the name of the thing. */
1158 print_name_for_stub_or_jni (stream, jcf, name_index,
1159 signature_index, is_init, name_override,
1162 /* Print the body. */
1166 fputs ("\n{\n (*env)->FatalError (\"", stream);
1168 fputs ("\n{\n JvFail (\"", stream);
1169 print_name_for_stub_or_jni (stream, jcf, name_index,
1170 signature_index, is_init,
1173 fputs (" not implemented\");\n}\n\n", stream);
1179 DEFUN(print_mangled_classname, (stream, jcf, prefix, index),
1180 FILE *stream AND JCF *jcf AND const char *prefix AND int index)
1182 int name_index = JPOOL_USHORT1 (jcf, index);
1183 fputs (prefix, stream);
1184 jcf_print_utf8_replace (out,
1185 JPOOL_UTF_DATA (jcf, name_index),
1186 JPOOL_UTF_LENGTH (jcf, name_index),
1190 /* Print PREFIX, then a class name in C++ format. If the name refers
1191 to an array, ignore it and don't print PREFIX. Returns 1 if
1192 something was printed, 0 otherwise. */
1194 print_cxx_classname (stream, prefix, jcf, index)
1200 int name_index = JPOOL_USHORT1 (jcf, index);
1202 const unsigned char *s, *p, *limit;
1204 s = JPOOL_UTF_DATA (jcf, name_index);
1205 len = JPOOL_UTF_LENGTH (jcf, name_index);
1208 /* Explicitly omit arrays here. */
1210 c = UTF8_GET (p, limit);
1214 fputs (prefix, stream);
1216 /* Print a leading "::" so we look in the right namespace. */
1218 fputs ("::", stream);
1222 c = UTF8_GET (s, limit);
1224 fputs (flag_jni ? "_" : "::", stream);
1226 jcf_print_char (stream, c);
1232 int written_class_count = 0;
1234 /* Return name of superclass. If LEN is not NULL, fill it with length
1236 static const unsigned char *
1237 super_class_name (derived_jcf, len)
1241 int supername_index = JPOOL_USHORT1 (derived_jcf, derived_jcf->super_class);
1242 int supername_length = JPOOL_UTF_LENGTH (derived_jcf, supername_index);
1243 const unsigned char *supername =
1244 JPOOL_UTF_DATA (derived_jcf, supername_index);
1247 *len = supername_length;
1254 /* We keep track of all the `#include's we generate, so we can avoid
1259 struct include *next;
1262 /* List of all includes. */
1263 static struct include *all_includes = NULL;
1265 /* Generate a #include. */
1267 print_include (out, utf8, len)
1269 const unsigned char *utf8;
1272 struct include *incl;
1278 len = strlen (utf8);
1280 for (incl = all_includes; incl; incl = incl->next)
1282 /* We check the length because we might have a proper prefix. */
1283 if (len == (int) strlen (incl->name)
1284 && ! strncmp (incl->name, utf8, len))
1288 incl = (struct include *) xmalloc (sizeof (struct include));
1289 incl->name = xmalloc (len + 1);
1290 strncpy (incl->name, utf8, len);
1291 incl->name[len] = '\0';
1292 incl->next = all_includes;
1293 all_includes = incl;
1295 fputs ("#include <", out);
1296 jcf_print_utf8_replace (out, utf8, len,
1298 flag_jni ? '_' : '/');
1299 fputs (".h>\n", out);
1304 /* This is used to represent part of a package or class name. */
1307 /* The text of this part of the name. */
1309 /* True if this represents a class. */
1311 /* Linked list of all classes and packages inside this one. */
1312 struct namelet *subnamelets;
1313 /* Pointer to next sibling. */
1314 struct namelet *next;
1317 static void add_namelet PARAMS ((const unsigned char *,
1318 const unsigned char *, struct namelet *));
1319 static void print_namelet PARAMS ((FILE *, struct namelet *, int));
1321 /* The special root namelet. */
1322 static struct namelet root =
1330 /* This extracts the next name segment from the full UTF-8 encoded
1331 package or class name and links it into the tree. It does this
1334 add_namelet (name, name_limit, parent)
1335 const unsigned char *name, *name_limit;
1336 struct namelet *parent;
1338 const unsigned char *p;
1339 struct namelet *n = NULL, *np;
1341 /* We want to skip the standard namespaces that we assume the
1342 runtime already knows about. We only do this at the top level,
1343 though, hence the check for `root'. */
1344 if (parent == &root)
1346 #define JAVALANG "java/lang/"
1347 #define JAVAIO "java/io/"
1348 #define JAVAUTIL "java/util/"
1349 if ((name_limit - name >= (int) sizeof (JAVALANG) - 1
1350 && ! strncmp (name, JAVALANG, sizeof (JAVALANG) - 1))
1351 || (name_limit - name >= (int) sizeof (JAVAUTIL) - 1
1352 && ! strncmp (name, JAVAUTIL, sizeof (JAVAUTIL) - 1))
1353 || (name_limit - name >= (int) sizeof (JAVAIO) - 1
1354 && ! strncmp (name, JAVAIO, sizeof (JAVAIO) - 1)))
1358 for (p = name; p < name_limit && *p != '/' && *p != '$'; ++p)
1361 /* Search for this name beneath the PARENT node. */
1362 for (np = parent->subnamelets; np != NULL; np = np->next)
1364 /* We check the length because we might have a proper prefix. */
1365 if ((int) strlen (np->name) == p - name &&
1366 ! strncmp (name, np->name, p - name))
1375 n = (struct namelet *) xmalloc (sizeof (struct namelet));
1376 n->name = xmalloc (p - name + 1);
1377 strncpy (n->name, name, p - name);
1378 n->name[p - name] = '\0';
1379 n->is_class = (p == name_limit || *p == '$');
1380 n->subnamelets = NULL;
1381 n->next = parent->subnamelets;
1382 parent->subnamelets = n;
1385 /* We recurse if there is more text, and if the trailing piece does
1386 not represent an inner class. */
1387 if (p < name_limit && *p != '$')
1388 add_namelet (p + 1, name_limit, n);
1391 /* Print a single namelet. Destroys namelets while printing. */
1393 print_namelet (out, name, depth)
1395 struct namelet *name;
1403 for (i = 0; i < depth; ++i)
1405 fprintf (out, "%s %s", name->is_class ? "class" : "namespace",
1407 if (name->is_class && name->subnamelets == NULL)
1413 for (i = 0; i < depth; ++i)
1419 c = name->subnamelets;
1422 struct namelet *next = c->next;
1423 print_namelet (out, c, depth + 2);
1431 for (i = 0; i < depth; ++i)
1434 /* Only print a `;' when printing a class. C++ is evil. */
1444 /* This is called to add some classes to the list of classes for which
1445 we need decls. The signature argument can be a function
1448 add_class_decl (out, jcf, signature)
1453 const unsigned char *s = JPOOL_UTF_DATA (jcf, signature);
1454 int len = JPOOL_UTF_LENGTH (jcf, signature);
1456 /* Name of class we are processing. */
1457 int name_index = JPOOL_USHORT1 (jcf, jcf->this_class);
1458 int tlen = JPOOL_UTF_LENGTH (jcf, name_index);
1459 const char *tname = JPOOL_UTF_DATA (jcf, name_index);
1461 for (i = 0; i < len; ++i)
1463 int start, saw_dollar;
1465 /* If we see an array, then we include the array header. */
1468 print_include (out, "gcj/array", -1);
1472 /* We're looking for `L<stuff>;' -- everything else is
1478 for (start = ++i; i < len && s[i] != ';'; ++i)
1480 if (! saw_dollar && s[i] == '$' && out)
1483 /* If this class represents an inner class, then
1484 generate a `#include' for the outer class. However,
1485 don't generate the include if the outer class is the
1486 class we are processing. */
1487 if (i - start < tlen || strncmp (&s[start], tname, i - start))
1488 print_include (out, &s[start], i - start);
1493 /* If we saw an inner class, then the generated #include will
1494 declare the class. So in this case we needn't bother. */
1496 add_namelet (&s[start], &s[i], &root);
1500 /* Print declarations for all classes required by this class. Any
1501 class or package in the `java' package is assumed to be handled
1502 statically in libjava; we don't generate declarations for these.
1503 This makes the generated headers a bit easier to read. */
1505 print_class_decls (out, jcf, self)
1510 /* Make sure to always add the current class to the list of things
1511 that should be declared. */
1512 int name_index = JPOOL_USHORT1 (jcf, self);
1514 const unsigned char *s;
1516 s = JPOOL_UTF_DATA (jcf, name_index);
1517 len = JPOOL_UTF_LENGTH (jcf, name_index);
1518 add_namelet (s, s + len, &root);
1520 if (root.subnamelets)
1522 fputs ("extern \"Java\"\n{\n", out);
1523 /* We use an initial offset of 0 because the root namelet
1524 doesn't cause anything to print. */
1525 print_namelet (out, &root, 0);
1526 fputs ("};\n\n", out);
1533 DEFUN(process_file, (jcf, out),
1534 JCF *jcf AND FILE *out)
1537 uint32 field_start, method_end, method_start;
1543 if (jcf_parse_preamble (jcf) != 0)
1545 fprintf (stderr, "Not a valid Java .class file.\n");
1550 /* Parse and possibly print constant pool */
1551 code = jcf_parse_constant_pool (jcf);
1554 fprintf (stderr, "error while parsing constant pool\n");
1558 code = verify_constant_pool (jcf);
1561 fprintf (stderr, "error in constant pool entry #%d\n", code);
1566 jcf_parse_class (jcf);
1568 if (written_class_count++ == 0 && out)
1570 char *cstart, *cstart2, *mode, *cend, *what, *jflag;
1585 mode = " -*- c++ -*-";
1591 fprintf (out, "%s DO NOT EDIT THIS FILE - it is machine generated%s%s\n\n",
1592 cstart, mode, cend);
1595 fprintf (out, "%s This file was created by `gcjh -stubs%s'.%s\n\
1597 %s This file is intended to give you a head start on implementing native\n\
1598 %s methods using %s.\n\
1599 %s Be aware: running `gcjh -stubs %s' once more for this class may\n\
1600 %s overwrite any edits you have made to this file.%s\n\n",
1601 cstart, jflag, mode,
1617 print_mangled_classname (out, jcf, "#ifndef __", jcf->this_class);
1618 fprintf (out, "__\n");
1620 print_mangled_classname (out, jcf, "#define __", jcf->this_class);
1621 fprintf (out, "__\n\n");
1625 fprintf (out, "#include <jni.h>\n\n");
1626 fprintf (out, "#ifdef __cplusplus\n");
1627 fprintf (out, "extern \"C\"\n");
1628 fprintf (out, "{\n");
1629 fprintf (out, "#endif\n");
1633 /* We do this to ensure that inline methods won't be
1634 `outlined' by g++. This works as long as method and
1635 fields are not added by the user. */
1636 fprintf (out, "#pragma interface\n");
1638 if (jcf->super_class)
1641 const unsigned char *supername =
1642 super_class_name (jcf, &super_length);
1645 print_include (out, supername, super_length);
1651 /* Strip off the ".class" portion of the name when printing
1652 the include file name. */
1653 int len = strlen (jcf->classname);
1654 if (len > 6 && ! strcmp (&jcf->classname[len - 6], ".class"))
1656 print_include (out, jcf->classname, len);
1660 /* We want to parse the methods first. But we need to find where
1661 they start. So first we skip the fields, then parse the methods.
1662 Then we parse the fields and skip the methods. This is ugly, but
1663 not too bad since we need two full passes to get class decl
1664 information anyway. */
1666 field_start = JCF_TELL (jcf);
1667 jcf_parse_fields (jcf);
1669 method_start = JCF_TELL (jcf);
1671 jcf_parse_methods (jcf);
1676 if (out && ! flag_jni)
1679 print_class_decls (out, jcf, jcf->this_class);
1681 for (i = 0; i < prepend_count; ++i)
1682 fprintf (out, "%s\n", prepend_specs[i]);
1683 if (prepend_count > 0)
1688 if (! print_cxx_classname (out, "class ", jcf, jcf->this_class))
1690 fprintf (stderr, "class is of array type\n");
1694 if (jcf->super_class)
1696 if (! print_cxx_classname (out, " : public ",
1697 jcf, jcf->super_class))
1699 fprintf (stderr, "base class is of array type\n");
1705 fputs ("\n{\n", out);
1709 /* Now go back for second pass over methods and fields. */
1710 JCF_SEEK (jcf, method_start);
1712 jcf_parse_methods (jcf);
1713 method_end = JCF_TELL (jcf);
1716 JCF_SEEK (jcf, field_start);
1717 jcf_parse_fields (jcf);
1718 JCF_SEEK (jcf, method_end);
1720 jcf_parse_final_attributes (jcf);
1726 fprintf (out, "\n#ifdef __cplusplus\n");
1727 fprintf (out, "}\n");
1728 fprintf (out, "#endif\n");
1732 /* Generate friend decl if we still must. */
1733 for (i = 0; i < friend_count; ++i)
1734 fprintf (out, " friend %s\n", friend_specs[i]);
1736 /* Generate extra declarations. */
1739 for (i = 0; i < add_count; ++i)
1740 fprintf (out, " %s\n", add_specs[i]);
1743 fputs ("};\n", out);
1745 if (append_count > 0)
1747 for (i = 0; i < append_count; ++i)
1748 fprintf (out, "%s\n", append_specs[i]);
1751 print_mangled_classname (out, jcf,
1752 "\n#endif /* __", jcf->this_class);
1753 fprintf (out, "__ */\n");
1759 /* This is used to mark options with no short value. */
1760 #define LONG_OPT(Num) ((Num) + 128)
1762 #define OPT_classpath LONG_OPT (0)
1763 #define OPT_CLASSPATH LONG_OPT (1)
1764 #define OPT_HELP LONG_OPT (2)
1765 #define OPT_TEMP LONG_OPT (3)
1766 #define OPT_VERSION LONG_OPT (4)
1767 #define OPT_PREPEND LONG_OPT (5)
1768 #define OPT_FRIEND LONG_OPT (6)
1769 #define OPT_ADD LONG_OPT (7)
1770 #define OPT_APPEND LONG_OPT (8)
1771 #define OPT_M LONG_OPT (9)
1772 #define OPT_MM LONG_OPT (10)
1773 #define OPT_MG LONG_OPT (11)
1774 #define OPT_MD LONG_OPT (12)
1775 #define OPT_MMD LONG_OPT (13)
1777 static struct option options[] =
1779 { "classpath", required_argument, NULL, OPT_classpath },
1780 { "CLASSPATH", required_argument, NULL, OPT_CLASSPATH },
1781 { "help", no_argument, NULL, OPT_HELP },
1782 { "stubs", no_argument, &stubs, 1 },
1783 { "td", required_argument, NULL, OPT_TEMP },
1784 { "verbose", no_argument, NULL, 'v' },
1785 { "version", no_argument, NULL, OPT_VERSION },
1786 { "prepend", required_argument, NULL, OPT_PREPEND },
1787 { "friend", required_argument, NULL, OPT_FRIEND },
1788 { "add", required_argument, NULL, OPT_ADD },
1789 { "append", required_argument, NULL, OPT_APPEND },
1790 { "M", no_argument, NULL, OPT_M },
1791 { "MM", no_argument, NULL, OPT_MM },
1792 { "MG", no_argument, NULL, OPT_MG },
1793 { "MD", no_argument, NULL, OPT_MD },
1794 { "MMD", no_argument, NULL, OPT_MMD },
1795 { "jni", no_argument, &flag_jni, 1 },
1796 { NULL, no_argument, NULL, 0 }
1802 fprintf (stderr, "Try `gcjh --help' for more information.\n");
1809 printf ("Usage: gcjh [OPTION]... CLASS...\n\n");
1810 printf ("Generate C++ header files from .class files\n\n");
1811 printf (" -stubs Generate an implementation stub file\n");
1812 printf (" -jni Generate a JNI header or stub\n");
1814 printf (" -add TEXT Insert TEXT into class body\n");
1815 printf (" -append TEXT Insert TEXT after class declaration\n");
1816 printf (" -friend TEXT Insert TEXT as `friend' declaration\n");
1817 printf (" -prepend TEXT Insert TEXT before start of class\n");
1819 printf (" --classpath PATH Set path to find .class files\n");
1820 printf (" --CLASSPATH PATH Set path to find .class files\n");
1821 printf (" -IDIR Append directory to class path\n");
1822 printf (" -d DIRECTORY Set output directory name\n");
1823 printf (" -o FILE Set output file name\n");
1824 printf (" -td DIRECTORY Set temporary directory name\n");
1826 printf (" --help Print this help, then exit\n");
1827 printf (" --version Print version number, then exit\n");
1828 printf (" -v, --verbose Print extra information while running\n");
1830 printf (" -M Print all dependencies to stdout;\n");
1831 printf (" suppress ordinary output\n");
1832 printf (" -MM Print non-system dependencies to stdout;\n");
1833 printf (" suppress ordinary output\n");
1834 printf (" -MD Print all dependencies to stdout\n");
1835 printf (" -MMD Print non-system dependencies to stdout\n");
1836 /* We omit -MG until it is implemented. */
1838 printf ("For bug reporting instructions, please see:\n");
1839 printf ("<URL:http://www.gnu.org/software/gcc/faq.html#bugreport>.\n");
1846 printf ("gcjh (%s)\n\n", version_string);
1847 printf ("Copyright (C) 1998, 1999 Free Software Foundation, Inc.\n");
1848 printf ("This is free software; see the source for copying conditions. There is NO\n");
1849 printf ("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n");
1854 DEFUN(main, (argc, argv),
1855 int argc AND char** argv)
1859 char *output_file = NULL;
1860 int emit_dependencies = 0, suppress_output = 0;
1865 fprintf (stderr, "gcjh: no classes specified\n");
1871 /* We use getopt_long_only to allow single `-' long options. For
1872 some of our options this is more natural. */
1873 while ((opt = getopt_long_only (argc, argv, "I:d:o:v", options, NULL)) != -1)
1878 /* Already handled. */
1882 output_file = optarg;
1886 output_directory = optarg;
1890 jcf_path_include_arg (optarg);
1898 jcf_path_classpath_arg (optarg);
1902 jcf_path_CLASSPATH_arg (optarg);
1910 temp_directory = optarg;
1918 if (prepend_count == 0)
1919 prepend_specs = (char**) ALLOC (argc * sizeof (char*));
1920 prepend_specs[prepend_count++] = optarg;
1924 if (friend_count == 0)
1925 friend_specs = (char**) ALLOC (argc * sizeof (char*));
1926 friend_specs[friend_count++] = optarg;
1931 add_specs = (char**) ALLOC (argc * sizeof (char*));
1932 add_specs[add_count++] = optarg;
1936 if (append_count == 0)
1937 append_specs = (char**) ALLOC (argc * sizeof (char*));
1938 append_specs[append_count++] = optarg;
1942 emit_dependencies = 1;
1943 suppress_output = 1;
1944 jcf_dependency_init (1);
1948 emit_dependencies = 1;
1949 suppress_output = 1;
1950 jcf_dependency_init (0);
1954 fprintf (stderr, "gcjh: `%s' option is unimplemented\n", argv[argi]);
1958 emit_dependencies = 1;
1959 jcf_dependency_init (1);
1963 emit_dependencies = 1;
1964 jcf_dependency_init (0);
1975 fprintf (stderr, "gcjh: no classes specified\n");
1981 if (output_file && emit_dependencies)
1983 fprintf (stderr, "gcjh: can't specify both -o and -MD\n");
1987 for (argi = optind; argi < argc; argi++)
1989 char *classname = argv[argi];
1990 char *current_output_file;
1991 const char *classfile_name;
1994 fprintf (stderr, "Processing %s\n", classname);
1996 jcf_dependency_reset ();
1997 classfile_name = find_class (classname, strlen (classname), &jcf, 0);
1998 if (classfile_name == NULL)
2000 fprintf (stderr, "%s: no such class\n", classname);
2004 fprintf (stderr, "Found in %s\n", classfile_name);
2007 if (strcmp (output_file, "-") == 0)
2009 else if (out == NULL)
2011 out = fopen (output_file, "w");
2015 perror (output_file);
2018 current_output_file = output_file;
2022 int dir_len = strlen (output_directory);
2023 int i, classname_length = strlen (classname);
2024 current_output_file = (char*) ALLOC (dir_len + classname_length + 5);
2025 strcpy (current_output_file, output_directory);
2026 if (dir_len > 0 && output_directory[dir_len-1] != '/')
2027 current_output_file[dir_len++] = '/';
2028 for (i = 0; classname[i] != '\0'; i++)
2030 char ch = classname[i];
2033 if (flag_jni && ch == '/')
2035 current_output_file[dir_len++] = ch;
2037 if (emit_dependencies)
2039 if (suppress_output)
2041 jcf_dependency_set_dep_file ("-");
2046 /* We use `.hd' and not `.d' to avoid clashes with
2047 dependency tracking from straight compilation. */
2048 strcpy (current_output_file + dir_len, ".hd");
2049 jcf_dependency_set_dep_file (current_output_file);
2052 strcpy (current_output_file + dir_len,
2053 stubs ? (flag_jni ? ".c" : ".cc") : ".h");
2054 jcf_dependency_set_target (current_output_file);
2055 if (! suppress_output)
2057 out = fopen (current_output_file, "w");
2060 perror (current_output_file);
2065 process_file (&jcf, out);
2067 if (current_output_file != output_file)
2068 free (current_output_file);
2069 jcf_dependency_write ();
2072 if (out != NULL && out != stdout)