diff options
Diffstat (limited to 'gcc/java/gjavah.c')
-rw-r--r-- | gcc/java/gjavah.c | 163 |
1 files changed, 115 insertions, 48 deletions
diff --git a/gcc/java/gjavah.c b/gcc/java/gjavah.c index b6229cc..4ad28db 100644 --- a/gcc/java/gjavah.c +++ b/gcc/java/gjavah.c @@ -40,8 +40,6 @@ static int found_error = 0; /* Directory to place resulting files in. Set by -d option. */ char *output_directory = ""; -char *output_file = NULL; - /* Directory to place temporary file. Set by -td option. Currently unused. */ char *temp_directory = "/tmp"; @@ -115,14 +113,14 @@ JCF_u2 current_field_flags; static int field_pass; #define HANDLE_END_FIELD() \ - if (field_pass) print_field_info (out, jcf, current_field_name, \ - current_field_signature, \ - current_field_flags); + if (out && field_pass) print_field_info (out, jcf, current_field_name, \ + current_field_signature, \ + current_field_flags); #define HANDLE_CONSTANTVALUE(VALUEINDEX) current_field_value = (VALUEINDEX) #define HANDLE_METHOD(ACCESS_FLAGS, NAME, SIGNATURE, ATTRIBUTE_COUNT) \ - print_method_info (out, jcf, NAME, SIGNATURE, ACCESS_FLAGS) + if (out) print_method_info (out, jcf, NAME, SIGNATURE, ACCESS_FLAGS) #include "jcf-reader.c" @@ -175,7 +173,7 @@ print_base_classname (stream, jcf, index) int index; { int name_index = JPOOL_USHORT1 (jcf, index); - int i, len; + int len; unsigned char *s, *p, *limit; s = JPOOL_UTF_DATA (jcf, name_index); @@ -629,7 +627,7 @@ DEFUN(print_c_decl, (stream, jcf, name_index, signature_index, flags, is_init, } } -int +void DEFUN(print_mangled_classname, (stream, jcf, prefix, index), FILE *stream AND JCF *jcf AND char *prefix AND int index) { @@ -652,7 +650,7 @@ print_cxx_classname (stream, prefix, jcf, index) int index; { int name_index = JPOOL_USHORT1 (jcf, index); - int i, len, c; + int len, c; unsigned char *s, *p, *limit; s = JPOOL_UTF_DATA (jcf, name_index); @@ -760,17 +758,20 @@ DEFUN(process_file, (jcf, out), jcf_parse_class (jcf); - if (written_class_count++ == 0) + if (written_class_count++ == 0 && out) fputs ("// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*-\n\n", out); - print_mangled_classname (out, jcf, "#ifndef __", jcf->this_class); - fprintf (out, "__\n"); + if (out) + { + print_mangled_classname (out, jcf, "#ifndef __", jcf->this_class); + fprintf (out, "__\n"); - print_mangled_classname (out, jcf, "#define __", jcf->this_class); - fprintf (out, "__\n\n"); + print_mangled_classname (out, jcf, "#define __", jcf->this_class); + fprintf (out, "__\n\n"); + } - if (jcf->super_class) + if (jcf->super_class && out) { int super_length; unsigned char *supername = super_class_name (jcf, &super_length); @@ -789,20 +790,23 @@ DEFUN(process_file, (jcf, out), fputs ("\n", out); } - print_class_decls (out, jcf); + if (out) + { + print_class_decls (out, jcf); - for (i = 0; i < prepend_count; ++i) - fprintf (out, "%s\n", prepend_specs[i]); - if (prepend_count > 0) - fputc ('\n', out); + for (i = 0; i < prepend_count; ++i) + fprintf (out, "%s\n", prepend_specs[i]); + if (prepend_count > 0) + fputc ('\n', out); + } - if (! print_cxx_classname (out, "class ", jcf, jcf->this_class)) + if (out && ! print_cxx_classname (out, "class ", jcf, jcf->this_class)) { fprintf (stderr, "class is of array type\n"); found_error = 1; return; } - if (jcf->super_class) + if (out && jcf->super_class) { if (! print_cxx_classname (out, " : public ", jcf, jcf->super_class)) { @@ -811,7 +815,8 @@ DEFUN(process_file, (jcf, out), return; } } - fputs ("\n{\n", out); + if (out) + fputs ("\n{\n", out); /* We make a single pass over the file, printing methods and fields as we see them. We have to list the methods in the same order @@ -835,38 +840,41 @@ DEFUN(process_file, (jcf, out), jcf_parse_final_attributes (jcf); - /* Generate friend decl if we still must. */ - for (i = 0; i < friend_count; ++i) - fprintf (out, " friend %s\n", friend_specs[i]); + if (out) + { + /* Generate friend decl if we still must. */ + for (i = 0; i < friend_count; ++i) + fprintf (out, " friend %s\n", friend_specs[i]); - /* Generate extra declarations. */ - if (add_count > 0) - fputc ('\n', out); - for (i = 0; i < add_count; ++i) - fprintf (out, " %s\n", add_specs[i]); + /* Generate extra declarations. */ + if (add_count > 0) + fputc ('\n', out); + for (i = 0; i < add_count; ++i) + fprintf (out, " %s\n", add_specs[i]); - fputs ("};\n", out); + fputs ("};\n", out); - if (append_count > 0) - fputc ('\n', out); - for (i = 0; i < append_count; ++i) - fprintf (out, "%s\n", append_specs[i]); + if (append_count > 0) + fputc ('\n', out); + for (i = 0; i < append_count; ++i) + fprintf (out, "%s\n", append_specs[i]); - print_mangled_classname (out, jcf, "\n#endif /* __", jcf->this_class); - fprintf (out, "__ */\n"); + print_mangled_classname (out, jcf, "\n#endif /* __", jcf->this_class); + fprintf (out, "__ */\n"); + } } static void usage () { - fprintf (stderr, "gjavah: no classes specified\n"); + fprintf (stderr, "gcjh: no classes specified\n"); exit (1); } static void help () { - printf ("Usage: gjavah [OPTION]... CLASS...\n\n"); + printf ("Usage: gcjh [OPTION]... CLASS...\n\n"); printf ("Generate C++ header files from .class files\n\n"); printf (" --classpath PATH Set path to find .class files\n"); printf (" -d DIRECTORY Set output directory name\n"); @@ -883,7 +891,7 @@ static void java_no_argument (opt) char *opt; { - fprintf (stderr, "gjavah: no argument given for option `%s'\n", opt); + fprintf (stderr, "gcjh: no argument given for option `%s'\n", opt); exit (1); } @@ -891,7 +899,7 @@ static void version () { /* FIXME: use version.c? */ - printf ("gjavah (GNU gcc) 0.0\n\n"); + printf ("gcjh (GNU gcc) 0.0\n\n"); printf ("Copyright (C) 1998 Free Software Foundation, Inc.\n"); printf ("This is free software; see the source for copying conditions. There is NO\n"); printf ("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"); @@ -904,6 +912,8 @@ DEFUN(main, (argc, argv), { JCF jcf; int argi; + char *output_file = NULL; + int emit_dependencies = 0, suppress_output = 0; if (argc <= 1) usage (); @@ -999,6 +1009,33 @@ DEFUN(main, (argc, argv), help (); else if (strcmp (arg, "-version") == 0) version (); + else if (strcmp (arg, "-M") == 0) + { + emit_dependencies = 1; + suppress_output = 1; + jcf_dependency_init (1); + } + else if (strcmp (arg, "-MM") == 0) + { + emit_dependencies = 1; + suppress_output = 1; + jcf_dependency_init (0); + } + else if (strcmp (arg, "-MG") == 0) + { + fprintf (stderr, "gcjh: `%s' option is unimplemented\n", argv[argi]); + exit (1); + } + else if (strcmp (arg, "-MD") == 0) + { + emit_dependencies = 1; + jcf_dependency_init (1); + } + else if (strcmp (arg, "-MMD") == 0) + { + emit_dependencies = 1; + jcf_dependency_init (0); + } else { fprintf (stderr, "%s: illegal argument\n", argv[argi]); @@ -1009,6 +1046,12 @@ DEFUN(main, (argc, argv), if (argi == argc) usage (); + if (output_file && emit_dependencies) + { + fprintf (stderr, "gcjh: can't specify both -o and -MD\n"); + exit (1); + } + if (classpath == NULL) { classpath = (char *) getenv ("CLASSPATH"); @@ -1023,6 +1066,8 @@ DEFUN(main, (argc, argv), if (verbose) fprintf (stderr, "Processing %s\n", classname); + if (! output_file) + jcf_dependency_reset (); classfile_name = find_class (classname, strlen (classname), &jcf, 1); if (classfile_name == NULL) { @@ -1036,7 +1081,9 @@ DEFUN(main, (argc, argv), if (strcmp (output_file, "-") == 0) out = stdout; else if (out == NULL) - out = fopen (output_file, "w"); + { + out = fopen (output_file, "w"); + } if (out == NULL) { perror (output_file); @@ -1059,18 +1106,38 @@ DEFUN(main, (argc, argv), ch = '/'; current_output_file[dir_len++] = ch; } - strcpy (current_output_file+dir_len, ".h"); - out = fopen (current_output_file, "w"); - if (out == NULL) + if (emit_dependencies) { - perror (current_output_file); - exit (1); + if (suppress_output) + { + jcf_dependency_set_dep_file ("-"); + out = NULL; + } + else + { + /* We use `.hd' and not `.d' to avoid clashes with + dependency tracking from straight compilation. */ + strcpy (current_output_file + dir_len, ".hd"); + jcf_dependency_set_dep_file (current_output_file); + } + } + strcpy (current_output_file + dir_len, ".h"); + jcf_dependency_set_target (current_output_file); + if (! suppress_output) + { + out = fopen (current_output_file, "w"); + if (out == NULL) + { + perror (current_output_file); + exit (1); + } } } process_file (&jcf, out); JCF_FINISH (&jcf); if (current_output_file != output_file) free (current_output_file); + jcf_dependency_write (); } if (out != NULL && out != stdout) |