Merge pull request #12303 from cv3d:improvements/binding_python
This commit is contained in:
@@ -680,7 +680,7 @@ class FuncInfo(object):
|
||||
defval0 = "0"
|
||||
tp1 = tp.replace("*", "_ptr")
|
||||
tp_candidates = [a.tp, normalize_class_name(self.namespace + "." + a.tp)]
|
||||
if any(tp in codegen.enum_types for tp in tp_candidates):
|
||||
if any(tp in codegen.enumTypes for tp in tp_candidates):
|
||||
defval0 = "static_cast<%s>(%d)" % (a.tp, 0)
|
||||
|
||||
amapping = simple_argtype_mapping.get(tp, (tp, "O", defval0))
|
||||
@@ -855,7 +855,7 @@ class PythonWrapperGenerator(object):
|
||||
self.classes = {}
|
||||
self.namespaces = {}
|
||||
self.consts = {}
|
||||
self.enum_types = []
|
||||
self.enumTypes = []
|
||||
self.code_include = StringIO()
|
||||
self.code_types = StringIO()
|
||||
self.code_funcs = StringIO()
|
||||
@@ -914,8 +914,16 @@ class PythonWrapperGenerator(object):
|
||||
#print(cname + ' => ' + str(py_name) + ' (value=' + value + ')')
|
||||
|
||||
def add_enum(self, name, decl):
|
||||
enumname = normalize_class_name(name)
|
||||
self.enum_types.append(enumname)
|
||||
enumType = normalize_class_name(name)
|
||||
if enumType.endswith("<unnamed>"):
|
||||
enumType = None
|
||||
else:
|
||||
self.enumTypes.append(enumType)
|
||||
const_decls = decl[3]
|
||||
|
||||
for decl in const_decls:
|
||||
name = decl[0]
|
||||
self.add_const(name.replace("const ", "").strip(), decl)
|
||||
|
||||
def add_func(self, decl):
|
||||
namespace, classes, barename = self.split_decl_name(decl[0])
|
||||
@@ -987,10 +995,10 @@ class PythonWrapperGenerator(object):
|
||||
|
||||
self.code_ns_reg.write('static ConstDef consts_%s[] = {\n'%wname)
|
||||
for name, cname in sorted(ns.consts.items()):
|
||||
self.code_ns_reg.write(' {"%s", %s},\n'%(name, cname))
|
||||
self.code_ns_reg.write(' {"%s", static_cast<long>(%s)},\n'%(name, cname))
|
||||
compat_name = re.sub(r"([a-z])([A-Z])", r"\1_\2", name).upper()
|
||||
if name != compat_name:
|
||||
self.code_ns_reg.write(' {"%s", %s},\n'%(compat_name, cname))
|
||||
self.code_ns_reg.write(' {"%s", static_cast<long>(%s)},\n'%(compat_name, cname))
|
||||
self.code_ns_reg.write(' {NULL, 0}\n};\n\n')
|
||||
|
||||
def gen_namespaces_reg(self):
|
||||
@@ -1035,7 +1043,7 @@ class PythonWrapperGenerator(object):
|
||||
self.add_const(name.replace("const ", "").strip(), decl)
|
||||
elif name.startswith("enum"):
|
||||
# enum
|
||||
self.add_enum(name.replace("enum ", "").strip(), decl)
|
||||
self.add_enum(name.rsplit(" ", 1)[1], decl)
|
||||
else:
|
||||
# function
|
||||
self.add_func(decl)
|
||||
|
||||
@@ -634,8 +634,8 @@ class CppHeaderParser(object):
|
||||
block_type, block_name = b[self.BLOCK_TYPE], b[self.BLOCK_NAME]
|
||||
if block_type in ["file", "enum"]:
|
||||
continue
|
||||
if block_type not in ["struct", "class", "namespace"]:
|
||||
print("Error at %d: there are non-valid entries in the current block stack " % (self.lineno, self.block_stack))
|
||||
if block_type not in ["struct", "class", "namespace", "enum struct", "enum class"]:
|
||||
print("Error at %d: there are non-valid entries in the current block stack %s" % (self.lineno, self.block_stack))
|
||||
sys.exit(-1)
|
||||
if block_name and (block_type == "namespace" or not qualified_name):
|
||||
n += block_name + "."
|
||||
@@ -712,7 +712,7 @@ class CppHeaderParser(object):
|
||||
return stmt_type, classname, True, decl
|
||||
|
||||
if stmt.startswith("enum") or stmt.startswith("namespace"):
|
||||
stmt_list = stmt.split()
|
||||
stmt_list = stmt.rsplit(" ", 1)
|
||||
if len(stmt_list) < 2:
|
||||
stmt_list.append("<unnamed>")
|
||||
return stmt_list[0], stmt_list[1], True, None
|
||||
@@ -720,10 +720,10 @@ class CppHeaderParser(object):
|
||||
if stmt.startswith("extern") and "\"C\"" in stmt:
|
||||
return "namespace", "", True, None
|
||||
|
||||
if end_token == "}" and context == "enum":
|
||||
if end_token == "}" and context.startswith("enum"):
|
||||
decl = self.parse_enum(stmt)
|
||||
name = stack_top[self.BLOCK_NAME]
|
||||
return "enum", name, False, decl
|
||||
return context, name, False, decl
|
||||
|
||||
if end_token == ";" and stmt.startswith("typedef"):
|
||||
# TODO: handle typedef's more intelligently
|
||||
@@ -900,10 +900,8 @@ class CppHeaderParser(object):
|
||||
docstring = docstring.strip()
|
||||
stmt_type, name, parse_flag, decl = self.parse_stmt(stmt, token, docstring=docstring)
|
||||
if decl:
|
||||
if stmt_type == "enum":
|
||||
if name != "<unnamed>":
|
||||
decls.append(["enum " + self.get_dotted_name(name), "", [], [], None, ""])
|
||||
decls.extend(decl)
|
||||
if stmt_type.startswith("enum"):
|
||||
decls.append([stmt_type + " " + self.get_dotted_name(name), "", [], decl, None, ""])
|
||||
else:
|
||||
decls.append(decl)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user