From 2a5434df96e8158bb95cd97f949505c7e640444b Mon Sep 17 00:00:00 2001 From: krangelov Date: Tue, 12 Oct 2021 19:07:21 +0200 Subject: [PATCH] avoid using the wildcard constant --- src/runtime/c/pgf/expr.cxx | 32 ++++++++++++++++++++------------ src/runtime/c/pgf/expr.h | 2 -- src/runtime/c/pgf/printer.cxx | 2 +- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/runtime/c/pgf/expr.cxx b/src/runtime/c/pgf/expr.cxx index 542130594..dafe8db6b 100644 --- a/src/runtime/c/pgf/expr.cxx +++ b/src/runtime/c/pgf/expr.cxx @@ -460,7 +460,10 @@ void PgfExprParser::token() if (!getc()) break; } while (pgf_is_ident_rest(ch)); - token_tag = PGF_TOKEN_IDENT; + if (token_value->size == 1 && strcmp(token_value->text,"_")==0) + token_tag = PGF_TOKEN_WILD; + else + token_tag = PGF_TOKEN_IDENT; } else if (isdigit(ch)) { digit: do { @@ -628,9 +631,6 @@ PgfExpr PgfExprParser::parse_arg() return arg; } -// PGF_INTERNAL PgfText wildcard = {size: 1, text: {'_',0}}; -PGF_INTERNAL PgfText wildcard = {size: 1, text: {}}; // TODO - PgfBind *PgfExprParser::parse_bind(PgfBind *next) { PgfBind *last = next; @@ -643,10 +643,8 @@ PgfBind *PgfExprParser::parse_bind(PgfBind *next) for (;;) { PgfText *var; - if (token_tag == PGF_TOKEN_IDENT) { + if (token_tag == PGF_TOKEN_IDENT || token_tag == PGF_TOKEN_WILD) { var = token_value; - } else if (token_tag == PGF_TOKEN_WILD) { - var = &wildcard; } else { goto error; } @@ -785,10 +783,8 @@ bool PgfExprParser::parse_hypos(size_t *n_hypos, PgfTypeHypo **hypos) } PgfText *var; - if (token_tag == PGF_TOKEN_IDENT) { + if (token_tag == PGF_TOKEN_IDENT || token_tag == PGF_TOKEN_WILD) { var = token_value; - } else if (token_tag == PGF_TOKEN_WILD) { - var = &wildcard; } else { return false; } @@ -821,6 +817,18 @@ bool PgfExprParser::parse_hypos(size_t *n_hypos, PgfTypeHypo **hypos) return true; } +static +PgfText *mk_wildcard() +{ + PgfText *t = (PgfText *) malloc(sizeof(PgfText)+2); + if (t != NULL) { + t->size = 1; + t->text[0] = '_'; + t->text[1] = 0; + } + return t; +} + PgfType PgfExprParser::parse_type() { PgfType type = 0; @@ -856,7 +864,7 @@ PgfType PgfExprParser::parse_type() hypos = (PgfTypeHypo*) realloc(hypos, sizeof(PgfTypeHypo)*(n_hypos+1)); PgfTypeHypo *bt = &hypos[n_hypos]; bt->bind_type = PGF_BIND_TYPE_EXPLICIT; - bt->cid = textdup(&wildcard); + bt->cid = mk_wildcard(); bt->type = 0; n_hypos++; } @@ -903,7 +911,7 @@ PgfType PgfExprParser::parse_type() hypos = (PgfTypeHypo*) realloc(hypos, sizeof(PgfTypeHypo)*(n_hypos+1)); PgfTypeHypo *bt = &hypos[n_hypos]; bt->bind_type = PGF_BIND_TYPE_EXPLICIT; - bt->cid = textdup(&wildcard); + bt->cid = mk_wildcard(); bt->type = u->dtyp(0,NULL,cat,n_args,args); n_hypos++; diff --git a/src/runtime/c/pgf/expr.h b/src/runtime/c/pgf/expr.h index fef16c85b..bb1c62b3c 100644 --- a/src/runtime/c/pgf/expr.h +++ b/src/runtime/c/pgf/expr.h @@ -267,8 +267,6 @@ public: prob_t get_prob() { return prob; }; }; -PGF_INTERNAL_DECL extern PgfText wildcard; - /* The following functions release the memory in the database, * allocated for values of the corresponding types. */ diff --git a/src/runtime/c/pgf/printer.cxx b/src/runtime/c/pgf/printer.cxx index fefee4717..2643724db 100644 --- a/src/runtime/c/pgf/printer.cxx +++ b/src/runtime/c/pgf/printer.cxx @@ -382,7 +382,7 @@ PgfLiteral PgfPrinter::lstr(PgfText *v) void PgfPrinter::hypo(PgfTypeHypo *hypo, int prio) { - if (textcmp(hypo->cid, &wildcard) == 0) { + if (hypo->cid->size == 1 && strcmp(hypo->cid->text, "_") == 0) { this->prio = prio; m->match_type(this, hypo->type); } else {