20
20
std_namespaces = ('std' , 'stdext' , '__gnu_cxx' )
21
21
22
22
23
+ def _replace_basic_string (cls_name ):
24
+ # Replace all the variations of strings by the smallest one.
25
+ strings = {
26
+ "std::string" :
27
+ [v for v in
28
+ type_traits .normalized_string_equivalences
29
+ if not v == "std::string" ],
30
+ "std::wstring" :
31
+ [v for v in
32
+ type_traits .normalized_wstring_equivalences
33
+ if not v == "std::wstring" ]
34
+ }
35
+
36
+ new_name = cls_name
37
+ for short_name , long_names in strings .items ():
38
+ for lname in long_names :
39
+ new_name = new_name .replace (lname , short_name )
40
+
41
+ return new_name
42
+
43
+
23
44
class defaults_eraser (object ):
24
45
25
46
def __init__ (self , unordered_maps_and_sets ):
@@ -29,24 +50,7 @@ def normalize(self, type_str):
29
50
return type_str .replace (' ' , '' )
30
51
31
52
def replace_basic_string (self , cls_name ):
32
- # Replace all the variations of strings by the smallest one.
33
- strings = {
34
- "std::string" :
35
- [v for v in
36
- type_traits .normalized_string_equivalences
37
- if not v == "std::string" ],
38
- "std::wstring" :
39
- [v for v in
40
- type_traits .normalized_wstring_equivalences
41
- if not v == "std::wstring" ]
42
- }
43
-
44
- new_name = cls_name
45
- for short_name , long_names in strings .items ():
46
- for lname in long_names :
47
- new_name = new_name .replace (lname , short_name )
48
-
49
- return new_name
53
+ return _replace_basic_string (cls_name )
50
54
51
55
def decorated_call_prefix (self , cls_name , text , doit ):
52
56
has_text = cls_name .startswith (text )
@@ -96,10 +100,11 @@ def erase_recursive(self, cls_name):
96
100
return self .no_end_const (cls_name )
97
101
98
102
def erase_allocator (self , cls_name , default_allocator = 'std::allocator' ):
99
- cls_name = self . replace_basic_string ( cls_name )
103
+ print ( "erase_allocator" , cls_name )
100
104
c_name , c_args = templates .split (cls_name )
105
+ print ("c_name, c_args" , c_name , c_args )
101
106
if len (c_args ) != 2 :
102
- return
107
+ return cls_name
103
108
value_type = c_args [0 ]
104
109
tmpl = string .Template (
105
110
"$container< $value_type, $allocator<$value_type> >" )
@@ -109,19 +114,22 @@ def erase_allocator(self, cls_name, default_allocator='std::allocator'):
109
114
allocator = default_allocator )
110
115
if self .normalize (cls_name ) == \
111
116
self .normalize (tmpl ):
112
- return templates .join (
117
+ result = templates .join (
113
118
c_name , [self .erase_recursive (value_type )])
119
+ print ("result" , result )
120
+ print ("c_name" , c_name )
121
+ print ("value_type" , value_type )
122
+ return result
114
123
115
124
def erase_container (self , cls_name , default_container_name = 'std::deque' ):
116
- cls_name = self .replace_basic_string (cls_name )
117
125
c_name , c_args = templates .split (cls_name )
118
126
if len (c_args ) != 2 :
119
- return
127
+ return cls_name
120
128
value_type = c_args [0 ]
121
129
dc_no_defaults = self .erase_recursive (c_args [1 ])
122
130
if self .normalize (dc_no_defaults ) != self .normalize (
123
131
templates .join (default_container_name , [value_type ])):
124
- return
132
+ return None
125
133
return templates .join (
126
134
c_name , [self .erase_recursive (value_type )])
127
135
@@ -130,10 +138,9 @@ def erase_container_compare(
130
138
cls_name ,
131
139
default_container_name = 'std::vector' ,
132
140
default_compare = 'std::less' ):
133
- cls_name = self .replace_basic_string (cls_name )
134
141
c_name , c_args = templates .split (cls_name )
135
142
if len (c_args ) != 3 :
136
- return
143
+ return cls_name
137
144
dc_no_defaults = self .erase_recursive (c_args [1 ])
138
145
if self .normalize (dc_no_defaults ) != self .normalize (
139
146
templates .join (default_container_name , [c_args [0 ]])):
@@ -150,10 +157,9 @@ def erase_compare_allocator(
150
157
cls_name ,
151
158
default_compare = 'std::less' ,
152
159
default_allocator = 'std::allocator' ):
153
- cls_name = self .replace_basic_string (cls_name )
154
160
c_name , c_args = templates .split (cls_name )
155
161
if len (c_args ) != 3 :
156
- return
162
+ return cls_name
157
163
value_type = c_args [0 ]
158
164
tmpl = string .Template (
159
165
"$container< $value_type, $compare<$value_type>, " +
@@ -173,10 +179,9 @@ def erase_map_compare_allocator(
173
179
cls_name ,
174
180
default_compare = 'std::less' ,
175
181
default_allocator = 'std::allocator' ):
176
- cls_name = self .replace_basic_string (cls_name )
177
182
c_name , c_args = templates .split (cls_name )
178
183
if len (c_args ) != 4 :
179
- return
184
+ return cls_name
180
185
key_type = c_args [0 ]
181
186
mapped_type = c_args [1 ]
182
187
tmpls = [
@@ -203,10 +208,9 @@ def erase_map_compare_allocator(
203
208
self .erase_recursive (mapped_type )])
204
209
205
210
def erase_hash_allocator (self , cls_name ):
206
- cls_name = self .replace_basic_string (cls_name )
207
211
c_name , c_args = templates .split (cls_name )
208
212
if len (c_args ) < 3 :
209
- return
213
+ return cls_name
210
214
211
215
default_less = 'std::less'
212
216
default_equal_to = 'std::equal_to'
@@ -223,7 +227,7 @@ def erase_hash_allocator(self, cls_name):
223
227
"$container< $value_type, $hash<$value_type >, " +
224
228
"$equal_to<$value_type >, $allocator<$value_type> >" )
225
229
else :
226
- return
230
+ return cls_name
227
231
228
232
value_type = c_args [0 ]
229
233
template = string .Template (tmpl )
@@ -241,7 +245,6 @@ def erase_hash_allocator(self, cls_name):
241
245
c_name , [self .erase_recursive (value_type )])
242
246
243
247
def erase_hashmap_compare_allocator (self , cls_name ):
244
- cls_name = self .replace_basic_string (cls_name )
245
248
c_name , c_args = templates .split (cls_name )
246
249
247
250
if self .unordered_maps_and_sets :
@@ -255,7 +258,7 @@ def erase_hashmap_compare_allocator(self, cls_name):
255
258
key_type = c_args [0 ]
256
259
mapped_type = c_args [1 ]
257
260
else :
258
- return
261
+ return cls_name
259
262
260
263
if len (c_args ) == 4 :
261
264
default_hash = 'hash_compare'
@@ -302,7 +305,7 @@ def erase_hashmap_compare_allocator(self, cls_name):
302
305
"$equal_to<$key_type>, " +
303
306
"$allocator< $mapped_type > >" )
304
307
else :
305
- return
308
+ return cls_name
306
309
307
310
for ns in std_namespaces :
308
311
inst = tmpl .substitute (
@@ -517,15 +520,18 @@ def remove_defaults(self, type_or_string):
517
520
std::vector< int >
518
521
519
522
"""
520
-
521
523
name = type_or_string
522
524
if not isinstance (type_or_string , str ):
525
+ print (
526
+ "xxxx" ,
527
+ type (self .class_declaration (type_or_string )),
528
+ self .class_declaration (type_or_string ).name
529
+ )
523
530
name = self .class_declaration (type_or_string ).name
524
531
if not self .remove_defaults_impl :
525
532
return name
533
+ name = self .replace_basic_string (name )
526
534
no_defaults = self .remove_defaults_impl (name )
527
- if not no_defaults :
528
- return name
529
535
return no_defaults
530
536
531
537
0 commit comments