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
901de4b2
Commit
901de4b2
authored
Mar 01, 2015
by
Miro Knejp
Committed by
Jacob Potter
Apr 17, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move C++ stuff from base Marshal to CppMarshal
parent
4b803ef0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
54 deletions
+51
-54
src/source/CppMarshal.scala
src/source/CppMarshal.scala
+47
-2
src/source/JNIMarshal.scala
src/source/JNIMarshal.scala
+2
-2
src/source/JavaMarshal.scala
src/source/JavaMarshal.scala
+2
-2
src/source/Marshal.scala
src/source/Marshal.scala
+0
-48
No files found.
src/source/CppMarshal.scala
View file @
901de4b2
...
...
@@ -6,18 +6,63 @@ import djinni.meta._
class
CppMarshal
(
spec
:
Spec
)
extends
Marshal
(
spec
)
{
def
typename
(
tm
:
MExpr
)
:
String
=
toCppType
(
tm
,
None
)
override
def
typename
(
tm
:
MExpr
)
:
String
=
toCppType
(
tm
,
None
)
def
typename
(
name
:
String
,
ty
:
TypeDef
)
:
String
=
ty
match
{
case
e
:
Enum
=>
idCpp
.
enumType
(
name
)
case
i
:
Interface
=>
idCpp
.
ty
(
name
)
case
r
:
Record
=>
idCpp
.
ty
(
name
)
}
def
fqTypename
(
tm
:
MExpr
)
:
String
=
toCppType
(
tm
,
spec
.
cppNamespace
)
override
def
fqTypename
(
tm
:
MExpr
)
:
String
=
toCppType
(
tm
,
spec
.
cppNamespace
)
def
fqTypename
(
name
:
String
,
ty
:
TypeDef
)
:
String
=
ty
match
{
case
e
:
Enum
=>
withNs
(
spec
.
cppNamespace
,
idCpp
.
enumType
(
name
))
case
i
:
Interface
=>
withNs
(
spec
.
cppNamespace
,
idCpp
.
ty
(
name
))
case
r
:
Record
=>
withNs
(
spec
.
cppNamespace
,
idCpp
.
ty
(
name
))
}
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
{
case
p
:
MPrimitive
=>
p
.
cName
case
MString
=>
"std::string"
case
MDate
=>
"std::chrono::system_clock::time_point"
case
MBinary
=>
"std::vector<uint8_t>"
case
MOptional
=>
spec
.
cppOptionalTemplate
case
MList
=>
"std::vector"
case
MSet
=>
"std::unordered_set"
case
MMap
=>
"std::unordered_map"
case
d
:
MDef
=>
d
.
defType
match
{
case
DEnum
=>
withNs
(
namespace
,
idCpp
.
enumType
(
d
.
name
))
case
DRecord
=>
withNs
(
namespace
,
idCpp
.
ty
(
d
.
name
))
case
DInterface
=>
s
"std::shared_ptr<${withNs(namespace, idCpp.ty(d.name))}>"
}
case
p
:
MParam
=>
idCpp
.
typeParam
(
p
.
name
)
}
def
expr
(
tm
:
MExpr
)
:
String
=
{
val
args
=
if
(
tm
.
args
.
isEmpty
)
""
else
tm
.
args
.
map
(
expr
).
mkString
(
"<"
,
", "
,
">"
)
base
(
tm
.
base
)
+
args
}
expr
(
tm
)
}
// this can be used in c++ generation to know whether a const& should be applied to the parameter or not
private
def
toCppParamType
(
f
:
Field
)
:
String
=
toCppParamType
(
f
,
None
,
""
)
private
def
toCppParamType
(
f
:
Field
,
namespace
:
Option
[
String
]
=
None
,
prefix
:
String
=
""
)
:
String
=
{
val
cppType
=
toCppType
(
f
.
ty
,
namespace
)
val
localName
=
prefix
+
idCpp
.
local
(
f
.
ident
);
val
refType
=
"const "
+
cppType
+
" & "
+
localName
val
valueType
=
cppType
+
" "
+
localName
def
toType
(
expr
:
MExpr
)
:
String
=
expr
.
base
match
{
case
MPrimitive
(
_
,
_
,
_
,
_
,
_
,
_
,
_
,
_
)
=>
valueType
case
d
:
MDef
=>
d
.
defType
match
{
case
DEnum
=>
valueType
case
_
=>
refType
}
case
MOptional
=>
toType
(
expr
.
args
.
head
)
case
_
=>
refType
}
toType
(
f
.
ty
.
resolved
)
}
}
src/source/JNIMarshal.scala
View file @
901de4b2
...
...
@@ -7,10 +7,10 @@ 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
)
override
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
)
override
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
...
...
src/source/JavaMarshal.scala
View file @
901de4b2
...
...
@@ -6,10 +6,10 @@ import djinni.meta._
class
JavaMarshal
(
spec
:
Spec
)
extends
Marshal
(
spec
)
{
def
typename
(
tm
:
MExpr
)
:
String
=
toJavaType
(
tm
,
None
)
override
def
typename
(
tm
:
MExpr
)
:
String
=
toJavaType
(
tm
,
None
)
def
typename
(
name
:
String
,
ty
:
TypeDef
)
:
String
=
idJava
.
ty
(
name
)
def
fqTypename
(
tm
:
MExpr
)
:
String
=
toJavaType
(
tm
,
spec
.
javaPackage
)
override
def
fqTypename
(
tm
:
MExpr
)
:
String
=
toJavaType
(
tm
,
spec
.
javaPackage
)
def
fqTypename
(
name
:
String
,
ty
:
TypeDef
)
:
String
=
withPackage
(
spec
.
javaPackage
,
idJava
.
ty
(
name
))
def
toJavaType
(
tm
:
MExpr
,
packageName
:
Option
[
String
])
:
String
=
{
...
...
src/source/Marshal.scala
View file @
901de4b2
...
...
@@ -13,62 +13,14 @@ abstract class Marshal(spec: Spec) {
// Typename string to be used to declare a type or template parameter, without namespace or package, except for extern types which are always fully qualified.
def
typename
(
tm
:
MExpr
)
:
String
def
typename
(
ty
:
TypeRef
)
:
String
=
typename
(
ty
.
resolved
)
def
typename
(
name
:
String
,
ty
:
TypeDef
)
:
String
// Same as typename() but always fully namespace or package qualified
def
fqTypename
(
tm
:
MExpr
)
:
String
def
fqTypename
(
ty
:
TypeRef
)
:
String
=
fqTypename
(
ty
.
resolved
)
def
fqTypename
(
name
:
String
,
ty
:
TypeDef
)
:
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
toCppType
(
ty
:
TypeRef
,
namespace
:
Option
[
String
]
=
None
)
:
String
=
toCppType
(
ty
.
resolved
,
namespace
)
protected
def
toCppType
(
tm
:
MExpr
,
namespace
:
Option
[
String
])
:
String
=
{
def
base
(
m
:
Meta
)
:
String
=
m
match
{
case
p
:
MPrimitive
=>
p
.
cName
case
MString
=>
"std::string"
case
MDate
=>
"std::chrono::system_clock::time_point"
case
MBinary
=>
"std::vector<uint8_t>"
case
MOptional
=>
spec
.
cppOptionalTemplate
case
MList
=>
"std::vector"
case
MSet
=>
"std::unordered_set"
case
MMap
=>
"std::unordered_map"
case
d
:
MDef
=>
d
.
defType
match
{
case
DEnum
=>
withNs
(
namespace
,
idCpp
.
enumType
(
d
.
name
))
case
DRecord
=>
withNs
(
namespace
,
idCpp
.
ty
(
d
.
name
))
case
DInterface
=>
s
"std::shared_ptr<${withNs(namespace, idCpp.ty(d.name))}>"
}
case
p
:
MParam
=>
idCpp
.
typeParam
(
p
.
name
)
}
def
expr
(
tm
:
MExpr
)
:
String
=
{
val
args
=
if
(
tm
.
args
.
isEmpty
)
""
else
tm
.
args
.
map
(
expr
).
mkString
(
"<"
,
", "
,
">"
)
base
(
tm
.
base
)
+
args
}
expr
(
tm
)
}
// this can be used in c++ generation to know whether a const& should be applied to the parameter or not
protected
def
toCppParamType
(
f
:
Field
)
:
String
=
toCppParamType
(
f
,
None
,
""
)
protected
def
toCppParamType
(
f
:
Field
,
namespace
:
Option
[
String
]
=
None
,
prefix
:
String
=
""
)
:
String
=
{
val
cppType
=
toCppType
(
f
.
ty
,
namespace
)
val
localName
=
prefix
+
idCpp
.
local
(
f
.
ident
);
val
refType
=
"const "
+
cppType
+
" & "
+
localName
val
valueType
=
cppType
+
" "
+
localName
def
toType
(
expr
:
MExpr
)
:
String
=
expr
.
base
match
{
case
MPrimitive
(
_
,
_
,
_
,
_
,
_
,
_
,
_
,
_
)
=>
valueType
case
d
:
MDef
=>
d
.
defType
match
{
case
DEnum
=>
valueType
case
_
=>
refType
}
case
MOptional
=>
toType
(
expr
.
args
.
head
)
case
_
=>
refType
}
toType
(
f
.
ty
.
resolved
)
}
protected
def
withNs
(
namespace
:
Option
[
String
],
t
:
String
)
=
namespace
.
fold
(
t
)(
"::"
+
_
+
"::"
+
t
)
}
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