OSDN Git Service

* unwind-dw2-fde.c (__deregister_frame_info): Stringize use
[pf3gnuchains/gcc-fork.git] / gcc / cpphash.c
1 /* Hash tables for the CPP library.
2    Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1998,
3    1999, 2000 Free Software Foundation, Inc.
4    Written by Per Bothner, 1994.
5    Based on CCCP program by Paul Rubin, June 1986
6    Adapted to ANSI C, Richard Stallman, Jan 1987
7
8 This program is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 2, or (at your option) any
11 later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
22  In other words, you are welcome to use, share and improve this program.
23  You are forbidden to forbid anyone else to use, share and improve
24  what you give them.   Help stamp out software-hoarding!  */
25
26 #include "config.h"
27 #include "system.h"
28 #include "cpplib.h"
29 #include "cpphash.h"
30
31 static cpp_hashnode *alloc_node PARAMS ((hash_table *));
32
33 /* Return an identifier node for hashtable.c.  Used by cpplib except
34    when integrated with the C front ends.  */
35
36 static cpp_hashnode *
37 alloc_node (table)
38      hash_table *table;
39 {
40   cpp_hashnode *node;
41   
42   node = obstack_alloc (&table->pfile->hash_ob, sizeof (cpp_hashnode));
43   memset ((PTR) node, 0, sizeof (cpp_hashnode));
44   return node;
45 }
46
47 /* Set up the identifier hash table.  Use TABLE if non-null, otherwise
48    create our own.  */
49
50 void
51 _cpp_init_hashtable (pfile, table)
52      cpp_reader *pfile;
53      hash_table *table;
54 {
55   if (table == NULL)
56     {
57       pfile->our_hashtable = 1;
58       table = ht_create (13);   /* 8K (=2^13) entries.  */
59       table->alloc_node = (hashnode (*) PARAMS ((hash_table *))) alloc_node;
60       gcc_obstack_init (&pfile->hash_ob);
61     }
62
63   table->pfile = pfile;
64   pfile->hash_table = table;
65 }
66
67 /* Tear down the identifier hash table.  */
68
69 void
70 _cpp_destroy_hashtable (pfile)
71      cpp_reader *pfile;
72 {
73   if (pfile->our_hashtable)
74     {
75       free (pfile->hash_table);
76       obstack_free (&pfile->hash_ob, 0);
77     }
78 }
79
80 /* Returns the hash entry for the STR of length LEN, creating one
81    if necessary.  */
82
83 cpp_hashnode *
84 cpp_lookup (pfile, str, len)
85      cpp_reader *pfile;
86      const unsigned char *str;
87      unsigned int len;
88 {
89   /* ht_lookup cannot return NULL.  */
90   return CPP_HASHNODE (ht_lookup (pfile->hash_table, str, len, HT_ALLOC));
91 }
92
93 /* Determine whether the str STR, of length LEN, is a defined macro.  */
94
95 int
96 cpp_defined (pfile, str, len)
97      cpp_reader *pfile;
98      const unsigned char *str;
99      int len;
100 {
101   cpp_hashnode *node;
102
103   node = CPP_HASHNODE (ht_lookup (pfile->hash_table, str, len, HT_NO_INSERT));
104
105   /* If it's of type NT_MACRO, it cannot be poisoned.  */
106   return node && node->type == NT_MACRO;
107 }
108
109 /* For all nodes in the hashtable, callback CB with parameters PFILE,
110    the node, and V.  */
111
112 void
113 cpp_forall_identifiers (pfile, cb, v)
114      cpp_reader *pfile;
115      cpp_cb cb;
116      PTR v;
117 {
118   /* We don't need a proxy since the hash table's identifier comes
119      first in cpp_hashnode.  */
120   ht_forall (pfile->hash_table, (ht_cb) cb, v);
121 }