]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/cpphash.c
baseline_symbols.txt: Update to 3.3.0.
[thirdparty/gcc.git] / gcc / cpphash.c
CommitLineData
2a967f3d 1/* Hash tables for the CPP library.
5e7b4e25 2 Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1998,
5d8ebbd8 3 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
7f2935c7 4 Written by Per Bothner, 1994.
38e01259 5 Based on CCCP program by Paul Rubin, June 1986
7f2935c7
PB
6 Adapted to ANSI C, Richard Stallman, Jan 1987
7
8This program is free software; you can redistribute it and/or modify it
9under the terms of the GNU General Public License as published by the
10Free Software Foundation; either version 2, or (at your option) any
11later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with this program; if not, write to the Free Software
940d9d63 20Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
7f2935c7
PB
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
b04cd507
KG
26#include "config.h"
27#include "system.h"
4977bab6
ZW
28#include "coretypes.h"
29#include "tm.h"
7f2935c7 30#include "cpplib.h"
e38992e8
RK
31#include "cpphash.h"
32
2a967f3d 33static cpp_hashnode *alloc_node PARAMS ((hash_table *));
7f2935c7 34
2a967f3d
NB
35/* Return an identifier node for hashtable.c. Used by cpplib except
36 when integrated with the C front ends. */
2a967f3d
NB
37static cpp_hashnode *
38alloc_node (table)
39 hash_table *table;
2964d54f 40{
2a967f3d 41 cpp_hashnode *node;
df383483 42
f278806b
NB
43 node = (cpp_hashnode *) obstack_alloc (&table->pfile->hash_ob,
44 sizeof (cpp_hashnode));
fad205ff 45 memset (node, 0, sizeof (cpp_hashnode));
2a967f3d 46 return node;
d9e0bd53
ZW
47}
48
2a967f3d
NB
49/* Set up the identifier hash table. Use TABLE if non-null, otherwise
50 create our own. */
711b8824 51void
2a967f3d 52_cpp_init_hashtable (pfile, table)
6de1e2a9 53 cpp_reader *pfile;
2a967f3d 54 hash_table *table;
6de1e2a9 55{
f5e99456
NB
56 struct spec_nodes *s;
57
2a967f3d 58 if (table == NULL)
6de1e2a9 59 {
2a967f3d
NB
60 pfile->our_hashtable = 1;
61 table = ht_create (13); /* 8K (=2^13) entries. */
62 table->alloc_node = (hashnode (*) PARAMS ((hash_table *))) alloc_node;
63 gcc_obstack_init (&pfile->hash_ob);
b30892f9 64 }
711b8824 65
2a967f3d
NB
66 table->pfile = pfile;
67 pfile->hash_table = table;
f5e99456
NB
68
69 /* Now we can initialize things that use the hash table. */
70 _cpp_init_directives (pfile);
71 _cpp_init_internal_pragmas (pfile);
72
73 s = &pfile->spec_nodes;
f5e99456
NB
74 s->n_defined = cpp_lookup (pfile, DSC("defined"));
75 s->n_true = cpp_lookup (pfile, DSC("true"));
76 s->n_false = cpp_lookup (pfile, DSC("false"));
f5e99456
NB
77 s->n__VA_ARGS__ = cpp_lookup (pfile, DSC("__VA_ARGS__"));
78 s->n__VA_ARGS__->flags |= NODE_DIAGNOSTIC;
ba412f14
ZW
79}
80
2a967f3d 81/* Tear down the identifier hash table. */
2a967f3d
NB
82void
83_cpp_destroy_hashtable (pfile)
ba412f14 84 cpp_reader *pfile;
ba412f14 85{
2a967f3d 86 if (pfile->our_hashtable)
b30892f9 87 {
bef985f3 88 ht_destroy (pfile->hash_table);
2a967f3d 89 obstack_free (&pfile->hash_ob, 0);
b30892f9 90 }
45b966db
ZW
91}
92
2a967f3d
NB
93/* Returns the hash entry for the STR of length LEN, creating one
94 if necessary. */
711b8824 95cpp_hashnode *
2a967f3d 96cpp_lookup (pfile, str, len)
6de1e2a9 97 cpp_reader *pfile;
2a967f3d
NB
98 const unsigned char *str;
99 unsigned int len;
6de1e2a9 100{
2a967f3d
NB
101 /* ht_lookup cannot return NULL. */
102 return CPP_HASHNODE (ht_lookup (pfile->hash_table, str, len, HT_ALLOC));
d9e0bd53 103}
3caee4a8 104
2a967f3d 105/* Determine whether the str STR, of length LEN, is a defined macro. */
2a967f3d
NB
106int
107cpp_defined (pfile, str, len)
108 cpp_reader *pfile;
109 const unsigned char *str;
110 int len;
d9e0bd53 111{
2a967f3d 112 cpp_hashnode *node;
3caee4a8 113
2a967f3d 114 node = CPP_HASHNODE (ht_lookup (pfile->hash_table, str, len, HT_NO_INSERT));
d35364d1 115
2a967f3d
NB
116 /* If it's of type NT_MACRO, it cannot be poisoned. */
117 return node && node->type == NT_MACRO;
d35364d1
ZW
118}
119
2a967f3d
NB
120/* For all nodes in the hashtable, callback CB with parameters PFILE,
121 the node, and V. */
d35364d1 122void
926c5678 123cpp_forall_identifiers (pfile, cb, v)
d35364d1 124 cpp_reader *pfile;
2a967f3d 125 cpp_cb cb;
fad205ff 126 void *v;
d35364d1 127{
2a967f3d
NB
128 /* We don't need a proxy since the hash table's identifier comes
129 first in cpp_hashnode. */
130 ht_forall (pfile->hash_table, (ht_cb) cb, v);
a949941c 131}