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
doc
modules
java/generator
python/src2

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

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

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