diff --git a/src/runtime/c/pgf/data.cxx b/src/runtime/c/pgf/data.cxx index d188f3133..982db8de2 100644 --- a/src/runtime/c/pgf/data.cxx +++ b/src/runtime/c/pgf/data.cxx @@ -47,22 +47,22 @@ void PgfConcr::release(ref concr) void PgfConcrLincat::release(ref lincat) { - for (size_t i = 0; i < lincat->fields->len; i++) { - text_db_release(*vector_elem(lincat->fields, i)); + for (ref field : lincat->fields) { + text_db_release(field); } - Vector>::release(lincat->fields); + vector>::release(lincat->fields); - for (size_t i = 0; i < lincat->args->len; i++) { - PgfLParam::release(vector_elem(lincat->args, i)->param); + for (size_t i = 0; i < lincat->args.size(); i++) { + PgfLParam::release(lincat->args[i].param); } - Vector::release(lincat->args); + vector::release(lincat->args); - for (size_t i = 0; i < lincat->res->len; i++) { - PgfPResult::release(*vector_elem(lincat->res, i)); + for (ref res : lincat->res) { + PgfPResult::release(res); } - Vector>::release(lincat->res); + vector>::release(lincat->res); - Vector>::release(lincat->seqs); + vector>::release(lincat->seqs); PgfDB::free(lincat, lincat->name.size+1); } @@ -75,15 +75,13 @@ void PgfLParam::release(ref param) void PgfPResult::release(ref res) { if (res->vars != 0) - Vector::release(res->vars); + vector::release(res->vars); PgfDB::free(res, res->param.n_terms*sizeof(res->param.terms[0])); } void PgfSequence::release(ref seq) { - for (size_t i = 0; i < seq->syms.len; i++) { - PgfSymbol sym = *vector_elem(&seq->syms, i); - + for (PgfSymbol sym : seq->syms) { switch (ref::get_tag(sym)) { case PgfSymbolCat::tag: { auto sym_cat = ref::untagged(sym); @@ -106,13 +104,13 @@ void PgfSequence::release(ref seq) case PgfSymbolKP::tag: { auto sym_kp = ref::untagged(sym); PgfSequence::release(sym_kp->default_form); - for (size_t i = 0; i < sym_kp->alts.len; i++) { - PgfSequence::release(sym_kp->alts.data[i].form); - for (size_t j = 0; j < sym_kp->alts.data[i].prefixes->len; j++) { - text_db_release(*vector_elem(sym_kp->alts.data[i].prefixes, j)); + for (size_t i = 0; i < sym_kp->alts.size(); i++) { + PgfSequence::release(sym_kp->alts[i].form); + for (size_t j = 0; j < sym_kp->alts[i].prefixes.size(); j++) { + text_db_release(sym_kp->alts[i].prefixes[j]); } } - PgfDB::free(sym_kp, sym_kp->alts.len*sizeof(PgfAlternative)); + inline_vector::release(&PgfSymbolKP::alts, sym_kp); break; } case PgfSymbolBIND::tag: @@ -126,22 +124,22 @@ void PgfSequence::release(ref seq) throw pgf_error("Unknown symbol tag"); } } - PgfDB::free(seq,seq->syms.len*sizeof(PgfSymbol)); + inline_vector::release(&PgfSequence::syms, seq); } void PgfConcrLin::release(ref lin) { - for (size_t i = 0; i < lin->args->len; i++) { - PgfLParam::release(vector_elem(lin->args, i)->param); + for (size_t i = 0; i < lin->args.size(); i++) { + PgfLParam::release(lin->args[i].param); } - Vector::release(lin->args); + vector::release(lin->args); - for (size_t i = 0; i < lin->res->len; i++) { - PgfPResult::release(*vector_elem(lin->res, i)); + for (ref res : lin->res) { + PgfPResult::release(res); } - Vector>::release(lin->res); + vector>::release(lin->res); - Vector>::release(lin->seqs); + vector>::release(lin->seqs); PgfDB::free(lin, lin->name.size+1); } diff --git a/src/runtime/c/pgf/data.h b/src/runtime/c/pgf/data.h index ac1249c36..7945e9417 100644 --- a/src/runtime/c/pgf/data.h +++ b/src/runtime/c/pgf/data.h @@ -109,7 +109,7 @@ struct PGF_INTERNAL_DECL PgfAbsFun { }; struct PGF_INTERNAL_DECL PgfAbsCat { - ref> context; + vector context; prob_t prob; PgfText name; @@ -145,7 +145,7 @@ struct PGF_INTERNAL_DECL PgfPArg { }; struct PGF_INTERNAL_DECL PgfPResult { - ref> vars; + vector vars; PgfLParam param; static void release(ref res); @@ -154,7 +154,7 @@ struct PGF_INTERNAL_DECL PgfPResult { typedef object PgfSymbol; struct PGF_INTERNAL_DECL PgfSequence { - Vector syms; + inline_vector syms; static void release(ref seq); }; @@ -190,7 +190,7 @@ struct PGF_INTERNAL_DECL PgfAlternative { ref form; /**< The form of this variant as a list of tokens. */ - ref>> prefixes; + vector> prefixes; /**< The prefixes of the following symbol that trigger this * form. */ }; @@ -198,7 +198,7 @@ struct PGF_INTERNAL_DECL PgfAlternative { struct PGF_INTERNAL_DECL PgfSymbolKP { static const uint8_t tag = 4; ref default_form; - Vector alts; + inline_vector alts; }; struct PGF_INTERNAL_DECL PgfSymbolBIND { @@ -231,10 +231,10 @@ struct PGF_INTERNAL_DECL PgfConcrLincat { ref abscat; size_t n_lindefs; - ref> args; - ref>> res; - ref>> seqs; - ref>> fields; + vector args; + vector> res; + vector> seqs; + vector> fields; PgfText name; @@ -247,9 +247,9 @@ struct PGF_INTERNAL_DECL PgfConcrLin { ref absfun; ref lincat; - ref> args; - ref>> res; - ref>> seqs; + vector args; + vector> res; + vector> seqs; PgfText name; @@ -280,7 +280,7 @@ struct PgfLRReduceArg; struct PGF_INTERNAL_DECL PgfLRProduction { ref lin; size_t index; - ref>> args; + vector> args; }; struct PGF_INTERNAL_DECL PgfLRReduceArg { @@ -301,18 +301,16 @@ struct PGF_INTERNAL_DECL PgfLRReduce { size_t stk_idx; }; - ref> args; + vector args; }; struct PGF_INTERNAL_DECL PgfLRState { - ref> shifts; - ref> tokens; + vector shifts; + vector tokens; size_t next_bind_state; - ref> reductions; + vector reductions; }; -typedef Vector PgfLRTable; - struct PGF_INTERNAL_DECL PgfConcr { static const uint8_t tag = 1; @@ -322,7 +320,7 @@ struct PGF_INTERNAL_DECL PgfConcr { PgfPhrasetable phrasetable; Namespace printnames; - ref lrtable; + vector lrtable; PgfText name; diff --git a/src/runtime/c/pgf/expr.cxx b/src/runtime/c/pgf/expr.cxx index b52013dce..0e8496ae0 100644 --- a/src/runtime/c/pgf/expr.cxx +++ b/src/runtime/c/pgf/expr.cxx @@ -81,28 +81,28 @@ PgfType PgfDBMarshaller::match_type(PgfUnmarshaller *u, PgfType ty) ref tp = ty; PgfTypeHypo *hypos = (PgfTypeHypo *) - alloca(tp->hypos->len * sizeof(PgfTypeHypo)); - for (size_t i = 0; i < tp->hypos->len; i++) { - hypos[i].bind_type = tp->hypos->data[i].bind_type; - hypos[i].cid = &(*tp->hypos->data[i].cid); - hypos[i].type = match_type(u, tp->hypos->data[i].type.as_object()); + alloca(tp->hypos.size() * sizeof(PgfTypeHypo)); + for (size_t i = 0; i < tp->hypos.size(); i++) { + hypos[i].bind_type = tp->hypos[i].bind_type; + hypos[i].cid = &(*tp->hypos[i].cid); + hypos[i].type = match_type(u, tp->hypos[i].type.as_object()); } PgfExpr *exprs = (PgfExpr *) - alloca(tp->exprs->len * sizeof(PgfExpr)); - for (size_t i = 0; i < tp->exprs->len; i++) { - exprs[i] = match_expr(u, tp->exprs->data[i]); + alloca(tp->exprs.size() * sizeof(PgfExpr)); + for (size_t i = 0; i < tp->exprs.size(); i++) { + exprs[i] = match_expr(u, tp->exprs[i]); } - PgfType res = u->dtyp(tp->hypos->len, hypos, + PgfType res = u->dtyp(tp->hypos.size(), hypos, &tp->name, - tp->exprs->len, exprs); + tp->exprs.size(), exprs); - for (size_t i = 0; i < tp->hypos->len; i++) { + for (size_t i = 0; i < tp->hypos.size(); i++) { u->free_ref(hypos[i].type); } - for (size_t i = 0; i < tp->exprs->len; i++) { + for (size_t i = 0; i < tp->exprs.size(); i++) { u->free_ref(exprs[i]); } @@ -202,16 +202,18 @@ PgfType PgfDBUnmarshaller::dtyp(size_t n_hypos, PgfTypeHypo *hypos, ref ty = PgfDB::malloc(cat->size+1); memcpy(&ty->name, cat, sizeof(PgfText)+cat->size+1); - ty->hypos = vector_new(n_hypos); + ty->hypos = vector::alloc(n_hypos); for (size_t i = 0; i < n_hypos; i++) { - ref hypo = vector_elem(ty->hypos,i); + ref hypo = ty->hypos.elem(i); hypo->bind_type = hypos[i].bind_type; hypo->cid = textdup_db(hypos[i].cid); - hypo->type = m->match_type(this, hypos[i].type); + PgfType type = m->match_type(this, hypos[i].type); + hypo->type = type; } - ty->exprs = vector_new(n_exprs); + ty->exprs = vector::alloc(n_exprs); for (size_t i = 0; i < n_exprs; i++) { - *vector_elem(ty->exprs,i) = m->match_expr(this, exprs[i]); + PgfExpr expr = m->match_expr(this, exprs[i]); + ty->exprs[i] = expr; } return ty.as_object(); @@ -282,16 +284,16 @@ PgfType PgfInternalMarshaller::match_type(PgfUnmarshaller *u, PgfType ty) ref tp = ty; PgfTypeHypo *hypos = (PgfTypeHypo *) - alloca(tp->hypos->len * sizeof(PgfTypeHypo)); - for (size_t i = 0; i < tp->hypos->len; i++) { - hypos[i].bind_type = tp->hypos->data[i].bind_type; - hypos[i].cid = &(*tp->hypos->data[i].cid); - hypos[i].type = tp->hypos->data[i].type.as_object(); + alloca(tp->hypos.size() * sizeof(PgfTypeHypo)); + for (size_t i = 0; i < tp->hypos.size(); i++) { + hypos[i].bind_type = tp->hypos[i].bind_type; + hypos[i].cid = &(*tp->hypos[i].cid); + hypos[i].type = tp->hypos[i].type.as_object(); } - return u->dtyp(tp->hypos->len, hypos, + return u->dtyp(tp->hypos.size(), hypos, &tp->name, - tp->exprs->len, tp->exprs->data); + tp->exprs.size(), tp->exprs.get_data()); } PgfExprParser::PgfExprParser(PgfText *input, PgfUnmarshaller *unmarshaller) @@ -1329,14 +1331,14 @@ void pgf_expr_release(PgfExpr expr) } PGF_INTERNAL -void pgf_context_release(ref> hypos) +void pgf_context_release(vector hypos) { - for (size_t i = 0; i < hypos->len; i++) { - text_db_release(vector_elem(hypos, i)->cid); - pgf_type_release(vector_elem(hypos, i)->type); + for (size_t i = 0; i < hypos.size(); i++) { + text_db_release(hypos[i].cid); + pgf_type_release(hypos[i].type); } - Vector::release(hypos); + vector::release(hypos); } PGF_INTERNAL @@ -1344,10 +1346,10 @@ void pgf_type_release(ref dtyp) { pgf_context_release(dtyp->hypos); - for (size_t i = 0; i < dtyp->exprs->len; i++) { - pgf_expr_release(*vector_elem(dtyp->exprs, i)); + for (PgfExpr expr : dtyp->exprs) { + pgf_expr_release(expr); } - Vector::release(dtyp->exprs); + vector::release(dtyp->exprs); PgfDB::free(dtyp, dtyp->name.size+1); } diff --git a/src/runtime/c/pgf/expr.h b/src/runtime/c/pgf/expr.h index 4496f2856..a5d7ae429 100644 --- a/src/runtime/c/pgf/expr.h +++ b/src/runtime/c/pgf/expr.h @@ -30,8 +30,8 @@ struct PGF_INTERNAL_DECL PgfHypo { }; struct PGF_INTERNAL_DECL PgfDTyp { - ref> hypos; - ref> exprs; + vector hypos; + vector exprs; PgfText name; }; @@ -240,7 +240,7 @@ PGF_INTERNAL_DECL void pgf_expr_release(PgfExpr expr); PGF_INTERNAL_DECL -void pgf_context_release(ref> hypos); +void pgf_context_release(vector hypos); PGF_INTERNAL_DECL void pgf_type_release(ref dtyp); diff --git a/src/runtime/c/pgf/generator.cxx b/src/runtime/c/pgf/generator.cxx index 1de081035..1ae745e07 100644 --- a/src/runtime/c/pgf/generator.cxx +++ b/src/runtime/c/pgf/generator.cxx @@ -239,21 +239,21 @@ again: { if (total_prob < 0) // possible because of rounding total_prob = 0; } else { - ref> hypos = fun->type->hypos; - if (depth > ((hypos->len > 0) ? 1 : 0)) { + vector hypos = fun->type->hypos; + if (depth > ((hypos.size() > 0) ? 1 : 0)) { prob += fun->prob; expr = u->efun(&fun->name); PgfTypeHypo *t_hypos = (PgfTypeHypo *) - alloca(hypos->len * sizeof(PgfTypeHypo)); - for (size_t i = 0; i < hypos->len; i++) { - t_hypos[i].bind_type = hypos->data[i].bind_type; - t_hypos[i].cid = &(*hypos->data[i].cid); - t_hypos[i].type = hypos->data[i].type.as_object(); + alloca(hypos.size() * sizeof(PgfTypeHypo)); + for (size_t i = 0; i < hypos.size(); i++) { + t_hypos[i].bind_type = hypos[i].bind_type; + t_hypos[i].cid = &(*hypos[i].cid); + t_hypos[i].type = hypos[i].type.as_object(); } auto tmp = this->m; this->m = &i_m; - expr = descend(expr, hypos->len, t_hypos); + expr = descend(expr, hypos.size(), t_hypos); this->m = tmp; } @@ -450,16 +450,16 @@ bool PgfExhaustiveGenerator::State0::process(PgfExhaustiveGenerator *gen) bool PgfExhaustiveGenerator::State1::process(PgfExhaustiveGenerator *gen) { - if (n_args >= type->hypos->len) { + if (n_args >= type->hypos.size()) { complete(gen); return true; } Scope *scope = res->scope; size_t scope_len = res->scope_len; - ref arg_type = vector_elem(type->hypos, n_args)->type; - for (size_t i = 0; i < arg_type->hypos->len; i++) { - ref hypo = vector_elem(arg_type->hypos, i); + ref arg_type = type->hypos[n_args].type; + for (size_t i = 0; i < arg_type->hypos.size(); i++) { + ref hypo = arg_type->hypos.elem(i); size_t buf_size = 16; Scope *new_scope = (Scope *) malloc(sizeof(Scope)+buf_size); @@ -548,7 +548,7 @@ void PgfExhaustiveGenerator::State1::combine(PgfExhaustiveGenerator *gen, s = s->next; } - PgfBindType bind_type = vector_elem(type->hypos, n_args)->bind_type; + PgfBindType bind_type = type->hypos[n_args].bind_type; if (bind_type == PGF_BIND_TYPE_IMPLICIT) { PgfExpr implarg = gen->u->eimplarg(expr); diff --git a/src/runtime/c/pgf/linearizer.cxx b/src/runtime/c/pgf/linearizer.cxx index 3df419763..8591bc718 100644 --- a/src/runtime/c/pgf/linearizer.cxx +++ b/src/runtime/c/pgf/linearizer.cxx @@ -54,8 +54,8 @@ void PgfLinearizer::TreeNode::linearize_var(PgfLinearizationOutputIface *out, Pg void PgfLinearizer::TreeNode::linearize_seq(PgfLinearizationOutputIface *out, PgfLinearizer *linearizer, ref seq) { - for (size_t i = 0; i < seq->syms.len; i++) { - PgfSymbol sym = *vector_elem(&seq->syms, i); + for (size_t i = 0; i < seq->syms.size(); i++) { + PgfSymbol sym = seq->syms[i]; switch (ref::get_tag(sym)) { case PgfSymbolCat::tag: { @@ -194,13 +194,13 @@ PgfLinearizer::TreeLinNode::TreeLinNode(PgfLinearizer *linearizer, ref> hypos = lin->absfun->type->hypos; - size_t n_args = lin->args->len / lin->res->len; + vector hypos = lin->absfun->type->hypos; + size_t n_args = lin->args.size() / lin->res.size(); - while (lin_index < lin->res->len) { + while (lin_index < lin->res.size()) { size_t offset = lin_index*n_args; - ref pres = *vector_elem(lin->res, lin_index); + ref pres = lin->res[lin_index]; // Unbind all variables for (size_t j = 0; j < var_count; j++) { @@ -210,8 +210,8 @@ bool PgfLinearizer::TreeLinNode::resolve(PgfLinearizer *linearizer) int i = 0; TreeNode *arg = args; while (arg != NULL) { - ref parg = vector_elem(lin->args, offset+i); - arg->check_category(linearizer, &vector_elem(hypos,i)->type->name); + ref parg = lin->args.elem(offset+i); + arg->check_category(linearizer, &hypos[i].type->name); if (arg->value < parg->param->i0) break; @@ -231,8 +231,8 @@ bool PgfLinearizer::TreeLinNode::resolve(PgfLinearizer *linearizer) // find the range for the variable size_t range = 0; - for (size_t k = 0; k < pres->vars->len; k++) { - ref var_range = vector_elem(pres->vars, k); + for (size_t k = 0; k < pres->vars.size(); k++) { + ref var_range = pres->vars.elem(k); if (var_range->var == var) { range = var_range->range; break; @@ -287,7 +287,7 @@ void PgfLinearizer::TreeLinNode::check_category(PgfLinearizer *linearizer, PgfTe void PgfLinearizer::TreeLinNode::linearize(PgfLinearizationOutputIface *out, PgfLinearizer *linearizer, size_t lindex) { PgfText *cat = &lin->absfun->type->name; - PgfText *field = &**vector_elem(lin->lincat->fields, lindex); + PgfText *field = &*lin->lincat->fields[lindex]; if (linearizer->pre_stack == NULL) out->begin_phrase(cat, fid, field, &lin->name); @@ -302,8 +302,8 @@ void PgfLinearizer::TreeLinNode::linearize(PgfLinearizationOutputIface *out, Pgf linearizer->pre_stack->bracket_stack = bracket; } - size_t n_seqs = lin->seqs->len / lin->res->len; - ref seq = *vector_elem(lin->seqs, (lin_index-1)*n_seqs + lindex); + size_t n_seqs = lin->seqs.size() / lin->res.size(); + ref seq = lin->seqs[(lin_index-1)*n_seqs + lindex]; linearize_seq(out, linearizer, seq); if (linearizer->pre_stack == NULL) @@ -358,7 +358,7 @@ bool PgfLinearizer::TreeLindefNode::resolve(PgfLinearizer *linearizer) if (lincat == 0) { return (lin_index = !lin_index); } else { - ref pres = *vector_elem(lincat->res, lin_index); + ref pres = lincat->res[lin_index]; value = eval_param(&pres->param); lin_index++; if (lin_index <= lincat->n_lindefs) @@ -390,7 +390,7 @@ void PgfLinearizer::TreeLindefNode::linearize_arg(PgfLinearizationOutputIface *o void PgfLinearizer::TreeLindefNode::linearize(PgfLinearizationOutputIface *out, PgfLinearizer *linearizer, size_t lindex) { if (lincat != 0) { - PgfText *field = &**vector_elem(lincat->fields, lindex); + PgfText *field = &*lincat->fields[lindex]; if (linearizer->pre_stack == NULL) out->begin_phrase(&lincat->name, fid, field, fun); else { @@ -404,7 +404,7 @@ void PgfLinearizer::TreeLindefNode::linearize(PgfLinearizationOutputIface *out, linearizer->pre_stack->bracket_stack = bracket; } - ref seq = *vector_elem(lincat->seqs, (lin_index-1)*lincat->fields->len + lindex); + ref seq = lincat->seqs[(lin_index-1)*lincat->fields.size() + lindex]; linearize_seq(out, linearizer, seq); if (linearizer->pre_stack == NULL) @@ -443,14 +443,14 @@ bool PgfLinearizer::TreeLinrefNode::resolve(PgfLinearizer *linearizer) if (lincat == 0) return (lin_index = !lin_index); - while (lincat->n_lindefs+lin_index < lincat->res->len) { + while (lincat->n_lindefs+lin_index < lincat->res.size()) { // Unbind all variables for (size_t j = 0; j < var_count; j++) { var_values[j] = (size_t) -1; } - ref pres = *vector_elem(lincat->res, lincat->n_lindefs+lin_index); - ref parg = vector_elem(lincat->args, lincat->n_lindefs+lin_index); + ref pres = lincat->res[lincat->n_lindefs+lin_index]; + ref parg = lincat->args.elem(lincat->n_lindefs+lin_index); if (root->value < parg->param->i0) break; @@ -470,8 +470,8 @@ bool PgfLinearizer::TreeLinrefNode::resolve(PgfLinearizer *linearizer) // find the range for the variable size_t range = 0; - for (size_t k = 0; k < pres->vars->len; k++) { - ref var_range = vector_elem(pres->vars, k); + for (size_t k = 0; k < pres->vars.size(); k++) { + ref var_range = pres->vars.elem(k); if (var_range->var == var) { range = var_range->range; break; @@ -513,8 +513,8 @@ void PgfLinearizer::TreeLinrefNode::linearize(PgfLinearizationOutputIface *out, { ref lincat = args->get_lincat(linearizer); if (lincat != 0) { - size_t i = lincat->n_lindefs*lincat->fields->len + (lin_index-1); - ref seq = *vector_elem(lincat->seqs, i); + size_t i = lincat->n_lindefs*lincat->fields.size() + (lin_index-1); + ref seq = lincat->seqs[i]; linearize_seq(out, linearizer, seq); } else { args->linearize(out, linearizer, lindex); @@ -540,10 +540,10 @@ void PgfLinearizer::TreeLitNode::check_category(PgfLinearizer *linearizer, PgfTe } void PgfLinearizer::TreeLitNode::linearize(PgfLinearizationOutputIface *out, PgfLinearizer *linearizer, size_t lindex) -{ +{ PgfText *field = NULL; if (lincat != 0) { - field = &**vector_elem(lincat->fields, lindex); + field = &*lincat->fields[lindex]; } linearizer->flush_pre_stack(out, literal); @@ -659,10 +659,9 @@ void PgfLinearizer::flush_pre_stack(PgfLinearizationOutputIface *out, PgfText *t pre_stack = pre->next; if (token != NULL) { - for (size_t i = 0; i < pre->sym_kp->alts.len; i++) { - PgfAlternative *alt = &pre->sym_kp->alts.data[i]; - for (size_t j = 0; j < alt->prefixes->len; j++) { - ref prefix = *vector_elem(alt->prefixes,j); + for (size_t i = 0; i < pre->sym_kp->alts.size(); i++) { + ref alt = pre->sym_kp->alts.elem(i); + for (ref prefix : alt->prefixes) { if (cmp(token, &(*prefix))) { pre->node->linearize_seq(out, this, alt->form); goto done; diff --git a/src/runtime/c/pgf/namespace.h b/src/runtime/c/pgf/namespace.h index 9cf9e8c25..3d40470f8 100644 --- a/src/runtime/c/pgf/namespace.h +++ b/src/runtime/c/pgf/namespace.h @@ -691,7 +691,7 @@ Namespace namespace_map(Namespace map, std::function(ref)> &f) } template -void namespace_vec_fill_names(Namespace node, size_t offs, Vector *vec) +void namespace_vec_fill_names(Namespace node, size_t offs, A *vec) { if (node == 0) return; @@ -699,20 +699,19 @@ void namespace_vec_fill_names(Namespace node, size_t offs, Vector *vec) namespace_vec_fill_names(node->left, offs, vec); offs += namespace_size(node->left); - vector_elem(vec, offs++)->name = &node->value->name; + vec[offs++].name = &node->value->name; namespace_vec_fill_names(node->right, offs, vec); } template -Vector *namespace_to_sorted_names(Namespace node) +A *namespace_to_sorted_names(Namespace node) { - Vector *vec = (Vector *) - malloc(sizeof(Vector)+node->sz*sizeof(A)); + A *vec = (A*) + malloc(node->sz*sizeof(A)); if (errno != 0) throw pgf_systemerror(errno); - vec->len = node->sz; - memset(vec->data, 0, node->sz*sizeof(A)); + memset(vec, 0, node->sz*sizeof(A)); namespace_vec_fill_names(node, 0, vec); return vec; } diff --git a/src/runtime/c/pgf/parser.cxx b/src/runtime/c/pgf/parser.cxx index 7b0377df5..e6a77cf0b 100644 --- a/src/runtime/c/pgf/parser.cxx +++ b/src/runtime/c/pgf/parser.cxx @@ -167,13 +167,13 @@ ref PgfLRTableMaker::CCat::persist() { Production *prod = prods[i]; persistant->prods[i].lin = prod->lin; persistant->prods[i].index = prod->index; - auto children = vector_new>(prod->args.count); + auto children = vector>::alloc(prod->args.count); for (size_t j = 0; j < prod->args.count; j++) { if (prod->args[j] == NULL) { - *vector_elem(children, j) = 0; + children[j] = 0; } else { ref child_arg = prod->args[j]->persist(); - *vector_elem(children, j) = child_arg; + children[j] = child_arg; } } persistant->prods[i].args = children; @@ -209,7 +209,7 @@ PgfLRTableMaker::CCat::~CCat() { void *PgfLRTableMaker::Production::operator new(size_t size, Item *item) { ref lin = ref::untagged(item->lin_obj); - size_t n_fields = lin->seqs->len / lin->res->len; + size_t n_fields = lin->seqs.size() / lin->res.size(); size_t ex_size = sizeof(CCat*)*item->args.count+sizeof(size_t)*item->vals.count; Production *prod = (Production *) malloc(size+ex_size); @@ -229,17 +229,17 @@ void *PgfLRTableMaker::Production::operator new(size_t size, Item *item) { } void *PgfLRTableMaker::Item::operator new(size_t size, CCat* ccat, ref lin, size_t seq_idx) { - size_t n_args = lin->absfun->type->hypos->len; - size_t n_fields = lin->seqs->len / lin->res->len; - ref res = *vector_elem(lin->res, seq_idx / n_fields); - size_t n_vars = res->vars->len; + size_t n_args = lin->absfun->type->hypos.size(); + size_t n_fields = lin->seqs.size() / lin->res.size(); + ref res = lin->res[seq_idx / n_fields]; + size_t n_vars = res->vars.size(); size_t ex_size = sizeof(Arg)*n_args+sizeof(size_t)*n_vars; Item *item = (Item *) malloc(size+ex_size); item->ref_cnt = 0; item->ccat = ccat; item->lin_obj = lin.tagged(); - item->seq = *vector_elem(lin->seqs,seq_idx); + item->seq = lin->seqs[seq_idx]; item->seq_idx = seq_idx; item->sym_idx = 0; item->stk_size = 0; @@ -252,18 +252,18 @@ void *PgfLRTableMaker::Item::operator new(size_t size, CCat* ccat, ref lincat, size_t index) { size_t n_args = 1; - ref res = *vector_elem(lincat->res, lincat->n_lindefs+index); - size_t n_vars = res->vars->len; + ref res = lincat->res[lincat->n_lindefs+index]; + size_t n_vars = res->vars.size(); size_t ex_size = sizeof(Arg)*n_args+sizeof(size_t)*n_vars; size_t seq_idx = - lincat->n_lindefs*lincat->fields->len + index; + lincat->n_lindefs*lincat->fields.size() + index; Item *item = (Item *) malloc(size+ex_size); item->ref_cnt = 0; item->ccat = NULL; item->lin_obj = lincat.tagged(); - item->seq = *vector_elem(lincat->seqs,seq_idx); + item->seq = lincat->seqs[seq_idx]; item->seq_idx = seq_idx; item->sym_idx = 0; item->stk_size = 0; @@ -275,8 +275,8 @@ void *PgfLRTableMaker::Item::operator new(size_t size, ref linca } void *PgfLRTableMaker::Item::operator new(size_t size, CCat* ccat, Production *prod, size_t lin_idx) { - size_t n_fields = prod->lin->seqs->len / prod->lin->res->len; - ref res = *vector_elem(prod->lin->res, prod->index); + size_t n_fields = prod->lin->seqs.size() / prod->lin->res.size(); + ref res = prod->lin->res[prod->index]; size_t ex_size = sizeof(Arg)*prod->args.count+sizeof(size_t)*prod->vals.count; Item *item = (Item *) malloc(size+ex_size); @@ -284,7 +284,7 @@ void *PgfLRTableMaker::Item::operator new(size_t size, CCat* ccat, Production *p item->ccat = ccat; item->lin_obj = prod->lin.tagged(); item->seq_idx = prod->index*n_fields+lin_idx; - item->seq = *vector_elem(prod->lin->seqs,item->seq_idx); + item->seq = prod->lin->seqs[item->seq_idx]; item->sym_idx = 0; item->stk_size = 0; item->args.count = prod->args.count; @@ -317,7 +317,7 @@ void *PgfLRTableMaker::Item::operator new(size_t size, Item *item, CCat *ccat) { memcpy(new_item+1,item+1,ex_size); ref scat = - ref::untagged(item->seq->syms.data[item->sym_idx]); + ref::untagged(item->seq->syms[item->sym_idx]); new_item->args[scat->d].ccat = ccat; return new_item; @@ -339,7 +339,7 @@ void *PgfLRTableMaker::Item::operator new(size_t size, Item *item, size_t lin_id memcpy(new_item+1,item+1,ex_size); ref scat = - ref::untagged(item->seq->syms.data[item->sym_idx]); + ref::untagged(item->seq->syms[item->sym_idx]); new_item->args[scat->d].stk_idx = ++new_item->stk_size; return new_item; @@ -359,14 +359,14 @@ bool PgfLRTableMaker::CompareKey3::operator() (const Key3& k1, const Key3& k2) c size_t i = k1.second; size_t j = k2.second; for (;;) { - if (i >= k1.first->syms.len || ref::get_tag(k1.first->syms.data[i]) != PgfSymbolKS::tag) - return (j < k2.first->syms.len && ref::get_tag(k2.first->syms.data[j]) == PgfSymbolKS::tag); + if (i >= k1.first->syms.size() || ref::get_tag(k1.first->syms[i]) != PgfSymbolKS::tag) + return (j < k2.first->syms.size() && ref::get_tag(k2.first->syms[j]) == PgfSymbolKS::tag); - if (j >= k2.first->syms.len || ref::get_tag(k2.first->syms.data[j]) != PgfSymbolKS::tag) + if (j >= k2.first->syms.size() || ref::get_tag(k2.first->syms[j]) != PgfSymbolKS::tag) return false; - auto symks1 = ref::untagged(k1.first->syms.data[i]); - auto symks2 = ref::untagged(k2.first->syms.data[j]); + auto symks1 = ref::untagged(k1.first->syms[i]); + auto symks2 = ref::untagged(k2.first->syms[j]); int res[2] = {0,0}; texticmp(&symks1->token, &symks2->token, res); @@ -447,7 +447,7 @@ PgfLRTableMaker::PgfLRTableMaker(ref abstr, ref concr) MD5Context ctxt; - for (size_t i = 0; i < lincat->res->len-lincat->n_lindefs; i++) { + for (size_t i = 0; i < lincat->res.size()-lincat->n_lindefs; i++) { Item *item = new(lincat, i) Item; ctxt.update(item->lin_obj); @@ -634,8 +634,8 @@ void PgfLRTableMaker::process(State *state, Fold fold, Item *item) print_item(item); #endif - if (item->sym_idx < item->seq->syms.len) { - PgfSymbol sym = item->seq->syms.data[item->sym_idx]; + if (item->sym_idx < item->seq->syms.size()) { + PgfSymbol sym = item->seq->syms[item->sym_idx]; symbol(state, fold, item, sym); } else { complete(state, fold, item); @@ -652,13 +652,12 @@ void PgfLRTableMaker::symbol(State *state, Fold fold, Item *item, PgfSymbol sym) case PgfConcrLin::tag: { auto lin = ref::untagged(item->lin_obj); - ref res = - *vector_elem(lin->res, item->seq_idx / lin->lincat->fields->len); + ref res = lin->res[item->seq_idx / lin->lincat->fields.size()]; auto arg = item->args[symcat->d]; if (arg.ccat != NULL) { predict(state, fold, item, arg.ccat, res->vars, &symcat->r); } else { - ref hypo = vector_elem(lin->absfun->type->hypos, symcat->d); + ref hypo = lin->absfun->type->hypos.elem(symcat->d); predict(state, fold, item, ref::from_ptr(&hypo->type->name), res->vars, &symcat->r); } break; @@ -667,7 +666,7 @@ void PgfLRTableMaker::symbol(State *state, Fold fold, Item *item, PgfSymbol sym) auto lincat = ref::untagged(item->lin_obj); ref res = - *vector_elem(lincat->res, lincat->n_lindefs + item->seq_idx - lincat->n_lindefs*lincat->fields->len); + lincat->res[lincat->n_lindefs + item->seq_idx - lincat->n_lindefs*lincat->fields.size()]; auto arg = item->args[symcat->d]; if (arg.ccat != NULL) { predict(state, fold, item, arg.ccat, res->vars, &symcat->r); @@ -683,15 +682,15 @@ void PgfLRTableMaker::symbol(State *state, Fold fold, Item *item, PgfSymbol sym) auto symks = ref::untagged(sym); size_t sym_idx_2 = item->sym_idx+1; - while (sym_idx_2 < item->seq->syms.len) { - if (ref::get_tag(item->seq->syms.data[sym_idx_2]) != PgfSymbolKS::tag) + while (sym_idx_2 < item->seq->syms.size()) { + if (ref::get_tag(item->seq->syms[sym_idx_2]) != PgfSymbolKS::tag) break; sym_idx_2++; } if (fold == PROBE) { item->ccat->productive = true; - if (item->sym_idx > 0 || sym_idx_2 < item->seq->syms.len) { + if (item->sym_idx > 0 || sym_idx_2 < item->seq->syms.size()) { item->ccat->register_item(item); } } else { @@ -714,9 +713,9 @@ void PgfLRTableMaker::symbol(State *state, Fold fold, Item *item, PgfSymbol sym) auto symkp = ref::untagged(sym); Item *new_item1 = NULL; Item *new_item2 = NULL; - for (size_t i = 0; i < symkp->alts.len; i++) { - ref form = symkp->alts.data[i].form; - if (form->syms.len == 0) { + for (size_t i = 0; i < symkp->alts.size(); i++) { + ref form = symkp->alts[i].form; + if (form->syms.size() == 0) { if (!new_item1) { new_item1 = new (item) Item; new_item1->sym_idx++; @@ -737,7 +736,7 @@ void PgfLRTableMaker::symbol(State *state, Fold fold, Item *item, PgfSymbol sym) } ref form = symkp->default_form; - if (form->syms.len == 0) { + if (form->syms.size() == 0) { if (!new_item1) { new_item1 = new (item) Item; new_item1->sym_idx++; @@ -821,7 +820,7 @@ struct PGF_INTERNAL_DECL PgfVariableValue { template void PgfLRTableMaker::predict(State *state, Fold fold, Item *item, T cat, - ref> vars, PgfLParam *r) + vector vars, PgfLParam *r) { size_t index = r->i0; size_t n_terms = 0; @@ -831,9 +830,9 @@ void PgfLRTableMaker::predict(State *state, Fold fold, Item *item, T cat, for (size_t i = 0; i < r->n_terms; i++) { size_t var = r->terms[i].var; - for (size_t j = 0; j < vars->len; j++) + for (size_t j = 0; j < vars.size(); j++) { - ref range = vector_elem(vars, j); + ref range = vars.elem(j); if (range->var == var) { if (item->vals[j] == 0) { values[n_terms].range = range->range; @@ -985,8 +984,8 @@ void PgfLRTableMaker::predict(ref absfun, CCat *ccat) if (lin != 0) { ccat->lincat = lin->lincat; - size_t n_fields = lin->seqs->len / lin->res->len; - for (size_t i = 0; i < lin->res->len; i++) { + size_t n_fields = lin->seqs.size() / lin->res.size(); + for (size_t i = 0; i < lin->res.size(); i++) { size_t seq_idx = n_fields * i + ccat->lin_idx; Item *item = new(ccat, lin, seq_idx) Item; process(NULL, PROBE, item); @@ -1066,7 +1065,7 @@ void PgfLRTableMaker::internalize_state(State *&state) } } -ref PgfLRTableMaker::make() +vector PgfLRTableMaker::make() { while (!todo.empty()) { State *state = todo.front(); todo.pop(); @@ -1133,31 +1132,31 @@ ref PgfLRTableMaker::make() } - ref lrtable = vector_new(states.size()); + vector lrtable = vector::alloc(states.size()); for (auto v : states) { State *state = v.second; size_t index = 0; - auto shifts = vector_new(state->ccats1.size()+state->ccats2.size()); + auto shifts = vector::alloc(state->ccats1.size()+state->ccats2.size()); for (auto i : state->ccats1) { - ref shift = vector_elem(shifts,index++); + ref shift = shifts.elem(index++); shift->lincat = i.first.first; shift->r = i.first.second; shift->next_state = i.second->id; } for (auto i : state->ccats2) { - ref shift = vector_elem(shifts,index++); + ref shift = shifts.elem(index++); shift->lincat = i.first.first->lincat; shift->r = i.first.second; shift->next_state = i.second->id; } - ref> tokens = 0; + vector tokens = 0; if (state->tokens.size() > 0) { size_t index = 0; - tokens = vector_new(state->tokens.size()); + tokens = vector::alloc(state->tokens.size()); for (auto i : state->tokens) { - ref shift = vector_elem(tokens,index++); + ref shift = tokens.elem(index++); shift->seq = i.first.first; shift->sym_idx = i.first.second; shift->next_state = i.second->id; @@ -1169,27 +1168,27 @@ ref PgfLRTableMaker::make() next_bind_state = state->bind_state->id; } - auto reductions = vector_new(state->completed.size()); + auto reductions = vector::alloc(state->completed.size()); for (size_t i = 0; i < state->completed.size(); i++) { Item *item = state->completed[i]; - ref reduction = vector_elem(reductions,i); + ref reduction = reductions.elem(i); reduction->lin_obj = item->lin_obj; reduction->seq_idx = item->seq_idx; reduction->depth = item->stk_size; - auto args = vector_new(item->args.count); + auto args = vector::alloc(item->args.count); for (size_t j = 0; j < item->args.count; j++) { ref arg = 0; if (item->args[j].ccat != NULL) { arg = item->args[j].ccat->persist(); } - vector_elem(args, j)->arg = arg; - vector_elem(args, j)->stk_idx = item->args[j].stk_idx; + args[j].arg = arg; + args[j].stk_idx = item->args[j].stk_idx; } reduction->args = args; } - ref lrstate = vector_elem(lrtable, state->id); + ref lrstate = lrtable.elem(state->id); lrstate->shifts = shifts; lrstate->tokens = tokens; lrstate->next_bind_state = next_bind_state; @@ -1218,7 +1217,7 @@ struct PgfParser::Production { Choice *args[]; void *operator new(size_t size, ref lin, size_t index) { - size_t n_args = lin->args->len / lin->res->len; + size_t n_args = lin->args.size() / lin->res.size(); Production *prod = (Production *) malloc(size+sizeof(Choice*)*n_args); prod->lin = lin; @@ -1396,9 +1395,9 @@ PgfParser::PgfParser(ref concr, ref start, PgfText *se bool PgfParser::shift(StackNode *parent, ref lincat, size_t r, Production *prod, Stage *before, Stage *after) { - ref> shifts = vector_elem(concr->lrtable,parent->state_id)->shifts; - for (size_t i = 0; i < shifts->len; i++) { - ref shift = vector_elem(shifts,i); + vector shifts = concr->lrtable[parent->state_id].shifts; + for (size_t i = 0; i < shifts.size(); i++) { + ref shift = shifts.elem(i); if (lincat == shift->lincat && r == shift->r) { StackNode *node = NULL; for (StackNode *n : after->nodes) { @@ -1445,11 +1444,11 @@ bool PgfParser::shift(StackNode *parent, ref lincat, size_t r, P void PgfParser::shift(StackNode *parent, Stage *before) { - ref> shifts = vector_elem(concr->lrtable,parent->state_id)->tokens; + vector shifts = concr->lrtable[parent->state_id].tokens; if (shifts != 0) { const uint8_t *sent_end = (const uint8_t *) &sentence->text[sentence->size]; - for (size_t i = 0; i < shifts->len; i++) { - ref shift = vector_elem(shifts, i); + for (size_t i = 0; i < shifts.size(); i++) { + ref shift = shifts.elem(i); PgfTextSpot spot = before->end; size_t sym_idx = shift->sym_idx; int cmp = @@ -1487,7 +1486,7 @@ void PgfParser::shift(StackNode *parent, Stage *before) void PgfParser::shift(StackNode *parent, Stage *before, Stage *after) { - size_t next_bind_state = vector_elem(concr->lrtable,parent->state_id)->next_bind_state; + size_t next_bind_state = concr->lrtable[parent->state_id].next_bind_state; if (next_bind_state != 0) { StackNode *node = NULL; for (StackNode *n : after->nodes) { @@ -1561,12 +1560,12 @@ void PgfParser::reduce(StackNode *parent, ref lin, ref if (n == 0) { ref lincat = lin->lincat; - size_t index = red->seq_idx / lincat->fields->len; - size_t r = red->seq_idx % lincat->fields->len; + size_t index = red->seq_idx / lincat->fields.size(); + size_t r = red->seq_idx % lincat->fields.size(); Production *prod = new(lin,index) Production(); for (size_t i = 0; i < prod->n_args; i++) { - auto arg = vector_elem(red->args, i); + auto arg = red->args.elem(i); if (arg->stk_idx > 0) { Choice *choice = args[red->depth-arg->stk_idx]; @@ -1619,7 +1618,7 @@ PgfParser::Choice *PgfParser::retrieve_choice(ref arg) for (size_t i = 0; i < arg->n_prods; i++) { Production *prod = new(arg->prods[i].lin, arg->prods[i].index) Production(); for (size_t j = 0; j < prod->n_args; j++) { - auto child = *vector_elem(arg->prods[i].args, j); + auto child = arg->prods[i].args[j]; prod->args[j] = retrieve_choice(child); } choice->prods.push_back(prod); @@ -1649,9 +1648,9 @@ void PgfParser::complete(StackNode *parent, ref lincat, size_t r void PgfParser::reduce_all(StackNode *node) { - ref> reductions = vector_elem(concr->lrtable,node->state_id)->reductions; - for (size_t j = 0; j < reductions->len; j++) { - ref red = vector_elem(reductions,j); + vector reductions = concr->lrtable[node->state_id].reductions; + for (size_t j = 0; j < reductions.size(); j++) { + ref red = reductions.elem(j); switch (ref::get_tag(red->lin_obj)) { case PgfConcrLin::tag: { auto lin = @@ -1665,7 +1664,7 @@ void PgfParser::reduce_all(StackNode *node) ref::untagged(red->lin_obj); std::vector args; if (before->end.pos == sentence->size) { - complete(node, lincat, red->seq_idx % lincat->fields->len, red->depth, args); + complete(node, lincat, red->seq_idx % lincat->fields.size(), red->depth, args); } } } @@ -1723,8 +1722,8 @@ void PgfParser::start_matches(PgfTextSpot *end, PgfExn* err) void PgfParser::match(ref lin, size_t seq_index, PgfExn* err) { - size_t index = seq_index / lin->lincat->fields->len; - size_t r = seq_index % lin->lincat->fields->len; + size_t index = seq_index / lin->lincat->fields.size(); + size_t r = seq_index % lin->lincat->fields.size(); for (StackNode *parent : before->nodes) { Production *prod = new(lin,index) Production(); @@ -1933,4 +1932,4 @@ PgfParser::~PgfParser() ExprState *state = queue.top(); queue.pop(); delete state; } -} \ No newline at end of file +} diff --git a/src/runtime/c/pgf/parser.h b/src/runtime/c/pgf/parser.h index abd7f61bc..a17d32b80 100644 --- a/src/runtime/c/pgf/parser.h +++ b/src/runtime/c/pgf/parser.h @@ -78,7 +78,7 @@ class PGF_INTERNAL_DECL PgfLRTableMaker template void predict(State *state, Fold fold, Item *item, T cat, - ref> vars, PgfLParam *r); + vector vars, PgfLParam *r); void predict(State *state, Fold fold, Item *item, ref cat, size_t lin_idx); void predict(State *state, Fold fold, Item *item, CCat *ccat, size_t lin_idx); void predict(ref absfun, CCat *ccat); @@ -91,7 +91,7 @@ class PGF_INTERNAL_DECL PgfLRTableMaker public: PgfLRTableMaker(ref abstr, ref concr); - ref make(); + vector make(); ~PgfLRTableMaker(); }; diff --git a/src/runtime/c/pgf/pgf.cxx b/src/runtime/c/pgf/pgf.cxx index 10a1c35b9..9bf83771a 100644 --- a/src/runtime/c/pgf/pgf.cxx +++ b/src/runtime/c/pgf/pgf.cxx @@ -545,14 +545,14 @@ PgfTypeHypo *pgf_category_context(PgfDB *db, PgfRevision revision, PgfDBMarshaller m; PgfTypeHypo *hypos = (PgfTypeHypo *) - malloc(abscat->context->len * sizeof(PgfTypeHypo)); - 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 = m.match_type(u, abscat->context->data[i].type.as_object()); + malloc(abscat->context.size() * sizeof(PgfTypeHypo)); + for (size_t i = 0; i < abscat->context.size(); i++) { + hypos[i].bind_type = abscat->context[i].bind_type; + hypos[i].cid = textdup(abscat->context[i].cid); + hypos[i].type = m.match_type(u, abscat->context[i].type.as_object()); } - *n_hypos = abscat->context->len; + *n_hypos = abscat->context.size(); return hypos; } PGF_API_END @@ -845,13 +845,13 @@ PgfText *pgf_print_category_internal(object o) printer.puts("cat "); printer.efun(&abscat->name); - for (size_t i = 0; i < abscat->context->len; i++) { + for (size_t i = 0; i < abscat->context.size(); i++) { printer.puts(" "); PgfTypeHypo hypo; - hypo.bind_type = abscat->context->data[i].bind_type; - hypo.cid = abscat->context->data[i].cid; - hypo.type = abscat->context->data[i].type.as_object(); + hypo.bind_type = abscat->context[i].bind_type; + hypo.cid = abscat->context[i].cid; + hypo.type = abscat->context[i].type.as_object(); printer.hypo(&hypo,4); } @@ -967,7 +967,7 @@ class PGF_INTERNAL_DECL PgfMorphoScanner : public PgfPhraseScanner { virtual void match(ref lin, size_t seq_index, PgfExn* err) { ref field = - *vector_elem(lin->lincat->fields, seq_index % lin->lincat->fields->len); + lin->lincat->fields[seq_index % lin->lincat->fields.size()]; callback->fn(callback, &lin->absfun->name, field, lin->lincat->abscat->prob+lin->absfun->prob, err); } @@ -1015,7 +1015,7 @@ class PGF_INTERNAL_DECL PgfCohortsScanner : public PgfPhraseScanner { virtual void match(ref lin, size_t seq_index, PgfExn* err) { ref field = - *vector_elem(lin->lincat->fields, seq_index % lin->lincat->fields->len); + lin->lincat->fields[seq_index % lin->lincat->fields.size()]; callback->morpho.fn(&callback->morpho, &lin->absfun->name, field, lin->lincat->abscat->prob+lin->absfun->prob, err); } @@ -1072,23 +1072,23 @@ PGF_API void pgf_get_lincat_counts_internal(object o, size_t *counts) { ref lincat = o; - counts[0] = lincat->fields->len; + counts[0] = lincat->fields.size(); counts[1] = lincat->n_lindefs; - counts[2] = lincat->res->len - lincat->n_lindefs; + counts[2] = lincat->res.size() - lincat->n_lindefs; } PGF_API PgfText *pgf_get_lincat_field_internal(object o, size_t i) { ref lincat = o; - return &**vector_elem(lincat->fields, i); + return &*lincat->fields[i]; } PGF_API size_t pgf_get_lin_get_prod_count(object o) { ref lin = o; - return lin->res->len; + return lin->res.size(); } PGF_API @@ -1099,7 +1099,7 @@ PgfText *pgf_print_lindef_internal(PgfPhrasetableIds *seq_ids, object o, size_t PgfInternalMarshaller m; PgfPrinter printer(NULL,0,&m); - ref res = *vector_elem(lincat->res, i); + ref res = lincat->res[i]; if (res->vars != 0) { printer.lvar_ranges(res->vars, NULL); printer.puts(" . "); @@ -1112,12 +1112,12 @@ PgfText *pgf_print_lindef_internal(PgfPhrasetableIds *seq_ids, object o, size_t printer.efun(&lincat->name); printer.puts("[String(0)] = ["); - size_t n_seqs = lincat->fields->len; + size_t n_seqs = lincat->fields.size(); for (size_t j = 0; j < n_seqs; j++) { if (j > 0) printer.puts(","); - ref seq = *vector_elem(lincat->seqs, i*n_seqs + j); + ref seq = lincat->seqs[i*n_seqs + j]; printer.seq_id(seq_ids, seq); } @@ -1134,7 +1134,7 @@ PgfText *pgf_print_linref_internal(PgfPhrasetableIds *seq_ids, object o, size_t PgfInternalMarshaller m; PgfPrinter printer(NULL,0,&m); - ref res = *vector_elem(lincat->res, lincat->n_lindefs+i); + ref res = lincat->res[lincat->n_lindefs+i]; if (res->vars != 0) { printer.lvar_ranges(res->vars, NULL); printer.puts(" . "); @@ -1145,11 +1145,11 @@ PgfText *pgf_print_linref_internal(PgfPhrasetableIds *seq_ids, object o, size_t printer.puts("["); printer.efun(&lincat->name); printer.puts("("); - printer.lparam(vector_elem(lincat->args, lincat->n_lindefs+i)->param); + printer.lparam(lincat->args[lincat->n_lindefs+i].param); printer.puts(")] = ["); - size_t n_seqs = lincat->fields->len; - ref seq = *vector_elem(lincat->seqs, lincat->n_lindefs*n_seqs+i); + size_t n_seqs = lincat->fields.size(); + ref seq = lincat->seqs[lincat->n_lindefs*n_seqs+i]; printer.seq_id(seq_ids, seq); printer.puts("]"); @@ -1165,7 +1165,7 @@ PgfText *pgf_print_lin_internal(PgfPhrasetableIds *seq_ids, object o, size_t i) PgfInternalMarshaller m; PgfPrinter printer(NULL,0,&m); - ref res = *vector_elem(lin->res, i); + ref res = lin->res[i]; ref ty = lin->absfun->type; if (res->vars != 0) { @@ -1180,21 +1180,21 @@ PgfText *pgf_print_lin_internal(PgfPhrasetableIds *seq_ids, object o, size_t i) printer.efun(&lin->name); printer.puts("["); - size_t n_args = lin->args->len / lin->res->len; + size_t n_args = lin->args.size() / lin->res.size(); for (size_t j = 0; j < n_args; j++) { if (j > 0) printer.puts(","); - printer.parg(vector_elem(ty->hypos, j)->type, - vector_elem(lin->args, i*n_args + j)); + printer.parg(ty->hypos.elem(j)->type, + lin->args.elem(i*n_args + j)); } printer.puts("] = ["); - size_t n_seqs = lin->seqs->len / lin->res->len; + size_t n_seqs = lin->seqs.size() / lin->res.size(); for (size_t j = 0; j < n_seqs; j++) { if (j > 0) printer.puts(","); - ref seq = *vector_elem(lin->seqs, i*n_seqs + j); + ref seq = lin->seqs[i*n_seqs + j]; printer.seq_id(seq_ids, seq); } @@ -1223,11 +1223,11 @@ PgfText *pgf_sequence_get_text_internal(object o) ref seq = o; PgfPrinter printer(NULL,0,NULL); - for (size_t i = 0; i < seq->syms.len; i++) { + for (size_t i = 0; i < seq->syms.size(); i++) { if (i > 0) printer.puts(" "); - PgfSymbol sym = *vector_elem(&seq->syms, i); + PgfSymbol sym = seq->syms[i]; switch (ref::get_tag(sym)) { case PgfSymbolKS::tag: { auto sym_ks = ref::untagged(sym); @@ -1515,8 +1515,8 @@ void drop_lin(ref concr, PgfText *name) namespace_delete(concr->lins, name, &lin); if (lin != 0) { object container = lin.tagged(); - for (size_t i = 0; i < lin->seqs->len; i++) { - ref seq = *vector_elem(lin->seqs, i); + for (size_t i = 0; i < lin->seqs.size(); i++) { + ref seq = lin->seqs[i]; PgfPhrasetable phrasetable = phrasetable_delete(concr->phrasetable,container,i,seq); concr->phrasetable = phrasetable; @@ -1572,14 +1572,14 @@ void pgf_create_category(PgfDB *db, PgfRevision revision, ref pgf = db->revision2pgf(revision); ref abscat = PgfDB::malloc(name->size+1); - abscat->context = vector_new(n_hypos); + abscat->context = vector::alloc(n_hypos); abscat->prob = prob; memcpy(&abscat->name, name, sizeof(PgfText)+name->size+1); for (size_t i = 0; i < n_hypos; i++) { - vector_elem(abscat->context, i)->bind_type = context[i].bind_type; - vector_elem(abscat->context, i)->cid = textdup_db(context[i].cid); - vector_elem(abscat->context, i)->type = m->match_type(&u, context[i].type); + abscat->context[i].bind_type = context[i].bind_type; + abscat->context[i].cid = textdup_db(context[i].cid); + abscat->context[i].type = m->match_type(&u, context[i].type); } Namespace cats = @@ -1741,9 +1741,9 @@ class PGF_INTERNAL PgfLinBuilder : public PgfLinBuilderIface { ref concr; - ref> args; - ref>> res; - ref>> seqs; + vector args; + vector> res; + vector> seqs; object container; // what are we building? ref container_lincat; @@ -1791,9 +1791,9 @@ class PGF_INTERNAL PgfLinBuilder : public PgfLinBuilderIface PgfBuildLinIface *build, PgfExn *err) { size_t n_prods = n_lindefs+n_linrefs; - this->args = vector_new(n_prods); - this->res = vector_new>(n_prods); - this->seqs = vector_new>(n_lindefs*n_fields+n_linrefs); + this->args = vector::alloc(n_prods); + this->res = vector>::alloc(n_prods); + this->seqs = vector>::alloc(n_lindefs*n_fields+n_linrefs); this->n_lindefs = n_lindefs; this->n_linrefs = n_linrefs; @@ -1805,10 +1805,10 @@ class PGF_INTERNAL PgfLinBuilder : public PgfLinBuilderIface lincat->seqs = seqs; lincat->n_lindefs = n_lindefs; - ref>> db_fields = vector_new>(n_fields); + vector> db_fields = vector>::alloc(n_fields); for (size_t i = 0; i < n_fields; i++) { ref name = textdup_db(fields[i]); - *vector_elem(db_fields, i) = name; + db_fields[i] = name; } lincat->fields = db_fields; @@ -1816,7 +1816,7 @@ class PGF_INTERNAL PgfLinBuilder : public PgfLinBuilderIface this->container_lincat = 0; build->build(this, err); - if (err->type == PGF_EXN_NONE && res_index != res->len) { + if (err->type == PGF_EXN_NONE && res_index != res.size()) { err->type = PGF_EXN_PGF_ERROR; err->msg = builder_error_msg; } @@ -1837,9 +1837,9 @@ class PGF_INTERNAL PgfLinBuilder : public PgfLinBuilderIface throw pgf_error("Missing linearization category"); } - this->args = vector_new(n_prods*absfun->type->hypos->len); - this->res = vector_new>(n_prods); - this->seqs = vector_new>(n_prods*lincat->fields->len); + this->args = vector::alloc(n_prods*absfun->type->hypos.size()); + this->res = vector>::alloc(n_prods); + this->seqs = vector>::alloc(n_prods*lincat->fields.size()); this->n_lindefs = n_prods; ref lin = PgfDB::malloc(absfun->name.size+1); @@ -1854,7 +1854,7 @@ class PGF_INTERNAL PgfLinBuilder : public PgfLinBuilderIface this->container_lincat = lincat; build->build(this, err); - if (err->type == PGF_EXN_NONE && res_index != res->len) { + if (err->type == PGF_EXN_NONE && res_index != res.size()) { err->type = PGF_EXN_PGF_ERROR; err->msg = builder_error_msg; } @@ -1872,10 +1872,10 @@ class PGF_INTERNAL PgfLinBuilder : public PgfLinBuilderIface return; PGF_API_BEGIN { - if (res_index >= res->len) + if (res_index >= res.size()) throw pgf_error(builder_error_msg); var_index = 0; - *vector_elem(res, res_index) = 0; + res[res_index] = 0; } PGF_API_END } @@ -1885,7 +1885,7 @@ class PGF_INTERNAL PgfLinBuilder : public PgfLinBuilderIface return; PGF_API_BEGIN { - if (arg_index >= args->len) + if (arg_index >= args.size()) throw pgf_error(builder_error_msg); ref param = PgfDB::malloc(n_terms*2*sizeof(size_t)); @@ -1897,7 +1897,7 @@ class PGF_INTERNAL PgfLinBuilder : public PgfLinBuilderIface param->terms[i].var = terms[2*i+1]; } - ref parg = vector_elem(args, arg_index); + ref parg = args.elem(arg_index); parg->param = param; arg_index++; @@ -1910,11 +1910,11 @@ class PGF_INTERNAL PgfLinBuilder : public PgfLinBuilderIface return; PGF_API_BEGIN { - if (res_index >= res->len) + if (res_index >= res.size()) throw pgf_error(builder_error_msg); - ref> vars = - (n_vars > 0) ? vector_new(n_vars) + vector vars = + (n_vars > 0) ? vector::alloc(n_vars) : 0; ref res_elem = PgfDB::malloc(n_terms*2*sizeof(size_t)); @@ -1927,7 +1927,7 @@ class PGF_INTERNAL PgfLinBuilder : public PgfLinBuilderIface res_elem->param.terms[i].var = terms[2*i+1]; } - *vector_elem(res, res_index) = res_elem; + res[res_index] = res_elem; } PGF_API_END } @@ -1937,17 +1937,16 @@ class PGF_INTERNAL PgfLinBuilder : public PgfLinBuilderIface return; PGF_API_BEGIN { - if (res_index >= res->len) + if (res_index >= res.size()) throw pgf_error(builder_error_msg); - ref res_elem = - *vector_elem(res, res_index); + ref res_elem = res[res_index]; - if (res_elem->vars == 0 || var_index >= res_elem->vars->len) + if (res_elem->vars == 0 || var_index >= res_elem->vars.size()) throw pgf_error(builder_error_msg); ref var_range = - vector_elem(res_elem->vars, var_index); + res_elem->vars.elem(var_index); var_range->var = var; var_range->range = range; @@ -1961,13 +1960,12 @@ class PGF_INTERNAL PgfLinBuilder : public PgfLinBuilderIface return; PGF_API_BEGIN { - if (seq_index >= seqs->len) + if (seq_index >= seqs.size()) throw pgf_error(builder_error_msg); - seq = PgfDB::malloc(n_syms*sizeof(PgfSymbol)); - seq->syms.len = n_syms; + seq = inline_vector::alloc(&PgfSequence::syms, n_syms); - *vector_elem(seqs, seq_index) = seq; + seqs[seq_index] = seq; sym_index = 0; } PGF_API_END } @@ -1978,7 +1976,7 @@ class PGF_INTERNAL PgfLinBuilder : public PgfLinBuilderIface return; PGF_API_BEGIN { - if (seq == 0 || sym_index == (size_t) -1 || sym_index >= seq->syms.len) + if (seq == 0 || sym_index == (size_t) -1 || sym_index >= seq->syms.size()) throw pgf_error(builder_error_msg); ref symcat = PgfDB::malloc(n_terms*2*sizeof(size_t)); @@ -1991,7 +1989,7 @@ class PGF_INTERNAL PgfLinBuilder : public PgfLinBuilderIface symcat->r.terms[i].var = terms[2*i+1]; } - *vector_elem(&seq->syms, sym_index) = symcat.tagged(); + seq->syms[sym_index] = symcat.tagged(); sym_index++; } PGF_API_END } @@ -2002,7 +2000,7 @@ class PGF_INTERNAL PgfLinBuilder : public PgfLinBuilderIface return; PGF_API_BEGIN { - if (seq == 0 || sym_index == (size_t) -1 || sym_index >= seq->syms.len) + if (seq == 0 || sym_index == (size_t) -1 || sym_index >= seq->syms.size()) throw pgf_error(builder_error_msg); ref symlit = PgfDB::malloc(n_terms*2*sizeof(size_t)); @@ -2015,7 +2013,7 @@ class PGF_INTERNAL PgfLinBuilder : public PgfLinBuilderIface symlit->r.terms[i].var = terms[2*i+1]; } - *vector_elem(&seq->syms, sym_index) = symlit.tagged(); + seq->syms[sym_index] = symlit.tagged(); sym_index++; } PGF_API_END } @@ -2026,14 +2024,14 @@ class PGF_INTERNAL PgfLinBuilder : public PgfLinBuilderIface return; PGF_API_BEGIN { - if (seq == 0 || sym_index == (size_t) -1 || sym_index >= seq->syms.len) + if (seq == 0 || sym_index == (size_t) -1 || sym_index >= seq->syms.size()) throw pgf_error(builder_error_msg); ref symvar = PgfDB::malloc(); symvar->d = d; symvar->r = r; - *vector_elem(&seq->syms, sym_index) = symvar.tagged(); + seq->syms[sym_index] = symvar.tagged(); sym_index++; } PGF_API_END } @@ -2044,13 +2042,13 @@ class PGF_INTERNAL PgfLinBuilder : public PgfLinBuilderIface return; PGF_API_BEGIN { - if (seq == 0 || sym_index == (size_t) -1 || sym_index >= seq->syms.len) + if (seq == 0 || sym_index == (size_t) -1 || sym_index >= seq->syms.size()) throw pgf_error(builder_error_msg); ref symtok = PgfDB::malloc(token->size+1); memcpy(&symtok->token, token, sizeof(PgfText)+token->size+1); - *vector_elem(&seq->syms, sym_index) = symtok.tagged(); + seq->syms[sym_index] = symtok.tagged(); sym_index++; } PGF_API_END } @@ -2061,17 +2059,15 @@ class PGF_INTERNAL PgfLinBuilder : public PgfLinBuilderIface return; PGF_API_BEGIN { - if (seq == 0 || sym_index == (size_t) -1 || sym_index >= seq->syms.len || pre_sym_index != (size_t) -1) + if (seq == 0 || sym_index == (size_t) -1 || sym_index >= seq->syms.size() || pre_sym_index != (size_t) -1) throw pgf_error(builder_error_msg); - ref def = PgfDB::malloc(n_syms*sizeof(PgfSymbol)); - def->syms.len = n_syms; + ref def = inline_vector::alloc(&PgfSequence::syms,n_syms); - ref symkp = PgfDB::malloc(n_alts*sizeof(PgfAlternative)); + ref symkp = inline_vector::alloc(&PgfSymbolKP::alts,n_alts); symkp->default_form = def; - symkp->alts.len = n_alts; - *vector_elem(&seq->syms, sym_index) = symkp.tagged(); + seq->syms[sym_index] = symkp.tagged(); pre_sym_index = sym_index; seq = def; @@ -2089,18 +2085,17 @@ class PGF_INTERNAL PgfLinBuilder : public PgfLinBuilderIface if (pre_sym_index == (size_t) -1) throw pgf_error(builder_error_msg); - ref form = PgfDB::malloc(n_syms*sizeof(PgfSymbol)); - form->syms.len = n_syms; + ref form = inline_vector::alloc(&PgfSequence::syms, n_syms); - ref>> prefixes = vector_new>(n_prefs); + vector> prefixes = vector>::alloc(n_prefs); for (size_t i = 0; i < n_prefs; i++) { ref pref = textdup_db(prefs[i]); - *vector_elem(prefixes, i) = pref; + prefixes[i] = pref; } - seq = *vector_elem(seqs, seq_index); - ref symkp = ref::untagged(*vector_elem(&seq->syms, pre_sym_index)); - ref alt = ref::from_ptr(&symkp->alts.data[alt_index]); + seq = seqs[seq_index]; + ref symkp = ref::untagged(seq->syms[pre_sym_index]); + ref alt = symkp->alts.elem(alt_index); alt->form = form; alt->prefixes = prefixes; @@ -2119,9 +2114,9 @@ class PGF_INTERNAL PgfLinBuilder : public PgfLinBuilderIface if (pre_sym_index == (size_t) -1) throw pgf_error(builder_error_msg); - seq = *vector_elem(seqs, seq_index); - ref symkp = ref::untagged(*vector_elem(&seq->syms, pre_sym_index)); - if (alt_index >= symkp->alts.len) + seq = seqs[seq_index]; + ref symkp = ref::untagged(seq->syms[pre_sym_index]); + if (alt_index >= symkp->alts.size()) throw pgf_error(builder_error_msg); alt_index++; @@ -2137,7 +2132,7 @@ class PGF_INTERNAL PgfLinBuilder : public PgfLinBuilderIface if (pre_sym_index == (size_t) -1) throw pgf_error(builder_error_msg); - seq = *vector_elem(seqs, seq_index); + seq = seqs[seq_index]; sym_index = pre_sym_index+1; alt_index = 0; pre_sym_index = (size_t) -1; @@ -2150,10 +2145,10 @@ class PGF_INTERNAL PgfLinBuilder : public PgfLinBuilderIface return; PGF_API_BEGIN { - if (seq == 0 || sym_index == (size_t) -1 || sym_index >= seq->syms.len) + if (seq == 0 || sym_index == (size_t) -1 || sym_index >= seq->syms.size()) throw pgf_error(builder_error_msg); - *vector_elem(&seq->syms, sym_index) = ref(0).tagged(); + seq->syms[sym_index] = ref(0).tagged(); sym_index++; } PGF_API_END } @@ -2164,10 +2159,10 @@ class PGF_INTERNAL PgfLinBuilder : public PgfLinBuilderIface return; PGF_API_BEGIN { - if (seq == 0 || sym_index == (size_t) -1 || sym_index >= seq->syms.len) + if (seq == 0 || sym_index == (size_t) -1 || sym_index >= seq->syms.size()) throw pgf_error(builder_error_msg); - *vector_elem(&seq->syms, sym_index) = ref(0).tagged(); + seq->syms[sym_index] = ref(0).tagged(); sym_index++; } PGF_API_END } @@ -2178,10 +2173,10 @@ class PGF_INTERNAL PgfLinBuilder : public PgfLinBuilderIface return; PGF_API_BEGIN { - if (seq == 0 || sym_index == (size_t) -1 || sym_index >= seq->syms.len) + if (seq == 0 || sym_index == (size_t) -1 || sym_index >= seq->syms.size()) throw pgf_error(builder_error_msg); - *vector_elem(&seq->syms, sym_index) = ref(0).tagged(); + seq->syms[sym_index] = ref(0).tagged(); sym_index++; } PGF_API_END } @@ -2192,10 +2187,10 @@ class PGF_INTERNAL PgfLinBuilder : public PgfLinBuilderIface return; PGF_API_BEGIN { - if (seq == 0 || sym_index == (size_t) -1 || sym_index >= seq->syms.len) + if (seq == 0 || sym_index == (size_t) -1 || sym_index >= seq->syms.size()) throw pgf_error(builder_error_msg); - *vector_elem(&seq->syms, sym_index) = ref(0).tagged(); + seq->syms[sym_index] = ref(0).tagged(); sym_index++; } PGF_API_END } @@ -2206,10 +2201,10 @@ class PGF_INTERNAL PgfLinBuilder : public PgfLinBuilderIface return; PGF_API_BEGIN { - if (seq == 0 || sym_index == (size_t) -1 || sym_index >= seq->syms.len) + if (seq == 0 || sym_index == (size_t) -1 || sym_index >= seq->syms.size()) throw pgf_error(builder_error_msg); - *vector_elem(&seq->syms, sym_index) = ref(0).tagged(); + seq->syms[sym_index] = ref(0).tagged(); sym_index++; } PGF_API_END } @@ -2220,10 +2215,10 @@ class PGF_INTERNAL PgfLinBuilder : public PgfLinBuilderIface return; PGF_API_BEGIN { - if (seq == 0 || sym_index == (size_t) -1 || sym_index >= seq->syms.len) + if (seq == 0 || sym_index == (size_t) -1 || sym_index >= seq->syms.size()) throw pgf_error(builder_error_msg); - *vector_elem(&seq->syms, sym_index) = ref(0).tagged(); + seq->syms[sym_index] = ref(0).tagged(); sym_index++; } PGF_API_END } @@ -2236,7 +2231,7 @@ class PGF_INTERNAL PgfLinBuilder : public PgfLinBuilderIface ref entry = 0; PGF_API_BEGIN { - if (seq == 0 || sym_index != seq->syms.len) + if (seq == 0 || sym_index != seq->syms.size()) throw pgf_error(builder_error_msg); PgfPhrasetable phrasetable = @@ -2244,7 +2239,7 @@ class PGF_INTERNAL PgfLinBuilder : public PgfLinBuilderIface seq, container_lincat, container, seq_index, &entry); concr->phrasetable = phrasetable; - *vector_elem(seqs, seq_index) = entry->seq; + seqs[seq_index] = entry->seq; sym_index = (size_t) -1; seq = 0; @@ -2260,13 +2255,13 @@ class PGF_INTERNAL PgfLinBuilder : public PgfLinBuilderIface return; PGF_API_BEGIN { - if (seq_index >= seqs->len) + if (seq_index >= seqs.size()) throw pgf_error(builder_error_msg); ref entry = seq_id; phrasetable_add_backref(entry,PgfDB::get_txn_id(),container,seq_index); - *vector_elem(seqs, seq_index) = entry->seq; + seqs[seq_index] = entry->seq; seq_index++; } PGF_API_END @@ -2278,14 +2273,14 @@ class PGF_INTERNAL PgfLinBuilder : public PgfLinBuilderIface return; PGF_API_BEGIN { - size_t n_args = (args->len/res->len); + size_t n_args = (args.size()/res.size()); if (arg_index != (res_index+1)*n_args) throw pgf_error(builder_error_msg); - if (*vector_elem(res, res_index) == 0) + if (res[res_index] == 0) throw pgf_error(builder_error_msg); - size_t n_seqs = ((seqs->len-n_linrefs)/(res->len-n_linrefs)); + size_t n_seqs = ((seqs.size()-n_linrefs)/(res.size()-n_linrefs)); size_t exp_index = (res_index < n_lindefs) ? (res_index+1)*n_seqs : n_seqs * n_lindefs + (res_index-n_lindefs+1) ; @@ -2359,8 +2354,8 @@ void pgf_drop_lincat(PgfDB *db, // Remove the sequences comprizing the lindef and linref object container = lincat.tagged(); PgfPhrasetable phrasetable = concr->phrasetable; - for (size_t i = 0; i < lincat->seqs->len; i++) { - ref seq = *vector_elem(lincat->seqs, i); + for (size_t i = 0; i < lincat->seqs.size(); i++) { + ref seq = lincat->seqs[i]; phrasetable = phrasetable_delete(phrasetable,container,i,seq); } @@ -2437,8 +2432,8 @@ void pgf_alter_lin(PgfDB *db, if (old_lin != 0) { object container = old_lin.tagged(); PgfPhrasetable phrasetable = concr->phrasetable; - for (size_t i = 0; i < old_lin->seqs->len; i++) { - ref seq = *vector_elem(old_lin->seqs, i); + for (size_t i = 0; i < old_lin->seqs.size(); i++) { + ref seq = old_lin->seqs[i]; phrasetable = phrasetable_delete(phrasetable,container,i,seq); } @@ -2499,12 +2494,12 @@ PgfText **pgf_category_fields(PgfDB *db, PgfConcrRevision revision, *p_n_fields = 0; return NULL; } else { - size_t n_fields = lincat->fields->len; + size_t n_fields = lincat->fields.size(); PgfText **fields = (PgfText **) malloc(sizeof(PgfText*)*n_fields); if (fields == 0) throw pgf_systemerror(ENOMEM); for (size_t i = 0; i < n_fields; i++) { - fields[i] = textdup(*vector_elem(lincat->fields, i)); + fields[i] = textdup(lincat->fields[i]); } *p_n_fields = n_fields; return fields; @@ -2588,16 +2583,16 @@ PgfText **pgf_tabular_linearize(PgfDB *db, PgfConcrRevision revision, ref lincat = linearizer.get_lincat(); if (lincat != 0) { PgfText **res = (PgfText **) - malloc((lincat->fields->len+1)*2*sizeof(PgfText*)); + malloc((lincat->fields.size()+1)*2*sizeof(PgfText*)); if (res == NULL) throw pgf_systemerror(ENOMEM); size_t pos = 0; - for (size_t i = 0; i < lincat->fields->len; i++) { + for (size_t i = 0; i < lincat->fields.size(); i++) { linearizer.linearize(&out, i); PgfText *text = out.get_text(); if (text != NULL) { - res[pos++] = textdup(&**vector_elem(lincat->fields,i)); + res[pos++] = textdup(&*lincat->fields[i]); res[pos++] = text; } } @@ -2630,13 +2625,13 @@ PgfText **pgf_tabular_linearize_all(PgfDB *db, PgfConcrRevision revision, while (linearizer.resolve()) { ref lincat = linearizer.get_lincat(); res = (PgfText **) - realloc(res, (pos+(lincat->fields->len+1)*2)*sizeof(PgfText*)); - for (size_t i = 0; i < lincat->fields->len; i++) { + realloc(res, (pos+(lincat->fields.size()+1)*2)*sizeof(PgfText*)); + for (size_t i = 0; i < lincat->fields.size(); i++) { linearizer.linearize(&out, i); PgfText *text = out.get_text(); if (text != NULL) { - res[pos++] = textdup(&**vector_elem(lincat->fields, i)); + res[pos++] = textdup(&*lincat->fields[i]); res[pos++] = text; } } @@ -3116,12 +3111,12 @@ pgf_graphviz_lr_automaton(PgfDB *db, PgfConcrRevision revision, PgfPrinter printer(NULL,0,NULL); printer.puts("digraph {\n"); - for (size_t i = 0; i < concr->lrtable->len; i++) { - ref state = vector_elem(concr->lrtable, i); + for (size_t i = 0; i < concr->lrtable.size(); i++) { + ref state = concr->lrtable.elem(i); printer.nprintf(16, " s%zu [label=\"", i); - for (size_t j = 0; j < state->reductions->len; j++) { - ref reduce = vector_elem(state->reductions, j); + for (size_t j = 0; j < state->reductions.size(); j++) { + ref reduce = state->reductions.elem(j); switch (ref::get_tag(reduce->lin_obj)) { case PgfConcrLin::tag: { @@ -3140,8 +3135,8 @@ pgf_graphviz_lr_automaton(PgfDB *db, PgfConcrRevision revision, } printer.puts("["); - for (size_t i = 0; i < reduce->args->len; i++) { - ref arg = vector_elem(reduce->args,i); + for (size_t i = 0; i < reduce->args.size(); i++) { + ref arg = reduce->args.elem(i); if (i > 0) printer.puts(","); if (arg->arg == 0 && arg->stk_idx == 0) { @@ -3159,23 +3154,23 @@ pgf_graphviz_lr_automaton(PgfDB *db, PgfConcrRevision revision, if (i == 0) printer.puts(",penwidth=3"); printer.nprintf(16, "]\n"); - for (size_t j = 0; j < state->shifts->len; j++) { - ref shift = vector_elem(state->shifts, j); + for (size_t j = 0; j < state->shifts.size(); j++) { + ref shift = state->shifts.elem(j); printer.nprintf(16, " s%zu -> s%zu [label=\"", i, shift->next_state); printer.efun(&shift->lincat->name); printer.nprintf(16, ".%zu\"];\n", shift->r); } - for (size_t j = 0; j < state->tokens->len; j++) { - ref shift = vector_elem(state->tokens, j); + for (size_t j = 0; j < state->tokens.size(); j++) { + ref shift = state->tokens.elem(j); printer.nprintf(16, " s%zu -> s%zu [label=\"", i, shift->next_state); size_t sym_idx = shift->sym_idx; - while (sym_idx < shift->seq->syms.len) { - if (ref::get_tag(shift->seq->syms.data[sym_idx]) != PgfSymbolKS::tag) + while (sym_idx < shift->seq->syms.size()) { + if (ref::get_tag(shift->seq->syms[sym_idx]) != PgfSymbolKS::tag) break; if (sym_idx > shift->sym_idx) printer.puts(" "); - auto symks = ref::untagged(shift->seq->syms.data[sym_idx]); + auto symks = ref::untagged(shift->seq->syms[sym_idx]); printer.puts("\\\""); printer.put_esc_str(&symks->token); printer.puts("\\\""); diff --git a/src/runtime/c/pgf/phrasetable.cxx b/src/runtime/c/pgf/phrasetable.cxx index be69b9e7e..49e7c95c7 100644 --- a/src/runtime/c/pgf/phrasetable.cxx +++ b/src/runtime/c/pgf/phrasetable.cxx @@ -164,32 +164,32 @@ void symbol_cmp(PgfSymbol sym1, PgfSymbol sym2, int res[2]) return; for (size_t i = 0; ; i++) { - if (i >= sym_kp1->alts.len) { - res[0] = (res[1] = -(i < sym_kp2->alts.len)); + if (i >= sym_kp1->alts.size()) { + res[0] = (res[1] = -(i < sym_kp2->alts.size())); return; } - if (i >= sym_kp2->alts.len) { + if (i >= sym_kp2->alts.size()) { res[0] = (res[1] = 1); return; } - res[0] = (res[1] = sequence_cmp(sym_kp1->alts.data[i].form, sym_kp2->alts.data[i].form)); + res[0] = (res[1] = sequence_cmp(sym_kp1->alts[i].form, sym_kp2->alts[i].form)); if (res[0] != 0) return; - ref>> prefixes1 = sym_kp1->alts.data[i].prefixes; - ref>> prefixes2 = sym_kp2->alts.data[i].prefixes; + vector> prefixes1 = sym_kp1->alts[i].prefixes; + vector> prefixes2 = sym_kp2->alts[i].prefixes; for (size_t j = 0; ; j++) { - if (j >= prefixes1->len) { - res[0] = (res[1] = -(j < prefixes2->len)); + if (j >= prefixes1.size()) { + res[0] = (res[1] = -(j < prefixes2.size())); return; } - if (j >= prefixes2->len) { + if (j >= prefixes2.size()) { res[0] = (res[1] = 1); return; } - res[0] = (res[1] = textcmp(&(**vector_elem(prefixes1, j)), &(**vector_elem(prefixes2, j)))); + res[0] = (res[1] = textcmp(&*prefixes1[j], &*prefixes2[j])); if (res[0] != 0) return; } @@ -212,15 +212,15 @@ int sequence_cmp(ref seq1, ref seq2) { int res[2] = {0,0}; for (size_t i = 0; ; i++) { - if (i >= seq1->syms.len) { - if (i < seq2->syms.len) + if (i >= seq1->syms.size()) { + if (i < seq2->syms.size()) return -1; return res[1]; } - if (i >= seq2->syms.len) + if (i >= seq2->syms.size()) return 1; - symbol_cmp(seq1->syms.data[i], seq2->syms.data[i], res); + symbol_cmp(seq1->syms[i], seq2->syms[i], res); if (res[0] != 0) return res[0]; } @@ -239,8 +239,8 @@ int text_sequence_cmp(PgfTextSpot *spot, const uint8_t *end, const uint8_t *e2 = NULL; uint8_t t = 0xff; - if (*p_i < seq->syms.len) { - t = ref::get_tag(seq->syms.data[*p_i]); + if (*p_i < seq->syms.size()) { + t = ref::get_tag(seq->syms[*p_i]); } size_t count = 0; @@ -279,14 +279,14 @@ int text_sequence_cmp(PgfTextSpot *spot, const uint8_t *end, return ((int) PgfSymbolKS::tag) - ((int) t); } - auto sym_ks = ref::untagged(seq->syms.data[*p_i]); + auto sym_ks = ref::untagged(seq->syms[*p_i]); s2 = (uint8_t *) &sym_ks->token.text; e2 = s2+sym_ks->token.size; (*p_i)++; t = 0xff; - if (*p_i < seq->syms.len) { - t = ref::get_tag(seq->syms.data[*p_i]); + if (*p_i < seq->syms.size()) { + t = ref::get_tag(seq->syms[*p_i]); } } @@ -317,16 +317,15 @@ void phrasetable_add_backref(ref entry, txn_t txn_id, object container, size_t seq_index) { - ref> backrefs = entry->backrefs; + vector backrefs = entry->backrefs; - size_t len = (backrefs != 0) ? backrefs->len : 0; + size_t len = (backrefs != 0) ? backrefs.size() : 0; if (entry->n_backrefs >= len) { size_t new_len = get_next_padovan(entry->n_backrefs+1); - backrefs = PgfDB::realloc>(backrefs,len*sizeof(PgfSequenceBackref),new_len*sizeof(PgfSequenceBackref),txn_id); - backrefs->len = new_len; + backrefs = backrefs.realloc(new_len, txn_id); } - backrefs->data[entry->n_backrefs].container = container; - backrefs->data[entry->n_backrefs].seq_index = seq_index; + backrefs[entry->n_backrefs].container = container; + backrefs[entry->n_backrefs].seq_index = seq_index; entry->n_backrefs++; entry->backrefs = backrefs; @@ -344,9 +343,9 @@ PgfPhrasetable phrasetable_internalize(PgfPhrasetable table, PgfPhrasetableEntry entry; entry.seq = seq; entry.n_backrefs = 1; - entry.backrefs = vector_new(1); - entry.backrefs->data[0].container = container; - entry.backrefs->data[0].seq_index = seq_index; + entry.backrefs = vector::alloc(1); + entry.backrefs[0].container = container; + entry.backrefs[0].seq_index = seq_index; PgfPhrasetable new_table = Node::new_node(entry); *pentry = ref::from_ptr(&new_table->value); return new_table; @@ -427,16 +426,14 @@ PgfPhrasetable phrasetable_delete(PgfPhrasetable table, table = Node::upd_node(table,table->left,right); return Node::balanceL(table); } else { - size_t len = table->value.backrefs->len; + size_t len = table->value.backrefs.size(); size_t n_backrefs = table->value.n_backrefs; if (n_backrefs > 1) { - ref> backrefs = - PgfDB::realloc>(table->value.backrefs,len*sizeof(PgfSequenceBackref),n_backrefs*sizeof(PgfSequenceBackref),table->txn_id); - backrefs->len = n_backrefs; + vector backrefs = + table->value.backrefs.realloc(n_backrefs,table->txn_id); size_t i = 0; while (i < n_backrefs) { - ref backref = - vector_elem(backrefs, i); + ref backref = backrefs.elem(i); if (backref->container == container && backref->seq_index == seq_index) { break; @@ -445,7 +442,7 @@ PgfPhrasetable phrasetable_delete(PgfPhrasetable table, } i++; while (i < n_backrefs) { - *vector_elem(backrefs, i-1) = *vector_elem(table->value.backrefs, i); + backrefs[i-1] = table->value.backrefs[i]; i++; } n_backrefs--; @@ -457,7 +454,7 @@ PgfPhrasetable phrasetable_delete(PgfPhrasetable table, return new_table; } else { PgfSequence::release(table->value.seq); - Vector::release(table->value.backrefs); + vector::release(table->value.backrefs); if (table->left == 0) { Node::release(table); return table->right; @@ -509,11 +506,11 @@ void phrasetable_lookup(PgfPhrasetable table, } else { auto backrefs = table->value.backrefs; for (size_t i = 0; i < table->value.n_backrefs; i++) { - PgfSequenceBackref backref = *vector_elem(backrefs,i); + PgfSequenceBackref backref = backrefs[i]; switch (ref::get_tag(backref.container)) { case PgfConcrLin::tag: { ref lin = ref::untagged(backref.container); - if (lin->absfun->type->hypos->len == 0) { + if (lin->absfun->type->hypos.size() == 0) { scanner->match(lin, backref.seq_index, err); if (err->type != PGF_EXN_NONE) return; @@ -651,11 +648,11 @@ void phrasetable_lookup_prefixes(PgfCohortsState *state, state->queue.push(current); for (size_t i = 0; i < table->value.n_backrefs; i++) { - PgfSequenceBackref backref = *vector_elem(backrefs,i); + PgfSequenceBackref backref = backrefs[i]; switch (ref::get_tag(backref.container)) { case PgfConcrLin::tag: { ref lin = ref::untagged(backref.container); - if (lin->absfun->type->hypos->len == 0) { + if (lin->absfun->type->hypos.size() == 0) { state->scanner->match(lin, backref.seq_index, state->err); @@ -786,7 +783,7 @@ void phrasetable_iter(PgfConcr *concr, if (table->value.backrefs != 0 && res == 0 && callback != 0) { for (size_t i = 0; i < table->value.n_backrefs; i++) { - PgfSequenceBackref backref = *vector_elem(table->value.backrefs,i); + PgfSequenceBackref backref = table->value.backrefs[i]; switch (ref::get_tag(backref.container)) { case PgfConcrLin::tag: { ref lin = ref::untagged(backref.container); @@ -794,7 +791,7 @@ void phrasetable_iter(PgfConcr *concr, namespace_lookup(concr->lincats, &lin->absfun->type->name); if (lincat != 0) { ref field = - *vector_elem(lincat->fields, backref.seq_index % lincat->fields->len); + lincat->fields[backref.seq_index % lincat->fields.size()]; callback->fn(callback, &lin->absfun->name, &*field, lincat->abscat->prob+lin->absfun->prob, err); if (err->type != PGF_EXN_NONE) diff --git a/src/runtime/c/pgf/phrasetable.h b/src/runtime/c/pgf/phrasetable.h index 720716861..eabd74abd 100644 --- a/src/runtime/c/pgf/phrasetable.h +++ b/src/runtime/c/pgf/phrasetable.h @@ -11,7 +11,7 @@ struct PGF_INTERNAL_DECL PgfPhrasetableEntry { // the vector backrefs. On the other hand, backrefs->len tells us // how big buffer we have allocated. size_t n_backrefs; - ref> backrefs; + vector backrefs; }; struct PgfSequenceItor; diff --git a/src/runtime/c/pgf/printer.cxx b/src/runtime/c/pgf/printer.cxx index e185dc335..0add283eb 100644 --- a/src/runtime/c/pgf/printer.cxx +++ b/src/runtime/c/pgf/printer.cxx @@ -499,15 +499,15 @@ void PgfPrinter::lparam(ref lparam) } } -void PgfPrinter::lvar_ranges(ref> vars, size_t *values) +void PgfPrinter::lvar_ranges(vector vars, size_t *values) { puts("{"); - for (size_t i = 0; i < vars->len; i++) { + for (size_t i = 0; i < vars.size(); i++) { if (i > 0) puts(", "); - lvar(vars->data[i].var); + lvar(vars[i].var); if (values == NULL || values[i] == 0) - nprintf(32,"<%ld",vars->data[i].range); + nprintf(32,"<%ld",vars[i].range); else nprintf(32,"=%ld",values[i]-1); } @@ -547,13 +547,13 @@ void PgfPrinter::symbol(PgfSymbol sym) sequence(sym_kp->default_form); - for (size_t i = 0; i < sym_kp->alts.len; i++) { + for (size_t i = 0; i < sym_kp->alts.size(); i++) { puts("; "); - sequence(sym_kp->alts.data[i].form); + sequence(sym_kp->alts[i].form); puts(" /"); - for (size_t j = 0; j < sym_kp->alts.data[i].prefixes->len; j++) { + for (size_t j = 0; j < sym_kp->alts[i].prefixes.size(); j++) { puts(" "); - lstr(sym_kp->alts.data[i].prefixes->data[j]); + lstr(sym_kp->alts[i].prefixes[j]); } } @@ -583,11 +583,11 @@ void PgfPrinter::symbol(PgfSymbol sym) void PgfPrinter::sequence(ref seq) { - for (size_t i = 0; i < seq->syms.len; i++) { + for (size_t i = 0; i < seq->syms.size(); i++) { if (i > 0) puts(" "); - symbol(*vector_elem(&seq->syms, i)); + symbol(seq->syms[i]); } } diff --git a/src/runtime/c/pgf/printer.h b/src/runtime/c/pgf/printer.h index 9d13f202b..9cd209605 100644 --- a/src/runtime/c/pgf/printer.h +++ b/src/runtime/c/pgf/printer.h @@ -78,7 +78,7 @@ class PGF_INTERNAL_DECL PgfPrinter : public PgfUnmarshaller { void parg(ref ty, ref parg); void lvar(size_t var); void lparam(ref lparam); - void lvar_ranges(ref> vars, size_t *values); + void lvar_ranges(vector vars, size_t *values); void seq_id(PgfPhrasetableIds *seq_ids, ref seq); void symbol(PgfSymbol sym); void sequence(ref seq); diff --git a/src/runtime/c/pgf/probspace.cxx b/src/runtime/c/pgf/probspace.cxx index 920f1caa5..19ed03d56 100644 --- a/src/runtime/c/pgf/probspace.cxx +++ b/src/runtime/c/pgf/probspace.cxx @@ -49,8 +49,8 @@ PgfProbspace probspace_insert(PgfProbspace space, ref fun, ref type) { - for (size_t i = 0; i < type->hypos->len; i++) { - ref hypo = vector_elem(type->hypos,i); + for (size_t i = 0; i < type->hypos.size(); i++) { + ref hypo = type->hypos.elem(i); space = probspace_insert(space,fun,hypo->type); } @@ -113,8 +113,8 @@ PgfProbspace probspace_delete(PgfProbspace space, ref fun, ref type) { - for (size_t i = 0; i < type->hypos->len; i++) { - ref hypo = vector_elem(type->hypos,i); + for (size_t i = 0; i < type->hypos.size(); i++) { + ref hypo = type->hypos.elem(i); space = probspace_delete(space,fun,hypo->type); } diff --git a/src/runtime/c/pgf/reader.cxx b/src/runtime/c/pgf/reader.cxx index 387ac2b32..3c1294254 100644 --- a/src/runtime/c/pgf/reader.cxx +++ b/src/runtime/c/pgf/reader.cxx @@ -151,23 +151,23 @@ void PgfReader::merge_namespace(ref (PgfReader::*read_value)()) } template -ref PgfReader::read_vector(Vector C::* field, void (PgfReader::*read_value)(ref val)) +ref PgfReader::read_vector(inline_vector C::* field, void (PgfReader::*read_value)(ref val)) { size_t len = read_len(); - ref loc = vector_new(field,len); + ref loc = inline_vector::alloc(field,len); for (size_t i = 0; i < len; i++) { - (this->*read_value)(vector_elem(ref>::from_ptr(&(loc->*field)),i)); + (this->*read_value)(loc->*field.elem(i)); } return loc; } template -ref> PgfReader::read_vector(void (PgfReader::*read_value)(ref val)) +vector PgfReader::read_vector(void (PgfReader::*read_value)(ref val)) { size_t len = read_len(); - ref> vec = vector_new(len); + vector vec = vector::alloc(len); for (size_t i = 0; i < len; i++) { - (this->*read_value)(vector_elem(vec,i)); + (this->*read_value)(vec.elem(i)); } return vec; } @@ -374,13 +374,13 @@ struct PGF_INTERNAL_DECL PgfAbsCatCounts }; static -PgfAbsCatCounts *find_counts(Vector *cats, PgfText *name) +PgfAbsCatCounts *find_counts(PgfAbsCatCounts *cats, size_t n_cats, PgfText *name) { size_t i = 0; - size_t j = cats->len-1; + size_t j = n_cats-1; while (i <= j) { size_t k = (i+j)/2; - PgfAbsCatCounts *counts = &cats->data[k]; + PgfAbsCatCounts *counts = &cats[k]; int cmp = textcmp(name, counts->name); if (cmp < 0) { j = k-1; @@ -410,12 +410,13 @@ void PgfReader::read_abstract(ref abstract) abstract->cats = cats; if (probs_callback != NULL) { - Vector *cats = namespace_to_sorted_names(abstract->cats); + PgfAbsCatCounts *cats = namespace_to_sorted_names(abstract->cats); + size_t n_cats = namespace_size(abstract->cats); std::function)> collect_counts = - [cats](ref absfun) { + [cats,n_cats](ref absfun) { PgfAbsCatCounts *counts = - find_counts(cats, &absfun->type->name); + find_counts(cats, n_cats, &absfun->type->name); if (counts != NULL) { if (isnan(absfun->prob)) { counts->n_nan_probs++; @@ -427,16 +428,15 @@ void PgfReader::read_abstract(ref abstract) }; namespace_iter(abstract->funs, collect_counts); - for (size_t i = 0; i < cats->len; i++) { - PgfAbsCatCounts *counts = &cats->data[i]; - counts->prob = - logf((1-counts->probs_sum) / counts->n_nan_probs); + for (size_t i = 0; i < n_cats; i++) { + cats[i].prob = - logf((1-cats[i].probs_sum) / cats[i].n_nan_probs); } std::function)> pad_probs = - [cats](ref absfun) { + [cats, n_cats](ref absfun) { if (isnan(absfun->prob)) { PgfAbsCatCounts *counts = - find_counts(cats, &absfun->type->name); + find_counts(cats, n_cats, &absfun->type->name); if (counts != NULL) { absfun->prob = counts->prob; } @@ -494,12 +494,12 @@ void PgfReader::read_parg(ref parg) ref PgfReader::read_presult() { - ref> vars = 0; + vector vars = 0; size_t n_vars = read_len(); if (n_vars > 0) { - vars = vector_new(n_vars); + vars = vector::alloc(n_vars); for (size_t i = 0; i < n_vars; i++) { - read_variable_range(vector_elem(vars,i)); + read_variable_range(vars.elem(i)); } } @@ -569,15 +569,14 @@ PgfSymbol PgfReader::read_symbol() } case PgfSymbolKP::tag: { size_t n_alts = read_len(); - ref sym_kp = PgfDB::malloc(n_alts*sizeof(PgfAlternative)); - sym_kp->alts.len = n_alts; + ref sym_kp = inline_vector::alloc(&PgfSymbolKP::alts,n_alts); for (size_t i = 0; i < n_alts; i++) { auto form = read_seq(); auto prefixes = read_vector(&PgfReader::read_text2); - sym_kp->alts.data[i].form = form; - sym_kp->alts.data[i].prefixes = prefixes; + sym_kp->alts[i].form = form; + sym_kp->alts[i].prefixes = prefixes; } auto default_form = read_seq(); @@ -621,21 +620,20 @@ ref PgfReader::read_seq() { size_t n_syms = read_len(); - ref seq = PgfDB::malloc(n_syms*sizeof(PgfSymbol)); - seq->syms.len = n_syms; + ref seq = inline_vector::alloc(&PgfSequence::syms, n_syms); for (size_t i = 0; i < n_syms; i++) { PgfSymbol sym = read_symbol(); - *vector_elem(&seq->syms,i) = sym; + seq->syms[i] = sym; } return seq; } -ref>> PgfReader::read_seq_ids(object container) +vector> PgfReader::read_seq_ids(object container) { size_t len = read_len(); - ref>> vec = vector_new>(len); + vector> vec = vector>::alloc(len); for (size_t i = 0; i < len; i++) { size_t seq_id = read_len(); ref seq = phrasetable_relink(concrete->phrasetable, @@ -644,7 +642,7 @@ ref>> PgfReader::read_seq_ids(object container) if (seq == 0) { throw pgf_error("Invalid sequence id"); } - *vector_elem(vec,i) = seq; + vec[i] = seq; } return vec; } @@ -695,13 +693,13 @@ ref PgfReader::read_lincat() return lincat; } -ref>> PgfReader::read_lincat_fields(ref lincat) +vector> PgfReader::read_lincat_fields(ref lincat) { size_t len = read_len(); - ref>> fields = vector_new>(len); + vector> fields = vector>::alloc(len); for (size_t i = 0; i < len; i++) { auto name = read_text(); - *vector_elem(fields,i) = name; + fields[i] = name; } return fields; } diff --git a/src/runtime/c/pgf/reader.h b/src/runtime/c/pgf/reader.h index fc859418a..74902a6a7 100644 --- a/src/runtime/c/pgf/reader.h +++ b/src/runtime/c/pgf/reader.h @@ -49,10 +49,10 @@ class PGF_INTERNAL_DECL PgfReader void merge_namespace(ref (PgfReader::*read_value)()); template - ref read_vector(Vector C::* field, void (PgfReader::*read_value)(ref val)); + ref read_vector(inline_vector C::* field, void (PgfReader::*read_value)(ref val)); template - ref> read_vector(void (PgfReader::*read_value)(ref val)); + vector read_vector(void (PgfReader::*read_value)(ref val)); PgfLiteral read_literal(); PgfExpr read_expr(); @@ -71,14 +71,14 @@ class PGF_INTERNAL_DECL PgfReader void merge_abstract(ref abstract); ref read_lincat(); - ref>> read_lincat_fields(ref lincat); + vector> read_lincat_fields(ref lincat); ref read_lparam(); void read_variable_range(ref var_info); void read_parg(ref parg); ref read_presult(); PgfSymbol read_symbol(); ref read_seq(); - ref>> read_seq_ids(object container); + vector> read_seq_ids(object container); PgfPhrasetable read_phrasetable(size_t len); PgfPhrasetable read_phrasetable(); ref read_lin(); diff --git a/src/runtime/c/pgf/typechecker.cxx b/src/runtime/c/pgf/typechecker.cxx index 379bc44b6..a0e5a3973 100644 --- a/src/runtime/c/pgf/typechecker.cxx +++ b/src/runtime/c/pgf/typechecker.cxx @@ -348,7 +348,7 @@ PgfType PgfTypechecker::Context::dtyp(size_t n_hypos, PgfTypeHypo *hypos, PgfType ty = 0; PgfTypeHypo *new_hypos = (PgfTypeHypo *) alloca(sizeof(PgfTypeHypo)*n_hypos); - size_t n_new_exprs = abscat->context->len; + size_t n_new_exprs = abscat->context.size(); PgfExpr *new_exprs = (PgfExpr *) alloca(sizeof(PgfExpr)*n_new_exprs); @@ -366,7 +366,7 @@ PgfType PgfTypechecker::Context::dtyp(size_t n_hypos, PgfTypeHypo *hypos, size_t i, j; for (i = 0, j = 0; i < n_new_exprs && j < n_exprs; i++) { Unmarshaller1 tu; - PgfHypo *hypo = vector_elem(abscat->context,i); + ref hypo = abscat->context.elem(i); Type *ty = (Type *) tc->db_m.match_type(&tu,hypo->type.as_object()); tc->temps.push_back(ty); Context expr_ctxt(tc,scope,ty,hypo->bind_type); diff --git a/src/runtime/c/pgf/vector.h b/src/runtime/c/pgf/vector.h index cd999f01c..dd86869b6 100644 --- a/src/runtime/c/pgf/vector.h +++ b/src/runtime/c/pgf/vector.h @@ -1,61 +1,71 @@ #ifndef VECTOR_H #define VECTOR_H -template -struct PGF_INTERNAL Vector { +template class vector; + +template class PGF_INTERNAL_DECL inline_vector { +private: size_t len; A data[]; - + public: - static void release(ref vec) { - PgfDB::free(vec, vec->len*sizeof(A)); + class iterator { + public: + object offset; + + iterator(ref r) { + this->offset = r.as_object(); + } + + bool operator!=(iterator other) { + return offset != other.offset; + } + + void operator++() { + offset += sizeof(A); + } + + A &operator*() { + return *((A*) (current_base+offset)); + } + }; + + size_t size() { return len; }; + A &operator[] (size_t i) { return data[i]; }; + ref elem(size_t i) { return ref::from_ptr(&data[i]); }; + iterator begin() { return iterator(ref::from_ptr(&data[0])); } + iterator end() { return iterator(ref::from_ptr(&data[len])); } + + template + static ref alloc(inline_vector C::* field, size_t size) + { + ref res = PgfDB::malloc(size*sizeof(A)).as_object(); + (res->*field).len = size; + return res; } -}; -template inline PGF_INTERNAL -ref> vector_new(size_t len) -{ - ref> res = PgfDB::malloc>(len*sizeof(A)); - res->len = len; - return res; -} - -template inline PGF_INTERNAL -ref vector_new(Vector C::* field, size_t len) -{ - ref res = PgfDB::malloc(len*sizeof(A)).as_object(); - (res->*field).len = len; - return res; -} - -template inline PGF_INTERNAL -ref vector_elem(ref> v, size_t index) -{ - return ref::from_ptr(&v->data[index]); -} - -template inline PGF_INTERNAL -A *vector_elem(Vector *v, size_t index) -{ - return &v->data[index]; -} + template + static void release(inline_vector C::* field, ref o) { + PgfDB::free(o,(o->*field).len*sizeof(A)); + } + + vector as_vector() { return vector(((unsigned char*) this)-current_base); } + + friend class vector; +}; template class PGF_INTERNAL_DECL vector { private: object offset; - struct V { - size_t size; - A data[]; - }; - - V* v() const { return (V*) (current_base+offset); } + inline_vector* v() const { return (inline_vector*) (current_base+offset); } +public: + vector() { } vector(object o) { this->offset = o; } -public: class iterator { public: object offset; @@ -77,18 +87,39 @@ template class PGF_INTERNAL_DECL vector { } }; - size_t size() { return v()->size; }; + size_t size() { return v()->len; }; A &operator[] (size_t i) { return v()->data[i]; }; + ref elem(size_t i) { return ref::from_ptr(&v()->data[i]); }; iterator begin() { return iterator(ref::from_ptr(&v()->data[0])); } - iterator end() { return iterator(ref::from_ptr(&v()->data[v()->size])); } + iterator end() { return iterator(ref::from_ptr(&v()->data[v()->len])); } + + bool operator ==(vector& other) const { return offset==other.as_object(); } + bool operator !=(vector& other) const { return offset!=other.as_object(); } + bool operator ==(object other_offset) const { return offset==other_offset; } + bool operator !=(object other_offset) const { return offset!=other_offset; } + + A *get_data() { + return v()->data; + } static vector alloc(size_t size) { - auto res = PgfDB::malloc::V>(size*sizeof(A)); - res->size = size; + auto res = PgfDB::malloc>(size*sizeof(A)); + res->len = size; return vector(res.as_object()); } -}; + vector realloc(size_t new_size, txn_t txn_id) + { + ref> r = offset; + auto res = PgfDB::realloc>(r,v()->len*sizeof(A),new_size*sizeof(A),txn_id); + res->len = new_size; + return res->as_vector(); + } + + static void release(vector vec) { + PgfDB::free(ref>(vec.offset), vec.v()->len*sizeof(A)); + } +}; #endif // VECTOR_H diff --git a/src/runtime/c/pgf/writer.cxx b/src/runtime/c/pgf/writer.cxx index 3c210793f..dfd881995 100644 --- a/src/runtime/c/pgf/writer.cxx +++ b/src/runtime/c/pgf/writer.cxx @@ -136,11 +136,11 @@ void PgfWriter::write_namespace_helper(Namespace nmsp, void (PgfWriter::*writ } template -void PgfWriter::write_vector(ref> vec, void (PgfWriter::*write_value)(ref val)) +void PgfWriter::write_vector(vector vec, void (PgfWriter::*write_value)(ref val)) { - write_len(vec->len); - for (size_t i = 0; i < vec->len; i++) { - (this->*write_value)(vector_elem(vec,i)); + write_len(vec.size()); + for (size_t i = 0; i < vec.size(); i++) { + (this->*write_value)(vec.elem(i)); } } @@ -338,13 +338,13 @@ void PgfWriter::write_symbol(PgfSymbol sym) } case PgfSymbolKP::tag: { auto sym_kp = ref::untagged(sym); - write_len(sym_kp->alts.len); - for (size_t i = 0; i < sym_kp->alts.len; i++) { - PgfAlternative *alt = vector_elem(&sym_kp->alts, i); - write_vector(ref>::from_ptr(&alt->form->syms), &PgfWriter::write_symbol); + write_len(sym_kp->alts.size()); + for (size_t i = 0; i < sym_kp->alts.size(); i++) { + ref alt = sym_kp->alts.elem(i); + write_vector(alt->form->syms.as_vector(), &PgfWriter::write_symbol); write_vector(alt->prefixes, &PgfWriter::write_text); } - write_vector(ref>::from_ptr(&sym_kp->default_form->syms), &PgfWriter::write_symbol); + write_vector(sym_kp->default_form->syms.as_vector(), &PgfWriter::write_symbol); break; } case PgfSymbolBIND::tag: @@ -362,7 +362,7 @@ void PgfWriter::write_symbol(PgfSymbol sym) void PgfWriter::write_seq(ref seq) { seq_ids.add(seq); - write_vector(ref>::from_ptr(&seq->syms), &PgfWriter::write_symbol); + write_vector(seq->syms.as_vector(), &PgfWriter::write_symbol); } void PgfWriter::write_phrasetable(PgfPhrasetable table) diff --git a/src/runtime/c/pgf/writer.h b/src/runtime/c/pgf/writer.h index 5713ac675..4625f41c1 100644 --- a/src/runtime/c/pgf/writer.h +++ b/src/runtime/c/pgf/writer.h @@ -23,7 +23,7 @@ class PGF_INTERNAL_DECL PgfWriter void write_namespace(Namespace nmsp, void (PgfWriter::*write_value)(ref)); template - void write_vector(ref> vec, void (PgfWriter::*write_value)(ref val)); + void write_vector(vector vec, void (PgfWriter::*write_value)(ref val)); void write_literal(PgfLiteral literal); void write_expr(PgfExpr expr);