mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-09 04:59:31 -06:00
small refactoring in the Java binding
This commit is contained in:
@@ -51,16 +51,10 @@ j2gu_string(JNIEnv *env, jstring s, GuPool* pool) {
|
||||
return gu_str_string(str, pool);
|
||||
}
|
||||
|
||||
static PgfPGF*
|
||||
get_pgf(JNIEnv *env, jobject self) {
|
||||
jfieldID grId = (*env)->GetFieldID(env, (*env)->GetObjectClass(env, self), "gr", "J");
|
||||
return (PgfPGF*) (*env)->GetLongField(env, self, grId);
|
||||
}
|
||||
|
||||
static PgfPGF*
|
||||
get_concr(JNIEnv *env, jobject self) {
|
||||
jfieldID concrId = (*env)->GetFieldID(env, (*env)->GetObjectClass(env, self), "concr", "J");
|
||||
return (PgfPGF*) (*env)->GetLongField(env, self, concrId);
|
||||
static void*
|
||||
get_ref(JNIEnv *env, jobject self) {
|
||||
jfieldID refId = (*env)->GetFieldID(env, (*env)->GetObjectClass(env, self), "ref", "J");
|
||||
return (void*) (*env)->GetLongField(env, self, refId);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -123,7 +117,7 @@ Java_org_grammaticalframework_pgf_PGF_readPGF(JNIEnv *env, jclass cls, jstring s
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_org_grammaticalframework_pgf_PGF_getAbstractName(JNIEnv* env, jobject self)
|
||||
{
|
||||
return gu2j_string(env, pgf_abstract_name(get_pgf(env, self)));
|
||||
return gu2j_string(env, pgf_abstract_name(get_ref(env, self)));
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
@@ -171,7 +165,7 @@ Java_org_grammaticalframework_pgf_PGF_getLanguages(JNIEnv* env, jobject self)
|
||||
if (!languages)
|
||||
return NULL;
|
||||
|
||||
PgfPGF* pgf = get_pgf(env, self);
|
||||
PgfPGF* pgf = get_ref(env, self);
|
||||
|
||||
GuPool* tmp_pool = gu_local_pool();
|
||||
|
||||
@@ -193,7 +187,7 @@ Java_org_grammaticalframework_pgf_PGF_getLanguages(JNIEnv* env, jobject self)
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_org_grammaticalframework_pgf_Concr_getName(JNIEnv* env, jobject self)
|
||||
{
|
||||
return gu2j_string(env, pgf_concrete_name(get_concr(env, self)));
|
||||
return gu2j_string(env, pgf_concrete_name(get_ref(env, self)));
|
||||
}
|
||||
|
||||
JNIEXPORT jobject JNICALL
|
||||
@@ -210,7 +204,7 @@ Java_org_grammaticalframework_pgf_Parser_parse
|
||||
PgfLexer *lexer = pgf_new_simple_lexer(rdr, pool);
|
||||
|
||||
GuEnum* res =
|
||||
pgf_parse(get_concr(env, concr), startCat, lexer, pool, out_pool);
|
||||
pgf_parse(get_ref(env, concr), startCat, lexer, pool, out_pool);
|
||||
|
||||
if (res == NULL) {
|
||||
PgfToken tok =
|
||||
@@ -256,7 +250,7 @@ Java_org_grammaticalframework_pgf_Pool_free(JNIEnv* env, jobject self, jlong ref
|
||||
gu_pool_free((GuPool*) ref);
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_org_grammaticalframework_pgf_Expr_showExpr(JNIEnv* env, jclass clazz, jlong ref)
|
||||
{
|
||||
GuPool* tmp_pool = gu_local_pool();
|
||||
|
||||
@@ -14,10 +14,10 @@ public class Concr {
|
||||
// private stuff
|
||||
|
||||
private PGF gr;
|
||||
public long concr;
|
||||
public long ref;
|
||||
|
||||
private Concr(PGF gr, long concr) {
|
||||
this.gr = gr;
|
||||
this.concr = concr;
|
||||
private Concr(PGF gr, long ref) {
|
||||
this.gr = gr;
|
||||
this.ref = ref;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,20 +3,22 @@ package org.grammaticalframework.pgf;
|
||||
import java.util.*;
|
||||
|
||||
class ExprIterator implements Iterator<ExprProb> {
|
||||
private Concr concr;
|
||||
private Pool pool, out_pool;
|
||||
private long enumRef;
|
||||
private long ref;
|
||||
private ExprProb ep;
|
||||
private boolean fetched;
|
||||
|
||||
public ExprIterator(long pool, long out_pool, long enumRef) {
|
||||
this.pool = new Pool(pool);
|
||||
public ExprIterator(Concr concr, long pool, long out_pool, long ref) {
|
||||
this.concr = concr;
|
||||
this.pool = new Pool(pool);
|
||||
this.out_pool = new Pool(out_pool);
|
||||
this.enumRef = enumRef;
|
||||
this.ep = null;
|
||||
this.fetched = false;
|
||||
this.ref = ref;
|
||||
this.ep = null;
|
||||
this.fetched = false;
|
||||
}
|
||||
|
||||
private native ExprProb fetchExprProb(long enumRef, Pool out_pool);
|
||||
private native ExprProb fetchExprProb(long ref, Pool out_pool);
|
||||
|
||||
private void fetch() {
|
||||
if (!fetched) {
|
||||
|
||||
@@ -30,18 +30,18 @@ public class PGF {
|
||||
private static native void free(long pool);
|
||||
|
||||
private long pool;
|
||||
private long gr;
|
||||
private long ref;
|
||||
|
||||
private PGF(long pool, long gr) {
|
||||
private PGF(long pool, long ref) {
|
||||
this.pool = pool;
|
||||
this.gr = gr;
|
||||
this.ref = ref;
|
||||
}
|
||||
|
||||
protected void finalize () throws Throwable {
|
||||
if (pool != 0) {
|
||||
free(pool);
|
||||
pool = 0;
|
||||
gr = 0;
|
||||
ref = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user