Skip to content

Commit 7b51283

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

File tree

9 files changed

+122
-110
lines changed

9 files changed

+122
-110
lines changed

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: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ 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,
@@ -118,15 +118,16 @@ def erase_allocator(self, cls_name, default_allocator='std::allocator'):
118118
def erase_container(self, cls_name, default_container_name='std::deque'):
119119
cls_name = self.replace_basic_string(cls_name)
120120
c_name, c_args = templates.split(cls_name)
121+
print("erase_container c_name, c_args", c_name, c_args)
121122
if len(c_args) != 2:
122123
return
123124
value_type = c_args[0]
124125
dc_no_defaults = self.erase_recursive(c_args[1])
125-
if self.normalize(dc_no_defaults) != self.normalize(
126+
print("erase_container dc_no_defaults", dc_no_defaults)
127+
if self.normalize(dc_no_defaults) == self.normalize(
126128
templates.join(default_container_name, [value_type])):
127-
return
128-
return templates.join(
129-
c_name, [self.erase_recursive(value_type)])
129+
return templates.join(
130+
c_name, [self.erase_recursive(value_type)])
130131

131132
def erase_container_compare(
132133
self,
@@ -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/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_call_invocation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def test_split_on_map():
6262

6363

6464
def test_join_on_vector():
65-
assert "vector( int, std::allocator(int) )" == \
65+
assert "vector(int, std::allocator(int))" == \
6666
declarations.call_invocation.join(
6767
"vector", ("int", "std::allocator(int)"))
6868

tests/test_find_container_traits.py

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99

1010
from pygccxml import parser
1111
from pygccxml import declarations
12+
from pygccxml import utils
13+
14+
import logging
15+
utils.loggers.set_level(logging.DEBUG)
1216

1317
TEST_FILES = ["remove_template_defaults.hpp", "indexing_suites2.hpp"]
1418

@@ -17,6 +21,7 @@
1721
def global_ns():
1822
COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE
1923
config = autoconfig.cxx_parsers_cfg.config.clone()
24+
config.keep_xml = True
2025
decls = parser.parse(TEST_FILES, config, COMPILATION_MODE)
2126
global_ns = declarations.get_global_namespace(decls)
2227
global_ns.init_optimizer()
@@ -33,7 +38,6 @@ def __cmp_traits(global_ns, typedef, expected, partial_name, key_type=None):
3338
assert declarations.find_container_traits(cls) == expected
3439
assert cls.partial_name == partial_name
3540
cls = traits.class_declaration(cls)
36-
print("xxxx", traits, typedef)
3741
assert traits.element_type(typedef) is not None
3842
assert cls.cache.container_element_type is not None
3943

@@ -51,91 +55,92 @@ def test_find_traits(global_ns):
5155
global_ns,
5256
"v_int",
5357
declarations.vector_traits,
54-
"vector< int >"
58+
"vector<int>"
5559
)
5660
__cmp_traits(
5761
global_ns,
5862
"l_int",
5963
declarations.list_traits,
60-
"list< int >"
64+
"list<int>"
6165
)
6266
__cmp_traits(
63-
global_ns, "d_v_int",
67+
global_ns,
68+
"d_v_int",
6469
declarations.deque_traits,
65-
"deque< std::vector< int > >"
70+
"deque<std::vector<int> >"
6671
)
6772
__cmp_traits(
6873
global_ns, "q_int",
6974
declarations.queue_traits,
70-
"queue< int >"
75+
"queue<int>"
7176
)
7277
__cmp_traits(
7378
global_ns, "pq_int",
7479
declarations.priority_queue_traits,
75-
"priority_queue< int >"
80+
"priority_queue<int>"
7681
)
7782
__cmp_traits(
7883
global_ns, "s_v_int",
7984
declarations.set_traits,
80-
"set< std::vector< int > >"
85+
"set<std::vector<int> >"
8186
)
8287
__cmp_traits(
8388
global_ns,
8489
"ms_v_int",
8590
declarations.multiset_traits,
86-
"multiset< std::vector< int > >",
91+
"multiset<std::vector<int> >",
8792
)
8893
__cmp_traits(
8994
global_ns, "m_i2d",
9095
declarations.map_traits,
91-
"map< int, double >",
96+
"map<int, double>",
9297
"int"
9398
)
9499
__cmp_traits(
95100
global_ns,
96101
"mm_i2d",
97102
declarations.multimap_traits,
98-
"multimap< int, double >",
103+
"multimap<int, double>",
99104
"int",
100105
)
101106
__cmp_traits(
102107
global_ns,
103108
"hs_v_int",
104109
declarations.unordered_set_traits,
105-
"unordered_set< std::vector< int > >",
110+
"unordered_set<std::vector<int> >",
106111
)
107112
__cmp_traits(
108113
global_ns,
109114
"mhs_v_int",
110115
declarations.unordered_multiset_traits,
111-
"unordered_multiset< std::vector< int > >",
116+
"unordered_multiset<std::vector<int> >",
112117
)
113118
__cmp_traits(
114119
global_ns,
115120
"hm_i2d",
116121
declarations.unordered_map_traits,
117-
"unordered_map< int, double >",
122+
"unordered_map<int, double>",
118123
"int",
119124
)
120125
__cmp_traits(
121126
global_ns,
122127
"hmm_i2d",
123128
declarations.unordered_multimap_traits,
124-
"unordered_multimap< int, double >",
129+
"unordered_multimap<int, double>",
125130
"int",
126131
)
127132

128133

129134
def test_multimap(global_ns):
130135
m = global_ns.class_(lambda decl: decl.name.startswith("multimap"))
131136
declarations.find_container_traits(m)
132-
assert m.partial_name == "multimap< int, int >"
137+
assert m.partial_name == "multimap<int, int>"
133138

134139

135140
def test_recursive_partial_name(global_ns):
136141
f1 = global_ns.free_function("f1")
137142
t1 = declarations.class_traits.get_declaration(f1.arguments[0].decl_type)
138-
assert "type< std::set< std::vector< int > > >" == t1.partial_name
143+
assert "type<std::set<std::vector<int> >>" == t1.partial_name
139144

140145

141146
def test_remove_defaults_partial_name_namespace(global_ns):
@@ -154,7 +159,7 @@ def test_from_ogre():
154159
"map<std::string, bool (*)(std::string&, "
155160
+ "Ogre::MaterialScriptContext&), std::less<std::string>, "
156161
+ "std::allocator<std::pair<std::string const, bool (*)"
157-
+ "(std::string&, Ogre::MaterialScriptContext&)> > >"
162+
+ "(std::string&, Ogre::MaterialScriptContext&)>>>"
158163
)
159164
ct = declarations.find_container_traits(x)
160165
ct.remove_defaults(x)

0 commit comments

Comments
 (0)