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
4b803ef0
Commit
4b803ef0
authored
Mar 01, 2015
by
Miro Knejp
Committed by
Jacob Potter
Apr 17, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduce marshalling object for JNI code generator
parent
b2e75f1a
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
104 additions
and
76 deletions
+104
-76
src/source/JNIGenerator.scala
src/source/JNIGenerator.scala
+49
-76
src/source/JNIMarshal.scala
src/source/JNIMarshal.scala
+55
-0
No files found.
src/source/JNIGenerator.scala
View file @
4b803ef0
This diff is collapsed.
Click to expand it.
src/source/JNIMarshal.scala
0 → 100644
View file @
4b803ef0
package
djinni
import
djinni.ast._
import
djinni.generatorTools._
import
djinni.meta._
class
JNIMarshal
(
spec
:
Spec
)
extends
Marshal
(
spec
)
{
// For JNI typename() is always fully qualified and describes the mangled Java type to be used in field/method signatures
def
typename
(
tm
:
MExpr
)
:
String
=
javaTypeSignature
(
tm
)
def
typename
(
name
:
String
,
ty
:
TypeDef
)
:
String
=
throw
new
AssertionError
(
"not supported"
)
def
fqTypename
(
tm
:
MExpr
)
:
String
=
typename
(
tm
)
def
fqTypename
(
name
:
String
,
ty
:
TypeDef
)
:
String
=
typename
(
name
,
ty
)
// 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
))
def
toJniType
(
ty
:
TypeRef
)
:
String
=
toJniType
(
ty
.
resolved
,
false
)
def
toJniType
(
m
:
MExpr
,
needRef
:
Boolean
)
:
String
=
m
.
base
match
{
case
p
:
MPrimitive
=>
if
(
needRef
)
"jobject"
else
p
.
jniName
case
MString
=>
"jstring"
case
MOptional
=>
toJniType
(
m
.
args
.
head
,
true
)
case
MBinary
=>
"jbyteArray"
case
tp
:
MParam
=>
helperClass
(
tp
.
name
)
+
"::JniType"
case
_
=>
"jobject"
}
// The mangled Java typename without the "L...;" decoration useful only for class reflection on our own type
def
undecoratedTypename
(
name
:
String
,
ty
:
TypeDef
)
:
String
=
{
val
javaClassName
=
idJava
.
ty
(
name
)
spec
.
javaPackage
.
fold
(
javaClassName
)(
p
=>
p
.
replaceAllLiterally
(
"."
,
"/"
)
+
"/"
+
javaClassName
)
}
private
def
javaTypeSignature
(
tm
:
MExpr
)
:
String
=
tm
.
base
match
{
case
o
:
MOpaque
=>
o
match
{
case
p
:
MPrimitive
=>
p
.
jSig
case
MString
=>
"Ljava/lang/String;"
case
MDate
=>
"Ljava/util/Date;"
case
MBinary
=>
"[B"
case
MOptional
=>
tm
.
args
.
head
.
base
match
{
case
p
:
MPrimitive
=>
s
"Ljava/lang/${p.jBoxed};"
case
MOptional
=>
throw
new
AssertionError
(
"nested optional?"
)
case
m
=>
javaTypeSignature
(
tm
.
args
.
head
)
}
case
MList
=>
"Ljava/util/ArrayList;"
case
MSet
=>
"Ljava/util/HashSet;"
case
MMap
=>
"Ljava/util/HashMap;"
}
case
MParam
(
_
)
=>
"Ljava/lang/Object;"
case
d
:
MDef
=>
s
"L${undecoratedTypename(d.name, d.body)};"
}
}
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