Skip to content

Commit d0a11a1

Browse files
committed
scanner: debug spaces in templates
1 parent ea300f6 commit d0a11a1

File tree

7 files changed

+80
-69
lines changed

7 files changed

+80
-69
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,4 @@ jobs:
102102
- name: Run tests
103103
run: |
104104
export PATH=~/castxml/bin:$PATH
105-
pytest tests
105+
pytest tests/test_remove_template_defaults.py

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,5 @@ docs = [
6464
examples = [
6565
"notebook",
6666
]
67+
[tool.pytest.ini_options]
68+
pythonpath = ["src"]

src/pygccxml/declarations/container_traits.py

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,16 @@ def erase_allocator(self, cls_name, default_allocator='std::allocator'):
105105
return
106106
value_type = c_args[0]
107107
tmpl = string.Template(
108-
"$container< $value_type, $allocator<$value_type> >")
108+
"$container<$value_type, $allocator<$value_type>>")
109109
tmpl = tmpl.substitute(
110110
container=c_name,
111111
value_type=value_type,
112112
allocator=default_allocator)
113113
if self.normalize(cls_name) == \
114114
self.normalize(tmpl):
115-
return templates.join(
115+
x = templates.join(
116116
c_name, [self.erase_recursive(value_type)])
117+
return x
117118

118119
def erase_container(self, cls_name, default_container_name='std::deque'):
119120
cls_name = self.replace_basic_string(cls_name)
@@ -159,8 +160,8 @@ def erase_compare_allocator(
159160
return
160161
value_type = c_args[0]
161162
tmpl = string.Template(
162-
"$container< $value_type, $compare<$value_type>, " +
163-
"$allocator<$value_type> >")
163+
"$container<$value_type, $compare<$value_type>, " +
164+
"$allocator<$value_type>>")
164165
tmpl = tmpl.substitute(
165166
container=c_name,
166167
value_type=value_type,
@@ -184,14 +185,14 @@ def erase_map_compare_allocator(
184185
mapped_type = c_args[1]
185186
tmpls = [
186187
string.Template(
187-
"$container< $key_type, $mapped_type, $compare<$key_type>, " +
188-
"$allocator< std::pair< const $key_type, $mapped_type> > >"),
188+
"$container<$key_type, $mapped_type, $compare<$key_type>, " +
189+
"$allocator<std::pair<const $key_type, $mapped_type>>>"),
189190
string.Template(
190-
"$container< $key_type, $mapped_type, $compare<$key_type>, " +
191-
"$allocator< std::pair< $key_type const, $mapped_type> > >"),
191+
"$container<$key_type, $mapped_type, $compare<$key_type>, " +
192+
"$allocator<std::pair< $key_type const, $mapped_type>>>"),
192193
string.Template(
193-
"$container< $key_type, $mapped_type, $compare<$key_type>, " +
194-
"$allocator< std::pair< $key_type, $mapped_type> > >")]
194+
"$container<$key_type, $mapped_type, $compare<$key_type>, " +
195+
"$allocator<std::pair<$key_type, $mapped_type>>>")]
195196
for tmpl in tmpls:
196197
tmpl = tmpl.substitute(
197198
container=c_name,
@@ -218,13 +219,13 @@ def erase_hash_allocator(self, cls_name):
218219
if len(c_args) == 3:
219220
default_hash = 'hash_compare'
220221
tmpl = (
221-
"$container< $value_type, $hash<$value_type, " +
222-
"$less<$value_type> >, $allocator<$value_type> >")
222+
"$container<$value_type, $hash<$value_type, " +
223+
"$less<$value_type>>, $allocator<$value_type>>")
223224
elif len(c_args) == 4:
224225
default_hash = 'hash'
225226
tmpl = (
226-
"$container< $value_type, $hash<$value_type >, " +
227-
"$equal_to<$value_type >, $allocator<$value_type> >")
227+
"$container<$value_type, $hash<$value_type>, " +
228+
"$equal_to<$value_type>, $allocator<$value_type>>")
228229
else:
229230
return
230231

@@ -263,14 +264,14 @@ def erase_hashmap_compare_allocator(self, cls_name):
263264
if len(c_args) == 4:
264265
default_hash = 'hash_compare'
265266
tmpl = string.Template(
266-
"$container< $key_type, $mapped_type, " +
267-
"$hash<$key_type, $less<$key_type> >, " +
268-
"$allocator< std::pair< const $key_type, $mapped_type> > >")
267+
"$container<$key_type, $mapped_type, " +
268+
"$hash<$key_type, $less<$key_type>>, " +
269+
"$allocator<std::pair<const $key_type, $mapped_type>>>")
269270
if key_type.startswith('const ') or key_type.endswith(' const'):
270271
tmpl = string.Template(
271-
"$container< $key_type, $mapped_type, $hash<$key_type, " +
272-
"$less<$key_type> >, $allocator< std::pair< $key_type, " +
273-
"$mapped_type> > >")
272+
"$container<$key_type, $mapped_type, $hash<$key_type, " +
273+
"$less<$key_type>>, $allocator<std::pair<$key_type, " +
274+
"$mapped_type>>>")
274275
elif len(c_args) == 5:
275276
default_hash = 'hash'
276277
if self.unordered_maps_and_sets:
@@ -279,31 +280,31 @@ def erase_hashmap_compare_allocator(self, cls_name):
279280
"$hash<$key_type>, " +
280281
"$equal_to<$key_type>, " +
281282
"$allocator<std::pair<const$key_type, " +
282-
"$mapped_type> > >")
283+
"$mapped_type>>>")
283284
if key_type.startswith('const ') or \
284285
key_type.endswith(' const'):
285286
tmpl = string.Template(
286287
"$container<$key_type, $mapped_type, " +
287-
"$hash<$key_type >, " +
288-
"$equal_to<$key_type >, " +
288+
"$hash<$key_type>, " +
289+
"$equal_to<$key_type>, " +
289290
"$allocator<std::pair<$key_type, " +
290-
"$mapped_type> > >")
291+
"$mapped_type>>>")
291292
else:
292293
tmpl = string.Template(
293-
"$container< $key_type, $mapped_type, "
294+
"$container<$key_type, $mapped_type, "
294295
"$hash<$key_type >, " +
295296
"$equal_to<$key_type>, "
296-
"$allocator< $mapped_type> >")
297+
"$allocator<$mapped_type>>")
297298
if key_type.startswith('const ') or \
298299
key_type.endswith(' const'):
299300
# TODO: this template is the same than above.
300301
# Make sure why this was needed and if this is
301302
# tested. There may be a const missing somewhere.
302303
tmpl = string.Template(
303-
"$container< $key_type, $mapped_type, " +
304-
"$hash<$key_type >, " +
304+
"$container<$key_type, $mapped_type, " +
305+
"$hash<$key_type>, " +
305306
"$equal_to<$key_type>, " +
306-
"$allocator< $mapped_type > >")
307+
"$allocator<$mapped_type>>")
307308
else:
308309
return
309310

src/pygccxml/declarations/pattern_parser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,11 @@ def join(self, name, args, arg_separator=None):
192192
args = [_f for _f in args if _f]
193193

194194
if not args:
195-
args_str = ' '
195+
args_str = ''
196196
elif len(args) == 1:
197-
args_str = ' ' + args[0] + ' '
197+
args_str = args[0]
198198
else:
199-
args_str = ' ' + arg_separator.join(args) + ' '
199+
args_str = arg_separator.join(args)
200200

201201
return ''.join([name, self.__begin, args_str, self.__end])
202202

src/pygccxml/declarations/type_traits.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,15 @@ def remove_alias(type_):
5252
Returns:
5353
type_t: the type associated to the inputted declaration
5454
"""
55+
print("remove_alias", type_)
5556
if isinstance(type_, cpptypes.type_t):
5657
type_ref = type_
5758
elif isinstance(type_, typedef.typedef_t):
5859
type_ref = type_.decl_type
5960
else:
6061
# Not a valid input, just return it
6162
return type_
63+
print("remove_alias type_ref", type_ref)
6264
if type_ref.cache.remove_alias:
6365
return type_ref.cache.remove_alias
6466
no_alias = __remove_alias(type_ref.clone())

src/pygccxml/parser/scanner.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ def members(self):
286286

287287
def startElement(self, name, attrs):
288288

289+
# print(attrs)
290+
289291
try:
290292
if name not in self.__readers:
291293
return
@@ -654,6 +656,7 @@ def __read_variable(self, attrs):
654656

655657
def __read_class_impl(self, class_type, attrs):
656658
name = attrs.get(XML_AN_NAME, '')
659+
# name = name.replace(">", " >").replace("<", "< ")
657660
if '$' in name or '.' in name:
658661
name = ''
659662
if XML_AN_INCOMPLETE in attrs:

tests/test_remove_template_defaults.py

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
'remove_template_defaults.hpp'
1818
]
1919

20+
# import logging
21+
# utils.loggers.set_level(logging.DEBUG)
22+
2023

2124
@pytest.fixture
2225
def global_ns():
@@ -37,149 +40,149 @@ def global_ns():
3740
def test_vector(global_ns):
3841
v_int = global_ns.typedef('v_int')
3942
v_traits = declarations.vector_traits
40-
assert 'vector< int >' == v_traits.remove_defaults(v_int)
43+
assert 'vector<int>' == v_traits.remove_defaults(v_int)
4144
v_string = global_ns.typedef('v_string')
42-
assert 'vector< std::string >' == \
45+
assert 'vector<std::string>' == \
4346
v_traits.remove_defaults(v_string)
4447
v_v_int = global_ns.typedef('v_v_int')
45-
assert 'vector< std::vector< int > >' == \
48+
assert 'vector<std::vector<int>>' == \
4649
v_traits.remove_defaults(v_v_int)
4750

4851

4952
def test_list(global_ns):
5053
l_int = global_ns.typedef('l_int')
5154
l_traits = declarations.list_traits
52-
assert 'list< int >' == l_traits.remove_defaults(l_int)
55+
assert 'list<int>' == l_traits.remove_defaults(l_int)
5356
l_wstring = global_ns.typedef('l_wstring')
54-
assert 'list< std::wstring >' == l_traits.remove_defaults(l_wstring)
57+
assert 'list<std::wstring>' == l_traits.remove_defaults(l_wstring)
5558

5659

5760
def test_deque(global_ns):
5861
d_v_int = global_ns.typedef('d_v_int')
5962
d_v_traits = declarations.deque_traits
60-
assert 'deque< std::vector< int > >' == \
63+
assert 'deque<std::vector<int>>' == \
6164
d_v_traits.remove_defaults(d_v_int)
6265
d_l_string = global_ns.typedef('d_l_string')
63-
assert 'deque< std::list< std::string > >' == \
66+
assert 'deque<std::list<std::string>>' == \
6467
d_v_traits.remove_defaults(d_l_string)
6568

6669

6770
def test_queue(global_ns):
6871
q_int = global_ns.typedef('q_int')
6972
q_traits = declarations.queue_traits
70-
assert 'queue< int >' == q_traits.remove_defaults(q_int)
73+
assert 'queue<int>' == q_traits.remove_defaults(q_int)
7174
q_string = global_ns.typedef('q_string')
72-
assert 'queue< std::string >' == q_traits.remove_defaults(q_string)
75+
assert 'queue<std::string>' == q_traits.remove_defaults(q_string)
7376

7477

7578
def test_priority_queue(global_ns):
7679
pq_int = global_ns.typedef('pq_int')
7780
pq_traits = declarations.priority_queue_traits
78-
assert 'priority_queue< int >' == pq_traits.remove_defaults(pq_int)
81+
assert 'priority_queue<int>' == pq_traits.remove_defaults(pq_int)
7982
pq_string = global_ns.typedef('pq_string')
80-
assert 'priority_queue< std::string >' == \
83+
assert 'priority_queue<std::string>' == \
8184
pq_traits.remove_defaults(pq_string)
8285

8386

8487
def test_set(global_ns):
8588
s_v_int = global_ns.typedef('s_v_int')
86-
assert 'set< std::vector< int > >' == \
89+
assert 'set<std::vector<int>>' == \
8790
declarations.set_traits.remove_defaults(s_v_int)
8891
s_string = global_ns.typedef('s_string')
89-
assert 'set< std::string >' == \
92+
assert 'set<std::string>' == \
9093
declarations.set_traits.remove_defaults(s_string)
9194

9295

9396
def test_multiset(global_ns):
9497
ms_v_int = global_ns.typedef('ms_v_int')
9598
ms_v_traits = declarations.multiset_traits
96-
assert 'multiset< std::vector< int > >' == \
99+
assert 'multiset<std::vector<int>>' == \
97100
ms_v_traits.remove_defaults(ms_v_int)
98101
ms_string = global_ns.typedef('ms_string')
99-
assert 'multiset< std::string >' == \
102+
assert 'multiset<std::string>' == \
100103
ms_v_traits.remove_defaults(ms_string)
101104

102105

103106
def test_map(global_ns):
104107
m_i2d = global_ns.typedef('m_i2d')
105-
assert 'map< int, double >' == \
108+
assert 'map<int, double>' == \
106109
declarations.map_traits.remove_defaults(m_i2d)
107110
m_wstr2d = global_ns.typedef('m_wstr2d')
108-
assert 'map< std::wstring, double >' == \
111+
assert 'map<std::wstring, double>' == \
109112
declarations.map_traits.remove_defaults(m_wstr2d)
110113
m_v_i2m_wstr2d = global_ns.typedef('m_v_i2m_wstr2d')
111-
m = 'map< const std::vector< int >, std::map< std::wstring, double > >'
114+
m = 'map<const std::vector<int>, std::map<std::wstring, double>>'
112115
assert m == declarations.map_traits.remove_defaults(m_v_i2m_wstr2d)
113116

114117

115118
def test_multimap(global_ns):
116119
mm_i2d = global_ns.typedef('mm_i2d')
117120
mm_traits = declarations.multimap_traits
118-
assert 'multimap< int, double >' == mm_traits.remove_defaults(mm_i2d)
121+
assert 'multimap<int, double>' == mm_traits.remove_defaults(mm_i2d)
119122
mm_wstr2d = global_ns.typedef('mm_wstr2d')
120-
assert 'multimap< const std::wstring, double >' == \
123+
assert 'multimap<const std::wstring, double>' == \
121124
mm_traits.remove_defaults(mm_wstr2d)
122125
mm_v_i2mm_wstr2d = global_ns.typedef('mm_v_i2mm_wstr2d')
123-
assert ('multimap< const std::vector< int >, ' +
124-
'const std::multimap< const std::wstring, double > >') == \
126+
assert ('multimap<const std::vector<int>, ' +
127+
'const std::multimap<const std::wstring, double>>') == \
125128
mm_traits.remove_defaults(mm_v_i2mm_wstr2d)
126129

127130

128131
def test_hash_set(global_ns):
129132
hs_v_int = global_ns.typedef('hs_v_int')
130133
hs_traits = declarations.unordered_set_traits
131134
name = 'unordered_set'
132-
assert (name + '< std::vector< int > >') == \
135+
assert (name + '<std::vector<int>>') == \
133136
hs_traits.remove_defaults(hs_v_int), \
134137
hs_traits.remove_defaults(hs_v_int)
135138
hs_string = global_ns.typedef('hs_string')
136-
assert (name + '< std::string >') == \
139+
assert (name + '<std::string>') == \
137140
hs_traits.remove_defaults(hs_string)
138141

139142

140143
def test_hash_multiset(global_ns):
141144
mhs_v_int = global_ns.typedef('mhs_v_int')
142145
mhs_traits = declarations.unordered_multiset_traits
143146
name = 'unordered_multiset'
144-
assert (name + '< std::vector< int > >') == \
147+
assert (name + '<std::vector<int>>') == \
145148
mhs_traits.remove_defaults(mhs_v_int)
146149
mhs_string = global_ns.typedef('mhs_string')
147-
assert (name + '< std::string >') == \
150+
assert (name + '<std::string>') == \
148151
mhs_traits.remove_defaults(mhs_string)
149152

150153

151154
def test_hash_map(global_ns):
152155
hm_i2d = global_ns.typedef('hm_i2d')
153156
hm_traits = declarations.unordered_map_traits
154157
name = 'unordered_map'
155-
assert (name + '< int, double >') == \
158+
assert (name + '<int, double>') == \
156159
hm_traits.remove_defaults(hm_i2d)
157160
hm_wstr2d = global_ns.typedef('hm_wstr2d')
158-
assert (name + '< std::wstring, double >') == \
161+
assert (name + '<std::wstring, double>') == \
159162
hm_traits.remove_defaults(hm_wstr2d)
160163

161164

162165
def test_hash_multimap(global_ns):
163166
hmm_i2d = global_ns.typedef('hmm_i2d')
164167
hmm_traits = declarations.unordered_multimap_traits
165168
name = 'unordered_multimap'
166-
assert (name + '< int, double >') == \
169+
assert (name + '<int, double>') == \
167170
hmm_traits.remove_defaults(hmm_i2d)
168171
hmm_wstr2d = global_ns.typedef('hmm_wstr2d')
169-
assert (name + '< const std::wstring, double >') == \
172+
assert (name + '<const std::wstring, double>') == \
170173
hmm_traits.remove_defaults(hmm_wstr2d)
171174

172175
hmm_v_i2mm_wstr2d = global_ns.typedef('hmm_v_i2mm_wstr2d')
173176

174177
hmm_traits_value = hmm_traits.remove_defaults(hmm_v_i2mm_wstr2d)
175178

176179
possible_values = (
177-
name + '< const std::vector< int >, ' +
178-
'const __gnu_cxx::' + name + '< const std::wstring, double > >',
179-
name + '< const std::vector< int >, ' +
180+
name + '<const std::vector<int>, ' +
181+
'const __gnu_cxx::' + name + '<const std::wstring, double>>',
182+
name + '<const std::vector<int>, ' +
180183
'const std::' + utils.get_tr1(hmm_traits_value) + name +
181-
'< const std::wstring, double > >',
182-
name + '< const std::vector< int >, ' +
183-
'const stdext::' + name + '< const std::wstring, double > >')
184+
'<const std::wstring, double>>',
185+
name + '<const std::vector<int>, ' +
186+
'const stdext::' + name + '<const std::wstring, double>>')
184187

185188
assert hmm_traits_value in possible_values, hmm_traits_value

0 commit comments

Comments
 (0)