correctly parse types with spaces in their names (e.g. unsigned long)
MODIFY
gen_rust.py
gen_rust.py
@@ -694,7 +694,7 @@ class FuncInfo(GeneralInfo):
return io.getvalue()
def c_name(self):
- return "cv_%s_%s" % (self.gen.module, self.identifier.replace("::", ""))
+ return "cv_%s_%s" % (self.gen.module, self.identifier.replace("::", "").replace(" ", "_"))
def r_name(self):
if self._r_name is not None:
@@ -1028,7 +1028,7 @@ class PrimitiveTypeInfo(TypeInfo):
self.ctype = primitives[typeid]["ctype"]
self.cpptype = typeid
self.rust_extern = self.rust_full = self.rust_local = primitives[typeid]["rust_local"]
- self.sane = typeid
+ self.sane = typeid.replace(" ", "_")
self.c_sane = self.ctype.replace(" ", "_").replace("*", "X").replace("::", "_")
def __str__(self):

MODIFY
hdr_parser.py
hdr_parser.py
@@ -70,6 +70,16 @@ class CppHeaderParser(object):
return arg_str[npos2+1:npos3].strip(), npos3
+ def is_spaced_type_def(self, built_type, token):
+ if built_type == "unsigned" and (token == "long" or token == "int" or token == "short" or token == "char"):
+ return True
+ if built_type == "long" and token == "long":
+ return True
+ if built_type == "unsigned long" and token == "long":
+ return True
+ return False
+
+
def parse_arg(self, arg_str, argno):
"""
Parses <arg_type> [arg_name]
@@ -177,10 +187,12 @@ class CppHeaderParser(object):
angle_stack[-1] += 1
elif arg_type == "struct":
arg_type += " " + w
- elif arg_type and arg_type != "~":
+ elif arg_type and arg_type != "~" and not self.is_spaced_type_def(arg_type, w):
arg_name = " ".join(word_list[wi:])
break
else:
+ if arg_type:
+ arg_type += " "
arg_type += w
prev_w = w

correctly parse types with spaces in their names (e.g. unsigned long)