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
00027
00028
00029
00030
00031
00032
00033
00034 #include "config.h"
00035 #include "system.h"
00036 #include "ggc.h"
00037 #ifdef SGI_MONGOOSE
00038
00039 #include "rtl.h"
00040 #endif
00041 #include "tree.h"
00042 #include "hashtable.h"
00043
00044
00045 const char empty_string[] = "";
00046
00047
00048
00049 const char digit_vector[] = {
00050 '0', 0, '1', 0, '2', 0, '3', 0, '4', 0,
00051 '5', 0, '6', 0, '7', 0, '8', 0, '9', 0
00052 };
00053
00054 struct ht *ident_hash;
00055 static struct obstack string_stack;
00056
00057 static hashnode alloc_node PARAMS ((hash_table *));
00058 static int mark_ident PARAMS ((struct cpp_reader *, hashnode, const PTR));
00059 static void mark_ident_hash PARAMS ((void *));
00060
00061
00062 void
00063 init_stringpool ()
00064 {
00065
00066 ident_hash = ht_create (14);
00067 ident_hash->alloc_node = alloc_node;
00068 gcc_obstack_init (&string_stack);
00069 ggc_add_root (&ident_hash, 1, sizeof ident_hash, mark_ident_hash);
00070 }
00071
00072
00073 static hashnode
00074 alloc_node (table)
00075 hash_table *table ATTRIBUTE_UNUSED;
00076 {
00077 return GCC_IDENT_TO_HT_IDENT (make_node (IDENTIFIER_NODE));
00078 }
00079
00080
00081
00082
00083
00084
00085
00086 const char *
00087 ggc_alloc_string (contents, length)
00088 const char *contents;
00089 int length;
00090 {
00091 if (length == -1)
00092 length = strlen (contents);
00093
00094 if (length == 0)
00095 return empty_string;
00096 if (length == 1 && ISDIGIT (contents[0]))
00097 return digit_string (contents[0] - '0');
00098
00099 obstack_grow0 (&string_stack, contents, length);
00100 return obstack_finish (&string_stack);
00101 }
00102
00103
00104
00105
00106
00107 #undef get_identifier
00108
00109 tree
00110 get_identifier (text)
00111 const char *text;
00112 {
00113 hashnode ht_node = ht_lookup (ident_hash,
00114 (const unsigned char *) text,
00115 strlen (text), HT_ALLOC);
00116
00117
00118 return HT_IDENT_TO_GCC_IDENT (ht_node);
00119 }
00120
00121
00122
00123
00124 tree
00125 get_identifier_with_length (text, length)
00126 const char *text;
00127 unsigned int length;
00128 {
00129 hashnode ht_node = ht_lookup (ident_hash,
00130 (const unsigned char *) text,
00131 length, HT_ALLOC);
00132
00133
00134 return HT_IDENT_TO_GCC_IDENT (ht_node);
00135 }
00136
00137
00138
00139
00140
00141 tree
00142 maybe_get_identifier (text)
00143 const char *text;
00144 {
00145 hashnode ht_node;
00146
00147 ht_node = ht_lookup (ident_hash, (const unsigned char *) text,
00148 strlen (text), HT_NO_INSERT);
00149 if (ht_node)
00150 return HT_IDENT_TO_GCC_IDENT (ht_node);
00151
00152 return NULL_TREE;
00153 }
00154
00155
00156
00157 void
00158 stringpool_statistics ()
00159 {
00160 ht_dump_statistics (ident_hash);
00161 }
00162
00163
00164
00165 static int
00166 mark_ident (pfile, h, v)
00167 struct cpp_reader *pfile ATTRIBUTE_UNUSED;
00168 hashnode h;
00169 const PTR v ATTRIBUTE_UNUSED;
00170 {
00171 ggc_mark_tree (HT_IDENT_TO_GCC_IDENT (h));
00172 return 1;
00173 }
00174
00175
00176
00177 static void
00178 mark_ident_hash (arg)
00179 PTR arg ATTRIBUTE_UNUSED;
00180 {
00181 ht_forall (ident_hash, mark_ident, NULL);
00182 }