Mercurial > hg > CbC > CbC_gcc
comparison gcc/stringpool.c @ 111:04ced10e8804
gcc 7
author | kono |
---|---|
date | Fri, 27 Oct 2017 22:46:09 +0900 |
parents | f6334be47118 |
children | 84e7813d76e9 |
comparison
equal
deleted
inserted
replaced
68:561a7518be6b | 111:04ced10e8804 |
---|---|
1 /* String pool for GCC. | 1 /* String pool for GCC. |
2 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010 | 2 Copyright (C) 2000-2017 Free Software Foundation, Inc. |
3 Free Software Foundation, Inc. | |
4 | 3 |
5 This file is part of GCC. | 4 This file is part of GCC. |
6 | 5 |
7 GCC is free software; you can redistribute it and/or modify it under | 6 GCC is free software; you can redistribute it and/or modify it under |
8 the terms of the GNU General Public License as published by the Free | 7 the terms of the GNU General Public License as published by the Free |
27 is faster. */ | 26 is faster. */ |
28 | 27 |
29 #include "config.h" | 28 #include "config.h" |
30 #include "system.h" | 29 #include "system.h" |
31 #include "coretypes.h" | 30 #include "coretypes.h" |
32 #include "ggc.h" | |
33 #include "ggc-internal.h" | |
34 #include "tree.h" | 31 #include "tree.h" |
35 #include "symtab.h" | |
36 #include "cpplib.h" | |
37 | |
38 /* The "" allocated string. */ | |
39 const char empty_string[] = ""; | |
40 | |
41 /* Character strings, each containing a single decimal digit. | |
42 Written this way to save space. */ | |
43 static const char digit_vector[] = { | |
44 '0', 0, '1', 0, '2', 0, '3', 0, '4', 0, | |
45 '5', 0, '6', 0, '7', 0, '8', 0, '9', 0 | |
46 }; | |
47 | |
48 #define digit_string(d) (digit_vector + ((d) * 2)) | |
49 | 32 |
50 struct ht *ident_hash; | 33 struct ht *ident_hash; |
51 | 34 |
52 static hashnode alloc_node (hash_table *); | 35 static hashnode alloc_node (cpp_hash_table *); |
53 static int mark_ident (struct cpp_reader *, hashnode, const void *); | 36 static int mark_ident (struct cpp_reader *, hashnode, const void *); |
54 | 37 |
55 static void * | 38 static void * |
56 stringpool_ggc_alloc (size_t x) | 39 stringpool_ggc_alloc (size_t x) |
57 { | 40 { |
60 | 43 |
61 /* Initialize the string pool. */ | 44 /* Initialize the string pool. */ |
62 void | 45 void |
63 init_stringpool (void) | 46 init_stringpool (void) |
64 { | 47 { |
48 /* Clean up if we're called more than once. | |
49 (We can't make this idempotent since identifiers contain state) */ | |
50 if (ident_hash) | |
51 ht_destroy (ident_hash); | |
52 | |
65 /* Create with 16K (2^14) entries. */ | 53 /* Create with 16K (2^14) entries. */ |
66 ident_hash = ht_create (14); | 54 ident_hash = ht_create (14); |
67 ident_hash->alloc_node = alloc_node; | 55 ident_hash->alloc_node = alloc_node; |
68 ident_hash->alloc_subobject = stringpool_ggc_alloc; | 56 ident_hash->alloc_subobject = stringpool_ggc_alloc; |
69 } | 57 } |
70 | 58 |
71 /* Allocate a hash node. */ | 59 /* Allocate a hash node. */ |
72 static hashnode | 60 static hashnode |
73 alloc_node (hash_table *table ATTRIBUTE_UNUSED) | 61 alloc_node (cpp_hash_table *table ATTRIBUTE_UNUSED) |
74 { | 62 { |
75 return GCC_IDENT_TO_HT_IDENT (make_node (IDENTIFIER_NODE)); | 63 return GCC_IDENT_TO_HT_IDENT (make_node (IDENTIFIER_NODE)); |
76 } | 64 } |
77 | 65 |
78 /* Allocate and return a string constant of length LENGTH, containing | 66 /* Allocate and return a string constant of length LENGTH, containing |
79 CONTENTS. If LENGTH is -1, CONTENTS is assumed to be a | 67 CONTENTS. If LENGTH is -1, CONTENTS is assumed to be a |
80 nul-terminated string, and the length is calculated using strlen. */ | 68 nul-terminated string, and the length is calculated using strlen. */ |
81 | 69 |
82 const char * | 70 const char * |
83 ggc_alloc_string_stat (const char *contents, int length MEM_STAT_DECL) | 71 ggc_alloc_string (const char *contents, int length MEM_STAT_DECL) |
84 { | 72 { |
85 char *result; | |
86 | |
87 if (length == -1) | 73 if (length == -1) |
88 length = strlen (contents); | 74 length = strlen (contents); |
89 | 75 |
90 if (length == 0) | 76 if (!length) |
91 return empty_string; | 77 return ""; |
92 if (length == 1 && ISDIGIT (contents[0])) | 78 |
93 return digit_string (contents[0] - '0'); | 79 char *result = (char *) ggc_alloc_atomic (length + 1); |
94 | |
95 result = (char *) ggc_alloc_atomic_stat (length + 1 PASS_MEM_STAT); | |
96 memcpy (result, contents, length); | 80 memcpy (result, contents, length); |
97 result[length] = '\0'; | 81 result[length] = '\0'; |
82 | |
98 return (const char *) result; | 83 return (const char *) result; |
99 } | 84 } |
100 | 85 |
101 /* Return an IDENTIFIER_NODE whose name is TEXT (a null-terminated string). | 86 /* Return an IDENTIFIER_NODE whose name is TEXT (a null-terminated string). |
102 If an identifier with that name has previously been referred to, | 87 If an identifier with that name has previously been referred to, |
206 | 191 |
207 void | 192 void |
208 gt_pch_n_S (const void *x) | 193 gt_pch_n_S (const void *x) |
209 { | 194 { |
210 gt_pch_note_object (CONST_CAST (void *, x), CONST_CAST (void *, x), | 195 gt_pch_note_object (CONST_CAST (void *, x), CONST_CAST (void *, x), |
211 >_pch_p_S, gt_types_enum_last); | 196 >_pch_p_S); |
197 } | |
198 | |
199 | |
200 /* User-callable entry point for marking string X. */ | |
201 | |
202 void | |
203 gt_pch_nx (const char *& x) | |
204 { | |
205 gt_pch_n_S (x); | |
206 } | |
207 | |
208 void | |
209 gt_pch_nx (unsigned char *& x) | |
210 { | |
211 gt_pch_n_S (x); | |
212 } | |
213 | |
214 void | |
215 gt_pch_nx (unsigned char& x ATTRIBUTE_UNUSED) | |
216 { | |
217 } | |
218 | |
219 void | |
220 gt_pch_nx (unsigned char *x, gt_pointer_operator op, void *cookie) | |
221 { | |
222 op (x, cookie); | |
212 } | 223 } |
213 | 224 |
214 /* Handle saving and restoring the string pool for PCH. */ | 225 /* Handle saving and restoring the string pool for PCH. */ |
215 | 226 |
216 /* SPD is saved in the PCH file and holds the information needed | 227 /* SPD is saved in the PCH file and holds the information needed |
231 /* Save the stringpool data in SPD. */ | 242 /* Save the stringpool data in SPD. */ |
232 | 243 |
233 void | 244 void |
234 gt_pch_save_stringpool (void) | 245 gt_pch_save_stringpool (void) |
235 { | 246 { |
236 spd = ggc_alloc_string_pool_data (); | 247 spd = ggc_alloc<string_pool_data> (); |
237 spd->nslots = ident_hash->nslots; | 248 spd->nslots = ident_hash->nslots; |
238 spd->nelements = ident_hash->nelements; | 249 spd->nelements = ident_hash->nelements; |
239 spd->entries = ggc_alloc_vec_ht_identifier_ptr (spd->nslots); | 250 spd->entries = ggc_vec_alloc<ht_identifier_ptr> (spd->nslots); |
240 memcpy (spd->entries, ident_hash->entries, | 251 memcpy (spd->entries, ident_hash->entries, |
241 spd->nslots * sizeof (spd->entries[0])); | 252 spd->nslots * sizeof (spd->entries[0])); |
242 } | 253 } |
243 | 254 |
244 /* Return the stringpool to its state before gt_pch_save_stringpool | 255 /* Return the stringpool to its state before gt_pch_save_stringpool |