Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
a8ad5a40
L
libvirt
项目概览
openeuler
/
libvirt
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
libvirt
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
a8ad5a40
编写于
4月 10, 2011
作者:
M
Matthias Bolte
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
esx: Cleanup VI generator code
上级
2444c411
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
71 addition
and
106 deletion
+71
-106
src/esx/esx_vi_generator.py
src/esx/esx_vi_generator.py
+71
-106
未找到文件。
src/esx/esx_vi_generator.py
浏览文件 @
a8ad5a40
...
...
@@ -41,6 +41,11 @@ valid_occurrences = [OCCURRENCE__REQUIRED_ITEM,
def
aligned
(
left
,
right
):
while
len
(
left
)
<
59
:
left
+=
" "
return
left
+
right
...
...
@@ -64,9 +69,6 @@ class Parameter:
def
is_enum
(
self
):
global
predefined_enums
global
enums_by_name
return
self
.
type
in
predefined_enums
or
self
.
type
in
enums_by_name
...
...
@@ -88,10 +90,7 @@ class Parameter:
else
:
string
+=
", "
while
len
(
string
)
<
59
:
string
+=
" "
return
string
+
self
.
get_occurrence_comment
()
+
"
\n
"
return
aligned
(
string
,
self
.
get_occurrence_comment
()
+
"
\n
"
)
def
generate_return
(
self
,
offset
=
0
,
end_of_line
=
";"
):
...
...
@@ -102,10 +101,7 @@ class Parameter:
string
+=
" "
*
offset
string
+=
"%s%s)%s"
%
(
self
.
get_type_string
(
True
),
self
.
name
,
end_of_line
)
while
len
(
string
)
<
59
:
string
+=
" "
return
string
+
self
.
get_occurrence_comment
()
+
"
\n
"
return
aligned
(
string
,
self
.
get_occurrence_comment
()
+
"
\n
"
)
def
generate_require_code
(
self
):
...
...
@@ -274,9 +270,6 @@ class Property:
def
is_enum
(
self
):
global
predefined_enums
global
enums_by_name
return
self
.
type
in
predefined_enums
or
self
.
type
in
enums_by_name
...
...
@@ -286,10 +279,7 @@ class Property:
else
:
string
=
" %s%s; "
%
(
self
.
get_type_string
(),
self
.
name
)
while
len
(
string
)
<
59
:
string
+=
" "
return
string
+
self
.
get_occurrence_comment
()
+
"
\n
"
return
aligned
(
string
,
self
.
get_occurrence_comment
()
+
"
\n
"
)
def
generate_free_code
(
self
):
...
...
@@ -380,7 +370,37 @@ class Property:
class
Object
:
class
Base
:
def
__init__
(
self
,
kind
,
name
):
self
.
kind
=
kind
self
.
name
=
name
def
generate_typedef
(
self
):
return
"typedef %s _esxVI_%s esxVI_%s;
\n
"
%
(
self
.
kind
,
self
.
name
,
self
.
name
)
def
generate_typeenum
(
self
):
return
" esxVI_Type_%s,
\n
"
%
self
.
name
def
generate_typetostring
(
self
):
string
=
" case esxVI_Type_%s:
\n
"
%
self
.
name
string
+=
" return
\"
%s
\"
;
\n\n
"
%
self
.
name
return
string
def
generate_typefromstring
(
self
):
string
=
" else if (STREQ(type,
\"
%s
\"
)) {
\n
"
%
self
.
name
string
+=
" return esxVI_Type_%s;
\n
"
%
self
.
name
string
+=
" }
\n
"
return
string
class
Object
(
Base
):
FEATURE__DYNAMIC_CAST
=
(
1
<<
1
)
FEATURE__LIST
=
(
1
<<
2
)
FEATURE__DEEP_COPY
=
(
1
<<
3
)
...
...
@@ -390,34 +410,24 @@ class Object:
def
__init__
(
self
,
name
,
extends
,
properties
,
features
=
0
,
extended_by
=
None
):
self
.
name
=
name
Base
.
__init__
(
self
,
"struct"
,
name
)
self
.
extends
=
extends
self
.
features
=
features
|
Object
.
FEATURE__SERIALIZE
|
Object
.
FEATURE__DESERIALIZE
self
.
properties
=
properties
self
.
extended_by
=
extended_by
if
self
.
extended_by
is
not
None
:
self
.
extended_by
.
sort
()
;
self
.
extended_by
.
sort
()
def
generate_struct_members
(
self
,
add_banner
=
False
,
struct_gap
=
False
):
global
objects_by_name
def
generate_struct_members
(
self
,
add_banner
=
False
,
struct_gap
=
False
):
members
=
""
if
self
.
extends
is
None
:
struct_gap
=
True
string
=
" esxVI_Type _type; "
while
len
(
string
)
<
59
:
string
+=
" "
members
+=
string
+
"/* required */
\n
"
if
struct_gap
and
self
.
extends
is
None
:
if
struct_gap
:
members
+=
"
\n
"
if
self
.
extends
is
not
None
:
members
+=
objects_by_name
[
self
.
extends
].
generate_struct_members
(
add_banner
=
True
,
struct_gap
=
False
)
+
"
\n
"
members
+=
objects_by_name
[
self
.
extends
].
generate_struct_members
(
add_banner
=
True
,
struct_gap
=
False
)
+
"
\n
"
if
self
.
extends
is
not
None
or
add_banner
:
members
+=
" /* %s */
\n
"
%
self
.
name
...
...
@@ -431,12 +441,11 @@ class Object:
return
members
def
generate_free_code
(
self
,
add_banner
=
False
):
global
objects_by_name
def
generate_free_code
(
self
,
add_banner
=
False
):
source
=
""
if
self
.
extends
is
not
None
:
source
+=
objects_by_name
[
self
.
extends
].
generate_free_code
(
add_banner
=
True
)
+
"
\n
"
source
+=
objects_by_name
[
self
.
extends
].
generate_free_code
(
add_banner
=
True
)
+
"
\n
"
if
self
.
extends
is
not
None
or
add_banner
:
source
+=
" /* %s */
\n
"
%
self
.
name
...
...
@@ -457,12 +466,11 @@ class Object:
return
source
def
generate_validate_code
(
self
,
add_banner
=
False
):
global
objects_by_name
def
generate_validate_code
(
self
,
add_banner
=
False
):
source
=
""
if
self
.
extends
is
not
None
:
source
+=
objects_by_name
[
self
.
extends
].
generate_validate_code
(
add_banner
=
True
)
+
"
\n
"
source
+=
objects_by_name
[
self
.
extends
].
generate_validate_code
(
add_banner
=
True
)
+
"
\n
"
if
self
.
extends
is
not
None
or
add_banner
:
source
+=
" /* %s */
\n
"
%
self
.
name
...
...
@@ -484,7 +492,6 @@ class Object:
def
generate_dynamic_cast_code
(
self
,
is_first
=
True
):
global
objects_by_name
source
=
""
if
self
.
extended_by
is
not
None
:
...
...
@@ -503,7 +510,6 @@ class Object:
def
generate_deep_copy_code
(
self
,
add_banner
=
False
):
global
objects_by_name
source
=
""
if
self
.
extends
is
not
None
:
...
...
@@ -529,7 +535,6 @@ class Object:
def
generate_serialize_code
(
self
,
add_banner
=
False
):
global
objects_by_name
source
=
""
if
self
.
extends
is
not
None
:
...
...
@@ -548,11 +553,10 @@ class Object:
def
generate_deserialize_code
(
self
,
add_banner
=
False
):
global
objects_by_name
source
=
""
if
self
.
extends
is
not
None
:
source
+=
objects_by_name
[
self
.
extends
].
generate_deserialize_code
(
add_banner
=
True
)
+
"
\n
"
source
+=
objects_by_name
[
self
.
extends
].
generate_deserialize_code
(
add_banner
=
True
)
+
"
\n
"
if
self
.
extends
is
not
None
or
add_banner
:
source
+=
" /* %s */
\n
"
%
self
.
name
...
...
@@ -566,29 +570,6 @@ class Object:
return
source
def
generate_typedef
(
self
):
return
"typedef struct _esxVI_%s esxVI_%s;
\n
"
%
(
self
.
name
,
self
.
name
)
def
generate_typeenum
(
self
):
return
" esxVI_Type_%s,
\n
"
%
self
.
name
def
generate_typetostring
(
self
):
string
=
" case esxVI_Type_%s:
\n
"
%
self
.
name
string
+=
" return
\"
%s
\"
;
\n\n
"
%
self
.
name
return
string
def
generate_typefromstring
(
self
):
string
=
" else if (STREQ(type,
\"
%s
\"
)) {
\n
"
%
self
.
name
string
+=
" return esxVI_Type_%s;
\n
"
%
self
.
name
string
+=
" }
\n
"
return
string
def
generate_header
(
self
):
header
=
"/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
\n
"
header
+=
" * VI Type: %s
\n
"
%
self
.
name
...
...
@@ -612,17 +593,12 @@ class Object:
header
+=
"struct _esxVI_%s {
\n
"
%
self
.
name
if
self
.
features
&
Object
.
FEATURE__LIST
:
string
=
" esxVI_%s *_next; "
%
self
.
name
header
+=
aligned
(
" esxVI_%s *_next; "
%
self
.
name
,
"/* optional */
\n
"
)
else
:
string
=
" esxVI_%s *_unused; "
%
self
.
name
while
len
(
string
)
<
59
:
string
+=
" "
header
+=
string
+
"/* optional */
\n
"
header
+=
self
.
generate_struct_members
(
struct_gap
=
True
)
header
+=
aligned
(
" esxVI_%s *_unused; "
%
self
.
name
,
"/* optional */
\n
"
)
header
+=
aligned
(
" esxVI_Type _type; "
,
"/* required */
\n
"
)
header
+=
self
.
generate_struct_members
(
struct_gap
=
True
)
header
+=
"};
\n\n
"
# functions
...
...
@@ -888,39 +864,28 @@ class Object:
class
Enum
:
FEATURE__ANY_TYPE
=
(
1
<<
1
)
FEATURE__SERIALIZE
=
(
1
<<
2
)
FEATURE__DESERIALIZE
=
(
1
<<
3
)
def
__init__
(
self
,
name
,
values
,
features
=
0
):
self
.
name
=
name
self
.
values
=
values
self
.
features
=
features
|
Enum
.
FEATURE__SERIALIZE
|
Enum
.
FEATURE__DESERIALIZE
def
generate_typedef
(
self
):
return
"typedef enum _esxVI_%s esxVI_%s;
\n
"
%
(
self
.
name
,
self
.
name
)
def
generate_typeenum
(
self
):
return
" esxVI_Type_%s,
\n
"
%
self
.
name
def
generate_typetostring
(
self
):
string
=
" case esxVI_Type_%s:
\n
"
%
self
.
name
string
+=
" return
\"
%s
\"
;
\n\n
"
%
self
.
name
return
string
def
generate_typefromstring
(
self
):
string
=
" else if (STREQ(type,
\"
%s
\"
)) {
\n
"
%
self
.
name
string
+=
" return esxVI_Type_%s;
\n
"
%
self
.
name
string
+=
" }
\n
"
return
string
class
Enum
(
Base
):
FEATURE__ANY_TYPE
=
(
1
<<
1
)
FEATURE__SERIALIZE
=
(
1
<<
2
)
FEATURE__DESERIALIZE
=
(
1
<<
3
)
def
__init__
(
self
,
name
,
values
,
features
=
0
):
Base
.
__init__
(
self
,
"enum"
,
name
)
self
.
values
=
values
self
.
features
=
features
|
Enum
.
FEATURE__SERIALIZE
|
Enum
.
FEATURE__DESERIALIZE
def
generate_header
(
self
):
...
...
@@ -1027,8 +992,8 @@ def parse_object(block):
if
items
[
2
]
not
in
valid_occurrences
:
report_error
(
"line %d: invalid occurrence"
%
line
[
0
])
properties
.
append
(
Property
(
type
=
items
[
0
],
name
=
items
[
1
],
occurrence
=
items
[
2
]))
properties
.
append
(
Property
(
type
=
items
[
0
],
name
=
items
[
1
],
occurrence
=
items
[
2
]))
return
Object
(
name
=
name
,
extends
=
extends
,
properties
=
properties
)
...
...
@@ -1051,7 +1016,7 @@ def parse_enum(block):
# expected format: <value>
values
.
append
(
line
[
1
])
return
Enum
(
name
=
name
,
values
=
values
)
return
Enum
(
name
=
name
,
values
=
values
)
...
...
@@ -1071,8 +1036,8 @@ def parse_method(block):
if
header_items
[
2
]
!=
"returns"
:
report_error
(
"line %d: invalid block header"
%
(
number
))
else
:
returns
=
Parameter
(
type
=
header_items
[
3
],
name
=
"output"
,
occurrence
=
header_items
[
4
])
returns
=
Parameter
(
type
=
header_items
[
3
],
name
=
"output"
,
occurrence
=
header_items
[
4
])
parameters
=
[]
...
...
@@ -1086,10 +1051,10 @@ def parse_method(block):
if
items
[
2
]
not
in
valid_occurrences
:
report_error
(
"line %d: invalid occurrence"
%
line
[
0
])
parameters
.
append
(
Parameter
(
type
=
items
[
0
],
name
=
items
[
1
],
occurrence
=
items
[
2
]))
parameters
.
append
(
Parameter
(
type
=
items
[
0
],
name
=
items
[
1
],
occurrence
=
items
[
2
]))
return
Method
(
name
=
name
,
parameters
=
parameters
,
returns
=
returns
)
return
Method
(
name
=
name
,
parameters
=
parameters
,
returns
=
returns
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录