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+ ddd = [v .replace ("::std" , "std" ) for v in type_traits .string_equivalences
27+ if not v == "std::string" ]
28+
29+ sss = [v for v in
30+ type_traits .normalized_string_equivalences
31+ if not v == "std::string" ]
32+ ddd .extend (sss )
33+
34+ strings = {
35+ "std::string" : ddd ,
36+ "std::wstring" :
37+ [v for v in
38+ type_traits .normalized_wstring_equivalences
39+ if not v == "std::wstring" ]
40+ }
41+
42+ new_name = cls_name
43+ for short_name , long_names in strings .items ():
44+ for lname in long_names :
45+ print ("_replace_basic_string lname" , lname , short_name )
46+ new_name = new_name .replace (lname , short_name )
47+
48+ print ("_replace_basic_string end" , new_name )
49+ # new_name = cls_name.replace(" ", "")
50+ # for short_name, long_names in strings.items():
51+ # for lname in long_names:
52+ # print("_replace_basic_string lname", lname, short_name)
53+ # new_name = new_name.replace(lname, short_name)
54+ # new_name = new_name.replace(",", ", ").
55+ # replace("<", "< ").replace(">", " >")
56+ # print("_replace_basic_string end", new_name)
57+ return new_name
58+
59+
2360class defaults_eraser (object ):
2461
2562 def __init__ (self , unordered_maps_and_sets ):
@@ -29,24 +66,7 @@ def normalize(self, type_str):
2966 return type_str .replace (' ' , '' )
3067
3168 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
69+ return _replace_basic_string (cls_name )
5070
5171 def decorated_call_prefix (self , cls_name , text , doit ):
5272 has_text = cls_name .startswith (text )
@@ -96,10 +116,11 @@ def erase_recursive(self, cls_name):
96116 return self .no_end_const (cls_name )
97117
98118 def erase_allocator (self , cls_name , default_allocator = 'std::allocator' ):
99- cls_name = self . replace_basic_string ( cls_name )
119+ print ( "erase_allocator" , cls_name )
100120 c_name , c_args = templates .split (cls_name )
121+ print ("c_name, c_args" , c_name , c_args )
101122 if len (c_args ) != 2 :
102- return
123+ return cls_name
103124 value_type = c_args [0 ]
104125 tmpl = string .Template (
105126 "$container< $value_type, $allocator<$value_type> >" )
@@ -109,19 +130,22 @@ def erase_allocator(self, cls_name, default_allocator='std::allocator'):
109130 allocator = default_allocator )
110131 if self .normalize (cls_name ) == \
111132 self .normalize (tmpl ):
112- return templates .join (
133+ result = templates .join (
113134 c_name , [self .erase_recursive (value_type )])
135+ print ("result" , result )
136+ print ("c_name" , c_name )
137+ print ("value_type" , value_type )
138+ return result
114139
115140 def erase_container (self , cls_name , default_container_name = 'std::deque' ):
116- cls_name = self .replace_basic_string (cls_name )
117141 c_name , c_args = templates .split (cls_name )
118142 if len (c_args ) != 2 :
119- return
143+ return cls_name
120144 value_type = c_args [0 ]
121145 dc_no_defaults = self .erase_recursive (c_args [1 ])
122146 if self .normalize (dc_no_defaults ) != self .normalize (
123147 templates .join (default_container_name , [value_type ])):
124- return
148+ return None
125149 return templates .join (
126150 c_name , [self .erase_recursive (value_type )])
127151
@@ -130,10 +154,9 @@ def erase_container_compare(
130154 cls_name ,
131155 default_container_name = 'std::vector' ,
132156 default_compare = 'std::less' ):
133- cls_name = self .replace_basic_string (cls_name )
134157 c_name , c_args = templates .split (cls_name )
135158 if len (c_args ) != 3 :
136- return
159+ return cls_name
137160 dc_no_defaults = self .erase_recursive (c_args [1 ])
138161 if self .normalize (dc_no_defaults ) != self .normalize (
139162 templates .join (default_container_name , [c_args [0 ]])):
@@ -150,10 +173,9 @@ def erase_compare_allocator(
150173 cls_name ,
151174 default_compare = 'std::less' ,
152175 default_allocator = 'std::allocator' ):
153- cls_name = self .replace_basic_string (cls_name )
154176 c_name , c_args = templates .split (cls_name )
155177 if len (c_args ) != 3 :
156- return
178+ return cls_name
157179 value_type = c_args [0 ]
158180 tmpl = string .Template (
159181 "$container< $value_type, $compare<$value_type>, " +
@@ -173,10 +195,9 @@ def erase_map_compare_allocator(
173195 cls_name ,
174196 default_compare = 'std::less' ,
175197 default_allocator = 'std::allocator' ):
176- cls_name = self .replace_basic_string (cls_name )
177198 c_name , c_args = templates .split (cls_name )
178199 if len (c_args ) != 4 :
179- return
200+ return cls_name
180201 key_type = c_args [0 ]
181202 mapped_type = c_args [1 ]
182203 tmpls = [
@@ -203,10 +224,9 @@ def erase_map_compare_allocator(
203224 self .erase_recursive (mapped_type )])
204225
205226 def erase_hash_allocator (self , cls_name ):
206- cls_name = self .replace_basic_string (cls_name )
207227 c_name , c_args = templates .split (cls_name )
208228 if len (c_args ) < 3 :
209- return
229+ return cls_name
210230
211231 default_less = 'std::less'
212232 default_equal_to = 'std::equal_to'
@@ -223,7 +243,7 @@ def erase_hash_allocator(self, cls_name):
223243 "$container< $value_type, $hash<$value_type >, " +
224244 "$equal_to<$value_type >, $allocator<$value_type> >" )
225245 else :
226- return
246+ return cls_name
227247
228248 value_type = c_args [0 ]
229249 template = string .Template (tmpl )
@@ -241,7 +261,6 @@ def erase_hash_allocator(self, cls_name):
241261 c_name , [self .erase_recursive (value_type )])
242262
243263 def erase_hashmap_compare_allocator (self , cls_name ):
244- cls_name = self .replace_basic_string (cls_name )
245264 c_name , c_args = templates .split (cls_name )
246265
247266 if self .unordered_maps_and_sets :
@@ -255,7 +274,7 @@ def erase_hashmap_compare_allocator(self, cls_name):
255274 key_type = c_args [0 ]
256275 mapped_type = c_args [1 ]
257276 else :
258- return
277+ return cls_name
259278
260279 if len (c_args ) == 4 :
261280 default_hash = 'hash_compare'
@@ -302,7 +321,7 @@ def erase_hashmap_compare_allocator(self, cls_name):
302321 "$equal_to<$key_type>, " +
303322 "$allocator< $mapped_type > >" )
304323 else :
305- return
324+ return cls_name
306325
307326 for ns in std_namespaces :
308327 inst = tmpl .substitute (
@@ -517,15 +536,18 @@ def remove_defaults(self, type_or_string):
517536 std::vector< int >
518537
519538 """
520-
521539 name = type_or_string
522540 if not isinstance (type_or_string , str ):
541+ print (
542+ "xxxx" ,
543+ type (self .class_declaration (type_or_string )),
544+ self .class_declaration (type_or_string ).name
545+ )
523546 name = self .class_declaration (type_or_string ).name
524547 if not self .remove_defaults_impl :
525548 return name
549+ name = _replace_basic_string (name )
526550 no_defaults = self .remove_defaults_impl (name )
527- if not no_defaults :
528- return name
529551 return no_defaults
530552
531553
0 commit comments