Volker Birk 10 years ago
parent
commit
f9ddf78282
  1. 62
      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

62
src/gen_cpp_Engine.ysl2

@ -1,7 +1,9 @@
include yslt.yml2
tstylesheet {
include ./textutils.ysl2
include ./types_c.ysl2
include ./types_java.ysl2
template "/namespace[@name='pEp']" apply "interface", 0;
@ -23,6 +25,9 @@ tstylesheet {
template "method" {
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»(
@ -40,30 +45,59 @@ tstylesheet {
||
choose {
when "count(parm[returns|creates]) > 1"
||
jclass clazz = findClass(env, "org/pEp/jniadapter/_«@name»_Return");
||
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" {
apply "parm[returns|creates]", mode=return {
with "retname", "'result'";
}
}
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 {
with "name", "'result'";
with "jtype", "$jtype";
with "jnitype", "'jlong'";
with "retname", "$retname";
with "sig", "'(J)V'";
}
otherwise error | # not implemented: return type "«$rettype»"
}
}
||
jmethodID constructor = env->GetMethodID(clazz, "<init>", "()V");
assert(constructor);
jobject result = env->NewObject(clazz, constructor);
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 {
const "type", "name(*[2])";
const "name", "name(*[3])";

1
src/gen_cpp_Message.ysl2

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

1
src/gen_java_Engine.ysl2

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

7
src/gen_java_Message.ysl2

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

2
src/types_c.ysl2

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

21
src/types_java.ysl2

@ -1,5 +1,3 @@
include ./textutils.ysl2
function "toJava" {
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" {
param "type";

Loading…
Cancel
Save