diff --git a/src/runtime/c/pgf/expr.cxx b/src/runtime/c/pgf/expr.cxx index 375661ba6..e000cf2c8 100644 --- a/src/runtime/c/pgf/expr.cxx +++ b/src/runtime/c/pgf/expr.cxx @@ -1149,23 +1149,30 @@ exit: PgfExpr PgfExprProbEstimator::eabs(PgfBindType bind_type, PgfText *name, PgfExpr body) { m->match_expr(this, body); + cat_prob = 0; return 0; } PgfExpr PgfExprProbEstimator::eapp(PgfExpr fun, PgfExpr arg) { - m->match_expr(this, fun); + prob_t tmp = cat_prob_total; + cat_prob_total = 0; m->match_expr(this, arg); + cat_prob_total = tmp + cat_prob; + m->match_expr(this, fun); return 0; } PgfExpr PgfExprProbEstimator::elit(PgfLiteral lit) { + cat_prob = 0; return 0; } PgfExpr PgfExprProbEstimator::emeta(PgfMetaId meta_id) { + prob += cat_prob_total; + cat_prob = 0; return 0; } @@ -1173,16 +1180,25 @@ PgfExpr PgfExprProbEstimator::efun(PgfText *name) { ref absfun = namespace_lookup(pgf->abstract.funs, name); - if (absfun == 0) + if (absfun == 0) { prob = INFINITY; - else + cat_prob = INFINITY; + } else { prob += absfun->prob; + ref abscat = + namespace_lookup(pgf->abstract.cats, &absfun->type->name); + if (abscat == 0) + cat_prob = INFINITY; + else + cat_prob = abscat->prob; + } return 0; } PgfExpr PgfExprProbEstimator::evar(int index) { + cat_prob = 0; return 0; } diff --git a/src/runtime/c/pgf/expr.h b/src/runtime/c/pgf/expr.h index 33320b37d..4496f2856 100644 --- a/src/runtime/c/pgf/expr.h +++ b/src/runtime/c/pgf/expr.h @@ -198,12 +198,16 @@ class PGF_INTERNAL_DECL PgfExprProbEstimator : public PgfUnmarshaller { PgfPGF *pgf; PgfMarshaller *m; prob_t prob; + prob_t cat_prob; + prob_t cat_prob_total; public: PgfExprProbEstimator(PgfPGF *pgf, PgfMarshaller *marshaller) { this->pgf = pgf; this->m = marshaller; - this->prob = 0; + this->prob = 0; + this->cat_prob = 0; + this->cat_prob_total = 0; } virtual PgfExpr eabs(PgfBindType bind_type, PgfText *name, PgfExpr body);