2013-04-11 22:34:04 +08:00
|
|
|
#!/usr/bin/env python
|
2012-11-24 02:57:22 +08:00
|
|
|
|
2013-06-13 04:02:30 +08:00
|
|
|
from __future__ import print_function
|
2014-11-10 13:39:18 +08:00
|
|
|
import os, sys, re, string, io
|
2010-10-12 23:59:00 +08:00
|
|
|
|
2010-11-03 01:58:22 +08:00
|
|
|
# the list only for debugging. The real list, used in the real OpenCV build, is specified in CMakeLists.txt
|
2010-10-29 21:09:49 +08:00
|
|
|
opencv_hdr_list = [
|
2013-03-13 20:22:44 +08:00
|
|
|
"../../core/include/opencv2/core.hpp",
|
2018-08-19 01:34:47 +08:00
|
|
|
"../../core/include/opencv2/core/mat.hpp",
|
2014-04-29 20:57:19 +08:00
|
|
|
"../../core/include/opencv2/core/ocl.hpp",
|
2011-07-14 07:04:39 +08:00
|
|
|
"../../flann/include/opencv2/flann/miniflann.hpp",
|
2013-03-13 20:22:44 +08:00
|
|
|
"../../ml/include/opencv2/ml.hpp",
|
|
|
|
"../../imgproc/include/opencv2/imgproc.hpp",
|
2020-12-02 04:42:15 +08:00
|
|
|
"../../3d/include/opencv2/3d.hpp",
|
|
|
|
"../../stereo/include/opencv2/stereo.hpp",
|
|
|
|
"../../calib/include/opencv2/calib.hpp",
|
2013-03-13 20:22:44 +08:00
|
|
|
"../../features2d/include/opencv2/features2d.hpp",
|
2011-04-17 21:09:04 +08:00
|
|
|
"../../video/include/opencv2/video/tracking.hpp",
|
|
|
|
"../../video/include/opencv2/video/background_segm.hpp",
|
2013-03-13 20:22:44 +08:00
|
|
|
"../../objdetect/include/opencv2/objdetect.hpp",
|
2014-07-04 22:48:15 +08:00
|
|
|
"../../imgcodecs/include/opencv2/imgcodecs.hpp",
|
2014-07-10 22:27:32 +08:00
|
|
|
"../../videoio/include/opencv2/videoio.hpp",
|
2016-02-08 00:04:39 +08:00
|
|
|
"../../highgui/include/opencv2/highgui.hpp",
|
2010-10-12 23:59:00 +08:00
|
|
|
]
|
|
|
|
|
|
|
|
"""
|
2017-06-12 10:18:00 +08:00
|
|
|
Each declaration is [funcname, return_value_type /* in C, not in Python */, <list_of_modifiers>, <list_of_arguments>, original_return_type, docstring],
|
2010-10-12 23:59:00 +08:00
|
|
|
where each element of <list_of_arguments> is 4-element list itself:
|
|
|
|
[argtype, argname, default_value /* or "" if none */, <list_of_modifiers>]
|
|
|
|
where the list of modifiers is yet another nested list of strings
|
|
|
|
(currently recognized are "/O" for output argument, "/S" for static (i.e. class) methods
|
2011-05-17 20:52:07 +08:00
|
|
|
and "/A value" for the plain C arrays with counters)
|
2017-06-12 10:18:00 +08:00
|
|
|
original_return_type is None if the original_return_type is the same as return_value_type
|
2010-10-12 23:59:00 +08:00
|
|
|
"""
|
|
|
|
|
|
|
|
class CppHeaderParser(object):
|
|
|
|
|
2018-08-06 19:46:46 +08:00
|
|
|
def __init__(self, generate_umat_decls=False, generate_gpumat_decls=False):
|
2016-02-08 00:04:39 +08:00
|
|
|
self._generate_umat_decls = generate_umat_decls
|
2018-08-06 19:46:46 +08:00
|
|
|
self._generate_gpumat_decls = generate_gpumat_decls
|
2016-02-08 00:04:39 +08:00
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
self.BLOCK_TYPE = 0
|
|
|
|
self.BLOCK_NAME = 1
|
|
|
|
self.PROCESS_FLAG = 2
|
|
|
|
self.PUBLIC_SECTION = 3
|
|
|
|
self.CLASS_DECL = 4
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2014-08-19 17:35:46 +08:00
|
|
|
self.namespaces = set()
|
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
def batch_replace(self, s, pairs):
|
|
|
|
for before, after in pairs:
|
|
|
|
s = s.replace(before, after)
|
|
|
|
return s
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-29 21:09:49 +08:00
|
|
|
def get_macro_arg(self, arg_str, npos):
|
|
|
|
npos2 = npos3 = arg_str.find("(", npos)
|
|
|
|
if npos2 < 0:
|
2021-09-27 15:53:23 +08:00
|
|
|
print("Error: no arguments for the macro at %s:%d" % (self.hname, self.lineno))
|
2010-10-29 21:09:49 +08:00
|
|
|
sys.exit(-1)
|
2011-05-17 20:52:07 +08:00
|
|
|
balance = 1
|
2010-10-29 21:09:49 +08:00
|
|
|
while 1:
|
|
|
|
t, npos3 = self.find_next_token(arg_str, ['(', ')'], npos3+1)
|
|
|
|
if npos3 < 0:
|
2021-09-27 15:53:23 +08:00
|
|
|
print("Error: no matching ')' in the macro call at %s:%d" % (self.hname, self.lineno))
|
2010-10-29 21:09:49 +08:00
|
|
|
sys.exit(-1)
|
|
|
|
if t == '(':
|
|
|
|
balance += 1
|
|
|
|
if t == ')':
|
|
|
|
balance -= 1
|
|
|
|
if balance == 0:
|
|
|
|
break
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-29 21:09:49 +08:00
|
|
|
return arg_str[npos2+1:npos3].strip(), npos3
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
def parse_arg(self, arg_str, argno):
|
|
|
|
"""
|
|
|
|
Parses <arg_type> [arg_name]
|
|
|
|
Returns arg_type, arg_name, modlist, argno, where
|
|
|
|
modlist is the list of wrapper-related modifiers (such as "output argument", "has counter", ...)
|
|
|
|
and argno is the new index of an anonymous argument.
|
|
|
|
That is, if no arg_str is just an argument type without argument name, the argument name is set to
|
|
|
|
"arg" + str(argno), and then argno is incremented.
|
|
|
|
"""
|
|
|
|
modlist = []
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
# pass 0: extracts the modifiers
|
|
|
|
if "CV_OUT" in arg_str:
|
|
|
|
modlist.append("/O")
|
|
|
|
arg_str = arg_str.replace("CV_OUT", "")
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-29 21:09:49 +08:00
|
|
|
if "CV_IN_OUT" in arg_str:
|
|
|
|
modlist.append("/IO")
|
|
|
|
arg_str = arg_str.replace("CV_IN_OUT", "")
|
2010-10-12 23:59:00 +08:00
|
|
|
|
|
|
|
isarray = False
|
|
|
|
npos = arg_str.find("CV_CARRAY")
|
|
|
|
if npos >= 0:
|
|
|
|
isarray = True
|
2010-10-29 21:09:49 +08:00
|
|
|
macro_arg, npos3 = self.get_macro_arg(arg_str, npos)
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-29 21:09:49 +08:00
|
|
|
modlist.append("/A " + macro_arg)
|
|
|
|
arg_str = arg_str[:npos] + arg_str[npos3+1:]
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-29 21:09:49 +08:00
|
|
|
npos = arg_str.find("CV_CUSTOM_CARRAY")
|
|
|
|
if npos >= 0:
|
|
|
|
isarray = True
|
|
|
|
macro_arg, npos3 = self.get_macro_arg(arg_str, npos)
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-29 21:09:49 +08:00
|
|
|
modlist.append("/CA " + macro_arg)
|
2010-10-12 23:59:00 +08:00
|
|
|
arg_str = arg_str[:npos] + arg_str[npos3+1:]
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2017-09-25 21:52:07 +08:00
|
|
|
npos = arg_str.find("const")
|
|
|
|
if npos >= 0:
|
|
|
|
modlist.append("/C")
|
|
|
|
|
2020-07-29 21:18:52 +08:00
|
|
|
npos = arg_str.find("&&")
|
|
|
|
if npos >= 0:
|
|
|
|
arg_str = arg_str.replace("&&", '')
|
|
|
|
modlist.append("/RRef")
|
|
|
|
|
2017-09-25 21:52:07 +08:00
|
|
|
npos = arg_str.find("&")
|
|
|
|
if npos >= 0:
|
|
|
|
modlist.append("/Ref")
|
|
|
|
|
2011-05-17 20:52:07 +08:00
|
|
|
arg_str = arg_str.strip()
|
2010-10-12 23:59:00 +08:00
|
|
|
word_start = 0
|
|
|
|
word_list = []
|
|
|
|
npos = -1
|
2011-05-17 20:52:07 +08:00
|
|
|
|
|
|
|
#print self.lineno, ":\t", arg_str
|
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
# pass 1: split argument type into tokens
|
|
|
|
while 1:
|
|
|
|
npos += 1
|
|
|
|
t, npos = self.find_next_token(arg_str, [" ", "&", "*", "<", ">", ","], npos)
|
|
|
|
w = arg_str[word_start:npos].strip()
|
|
|
|
if w == "operator":
|
|
|
|
word_list.append("operator " + arg_str[npos:].strip())
|
|
|
|
break
|
|
|
|
if w not in ["", "const"]:
|
|
|
|
word_list.append(w)
|
|
|
|
if t not in ["", " ", "&"]:
|
|
|
|
word_list.append(t)
|
|
|
|
if not t:
|
|
|
|
break
|
|
|
|
word_start = npos+1
|
|
|
|
npos = word_start - 1
|
|
|
|
|
|
|
|
arg_type = ""
|
|
|
|
arg_name = ""
|
|
|
|
angle_stack = []
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
#print self.lineno, ":\t", word_list
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
# pass 2: decrypt the list
|
|
|
|
wi = -1
|
|
|
|
prev_w = ""
|
|
|
|
for w in word_list:
|
|
|
|
wi += 1
|
|
|
|
if w == "*":
|
|
|
|
if prev_w == "char" and not isarray:
|
|
|
|
arg_type = arg_type[:-len("char")] + "c_string"
|
|
|
|
else:
|
|
|
|
arg_type += w
|
|
|
|
continue
|
|
|
|
elif w == "<":
|
|
|
|
arg_type += "_"
|
|
|
|
angle_stack.append(0)
|
|
|
|
elif w == "," or w == '>':
|
|
|
|
if not angle_stack:
|
2021-09-27 15:53:23 +08:00
|
|
|
print("Error at %s:%d: argument contains ',' or '>' not within template arguments" % (self.hname, self.lineno))
|
2010-10-12 23:59:00 +08:00
|
|
|
sys.exit(-1)
|
|
|
|
if w == ",":
|
|
|
|
arg_type += "_and_"
|
|
|
|
elif w == ">":
|
|
|
|
if angle_stack[0] == 0:
|
2013-06-13 04:02:30 +08:00
|
|
|
print("Error at %s:%d: template has no arguments" % (self.hname, self.lineno))
|
2010-10-12 23:59:00 +08:00
|
|
|
sys.exit(-1)
|
|
|
|
if angle_stack[0] > 1:
|
|
|
|
arg_type += "_end_"
|
|
|
|
angle_stack[-1:] = []
|
|
|
|
elif angle_stack:
|
|
|
|
arg_type += w
|
|
|
|
angle_stack[-1] += 1
|
2012-09-08 04:40:06 +08:00
|
|
|
elif arg_type == "struct":
|
|
|
|
arg_type += " " + w
|
2010-10-12 23:59:00 +08:00
|
|
|
elif arg_type and arg_type != "~":
|
|
|
|
arg_name = " ".join(word_list[wi:])
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
arg_type += w
|
|
|
|
prev_w = w
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
counter_str = ""
|
|
|
|
add_star = False
|
2010-10-29 21:09:49 +08:00
|
|
|
if ("[" in arg_name) and not ("operator" in arg_str):
|
|
|
|
#print arg_str
|
2010-10-12 23:59:00 +08:00
|
|
|
p1 = arg_name.find("[")
|
|
|
|
p2 = arg_name.find("]",p1+1)
|
|
|
|
if p2 < 0:
|
2021-09-27 15:53:23 +08:00
|
|
|
print("Error at %s:%d: no closing ]" % (self.hname, self.lineno))
|
2010-10-12 23:59:00 +08:00
|
|
|
sys.exit(-1)
|
|
|
|
counter_str = arg_name[p1+1:p2].strip()
|
|
|
|
if counter_str == "":
|
|
|
|
counter_str = "?"
|
|
|
|
if not isarray:
|
|
|
|
modlist.append("/A " + counter_str.strip())
|
|
|
|
arg_name = arg_name[:p1]
|
|
|
|
add_star = True
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
if not arg_name:
|
|
|
|
if arg_type.startswith("operator"):
|
|
|
|
arg_type, arg_name = "", arg_type
|
|
|
|
else:
|
|
|
|
arg_name = "arg" + str(argno)
|
|
|
|
argno += 1
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
while arg_type.endswith("_end_"):
|
|
|
|
arg_type = arg_type[:-len("_end_")]
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
if add_star:
|
|
|
|
arg_type += "*"
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2011-09-15 19:10:06 +08:00
|
|
|
arg_type = self.batch_replace(arg_type, [("std::", ""), ("cv::", ""), ("::", "_")])
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
return arg_type, arg_name, modlist, argno
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-29 21:09:49 +08:00
|
|
|
def parse_enum(self, decl_str):
|
|
|
|
l = decl_str
|
|
|
|
ll = l.split(",")
|
2014-07-23 18:54:04 +08:00
|
|
|
if ll[-1].strip() == "":
|
|
|
|
ll = ll[:-1]
|
2010-10-29 21:09:49 +08:00
|
|
|
prev_val = ""
|
|
|
|
prev_val_delta = -1
|
|
|
|
decl = []
|
|
|
|
for pair in ll:
|
|
|
|
pv = pair.split("=")
|
|
|
|
if len(pv) == 1:
|
|
|
|
prev_val_delta += 1
|
|
|
|
val = ""
|
|
|
|
if prev_val:
|
|
|
|
val = prev_val + "+"
|
|
|
|
val += str(prev_val_delta)
|
|
|
|
else:
|
|
|
|
prev_val_delta = 0
|
|
|
|
prev_val = val = pv[1].strip()
|
2017-06-12 10:18:00 +08:00
|
|
|
decl.append(["const " + self.get_dotted_name(pv[0].strip()), val, [], [], None, ""])
|
2010-10-29 21:09:49 +08:00
|
|
|
return decl
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
def parse_class_decl(self, decl_str):
|
|
|
|
"""
|
|
|
|
Parses class/struct declaration start in the form:
|
|
|
|
{class|struct} [CV_EXPORTS] <class_name> [: public <base_class1> [, ...]]
|
|
|
|
Returns class_name1, <list of base_classes>
|
|
|
|
"""
|
2010-10-29 21:09:49 +08:00
|
|
|
l = decl_str
|
|
|
|
modlist = []
|
2010-11-03 01:58:22 +08:00
|
|
|
if "CV_EXPORTS_W_MAP" in l:
|
|
|
|
l = l.replace("CV_EXPORTS_W_MAP", "")
|
2010-10-29 21:09:49 +08:00
|
|
|
modlist.append("/Map")
|
2020-12-18 20:00:42 +08:00
|
|
|
if "CV_EXPORTS_W_PARAMS" in l:
|
|
|
|
l = l.replace("CV_EXPORTS_W_PARAMS", "")
|
|
|
|
modlist.append("/Map")
|
|
|
|
modlist.append("/Params")
|
2010-11-03 01:58:22 +08:00
|
|
|
if "CV_EXPORTS_W_SIMPLE" in l:
|
|
|
|
l = l.replace("CV_EXPORTS_W_SIMPLE", "")
|
|
|
|
modlist.append("/Simple")
|
2010-10-29 21:09:49 +08:00
|
|
|
npos = l.find("CV_EXPORTS_AS")
|
2021-03-31 04:54:11 +08:00
|
|
|
if npos < 0:
|
|
|
|
npos = l.find('CV_WRAP_AS')
|
2010-10-29 21:09:49 +08:00
|
|
|
if npos >= 0:
|
|
|
|
macro_arg, npos3 = self.get_macro_arg(l, npos)
|
|
|
|
modlist.append("=" + macro_arg)
|
|
|
|
l = l[:npos] + l[npos3+1:]
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2012-01-25 21:25:35 +08:00
|
|
|
l = self.batch_replace(l, [("CV_EXPORTS_W", ""), ("CV_EXPORTS", ""), ("public virtual ", " "), ("public ", " "), ("::", ".")]).strip()
|
2016-11-11 22:45:12 +08:00
|
|
|
ll = re.split(r'\s+|\s*[,:]\s*', l)
|
2010-10-12 23:59:00 +08:00
|
|
|
ll = [le for le in ll if le]
|
|
|
|
classname = ll[1]
|
|
|
|
bases = ll[2:]
|
2010-10-29 21:09:49 +08:00
|
|
|
return classname, bases, modlist
|
2010-10-12 23:59:00 +08:00
|
|
|
|
2017-06-12 10:18:00 +08:00
|
|
|
def parse_func_decl_no_wrap(self, decl_str, static_method=False, docstring=""):
|
2012-05-28 19:22:43 +08:00
|
|
|
decl_str = (decl_str or "").strip()
|
|
|
|
virtual_method = False
|
|
|
|
explicit_method = False
|
|
|
|
if decl_str.startswith("explicit"):
|
|
|
|
decl_str = decl_str[len("explicit"):].lstrip()
|
|
|
|
explicit_method = True
|
|
|
|
if decl_str.startswith("virtual"):
|
|
|
|
decl_str = decl_str[len("virtual"):].lstrip()
|
|
|
|
virtual_method = True
|
|
|
|
if decl_str.startswith("static"):
|
|
|
|
decl_str = decl_str[len("static"):].lstrip()
|
|
|
|
static_method = True
|
|
|
|
|
2011-06-02 05:15:36 +08:00
|
|
|
fdecl = decl_str.replace("CV_OUT", "").replace("CV_IN_OUT", "")
|
|
|
|
fdecl = fdecl.strip().replace("\t", " ")
|
|
|
|
while " " in fdecl:
|
|
|
|
fdecl = fdecl.replace(" ", " ")
|
|
|
|
fname = fdecl[:fdecl.find("(")].strip()
|
|
|
|
fnpos = fname.rfind(" ")
|
|
|
|
if fnpos < 0:
|
|
|
|
fnpos = 0
|
|
|
|
fname = fname[fnpos:].strip()
|
|
|
|
rettype = fdecl[:fnpos].strip()
|
2011-07-13 05:13:56 +08:00
|
|
|
|
2011-06-08 06:51:31 +08:00
|
|
|
if rettype.endswith("operator"):
|
|
|
|
fname = ("operator " + fname).strip()
|
|
|
|
rettype = rettype[:rettype.rfind("operator")].strip()
|
|
|
|
if rettype.endswith("::"):
|
|
|
|
rpos = rettype.rfind(" ")
|
|
|
|
if rpos >= 0:
|
|
|
|
fname = rettype[rpos+1:].strip() + fname
|
|
|
|
rettype = rettype[:rpos].strip()
|
|
|
|
else:
|
|
|
|
fname = rettype + fname
|
|
|
|
rettype = ""
|
2011-07-13 05:13:56 +08:00
|
|
|
|
2011-06-08 06:51:31 +08:00
|
|
|
apos = fdecl.find("(")
|
|
|
|
if fname.endswith("operator"):
|
2012-05-29 04:11:38 +08:00
|
|
|
fname += " ()"
|
2011-06-08 06:51:31 +08:00
|
|
|
apos = fdecl.find("(", apos+1)
|
2011-07-13 05:13:56 +08:00
|
|
|
|
2011-06-02 05:15:36 +08:00
|
|
|
fname = "cv." + fname.replace("::", ".")
|
2017-06-12 10:18:00 +08:00
|
|
|
decl = [fname, rettype, [], [], None, docstring]
|
2012-05-28 15:34:49 +08:00
|
|
|
|
|
|
|
# inline constructor implementation
|
|
|
|
implmatch = re.match(r"(\(.*?\))\s*:\s*(\w+\(.*?\),?\s*)+", fdecl[apos:])
|
|
|
|
if bool(implmatch):
|
|
|
|
fdecl = fdecl[:apos] + implmatch.group(1)
|
|
|
|
|
2011-06-09 09:16:45 +08:00
|
|
|
args0str = fdecl[apos+1:fdecl.rfind(")")].strip()
|
2011-07-13 05:13:56 +08:00
|
|
|
|
2012-05-28 15:34:49 +08:00
|
|
|
if args0str != "" and args0str != "void":
|
|
|
|
args0str = re.sub(r"\([^)]*\)", lambda m: m.group(0).replace(',', "@comma@"), args0str)
|
2011-06-09 09:16:45 +08:00
|
|
|
args0 = args0str.split(",")
|
|
|
|
|
|
|
|
args = []
|
|
|
|
narg = ""
|
|
|
|
for arg in args0:
|
|
|
|
narg += arg.strip()
|
|
|
|
balance_paren = narg.count("(") - narg.count(")")
|
|
|
|
balance_angle = narg.count("<") - narg.count(">")
|
|
|
|
if balance_paren == 0 and balance_angle == 0:
|
|
|
|
args.append(narg.strip())
|
|
|
|
narg = ""
|
2011-07-13 05:13:56 +08:00
|
|
|
|
2011-06-09 09:16:45 +08:00
|
|
|
for arg in args:
|
|
|
|
dfpos = arg.find("=")
|
|
|
|
defval = ""
|
|
|
|
if dfpos >= 0:
|
|
|
|
defval = arg[dfpos+1:].strip()
|
2012-05-28 15:34:49 +08:00
|
|
|
else:
|
|
|
|
dfpos = arg.find("CV_DEFAULT")
|
|
|
|
if dfpos >= 0:
|
|
|
|
defval, pos3 = self.get_macro_arg(arg, dfpos)
|
|
|
|
else:
|
|
|
|
dfpos = arg.find("CV_WRAP_DEFAULT")
|
|
|
|
if dfpos >= 0:
|
|
|
|
defval, pos3 = self.get_macro_arg(arg, dfpos)
|
|
|
|
if dfpos >= 0:
|
|
|
|
defval = defval.replace("@comma@", ",")
|
2011-06-09 09:16:45 +08:00
|
|
|
arg = arg[:dfpos].strip()
|
2011-07-07 22:49:24 +08:00
|
|
|
pos = len(arg)-1
|
2012-05-28 15:34:49 +08:00
|
|
|
while pos >= 0 and (arg[pos] in "_[]" or arg[pos].isalpha() or arg[pos].isdigit()):
|
2011-07-07 22:49:24 +08:00
|
|
|
pos -= 1
|
2011-06-09 09:16:45 +08:00
|
|
|
if pos >= 0:
|
|
|
|
aname = arg[pos+1:].strip()
|
2011-07-07 22:49:24 +08:00
|
|
|
atype = arg[:pos+1].strip()
|
2013-03-21 00:42:07 +08:00
|
|
|
if aname.endswith("&") or aname.endswith("*") or (aname in ["int", "String", "Mat"]):
|
2011-06-09 09:16:45 +08:00
|
|
|
atype = (atype + " " + aname).strip()
|
2012-11-12 18:42:28 +08:00
|
|
|
aname = ""
|
2011-06-09 09:16:45 +08:00
|
|
|
else:
|
|
|
|
atype = arg
|
2012-11-12 18:42:28 +08:00
|
|
|
aname = ""
|
2012-05-29 18:36:19 +08:00
|
|
|
if aname.endswith("]"):
|
|
|
|
bidx = aname.find('[')
|
|
|
|
atype += aname[bidx:]
|
|
|
|
aname = aname[:bidx]
|
2011-06-09 09:16:45 +08:00
|
|
|
decl[3].append([atype, aname, defval, []])
|
2011-07-13 05:13:56 +08:00
|
|
|
|
2012-05-28 15:34:49 +08:00
|
|
|
if static_method:
|
|
|
|
decl[2].append("/S")
|
2012-05-28 19:22:43 +08:00
|
|
|
if virtual_method:
|
|
|
|
decl[2].append("/V")
|
|
|
|
if explicit_method:
|
|
|
|
decl[2].append("/E")
|
|
|
|
if bool(re.match(r".*\)\s*(const)?\s*=\s*0", decl_str)):
|
|
|
|
decl[2].append("/A")
|
|
|
|
if bool(re.match(r".*\)\s*const(\s*=\s*0)?", decl_str)):
|
2012-05-28 15:34:49 +08:00
|
|
|
decl[2].append("/C")
|
2011-06-02 05:15:36 +08:00
|
|
|
return decl
|
|
|
|
|
2018-08-06 19:46:46 +08:00
|
|
|
def parse_func_decl(self, decl_str, mat="Mat", docstring=""):
|
2010-10-12 23:59:00 +08:00
|
|
|
"""
|
|
|
|
Parses the function or method declaration in the form:
|
|
|
|
[([CV_EXPORTS] <rettype>) | CVAPI(rettype)]
|
|
|
|
[~]<function_name>
|
|
|
|
(<arg_type1> <arg_name1>[=<default_value1>] [, <arg_type2> <arg_name2>[=<default_value2>] ...])
|
|
|
|
[const] {; | <function_body>}
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
Returns the function declaration entry:
|
2017-06-12 10:18:00 +08:00
|
|
|
[<func name>, <return value C-type>, <list of modifiers>, <list of arguments>, <original return type>, <docstring>] (see above)
|
2010-10-12 23:59:00 +08:00
|
|
|
"""
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2011-06-02 05:15:36 +08:00
|
|
|
if self.wrap_mode:
|
2018-08-19 01:34:47 +08:00
|
|
|
if not (("CV_EXPORTS_AS" in decl_str) or ("CV_EXPORTS_W" in decl_str) or ("CV_WRAP" in decl_str)):
|
2011-06-02 05:15:36 +08:00
|
|
|
return []
|
2011-07-13 05:13:56 +08:00
|
|
|
|
|
|
|
# ignore old API in the documentation check (for now)
|
2012-05-28 15:34:49 +08:00
|
|
|
if "CVAPI(" in decl_str and self.wrap_mode:
|
2011-07-13 05:13:56 +08:00
|
|
|
return []
|
|
|
|
|
2010-11-03 01:58:22 +08:00
|
|
|
top = self.block_stack[-1]
|
2010-10-29 21:09:49 +08:00
|
|
|
func_modlist = []
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-29 21:09:49 +08:00
|
|
|
npos = decl_str.find("CV_EXPORTS_AS")
|
|
|
|
if npos >= 0:
|
|
|
|
arg, npos3 = self.get_macro_arg(decl_str, npos)
|
|
|
|
func_modlist.append("="+arg)
|
|
|
|
decl_str = decl_str[:npos] + decl_str[npos3+1:]
|
|
|
|
npos = decl_str.find("CV_WRAP_AS")
|
|
|
|
if npos >= 0:
|
|
|
|
arg, npos3 = self.get_macro_arg(decl_str, npos)
|
|
|
|
func_modlist.append("="+arg)
|
|
|
|
decl_str = decl_str[:npos] + decl_str[npos3+1:]
|
2018-08-19 01:34:47 +08:00
|
|
|
npos = decl_str.find("CV_WRAP_PHANTOM")
|
|
|
|
if npos >= 0:
|
|
|
|
decl_str, _ = self.get_macro_arg(decl_str, npos)
|
|
|
|
func_modlist.append("/phantom")
|
|
|
|
npos = decl_str.find("CV_WRAP_MAPPABLE")
|
|
|
|
if npos >= 0:
|
|
|
|
mappable, npos3 = self.get_macro_arg(decl_str, npos)
|
|
|
|
func_modlist.append("/mappable="+mappable)
|
|
|
|
classname = top[1]
|
|
|
|
return ['.'.join([classname, classname]), None, func_modlist, [], None, None]
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2017-09-25 21:52:07 +08:00
|
|
|
virtual_method = False
|
|
|
|
pure_virtual_method = False
|
|
|
|
const_method = False
|
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
# filter off some common prefixes, which are meaningless for Python wrappers.
|
|
|
|
# note that we do not strip "static" prefix, which does matter;
|
|
|
|
# it means class methods, not instance methods
|
2021-09-09 21:20:45 +08:00
|
|
|
decl_str = self.batch_replace(decl_str, [("static inline", ""),
|
|
|
|
("inline", ""),
|
|
|
|
("explicit ", ""),
|
|
|
|
("CV_EXPORTS_W", ""),
|
|
|
|
("CV_EXPORTS", ""),
|
|
|
|
("CV_CDECL", ""),
|
|
|
|
("CV_WRAP ", " "),
|
|
|
|
("CV_INLINE", ""),
|
|
|
|
("CV_DEPRECATED", ""),
|
|
|
|
("CV_DEPRECATED_EXTERNAL", ""),
|
|
|
|
("CV_NODISCARD_STD", ""),
|
|
|
|
("CV_NODISCARD", "")]).strip()
|
2017-09-25 21:52:07 +08:00
|
|
|
|
|
|
|
if decl_str.strip().startswith('virtual'):
|
|
|
|
virtual_method = True
|
|
|
|
|
|
|
|
decl_str = decl_str.replace('virtual' , '')
|
|
|
|
|
|
|
|
end_tokens = decl_str[decl_str.rfind(')'):].split()
|
|
|
|
const_method = 'const' in end_tokens
|
|
|
|
pure_virtual_method = '=' in end_tokens and '0' in end_tokens
|
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
static_method = False
|
2010-11-03 01:58:22 +08:00
|
|
|
context = top[0]
|
2010-10-12 23:59:00 +08:00
|
|
|
if decl_str.startswith("static") and (context == "class" or context == "struct"):
|
|
|
|
decl_str = decl_str[len("static"):].lstrip()
|
|
|
|
static_method = True
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
args_begin = decl_str.find("(")
|
|
|
|
if decl_str.startswith("CVAPI"):
|
|
|
|
rtype_end = decl_str.find(")", args_begin+1)
|
|
|
|
if rtype_end < 0:
|
2013-06-13 04:02:30 +08:00
|
|
|
print("Error at %d. no terminating ) in CVAPI() macro: %s" % (self.lineno, decl_str))
|
2010-10-12 23:59:00 +08:00
|
|
|
sys.exit(-1)
|
|
|
|
decl_str = decl_str[args_begin+1:rtype_end] + " " + decl_str[rtype_end+1:]
|
|
|
|
args_begin = decl_str.find("(")
|
|
|
|
if args_begin < 0:
|
2013-06-13 04:02:30 +08:00
|
|
|
print("Error at %d: no args in '%s'" % (self.lineno, decl_str))
|
2010-10-12 23:59:00 +08:00
|
|
|
sys.exit(-1)
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
decl_start = decl_str[:args_begin].strip()
|
|
|
|
# handle operator () case
|
|
|
|
if decl_start.endswith("operator"):
|
|
|
|
args_begin = decl_str.find("(", args_begin+1)
|
|
|
|
if args_begin < 0:
|
2013-06-13 04:02:30 +08:00
|
|
|
print("Error at %d: no args in '%s'" % (self.lineno, decl_str))
|
2010-10-12 23:59:00 +08:00
|
|
|
sys.exit(-1)
|
|
|
|
decl_start = decl_str[:args_begin].strip()
|
2012-05-28 23:29:21 +08:00
|
|
|
# TODO: normalize all type of operators
|
|
|
|
if decl_start.endswith("()"):
|
|
|
|
decl_start = decl_start[0:-2].rstrip() + " ()"
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2012-05-28 15:34:49 +08:00
|
|
|
# constructor/destructor case
|
2012-09-08 04:40:06 +08:00
|
|
|
if bool(re.match(r'^(\w+::)*(?P<x>\w+)::~?(?P=x)$', decl_start)):
|
2012-05-28 15:34:49 +08:00
|
|
|
decl_start = "void " + decl_start
|
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
rettype, funcname, modlist, argno = self.parse_arg(decl_start, -1)
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2015-05-06 20:21:23 +08:00
|
|
|
# determine original return type, hack for return types with underscore
|
|
|
|
original_type = None
|
|
|
|
i = decl_start.rfind(funcname)
|
|
|
|
if i > 0:
|
|
|
|
original_type = decl_start[:i].replace("&", "").replace("const", "").strip()
|
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
if argno >= 0:
|
2010-11-03 01:58:22 +08:00
|
|
|
classname = top[1]
|
2010-10-12 23:59:00 +08:00
|
|
|
if rettype == classname or rettype == "~" + classname:
|
|
|
|
rettype, funcname = "", rettype
|
|
|
|
else:
|
2012-05-28 15:34:49 +08:00
|
|
|
if bool(re.match('\w+\s+\(\*\w+\)\s*\(.*\)', decl_str)):
|
|
|
|
return [] # function typedef
|
2012-09-08 04:40:06 +08:00
|
|
|
elif bool(re.match('\w+\s+\(\w+::\*\w+\)\s*\(.*\)', decl_str)):
|
|
|
|
return [] # class method typedef
|
2012-05-28 15:34:49 +08:00
|
|
|
elif bool(re.match('[A-Z_]+', decl_start)):
|
|
|
|
return [] # it seems to be a macro instantiation
|
|
|
|
elif "__declspec" == decl_start:
|
|
|
|
return []
|
2012-09-08 04:40:06 +08:00
|
|
|
elif bool(re.match(r'\w+\s+\(\*\w+\)\[\d+\]', decl_str)):
|
|
|
|
return [] # exotic - dynamic 2d array
|
2012-05-28 15:34:49 +08:00
|
|
|
else:
|
|
|
|
#print rettype, funcname, modlist, argno
|
2013-06-13 04:02:30 +08:00
|
|
|
print("Error at %s:%d the function/method name is missing: '%s'" % (self.hname, self.lineno, decl_start))
|
2012-05-28 15:34:49 +08:00
|
|
|
sys.exit(-1)
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2011-06-02 05:15:36 +08:00
|
|
|
if self.wrap_mode and (("::" in funcname) or funcname.startswith("~")):
|
2010-10-12 23:59:00 +08:00
|
|
|
# if there is :: in function name (and this is in the header file),
|
|
|
|
# it means, this is inline implementation of a class method.
|
|
|
|
# Thus the function has been already declared within the class and we skip this repeated
|
|
|
|
# declaration.
|
|
|
|
# Also, skip the destructors, as they are always wrapped
|
|
|
|
return []
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
funcname = self.get_dotted_name(funcname)
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2011-06-02 05:15:36 +08:00
|
|
|
if not self.wrap_mode:
|
2017-06-12 10:18:00 +08:00
|
|
|
decl = self.parse_func_decl_no_wrap(decl_str, static_method, docstring)
|
2011-06-02 05:15:36 +08:00
|
|
|
decl[0] = funcname
|
|
|
|
return decl
|
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
arg_start = args_begin+1
|
|
|
|
npos = arg_start-1
|
|
|
|
balance = 1
|
|
|
|
angle_balance = 0
|
|
|
|
# scan the argument list; handle nested parentheses
|
|
|
|
args_decls = []
|
|
|
|
args = []
|
|
|
|
argno = 1
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
while balance > 0:
|
|
|
|
npos += 1
|
|
|
|
t, npos = self.find_next_token(decl_str, ["(", ")", ",", "<", ">"], npos)
|
|
|
|
if not t:
|
2013-06-13 04:02:30 +08:00
|
|
|
print("Error: no closing ')' at %d" % (self.lineno,))
|
2010-10-12 23:59:00 +08:00
|
|
|
sys.exit(-1)
|
|
|
|
if t == "<":
|
|
|
|
angle_balance += 1
|
|
|
|
if t == ">":
|
|
|
|
angle_balance -= 1
|
|
|
|
if t == "(":
|
|
|
|
balance += 1
|
|
|
|
if t == ")":
|
|
|
|
balance -= 1
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
if (t == "," and balance == 1 and angle_balance == 0) or balance == 0:
|
|
|
|
# process next function argument
|
|
|
|
a = decl_str[arg_start:npos].strip()
|
|
|
|
#print "arg = ", a
|
|
|
|
arg_start = npos+1
|
|
|
|
if a:
|
|
|
|
eqpos = a.find("=")
|
|
|
|
defval = ""
|
|
|
|
modlist = []
|
|
|
|
if eqpos >= 0:
|
|
|
|
defval = a[eqpos+1:].strip()
|
|
|
|
else:
|
|
|
|
eqpos = a.find("CV_DEFAULT")
|
|
|
|
if eqpos >= 0:
|
2010-10-29 21:09:49 +08:00
|
|
|
defval, pos3 = self.get_macro_arg(a, eqpos)
|
|
|
|
else:
|
|
|
|
eqpos = a.find("CV_WRAP_DEFAULT")
|
|
|
|
if eqpos >= 0:
|
|
|
|
defval, pos3 = self.get_macro_arg(a, eqpos)
|
|
|
|
if defval == "NULL":
|
|
|
|
defval = "0"
|
2010-10-12 23:59:00 +08:00
|
|
|
if eqpos >= 0:
|
|
|
|
a = a[:eqpos].strip()
|
|
|
|
arg_type, arg_name, modlist, argno = self.parse_arg(a, argno)
|
2011-06-02 05:15:36 +08:00
|
|
|
if self.wrap_mode:
|
2016-02-08 00:04:39 +08:00
|
|
|
# TODO: Vectors should contain UMat, but this is not very easy to support and not very needed
|
2019-10-24 01:40:56 +08:00
|
|
|
vector_mat = "vector_{}".format(mat)
|
|
|
|
vector_mat_template = "vector<{}>".format(mat)
|
2016-02-08 00:04:39 +08:00
|
|
|
|
2011-07-13 05:13:56 +08:00
|
|
|
if arg_type == "InputArray":
|
2016-02-08 00:04:39 +08:00
|
|
|
arg_type = mat
|
2011-07-13 05:13:56 +08:00
|
|
|
elif arg_type == "InputOutputArray":
|
2016-02-08 00:04:39 +08:00
|
|
|
arg_type = mat
|
2011-07-13 05:13:56 +08:00
|
|
|
modlist.append("/IO")
|
2011-06-02 05:15:36 +08:00
|
|
|
elif arg_type == "OutputArray":
|
2016-02-08 00:04:39 +08:00
|
|
|
arg_type = mat
|
2011-06-02 05:15:36 +08:00
|
|
|
modlist.append("/O")
|
2011-07-13 05:13:56 +08:00
|
|
|
elif arg_type == "InputArrayOfArrays":
|
2016-02-08 00:04:39 +08:00
|
|
|
arg_type = vector_mat
|
2011-07-13 05:13:56 +08:00
|
|
|
elif arg_type == "InputOutputArrayOfArrays":
|
2016-02-08 00:04:39 +08:00
|
|
|
arg_type = vector_mat
|
2011-07-13 05:13:56 +08:00
|
|
|
modlist.append("/IO")
|
2011-06-02 05:15:36 +08:00
|
|
|
elif arg_type == "OutputArrayOfArrays":
|
2016-02-08 00:04:39 +08:00
|
|
|
arg_type = vector_mat
|
2011-06-02 05:15:36 +08:00
|
|
|
modlist.append("/O")
|
2016-02-08 00:04:39 +08:00
|
|
|
defval = self.batch_replace(defval, [("InputArrayOfArrays", vector_mat_template),
|
|
|
|
("InputOutputArrayOfArrays", vector_mat_template),
|
|
|
|
("OutputArrayOfArrays", vector_mat_template),
|
|
|
|
("InputArray", mat),
|
|
|
|
("InputOutputArray", mat),
|
|
|
|
("OutputArray", mat),
|
2011-06-08 14:55:04 +08:00
|
|
|
("noArray", arg_type)]).strip()
|
2010-10-12 23:59:00 +08:00
|
|
|
args.append([arg_type, arg_name, defval, modlist])
|
|
|
|
npos = arg_start-1
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
if static_method:
|
2011-05-17 20:52:07 +08:00
|
|
|
func_modlist.append("/S")
|
2017-09-25 21:52:07 +08:00
|
|
|
if const_method:
|
|
|
|
func_modlist.append("/C")
|
|
|
|
if virtual_method:
|
|
|
|
func_modlist.append("/V")
|
|
|
|
if pure_virtual_method:
|
|
|
|
func_modlist.append("/PV")
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2017-06-12 10:18:00 +08:00
|
|
|
return [funcname, rettype, func_modlist, args, original_type, docstring]
|
2010-10-12 23:59:00 +08:00
|
|
|
|
|
|
|
def get_dotted_name(self, name):
|
|
|
|
"""
|
|
|
|
adds the dot-separated container class/namespace names to the bare function/class name, e.g. when we have
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
namespace cv {
|
|
|
|
class A {
|
|
|
|
public:
|
|
|
|
f(int);
|
|
|
|
};
|
|
|
|
}
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
the function will convert "A" to "cv.A" and "f" to "cv.A.f".
|
|
|
|
"""
|
|
|
|
if not self.block_stack:
|
|
|
|
return name
|
2012-12-26 21:51:04 +08:00
|
|
|
if name.startswith("cv."):
|
|
|
|
return name
|
2014-07-30 20:11:08 +08:00
|
|
|
qualified_name = (("." in name) or ("::" in name))
|
2010-10-12 23:59:00 +08:00
|
|
|
n = ""
|
|
|
|
for b in self.block_stack:
|
|
|
|
block_type, block_name = b[self.BLOCK_TYPE], b[self.BLOCK_NAME]
|
2010-10-29 21:09:49 +08:00
|
|
|
if block_type in ["file", "enum"]:
|
2010-10-12 23:59:00 +08:00
|
|
|
continue
|
2018-12-18 22:39:31 +08:00
|
|
|
if block_type in ["enum struct", "enum class"] and block_name == name:
|
|
|
|
continue
|
2018-08-26 17:38:07 +08:00
|
|
|
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))
|
2010-10-12 23:59:00 +08:00
|
|
|
sys.exit(-1)
|
2014-07-30 20:11:08 +08:00
|
|
|
if block_name and (block_type == "namespace" or not qualified_name):
|
2010-10-12 23:59:00 +08:00
|
|
|
n += block_name + "."
|
2014-07-30 20:11:08 +08:00
|
|
|
n += name.replace("::", ".")
|
|
|
|
if n.endswith(".Algorithm"):
|
|
|
|
n = "cv.Algorithm"
|
|
|
|
return n
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2018-08-06 19:46:46 +08:00
|
|
|
def parse_stmt(self, stmt, end_token, mat="Mat", docstring=""):
|
2010-10-12 23:59:00 +08:00
|
|
|
"""
|
|
|
|
parses the statement (ending with ';' or '}') or a block head (ending with '{')
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
The function calls parse_class_decl or parse_func_decl when necessary. It returns
|
|
|
|
<block_type>, <block_name>, <parse_flag>, <declaration>
|
|
|
|
where the first 3 values only make sense for blocks (i.e. code blocks, namespaces, classes, enums and such)
|
|
|
|
"""
|
|
|
|
stack_top = self.block_stack[-1]
|
|
|
|
context = stack_top[self.BLOCK_TYPE]
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2020-11-08 02:25:48 +08:00
|
|
|
if stmt.startswith('inline namespace'):
|
|
|
|
# emulate anonymous namespace
|
|
|
|
return "namespace", "", True, None
|
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
stmt_type = ""
|
|
|
|
if end_token == "{":
|
|
|
|
stmt_type = "block"
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
if context == "block":
|
2013-06-13 04:02:30 +08:00
|
|
|
print("Error at %d: should not call parse_stmt inside blocks" % (self.lineno,))
|
2010-10-12 23:59:00 +08:00
|
|
|
sys.exit(-1)
|
|
|
|
|
|
|
|
if context == "class" or context == "struct":
|
|
|
|
while 1:
|
|
|
|
colon_pos = stmt.find(":")
|
|
|
|
if colon_pos < 0:
|
|
|
|
break
|
|
|
|
w = stmt[:colon_pos].strip()
|
|
|
|
if w in ["public", "protected", "private"]:
|
2012-05-29 04:11:38 +08:00
|
|
|
if w == "public" or (not self.wrap_mode and w == "protected"):
|
2010-10-12 23:59:00 +08:00
|
|
|
stack_top[self.PUBLIC_SECTION] = True
|
|
|
|
else:
|
|
|
|
stack_top[self.PUBLIC_SECTION] = False
|
|
|
|
stmt = stmt[colon_pos+1:].strip()
|
|
|
|
break
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
# do not process hidden class members and template classes/functions
|
|
|
|
if not stack_top[self.PUBLIC_SECTION] or stmt.startswith("template"):
|
|
|
|
return stmt_type, "", False, None
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
if end_token == "{":
|
2012-05-28 22:36:15 +08:00
|
|
|
if not self.wrap_mode and stmt.startswith("typedef struct"):
|
|
|
|
stmt_type = "struct"
|
|
|
|
try:
|
|
|
|
classname, bases, modlist = self.parse_class_decl(stmt[len("typedef "):])
|
|
|
|
except:
|
2013-06-13 04:02:30 +08:00
|
|
|
print("Error at %s:%d" % (self.hname, self.lineno))
|
2012-05-28 22:36:15 +08:00
|
|
|
exit(1)
|
|
|
|
if classname.startswith("_Ipl"):
|
|
|
|
classname = classname[1:]
|
2017-06-12 10:18:00 +08:00
|
|
|
decl = [stmt_type + " " + self.get_dotted_name(classname), "", modlist, [], None, docstring]
|
2012-05-28 22:36:15 +08:00
|
|
|
if bases:
|
2014-07-30 20:11:08 +08:00
|
|
|
decl[1] = ": " + ", ".join([self.get_dotted_name(b).replace(".","::") for b in bases])
|
2012-05-28 22:36:15 +08:00
|
|
|
return stmt_type, classname, True, decl
|
|
|
|
|
2010-10-29 21:09:49 +08:00
|
|
|
if stmt.startswith("class") or stmt.startswith("struct"):
|
|
|
|
stmt_type = stmt.split()[0]
|
2012-05-28 22:36:15 +08:00
|
|
|
if stmt.strip() != stmt_type:
|
|
|
|
try:
|
|
|
|
classname, bases, modlist = self.parse_class_decl(stmt)
|
|
|
|
except:
|
2013-06-13 04:02:30 +08:00
|
|
|
print("Error at %s:%d" % (self.hname, self.lineno))
|
2012-05-28 22:36:15 +08:00
|
|
|
exit(1)
|
|
|
|
decl = []
|
|
|
|
if ("CV_EXPORTS_W" in stmt) or ("CV_EXPORTS_AS" in stmt) or (not self.wrap_mode):# and ("CV_EXPORTS" in stmt)):
|
2017-06-12 10:18:00 +08:00
|
|
|
decl = [stmt_type + " " + self.get_dotted_name(classname), "", modlist, [], None, docstring]
|
2012-05-28 22:36:15 +08:00
|
|
|
if bases:
|
2014-07-30 20:11:08 +08:00
|
|
|
decl[1] = ": " + ", ".join([self.get_dotted_name(b).replace(".","::") for b in bases])
|
2012-05-28 22:36:15 +08:00
|
|
|
return stmt_type, classname, True, decl
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2018-08-20 22:35:41 +08:00
|
|
|
if stmt.startswith("enum") or stmt.startswith("namespace"):
|
2020-07-29 21:18:52 +08:00
|
|
|
# NB: Drop inheritance syntax for enum
|
|
|
|
stmt = stmt.split(':')[0]
|
2018-08-26 17:38:07 +08:00
|
|
|
stmt_list = stmt.rsplit(" ", 1)
|
2012-05-28 15:34:49 +08:00
|
|
|
if len(stmt_list) < 2:
|
|
|
|
stmt_list.append("<unnamed>")
|
2010-10-12 23:59:00 +08:00
|
|
|
return stmt_list[0], stmt_list[1], True, None
|
2018-08-20 22:35:41 +08:00
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
if stmt.startswith("extern") and "\"C\"" in stmt:
|
|
|
|
return "namespace", "", True, None
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2018-08-26 17:38:07 +08:00
|
|
|
if end_token == "}" and context.startswith("enum"):
|
2010-10-29 21:09:49 +08:00
|
|
|
decl = self.parse_enum(stmt)
|
2018-08-20 22:35:41 +08:00
|
|
|
name = stack_top[self.BLOCK_NAME]
|
2018-08-26 17:38:07 +08:00
|
|
|
return context, name, False, decl
|
2010-10-12 23:59:00 +08:00
|
|
|
|
|
|
|
if end_token == ";" and stmt.startswith("typedef"):
|
|
|
|
# TODO: handle typedef's more intelligently
|
|
|
|
return stmt_type, "", False, None
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
paren_pos = stmt.find("(")
|
|
|
|
if paren_pos >= 0:
|
|
|
|
# assume it's function or method declaration,
|
|
|
|
# since we filtered off the other places where '(' can normally occur:
|
|
|
|
# - code blocks
|
|
|
|
# - function pointer typedef's
|
2018-08-06 19:46:46 +08:00
|
|
|
decl = self.parse_func_decl(stmt, mat=mat, docstring=docstring)
|
2010-10-12 23:59:00 +08:00
|
|
|
# we return parse_flag == False to prevent the parser to look inside function/method bodies
|
|
|
|
# (except for tracking the nested blocks)
|
|
|
|
return stmt_type, "", False, decl
|
|
|
|
|
|
|
|
if (context == "struct" or context == "class") and end_token == ";" and stmt:
|
|
|
|
# looks like it's member declaration; append the members to the class declaration
|
|
|
|
class_decl = stack_top[self.CLASS_DECL]
|
2010-11-03 01:58:22 +08:00
|
|
|
if ("CV_PROP" in stmt): # or (class_decl and ("/Map" in class_decl[2])):
|
2010-10-29 21:09:49 +08:00
|
|
|
var_modlist = []
|
|
|
|
if "CV_PROP_RW" in stmt:
|
|
|
|
var_modlist.append("/RW")
|
|
|
|
stmt = self.batch_replace(stmt, [("CV_PROP_RW", ""), ("CV_PROP", "")]).strip()
|
|
|
|
var_list = stmt.split(",")
|
|
|
|
var_type, var_name1, modlist, argno = self.parse_arg(var_list[0], -1)
|
|
|
|
var_list = [var_name1] + [i.strip() for i in var_list[1:]]
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-29 21:09:49 +08:00
|
|
|
for v in var_list:
|
2020-12-18 20:00:42 +08:00
|
|
|
vv = v.split("=")
|
|
|
|
vname = vv[0].strip()
|
|
|
|
vdefval = ""
|
|
|
|
if len(vv) > 1:
|
|
|
|
vdefval = vv[1].strip()
|
|
|
|
class_decl[3].append([var_type, vname, vdefval, var_modlist])
|
2010-10-12 23:59:00 +08:00
|
|
|
return stmt_type, "", False, None
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
# something unknown
|
|
|
|
return stmt_type, "", False, None
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
def find_next_token(self, s, tlist, p=0):
|
|
|
|
"""
|
|
|
|
Finds the next token from the 'tlist' in the input 's', starting from position 'p'.
|
2018-02-14 00:28:11 +08:00
|
|
|
Returns the first occurred token and its position, or ("", len(s)) when no token is found
|
2010-10-12 23:59:00 +08:00
|
|
|
"""
|
|
|
|
token = ""
|
|
|
|
tpos = len(s)
|
|
|
|
for t in tlist:
|
|
|
|
pos = s.find(t, p)
|
|
|
|
if pos < 0:
|
|
|
|
continue
|
|
|
|
if pos < tpos:
|
|
|
|
tpos = pos
|
|
|
|
token = t
|
|
|
|
return token, tpos
|
|
|
|
|
2011-06-02 05:15:36 +08:00
|
|
|
def parse(self, hname, wmode=True):
|
2010-10-12 23:59:00 +08:00
|
|
|
"""
|
|
|
|
The main method. Parses the input file.
|
|
|
|
Returns the list of declarations (that can be print using print_decls)
|
|
|
|
"""
|
2012-05-28 15:34:49 +08:00
|
|
|
self.hname = hname
|
2010-10-12 23:59:00 +08:00
|
|
|
decls = []
|
2014-11-10 13:39:18 +08:00
|
|
|
f = io.open(hname, 'rt', encoding='utf-8')
|
2010-10-12 23:59:00 +08:00
|
|
|
linelist = list(f.readlines())
|
|
|
|
f.close()
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
# states:
|
|
|
|
SCAN = 0 # outside of a comment or preprocessor directive
|
|
|
|
COMMENT = 1 # inside a multi-line comment
|
|
|
|
DIRECTIVE = 2 # inside a multi-line preprocessor directive
|
2017-06-12 10:18:00 +08:00
|
|
|
DOCSTRING = 3 # inside a multi-line docstring
|
2019-12-04 22:29:05 +08:00
|
|
|
DIRECTIVE_IF_0 = 4 # inside a '#if 0' directive
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
state = SCAN
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
self.block_stack = [["file", hname, True, True, None]]
|
|
|
|
block_head = ""
|
2017-06-12 10:18:00 +08:00
|
|
|
docstring = ""
|
2010-10-12 23:59:00 +08:00
|
|
|
self.lineno = 0
|
2011-06-02 05:15:36 +08:00
|
|
|
self.wrap_mode = wmode
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2019-12-04 22:29:05 +08:00
|
|
|
depth_if_0 = 0
|
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
for l0 in linelist:
|
|
|
|
self.lineno += 1
|
2017-06-30 00:40:36 +08:00
|
|
|
#print(state, self.lineno, l0)
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
l = l0.strip()
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2020-07-29 21:18:52 +08:00
|
|
|
# G-API specific aliases
|
|
|
|
l = self.batch_replace(l, [
|
|
|
|
("GAPI_EXPORTS", "CV_EXPORTS"),
|
|
|
|
("GAPI_EXPORTS_W", "CV_EXPORTS_W"),
|
|
|
|
("GAPI_EXPORTS_W_SIMPLE","CV_EXPORTS_W_SIMPLE"),
|
|
|
|
("GAPI_WRAP", "CV_WRAP"),
|
2021-03-31 04:59:02 +08:00
|
|
|
("GAPI_PROP", "CV_PROP"),
|
2021-07-01 17:36:19 +08:00
|
|
|
("GAPI_PROP_RW", "CV_PROP_RW"),
|
2020-07-29 21:18:52 +08:00
|
|
|
('defined(GAPI_STANDALONE)', '0'),
|
|
|
|
])
|
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
if state == SCAN and l.startswith("#"):
|
|
|
|
state = DIRECTIVE
|
|
|
|
# fall through to the if state == DIRECTIVE check
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
if state == DIRECTIVE:
|
2019-12-04 22:29:05 +08:00
|
|
|
if l.endswith("\\"):
|
|
|
|
continue
|
|
|
|
state = SCAN
|
|
|
|
l = re.sub(r'//(.+)?', '', l).strip() # drop // comment
|
2021-03-31 04:54:11 +08:00
|
|
|
if l in [
|
|
|
|
'#if 0',
|
|
|
|
'#if defined(__OPENCV_BUILD)', '#ifdef __OPENCV_BUILD',
|
|
|
|
'#if !defined(OPENCV_BINDING_PARSER)', '#ifndef OPENCV_BINDING_PARSER',
|
|
|
|
]:
|
2019-12-04 22:29:05 +08:00
|
|
|
state = DIRECTIVE_IF_0
|
|
|
|
depth_if_0 = 1
|
|
|
|
continue
|
|
|
|
|
|
|
|
if state == DIRECTIVE_IF_0:
|
|
|
|
if l.startswith('#'):
|
|
|
|
l = l[1:].strip()
|
|
|
|
if l.startswith("if"):
|
|
|
|
depth_if_0 += 1
|
|
|
|
continue
|
|
|
|
if l.startswith("endif"):
|
|
|
|
depth_if_0 -= 1
|
|
|
|
if depth_if_0 == 0:
|
|
|
|
state = SCAN
|
|
|
|
else:
|
|
|
|
# print('---- {:30s}:{:5d}: {}'.format(hname[-30:], self.lineno, l))
|
|
|
|
pass
|
2010-10-12 23:59:00 +08:00
|
|
|
continue
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
if state == COMMENT:
|
|
|
|
pos = l.find("*/")
|
|
|
|
if pos < 0:
|
|
|
|
continue
|
|
|
|
l = l[pos+2:]
|
|
|
|
state = SCAN
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2017-06-12 10:18:00 +08:00
|
|
|
if state == DOCSTRING:
|
|
|
|
pos = l.find("*/")
|
|
|
|
if pos < 0:
|
2019-06-05 18:44:03 +08:00
|
|
|
docstring += l0
|
2017-06-12 10:18:00 +08:00
|
|
|
continue
|
|
|
|
docstring += l[:pos] + "\n"
|
|
|
|
l = l[pos+2:]
|
|
|
|
state = SCAN
|
|
|
|
|
2018-12-12 18:26:31 +08:00
|
|
|
if l.startswith('CV__') or l.startswith('__CV_'): # just ignore these lines
|
2017-06-30 00:40:36 +08:00
|
|
|
#print('IGNORE: ' + l)
|
|
|
|
state = SCAN
|
|
|
|
continue
|
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
if state != SCAN:
|
2017-06-30 00:40:36 +08:00
|
|
|
print("Error at %d: invalid state = %d" % (self.lineno, state))
|
2010-10-12 23:59:00 +08:00
|
|
|
sys.exit(-1)
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
while 1:
|
2020-07-29 21:18:52 +08:00
|
|
|
# NB: Avoid parsing '{' for case:
|
|
|
|
# foo(Obj&& = {});
|
|
|
|
if re.search(r'=\s*\{\s*\}', l):
|
|
|
|
token, pos = ';', len(l)
|
|
|
|
else:
|
|
|
|
token, pos = self.find_next_token(l, [";", "\"", "{", "}", "//", "/*"])
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
if not token:
|
|
|
|
block_head += " " + l
|
2018-12-12 18:26:31 +08:00
|
|
|
block_head = block_head.strip()
|
|
|
|
if len(block_head) > 0 and block_head[-1] == ')' and block_head.startswith('CV_ENUM_FLAGS('):
|
|
|
|
l = ''
|
|
|
|
token = ';'
|
|
|
|
else:
|
|
|
|
break
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
if token == "//":
|
|
|
|
block_head += " " + l[:pos]
|
2018-12-12 18:26:31 +08:00
|
|
|
l = ''
|
|
|
|
continue
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
if token == "/*":
|
|
|
|
block_head += " " + l[:pos]
|
2017-06-12 10:18:00 +08:00
|
|
|
end_pos = l.find("*/", pos+2)
|
|
|
|
if len(l) > pos + 2 and l[pos+2] == "*":
|
|
|
|
# '/**', it's a docstring
|
|
|
|
if end_pos < 0:
|
|
|
|
state = DOCSTRING
|
|
|
|
docstring = l[pos+3:] + "\n"
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
docstring = l[pos+3:end_pos]
|
|
|
|
|
|
|
|
elif end_pos < 0:
|
2010-10-12 23:59:00 +08:00
|
|
|
state = COMMENT
|
|
|
|
break
|
2017-06-12 10:18:00 +08:00
|
|
|
l = l[end_pos+2:]
|
2010-10-12 23:59:00 +08:00
|
|
|
continue
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
if token == "\"":
|
|
|
|
pos2 = pos + 1
|
|
|
|
while 1:
|
|
|
|
t2, pos2 = self.find_next_token(l, ["\\", "\""], pos2)
|
|
|
|
if t2 == "":
|
2013-06-13 04:02:30 +08:00
|
|
|
print("Error at %d: no terminating '\"'" % (self.lineno,))
|
2010-10-12 23:59:00 +08:00
|
|
|
sys.exit(-1)
|
|
|
|
if t2 == "\"":
|
|
|
|
break
|
|
|
|
pos2 += 2
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
block_head += " " + l[:pos2+1]
|
|
|
|
l = l[pos2+1:]
|
|
|
|
continue
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
stmt = (block_head + " " + l[:pos]).strip()
|
|
|
|
stmt = " ".join(stmt.split()) # normalize the statement
|
2017-06-30 00:40:36 +08:00
|
|
|
#print(stmt)
|
2010-10-12 23:59:00 +08:00
|
|
|
stack_top = self.block_stack[-1]
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2012-09-08 04:40:06 +08:00
|
|
|
if stmt.startswith("@"):
|
|
|
|
# Objective C ?
|
|
|
|
break
|
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
decl = None
|
|
|
|
if stack_top[self.PROCESS_FLAG]:
|
|
|
|
# even if stack_top[PUBLIC_SECTION] is False, we still try to process the statement,
|
|
|
|
# since it can start with "public:"
|
2017-06-12 10:18:00 +08:00
|
|
|
docstring = docstring.strip()
|
|
|
|
stmt_type, name, parse_flag, decl = self.parse_stmt(stmt, token, docstring=docstring)
|
2010-10-12 23:59:00 +08:00
|
|
|
if decl:
|
2018-08-26 17:38:07 +08:00
|
|
|
if stmt_type.startswith("enum"):
|
|
|
|
decls.append([stmt_type + " " + self.get_dotted_name(name), "", [], decl, None, ""])
|
2010-10-29 21:09:49 +08:00
|
|
|
else:
|
|
|
|
decls.append(decl)
|
2016-02-08 00:04:39 +08:00
|
|
|
|
2020-10-19 20:35:03 +08:00
|
|
|
if self._generate_gpumat_decls and ("cv.cuda" in decl[0] or decl[0] in [
|
|
|
|
"cv.imshow", # https://github.com/opencv/opencv/issues/18553
|
|
|
|
]):
|
2018-08-06 19:46:46 +08:00
|
|
|
# If function takes as one of arguments Mat or vector<Mat> - we want to create the
|
2019-12-04 23:57:58 +08:00
|
|
|
# same declaration working with GpuMat
|
2018-08-06 19:46:46 +08:00
|
|
|
args = decl[3]
|
|
|
|
has_mat = len(list(filter(lambda x: x[0] in {"Mat", "vector_Mat"}, args))) > 0
|
|
|
|
if has_mat:
|
|
|
|
_, _, _, gpumat_decl = self.parse_stmt(stmt, token, mat="cuda::GpuMat", docstring=docstring)
|
2021-08-04 21:17:25 +08:00
|
|
|
if gpumat_decl != decl:
|
|
|
|
decls.append(gpumat_decl)
|
2018-08-06 19:46:46 +08:00
|
|
|
|
2016-02-08 00:04:39 +08:00
|
|
|
if self._generate_umat_decls:
|
|
|
|
# If function takes as one of arguments Mat or vector<Mat> - we want to create the
|
|
|
|
# same declaration working with UMat (this is important for T-Api access)
|
|
|
|
args = decl[3]
|
|
|
|
has_mat = len(list(filter(lambda x: x[0] in {"Mat", "vector_Mat"}, args))) > 0
|
|
|
|
if has_mat:
|
2018-08-06 19:46:46 +08:00
|
|
|
_, _, _, umat_decl = self.parse_stmt(stmt, token, mat="UMat", docstring=docstring)
|
2021-08-04 21:17:25 +08:00
|
|
|
if umat_decl != decl:
|
|
|
|
decls.append(umat_decl)
|
2018-08-06 19:46:46 +08:00
|
|
|
|
2017-06-12 10:18:00 +08:00
|
|
|
docstring = ""
|
2014-08-19 17:35:46 +08:00
|
|
|
if stmt_type == "namespace":
|
|
|
|
chunks = [block[1] for block in self.block_stack if block[0] == 'namespace'] + [name]
|
|
|
|
self.namespaces.add('.'.join(chunks))
|
2010-10-12 23:59:00 +08:00
|
|
|
else:
|
|
|
|
stmt_type, name, parse_flag = "block", "", False
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
if token == "{":
|
|
|
|
if stmt_type == "class":
|
|
|
|
public_section = False
|
|
|
|
else:
|
2011-05-17 20:52:07 +08:00
|
|
|
public_section = True
|
2010-10-12 23:59:00 +08:00
|
|
|
self.block_stack.append([stmt_type, name, parse_flag, public_section, decl])
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
if token == "}":
|
|
|
|
if not self.block_stack:
|
2013-06-13 04:02:30 +08:00
|
|
|
print("Error at %d: the block stack is empty" % (self.lineno,))
|
2010-10-12 23:59:00 +08:00
|
|
|
self.block_stack[-1:] = []
|
|
|
|
if pos+1 < len(l) and l[pos+1] == ';':
|
|
|
|
pos += 1
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
block_head = ""
|
|
|
|
l = l[pos+1:]
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
return decls
|
2011-05-17 20:52:07 +08:00
|
|
|
|
2010-10-12 23:59:00 +08:00
|
|
|
def print_decls(self, decls):
|
|
|
|
"""
|
|
|
|
Prints the list of declarations, retrieived by the parse() method
|
|
|
|
"""
|
|
|
|
for d in decls:
|
2013-06-13 04:02:30 +08:00
|
|
|
print(d[0], d[1], ";".join(d[2]))
|
2017-06-12 10:18:00 +08:00
|
|
|
# Uncomment below line to see docstrings
|
|
|
|
# print('"""\n' + d[5] + '\n"""')
|
2010-10-29 21:09:49 +08:00
|
|
|
for a in d[3]:
|
2013-06-13 04:02:30 +08:00
|
|
|
print(" ", a[0], a[1], a[2], end="")
|
2010-10-12 23:59:00 +08:00
|
|
|
if a[3]:
|
2013-06-13 04:02:30 +08:00
|
|
|
print("; ".join(a[3]))
|
2010-10-12 23:59:00 +08:00
|
|
|
else:
|
2013-06-13 04:02:30 +08:00
|
|
|
print()
|
2010-10-12 23:59:00 +08:00
|
|
|
|
2010-11-03 01:58:22 +08:00
|
|
|
if __name__ == '__main__':
|
2018-08-06 19:46:46 +08:00
|
|
|
parser = CppHeaderParser(generate_umat_decls=True, generate_gpumat_decls=True)
|
2011-05-17 20:52:07 +08:00
|
|
|
decls = []
|
2010-10-29 21:09:49 +08:00
|
|
|
for hname in opencv_hdr_list:
|
|
|
|
decls += parser.parse(hname)
|
2012-09-08 04:40:06 +08:00
|
|
|
#for hname in sys.argv[1:]:
|
|
|
|
#decls += parser.parse(hname, wmode=False)
|
2010-11-03 01:58:22 +08:00
|
|
|
parser.print_decls(decls)
|
2013-06-13 04:02:30 +08:00
|
|
|
print(len(decls))
|
2014-08-19 17:35:46 +08:00
|
|
|
print("namespaces:", " ".join(sorted(parser.namespaces)))
|