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 "internal.h"
00030
00031 static cpp_hashnode *alloc_node (hash_table *);
00032
00033
00034
00035 static cpp_hashnode *
00036 alloc_node (hash_table *table)
00037 {
00038 cpp_hashnode *node;
00039
00040 node = obstack_alloc (&table->pfile->hash_ob, sizeof (cpp_hashnode));
00041 memset (node, 0, sizeof (cpp_hashnode));
00042 return node;
00043 }
00044
00045
00046
00047 void
00048 _cpp_init_hashtable (cpp_reader *pfile, hash_table *table)
00049 {
00050 struct spec_nodes *s;
00051
00052 if (table == NULL)
00053 {
00054 pfile->our_hashtable = 1;
00055 table = ht_create (13);
00056 table->alloc_node = (hashnode (*) (hash_table *)) alloc_node;
00057
00058 _obstack_begin (&pfile->hash_ob, 0, 0,
00059 (void *(*) (long)) xmalloc,
00060 (void (*) (void *)) free);
00061 }
00062
00063 table->pfile = pfile;
00064 pfile->hash_table = table;
00065
00066
00067 _cpp_init_directives (pfile);
00068 _cpp_init_internal_pragmas (pfile);
00069
00070 s = &pfile->spec_nodes;
00071 s->n_defined = cpp_lookup (pfile, DSC("defined"));
00072 s->n_true = cpp_lookup (pfile, DSC("true"));
00073 s->n_false = cpp_lookup (pfile, DSC("false"));
00074 s->n__VA_ARGS__ = cpp_lookup (pfile, DSC("__VA_ARGS__"));
00075 s->n__VA_ARGS__->flags |= NODE_DIAGNOSTIC;
00076 }
00077
00078
00079 void
00080 _cpp_destroy_hashtable (cpp_reader *pfile)
00081 {
00082 if (pfile->our_hashtable)
00083 {
00084 ht_destroy (pfile->hash_table);
00085 obstack_free (&pfile->hash_ob, 0);
00086 }
00087 }
00088
00089
00090
00091 cpp_hashnode *
00092 cpp_lookup (cpp_reader *pfile, const unsigned char *str, unsigned int len)
00093 {
00094
00095 return CPP_HASHNODE (ht_lookup (pfile->hash_table, str, len, HT_ALLOC));
00096 }
00097
00098
00099 int
00100 cpp_defined (cpp_reader *pfile, const unsigned char *str, int len)
00101 {
00102 cpp_hashnode *node;
00103
00104 node = CPP_HASHNODE (ht_lookup (pfile->hash_table, str, len, HT_NO_INSERT));
00105
00106
00107 return node && node->type == NT_MACRO;
00108 }
00109
00110
00111
00112 void
00113 cpp_forall_identifiers (cpp_reader *pfile, cpp_cb cb, void *v)
00114 {
00115
00116
00117 ht_forall (pfile->hash_table, (ht_cb) cb, v);
00118 }