Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Opencv
提交
e85e83f4
O
Opencv
项目概览
Greenplum
/
Opencv
11 个月 前同步成功
通知
7
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
Opencv
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e85e83f4
编写于
8月 14, 2014
作者:
A
Alexander Mordvintsev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
handling namespaces on parsing functions
submodule method tables generation
上级
8658aef3
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
38 addition
and
36 deletion
+38
-36
modules/python/src2/gen2.py
modules/python/src2/gen2.py
+38
-36
未找到文件。
modules/python/src2/gen2.py
浏览文件 @
e85e83f4
...
...
@@ -740,7 +740,7 @@ class PythonWrapperGenerator(object):
def
clear
(
self
):
self
.
classes
=
{}
self
.
funcs
=
{}
self
.
ns_
funcs
=
{}
self
.
consts
=
{}
self
.
code_include
=
StringIO
()
self
.
code_types
=
StringIO
()
...
...
@@ -748,6 +748,7 @@ class PythonWrapperGenerator(object):
self
.
code_func_tab
=
StringIO
()
self
.
code_type_reg
=
StringIO
()
self
.
code_const_reg
=
StringIO
()
self
.
code_ns_reg
=
StringIO
()
self
.
class_idx
=
0
def
add_class
(
self
,
stype
,
name
,
decl
):
...
...
@@ -773,53 +774,48 @@ class PythonWrapperGenerator(object):
self
.
consts
[
constinfo
.
name
]
=
constinfo
def
add_func
(
self
,
decl
):
classname
=
bareclassname
=
""
name
=
decl
[
0
]
dpos
=
name
.
rfind
(
"."
)
if
dpos
>=
0
and
name
[:
dpos
]
not
in
[
"cv"
,
"cv.ocl"
]:
classname
=
bareclassname
=
re
.
sub
(
r
"^cv\."
,
""
,
name
[:
dpos
])
name
=
name
[
dpos
+
1
:]
dpos
=
classname
.
rfind
(
"."
)
if
dpos
>=
0
:
bareclassname
=
classname
[
dpos
+
1
:]
classname
=
classname
.
replace
(
"."
,
"_"
)
cname
=
name
name
=
re
.
sub
(
r
"^cv\."
,
""
,
name
)
name
=
name
.
replace
(
"."
,
"_"
)
isconstructor
=
cname
==
bareclassname
cname
=
cname
.
replace
(
"."
,
"::"
)
chunks
=
decl
[
0
].
split
(
'.'
)
name
=
chunks
[
-
1
]
cname
=
'::'
.
join
(
chunks
)
namespace
=
'.'
.
join
(
chunks
[:
-
1
])
classname
=
normalize_class_name
(
namespace
)
if
classname
in
self
.
classes
:
bareclassname
=
chunks
[
-
2
]
namespace
=
'.'
.
join
(
chunks
[:
-
2
])
else
:
classname
=
''
bareclassname
=
''
isconstructor
=
name
==
bareclassname
isclassmethod
=
False
customname
=
False
for
m
in
decl
[
2
]:
if
m
==
"/S"
:
isclassmethod
=
True
elif
m
.
startswith
(
"="
):
name
=
m
[
1
:]
customname
=
True
func_map
=
self
.
funcs
if
not
classname
or
isconstructor
:
pass
elif
isclassmethod
:
if
not
customname
:
name
=
classname
+
"_"
+
name
cname
=
classname
+
"::"
+
cname
classname
=
""
if
isclassmethod
:
name
=
bareclassname
+
"_"
+
name
classname
=
bareclassname
=
''
if
classname
:
func_map
=
classinfo
=
self
.
classes
[
classname
].
methods
else
:
classinfo
=
self
.
classes
.
get
(
classname
,
ClassInfo
(
""
))
if
not
classinfo
.
name
:
print
(
"Generator error: the class for method %s is missing"
%
(
name
,))
sys
.
exit
(
-
1
)
func_map
=
classinfo
.
methods
func_map
=
self
.
ns_funcs
.
setdefault
(
namespace
,
{})
func
=
func_map
.
ge
t
(
name
,
FuncInfo
(
classname
,
name
,
cname
,
isconstructor
))
func
=
func_map
.
setdefaul
t
(
name
,
FuncInfo
(
classname
,
name
,
cname
,
isconstructor
))
func
.
add_variant
(
decl
)
if
len
(
func
.
variants
)
==
1
:
func_map
[
name
]
=
func
def
gen_const_reg
(
self
,
constinfo
):
self
.
code_const_reg
.
write
(
"PUBLISH2(%s,%s);
\n
"
%
(
constinfo
.
name
,
constinfo
.
cname
))
def
gen_namespace
(
self
,
ns_name
):
wname
=
normalize_class_name
(
ns_name
)
self
.
code_ns_reg
.
write
(
'static PyMethodDef methods_%s[] = {
\n
'
%
wname
)
funclist
=
sorted
(
self
.
ns_funcs
[
ns_name
].
items
())
for
name
,
func
in
funclist
:
self
.
code_ns_reg
.
write
(
func
.
get_tab_entry
())
self
.
code_ns_reg
.
write
(
' {NULL, NULL}
\n
};
\n\n
'
)
def
save
(
self
,
path
,
name
,
buf
):
f
=
open
(
path
+
"/"
+
name
,
"wt"
)
f
.
write
(
buf
.
getvalue
())
...
...
@@ -876,7 +872,7 @@ class PythonWrapperGenerator(object):
self
.
code_type_reg
.
write
(
"MKTYPE2(%s);
\n
"
%
(
classinfo
.
name
,)
)
# step 3: generate the code for all the global functions
funclist
=
list
(
self
.
funcs
.
items
())
funclist
=
list
(
self
.
ns_funcs
[
'cv'
]
.
items
())
funclist
.
sort
()
for
name
,
func
in
funclist
:
code
=
func
.
gen_code
(
self
.
classes
)
...
...
@@ -889,6 +885,11 @@ class PythonWrapperGenerator(object):
for
name
,
constinfo
in
constlist
:
self
.
gen_const_reg
(
constinfo
)
# step 5: generate the code for namespaces
for
ns
in
sorted
(
self
.
ns_funcs
):
if
ns
!=
'cv'
:
self
.
gen_namespace
(
ns
)
# That's it. Now save all the files
self
.
save
(
output_path
,
"pyopencv_generated_include.h"
,
self
.
code_include
)
self
.
save
(
output_path
,
"pyopencv_generated_funcs.h"
,
self
.
code_funcs
)
...
...
@@ -896,6 +897,7 @@ class PythonWrapperGenerator(object):
self
.
save
(
output_path
,
"pyopencv_generated_const_reg.h"
,
self
.
code_const_reg
)
self
.
save
(
output_path
,
"pyopencv_generated_types.h"
,
self
.
code_types
)
self
.
save
(
output_path
,
"pyopencv_generated_type_reg.h"
,
self
.
code_type_reg
)
self
.
save
(
output_path
,
"pyopencv_generated_ns_reg.h"
,
self
.
code_ns_reg
)
if
__name__
==
"__main__"
:
srcfiles
=
hdr_parser
.
opencv_hdr_list
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录