mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-05 01:02:51 -06:00
The unmarshaller is no longer stored in the PGF object but is passed explicitly to each function that needs it.
This commit is contained in:
@@ -119,15 +119,12 @@ struct PGF_INTERNAL_DECL PgfPGFRoot {
|
||||
#pragma GCC diagnostic ignored "-Wattributes"
|
||||
|
||||
struct PgfPGF : DB {
|
||||
PGF_INTERNAL_DECL PgfPGF(const char* fpath, int flags, int mode,
|
||||
PgfUnmarshaller *unmarshaller)
|
||||
PGF_INTERNAL_DECL PgfPGF(const char* fpath, int flags, int mode)
|
||||
: DB(fpath, flags, mode)
|
||||
{ u = unmarshaller; };
|
||||
{ };
|
||||
|
||||
PGF_INTERNAL_DECL ~PgfPGF()
|
||||
{ u->free_me(); };
|
||||
|
||||
PgfUnmarshaller *u;
|
||||
{ };
|
||||
};
|
||||
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
@@ -14,7 +14,6 @@ pgf_exn_clear(PgfExn* err)
|
||||
|
||||
PGF_API
|
||||
PgfPGF *pgf_read_pgf(const char* fpath,
|
||||
PgfUnmarshaller *unmarshaller,
|
||||
PgfExn* err)
|
||||
{
|
||||
PgfPGF *pgf = NULL;
|
||||
@@ -22,7 +21,7 @@ PgfPGF *pgf_read_pgf(const char* fpath,
|
||||
pgf_exn_clear(err);
|
||||
|
||||
try {
|
||||
pgf = new PgfPGF(NULL, 0, 0, unmarshaller);
|
||||
pgf = new PgfPGF(NULL, 0, 0);
|
||||
|
||||
std::ifstream in(fpath, std::ios::binary);
|
||||
if (in.fail()) {
|
||||
@@ -55,7 +54,6 @@ PgfPGF *pgf_read_pgf(const char* fpath,
|
||||
|
||||
PGF_API
|
||||
PgfPGF *pgf_boot_ngf(const char* pgf_path, const char* ngf_path,
|
||||
PgfUnmarshaller *unmarshaller,
|
||||
PgfExn* err)
|
||||
{
|
||||
PgfPGF *pgf = NULL;
|
||||
@@ -63,7 +61,7 @@ PgfPGF *pgf_boot_ngf(const char* pgf_path, const char* ngf_path,
|
||||
pgf_exn_clear(err);
|
||||
|
||||
try {
|
||||
pgf = new PgfPGF(ngf_path, O_CREAT | O_EXCL | O_RDWR, S_IRUSR | S_IWUSR, unmarshaller);
|
||||
pgf = new PgfPGF(ngf_path, O_CREAT | O_EXCL | O_RDWR, S_IRUSR | S_IWUSR);
|
||||
|
||||
std::ifstream in(pgf_path, std::ios::binary);
|
||||
if (in.fail()) {
|
||||
@@ -100,7 +98,6 @@ PgfPGF *pgf_boot_ngf(const char* pgf_path, const char* ngf_path,
|
||||
|
||||
PGF_API
|
||||
PgfPGF *pgf_read_ngf(const char *fpath,
|
||||
PgfUnmarshaller *unmarshaller,
|
||||
PgfExn* err)
|
||||
{
|
||||
PgfPGF *pgf = NULL;
|
||||
@@ -109,7 +106,7 @@ PgfPGF *pgf_read_ngf(const char *fpath,
|
||||
|
||||
bool is_new = false;
|
||||
try {
|
||||
pgf = new PgfPGF(fpath, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, unmarshaller);
|
||||
pgf = new PgfPGF(fpath, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
|
||||
|
||||
{
|
||||
DB_scope scope(pgf, WRITER_SCOPE);
|
||||
@@ -170,7 +167,7 @@ void pgf_iter_categories(PgfPGF *pgf, PgfItor *itor)
|
||||
}
|
||||
|
||||
PGF_API
|
||||
uintptr_t pgf_start_cat(PgfPGF *pgf)
|
||||
uintptr_t pgf_start_cat(PgfPGF *pgf, PgfUnmarshaller *u)
|
||||
{
|
||||
DB_scope scope(pgf, READER_SCOPE);
|
||||
|
||||
@@ -187,7 +184,7 @@ uintptr_t pgf_start_cat(PgfPGF *pgf)
|
||||
case PgfLiteralStr::tag: {
|
||||
auto lstr = ref<PgfLiteralStr>::untagged(flag->value);
|
||||
|
||||
uintptr_t type = pgf_read_type(&lstr->val, pgf->u);
|
||||
uintptr_t type = pgf_read_type(&lstr->val, u);
|
||||
if (type == 0)
|
||||
break;
|
||||
return type;
|
||||
@@ -200,11 +197,11 @@ uintptr_t pgf_start_cat(PgfPGF *pgf)
|
||||
s->size = 1;
|
||||
s->text[0] = 'S';
|
||||
s->text[1] = 0;
|
||||
return pgf->u->dtyp(0,NULL,s,0,NULL);
|
||||
return u->dtyp(0,NULL,s,0,NULL);
|
||||
}
|
||||
|
||||
PGF_API
|
||||
PgfTypeHypo *pgf_category_context(PgfPGF *pgf, PgfText *catname, size_t *n_hypos)
|
||||
PgfTypeHypo *pgf_category_context(PgfPGF *pgf, PgfText *catname, size_t *n_hypos, PgfUnmarshaller *u)
|
||||
{
|
||||
DB_scope scope(pgf, READER_SCOPE);
|
||||
|
||||
@@ -220,7 +217,7 @@ PgfTypeHypo *pgf_category_context(PgfPGF *pgf, PgfText *catname, size_t *n_hypos
|
||||
for (size_t i = 0; i < abscat->context->len; i++) {
|
||||
hypos[i].bind_type = abscat->context->data[i].bind_type;
|
||||
hypos[i].cid = textdup(abscat->context->data[i].cid);
|
||||
hypos[i].type = pgf_unmarshall_type(pgf->u, abscat->context->data[i].type);
|
||||
hypos[i].type = pgf_unmarshall_type(u, abscat->context->data[i].type);
|
||||
}
|
||||
|
||||
*n_hypos = abscat->context->len;
|
||||
@@ -277,7 +274,7 @@ void pgf_iter_functions_by_cat(PgfPGF *pgf, PgfText *cat, PgfItor *itor)
|
||||
}
|
||||
|
||||
PGF_API
|
||||
uintptr_t pgf_function_type(PgfPGF *pgf, PgfText *funname)
|
||||
uintptr_t pgf_function_type(PgfPGF *pgf, PgfText *funname, PgfUnmarshaller *u)
|
||||
{
|
||||
DB_scope scope(pgf, READER_SCOPE);
|
||||
|
||||
@@ -286,7 +283,7 @@ uintptr_t pgf_function_type(PgfPGF *pgf, PgfText *funname)
|
||||
if (absfun == 0)
|
||||
return 0;
|
||||
|
||||
return pgf_unmarshall_type(pgf->u, absfun->type);
|
||||
return pgf_unmarshall_type(u, absfun->type);
|
||||
}
|
||||
|
||||
PGF_API
|
||||
|
||||
@@ -93,15 +93,12 @@ struct PgfUnmarshaller {
|
||||
PgfText *cat,
|
||||
int n_exprs, uintptr_t *exprs)=0;
|
||||
virtual void free_ref(uintptr_t x)=0;
|
||||
virtual void free_me()=0;
|
||||
};
|
||||
|
||||
struct PgfMarshaller {
|
||||
virtual uintptr_t match_lit(PgfUnmarshaller *u, uintptr_t lit)=0;
|
||||
virtual uintptr_t match_expr(PgfUnmarshaller *u, uintptr_t expr)=0;
|
||||
virtual uintptr_t match_type(PgfUnmarshaller *u, uintptr_t ty)=0;
|
||||
virtual void free_ref(uintptr_t x)=0;
|
||||
virtual void free_me()=0;
|
||||
};
|
||||
#else
|
||||
typedef struct PgfUnmarshaller PgfUnmarshaller;
|
||||
@@ -123,7 +120,6 @@ struct PgfUnmarshallerVtbl {
|
||||
PgfText *cat,
|
||||
int n_exprs, uintptr_t *exprs);
|
||||
void (*free_ref)(PgfUnmarshaller *this, uintptr_t x);
|
||||
void (*free_me)(PgfUnmarshaller *this);
|
||||
};
|
||||
struct PgfUnmarshaller {
|
||||
PgfUnmarshallerVtbl *vtbl;
|
||||
@@ -135,7 +131,6 @@ struct PgfMarshallerVtbl {
|
||||
uintptr_t (*match_lit)(PgfUnmarshaller *u, uintptr_t lit);
|
||||
uintptr_t (*match_expr)(PgfUnmarshaller *u, uintptr_t expr);
|
||||
uintptr_t (*match_type)(PgfUnmarshaller *u, uintptr_t ty);
|
||||
void (*free_me)(PgfUnmarshaller *this);
|
||||
};
|
||||
struct PgfMarshaller {
|
||||
PgfMarshallerVtbl *vtbl;
|
||||
@@ -177,7 +172,6 @@ typedef struct {
|
||||
/* Reads a PGF file and keeps it in memory. */
|
||||
PGF_API_DECL
|
||||
PgfPGF *pgf_read_pgf(const char* fpath,
|
||||
PgfUnmarshaller *unmarshaller,
|
||||
PgfExn* err);
|
||||
|
||||
/* Reads a PGF file and stores the unpacked data in an NGF file
|
||||
@@ -186,7 +180,6 @@ PgfPGF *pgf_read_pgf(const char* fpath,
|
||||
* between machines. */
|
||||
PGF_API_DECL
|
||||
PgfPGF *pgf_boot_ngf(const char* pgf_path, const char* ngf_path,
|
||||
PgfUnmarshaller *unmarshaller,
|
||||
PgfExn* err);
|
||||
|
||||
/* Tries to read the grammar from an already booted NGF file.
|
||||
@@ -195,7 +188,6 @@ PgfPGF *pgf_boot_ngf(const char* pgf_path, const char* ngf_path,
|
||||
* rules dynamically. */
|
||||
PGF_API_DECL
|
||||
PgfPGF *pgf_read_ngf(const char* fpath,
|
||||
PgfUnmarshaller *unmarshaller,
|
||||
PgfExn* err);
|
||||
|
||||
/* Release the grammar when it is no longer needed. */
|
||||
@@ -209,13 +201,13 @@ PGF_API_DECL
|
||||
void pgf_iter_categories(PgfPGF *pgf, PgfItor *itor);
|
||||
|
||||
PGF_API_DECL
|
||||
uintptr_t pgf_start_cat(PgfPGF *pgf);
|
||||
uintptr_t pgf_start_cat(PgfPGF *pgf, PgfUnmarshaller *u);
|
||||
|
||||
PGF_API_DECL PgfTypeHypo*
|
||||
pgf_category_context(PgfPGF *pgf, PgfText *catname, size_t *n_hypos);
|
||||
PGF_API_DECL
|
||||
PgfTypeHypo *pgf_category_context(PgfPGF *pgf, PgfText *catname, size_t *n_hypos, PgfUnmarshaller *u);
|
||||
|
||||
PGF_API_DECL prob_t
|
||||
pgf_category_prob(PgfPGF* pgf, PgfText *catname);
|
||||
PGF_API_DECL
|
||||
prob_t pgf_category_prob(PgfPGF* pgf, PgfText *catname);
|
||||
|
||||
PGF_API_DECL
|
||||
void pgf_iter_functions(PgfPGF *pgf, PgfItor *itor);
|
||||
@@ -224,7 +216,7 @@ PGF_API_DECL
|
||||
void pgf_iter_functions_by_cat(PgfPGF *pgf, PgfText *cat, PgfItor *itor);
|
||||
|
||||
PGF_API_DECL
|
||||
uintptr_t pgf_function_type(PgfPGF *pgf, PgfText *funname);
|
||||
uintptr_t pgf_function_type(PgfPGF *pgf, PgfText *funname, PgfUnmarshaller *u);
|
||||
|
||||
PGF_API_DECL
|
||||
int pgf_function_is_constructor(PgfPGF *pgf, PgfText *funname);
|
||||
|
||||
@@ -356,7 +356,3 @@ uintptr_t PgfPrinter::dtyp(int n_hypos, PgfTypeHypo *hypos,
|
||||
void PgfPrinter::free_ref(uintptr_t x)
|
||||
{
|
||||
}
|
||||
|
||||
void PgfPrinter::free_me()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -60,7 +60,6 @@ public:
|
||||
PgfText *cat,
|
||||
int n_exprs, uintptr_t *exprs);
|
||||
virtual void free_ref(uintptr_t x);
|
||||
virtual void free_me();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user