Volker Birk 10 years ago
parent
commit
f9ddf78282
  1. 60
      src/gen_cpp_Engine.ysl2
  2. 1
      src/gen_cpp_Message.ysl2
  3. 1
      src/gen_java_Engine.ysl2
  4. 7
      src/gen_java_Message.ysl2
  5. 2
      src/types_c.ysl2
  6. 21
      src/types_java.ysl2

60
src/gen_cpp_Engine.ysl2

@ -1,7 +1,9 @@
include yslt.yml2 include yslt.yml2
tstylesheet { tstylesheet {
include ./textutils.ysl2
include ./types_c.ysl2 include ./types_c.ysl2
include ./types_java.ysl2
template "/namespace[@name='pEp']" apply "interface", 0; template "/namespace[@name='pEp']" apply "interface", 0;
@ -23,6 +25,9 @@ tstylesheet {
template "method" { template "method" {
const "mangled" call "mangle"; const "mangled" call "mangle";
const "rettype", "name(parm[creates|returns]/*[2])";
const "retname", "name(parm[creates|returns]/*[3])";
const "jtype" call "toJavaDeclare" with "type", "$rettype";
|| ||
JNIEXPORT jobject JNICALL «$mangled»( JNIEXPORT jobject JNICALL «$mangled»(
@ -40,30 +45,59 @@ tstylesheet {
|| ||
choose { choose {
when "count(parm[returns|creates]) > 1" when "count(parm[returns|creates]) > 1" {
|| apply "parm[returns|creates]", mode=return {
jclass clazz = findClass(env, "org/pEp/jniadapter/_«@name»_Return"); with "retname", "'result'";
|| }
when "count(parm[returns|creates]) = 1" {
const "jtype" call "CamelCase" with "text", "name(parm[creates|returns]/*[2])";
||
jclass clazz = findClass(env, "org/pEp/jniadapter/«$jtype»");
||
} }
when "count(parm[returns|creates]) = 1" choose {
when "$rettype = 'Color'" apply "parm[returns|creates]", mode=return {
with "name", "'result'";
with "jtype", "$jtype";
with "jnitype", "'jint'";
with "retname", "$retname";
with "sig", "'(I)V'";
} }
|| when "$rettype = 'message'" apply "parm[returns|creates]", mode=return {
jmethodID constructor = env->GetMethodID(clazz, "<init>", "()V"); with "name", "'result'";
assert(constructor); with "jtype", "$jtype";
jobject result = env->NewObject(clazz, constructor); with "jnitype", "'jlong'";
with "retname", "$retname";
with "sig", "'(J)V'";
}
otherwise error | # not implemented: return type "«$rettype»"
}
}
||
return result; return result;
} }
|| ||
} }
template "parm", mode=return {
param "jtype" call "toJavaDeclare" with "type", "name(*[2])";
param "name", "concat(name(*[3]), '_')";
param "jnitype";
param "retname";
param "sig", "'()V'";
||
jclass clazz_«$name» = findClass(env, "org/pEp/jniadapter/«$jtype»");
jmethodID constructor_«$name» = env->GetMethodID(clazz_«$name», "<init>", "«$sig»");
assert(constructor_«$name»);
||
indent(0);
> jobject «$name» = env->NewObject(clazz_«$name», constructor_«$name»
if "$jnitype" > , («$jnitype») _«$retname»
> );\n\n
}
template "parm", mode=in { template "parm", mode=in {
const "type", "name(*[2])"; const "type", "name(*[2])";
const "name", "name(*[3])"; const "name", "name(*[3])";

1
src/gen_cpp_Message.ysl2

@ -1,6 +1,7 @@
include yslt.yml2 include yslt.yml2
tstylesheet { tstylesheet {
include ./textutils.ysl2
include ./types_c.ysl2 include ./types_c.ysl2
template "/namespace[@name='pEp']" apply "struct", 0; template "/namespace[@name='pEp']" apply "struct", 0;

1
src/gen_java_Engine.ysl2

@ -1,6 +1,7 @@
include yslt.yml2 include yslt.yml2
tstylesheet { tstylesheet {
include ./textutils.ysl2
include ./types_java.ysl2 include ./types_java.ysl2
template "/namespace[@name='pEp']" apply "interface", 0; template "/namespace[@name='pEp']" apply "interface", 0;

7
src/gen_java_Message.ysl2

@ -1,6 +1,7 @@
include yslt.yml2 include yslt.yml2
tstylesheet { tstylesheet {
include ./textutils.ysl2
include ./types_java.ysl2 include ./types_java.ysl2
template "/namespace[@name='pEp']" apply "struct|enum", 0; template "/namespace[@name='pEp']" apply "struct|enum", 0;
@ -17,7 +18,7 @@ tstylesheet {
import java.util.HashMap; import java.util.HashMap;
public class «$cname» implements AutoCloseable { public class «$cname» implements AutoCloseable {
private final long handle; private long handle;
native long init(); native long init();
native void release(long handle); native void release(long handle);
@ -26,6 +27,10 @@ tstylesheet {
handle = init(); handle = init();
} }
private «$cname»(long h) {
handle = h;
}
public final void close() { public final void close() {
release(handle); release(handle);
} }

2
src/types_c.ysl2

@ -1,5 +1,3 @@
include ./textutils.ysl2
function "toC" { function "toC" {
param "type"; param "type";

21
src/types_java.ysl2

@ -1,5 +1,3 @@
include ./textutils.ysl2
function "toJava" { function "toJava" {
param "type"; param "type";
@ -19,6 +17,25 @@ function "toJava" {
} }
} }
function "toJavaDeclare" {
param "type";
choose {
when "$type='stringlist'" > java.util.Vector
when "$type='string'" error | # cannot declare "string"
when "$type='message'" > org.pEp.jniadapter.Message
when "$type='identity'" > org.pEp.jniadapter._Identity
when "$type='identitylist'" > java.util.Vector
when "$type='timestamp'" > java.util.Date
when "$type='EncFormat'" > org.pEp.jniadapter.Message.EncFormat
when "$type='bloblist'" > java.util.Vector
when "$type='stringpairlist'" > java.util.ArrayList
when "$type='message'" > org.pEp.jniadapter.Message
when "$type='Color'" > org.pEp.jniadapter.Color
otherwise error | # cannot declare "«$type»"
}
}
function "toIntermediate" { function "toIntermediate" {
param "type"; param "type";

Loading…
Cancel
Save