forked from GitHub/gf-core
added checkExpr in Java
This commit is contained in:
@@ -929,7 +929,7 @@ Prelude PGF2> print e'
|
|||||||
AdjCN (PositA red_A) (UseN theatre_N)
|
AdjCN (PositA red_A) (UseN theatre_N)
|
||||||
</pre>
|
</pre>
|
||||||
<pre class="java">
|
<pre class="java">
|
||||||
Expr new_e = gr.checkExpr(e,Type.readType("CN")); //// TODO
|
Expr new_e = gr.checkExpr(e,Type.readType("CN"));
|
||||||
System.out.println(e)
|
System.out.println(e)
|
||||||
</pre>
|
</pre>
|
||||||
<pre class="csharp">
|
<pre class="csharp">
|
||||||
|
|||||||
@@ -1704,3 +1704,43 @@ Java_org_grammaticalframework_pgf_PGF_inferExpr(JNIEnv* env, jobject self, jobje
|
|||||||
|
|
||||||
return jtyped_expr;
|
return jtyped_expr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JNIEXPORT jobject JNICALL
|
||||||
|
Java_org_grammaticalframework_pgf_PGF_checkExpr(JNIEnv* env, jobject self, jobject jexpr, jobject jtp)
|
||||||
|
{
|
||||||
|
GuPool* pool = gu_new_pool();
|
||||||
|
GuPool* tmp_pool = gu_local_pool();
|
||||||
|
GuExn* err = gu_exn(tmp_pool);
|
||||||
|
|
||||||
|
PgfExpr expr =
|
||||||
|
gu_variant_from_ptr((void*) get_ref(env, jexpr));
|
||||||
|
PgfType* tp =
|
||||||
|
get_ref(env, jtp);
|
||||||
|
pgf_check_expr(get_ref(env, self), &expr, tp, err, pool);
|
||||||
|
if (!gu_ok(err)) {
|
||||||
|
if (gu_exn_caught(err, PgfExn)) {
|
||||||
|
GuString msg = (GuString) gu_exn_caught_data(err);
|
||||||
|
throw_string_exception(env, "org/grammaticalframework/pgf/PGFError", msg);
|
||||||
|
} else if (gu_exn_caught(err, PgfTypeError)) {
|
||||||
|
GuString msg = (GuString) gu_exn_caught_data(err);
|
||||||
|
throw_string_exception(env, "org/grammaticalframework/pgf/TypeError", msg);
|
||||||
|
} else {
|
||||||
|
throw_string_exception(env, "org/grammaticalframework/pgf/PGFError", "The type cannot be inferred");
|
||||||
|
}
|
||||||
|
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));
|
||||||
|
|
||||||
|
jclass expr_class = (*env)->GetObjectClass(env, jexpr);
|
||||||
|
jmethodID expr_constrId = (*env)->GetMethodID(env, expr_class, "<init>", "(Lorg/grammaticalframework/pgf/Pool;Ljava/lang/Object;J)V");
|
||||||
|
jexpr = (*env)->NewObject(env, expr_class, expr_constrId, jpool, NULL, p2l(gu_variant_to_ptr(expr)));
|
||||||
|
|
||||||
|
return jexpr;
|
||||||
|
}
|
||||||
|
|||||||
@@ -67,7 +67,10 @@ public class PGF {
|
|||||||
/** Takes an expression and returns a refined version
|
/** Takes an expression and returns a refined version
|
||||||
* of the expression together with its type */
|
* of the expression together with its type */
|
||||||
public native TypedExpr inferExpr(Expr expr) throws TypeError;
|
public native TypedExpr inferExpr(Expr expr) throws TypeError;
|
||||||
|
|
||||||
|
/** Takes an expression and checks it agains a type. The returned expression
|
||||||
|
* is a possibly refined version of the original. */
|
||||||
|
public native Expr checkExpr(Expr expr, Type ty) throws TypeError;
|
||||||
|
|
||||||
public native String graphvizAbstractTree(Expr expr);
|
public native String graphvizAbstractTree(Expr expr);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user