8sa1-gcc/gcc/java/jvgenmain.c
Alexandre Petit-Bianco dc08e60389 All files with updated copyright when applicable.
2001-01-07  Alexandre Petit-Bianco  <apbianco@cygnus.com>

	All files with updated copyright when applicable.
	* Make-lang.in (JVGENMAIN_OBS): Removed java/mangle.o.
	* class.c (mangle_class_field): Function removed.
	(append_gpp_mangled_type, mangle_static_field, mangle_field): Likewise.
	(utf8_cmp, cxx_keyword_p): Moved to lex.c.
	(build_class_ref): Call `java_mangle_class_field' instead of
	`mangle_class_field.'
	(build_dtable_decl): Rewritten to call `java_mangle_vtable.'
	(layout_class): Call `java_mangle_decl' instead of
	`mangle_static_field.'
	(cxx_keywords): Initialized static array moved to `lex.c.'
	(layout_class_method): Changed leading comment. Simplified to
	call `java_mangle_decl.' Local `ptr' moved in for loop body.
	* decl.c (lang_mark_tree): Mark field `package_list.'
	* java-tree.h (TYPE_PACKAGE_LIST): New macro.
	(struct lang_type): New field `package_list.'
	(unicode_mangling_length): Prototype removed.
	(append_gpp_mangled_name, append_gpp_mangled_classtype,
	emit_unicode_mangled_name): Likewise.
	(cxx_keyword_p): New prototype.
	(java_mangle_decl, java_mangle_class_field,
	java_mangle_class_field_from_string, java_mangle_vtable): Likewise.
	* jcf-parse.c (jcf_parse_source): Constify `file' argument to
	`build_expr_wfl.'
	* jvgenmain.c (main_method_prefix): Global variable removed.
	(main_method_suffix): Likewise.
	(do_mangle_classname): New function.
	(main): Call it. Format changed to accomodate new mangling scheme.
	* lex.c: (utf8_cmp): Conditionally prototyped.
	(cxx_keywords): Moved from class.c, conditionally defined.
	(utf8_cmp, cxx_keyword_p): Likewise.
	* mangle.c (obstack.h, ggc.h): Included.
	(mangle_field_decl): New function.
	(mangle_method_decl, mangle_type, mangle_pointer_type,
	mangle_array_type, mangle_record_type,
	find_compression_pointer_match, find_compression_array_match,
	find_compression_record_match,
	find_compression_array_template_match, set_type_package_list,
	entry_match_pointer_p, emit_compression_string, init_mangling,
	finish_mangling, compression_table_add, mangle_member_name): Likewise.
	(mangle_obstack): New global.
	(MANGLE_RAW_STRING): New macro.
	(unicode_mangling_length): Turned static.
	(append_unicode_mangled_name): Renamed from
	`emit_unicode_mangled_name.'  Turned static. `mangle_obstack'
	replaces `obstack', removed from the parameter list.
	(append_gpp_mangled_name): Turned static. `mangle_obstack'
	replaces parameter `obstack', removed from the parameter list. Call
	`append_unicode_mangled_name' instead of `emit_unicode_mangled_name.
	(append_gpp_mangled_classtype): Removed.
	(compression_table, compression_next): New static variables.
	* parse.y (temporary_obstack): Extern declaration removed.

(This is the new C++ ABI compatibility patch:
  http://gcc.gnu.org/ml/gcc-patches/2001-01/msg01225.html)

From-SVN: r39031
2001-01-15 00:01:22 -08:00

204 lines
4.9 KiB
C

/* Program to generate "main" a Java(TM) class containing a main method.
Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU CC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Java and all Java-based marks are trademarks or registered trademarks
of Sun Microsystems, Inc. in the United States and other countries.
The Free Software Foundation is independent of Sun Microsystems, Inc. */
/* Written by Per Bothner <bothner@cygnus.com> */
#include "config.h"
#include "system.h"
#include "obstack.h"
#include "gansidecl.h"
#include "jcf.h"
#include "tree.h"
#include "java-tree.h"
static char * do_mangle_classname PARAMS ((const char *string));
const char class_mangling_suffix[] = "class$";
struct obstack name_obstack;
extern void error PARAMS ((const char *, ...))
ATTRIBUTE_PRINTF_1;
void
error VPARAMS ((const char *msgid, ...))
{
#ifndef ANSI_PROTOTYPES
const char *msgid;
#endif
va_list ap;
VA_START (ap, msgid);
#ifndef ANSI_PROTOTYPES
msgid = va_arg (ap, const char *);
#endif
vfprintf (stderr, msgid, ap);
va_end (ap);
}
void
gcc_obstack_init (obstack)
struct obstack *obstack;
{
/* Let particular systems override the size of a chunk. */
#ifndef OBSTACK_CHUNK_SIZE
#define OBSTACK_CHUNK_SIZE 0
#endif
/* Let them override the alloc and free routines too. */
#ifndef OBSTACK_CHUNK_ALLOC
#define OBSTACK_CHUNK_ALLOC xmalloc
#endif
#ifndef OBSTACK_CHUNK_FREE
#define OBSTACK_CHUNK_FREE free
#endif
_obstack_begin (obstack, OBSTACK_CHUNK_SIZE, 0,
(void *(*) PARAMS ((long))) OBSTACK_CHUNK_ALLOC,
(void (*) PARAMS ((void *))) OBSTACK_CHUNK_FREE);
}
static void usage (const char *) ATTRIBUTE_NORETURN;
static void
usage (const char *name)
{
fprintf (stderr, "Usage: %s [OPTIONS]... CLASSNAME [OUTFILE]\n", name);
exit (1);
}
int
main (int argc, const char **argv)
{
const char *classname;
FILE *stream;
const char *mangled_classname;
int i, last_arg;
if (argc < 2)
usage (argv[0]);
for (i = 1; i < argc; ++i)
{
if (! strncmp (argv[i], "-D", 2))
{
/* Handled later. */
}
else
break;
}
if (i < argc - 2 || i == argc)
usage (argv[0]);
last_arg = i;
classname = argv[i];
gcc_obstack_init (&name_obstack);
mangled_classname = do_mangle_classname (classname);
if (i < argc - 1 && strcmp (argv[i + 1], "-") != 0)
{
const char *outfile = argv[i + 1];
stream = fopen (outfile, "w");
if (stream == NULL)
{
fprintf (stderr, "%s: Cannot open output file: %s\n",
argv[0], outfile);
exit (1);
}
}
else
stream = stdout;
/* At this point every element of ARGV from 1 to LAST_ARG is a `-D'
option. Process them appropriately. */
fprintf (stream, "extern const char **_Jv_Compiler_Properties;\n");
fprintf (stream, "static const char *props[] =\n{\n");
for (i = 1; i < last_arg; ++i)
{
const char *p;
fprintf (stream, " \"");
for (p = &argv[i][2]; *p; ++p)
{
if (! ISPRINT (*p))
fprintf (stream, "\\%o", *p);
else if (*p == '\\' || *p == '"')
fprintf (stream, "\\%c", *p);
else
putc (*p, stream);
}
fprintf (stream, "\",\n");
}
fprintf (stream, " 0\n};\n\n");
fprintf (stream, "extern int class __attribute__ ((alias (\"%s\")));\n",
mangled_classname);
fprintf (stream, "int main (int argc, const char **argv)\n");
fprintf (stream, "{\n");
fprintf (stream, " _Jv_Compiler_Properties = props;\n");
fprintf (stream, " JvRunMain (&class, argc, argv);\n");
fprintf (stream, "}\n");
if (stream != stdout && fclose (stream) != 0)
{
fprintf (stderr, "%s: Failed to close output file %s\n",
argv[0], argv[2]);
exit (1);
}
return 0;
}
static char *
do_mangle_classname (string)
const char *string;
{
char *ptr;
int count = 0;
#define MANGLE_NAME() \
{ \
char buffer [128]; \
sprintf (buffer, "%d", count); \
obstack_grow (&name_obstack, buffer, strlen (buffer)); \
obstack_grow (&name_obstack, & ptr [-count], count); \
count = 0; \
}
obstack_grow (&name_obstack, "_ZN", 3);
for (ptr = (char *)string; *ptr; ptr++ )
{
if (ptr[0] == '.')
{
MANGLE_NAME ();
}
else
count++;
}
MANGLE_NAME ();
obstack_grow0 (&name_obstack, "6class$E", 8);
return obstack_finish (&name_obstack);
}