Changeset View
Changeset View
Standalone View
Standalone View
tools/libqtcodegen.py
Show All 15 Lines | |||||
16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | 16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
18 | # Lesser General Public License for more details. | 18 | # Lesser General Public License for more details. | ||
19 | # | 19 | # | ||
20 | # You should have received a copy of the GNU Lesser General Public | 20 | # You should have received a copy of the GNU Lesser General Public | ||
21 | # License along with this library; if not, write to the Free Software | 21 | # License along with this library; if not, write to the Free Software | ||
22 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | 22 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
23 | 23 | | |||
24 | from sys import maxint, stderr | 24 | from sys import maxsize, stderr | ||
25 | import re | 25 | import re | ||
26 | from libtpcodegen import get_by_path, get_descendant_text, NS_TP, xml_escape | 26 | from libtpcodegen import get_by_path, get_descendant_text, NS_TP, xml_escape | ||
27 | 27 | | |||
28 | class Xzibit(Exception): | 28 | class Xzibit(Exception): | ||
29 | def __init__(self, parent, child): | 29 | def __init__(self, parent, child): | ||
30 | self.parent = parent | 30 | self.parent = parent | ||
31 | self.child = child | 31 | self.child = child | ||
32 | 32 | | |||
33 | def __str__(self): | 33 | def __str__(self): | ||
34 | print """ | 34 | print(""" | ||
35 | Nested <%s>s are forbidden. | 35 | Nested <%s>s are forbidden. | ||
36 | Parent: | 36 | Parent: | ||
37 | %s... | 37 | %s... | ||
38 | Child: | 38 | Child: | ||
39 | %s... | 39 | %s... | ||
40 | """ % (self.parent.nodeName, self.parent.toxml()[:100], | 40 | """ % (self.parent.nodeName, self.parent.toxml()[:100], | ||
41 | self.child.toxml()[:100]) | 41 | self.child.toxml()[:100])) | ||
42 | 42 | | |||
43 | class _QtTypeBinding: | 43 | class _QtTypeBinding: | ||
44 | def __init__(self, val, inarg, outarg, array_val, custom_type, array_of, | 44 | def __init__(self, val, inarg, outarg, array_val, custom_type, array_of, | ||
45 | array_depth=None): | 45 | array_depth=None): | ||
46 | self.val = val | 46 | self.val = val | ||
47 | self.inarg = inarg | 47 | self.inarg = inarg | ||
48 | self.outarg = outarg | 48 | self.outarg = outarg | ||
49 | self.array_val = array_val | 49 | self.array_val = array_val | ||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Line(s) | 119 | else: | |||
120 | path = local | 120 | path = local | ||
121 | 121 | | |||
122 | target = self.targets.get(path) | 122 | target = self.targets.get(path) | ||
123 | 123 | | |||
124 | if target is None: | 124 | if target is None: | ||
125 | parent = get_closest_parent(ref, 'interface') or get_closest_parent(ref, 'error') | 125 | parent = get_closest_parent(ref, 'interface') or get_closest_parent(ref, 'error') | ||
126 | parent_name = parent.getAttribute('name') | 126 | parent_name = parent.getAttribute('name') | ||
127 | if (path + parent_name).find('.DRAFT') == -1 and (path + parent_name).find('.FUTURE') == -1: | 127 | if (path + parent_name).find('.DRAFT') == -1 and (path + parent_name).find('.FUTURE') == -1: | ||
128 | print >> stderr, 'WARNING: Failed to resolve %s to "%s" in "%s"' % ( | 128 | print(('WARNING: Failed to resolve %s to "%s" in "%s"' % ( | ||
129 | ref.localName, path, parent_name) | 129 | ref.localName, path, parent_name)), file=stderr) | ||
130 | return path | 130 | return path | ||
131 | 131 | | |||
132 | if ref.localName == 'member-ref': | 132 | if ref.localName == 'member-ref': | ||
133 | if target.kind == target.KIND_PROPERTY: | 133 | if target.kind == target.KIND_PROPERTY: | ||
134 | return '\\link %s %s \\endlink' % (target.member_link, target.member_text) | 134 | return '\\link %s %s \\endlink' % (target.member_link, target.member_text) | ||
135 | else: | 135 | else: | ||
136 | return target.member_text | 136 | return target.member_text | ||
137 | else: | 137 | else: | ||
Show All 23 Lines | 145 | natives = { | |||
161 | 'av' : ('QVariantList', True, "VariantListList"), | 161 | 'av' : ('QVariantList', True, "VariantListList"), | ||
162 | 'a{sv}' : ('QVariantMap', True, None) | 162 | 'a{sv}' : ('QVariantMap', True, None) | ||
163 | } | 163 | } | ||
164 | 164 | | |||
165 | val, inarg = None, None | 165 | val, inarg = None, None | ||
166 | custom_type = False | 166 | custom_type = False | ||
167 | array_of = None | 167 | array_of = None | ||
168 | 168 | | |||
169 | if natives.has_key(sig): | 169 | if sig in natives: | ||
170 | typename, pass_by_ref, array_name = natives[sig] | 170 | typename, pass_by_ref, array_name = natives[sig] | ||
171 | val = typename | 171 | val = typename | ||
172 | inarg = (pass_by_ref and ('const %s&' % val)) or val | 172 | inarg = (pass_by_ref and ('const %s&' % val)) or val | ||
173 | elif sig[0] == 'a' and natives.has_key(sig[1:]) and natives[sig[1:]][2]: | 173 | elif sig[0] == 'a' and sig[1:] in natives and natives[sig[1:]][2]: | ||
174 | val = natives[sig[1:]][2] | 174 | val = natives[sig[1:]][2] | ||
175 | if explicit_own_ns: | 175 | if explicit_own_ns: | ||
176 | val = explicit_own_ns + '::' + val | 176 | val = explicit_own_ns + '::' + val | ||
177 | inarg = 'const %s&' % val | 177 | inarg = 'const %s&' % val | ||
178 | array_of = natives[sig[1:]][0] | 178 | array_of = natives[sig[1:]][0] | ||
179 | elif tptype: | 179 | elif tptype: | ||
180 | tptype = tptype.replace('_', '') | 180 | tptype = tptype.replace('_', '') | ||
181 | custom_type = True | 181 | custom_type = True | ||
182 | 182 | | |||
183 | if external: | 183 | if external: | ||
184 | tptype = 'Tp::' + tptype | 184 | tptype = 'Tp::' + tptype | ||
185 | elif explicit_own_ns: | 185 | elif explicit_own_ns: | ||
186 | tptype = explicit_own_ns + '::' + tptype | 186 | tptype = explicit_own_ns + '::' + tptype | ||
187 | 187 | | |||
188 | if tptype.endswith('[]'): | 188 | if tptype.endswith('[]'): | ||
189 | tptype = tptype[:-2] | 189 | tptype = tptype[:-2] | ||
190 | extra_list_nesting = 0 | 190 | extra_list_nesting = 0 | ||
191 | 191 | | |||
192 | while tptype.endswith('[]'): | 192 | while tptype.endswith('[]'): | ||
193 | extra_list_nesting += 1 | 193 | extra_list_nesting += 1 | ||
194 | tptype = tptype[:-2] | 194 | tptype = tptype[:-2] | ||
195 | 195 | | |||
196 | assert custom_lists.has_key(tptype), ('No array version of custom type %s in the spec, but array version used' % tptype) | 196 | assert tptype in custom_lists, ('No array version of custom type %s in the spec, but array version used' % tptype) | ||
197 | val = custom_lists[tptype] + 'List' * extra_list_nesting | 197 | val = custom_lists[tptype] + 'List' * extra_list_nesting | ||
198 | else: | 198 | else: | ||
199 | val = tptype | 199 | val = tptype | ||
200 | 200 | | |||
201 | inarg = 'const %s&' % val | 201 | inarg = 'const %s&' % val | ||
202 | else: | 202 | else: | ||
203 | assert False, 'Don\'t know how to map type (%s, %s)' % (sig, tptype) | 203 | assert False, 'Don\'t know how to map type (%s, %s)' % (sig, tptype) | ||
204 | 204 | | |||
▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Line(s) | 273 | for ref in docstring_el.getElementsByTagNameNS(NS_TP, 'member-ref') + docstring_el.getElementsByTagNameNS(NS_TP, 'dbus-ref'): | |||
277 | 277 | | |||
278 | text = doc.createTextNode(' \\endhtmlonly ') | 278 | text = doc.createTextNode(' \\endhtmlonly ') | ||
279 | text.data += refs.process(ref) | 279 | text.data += refs.process(ref) | ||
280 | text.data += ' \\htmlonly ' | 280 | text.data += ' \\htmlonly ' | ||
281 | 281 | | |||
282 | ref.parentNode.replaceChild(text, ref) | 282 | ref.parentNode.replaceChild(text, ref) | ||
283 | 283 | | |||
284 | splitted = ''.join([el.toxml() for el in docstring_el.childNodes]).strip(' ').strip('\n').split('\n') | 284 | splitted = ''.join([el.toxml() for el in docstring_el.childNodes]).strip(' ').strip('\n').split('\n') | ||
285 | level = min([not match and maxint or match.end() - 1 for match in [re.match('^ *[^ ]', line) for line in splitted]]) | 285 | level = min([not match and maxsize or match.end() - 1 for match in [re.match('^ *[^ ]', line) for line in splitted]]) | ||
286 | assert level != maxint | 286 | assert level != maxsize | ||
287 | lines = ['\\htmlonly'] + [line[level:] for line in splitted] + ['\\endhtmlonly'] | 287 | lines = ['\\htmlonly'] + [line[level:] for line in splitted] + ['\\endhtmlonly'] | ||
288 | else: | 288 | else: | ||
289 | content = xml_escape(get_descendant_text(docstring_el).replace('\n', ' ').strip()) | 289 | content = xml_escape(get_descendant_text(docstring_el).replace('\n', ' ').strip()) | ||
290 | 290 | | |||
291 | while content.find(' ') != -1: | 291 | while content.find(' ') != -1: | ||
292 | content = content.replace(' ', ' ') | 292 | content = content.replace(' ', ' ') | ||
293 | 293 | | |||
294 | left = maxwidth - len(indent) - 1 | 294 | left = maxwidth - len(indent) - 1 | ||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Line(s) | 343 | def gather_custom_lists(spec, typesns): | |||
348 | 348 | | |||
349 | for (provider, ns) in structs + mappings + exts: | 349 | for (provider, ns) in structs + mappings + exts: | ||
350 | tptype = provider.getAttribute('name').replace('_', '') | 350 | tptype = provider.getAttribute('name').replace('_', '') | ||
351 | array_val = provider.getAttribute('array-name').replace('_', '') | 351 | array_val = provider.getAttribute('array-name').replace('_', '') | ||
352 | array_depth = provider.getAttribute('array-depth') | 352 | array_depth = provider.getAttribute('array-depth') | ||
353 | if array_depth: | 353 | if array_depth: | ||
354 | array_depth = int(array_depth) | 354 | array_depth = int(array_depth) | ||
355 | else: | 355 | else: | ||
356 | array_depth = None | 356 | array_depth = -1 | ||
357 | 357 | | |||
358 | if array_val: | 358 | if array_val: | ||
359 | custom_lists[tptype] = array_val | 359 | custom_lists[tptype] = array_val | ||
360 | custom_lists[ns + '::' + tptype] = ns + '::' + array_val | 360 | custom_lists[ns + '::' + tptype] = ns + '::' + array_val | ||
361 | if array_depth >= 2: | 361 | if array_depth >= 2: | ||
362 | for i in xrange(array_depth): | 362 | for i in range(array_depth): | ||
363 | custom_lists[tptype + ('[]' * (i+1))] = ( | 363 | custom_lists[tptype + ('[]' * (i+1))] = ( | ||
364 | array_val + ('List' * i)) | 364 | array_val + ('List' * i)) | ||
365 | custom_lists[ns + '::' + tptype + ('[]' * (i+1))] = ( | 365 | custom_lists[ns + '::' + tptype + ('[]' * (i+1))] = ( | ||
366 | ns + '::' + array_val + ('List' * i)) | 366 | ns + '::' + array_val + ('List' * i)) | ||
367 | 367 | | |||
368 | return custom_lists | 368 | return custom_lists | ||
369 | 369 | | |||
370 | def get_headerfile_cmd(realinclude, prettyinclude, indent=' * '): | 370 | def get_headerfile_cmd(realinclude, prettyinclude, indent=' * '): | ||
▲ Show 20 Lines • Show All 132 Lines • Show Last 20 Lines |