Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
900df21b
Commit
900df21b
authored
Aug 20, 2018
by
Hamdi Sahloul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support enum-type detection for binding generator
parent
93bad514
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
7 deletions
+26
-7
gen_java.py
modules/java/generator/gen_java.py
+8
-0
gen2.py
modules/python/src2/gen2.py
+11
-0
hdr_parser.py
modules/python/src2/hdr_parser.py
+7
-7
No files found.
modules/java/generator/gen_java.py
View file @
900df21b
...
@@ -341,6 +341,7 @@ class JavaWrapperGenerator(object):
...
@@ -341,6 +341,7 @@ class JavaWrapperGenerator(object):
self
.
classes
=
{
"Mat"
:
ClassInfo
([
'class Mat'
,
''
,
[],
[]
],
self
.
namespaces
)
}
self
.
classes
=
{
"Mat"
:
ClassInfo
([
'class Mat'
,
''
,
[],
[]
],
self
.
namespaces
)
}
self
.
module
=
""
self
.
module
=
""
self
.
Module
=
""
self
.
Module
=
""
self
.
enum_types
=
[]
self
.
ported_func_list
=
[]
self
.
ported_func_list
=
[]
self
.
skipped_func_list
=
[]
self
.
skipped_func_list
=
[]
self
.
def_args_hist
=
{}
# { def_args_cnt : funcs_cnt }
self
.
def_args_hist
=
{}
# { def_args_cnt : funcs_cnt }
...
@@ -421,6 +422,10 @@ class JavaWrapperGenerator(object):
...
@@ -421,6 +422,10 @@ class JavaWrapperGenerator(object):
ci
.
addConst
(
constinfo
)
ci
.
addConst
(
constinfo
)
logging
.
info
(
'ok:
%
s'
,
constinfo
)
logging
.
info
(
'ok:
%
s'
,
constinfo
)
def
add_enum
(
self
,
decl
):
# [ "enum cname", "", [], [] ]
enumname
=
decl
[
0
]
.
replace
(
"enum "
,
""
)
.
strip
()
self
.
enum_types
.
append
(
enumname
)
def
add_func
(
self
,
decl
):
def
add_func
(
self
,
decl
):
fi
=
FuncInfo
(
decl
,
namespaces
=
self
.
namespaces
)
fi
=
FuncInfo
(
decl
,
namespaces
=
self
.
namespaces
)
classname
=
fi
.
classname
or
self
.
Module
classname
=
fi
.
classname
or
self
.
Module
...
@@ -479,6 +484,9 @@ class JavaWrapperGenerator(object):
...
@@ -479,6 +484,9 @@ class JavaWrapperGenerator(object):
self
.
add_class
(
decl
)
self
.
add_class
(
decl
)
elif
name
.
startswith
(
"const"
):
elif
name
.
startswith
(
"const"
):
self
.
add_const
(
decl
)
self
.
add_const
(
decl
)
elif
name
.
startswith
(
"enum"
):
# enum
self
.
add_enum
(
decl
)
else
:
# function
else
:
# function
self
.
add_func
(
decl
)
self
.
add_func
(
decl
)
...
...
modules/python/src2/gen2.py
View file @
900df21b
...
@@ -664,6 +664,9 @@ class FuncInfo(object):
...
@@ -664,6 +664,9 @@ class FuncInfo(object):
if
tp
.
endswith
(
"*"
):
if
tp
.
endswith
(
"*"
):
defval0
=
"0"
defval0
=
"0"
tp1
=
tp
.
replace
(
"*"
,
"_ptr"
)
tp1
=
tp
.
replace
(
"*"
,
"_ptr"
)
tp_candidates
=
[
a
.
tp
,
normalize_class_name
(
self
.
namespace
+
"."
+
a
.
tp
)]
if
any
(
tp
in
codegen
.
enum_types
for
tp
in
tp_candidates
):
defval0
=
"static_cast<
%
s>(
%
d)"
%
(
a
.
tp
,
0
)
amapping
=
simple_argtype_mapping
.
get
(
tp
,
(
tp
,
"O"
,
defval0
))
amapping
=
simple_argtype_mapping
.
get
(
tp
,
(
tp
,
"O"
,
defval0
))
parse_name
=
a
.
name
parse_name
=
a
.
name
...
@@ -835,6 +838,7 @@ class PythonWrapperGenerator(object):
...
@@ -835,6 +838,7 @@ class PythonWrapperGenerator(object):
self
.
classes
=
{}
self
.
classes
=
{}
self
.
namespaces
=
{}
self
.
namespaces
=
{}
self
.
consts
=
{}
self
.
consts
=
{}
self
.
enum_types
=
[]
self
.
code_include
=
StringIO
()
self
.
code_include
=
StringIO
()
self
.
code_types
=
StringIO
()
self
.
code_types
=
StringIO
()
self
.
code_funcs
=
StringIO
()
self
.
code_funcs
=
StringIO
()
...
@@ -892,6 +896,10 @@ class PythonWrapperGenerator(object):
...
@@ -892,6 +896,10 @@ class PythonWrapperGenerator(object):
py_signatures
.
append
(
dict
(
name
=
py_name
,
value
=
value
))
py_signatures
.
append
(
dict
(
name
=
py_name
,
value
=
value
))
#print(cname + ' => ' + str(py_name) + ' (value=' + value + ')')
#print(cname + ' => ' + str(py_name) + ' (value=' + value + ')')
def
add_enum
(
self
,
name
,
decl
):
enumname
=
normalize_class_name
(
name
)
self
.
enum_types
.
append
(
enumname
)
def
add_func
(
self
,
decl
):
def
add_func
(
self
,
decl
):
namespace
,
classes
,
barename
=
self
.
split_decl_name
(
decl
[
0
])
namespace
,
classes
,
barename
=
self
.
split_decl_name
(
decl
[
0
])
cname
=
"::"
.
join
(
namespace
+
classes
+
[
barename
])
cname
=
"::"
.
join
(
namespace
+
classes
+
[
barename
])
...
@@ -996,6 +1004,9 @@ class PythonWrapperGenerator(object):
...
@@ -996,6 +1004,9 @@ class PythonWrapperGenerator(object):
elif
name
.
startswith
(
"const"
):
elif
name
.
startswith
(
"const"
):
# constant
# constant
self
.
add_const
(
name
.
replace
(
"const "
,
""
)
.
strip
(),
decl
)
self
.
add_const
(
name
.
replace
(
"const "
,
""
)
.
strip
(),
decl
)
elif
name
.
startswith
(
"enum"
):
# enum
self
.
add_enum
(
name
.
replace
(
"enum "
,
""
)
.
strip
(),
decl
)
else
:
else
:
# function
# function
self
.
add_func
(
decl
)
self
.
add_func
(
decl
)
...
...
modules/python/src2/hdr_parser.py
View file @
900df21b
...
@@ -705,20 +705,19 @@ class CppHeaderParser(object):
...
@@ -705,20 +705,19 @@ class CppHeaderParser(object):
decl
[
1
]
=
": "
+
", "
.
join
([
self
.
get_dotted_name
(
b
)
.
replace
(
"."
,
"::"
)
for
b
in
bases
])
decl
[
1
]
=
": "
+
", "
.
join
([
self
.
get_dotted_name
(
b
)
.
replace
(
"."
,
"::"
)
for
b
in
bases
])
return
stmt_type
,
classname
,
True
,
decl
return
stmt_type
,
classname
,
True
,
decl
if
stmt
.
startswith
(
"enum"
):
if
stmt
.
startswith
(
"enum"
)
or
stmt
.
startswith
(
"namespace"
):
return
"enum"
,
""
,
True
,
None
if
stmt
.
startswith
(
"namespace"
):
stmt_list
=
stmt
.
split
()
stmt_list
=
stmt
.
split
()
if
len
(
stmt_list
)
<
2
:
if
len
(
stmt_list
)
<
2
:
stmt_list
.
append
(
"<unnamed>"
)
stmt_list
.
append
(
"<unnamed>"
)
return
stmt_list
[
0
],
stmt_list
[
1
],
True
,
None
return
stmt_list
[
0
],
stmt_list
[
1
],
True
,
None
if
stmt
.
startswith
(
"extern"
)
and
"
\"
C
\"
"
in
stmt
:
if
stmt
.
startswith
(
"extern"
)
and
"
\"
C
\"
"
in
stmt
:
return
"namespace"
,
""
,
True
,
None
return
"namespace"
,
""
,
True
,
None
if
end_token
==
"}"
and
context
==
"enum"
:
if
end_token
==
"}"
and
context
==
"enum"
:
decl
=
self
.
parse_enum
(
stmt
)
decl
=
self
.
parse_enum
(
stmt
)
return
"enum"
,
""
,
False
,
decl
name
=
stack_top
[
self
.
BLOCK_NAME
]
return
"enum"
,
name
,
False
,
decl
if
end_token
==
";"
and
stmt
.
startswith
(
"typedef"
):
if
end_token
==
";"
and
stmt
.
startswith
(
"typedef"
):
# TODO: handle typedef's more intelligently
# TODO: handle typedef's more intelligently
...
@@ -896,8 +895,9 @@ class CppHeaderParser(object):
...
@@ -896,8 +895,9 @@ class CppHeaderParser(object):
stmt_type
,
name
,
parse_flag
,
decl
=
self
.
parse_stmt
(
stmt
,
token
,
docstring
=
docstring
)
stmt_type
,
name
,
parse_flag
,
decl
=
self
.
parse_stmt
(
stmt
,
token
,
docstring
=
docstring
)
if
decl
:
if
decl
:
if
stmt_type
==
"enum"
:
if
stmt_type
==
"enum"
:
for
d
in
decl
:
if
name
!=
"<unnamed>"
:
decls
.
append
(
d
)
decls
.
append
([
"enum "
+
self
.
get_dotted_name
(
name
),
""
,
[],
[],
None
,
""
])
decls
.
extend
(
decl
)
else
:
else
:
decls
.
append
(
decl
)
decls
.
append
(
decl
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment