2020std_namespaces = ('std' , 'stdext' , '__gnu_cxx' )
2121
2222
23+ def _replace_basic_string (cls_name ):
24+ print ("_replace_basic_string start" , cls_name )
25+ # Replace all the variations of strings by the smallest one.
26+ strings = {
27+ "std::string" :
28+ [v for v in
29+ type_traits .normalized_string_equivalences
30+ if not v == "std::string" ],
31+ "std::wstring" :
32+ [v for v in
33+ type_traits .normalized_wstring_equivalences
34+ if not v == "std::wstring" ]
35+ }
36+
37+ new_name = cls_name
38+ for short_name , long_names in strings .items ():
39+ for lname in long_names :
40+ new_name = new_name .replace (lname , short_name )
41+ print ("_replace_basic_string end" , new_name )
42+ return new_name
43+
44+
2345class defaults_eraser (object ):
2446
2547 def __init__ (self , unordered_maps_and_sets ):
@@ -29,24 +51,7 @@ def normalize(self, type_str):
2951 return type_str .replace (' ' , '' )
3052
3153 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
54+ return _replace_basic_string (cls_name )
5055
5156 def decorated_call_prefix (self , cls_name , text , doit ):
5257 has_text = cls_name .startswith (text )
@@ -96,10 +101,11 @@ def erase_recursive(self, cls_name):
96101 return self .no_end_const (cls_name )
97102
98103 def erase_allocator (self , cls_name , default_allocator = 'std::allocator' ):
99- cls_name = self . replace_basic_string ( cls_name )
104+ print ( "erase_allocator" , cls_name )
100105 c_name , c_args = templates .split (cls_name )
106+ print ("c_name, c_args" , c_name , c_args )
101107 if len (c_args ) != 2 :
102- return
108+ return cls_name
103109 value_type = c_args [0 ]
104110 tmpl = string .Template (
105111 "$container< $value_type, $allocator<$value_type> >" )
@@ -109,19 +115,22 @@ def erase_allocator(self, cls_name, default_allocator='std::allocator'):
109115 allocator = default_allocator )
110116 if self .normalize (cls_name ) == \
111117 self .normalize (tmpl ):
112- return templates .join (
118+ result = templates .join (
113119 c_name , [self .erase_recursive (value_type )])
120+ print ("result" , result )
121+ print ("c_name" , c_name )
122+ print ("value_type" , value_type )
123+ return result
114124
115125 def erase_container (self , cls_name , default_container_name = 'std::deque' ):
116- cls_name = self .replace_basic_string (cls_name )
117126 c_name , c_args = templates .split (cls_name )
118127 if len (c_args ) != 2 :
119- return
128+ return cls_name
120129 value_type = c_args [0 ]
121130 dc_no_defaults = self .erase_recursive (c_args [1 ])
122131 if self .normalize (dc_no_defaults ) != self .normalize (
123132 templates .join (default_container_name , [value_type ])):
124- return
133+ return None
125134 return templates .join (
126135 c_name , [self .erase_recursive (value_type )])
127136
@@ -130,10 +139,9 @@ def erase_container_compare(
130139 cls_name ,
131140 default_container_name = 'std::vector' ,
132141 default_compare = 'std::less' ):
133- cls_name = self .replace_basic_string (cls_name )
134142 c_name , c_args = templates .split (cls_name )
135143 if len (c_args ) != 3 :
136- return
144+ return cls_name
137145 dc_no_defaults = self .erase_recursive (c_args [1 ])
138146 if self .normalize (dc_no_defaults ) != self .normalize (
139147 templates .join (default_container_name , [c_args [0 ]])):
@@ -150,10 +158,9 @@ def erase_compare_allocator(
150158 cls_name ,
151159 default_compare = 'std::less' ,
152160 default_allocator = 'std::allocator' ):
153- cls_name = self .replace_basic_string (cls_name )
154161 c_name , c_args = templates .split (cls_name )
155162 if len (c_args ) != 3 :
156- return
163+ return cls_name
157164 value_type = c_args [0 ]
158165 tmpl = string .Template (
159166 "$container< $value_type, $compare<$value_type>, " +
@@ -173,10 +180,9 @@ def erase_map_compare_allocator(
173180 cls_name ,
174181 default_compare = 'std::less' ,
175182 default_allocator = 'std::allocator' ):
176- cls_name = self .replace_basic_string (cls_name )
177183 c_name , c_args = templates .split (cls_name )
178184 if len (c_args ) != 4 :
179- return
185+ return cls_name
180186 key_type = c_args [0 ]
181187 mapped_type = c_args [1 ]
182188 tmpls = [
@@ -203,10 +209,9 @@ def erase_map_compare_allocator(
203209 self .erase_recursive (mapped_type )])
204210
205211 def erase_hash_allocator (self , cls_name ):
206- cls_name = self .replace_basic_string (cls_name )
207212 c_name , c_args = templates .split (cls_name )
208213 if len (c_args ) < 3 :
209- return
214+ return cls_name
210215
211216 default_less = 'std::less'
212217 default_equal_to = 'std::equal_to'
@@ -223,7 +228,7 @@ def erase_hash_allocator(self, cls_name):
223228 "$container< $value_type, $hash<$value_type >, " +
224229 "$equal_to<$value_type >, $allocator<$value_type> >" )
225230 else :
226- return
231+ return cls_name
227232
228233 value_type = c_args [0 ]
229234 template = string .Template (tmpl )
@@ -241,7 +246,6 @@ def erase_hash_allocator(self, cls_name):
241246 c_name , [self .erase_recursive (value_type )])
242247
243248 def erase_hashmap_compare_allocator (self , cls_name ):
244- cls_name = self .replace_basic_string (cls_name )
245249 c_name , c_args = templates .split (cls_name )
246250
247251 if self .unordered_maps_and_sets :
@@ -255,7 +259,7 @@ def erase_hashmap_compare_allocator(self, cls_name):
255259 key_type = c_args [0 ]
256260 mapped_type = c_args [1 ]
257261 else :
258- return
262+ return cls_name
259263
260264 if len (c_args ) == 4 :
261265 default_hash = 'hash_compare'
@@ -302,7 +306,7 @@ def erase_hashmap_compare_allocator(self, cls_name):
302306 "$equal_to<$key_type>, " +
303307 "$allocator< $mapped_type > >" )
304308 else :
305- return
309+ return cls_name
306310
307311 for ns in std_namespaces :
308312 inst = tmpl .substitute (
@@ -517,15 +521,18 @@ def remove_defaults(self, type_or_string):
517521 std::vector< int >
518522
519523 """
520-
521524 name = type_or_string
522525 if not isinstance (type_or_string , str ):
526+ print (
527+ "xxxx" ,
528+ type (self .class_declaration (type_or_string )),
529+ self .class_declaration (type_or_string ).name
530+ )
523531 name = self .class_declaration (type_or_string ).name
524532 if not self .remove_defaults_impl :
525533 return name
534+ name = _replace_basic_string (name )
526535 no_defaults = self .remove_defaults_impl (name )
527- if not no_defaults :
528- return name
529536 return no_defaults
530537
531538
0 commit comments