Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
djinni
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
djinni
Commits
bf108787
Commit
bf108787
authored
Mar 06, 2015
by
Miro Knejp
Committed by
Jacob Potter
May 01, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use marshalling objects to generate code for function return types
parent
6b17a860
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
30 additions
and
12 deletions
+30
-12
src/source/CppGenerator.scala
src/source/CppGenerator.scala
+1
-1
src/source/CppMarshal.scala
src/source/CppMarshal.scala
+3
-0
src/source/JNIGenerator.scala
src/source/JNIGenerator.scala
+3
-3
src/source/JNIMarshal.scala
src/source/JNIMarshal.scala
+3
-0
src/source/JavaGenerator.scala
src/source/JavaGenerator.scala
+3
-3
src/source/JavaMarshal.scala
src/source/JavaMarshal.scala
+3
-0
src/source/Marshal.scala
src/source/Marshal.scala
+4
-1
src/source/ObjcGenerator.scala
src/source/ObjcGenerator.scala
+1
-1
src/source/ObjcMarshal.scala
src/source/ObjcMarshal.scala
+3
-0
src/source/ObjcppGenerator.scala
src/source/ObjcppGenerator.scala
+3
-3
src/source/ObjcppMarshal.scala
src/source/ObjcppMarshal.scala
+3
-0
No files found.
src/source/CppGenerator.scala
View file @
bf108787
...
...
@@ -317,7 +317,7 @@ class CppGenerator(spec: Spec) extends Generator(spec) {
for
(
m
<-
i
.
methods
)
{
w
.
wl
writeDoc
(
w
,
m
.
doc
)
val
ret
=
m
.
ret
.
fold
(
"void"
)(
marshal
.
typename
(
_
)
)
val
ret
=
m
arshal
.
returnType
(
m
.
ret
)
val
params
=
m
.
params
.
map
(
p
=>
marshal
.
paramType
(
p
.
ty
)
+
" "
+
idCpp
.
local
(
p
.
ident
))
if
(
m
.
static
)
{
w
.
wl
(
s
"static $ret ${idCpp.method(m.ident)}${params.mkString("
(
", "
,
", "
)
")};"
)
...
...
src/source/CppMarshal.scala
View file @
bf108787
...
...
@@ -23,6 +23,9 @@ class CppMarshal(spec: Spec) extends Marshal(spec) {
override
def
paramType
(
tm
:
MExpr
)
:
String
=
toCppParamType
(
tm
)
override
def
fqParamType
(
tm
:
MExpr
)
:
String
=
toCppParamType
(
tm
,
spec
.
cppNamespace
)
override
def
returnType
(
ret
:
Option
[
TypeRef
])
:
String
=
ret
.
fold
(
"void"
)(
toCppType
(
_
,
None
))
override
def
fqReturnType
(
ret
:
Option
[
TypeRef
])
:
String
=
ret
.
fold
(
"void"
)(
toCppType
(
_
,
spec
.
cppNamespace
))
private
def
toCppType
(
ty
:
TypeRef
,
namespace
:
Option
[
String
]
=
None
)
:
String
=
toCppType
(
ty
.
resolved
,
namespace
)
private
def
toCppType
(
tm
:
MExpr
,
namespace
:
Option
[
String
])
:
String
=
{
def
base
(
m
:
Meta
)
:
String
=
m
match
{
...
...
src/source/JNIGenerator.scala
View file @
bf108787
...
...
@@ -209,7 +209,7 @@ class JNIGenerator(spec: Spec) extends Generator(spec) {
w
.
wlOutdent
(
s
"public:"
)
w
.
wl
(
s
"JavaProxy(jobject obj);"
)
for
(
m
<-
i
.
methods
)
{
val
ret
=
m
.
ret
.
fold
(
"void"
)(
cppMarshal
.
fqTypename
)
val
ret
=
cppMarshal
.
fqReturnType
(
m
.
ret
)
val
params
=
m
.
params
.
map
(
p
=>
cppMarshal
.
fqParamType
(
p
.
ty
)
+
" "
+
idCpp
.
local
(
p
.
ident
))
w
.
wl
(
s
"virtual $ret ${idCpp.method(m.ident)}${params.mkString("
(
", "
,
", "
)
")} override;"
)
}
...
...
@@ -238,7 +238,7 @@ class JNIGenerator(spec: Spec) extends Generator(spec) {
for
(
m
<-
i
.
methods
)
{
w
.
wl
val
ret
=
m
.
ret
.
fold
(
"void"
)(
cppMarshal
.
fqTypename
)
val
ret
=
cppMarshal
.
fqReturnType
(
m
.
ret
)
val
params
=
m
.
params
.
map
(
p
=>
cppMarshal
.
fqParamType
(
p
.
ty
)
+
" c_"
+
idCpp
.
local
(
p
.
ident
))
writeJniTypeParams
(
w
,
typeParams
)
w
.
w
(
s
"$ret $jniSelf::JavaProxy::JavaProxy::${idCpp.method(m.ident)}${params.mkString("
(
", "
,
", "
)
")}"
).
bracedSemi
{
...
...
@@ -278,7 +278,7 @@ class JNIGenerator(spec: Spec) extends Generator(spec) {
val
prefix
=
"Java_"
+
classIdentMunged
def
nativeHook
(
name
:
String
,
static
:
Boolean
,
params
:
Iterable
[
Field
],
ret
:
Option
[
TypeRef
],
f
:
=>
Unit
)
=
{
val
paramList
=
params
.
map
(
p
=>
jniMarshal
.
paramType
(
p
.
ty
)
+
" j_"
+
idJava
.
local
(
p
.
ident
)).
mkString
(
", "
)
val
jniRetType
=
ret
.
fold
(
"void"
)(
toJniType
)
val
jniRetType
=
jniMarshal
.
fqReturnType
(
ret
)
w
.
wl
val
methodNameMunged
=
name
.
replaceAllLiterally
(
"_"
,
"_1"
)
val
zero
=
ret
.
fold
(
""
)(
s
=>
"0 /* value doesn't matter */"
)
...
...
src/source/JNIMarshal.scala
View file @
bf108787
...
...
@@ -16,6 +16,9 @@ class JNIMarshal(spec: Spec) extends Marshal(spec) {
override
def
paramType
(
tm
:
MExpr
)
:
String
=
toJniType
(
tm
,
false
)
override
def
fqParamType
(
tm
:
MExpr
)
:
String
=
paramType
(
tm
)
override
def
returnType
(
ret
:
Option
[
TypeRef
])
:
String
=
ret
.
fold
(
"void"
)(
toJniType
)
override
def
fqReturnType
(
ret
:
Option
[
TypeRef
])
:
String
=
returnType
(
ret
)
// Name for the autogenerated class containing field/method IDs and toJava()/fromJava() methods
def
helperClass
(
name
:
String
)
=
spec
.
jniClassIdentStyle
(
name
)
def
fqHelperClass
(
name
:
String
)
=
withNs
(
Some
(
spec
.
jniNamespace
),
helperClass
(
name
))
...
...
src/source/JavaGenerator.scala
View file @
bf108787
...
...
@@ -151,14 +151,14 @@ class JavaGenerator(spec: Spec) extends Generator(spec) {
for
(
m
<-
i
.
methods
if
!
m
.
static
)
{
skipFirst
{
w
.
wl
}
writeDoc
(
w
,
m
.
doc
)
val
ret
=
m
.
ret
.
fold
(
"void"
)(
marshal
.
typename
(
_
)
)
val
ret
=
m
arshal
.
returnType
(
m
.
ret
)
val
params
=
m
.
params
.
map
(
p
=>
marshal
.
paramType
(
p
.
ty
)
+
" "
+
idJava
.
local
(
p
.
ident
))
w
.
wl
(
"public abstract "
+
ret
+
" "
+
idJava
.
method
(
m
.
ident
)
+
params
.
mkString
(
"("
,
", "
,
")"
)
+
throwException
+
";"
)
}
for
(
m
<-
i
.
methods
if
m
.
static
)
{
skipFirst
{
w
.
wl
}
writeDoc
(
w
,
m
.
doc
)
val
ret
=
m
.
ret
.
fold
(
"void"
)(
marshal
.
typename
(
_
)
)
val
ret
=
m
arshal
.
returnType
(
m
.
ret
)
val
params
=
m
.
params
.
map
(
p
=>
marshal
.
paramType
(
p
.
ty
)
+
" "
+
idJava
.
local
(
p
.
ident
))
w
.
wl
(
"public static native "
+
ret
+
" "
+
idJava
.
method
(
m
.
ident
)
+
params
.
mkString
(
"("
,
", "
,
")"
)
+
";"
)
}
...
...
@@ -184,7 +184,7 @@ class JavaGenerator(spec: Spec) extends Generator(spec) {
w
.
wl
(
"super.finalize();"
)
}
for
(
m
<-
i
.
methods
if
!
m
.
static
)
{
// Static methods not in CppProxy
val
ret
=
m
.
ret
.
fold
(
"void"
)(
marshal
.
typename
(
_
)
)
val
ret
=
m
arshal
.
returnType
(
m
.
ret
)
val
returnStmt
=
m
.
ret
.
fold
(
""
)(
_
=>
"return "
)
val
params
=
m
.
params
.
map
(
p
=>
marshal
.
paramType
(
p
.
ty
)
+
" "
+
idJava
.
local
(
p
.
ident
)).
mkString
(
", "
)
val
args
=
m
.
params
.
map
(
p
=>
idJava
.
local
(
p
.
ident
)).
mkString
(
", "
)
...
...
src/source/JavaMarshal.scala
View file @
bf108787
...
...
@@ -15,6 +15,9 @@ class JavaMarshal(spec: Spec) extends Marshal(spec) {
override
def
paramType
(
tm
:
MExpr
)
:
String
=
typename
(
tm
)
override
def
fqParamType
(
tm
:
MExpr
)
:
String
=
fqTypename
(
tm
)
override
def
returnType
(
ret
:
Option
[
TypeRef
])
:
String
=
ret
.
fold
(
"void"
)(
ty
=>
toJavaType
(
ty
.
resolved
,
None
))
override
def
fqReturnType
(
ret
:
Option
[
TypeRef
])
:
String
=
ret
.
fold
(
"void"
)(
ty
=>
toJavaType
(
ty
.
resolved
,
spec
.
javaPackage
))
private
def
toJavaType
(
tm
:
MExpr
,
packageName
:
Option
[
String
])
:
String
=
{
def
f
(
tm
:
MExpr
,
needRef
:
Boolean
)
:
String
=
{
tm
.
base
match
{
...
...
src/source/Marshal.scala
View file @
bf108787
...
...
@@ -22,10 +22,13 @@ abstract class Marshal(spec: Spec) {
def
fqParamType
(
tm
:
MExpr
)
:
String
def
fqParamType
(
ty
:
TypeRef
)
:
String
=
fqParamType
(
ty
.
resolved
)
def
returnType
(
ret
:
Option
[
TypeRef
])
:
String
def
fqReturnType
(
ret
:
Option
[
TypeRef
])
:
String
implicit
def
identToString
(
ident
:
Ident
)
:
String
=
ident
.
name
protected
val
idCpp
=
spec
.
cppIdentStyle
protected
val
idJava
=
spec
.
javaIdentStyle
protected
val
idObjc
=
spec
.
objcIdentStyle
protected
def
withNs
(
namespace
:
Option
[
String
],
t
:
String
)
=
namespace
.
fold
(
t
)(
"::"
+
_
+
"::"
+
t
)
protected
def
withNs
(
namespace
:
Option
[
String
],
t
:
String
)
=
namespace
.
fold
(
t
)(
"::"
+
_
+
"::"
+
t
)
}
src/source/ObjcGenerator.scala
View file @
bf108787
...
...
@@ -154,7 +154,7 @@ class ObjcGenerator(spec: Spec) extends Generator(spec) {
def
writeObjcFuncDecl
(
method
:
Interface.Method
,
w
:
IndentWriter
)
{
val
label
=
if
(
method
.
static
)
"+"
else
"-"
val
ret
=
m
ethod
.
ret
.
fold
(
"void"
)(
marshal
.
paramType
)
val
ret
=
m
arshal
.
returnType
(
method
.
ret
)
w
.
w
(
s
"$label ($ret)${idObjc.method(method.ident)}"
)
val
skipFirst
=
SkipFirst
()
for
(
p
<-
method
.
params
)
{
...
...
src/source/ObjcMarshal.scala
View file @
bf108787
...
...
@@ -19,6 +19,9 @@ class ObjcMarshal(spec: Spec) extends Marshal(spec) {
override
def
paramType
(
tm
:
MExpr
)
:
String
=
toObjcParamType
(
tm
)
override
def
fqParamType
(
tm
:
MExpr
)
:
String
=
paramType
(
tm
)
override
def
returnType
(
ret
:
Option
[
TypeRef
])
:
String
=
ret
.
fold
(
"void"
)(
paramType
)
override
def
fqReturnType
(
ret
:
Option
[
TypeRef
])
:
String
=
returnType
(
ret
)
// Return value: (Type_Name, Is_Class_Or_Not)
def
toObjcType
(
ty
:
TypeRef
)
:
(
String
,
Boolean
)
=
toObjcType
(
ty
.
resolved
,
false
)
def
toObjcType
(
ty
:
TypeRef
,
needRef
:
Boolean
)
:
(
String
,
Boolean
)
=
toObjcType
(
ty
.
resolved
,
needRef
)
...
...
src/source/ObjcppGenerator.scala
View file @
bf108787
...
...
@@ -193,7 +193,7 @@ class ObjcppGenerator(spec: Spec) extends Generator(spec) {
def
writeObjcFuncDecl
(
method
:
Interface.Method
,
w
:
IndentWriter
)
{
val
label
=
if
(
method
.
static
)
"+"
else
"-"
val
ret
=
method
.
ret
.
fold
(
"void"
)(
objcMarshal
.
paramType
)
val
ret
=
objcMarshal
.
fqReturnType
(
method
.
ret
)
w
.
w
(
s
"$label ($ret)${idObjc.method(method.ident)}"
)
val
skipFirst
=
SkipFirst
()
for
(
p
<-
method
.
params
)
{
...
...
@@ -293,7 +293,7 @@ class ObjcppGenerator(spec: Spec) extends Generator(spec) {
w
.
wl
(
s
"virtual ~$objcExtSelf () override;"
)
w
.
wl
(
s
"static std::shared_ptr<$cppSelf> ${idCpp.method(ident.name + "
_with_objc
")} (id<$self> objcRef);"
)
for
(
m
<-
i
.
methods
)
{
val
ret
=
m
.
ret
.
fold
(
"void"
)(
cppMarshal
.
fqTypename
)
val
ret
=
cppMarshal
.
fqReturnType
(
m
.
ret
)
val
params
=
m
.
params
.
map
(
p
=>
cppMarshal
.
fqParamType
(
p
.
ty
)
+
" "
+
idCpp
.
local
(
p
.
ident
))
w
.
wl
(
s
"virtual $ret ${idCpp.method(m.ident)} ${params.mkString("
(
", "
,
", "
)
")} override;"
)
}
...
...
@@ -317,7 +317,7 @@ class ObjcppGenerator(spec: Spec) extends Generator(spec) {
}
for
(
m
<-
i
.
methods
)
{
w
.
wl
val
ret
=
m
.
ret
.
fold
(
"void"
)(
cppMarshal
.
fqTypename
)
val
ret
=
cppMarshal
.
fqReturnType
(
m
.
ret
)
val
params
=
m
.
params
.
map
(
p
=>
cppMarshal
.
fqParamType
(
p
.
ty
)
+
" "
+
idCpp
.
local
(
p
.
ident
))
w
.
wl
(
s
"$ret $objcExtSelf::${idCpp.method(m.ident)} ${params.mkString("
(
", "
,
", "
)
")}"
).
braced
{
w
.
w
(
"@autoreleasepool"
).
braced
{
...
...
src/source/ObjcppMarshal.scala
View file @
bf108787
...
...
@@ -15,6 +15,9 @@ class ObjcppMarshal(spec: Spec) extends Marshal(spec) {
def
paramType
(
tm
:
MExpr
)
:
String
=
throw
new
AssertionError
(
"not applicable"
)
def
fqParamType
(
tm
:
MExpr
)
:
String
=
throw
new
AssertionError
(
"not applicable"
)
def
returnType
(
ret
:
Option
[
TypeRef
])
:
String
=
throw
new
AssertionError
(
"not applicable"
)
def
fqReturnType
(
ret
:
Option
[
TypeRef
])
:
String
=
throw
new
AssertionError
(
"not applicable"
)
// Name for the autogenerated proxy class wrapping +o interfaces
def
helperClass
(
name
:
String
)
=
idCpp
.
ty
(
name
)
def
fqHelperClass
(
name
:
String
)
=
withNs
(
Some
(
spec
.
objcppNamespace
),
helperClass
(
name
))
...
...
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