
PR c/7652 gcc/ * alias.c (find_base_value): Adjust fall through comment. * cfgexpand.c (expand_debug_expr): Likewise. * combine.c (find_split_point): Likewise. (expand_compound_operation): Likewise. Add FALLTHRU. (make_compound_operation): Adjust fall through comment. (canon_reg_for_combine): Add FALLTHRU. (force_to_mode): Adjust fall through comment. (simplify_shift_const_1): Likewise. (simplify_comparison): Likewise. * config/aarch64/aarch64-builtins.c (aarch64_simd_expand_args): Add FALLTHRU. * config/aarch64/predicates.md: Likewise. * config/i386/i386.c (function_arg_advance_32): Likewise. (ix86_gimplify_va_arg): Likewise. (print_reg): Likewise. (ix86_print_operand): Likewise. (ix86_build_const_vector): Likewise. (ix86_expand_branch): Likewise. (ix86_sched_init_global): Adjust fall through comment. (ix86_expand_args_builtin): Add FALLTHRU. (ix86_expand_builtin): Likewise. (ix86_expand_vector_init_one_var): Likewise. * config/rs6000/rs6000.c (rs6000_emit_vector_compare_inner): Likewise. (rs6000_adjust_cost): Likewise. (insn_must_be_first_in_group): Likewise. * config/rs6000/rs6000.md: Likewise. Adjust fall through comment. * dbxout.c (dbxout_symbol): Adjust fall through comment. * df-scan.c (df_uses_record): Likewise. * dojump.c (do_jump): Add FALLTHRU. * dwarf2out.c (mem_loc_descriptor): Likewise. Adjust fall through comment. (resolve_args_picking_1): Adjust fall through comment. (loc_list_from_tree_1): Likewise. * expmed.c (make_tree): Likewise. * expr.c (expand_expr_real_2): Add FALLTHRU. (expand_expr_real_1): Likewise. Adjust fall through comment. * fold-const.c (const_binop): Adjust fall through comment. (fold_truth_not_expr): Likewise. (fold_cond_expr_with_comparison): Add FALLTHRU. (fold_binary_loc): Likewise. (contains_label_1): Adjust fall through comment. (multiple_of_p): Likewise. * gcov-tool.c (process_args): Add FALLTHRU. * genattrtab.c (check_attr_test): Likewise. (write_test_expr): Likewise. * genconfig.c (walk_insn_part): Likewise. * genpreds.c (validate_exp): Adjust fall through comment. (needs_variable): Likewise. * gensupport.c (get_alternatives_number): Add FALLTHRU. (subst_dup): Likewise. * gimple-pretty-print.c (dump_gimple_assign): Likewise. * gimplify.c (gimplify_addr_expr): Adjust fall through comment. (gimplify_scan_omp_clauses): Add FALLTHRU. (goa_stabilize_expr): Likewise. * graphite-isl-ast-to-gimple.c (substitute_ssa_name): Adjust fall through comment. * hsa-gen.c (get_address_from_value): Likewise. * ipa-icf.c (sem_function::hash_stmt): Likewise. * ira.c (ira_setup_alts): Add FALLTHRU. * lra-eliminations.c (lra_eliminate_regs_1): Adjust fall through comment. * lto-streamer-out.c (lto_output_tree_ref): Add FALLTHRU. * opts.c (common_handle_option): Likewise. * read-rtl.c (read_rtx_code): Likewise. * real.c (round_for_format): Likewise. * recog.c (asm_operand_ok): Likewise. * reginfo.c (reg_scan_mark_refs): Adjust fall through comment. * reload1.c (set_label_offsets): Likewise. (eliminate_regs_1): Likewise. (reload_reg_reaches_end_p): Likewise. * rtlanal.c (commutative_operand_precedence): Add FALLTHRU. (rtx_cost): Likewise. * sched-rgn.c (is_exception_free): Likewise. * simplify-rtx.c (simplify_rtx): Adjust fall through comment. * stor-layout.c (int_mode_for_mode): Likewise. * toplev.c (print_to_asm_out_file): Likewise. (print_to_stderr): Likewise. * tree-cfg.c (gimple_verify_flow_info): Likewise. * tree-chrec.c (chrec_fold_plus_1): Add FALLTHRU. (chrec_fold_multiply): Likewise. (evolution_function_is_invariant_rec_p): Likewise. (for_each_scev_op): Likewise. * tree-data-ref.c (siv_subscript_p): Likewise. (get_references_in_stmt): Likewise. * tree.c (find_placeholder_in_expr): Adjust fall through comment. (substitute_in_expr): Likewise. (type_cache_hasher::equal): Likewise. (walk_type_fields): Likewise. * var-tracking.c (adjust_mems): Add FALLTHRU. (set_dv_changed): Adjust fall through comment. * varasm.c (default_function_section): Add FALLTHRU. gcc/c-family/ * c-common.c (scalar_to_vector): Adjust fall through comment. * c-opts.c (c_common_handle_option): Likewise. * c-pragma.c (handle_pragma_pack): Add FALLTHRU. * c-pretty-print.c (c_pretty_printer::postfix_expression): Adjust fall through comment. * cilk.c (extract_free_variables): Add FALLTHRU. gcc/c/ * c-parser.c (c_parser_external_declaration): Add FALLTHRU. (c_parser_postfix_expression): Likewise. * c-typeck.c (build_unary_op): Adjust fall through comment. (c_mark_addressable): Likewise. gcc/cp/ * call.c (add_builtin_candidate): Add FALLTHRU. (build_integral_nontype_arg_conv): Adjust fall through comment. (build_new_op_1): Add FALLTHRU. (convert_like_real): Adjust fall through comment. * class.c (fixed_type_or_null): Likewise. * constexpr.c (cxx_eval_constant_expression): Likewise. (potential_constant_expression_1): Likewise. Add FALLTHRU. * cp-gimplify.c (cp_gimplify_expr): Adjust fall through comment. (cp_fold): Add FALLTHRU. * cvt.c (build_expr_type_conversion): Adjust fall through comment. * cxx-pretty-print.c (pp_cxx_unqualified_id): Add FALLTHRU. (pp_cxx_qualified_id): Likewise. (cxx_pretty_printer::constant): Adjust fall through comment. (cxx_pretty_printer::primary_expression): Add FALLTHRU. (pp_cxx_pm_expression): Adjust fall through comment. (cxx_pretty_printer::expression): Add FALLTHRU. (cxx_pretty_printer::declaration_specifiers): Reformat code. (pp_cxx_type_specifier_seq): Adjust fall through comment. (pp_cxx_ptr_operator): Likewise. Add FALLTHRU. * error.c (dump_type): Adjust fall through comment. (dump_decl): Likewise. * mangle.c (write_type): Likewise. * method.c (synthesized_method_walk): Add FALLTHRU. * name-lookup.c (arg_assoc_type): Likewise. * parser.c (cp_lexer_print_token): Adjust fall through comment. (cp_parser_primary_expression): Add FALLTHRU. (cp_parser_operator): Likewise. * pt.c (find_parameter_packs_r): Likewise. (tsubst_aggr_type): Adjust fall through comment. * semantics.c (finish_omp_clauses): Add FALLTHRU. * tree.c (lvalue_kind): Likewise. gcc/fortran/ * decl.c (match_attr_spec): Add FALLTHRU. * primary.c (match_arg_list_function): Likewise. * resolve.c (resolve_operator): Adjust fall through comment. (fixup_charlen): Add FALLTHRU. (resolve_allocate_expr): Adjust fall through comment. * trans-array.c (gfc_conv_ss_startstride): Add FALLTHRU. * trans-intrinsic.c (gfc_conv_intrinsic_len): Adjust fall through comment. gcc/java/ * expr.c (java_truthvalue_conversion): Adjust fall through comment. * jcf-io.c (verify_constant_pool): Likewise. * typeck.c (promote_type): Likewise. gcc/objc/ * objc-encoding.c (encode_type): Add FALLTHRU. libcpp/ * lex.c (search_line_fast): Add FALLTHRU. (_cpp_lex_direct): Likewise. (cpp_token_val_index): Adjust fall through comment. * macro.c (parse_params): Add FALLTHRU. * pch.c (count_defs): Adjust fall through comment. (write_defs): Likewise. libiberty/ * cp-demangle.c (d_print_mod): Add FALLTHRU. From-SVN: r239410
566 lines
14 KiB
C
566 lines
14 KiB
C
/* Utility routines for finding and reading Java(TM) .class files.
|
|
Copyright (C) 1996-2016 Free Software Foundation, Inc.
|
|
|
|
This file is part of GCC.
|
|
|
|
GCC 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 3, or (at your option)
|
|
any later version.
|
|
|
|
GCC 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 GCC; see the file COPYING3. If not see
|
|
<http://www.gnu.org/licenses/>.
|
|
|
|
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>, February 1996. */
|
|
|
|
#include "config.h"
|
|
#include "system.h"
|
|
#include "coretypes.h"
|
|
|
|
#include "jcf.h"
|
|
#include <dirent.h>
|
|
|
|
#include "zlib.h"
|
|
|
|
int
|
|
jcf_unexpected_eof (JCF *jcf, int count ATTRIBUTE_UNUSED)
|
|
{
|
|
if (jcf->filename)
|
|
fprintf (stderr, "Premature end of .class file %s.\n", jcf->filename);
|
|
else
|
|
fprintf (stderr, "Premature end of .class file <stdin>.\n");
|
|
exit (-1);
|
|
}
|
|
|
|
void
|
|
jcf_trim_old_input (JCF *jcf)
|
|
{
|
|
int count = jcf->read_ptr - jcf->buffer;
|
|
if (count > 0)
|
|
{
|
|
memmove (jcf->buffer, jcf->read_ptr, jcf->read_end - jcf->read_ptr);
|
|
jcf->read_ptr -= count;
|
|
jcf->read_end -= count;
|
|
}
|
|
}
|
|
|
|
int
|
|
jcf_filbuf_from_stdio (JCF *jcf, int count)
|
|
{
|
|
FILE *file = (FILE*) (jcf->read_state);
|
|
if (count > jcf->buffer_end - jcf->read_ptr)
|
|
{
|
|
JCF_u4 old_read_ptr = jcf->read_ptr - jcf->buffer;
|
|
JCF_u4 old_read_end = jcf->read_end - jcf->buffer;
|
|
JCF_u4 old_size = jcf->buffer_end - jcf->buffer;
|
|
JCF_u4 new_size = (old_size == 0 ? 2000 : 2 * old_size) + count;
|
|
unsigned char *new_buffer
|
|
= jcf->buffer == NULL ? XNEWVAR (unsigned char, new_size)
|
|
: XRESIZEVAR (unsigned char, jcf->buffer, new_size);
|
|
jcf->buffer = new_buffer;
|
|
jcf->buffer_end = new_buffer + new_size;
|
|
jcf->read_ptr = new_buffer + old_read_ptr;
|
|
jcf->read_end = new_buffer + old_read_end;
|
|
}
|
|
count -= jcf->read_end - jcf->read_ptr;
|
|
if (count <= 0)
|
|
return 0;
|
|
if ((int) fread (jcf->read_end, 1, count, file) != count)
|
|
jcf_unexpected_eof (jcf, count);
|
|
jcf->read_end += count;
|
|
return 0;
|
|
}
|
|
|
|
#include "zipfile.h"
|
|
|
|
struct ZipFile *SeenZipFiles = NULL;
|
|
|
|
/* Open a zip file with the given name, and cache directory and file
|
|
descriptor. If the file is missing, treat it as an empty archive.
|
|
Return NULL if the .zip file is malformed.
|
|
*/
|
|
|
|
ZipFile *
|
|
opendir_in_zip (const char *zipfile, int is_system)
|
|
{
|
|
struct ZipFile* zipf;
|
|
char magic [4];
|
|
int fd;
|
|
for (zipf = SeenZipFiles; zipf != NULL; zipf = zipf->next)
|
|
{
|
|
if (strcmp (zipf->name, zipfile) == 0)
|
|
return zipf;
|
|
}
|
|
|
|
zipf = XNEWVAR (struct ZipFile, sizeof (struct ZipFile) + strlen (zipfile) + 1);
|
|
zipf->next = SeenZipFiles;
|
|
zipf->name = (char*)(zipf+1);
|
|
strcpy (zipf->name, zipfile);
|
|
fd = open (zipfile, O_RDONLY | O_BINARY);
|
|
zipf->fd = fd;
|
|
if (fd < 0)
|
|
{
|
|
/* A missing zip file is not considered an error.
|
|
We may want to re-consider that. FIXME. */
|
|
zipf->count = 0;
|
|
zipf->dir_size = 0;
|
|
zipf->central_directory = NULL;
|
|
}
|
|
else
|
|
{
|
|
jcf_dependency_add_file (zipfile, is_system);
|
|
if (read (fd, magic, 4) != 4 || GET_u4 (magic) != (JCF_u4)ZIPMAGIC)
|
|
{
|
|
free (zipf);
|
|
close (fd);
|
|
return NULL;
|
|
}
|
|
lseek (fd, 0L, SEEK_SET);
|
|
if (read_zip_archive (zipf) != 0)
|
|
{
|
|
free (zipf);
|
|
close (fd);
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
SeenZipFiles = zipf;
|
|
return zipf;
|
|
}
|
|
|
|
/* Returns:
|
|
0: OK - zipmember found.
|
|
-1: Not found.
|
|
-2: Malformed archive.
|
|
*/
|
|
|
|
int
|
|
open_in_zip (JCF *jcf, const char *zipfile, const char *zipmember,
|
|
int is_system)
|
|
{
|
|
ZipDirectory *zipd;
|
|
int i, len;
|
|
ZipFile *zipf = opendir_in_zip (zipfile, is_system);
|
|
|
|
if (zipf == NULL)
|
|
return -2;
|
|
|
|
if (!zipmember)
|
|
return 0;
|
|
|
|
len = strlen (zipmember);
|
|
|
|
zipd = (struct ZipDirectory*) zipf->central_directory;
|
|
for (i = 0; i < zipf->count; i++, zipd = ZIPDIR_NEXT (zipd))
|
|
{
|
|
if (len == zipd->filename_length &&
|
|
strncmp (ZIPDIR_FILENAME (zipd), zipmember, len) == 0)
|
|
{
|
|
JCF_ZERO (jcf);
|
|
|
|
jcf->filename = xstrdup (zipfile);
|
|
jcf->classname = xstrdup (zipmember);
|
|
return read_zip_member(jcf, zipd, zipf);
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
/* Read data from zip archive member. */
|
|
|
|
int
|
|
read_zip_member (JCF *jcf, ZipDirectory *zipd, ZipFile *zipf)
|
|
{
|
|
jcf->filbuf = jcf_unexpected_eof;
|
|
jcf->zipd = zipd;
|
|
|
|
if (zipd->compression_method == Z_NO_COMPRESSION)
|
|
{
|
|
jcf->buffer = XNEWVEC (unsigned char, zipd->size);
|
|
jcf->buffer_end = jcf->buffer + zipd->size;
|
|
jcf->read_ptr = jcf->buffer;
|
|
jcf->read_end = jcf->buffer_end;
|
|
if (lseek (zipf->fd, zipd->filestart, 0) < 0
|
|
|| read (zipf->fd, jcf->buffer, zipd->size) != (long) zipd->size)
|
|
return -2;
|
|
}
|
|
else
|
|
{
|
|
char *buffer;
|
|
z_stream d_stream; /* decompression stream */
|
|
memset (&d_stream, 0, sizeof (d_stream));
|
|
|
|
jcf->buffer = XNEWVEC (unsigned char, zipd->uncompressed_size);
|
|
d_stream.next_out = jcf->buffer;
|
|
d_stream.avail_out = zipd->uncompressed_size;
|
|
jcf->buffer_end = jcf->buffer + zipd->uncompressed_size;
|
|
jcf->read_ptr = jcf->buffer;
|
|
jcf->read_end = jcf->buffer_end;
|
|
buffer = XNEWVEC (char, zipd->size);
|
|
d_stream.next_in = (unsigned char *) buffer;
|
|
d_stream.avail_in = zipd->size;
|
|
if (lseek (zipf->fd, zipd->filestart, 0) < 0
|
|
|| read (zipf->fd, buffer, zipd->size) != (long) zipd->size)
|
|
return -2;
|
|
/* Handle NO_HEADER using undocumented zlib feature.
|
|
This is a very common hack. */
|
|
inflateInit2 (&d_stream, -MAX_WBITS);
|
|
inflate (&d_stream, Z_NO_FLUSH);
|
|
inflateEnd (&d_stream);
|
|
free (buffer);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
const char *
|
|
open_class (const char *filename, JCF *jcf, int fd, const char *dep_name)
|
|
{
|
|
if (jcf)
|
|
{
|
|
struct stat stat_buf;
|
|
if (fstat (fd, &stat_buf) != 0
|
|
|| ! S_ISREG (stat_buf.st_mode))
|
|
{
|
|
perror ("Could not figure length of .class file");
|
|
return NULL;
|
|
}
|
|
if (dep_name != NULL)
|
|
jcf_dependency_add_file (dep_name, 0);
|
|
JCF_ZERO (jcf);
|
|
jcf->buffer = XNEWVEC (unsigned char, stat_buf.st_size);
|
|
jcf->buffer_end = jcf->buffer + stat_buf.st_size;
|
|
jcf->read_ptr = jcf->buffer;
|
|
jcf->read_end = jcf->buffer_end;
|
|
jcf->read_state = NULL;
|
|
jcf->filename = xstrdup (filename);
|
|
if (read (fd, jcf->buffer, stat_buf.st_size) != stat_buf.st_size)
|
|
{
|
|
perror ("Failed to read .class file");
|
|
return NULL;
|
|
}
|
|
close (fd);
|
|
jcf->filbuf = jcf_unexpected_eof;
|
|
}
|
|
else
|
|
close (fd);
|
|
return filename;
|
|
}
|
|
|
|
|
|
const char *
|
|
find_classfile (char *filename, JCF *jcf, const char *dep_name)
|
|
{
|
|
int fd = open (filename, O_RDONLY | O_BINARY);
|
|
if (fd < 0)
|
|
return NULL;
|
|
return open_class (filename, jcf, fd, dep_name);
|
|
}
|
|
|
|
/* A hash table keeping track of class names that were not found
|
|
during class lookup. (There is no need to cache the values
|
|
associated with names that were found; they are saved in
|
|
IDENTIFIER_CLASS_VALUE.) */
|
|
static hash_table<nofree_string_hash> *memoized_class_lookups;
|
|
|
|
/* Returns a freshly malloc'd string with the fully qualified pathname
|
|
of the .class file for the class CLASSNAME. CLASSNAME must be
|
|
allocated in permanent storage; this function may retain a pointer
|
|
to it. Returns NULL on failure. If JCF != NULL, it is suitably
|
|
initialized. SOURCE_OK is true if we should also look for .java
|
|
file. */
|
|
|
|
const char *
|
|
find_class (const char *classname, int classname_length, JCF *jcf)
|
|
{
|
|
int fd;
|
|
int i, k, klass = -1;
|
|
struct stat class_buf;
|
|
char *dep_file;
|
|
void *entry;
|
|
int buflen;
|
|
char *buffer;
|
|
hashval_t hash;
|
|
|
|
/* Create the hash table, if it does not already exist. */
|
|
if (!memoized_class_lookups)
|
|
memoized_class_lookups = new hash_table<nofree_string_hash> (37);
|
|
|
|
/* Loop for this class in the hashtable. If it is present, we've
|
|
already looked for this class and failed to find it. */
|
|
hash = nofree_string_hash::hash (classname);
|
|
if (memoized_class_lookups->find_with_hash (classname, hash))
|
|
return NULL;
|
|
|
|
/* Allocate and zero out the buffer, since we don't explicitly put a
|
|
null pointer when we're copying it below. */
|
|
buflen = jcf_path_max_len () + classname_length + 10;
|
|
buffer = XNEWVAR (char, buflen);
|
|
memset (buffer, 0, buflen);
|
|
|
|
for (entry = jcf_path_start (); entry != NULL; entry = jcf_path_next (entry))
|
|
{
|
|
const char *path_name = jcf_path_name (entry);
|
|
if (klass != 0)
|
|
{
|
|
int dir_len;
|
|
|
|
strcpy (buffer, path_name);
|
|
i = strlen (buffer);
|
|
|
|
/* This is right because we know that `.zip' entries will have a
|
|
trailing slash. See jcf-path.c. */
|
|
dir_len = i - 1;
|
|
|
|
for (k = 0; k < classname_length; k++, i++)
|
|
{
|
|
char ch = classname[k];
|
|
buffer[i] = ch == '.' ? '/' : ch;
|
|
}
|
|
strcpy (buffer+i, ".class");
|
|
|
|
if (jcf_path_is_zipfile (entry))
|
|
{
|
|
int err_code;
|
|
JCF _jcf;
|
|
buffer[dir_len] = '\0';
|
|
SOURCE_FRONTEND_DEBUG
|
|
(("Trying [...%s]:%s",
|
|
&buffer[dir_len-(dir_len > 15 ? 15 : dir_len)],
|
|
buffer+dir_len+1));
|
|
if (jcf == NULL)
|
|
jcf = &_jcf;
|
|
err_code = open_in_zip (jcf, buffer, buffer+dir_len+1,
|
|
jcf_path_is_system (entry));
|
|
if (err_code == 0)
|
|
{
|
|
/* Should we check if .zip is out-of-date wrt .java? */
|
|
buffer[dir_len] = '(';
|
|
strcpy (buffer+i, ".class)");
|
|
if (jcf == &_jcf)
|
|
JCF_FINISH (jcf);
|
|
return buffer;
|
|
}
|
|
else
|
|
continue;
|
|
}
|
|
klass = stat (buffer, &class_buf);
|
|
}
|
|
}
|
|
|
|
dep_file = buffer;
|
|
if (!klass)
|
|
{
|
|
SOURCE_FRONTEND_DEBUG ((stderr, "[Class selected: %s]\n",
|
|
classname+classname_length-
|
|
(classname_length <= 30 ?
|
|
classname_length : 30)));
|
|
fd = JCF_OPEN_EXACT_CASE (buffer, O_RDONLY | O_BINARY);
|
|
if (fd >= 0)
|
|
goto found;
|
|
}
|
|
|
|
free (buffer);
|
|
|
|
/* Remember that this class could not be found so that we do not
|
|
have to look again. */
|
|
*memoized_class_lookups->find_slot_with_hash (classname, hash, INSERT)
|
|
= classname;
|
|
|
|
return NULL;
|
|
found:
|
|
{
|
|
const char *const tmp = open_class (buffer, jcf, fd, dep_file);
|
|
jcf->classname = xstrdup (classname);
|
|
return tmp;
|
|
}
|
|
}
|
|
|
|
void
|
|
jcf_print_char (FILE *stream, int ch)
|
|
{
|
|
switch (ch)
|
|
{
|
|
case '\'':
|
|
case '\\':
|
|
case '\"':
|
|
fprintf (stream, "\\%c", ch);
|
|
break;
|
|
case '\n':
|
|
fprintf (stream, "\\n");
|
|
break;
|
|
case '\t':
|
|
fprintf (stream, "\\t");
|
|
break;
|
|
case '\r':
|
|
fprintf (stream, "\\r");
|
|
break;
|
|
default:
|
|
if (ch >= ' ' && ch < 127)
|
|
putc (ch, stream);
|
|
else if (ch < 256)
|
|
fprintf (stream, "\\%03x", ch);
|
|
else
|
|
fprintf (stream, "\\u%04x", ch);
|
|
}
|
|
}
|
|
|
|
/* Print UTF8 string at STR of length LENGTH bytes to STREAM. */
|
|
|
|
void
|
|
jcf_print_utf8 (FILE *stream, const unsigned char *str, int length)
|
|
{
|
|
const unsigned char * limit = str + length;
|
|
while (str < limit)
|
|
{
|
|
int ch = UTF8_GET (str, limit);
|
|
if (ch < 0)
|
|
{
|
|
fprintf (stream, "\\<invalid>");
|
|
return;
|
|
}
|
|
jcf_print_char (stream, ch);
|
|
}
|
|
}
|
|
|
|
/* Same as jcf_print_utf8, but print IN_CHAR as OUT_CHAR. */
|
|
|
|
void
|
|
jcf_print_utf8_replace (FILE *stream, const unsigned char *str, int length,
|
|
int in_char, int out_char)
|
|
{
|
|
const unsigned char *limit = str + length;
|
|
while (str < limit)
|
|
{
|
|
int ch = UTF8_GET (str, limit);
|
|
if (ch < 0)
|
|
{
|
|
fprintf (stream, "\\<invalid>");
|
|
return;
|
|
}
|
|
jcf_print_char (stream, ch == in_char ? out_char : ch);
|
|
}
|
|
}
|
|
|
|
/* Check that all the cross-references in the constant pool are
|
|
valid. Returns 0 on success.
|
|
Otherwise, returns the index of the (first) invalid entry.
|
|
Only checks internal consistency, but does not check that
|
|
any classes, fields, or methods are valid.*/
|
|
|
|
int
|
|
verify_constant_pool (JCF *jcf)
|
|
{
|
|
int i, n;
|
|
for (i = 1; i < JPOOL_SIZE (jcf); i++)
|
|
{
|
|
switch (JPOOL_TAG (jcf, i))
|
|
{
|
|
case CONSTANT_NameAndType:
|
|
n = JPOOL_USHORT2 (jcf, i);
|
|
if (n <= 0 || n >= JPOOL_SIZE(jcf)
|
|
|| JPOOL_TAG (jcf, n) != CONSTANT_Utf8)
|
|
return i;
|
|
/* fall through */
|
|
case CONSTANT_Class:
|
|
case CONSTANT_String:
|
|
n = JPOOL_USHORT1 (jcf, i);
|
|
if (n <= 0 || n >= JPOOL_SIZE(jcf)
|
|
|| JPOOL_TAG (jcf, n) != CONSTANT_Utf8)
|
|
return i;
|
|
break;
|
|
case CONSTANT_Fieldref:
|
|
case CONSTANT_Methodref:
|
|
case CONSTANT_InterfaceMethodref:
|
|
n = JPOOL_USHORT1 (jcf, i);
|
|
if (n <= 0 || n >= JPOOL_SIZE(jcf)
|
|
|| JPOOL_TAG (jcf, n) != CONSTANT_Class)
|
|
return i;
|
|
n = JPOOL_USHORT2 (jcf, i);
|
|
if (n <= 0 || n >= JPOOL_SIZE(jcf)
|
|
|| JPOOL_TAG (jcf, n) != CONSTANT_NameAndType)
|
|
return i;
|
|
break;
|
|
case CONSTANT_Long:
|
|
case CONSTANT_Double:
|
|
i++;
|
|
break;
|
|
case CONSTANT_Float:
|
|
case CONSTANT_Integer:
|
|
case CONSTANT_Utf8:
|
|
case CONSTANT_Unicode:
|
|
break;
|
|
case CONSTANT_MethodHandle:
|
|
n = JPOOL_USHORT1 (jcf, i);
|
|
if (n < 1 || n > 9)
|
|
return i;
|
|
n = JPOOL_USHORT2 (jcf, i);
|
|
if (n <= 0 || n >= JPOOL_SIZE(jcf))
|
|
return i;
|
|
break;
|
|
case CONSTANT_MethodType:
|
|
n = JPOOL_USHORT1 (jcf, i);
|
|
if (n <= 0 || n >= JPOOL_SIZE(jcf)
|
|
|| JPOOL_TAG (jcf, n) != CONSTANT_Utf8)
|
|
return i;
|
|
break;
|
|
case CONSTANT_InvokeDynamic:
|
|
n = JPOOL_USHORT2 (jcf, i);
|
|
if (n <= 0 || n >= JPOOL_SIZE(jcf)
|
|
|| JPOOL_TAG (jcf, n) != CONSTANT_NameAndType)
|
|
return i;
|
|
break;
|
|
default:
|
|
return i;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
void
|
|
format_uint (char *buffer, uint64 value, int base)
|
|
{
|
|
#define WRITE_BUF_SIZE (4 + sizeof(uint64) * 8)
|
|
char buf[WRITE_BUF_SIZE];
|
|
char *buf_ptr = buf+WRITE_BUF_SIZE; /* End of buf. */
|
|
int chars_written;
|
|
int i;
|
|
|
|
/* Now do the actual conversion, placing the result at the *end* of buf. */
|
|
/* Note this code does not pretend to be optimized. */
|
|
do {
|
|
int digit = value % base;
|
|
static const char digit_chars[] = "0123456789abcdefghijklmnopqrstuvwxyz";
|
|
*--buf_ptr = digit_chars[digit];
|
|
value /= base;
|
|
} while (value != 0);
|
|
|
|
chars_written = buf+WRITE_BUF_SIZE - buf_ptr;
|
|
for (i = 0; i < chars_written; i++)
|
|
buffer[i] = *buf_ptr++;
|
|
buffer[i] = 0;
|
|
}
|
|
|
|
void
|
|
format_int (char *buffer, jlong value, int base)
|
|
{
|
|
uint64 abs_value;
|
|
if (value < 0)
|
|
{
|
|
abs_value = -(uint64)value;
|
|
*buffer++ = '-';
|
|
}
|
|
else
|
|
abs_value = (uint64) value;
|
|
format_uint (buffer, abs_value, base);
|
|
}
|