Improve function arguments parsing and checking

* always use "argN" names for unnamed arguments
* honor space symbol between typename and "*", "&" symbols
* fix indent errors
This commit is contained in:
Andrey Kamaev 2012-11-12 14:42:28 +04:00
parent 5f41971305
commit aabbe11e64
3 changed files with 41 additions and 35 deletions

View File

@ -116,6 +116,8 @@ def compareSignatures(f, s):
sarg = arg[1] sarg = arg[1]
ftype = re.sub(r"\b(cv|std)::", "", (farg[0] or "")) ftype = re.sub(r"\b(cv|std)::", "", (farg[0] or ""))
stype = re.sub(r"\b(cv|std)::", "", (sarg[0] or "")) stype = re.sub(r"\b(cv|std)::", "", (sarg[0] or ""))
ftype = re.sub(r" (&|\*)$", "\\1", ftype)
stype = re.sub(r" (&|\*)$", "\\1", stype)
if ftype != stype: if ftype != stype:
return False, "type of argument #" + str(idx+1) + " mismatch" return False, "type of argument #" + str(idx+1) + " mismatch"
fname = farg[1] or "arg" + str(idx) fname = farg[1] or "arg" + str(idx)
@ -151,6 +153,7 @@ def formatSignature(s):
if idx > 0: if idx > 0:
_str += ", " _str += ", "
argtype = re.sub(r"\bcv::", "", arg[0]) argtype = re.sub(r"\bcv::", "", arg[0])
argtype = re.sub(r" (&|\*)$", "\\1", argtype)
bidx = argtype.find('[') bidx = argtype.find('[')
if bidx < 0: if bidx < 0:
_str += argtype + " " _str += argtype + " "

View File

@ -11,7 +11,7 @@ params_blacklist = {
"fromarray" : ("object", "allowND"), # python only function "fromarray" : ("object", "allowND"), # python only function
"reprojectImageTo3D" : ("ddepth"), # python only argument "reprojectImageTo3D" : ("ddepth"), # python only argument
"composeRT" : ("d*d*"), # wildchards in parameter names are not supported by this parser "composeRT" : ("d*d*"), # wildchards in parameter names are not supported by this parser
"CvSVM::train_auto" : ("\*Grid"), # wildchards in parameter names are not supported by this parser "CvSVM::train_auto" : ("\\*Grid"), # wildchards in parameter names are not supported by this parser
"error" : "args", # parameter of supporting macro "error" : "args", # parameter of supporting macro
"getConvertElem" : ("from", "cn", "to", "beta", "alpha"), # arguments of returned functions "getConvertElem" : ("from", "cn", "to", "beta", "alpha"), # arguments of returned functions
"gpu::swapChannels" : ("dstOrder") # parameter is not parsed correctly by the hdr_parser "gpu::swapChannels" : ("dstOrder") # parameter is not parsed correctly by the hdr_parser
@ -71,7 +71,8 @@ class DeclarationParser(object):
def isready(self): def isready(self):
return self.balance == 0 return self.balance == 0
def getLang(self, line): @classmethod
def getLang(cls, line):
if line.startswith(".. ocv:function::"): if line.startswith(".. ocv:function::"):
return "C++" return "C++"
if line.startswith(".. ocv:cfunction::"): if line.startswith(".. ocv:cfunction::"):
@ -115,7 +116,8 @@ class ParamParser(object):
else: else:
self.active = False self.active = False
def hasDeclaration(self, line): @classmethod
def hasDeclaration(cls, line):
return line.lstrip().startswith(":param") return line.lstrip().startswith(":param")
class RstParser(object): class RstParser(object):
@ -177,6 +179,7 @@ class RstParser(object):
was_code_line = False was_code_line = False
fdecl = DeclarationParser() fdecl = DeclarationParser()
pdecl = ParamParser() pdecl = ParamParser()
ll = None
for l in lines: for l in lines:
# read tail of function/method declaration if needed # read tail of function/method declaration if needed
@ -206,9 +209,7 @@ class RstParser(object):
if skip_code_lines: if skip_code_lines:
if not l: if not l:
continue continue
if l.startswith(" "): if not l.startswith(" "):
None
else:
skip_code_lines = False skip_code_lines = False
if ll.startswith(".. code-block::") or ll.startswith(".. image::"): if ll.startswith(".. code-block::") or ll.startswith(".. image::"):
@ -300,12 +301,12 @@ class RstParser(object):
if (was_code_line): if (was_code_line):
func["long"] = func.get("long", "") + "\n" + ll + "\n" func["long"] = func.get("long", "") + "\n" + ll + "\n"
else: else:
was_code_line = True; was_code_line = True
func["long"] = func.get("long", "") + ll +"\n<code>\n\n // C++ code:\n\n" func["long"] = func.get("long", "") + ll +"\n<code>\n\n // C++ code:\n\n"
else: else:
if (was_code_line): if (was_code_line):
func["long"] = func.get("long", "") + "\n" + ll + "\n</code>\n"; func["long"] = func.get("long", "") + "\n" + ll + "\n</code>\n"
was_code_line = False; was_code_line = False
else: else:
func["long"] = func.get("long", "") + "\n" + ll func["long"] = func.get("long", "") + "\n" + ll
# endfor l in lines # endfor l in lines
@ -377,7 +378,8 @@ class RstParser(object):
if len(lines) > 1: if len(lines) > 1:
self.parse_section_safe(module_name, fname, doc, flineno, lines) self.parse_section_safe(module_name, fname, doc, flineno, lines)
def parse_namespace(self, func, section_name): @classmethod
def parse_namespace(cls, func, section_name):
known_namespaces = ["cv", "gpu", "flann"] known_namespaces = ["cv", "gpu", "flann"]
l = section_name.strip() l = section_name.strip()
for namespace in known_namespaces: for namespace in known_namespaces:
@ -398,7 +400,8 @@ class RstParser(object):
decls.append( [decl.lang, decl.fdecl] ) decls.append( [decl.lang, decl.fdecl] )
func["decls"] = decls func["decls"] = decls
def add_new_pdecl(self, func, decl): @classmethod
def add_new_pdecl(cls, func, decl):
params = func.get("params", {}) params = func.get("params", {})
if decl.name in params: if decl.name in params:
if show_errors: if show_errors:

View File

@ -337,10 +337,10 @@ class CppHeaderParser(object):
atype = arg[:pos+1].strip() atype = arg[:pos+1].strip()
if aname.endswith("&") or aname.endswith("*") or (aname in ["int", "string", "Mat"]): if aname.endswith("&") or aname.endswith("*") or (aname in ["int", "string", "Mat"]):
atype = (atype + " " + aname).strip() atype = (atype + " " + aname).strip()
aname = "param" aname = ""
else: else:
atype = arg atype = arg
aname = "param" aname = ""
if aname.endswith("]"): if aname.endswith("]"):
bidx = aname.find('[') bidx = aname.find('[')
atype += aname[bidx:] atype += aname[bidx:]