bugfix for print names in the C runtime and expose the functionality from Java

This commit is contained in:
krasimir
2017-05-11 09:11:30 +00:00
parent f5c98af811
commit 77a91bdd1a
5 changed files with 26 additions and 7 deletions

View File

@@ -191,9 +191,7 @@ PGF_API GuString
pgf_print_name(PgfConcr* concr, PgfCId id)
{
PgfCId name =
gu_map_get(concr->printnames, id, PgfCId);
if (*name == 0)
name = id;
gu_map_get(concr->printnames, id, GuString);
return name;
}

View File

@@ -565,7 +565,7 @@ pgf_read_abstract(PgfReader* rdr, PgfAbstr* abstract)
static PgfCIdMap*
pgf_read_printnames(PgfReader* rdr)
{
PgfCIdMap* printnames = gu_new_string_map(GuString, &"", rdr->opool);
PgfCIdMap* printnames = gu_new_string_map(GuString, &gu_null_struct, rdr->opool);
size_t len = pgf_read_len(rdr);
gu_return_on_exn(rdr->err, NULL);

View File

@@ -1146,6 +1146,19 @@ Java_org_grammaticalframework_pgf_Concr_hasLinearization(JNIEnv* env, jobject se
return res;
}
JNIEXPORT jstring JNICALL
Java_org_grammaticalframework_pgf_Concr_getPrintName(JNIEnv* env, jobject self, jstring jid)
{
PgfConcr* concr = get_ref(env, self);
GuPool* tmp_pool = gu_local_pool();
PgfCId id = j2gu_string(env, jid, tmp_pool);
GuString name = pgf_print_name(concr, id);
jstring jname = (name == NULL) ? NULL : gu2j_string(env, name);
gu_pool_free(tmp_pool);
return jname;
}
JNIEXPORT jlong JNICALL
Java_org_grammaticalframework_pgf_Pool_alloc(JNIEnv* env, jclass clazz)
{

View File

@@ -79,6 +79,10 @@ public class Concr {
*/
public native boolean hasLinearization(String fun);
/** returns the print name for that function or category.
*/
public native String getPrintName(String id);
/** If the concrete syntaxes in the grammar are stored in external
* files then this method can be used to load the current syntax
* in memory.

View File

@@ -1303,11 +1303,15 @@ Concr_init(ConcrObject *self, PyObject *args, PyObject *kwds)
static PyObject*
Concr_printName(ConcrObject* self, PyObject *args)
{
GuString name;
if (!PyArg_ParseTuple(args, "s", &name))
GuString id;
if (!PyArg_ParseTuple(args, "s", &id))
return NULL;
return PyString_FromString(pgf_print_name(self->concr, name));
GuString name = pgf_print_name(self->concr, id);
if (name == NULL)
Py_RETURN_NONE;
return PyString_FromString(name);
}
#if ( (PY_VERSION_HEX < 0x02070000) \