diff --git a/src/gen_cpp_Engine.ysl2 b/src/gen_cpp_Engine.ysl2 index 614dd16..106e036 100644 --- a/src/gen_cpp_Engine.ysl2 +++ b/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, "", "()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», "", "«$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])"; diff --git a/src/gen_cpp_Message.ysl2 b/src/gen_cpp_Message.ysl2 index de42452..1cd6c1b 100644 --- a/src/gen_cpp_Message.ysl2 +++ b/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; diff --git a/src/gen_java_Engine.ysl2 b/src/gen_java_Engine.ysl2 index 80e6821..6366b4c 100644 --- a/src/gen_java_Engine.ysl2 +++ b/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; diff --git a/src/gen_java_Message.ysl2 b/src/gen_java_Message.ysl2 index 1692ef1..9863d1f 100644 --- a/src/gen_java_Message.ysl2 +++ b/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); } diff --git a/src/types_c.ysl2 b/src/types_c.ysl2 index 7b0bcfe..2aede77 100644 --- a/src/types_c.ysl2 +++ b/src/types_c.ysl2 @@ -1,5 +1,3 @@ -include ./textutils.ysl2 - function "toC" { param "type"; diff --git a/src/types_java.ysl2 b/src/types_java.ysl2 index 79c7f58..5e918c3 100644 --- a/src/types_java.ysl2 +++ b/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";