|
70 | 70 | from __future__ import print_function
|
71 | 71 | import sys, re, os
|
72 | 72 | from templates import *
|
73 |
| -from sets import Set |
74 | 73 |
|
75 | 74 | if sys.version_info[0] >= 3:
|
76 | 75 | from io import StringIO
|
@@ -185,7 +184,7 @@ def __init__(self, name, decl=None):
|
185 | 184 | self.consts = {}
|
186 | 185 | customname = False
|
187 | 186 | self.jsfuncs = {}
|
188 |
| - self.constructor_arg_num = Set() |
| 187 | + self.constructor_arg_num = set() |
189 | 188 |
|
190 | 189 | self.has_smart_ptr = False
|
191 | 190 |
|
@@ -369,21 +368,36 @@ def split_decl_name(self, name):
|
369 | 368 | return namespace, classes, chunks[-1]
|
370 | 369 |
|
371 | 370 | def add_enum(self, decl):
|
372 |
| - name = decl[1] |
| 371 | + name = decl[0].rsplit(" ", 1)[1] |
373 | 372 | namespace, classes, val = self.split_decl_name(name)
|
374 | 373 | namespace = '.'.join(namespace)
|
| 374 | + ns = self.namespaces.setdefault(namespace, Namespace()) |
| 375 | + if len(name) == 0: name = "<unnamed>" |
| 376 | + if name.endswith("<unnamed>"): |
| 377 | + i = 0 |
| 378 | + while True: |
| 379 | + i += 1 |
| 380 | + candidate_name = name.replace("<unnamed>", "unnamed_%u" % i) |
| 381 | + if candidate_name not in ns.enums: |
| 382 | + name = candidate_name |
| 383 | + break; |
375 | 384 | val = '_'.join(classes + [name])
|
376 | 385 | cname = name.replace('.', '::')
|
377 |
| - ns = self.namespaces.setdefault(namespace, Namespace()) |
378 | 386 | if name in ns.enums:
|
379 |
| - print("Generator warning: constant %s (cname=%s) already exists" \ |
| 387 | + print("Generator warning: enum %s (cname=%s) already exists" \ |
380 | 388 | % (name, cname))
|
381 | 389 | # sys.exit(-1)
|
382 | 390 | else:
|
383 | 391 | ns.enums[name] = []
|
384 | 392 | for item in decl[3]:
|
385 | 393 | ns.enums[name].append(item)
|
386 | 394 |
|
| 395 | + const_decls = decl[3] |
| 396 | + |
| 397 | + for decl in const_decls: |
| 398 | + name = decl[0] |
| 399 | + self.add_const(name.replace("const ", "").strip(), decl) |
| 400 | + |
387 | 401 | def add_const(self, name, decl):
|
388 | 402 | cname = name.replace('.','::')
|
389 | 403 | namespace, classes, name = self.split_decl_name(name)
|
@@ -803,7 +817,7 @@ def gen(self, dst_file, src_files, core_bindings):
|
803 | 817 | continue
|
804 | 818 |
|
805 | 819 | # Generate bindings for methods
|
806 |
| - for method_name, method in class_info.methods.iteritems(): |
| 820 | + for method_name, method in class_info.methods.items(): |
807 | 821 | if method.cname in ignore_list:
|
808 | 822 | continue
|
809 | 823 | if not method.name in white_list[method.class_name]:
|
@@ -833,7 +847,7 @@ def gen(self, dst_file, src_files, core_bindings):
|
833 | 847 | class_bindings.append(smart_ptr_reg_template.substitute(cname=class_info.cname, name=class_info.name))
|
834 | 848 |
|
835 | 849 | # Attach external constructors
|
836 |
| - # for method_name, method in class_info.ext_constructors.iteritems(): |
| 850 | + # for method_name, method in class_info.ext_constructors.items(): |
837 | 851 | # print("ext constructor", method_name)
|
838 | 852 | #if class_info.ext_constructors:
|
839 | 853 |
|
|
0 commit comments