d4476be259
* Makefile.in (parse.o): Depend on $(CONFIG_H) and $(srcdir)/../system.h. (class.o): Depend on $(PARSE_H) and $(srcdir)/../output.h. (jcf-parse.o): Depend on $(srcdir)/../toplev.h. (jcf-write.o): Likewise. (jv-scan.o): Depend on $(CONFIG_H) and $(srcdir)/../system.h. (mangle.o): Depend on $(srcdir)/../toplev.h. (parse-scan.o): Depend on $(CONFIG_H) and $(srcdir)/../system.h. (zextract.o): Depend on $(CONFIG_H) and $(srcdir)/../system.h. * class.c: Include output.h and parse.h. (mangled_classname): Add the `const' keyword to a char*. (find_named_method): Hide unused function definition. (build_utf8_ref): Change type of variable `c' to unsigned char. Use ISALPHA/ISDIGIT instead of isalpha/isdigit. (build_class_ref): Add the `const' keyword to a char*. (layout_class_method): Remove unused variable `buf'. * decl.c (find_local_variable): Remove unused variable `rtl'. (pushdecl): Likewise for variables `different_binding_level' and `oldglobal'. (pushlevel): Mark parameter `unused' with ATTRIBUTE_UNUSED. (maybe_build_cleanup): Likewise for parameter `decl'. * except.c (expand_start_java_handler): Mark parameter `range' with ATTRIBUTE_UNUSED. * expr.c: Include except.h. (pop_type): Remove unused variable `i'. (pop_value): Likewise for variables `n_words' and `i'. (expand_java_arrayload): Likewise for variable `convert'. (java_lang_expand_expr): Likewise for variables `op0', `type', `mode', `unsignedp', `node' and `elements'. (expand_byte_code): Likewise for variables `prev_eh_ranges' and `eh_ranges'. (process_jvm_instruction): Add a `const' qualifier to a char*. * gjavah.c (output_directory): Add the `const' keyword to a char*. (temp_directory): Likewise. (print_c_decl): Likewise. (print_method_info): Likewise. (decode_signature_piece): Likewise. (print_mangled_classname): Likewise. * java-except.h: Provide prototypes for maybe_start_try, maybe_end_try and add_handler. * java-tree.h (mangled_classname): Add the `const' keyword to a char*. (parse_error_context): Likewise. Also add ATTRIBUTE_PRINTF_2. (pushdecl_top_level, alloc_class_constant, unicode_mangling_length, init_expr_processing, push_super_field, init_class_processing, can_widen_reference_to, class_depth, verify_jvm_instructions, maybe_pushlevels, maybe_poplevels, process_jvm_instruction, set_local_type, merge_type_state, push_type, load_type_state, add_interface, find_in_current_zip, append_gpp_mangled_classtype, emit_unicode_mangled_name): Add prototypes. * jcf-dump.c (print_constant): Add the `const' keyword to a char*. (print_signature_type): Use ISDIGIT, not isdigit. (print_signature): Remove unused variable `j'. * jcf-io.c (jcf_filbuf_from_stdio): Cast the result of `fread' to int when comparing against one. * jcf-parse.c: Include toplev.h. * jcf-write.c: Likewise. Don't include <string.h> or <sys/stat.h>. (localvar_free): Remove unused variable `i'. (generate_bytecode_conditional): Likewise for variable `kind'. * jv-scan.c: Include config.h and system.h. Remove redundant OS header and gansidecl.h includes. (warning): Add the `const' keyword to a char*. Also add ATTRIBUTE_PRINTF_1 to the prototype. Check ANSI_PROTOTYPES, not __STDC__, when determining whether to use ANSI-isms. (fatal): Likewise. Also add ATTRIBUTE_UNUSED. (xmalloc): Don't redundantly prototype here. (main): Remove unused parameter `envp'. Also fix the arguments passed to function `fatal' to match the format specifier. * lang.c (java_tree_code_name): Add the `const' keyword to a char*. * mangle.c: Include toplev.h. (emit_unicode_mangled_name): Declare parameter `len'. * parse.y (parse_warning_context): Add the `const' keyword to a char*. Also add ATTRIBUTE_PRINTF_2 to the prototype. Check `ANSI_PROTOTYPES' not `__STDC__' for whether to use ANSI-isms. (issue_warning_error_from_context): Add the `const' keyword to a char*. (parse_error_context): Likewise. Also check `ANSI_PROTOTYPES' not `__STDC__' for whether to use ANSI-isms. * typeck.c (incomplete_type_error): Mark parameters `value' and `type' with ATTRIBUTE_UNUSED. (parse_signature_type): Use ISDIGIT, not isdigit. * verify.c (check_pending_block): Add the `const' keyword to a char*. (verify_jvm_instructions): Likewise. Remove unused variables `field_name' and `default_val'. * zextract.c: Include config.h and system.h. Remove redundant OS header includes. * zipfile.h: Prototype `read_zip_archive'. From-SVN: r24835
165 lines
4.3 KiB
C
165 lines
4.3 KiB
C
/* Functions related to mangling class names for the GNU compiler
|
|
for the Java(TM) language.
|
|
Copyright (C) 1998 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 "jcf.h"
|
|
#include "obstack.h"
|
|
#include "toplev.h"
|
|
|
|
/* Assuming (NAME, LEN) is a Utf8-encoding string, calculate
|
|
the length of the string as mangled (a la g++) including Unicode escapes.
|
|
If no escapes are needed, return 0. */
|
|
|
|
int
|
|
unicode_mangling_length (name, len)
|
|
char *name;
|
|
int len;
|
|
{
|
|
unsigned char *ptr;
|
|
unsigned char *limit = (unsigned char *)name + len;
|
|
int need_escapes = 0;
|
|
int num_chars = 0;
|
|
int underscores = 0;
|
|
for (ptr = (unsigned char *) name; ptr < limit; )
|
|
{
|
|
int ch = UTF8_GET(ptr, limit);
|
|
if (ch < 0)
|
|
error ("internal error - invalid Utf8 name");
|
|
if (ch >= '0' && ch <= '9')
|
|
need_escapes += num_chars == 0;
|
|
else if (ch == '_')
|
|
underscores++;
|
|
else if ((ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z'))
|
|
need_escapes++;
|
|
num_chars++;
|
|
}
|
|
if (need_escapes)
|
|
return num_chars + 4 * (need_escapes + underscores);
|
|
else
|
|
return 0;
|
|
}
|
|
|
|
/* Assuming (NAME, LEN) is a Utf8-encoding string, emit the string
|
|
appropriately mangled (with Unicode escapes) to OBSTACK. */
|
|
|
|
void
|
|
emit_unicode_mangled_name (obstack, name, len)
|
|
struct obstack *obstack;
|
|
char *name;
|
|
int len;
|
|
{
|
|
unsigned char *ptr;
|
|
unsigned char *limit = (unsigned char *)name + len;
|
|
for (ptr = (unsigned char *) name; ptr < limit; )
|
|
{
|
|
int ch = UTF8_GET(ptr, limit);
|
|
int emit_escape;
|
|
if (ch < 0)
|
|
{
|
|
error ("internal error - bad Utf8 string");
|
|
break;
|
|
}
|
|
if (ch >= '0' && ch <= '9')
|
|
emit_escape = (ptr == (unsigned char*) name);
|
|
else
|
|
emit_escape = (ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z');
|
|
if (emit_escape)
|
|
{
|
|
char buf[6];
|
|
sprintf (buf, "_%04x", ch);
|
|
obstack_grow (obstack, buf, 5);
|
|
}
|
|
else
|
|
{
|
|
obstack_1grow (obstack, ch);
|
|
}
|
|
}
|
|
}
|
|
|
|
/* Assuming (NAME, LEN) is a Utf8-encoding string, emit the string
|
|
appropriately mangled (with Unicode escapes if needed) to OBSTACK. */
|
|
|
|
void
|
|
append_gpp_mangled_name (obstack, name, len)
|
|
struct obstack *obstack;
|
|
char *name;
|
|
int len;
|
|
{
|
|
int encoded_len = unicode_mangling_length (name, len);
|
|
int needs_escapes = encoded_len > 0;
|
|
char buf[6];
|
|
if (needs_escapes)
|
|
{
|
|
sprintf (buf, "U%d", encoded_len);
|
|
obstack_grow (obstack, buf, strlen(buf));
|
|
emit_unicode_mangled_name (obstack, name, len);
|
|
}
|
|
else
|
|
{
|
|
sprintf (buf, "%d", len);
|
|
obstack_grow (obstack, buf, strlen(buf));
|
|
obstack_grow (obstack, name, len);
|
|
}
|
|
}
|
|
|
|
/* Append the mangled name of a class named CLASSNAME onto OBSTACK. */
|
|
|
|
void
|
|
append_gpp_mangled_classtype (obstack, class_name)
|
|
struct obstack *obstack;
|
|
char *class_name;
|
|
{
|
|
char *ptr;
|
|
int qualifications = 0;
|
|
|
|
for (ptr = class_name; *ptr != '\0'; ptr++)
|
|
{
|
|
if (*ptr == '.')
|
|
qualifications++;
|
|
}
|
|
if (qualifications)
|
|
{
|
|
char buf[8];
|
|
if (qualifications >= 9)
|
|
sprintf (buf, "Q_%d_", qualifications + 1);
|
|
else
|
|
sprintf (buf, "Q%d", qualifications + 1);
|
|
obstack_grow (obstack, buf, strlen (buf));
|
|
}
|
|
for (ptr = class_name; ; ptr++)
|
|
{
|
|
if (ptr[0] == '.' || ptr[0] == '\0')
|
|
{
|
|
append_gpp_mangled_name (obstack, class_name, ptr - class_name);
|
|
if (ptr[0] == '\0')
|
|
break;
|
|
class_name = ptr + 1;
|
|
}
|
|
}
|
|
}
|