2020std_namespaces = ('std' , 'stdext' , '__gnu_cxx' )
2121
2222
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+
2344class defaults_eraser (object ):
2445
2546 def __init__ (self , unordered_maps_and_sets ):
@@ -29,24 +50,7 @@ def normalize(self, type_str):
2950 return type_str .replace (' ' , '' )
3051
3152 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 )
5054
5155 def decorated_call_prefix (self , cls_name , text , doit ):
5256 has_text = cls_name .startswith (text )
@@ -96,10 +100,11 @@ def erase_recursive(self, cls_name):
96100 return self .no_end_const (cls_name )
97101
98102 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 )
100104 c_name , c_args = templates .split (cls_name )
105+ print ("c_name, c_args" , c_name , c_args )
101106 if len (c_args ) != 2 :
102- return
107+ return cls_name
103108 value_type = c_args [0 ]
104109 tmpl = string .Template (
105110 "$container< $value_type, $allocator<$value_type> >" )
@@ -109,19 +114,22 @@ def erase_allocator(self, cls_name, default_allocator='std::allocator'):
109114 allocator = default_allocator )
110115 if self .normalize (cls_name ) == \
111116 self .normalize (tmpl ):
112- return templates .join (
117+ result = templates .join (
113118 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
114123
115124 def erase_container (self , cls_name , default_container_name = 'std::deque' ):
116- cls_name = self .replace_basic_string (cls_name )
117125 c_name , c_args = templates .split (cls_name )
118126 if len (c_args ) != 2 :
119- return
127+ return cls_name
120128 value_type = c_args [0 ]
121129 dc_no_defaults = self .erase_recursive (c_args [1 ])
122130 if self .normalize (dc_no_defaults ) != self .normalize (
123131 templates .join (default_container_name , [value_type ])):
124- return
132+ return None
125133 return templates .join (
126134 c_name , [self .erase_recursive (value_type )])
127135
@@ -130,10 +138,9 @@ def erase_container_compare(
130138 cls_name ,
131139 default_container_name = 'std::vector' ,
132140 default_compare = 'std::less' ):
133- cls_name = self .replace_basic_string (cls_name )
134141 c_name , c_args = templates .split (cls_name )
135142 if len (c_args ) != 3 :
136- return
143+ return cls_name
137144 dc_no_defaults = self .erase_recursive (c_args [1 ])
138145 if self .normalize (dc_no_defaults ) != self .normalize (
139146 templates .join (default_container_name , [c_args [0 ]])):
@@ -150,10 +157,9 @@ def erase_compare_allocator(
150157 cls_name ,
151158 default_compare = 'std::less' ,
152159 default_allocator = 'std::allocator' ):
153- cls_name = self .replace_basic_string (cls_name )
154160 c_name , c_args = templates .split (cls_name )
155161 if len (c_args ) != 3 :
156- return
162+ return cls_name
157163 value_type = c_args [0 ]
158164 tmpl = string .Template (
159165 "$container< $value_type, $compare<$value_type>, " +
@@ -173,10 +179,9 @@ def erase_map_compare_allocator(
173179 cls_name ,
174180 default_compare = 'std::less' ,
175181 default_allocator = 'std::allocator' ):
176- cls_name = self .replace_basic_string (cls_name )
177182 c_name , c_args = templates .split (cls_name )
178183 if len (c_args ) != 4 :
179- return
184+ return cls_name
180185 key_type = c_args [0 ]
181186 mapped_type = c_args [1 ]
182187 tmpls = [
@@ -203,10 +208,9 @@ def erase_map_compare_allocator(
203208 self .erase_recursive (mapped_type )])
204209
205210 def erase_hash_allocator (self , cls_name ):
206- cls_name = self .replace_basic_string (cls_name )
207211 c_name , c_args = templates .split (cls_name )
208212 if len (c_args ) < 3 :
209- return
213+ return cls_name
210214
211215 default_less = 'std::less'
212216 default_equal_to = 'std::equal_to'
@@ -223,7 +227,7 @@ def erase_hash_allocator(self, cls_name):
223227 "$container< $value_type, $hash<$value_type >, " +
224228 "$equal_to<$value_type >, $allocator<$value_type> >" )
225229 else :
226- return
230+ return cls_name
227231
228232 value_type = c_args [0 ]
229233 template = string .Template (tmpl )
@@ -241,7 +245,6 @@ def erase_hash_allocator(self, cls_name):
241245 c_name , [self .erase_recursive (value_type )])
242246
243247 def erase_hashmap_compare_allocator (self , cls_name ):
244- cls_name = self .replace_basic_string (cls_name )
245248 c_name , c_args = templates .split (cls_name )
246249
247250 if self .unordered_maps_and_sets :
@@ -255,7 +258,7 @@ def erase_hashmap_compare_allocator(self, cls_name):
255258 key_type = c_args [0 ]
256259 mapped_type = c_args [1 ]
257260 else :
258- return
261+ return cls_name
259262
260263 if len (c_args ) == 4 :
261264 default_hash = 'hash_compare'
@@ -302,7 +305,7 @@ def erase_hashmap_compare_allocator(self, cls_name):
302305 "$equal_to<$key_type>, " +
303306 "$allocator< $mapped_type > >" )
304307 else :
305- return
308+ return cls_name
306309
307310 for ns in std_namespaces :
308311 inst = tmpl .substitute (
@@ -517,15 +520,18 @@ def remove_defaults(self, type_or_string):
517520 std::vector< int >
518521
519522 """
520-
521523 name = type_or_string
522524 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+ )
523530 name = self .class_declaration (type_or_string ).name
524531 if not self .remove_defaults_impl :
525532 return name
533+ name = _replace_basic_string (name )
526534 no_defaults = self .remove_defaults_impl (name )
527- if not no_defaults :
528- return name
529535 return no_defaults
530536
531537
0 commit comments