Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
BC
public
liblinphone
Commits
4e504716
Commit
4e504716
authored
Apr 13, 2017
by
François Grisez
Browse files
Store the declared values of enumerations in the abstract API
parent
b8d8eac3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
53 additions
and
5 deletions
+53
-5
tools/genapixml.py
tools/genapixml.py
+16
-1
wrappers/cpp/abstractapi.py
wrappers/cpp/abstractapi.py
+29
-2
wrappers/cpp/enums_header.mustache
wrappers/cpp/enums_header.mustache
+1
-1
wrappers/cpp/genwrapper.py
wrappers/cpp/genwrapper.py
+7
-1
No files found.
tools/genapixml.py
View file @
4e504716
...
...
@@ -34,7 +34,9 @@ class CObject:
class
CEnumValue
(
CObject
):
pass
def
__init__
(
self
,
name
):
CObject
.
__init__
(
self
,
name
)
self
.
value
=
None
class
CEnum
(
CObject
):
...
...
@@ -360,8 +362,21 @@ class Project:
c
.
addMethod
(
f
)
break
def
__parseCEnumValueInitializer
(
self
,
initializer
):
initializer
=
initializer
.
strip
()
if
not
initializer
.
startswith
(
'='
):
return
None
initializer
=
initializer
[
1
:]
initializer
.
strip
()
return
initializer
def
__parseCEnumValue
(
self
,
node
):
ev
=
CEnumValue
(
node
.
find
(
'./name'
).
text
)
initializerNode
=
node
.
find
(
'./initializer'
)
if
initializerNode
is
not
None
:
ev
.
value
=
self
.
__parseCEnumValueInitializer
(
initializerNode
.
text
)
deprecatedNode
=
node
.
find
(
".//xrefsect[xreftitle='Deprecated']"
)
if
deprecatedNode
is
not
None
:
ev
.
deprecated
=
True
...
...
wrappers/cpp/abstractapi.py
View file @
4e504716
...
...
@@ -14,15 +14,19 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import
re
import
genapixml
as
CApi
class
Error
(
RuntimeError
):
pass
class
BlacklistedException
(
Error
):
pass
class
Name
(
object
):
camelCaseParsingRegex
=
re
.
compile
(
'[A-Z][a-z0-9]*'
)
lowerCamelCaseSplitingRegex
=
re
.
compile
(
'([a-z][a-z0-9]*)([A-Z][a-z0-9]*)'
)
...
...
@@ -277,8 +281,22 @@ class Namespace(DocumentableObject):
child
.
parent
=
self
class
Flag
:
def
__init__
(
self
,
position
):
self
.
position
=
position
class
EnumValue
(
DocumentableObject
):
pass
def
__init__
(
self
,
name
):
DocumentableObject
.
__init__
(
self
,
name
)
self
.
value
=
None
def
value_from_string
(
self
,
stringValue
):
m
=
re
.
match
(
'^1\s*<<\s*([0-9]+)$'
,
stringValue
)
if
m
is
not
None
:
self
.
value
=
Flag
(
int
(
m
.
group
(
1
)))
else
:
self
.
value
=
int
(
stringValue
,
base
=
0
)
class
Enum
(
DocumentableObject
):
...
...
@@ -478,7 +496,11 @@ class CParser(object):
def
parse_all
(
self
):
for
enum
in
self
.
cProject
.
enums
:
self
.
parse_enum
(
enum
)
try
:
self
.
parse_enum
(
enum
)
except
Error
as
e
:
print
(
'Could not parse
\'
{0}
\'
enum: {1}'
.
format
(
enum
.
name
,
e
.
args
[
0
]))
for
_class
in
self
.
cProject
.
classes
:
try
:
self
.
parse_class
(
_class
)
...
...
@@ -570,6 +592,11 @@ class CParser(object):
valueName
=
EnumValueName
()
valueName
.
from_camel_case
(
cEnumValue
.
name
,
namespace
=
name
)
aEnumValue
=
EnumValue
(
valueName
)
if
cEnumValue
.
value
is
not
None
:
try
:
aEnumValue
.
value_from_string
(
cEnumValue
.
value
)
except
ValueError
:
raise
Error
(
'{0} enum value has an invalid definition ({1})'
.
format
(
cEnumValue
.
name
,
cEnumValue
.
value
))
enum
.
add_value
(
aEnumValue
)
self
.
enumsIndex
[
nameStr
]
=
enum
...
...
wrappers/cpp/enums_header.mustache
View file @
4e504716
...
...
@@ -24,7 +24,7 @@ namespace linphone {
{{#
enums
}}
enum
{{
name
}}
{
{{#
values
}}
{{
name
}}{{#
notLast
}}
,
{{/
notLast
}}
{{
name
}}{{#
value
}}
=
{{{
value
}}}{{/
value
}}{{#
notLast
}}
,
{{/
notLast
}}
{{/
values
}}
};
...
...
wrappers/cpp/genwrapper.py
View file @
4e504716
...
...
@@ -55,6 +55,12 @@ class CppTranslator(object):
def
translate_enum_value
(
enumValue
):
enumValueDict
=
{}
enumValueDict
[
'name'
]
=
CppTranslator
.
translate_enum_value_name
(
enumValue
.
name
)
if
type
(
enumValue
.
value
)
is
int
:
enumValueDict
[
'value'
]
=
str
(
enumValue
.
value
)
elif
type
(
enumValue
.
value
)
is
AbsApi
.
Flag
:
enumValueDict
[
'value'
]
=
'1<<'
+
str
(
enumValue
.
value
.
position
)
else
:
enumValueDict
[
'value'
]
=
None
return
enumValueDict
def
translate_class
(
self
,
_class
):
...
...
@@ -429,7 +435,7 @@ class CppTranslator(object):
raise
AbsApi
.
Error
(
'{0} has been escaped'
.
format
(
_type
.
name
))
if
_type
.
desc
is
None
:
raise
AbsApi
.
Error
(
'{0} has not been fixed'
.
format
(
_type
.
name
.
to_camel_case
(
fullName
=
True
)
))
raise
AbsApi
.
Error
(
'{0} has not been fixed'
.
format
(
_type
.
name
))
if
'namespace'
in
params
:
nsName
=
params
[
'namespace'
].
name
if
params
[
'namespace'
]
is
not
None
else
None
...
...
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