dae4174e53
libcpp * include/symtab.h (HT_ALLOCED): Remove. (ht_purge): Declare. * symtab.c (DELETED): New define. (ht_lookup): Update comment. (ht_lookup_with_hash): Handle deleted entries. Remove HT_ALLOCED code. Use subobject allocator for strings, if it exists. (ht_expand): Handle deleted entries. (ht_forall): Likewise. (ht_purge): New function. (ht_dump_statistics): Print deletion statistics. gcc * ggc-zone.c (lookup_page_table_if_allocated): New function. (zone_find_object_offset): Likewise. (gt_ggc_m_S): Likewise. (highest_bit): Likewise. * ggc-page.c (gt_ggc_m_S): New function. * stringpool.c (string_stack): Remove. (init_stringpool): Update. (ggc_alloc_string): Use ggc_alloc. (maybe_delete_ident): New function. (ggc_purge_stringpool): Likewise. (gt_ggc_m_S): Remove. * ggc-common.c (ggc_protect_identifiers): New global. (ggc_mark_roots): Call ggc_purge_stringpool. Use ggc_protect_identifiers. * ggc.h (ggc_protect_identifiers): Declare. (gt_ggc_m_S): Update. (ggc_purge_stringpool): Declare. * toplev.c (compile_file): Set and reset ggc_protect_identifiers. * gengtype.c (write_types_process_field) <TYPE_STRING>: Remove special case. (write_root): Cast gt_ggc_m_S to gt_pointer_walker. gcc/cp * mangle.c (save_partially_mangled_name): Remove. (restore_partially_mangled_name): Likewise. (write_encoding): Update. (write_unqualified_name): Likewise. (start_mangling): Always use name_obstack. Remove 'ident_p' argument. (get_identifier_nocopy): Remove. (finish_mangling_internal): Rename from finish_mangling. (finish_mangling): New function. (finish_mangling_get_identifier): Likewise. (partially_mangled_name, partially_mangled_name_len): Remove. (mangle_decl_string): Change return type. Update. (mangle_decl, mangle_type_string, mangle_special_for_type, mangle_ctor_vtbl_for_type, mangle_thunk, mangle_guard_variable, mangle_ref_init_variable): Update. From-SVN: r135720
103 lines
3.4 KiB
C
103 lines
3.4 KiB
C
/* Hash tables.
|
|
Copyright (C) 2000, 2001, 2003, 2004, 2007, 2008 Free Software Foundation, Inc.
|
|
|
|
This program 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.
|
|
|
|
This program 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 this program; if not, write to the Free Software
|
|
Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
|
|
|
|
#ifndef LIBCPP_SYMTAB_H
|
|
#define LIBCPP_SYMTAB_H
|
|
|
|
#include "obstack.h"
|
|
#ifndef GTY
|
|
#define GTY(x) /* nothing */
|
|
#endif
|
|
|
|
/* This is what each hash table entry points to. It may be embedded
|
|
deeply within another object. */
|
|
typedef struct ht_identifier ht_identifier;
|
|
struct ht_identifier GTY(())
|
|
{
|
|
const unsigned char *str;
|
|
unsigned int len;
|
|
unsigned int hash_value;
|
|
};
|
|
|
|
#define HT_LEN(NODE) ((NODE)->len)
|
|
#define HT_STR(NODE) ((NODE)->str)
|
|
|
|
typedef struct ht hash_table;
|
|
typedef struct ht_identifier *hashnode;
|
|
|
|
enum ht_lookup_option {HT_NO_INSERT = 0, HT_ALLOC};
|
|
|
|
/* An identifier hash table for cpplib and the front ends. */
|
|
struct ht
|
|
{
|
|
/* Identifiers are allocated from here. */
|
|
struct obstack stack;
|
|
|
|
hashnode *entries;
|
|
/* Call back, allocate a node. */
|
|
hashnode (*alloc_node) (hash_table *);
|
|
/* Call back, allocate something that hangs off a node like a cpp_macro.
|
|
NULL means use the usual allocator. */
|
|
void * (*alloc_subobject) (size_t);
|
|
|
|
unsigned int nslots; /* Total slots in the entries array. */
|
|
unsigned int nelements; /* Number of live elements. */
|
|
|
|
/* Link to reader, if any. For the benefit of cpplib. */
|
|
struct cpp_reader *pfile;
|
|
|
|
/* Table usage statistics. */
|
|
unsigned int searches;
|
|
unsigned int collisions;
|
|
|
|
/* Should 'entries' be freed when it is no longer needed? */
|
|
bool entries_owned;
|
|
};
|
|
|
|
/* Initialize the hashtable with 2 ^ order entries. */
|
|
extern hash_table *ht_create (unsigned int order);
|
|
|
|
/* Frees all memory associated with a hash table. */
|
|
extern void ht_destroy (hash_table *);
|
|
|
|
extern hashnode ht_lookup (hash_table *, const unsigned char *,
|
|
size_t, enum ht_lookup_option);
|
|
extern hashnode ht_lookup_with_hash (hash_table *, const unsigned char *,
|
|
size_t, unsigned int,
|
|
enum ht_lookup_option);
|
|
#define HT_HASHSTEP(r, c) ((r) * 67 + ((c) - 113));
|
|
#define HT_HASHFINISH(r, len) ((r) + (len))
|
|
|
|
/* For all nodes in TABLE, make a callback. The callback takes
|
|
TABLE->PFILE, the node, and a PTR, and the callback sequence stops
|
|
if the callback returns zero. */
|
|
typedef int (*ht_cb) (struct cpp_reader *, hashnode, const void *);
|
|
extern void ht_forall (hash_table *, ht_cb, const void *);
|
|
|
|
/* For all nodes in TABLE, call the callback. If the callback returns
|
|
a nonzero value, the node is removed from the table. */
|
|
extern void ht_purge (hash_table *, ht_cb, const void *);
|
|
|
|
/* Restore the hash table. */
|
|
extern void ht_load (hash_table *ht, hashnode *entries,
|
|
unsigned int nslots, unsigned int nelements, bool own);
|
|
|
|
/* Dump allocation statistics to stderr. */
|
|
extern void ht_dump_statistics (hash_table *);
|
|
|
|
#endif /* LIBCPP_SYMTAB_H */
|