1
0
forked from GitHub/gf-core

added readType in Java

This commit is contained in:
Krasimir Angelov
2017-08-30 08:15:59 +02:00
parent 3e9de6ffbb
commit d92f8f2f9e

View File

@@ -1539,6 +1539,34 @@ Java_org_grammaticalframework_pgf_Type_getHypos(JNIEnv* env, jobject self)
return jhypos;
}
JNIEXPORT jobject JNICALL
Java_org_grammaticalframework_pgf_Type_readType(JNIEnv* env, jclass clazz, jstring s)
{
GuPool* pool = gu_new_pool();
GuPool* tmp_pool = gu_local_pool();
GuString buf = j2gu_string(env, s, tmp_pool);
GuIn* in = gu_data_in((uint8_t*) buf, strlen(buf), tmp_pool);
GuExn* err = gu_exn(tmp_pool);
PgfType* ty = pgf_read_type(in, pool, err);
if (!gu_ok(err)) {
throw_string_exception(env, "org/grammaticalframework/pgf/PGFError", "The type cannot be parsed");
gu_pool_free(tmp_pool);
gu_pool_free(pool);
return NULL;
}
gu_pool_free(tmp_pool);
jclass pool_class = (*env)->FindClass(env, "org/grammaticalframework/pgf/Pool");
jmethodID pool_constrId = (*env)->GetMethodID(env, pool_class, "<init>", "(J)V");
jobject jpool = (*env)->NewObject(env, pool_class, pool_constrId, p2l(pool));
jmethodID constrId = (*env)->GetMethodID(env, clazz, "<init>", "(Ljava/lang/Object;J)V");
return (*env)->NewObject(env, clazz, constrId, jpool, p2l(ty));
}
JNIEXPORT jstring JNICALL
Java_org_grammaticalframework_pgf_Type_toString(JNIEnv* env, jobject self)
{