00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "config.h"
00027 #include "system.h"
00028 #include "cpplib.h"
00029 #include "cpphash.h"
00030
00031 static cpp_hashnode *alloc_node PARAMS ((hash_table *));
00032
00033
00034
00035 static cpp_hashnode *
00036 alloc_node (table)
00037 hash_table *table;
00038 {
00039 cpp_hashnode *node;
00040
00041 node = (cpp_hashnode *) obstack_alloc (&table->pfile->hash_ob,
00042 sizeof (cpp_hashnode));
00043 memset ((PTR) node, 0, sizeof (cpp_hashnode));
00044 return node;
00045 }
00046
00047
00048
00049 void
00050 _cpp_init_hashtable (pfile, table)
00051 cpp_reader *pfile;
00052 hash_table *table;
00053 {
00054 struct spec_nodes *s;
00055
00056 if (table == NULL)
00057 {
00058 pfile->our_hashtable = 1;
00059 table = ht_create (13);
00060 table->alloc_node = (hashnode (*) PARAMS ((hash_table *))) alloc_node;
00061 gcc_obstack_init (&pfile->hash_ob);
00062 }
00063
00064 table->pfile = pfile;
00065 pfile->hash_table = table;
00066
00067
00068 _cpp_init_directives (pfile);
00069 _cpp_init_internal_pragmas (pfile);
00070
00071 s = &pfile->spec_nodes;
00072 s->n_defined = cpp_lookup (pfile, DSC("defined"));
00073 s->n_true = cpp_lookup (pfile, DSC("true"));
00074 s->n_false = cpp_lookup (pfile, DSC("false"));
00075 s->n__VA_ARGS__ = cpp_lookup (pfile, DSC("__VA_ARGS__"));
00076 s->n__VA_ARGS__->flags |= NODE_DIAGNOSTIC;
00077 }
00078
00079
00080 void
00081 _cpp_destroy_hashtable (pfile)
00082 cpp_reader *pfile;
00083 {
00084 if (pfile->our_hashtable)
00085 {
00086 ht_destroy (pfile->hash_table);
00087 obstack_free (&pfile->hash_ob, 0);
00088 }
00089 }
00090
00091
00092
00093 cpp_hashnode *
00094 cpp_lookup (pfile, str, len)
00095 cpp_reader *pfile;
00096 const unsigned char *str;
00097 unsigned int len;
00098 {
00099
00100 return CPP_HASHNODE (ht_lookup (pfile->hash_table, str, len, HT_ALLOC));
00101 }
00102
00103
00104 int
00105 cpp_defined (pfile, str, len)
00106 cpp_reader *pfile;
00107 const unsigned char *str;
00108 int len;
00109 {
00110 cpp_hashnode *node;
00111
00112 node = CPP_HASHNODE (ht_lookup (pfile->hash_table, str, len, HT_NO_INSERT));
00113
00114
00115 return node && node->type == NT_MACRO;
00116 }
00117
00118
00119
00120 void
00121 cpp_forall_identifiers (pfile, cb, v)
00122 cpp_reader *pfile;
00123 cpp_cb cb;
00124 PTR v;
00125 {
00126
00127
00128 ht_forall (pfile->hash_table, (ht_cb) cb, v);
00129 }