1
0
forked from GitHub/gf-core

construction of Int and Float literals in the Java binding

This commit is contained in:
krasimir
2017-05-11 07:44:10 +00:00
parent a77ae5da30
commit 2cf98147e6
2 changed files with 56 additions and 0 deletions

View File

@@ -1226,6 +1226,46 @@ Java_org_grammaticalframework_pgf_Expr_initStringLit(JNIEnv* env, jclass clazz,
return expr;
}
JNIEXPORT jlong JNICALL
Java_org_grammaticalframework_pgf_Expr_initIntLit(JNIEnv* env, jclass clazz, jint jd, jlong jpool)
{
GuPool* pool = l2p(jpool);
PgfExpr expr;
PgfExprLit* e =
gu_new_variant(PGF_EXPR_LIT,
PgfExprLit,
&expr, pool);
PgfLiteralInt* nlit =
gu_new_variant(PGF_LITERAL_INT,
PgfLiteralInt,
&e->lit, pool);
nlit->val = jd;
return expr;
}
JNIEXPORT jlong JNICALL
Java_org_grammaticalframework_pgf_Expr_initFloatLit(JNIEnv* env, jclass clazz, jdouble jf, jlong jpool)
{
GuPool* pool = l2p(jpool);
PgfExpr expr;
PgfExprLit* e =
gu_new_variant(PGF_EXPR_LIT,
PgfExprLit,
&expr, pool);
PgfLiteralFlt* flit =
gu_new_variant(PGF_LITERAL_FLT,
PgfLiteralFlt,
&e->lit, pool);
flit->val = jf;
return expr;
}
JNIEXPORT jlong JNICALL
Java_org_grammaticalframework_pgf_Expr_initApp__Lorg_grammaticalframework_pgf_Expr_2_3Lorg_grammaticalframework_pgf_Expr_2J
(JNIEnv* env, jclass clazz, jobject jfun, jobjectArray args, jlong jpool)

View File

@@ -31,6 +31,20 @@ public class Expr implements Serializable {
this.ref = initStringLit(s, pool.ref);
}
/** Constructs an expression which represents an integer literal */
public Expr(int d) {
this.pool = new Pool();
this.master = null;
this.ref = initIntLit(d, pool.ref);
}
/** Constructs an expression which represents a floating point literal */
public Expr(double f) {
this.pool = new Pool();
this.master = null;
this.ref = initFloatLit(f, pool.ref);
}
/** Constructs an expression which is a function application
* @param fun The name of the top-level function.
* @param args the arguments for the function.
@@ -85,6 +99,8 @@ public class Expr implements Serializable {
private static native String showExpr(long ref);
private static native long initStringLit(String s, long pool);
private static native long initIntLit(int d, long pool);
private static native long initFloatLit(double f, long pool);
private static native long initApp(Expr fun, Expr[] args, long pool);
private static native long initApp(String fun, Expr[] args, long pool);