tla-ts 0.0.10-dev.094b9b512 → 0.0.10-dev.1ebc153bd
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/compile.cjs +3 -3
- package/dist/compile.js +1 -1
- package/dist/deciders.cjs +37 -36
- package/dist/deciders.js +38 -37
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove-worker.cjs +1 -1
- package/dist/prove-worker.js +1 -1
- package/dist/prove.cjs +146 -58
- package/dist/prove.js +145 -57
- package/dist/run.cjs +43 -43
- package/dist/run.js +45 -45
- package/dist/tlapm.cjs +1 -1
- package/dist/tlapm.js +2 -2
- package/dist/transfer.cjs +40 -37
- package/dist/transfer.js +38 -35
- package/dist/worker.cjs +6 -6
- package/dist/worker.js +6 -6
- package/package.json +1 -1
- package/src/ast.ts +4 -3
- package/src/bags.ts +46 -28
- package/src/check-trace.ts +2 -16
- package/src/check.ts +349 -91
- package/src/cli/runtime-invariants.ts +20 -56
- package/src/cli/tlapm.ts +268 -71
- package/src/cli/tlc-arguments.ts +2 -2
- package/src/cli/tlc-output.ts +4 -5
- package/src/cli/tlc-usage.ts +0 -1
- package/src/cli/tlc.ts +26 -7
- package/src/cli/xml-exporter.ts +1 -1
- package/src/codegen.ts +9 -5
- package/src/dependencies.ts +72 -11
- package/src/dfid.ts +9 -2
- package/src/environment.ts +65 -36
- package/src/errors.ts +8 -1
- package/src/evaluate.ts +92 -32
- package/src/exit-codes.ts +5 -2
- package/src/instances.ts +5 -5
- package/src/java-overrides.ts +2 -2
- package/src/levels.ts +138 -90
- package/src/liveness-checker.ts +572 -204
- package/src/liveness.ts +47 -32
- package/src/obligations/action.ts +0 -2
- package/src/obligations/anonymize.ts +2 -6
- package/src/obligations/equality.ts +0 -2
- package/src/obligations/expression.ts +0 -2
- package/src/obligations/format.ts +0 -2
- package/src/obligations/generate.ts +0 -2
- package/src/obligations/index.ts +9 -8
- package/src/obligations/levels.ts +0 -2
- package/src/obligations/module.ts +0 -2
- package/src/obligations/normalize.ts +1 -6
- package/src/obligations/operators.ts +0 -2
- package/src/obligations/pragma.ts +2 -2
- package/src/obligations/printer.ts +5 -7
- package/src/obligations/proof.ts +0 -2
- package/src/obligations/regroup.ts +0 -2
- package/src/obligations/simplify.ts +0 -2
- package/src/obligations/subexpression.ts +1 -4
- package/src/obligations/substitution.ts +0 -2
- package/src/obligations/temporal.ts +0 -2
- package/src/obligations/tuples.ts +0 -2
- package/src/parallel-worker.ts +8 -2
- package/src/parallel.ts +7 -2
- package/src/parser.ts +256 -185
- package/src/pretty-print.ts +1 -1
- package/src/prover/deciders.ts +1 -8
- package/src/prover/isabelle/encode.ts +0 -2
- package/src/prover/isabelle/isar/attrib.ts +86 -55
- package/src/prover/isabelle/isar/context.ts +25 -26
- package/src/prover/isabelle/isar/induct.ts +2 -12
- package/src/prover/isabelle/isar/method.ts +6 -10
- package/src/prover/isabelle/isar/proof.ts +40 -39
- package/src/prover/isabelle/isar/rule-cases.ts +14 -22
- package/src/prover/isabelle/isar/theory.ts +16 -17
- package/src/prover/isabelle/isar/toplevel.ts +46 -56
- package/src/prover/isabelle/isar/type-check.ts +0 -2
- package/src/prover/isabelle/provers/blast/blast.ts +0 -2
- package/src/prover/isabelle/provers/blast/branch.ts +0 -2
- package/src/prover/isabelle/provers/blast/prove.ts +0 -2
- package/src/prover/isabelle/provers/blast/rules.ts +0 -2
- package/src/prover/isabelle/provers/blast/state.ts +0 -2
- package/src/prover/isabelle/provers/blast/term.ts +0 -2
- package/src/prover/isabelle/provers/clasimp.ts +1 -3
- package/src/prover/isabelle/provers/classical.ts +1 -3
- package/src/prover/isabelle/provers/hypsubst.ts +2 -4
- package/src/prover/isabelle/pure/bicompose.ts +0 -2
- package/src/prover/isabelle/pure/consts.ts +0 -2
- package/src/prover/isabelle/pure/conv.ts +0 -2
- package/src/prover/isabelle/pure/drule.ts +0 -2
- package/src/prover/isabelle/pure/envir.ts +0 -2
- package/src/prover/isabelle/pure/goal.ts +0 -2
- package/src/prover/isabelle/pure/logic.ts +0 -2
- package/src/prover/isabelle/pure/name.ts +0 -2
- package/src/prover/isabelle/pure/net.ts +0 -2
- package/src/prover/isabelle/pure/object-logic.ts +0 -2
- package/src/prover/isabelle/pure/pattern.ts +0 -2
- package/src/prover/isabelle/pure/raw-simplifier.ts +0 -2
- package/src/prover/isabelle/pure/rewriter.ts +3 -5
- package/src/prover/isabelle/pure/search.ts +0 -2
- package/src/prover/isabelle/pure/seq.ts +0 -2
- package/src/prover/isabelle/pure/simplifier.ts +0 -2
- package/src/prover/isabelle/pure/table.ts +0 -2
- package/src/prover/isabelle/pure/tactic.ts +0 -2
- package/src/prover/isabelle/pure/tactical.ts +0 -2
- package/src/prover/isabelle/pure/term-ord.ts +0 -2
- package/src/prover/isabelle/pure/term.ts +3 -5
- package/src/prover/isabelle/pure/thm.ts +0 -2
- package/src/prover/isabelle/pure/type.ts +0 -2
- package/src/prover/isabelle/pure/unify.ts +0 -2
- package/src/prover/isabelle/pure/variable.ts +0 -2
- package/src/prover/isabelle/tla/classical-setup.ts +0 -2
- package/src/prover/isabelle/tla/simpdata.ts +0 -2
- package/src/prover/isabelle/tools/intuitionistic.ts +0 -2
- package/src/prover/ocaml.ts +4 -1
- package/src/prover/prep/action.ts +1 -0
- package/src/prover/prep/md5.ts +26 -29
- package/src/prover/prep/methods.ts +55 -6
- package/src/prover/prep/normalize.ts +4 -1
- package/src/prover/prove.ts +58 -32
- package/src/prover/ptl/decide.ts +43 -63
- package/src/prover/smt/context.ts +10 -14
- package/src/prover/smt/data.ts +51 -45
- package/src/prover/smt/encode.ts +1 -2
- package/src/prover/smt/rewrite.ts +3 -7
- package/src/prover/smt/simplify.ts +1 -1
- package/src/prover/smt/solver/ackermannize-bv-tactic.ts +0 -2
- package/src/prover/smt/solver/ackr-helper.ts +0 -3
- package/src/prover/smt/solver/ackr-model-converter.ts +1 -8
- package/src/prover/smt/solver/act-cache.ts +0 -1
- package/src/prover/smt/solver/add-bounds-tactic.ts +0 -1
- package/src/prover/smt/solver/aig-tactic.ts +25 -16
- package/src/prover/smt/solver/aig.ts +2 -3
- package/src/prover/smt/solver/arith-rewriter.ts +4 -7
- package/src/prover/smt/solver/arith-terms.ts +0 -2
- package/src/prover/smt/solver/array-decl-plugin.ts +0 -1
- package/src/prover/smt/solver/array-rewriter.ts +1 -4
- package/src/prover/smt/solver/asserted-formulas.ts +67 -3
- package/src/prover/smt/solver/ast-lt.ts +2 -3
- package/src/prover/smt/solver/ast-util.ts +4 -5
- package/src/prover/smt/solver/ast.ts +171 -168
- package/src/prover/smt/solver/auf-solver.ts +0 -1
- package/src/prover/smt/solver/bit-blast-tactic.ts +2 -11
- package/src/prover/smt/solver/bit-blaster.ts +0 -3
- package/src/prover/smt/solver/blast-term-ite.ts +47 -0
- package/src/prover/smt/solver/bound-manager.ts +39 -29
- package/src/prover/smt/solver/bound-simplifier.ts +2 -5
- package/src/prover/smt/solver/bv-bound-chk.ts +2 -10
- package/src/prover/smt/solver/bv-decl-plugin.ts +13 -11
- package/src/prover/smt/solver/bv-divrem-bounds.ts +0 -2
- package/src/prover/smt/solver/bv-rewriter.ts +15 -19
- package/src/prover/smt/solver/bv1-blast.ts +1 -11
- package/src/prover/smt/solver/bv2fpa-converter.ts +0 -1
- package/src/prover/smt/solver/bv2int-rewriter.ts +0 -1
- package/src/prover/smt/solver/bv2real-rewriter.ts +0 -1
- package/src/prover/smt/solver/card2bv.ts +3 -7
- package/src/prover/smt/solver/case-split-queue.ts +0 -2
- package/src/prover/smt/solver/cg-table.ts +19 -16
- package/src/prover/smt/solver/check-logic.ts +6 -2
- package/src/prover/smt/solver/clause.ts +0 -1
- package/src/prover/smt/solver/cofactor-elim-term-ite.ts +2 -5
- package/src/prover/smt/solver/conflict-resolution.ts +8 -8
- package/src/prover/smt/solver/context.ts +45 -15
- package/src/prover/smt/solver/ctx-simplify.ts +1 -3
- package/src/prover/smt/solver/ctx-solver-simplify.ts +0 -2
- package/src/prover/smt/solver/datatype-decl-plugin.ts +22 -17
- package/src/prover/smt/solver/datatype-rewriter.ts +0 -1
- package/src/prover/smt/solver/demodulator.ts +2 -5
- package/src/prover/smt/solver/dependent-expr-state.ts +25 -7
- package/src/prover/smt/solver/der.ts +0 -1
- package/src/prover/smt/solver/diff-neq.ts +1 -3
- package/src/prover/smt/solver/distribute-forall.ts +1 -11
- package/src/prover/smt/solver/dom-simplify.ts +1 -3
- package/src/prover/smt/solver/dt2bv-tactic.ts +2 -9
- package/src/prover/smt/solver/dyn-ack.ts +0 -1
- package/src/prover/smt/solver/e-matching.ts +6 -7
- package/src/prover/smt/solver/elim-small-bv-tactic.ts +0 -1
- package/src/prover/smt/solver/elim-term-ite-tactic.ts +48 -0
- package/src/prover/smt/solver/elim-uncnstr.ts +7 -23
- package/src/prover/smt/solver/enode.ts +16 -10
- package/src/prover/smt/solver/eq2bv-tactic.ts +0 -1
- package/src/prover/smt/solver/euf/arith-axioms.ts +0 -1
- package/src/prover/smt/solver/euf/arith-internalize.ts +2 -8
- package/src/prover/smt/solver/euf/arith-solver.ts +0 -6
- package/src/prover/smt/solver/euf/array-axioms.ts +0 -1
- package/src/prover/smt/solver/euf/array-internalize.ts +21 -12
- package/src/prover/smt/solver/euf/array-solver.ts +0 -2
- package/src/prover/smt/solver/euf/bv-ackerman.ts +0 -2
- package/src/prover/smt/solver/euf/bv-internalize.ts +1 -3
- package/src/prover/smt/solver/euf/bv-solver.ts +0 -2
- package/src/prover/smt/solver/euf/dt-solver.ts +19 -21
- package/src/prover/smt/solver/euf/egraph.ts +69 -53
- package/src/prover/smt/solver/euf/euf-solver.ts +38 -37
- package/src/prover/smt/solver/euf/fpa-solver.ts +37 -53
- package/src/prover/smt/solver/euf/mam.ts +7 -55
- package/src/prover/smt/solver/euf/q-ematch.ts +27 -98
- package/src/prover/smt/solver/euf/q-mbi.ts +4 -4
- package/src/prover/smt/solver/euf/q-model-fixer.ts +1 -4
- package/src/prover/smt/solver/euf/q-solver.ts +3 -3
- package/src/prover/smt/solver/euf/th-solver.ts +1 -16
- package/src/prover/smt/solver/euf/th-solvers.ts +0 -1
- package/src/prover/smt/solver/expr-ref.ts +0 -1
- package/src/prover/smt/solver/expr-safe-replace.ts +0 -1
- package/src/prover/smt/solver/expr2polynomial.ts +204 -80
- package/src/prover/smt/solver/factor.ts +37 -26
- package/src/prover/smt/solver/fd-solver.ts +3 -5
- package/src/prover/smt/solver/fingerprints.ts +0 -1
- package/src/prover/smt/solver/fix-dl-var.ts +2 -4
- package/src/prover/smt/solver/flat-literals.ts +0 -1
- package/src/prover/smt/solver/fm-tactic.ts +25 -14
- package/src/prover/smt/solver/fpa-decl-plugin.ts +0 -1
- package/src/prover/smt/solver/fpa-rewriter.ts +12 -14
- package/src/prover/smt/solver/fpa2bv-converter.ts +13 -8
- package/src/prover/smt/solver/fpa2bv-rewriter.ts +1 -1
- package/src/prover/smt/solver/fpa2bv-tactic.ts +1 -3
- package/src/prover/smt/solver/goal.ts +6 -4
- package/src/prover/smt/solver/goal2nlsat.ts +57 -32
- package/src/prover/smt/solver/guard-set.ts +0 -1
- package/src/prover/smt/solver/hash.ts +0 -1
- package/src/prover/smt/solver/hashtable.ts +4 -1
- package/src/prover/smt/solver/inf-eps.ts +1 -2
- package/src/prover/smt/solver/inj-axiom.ts +0 -1
- package/src/prover/smt/solver/internalizer.ts +41 -3
- package/src/prover/smt/solver/lackr.ts +0 -2
- package/src/prover/smt/solver/lbool.ts +0 -1
- package/src/prover/smt/solver/lia2card.ts +1 -2
- package/src/prover/smt/solver/lia2pb.ts +18 -5
- package/src/prover/smt/solver/literal.ts +0 -1
- package/src/prover/smt/solver/logic-tactics.ts +9 -6
- package/src/prover/smt/solver/lp/bound-propagator.ts +0 -1
- package/src/prover/smt/solver/lp/constraints.ts +0 -1
- package/src/prover/smt/solver/lp/containers.ts +7 -2
- package/src/prover/smt/solver/lp/core-solver.ts +0 -3
- package/src/prover/smt/solver/lp/cross-nested.ts +1 -4
- package/src/prover/smt/solver/lp/dep-intervals.ts +0 -3
- package/src/prover/smt/solver/lp/dependency.ts +0 -2
- package/src/prover/smt/solver/lp/dioph-eq.ts +0 -2
- package/src/prover/smt/solver/lp/explanation.ts +0 -1
- package/src/prover/smt/solver/lp/gomory.ts +0 -1
- package/src/prover/smt/solver/lp/hnf-cutter.ts +0 -1
- package/src/prover/smt/solver/lp/hnf.ts +0 -3
- package/src/prover/smt/solver/lp/int-cube.ts +0 -1
- package/src/prover/smt/solver/lp/int-solver.ts +0 -2
- package/src/prover/smt/solver/lp/lar-solver.ts +1 -2
- package/src/prover/smt/solver/lp/lar-term.ts +0 -1
- package/src/prover/smt/solver/lp/lp-settings.ts +1 -2
- package/src/prover/smt/solver/lp/maximize-term.ts +0 -3
- package/src/prover/smt/solver/lp/nex-creator.ts +3 -3
- package/src/prover/smt/solver/lp/nex.ts +2 -2
- package/src/prover/smt/solver/lp/nla-backoff.ts +0 -2
- package/src/prover/smt/solver/lp/nla-basics.ts +46 -3
- package/src/prover/smt/solver/lp/nla-core.ts +26 -7
- package/src/prover/smt/solver/lp/nla-divisions.ts +0 -2
- package/src/prover/smt/solver/lp/nla-emonics.ts +0 -1
- package/src/prover/smt/solver/lp/nla-factorization.ts +0 -1
- package/src/prover/smt/solver/lp/nla-grobner.ts +158 -82
- package/src/prover/smt/solver/lp/nla-horner.ts +0 -2
- package/src/prover/smt/solver/lp/nla-intervals.ts +0 -1
- package/src/prover/smt/solver/lp/nla-monomial-bounds.ts +0 -2
- package/src/prover/smt/solver/lp/nla-monotone.ts +0 -1
- package/src/prover/smt/solver/lp/nla-order.ts +0 -2
- package/src/prover/smt/solver/lp/nla-patcher.ts +0 -1
- package/src/prover/smt/solver/lp/nla-powers.ts +144 -108
- package/src/prover/smt/solver/lp/nla-tangents.ts +0 -2
- package/src/prover/smt/solver/lp/nla-throttle.ts +0 -1
- package/src/prover/smt/solver/lp/nla-transcendentals.ts +50 -19
- package/src/prover/smt/solver/lp/nla-types.ts +0 -2
- package/src/prover/smt/solver/lp/nla-var-eqs.ts +0 -1
- package/src/prover/smt/solver/lp/nra-solver.ts +138 -97
- package/src/prover/smt/solver/lp/numeric-pair.ts +0 -1
- package/src/prover/smt/solver/lp/pdd-interval.ts +6 -3
- package/src/prover/smt/solver/lp/pdd-simplifier.ts +60 -21
- package/src/prover/smt/solver/lp/pdd-solver.ts +72 -41
- package/src/prover/smt/solver/lp/pdd.ts +725 -290
- package/src/prover/smt/solver/lp/random-updater.ts +0 -2
- package/src/prover/smt/solver/lp/static-matrix.ts +0 -1
- package/src/prover/smt/solver/lp/union-find.ts +1 -2
- package/src/prover/smt/solver/macro-finder.ts +1 -4
- package/src/prover/smt/solver/mam-compiler.ts +14 -15
- package/src/prover/smt/solver/mam-interpreter.ts +0 -1
- package/src/prover/smt/solver/max-bv-sharing-tactic.ts +1 -13
- package/src/prover/smt/solver/max-cliques.ts +0 -2
- package/src/prover/smt/solver/maxcore.ts +6 -15
- package/src/prover/smt/solver/maximize-ac-sharing.ts +0 -2
- package/src/prover/smt/solver/maxlex.ts +0 -8
- package/src/prover/smt/solver/maxsmt-base.ts +7 -1
- package/src/prover/smt/solver/maxsmt.ts +0 -1
- package/src/prover/smt/solver/mbp/mbp-arith.ts +2 -12
- package/src/prover/smt/solver/mbp/mbp-basic-tg.ts +0 -1
- package/src/prover/smt/solver/mbp/mbp-plugin.ts +10 -3
- package/src/prover/smt/solver/mbp/mbp-qel.ts +0 -1
- package/src/prover/smt/solver/mbp/mbp-solve-plugin.ts +1 -10
- package/src/prover/smt/solver/mbp/mbp-term-graph.ts +1 -19
- package/src/prover/smt/solver/model-based-opt.ts +1 -2
- package/src/prover/smt/solver/model-checker.ts +2 -3
- package/src/prover/smt/solver/model-evaluator.ts +9 -6
- package/src/prover/smt/solver/model-finder.ts +0 -1
- package/src/prover/smt/solver/model-generator.ts +3 -2
- package/src/prover/smt/solver/model-macro-solver.ts +3 -4
- package/src/prover/smt/solver/model-printer.ts +0 -1
- package/src/prover/smt/solver/mpf.ts +2 -5
- package/src/prover/smt/solver/mus.ts +2 -4
- package/src/prover/smt/solver/muz/dl-context.ts +67 -19
- package/src/prover/smt/solver/muz/dl-mk-bit-blast.ts +0 -1
- package/src/prover/smt/solver/muz/dl-mk-coi-filter.ts +68 -22
- package/src/prover/smt/solver/muz/dl-mk-elim-term-ite.ts +7 -3
- package/src/prover/smt/solver/muz/dl-mk-interp-tail-simplifier.ts +0 -6
- package/src/prover/smt/solver/muz/dl-mk-rule-inliner.ts +39 -11
- package/src/prover/smt/solver/muz/dl-mk-slice.ts +78 -16
- package/src/prover/smt/solver/muz/dl-mk-subsumption-checker.ts +9 -4
- package/src/prover/smt/solver/muz/dl-rule-set.ts +0 -30
- package/src/prover/smt/solver/muz/dl-rule-transformer.ts +0 -4
- package/src/prover/smt/solver/muz/dl-rule.ts +93 -57
- package/src/prover/smt/solver/muz/hnf.ts +6 -6
- package/src/prover/smt/solver/muz/horn-subsume-model-converter.ts +176 -0
- package/src/prover/smt/solver/muz/horn-tactic.ts +15 -6
- package/src/prover/smt/solver/muz/rule-properties.ts +195 -37
- package/src/prover/smt/solver/muz/spacer-context.ts +111 -102
- package/src/prover/smt/solver/muz/spacer-dl-interface.ts +15 -4
- package/src/prover/smt/solver/muz/spacer-generalizers.ts +0 -3
- package/src/prover/smt/solver/muz/spacer-manager.ts +0 -6
- package/src/prover/smt/solver/muz/spacer-pdr.ts +4 -4
- package/src/prover/smt/solver/muz/spacer-prop-solver.ts +4 -15
- package/src/prover/smt/solver/muz/spacer-util.ts +2 -29
- package/src/prover/smt/solver/muz/substitution.ts +88 -39
- package/src/prover/smt/solver/nla2bv-tactic.ts +0 -1
- package/src/prover/smt/solver/nlqsat.ts +5 -5
- package/src/prover/smt/solver/nlsat/algebraic.ts +197 -96
- package/src/prover/smt/solver/nlsat/atoms.ts +52 -35
- package/src/prover/smt/solver/nlsat/evaluator.ts +0 -1
- package/src/prover/smt/solver/nlsat/explain.ts +379 -217
- package/src/prover/smt/solver/nlsat/interval-set.ts +0 -1
- package/src/prover/smt/solver/nlsat/levelwise.ts +460 -241
- package/src/prover/smt/solver/nlsat/mpbq.ts +0 -1
- package/src/prover/smt/solver/nlsat/polynomial.ts +2366 -683
- package/src/prover/smt/solver/nlsat/solver.ts +118 -105
- package/src/prover/smt/solver/nlsat/transcendental-eval.ts +2 -3
- package/src/prover/smt/solver/nlsat/transcendentals.ts +41 -19
- package/src/prover/smt/solver/nlsat/types.ts +0 -2
- package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +8 -7
- package/src/prover/smt/solver/nlsat/upolynomial.ts +41 -20
- package/src/prover/smt/solver/nlsat-tactic.ts +1 -2
- package/src/prover/smt/solver/nnf.ts +6 -3
- package/src/prover/smt/solver/normalize-bounds.ts +0 -1
- package/src/prover/smt/solver/occf.ts +0 -1
- package/src/prover/smt/solver/opt-context.ts +19 -13
- package/src/prover/smt/solver/opt-nlsat.ts +97 -77
- package/src/prover/smt/solver/opt-pareto.ts +0 -2
- package/src/prover/smt/solver/opt-preprocess.ts +1 -2
- package/src/prover/smt/solver/opt-solver.ts +22 -11
- package/src/prover/smt/solver/opt-value.ts +0 -1
- package/src/prover/smt/solver/optsmt.ts +13 -12
- package/src/prover/smt/solver/parallel-tactic.ts +0 -2
- package/src/prover/smt/solver/pattern-inference.ts +2 -3
- package/src/prover/smt/solver/pb-rewriter.ts +15 -30
- package/src/prover/smt/solver/pb2bv-tactic.ts +0 -2
- package/src/prover/smt/solver/poly-rewriter.ts +76 -21
- package/src/prover/smt/solver/probes.ts +91 -28
- package/src/prover/smt/solver/propagate-values.ts +4 -1
- package/src/prover/smt/solver/proto-model.ts +9 -12
- package/src/prover/smt/solver/pull-quant.ts +0 -1
- package/src/prover/smt/solver/purify-arith.ts +50 -16
- package/src/prover/smt/solver/qe-arith-plugin.ts +4 -7
- package/src/prover/smt/solver/qe-lite-der.ts +0 -1
- package/src/prover/smt/solver/qe-lite-fm.ts +0 -1
- package/src/prover/smt/solver/qe-lite.ts +2 -3
- package/src/prover/smt/solver/qe-mbp.ts +13 -24
- package/src/prover/smt/solver/qe.ts +48 -57
- package/src/prover/smt/solver/qel.ts +0 -1
- package/src/prover/smt/solver/qi-queue.ts +0 -1
- package/src/prover/smt/solver/qsat.ts +71 -97
- package/src/prover/smt/solver/quant-hoist.ts +2 -1
- package/src/prover/smt/solver/quant-tactics.ts +0 -1
- package/src/prover/smt/solver/quantifier-analyzer.ts +9 -10
- package/src/prover/smt/solver/quantifier-manager.ts +14 -10
- package/src/prover/smt/solver/quasi-macros.ts +9 -20
- package/src/prover/smt/solver/random-gen.ts +0 -1
- package/src/prover/smt/solver/rational.ts +17 -1
- package/src/prover/smt/solver/recfun-decl-plugin.ts +35 -21
- package/src/prover/smt/solver/recfun-rewriter.ts +1 -2
- package/src/prover/smt/solver/reduce-args.ts +0 -1
- package/src/prover/smt/solver/reduce-bv-size.ts +0 -1
- package/src/prover/smt/solver/ref-vector.ts +0 -1
- package/src/prover/smt/solver/relevancy.ts +0 -1
- package/src/prover/smt/solver/rewriter-tpl.ts +6 -3
- package/src/prover/smt/solver/rewriter.ts +1 -2
- package/src/prover/smt/solver/rlimit.ts +17 -1
- package/src/prover/smt/solver/sat/asymm-branch.ts +59 -48
- package/src/prover/smt/solver/sat/big.ts +0 -1
- package/src/prover/smt/solver/sat/clause-use-list.ts +0 -8
- package/src/prover/smt/solver/sat/clause.ts +2 -20
- package/src/prover/smt/solver/sat/cleaner.ts +0 -2
- package/src/prover/smt/solver/sat/config.ts +6 -9
- package/src/prover/smt/solver/sat/consequences.ts +1 -2
- package/src/prover/smt/solver/sat/elim-eqs.ts +0 -2
- package/src/prover/smt/solver/sat/goal2sat.ts +1 -3
- package/src/prover/smt/solver/sat/inc-sat-solver.ts +30 -15
- package/src/prover/smt/solver/sat/model-converter.ts +2 -22
- package/src/prover/smt/solver/sat/pb-constraint.ts +0 -3
- package/src/prover/smt/solver/sat/pb-solver.ts +50 -26
- package/src/prover/smt/solver/sat/probing.ts +22 -21
- package/src/prover/smt/solver/sat/sat-tactic.ts +4 -4
- package/src/prover/smt/solver/sat/sat2goal.ts +9 -15
- package/src/prover/smt/solver/sat/scc.ts +1 -2
- package/src/prover/smt/solver/sat/simplifier.ts +16 -60
- package/src/prover/smt/solver/sat/solver.ts +47 -70
- package/src/prover/smt/solver/sat/var-queue.ts +0 -2
- package/src/prover/smt/solver/sat/watch-list.ts +7 -3
- package/src/prover/smt/solver/search-tree.ts +0 -1
- package/src/prover/smt/solver/seq-axioms.ts +21 -39
- package/src/prover/smt/solver/seq-decl-plugin.ts +10 -14
- package/src/prover/smt/solver/seq-derive.ts +11 -16
- package/src/prover/smt/solver/seq-eq-approx.ts +0 -2
- package/src/prover/smt/solver/seq-eq-solver.ts +9 -10
- package/src/prover/smt/solver/seq-factory.ts +2 -4
- package/src/prover/smt/solver/seq-monadic.ts +7 -7
- package/src/prover/smt/solver/seq-range-predicate.ts +18 -8
- package/src/prover/smt/solver/seq-re-rewriter.ts +5 -130
- package/src/prover/smt/solver/seq-re-util.ts +8 -27
- package/src/prover/smt/solver/seq-regex-bisim.ts +2 -3
- package/src/prover/smt/solver/seq-regex-live.ts +6 -8
- package/src/prover/smt/solver/seq-rewriter.ts +32 -35
- package/src/prover/smt/solver/seq-skolem.ts +0 -24
- package/src/prover/smt/solver/seq-subset.ts +0 -1
- package/src/prover/smt/solver/seq-view-witness.ts +4 -6
- package/src/prover/smt/solver/smt-consequences.ts +0 -2
- package/src/prover/smt/solver/smt-kernel.ts +9 -5
- package/src/prover/smt/solver/smt-logics.ts +0 -1
- package/src/prover/smt/solver/smt-setup.ts +86 -20
- package/src/prover/smt/solver/smt2-printer.ts +0 -2
- package/src/prover/smt/solver/smtlib-parser.ts +1681 -721
- package/src/prover/smt/solver/smtlib-script.ts +1273 -793
- package/src/prover/smt/solver/solve-eqs.ts +13 -23
- package/src/prover/smt/solver/solver.ts +1 -2
- package/src/prover/smt/solver/static-features.ts +0 -5
- package/src/prover/smt/solver/sticky-generations.ts +0 -1
- package/src/prover/smt/solver/tactic.ts +269 -130
- package/src/prover/smt/solver/term-enumeration.ts +0 -1
- package/src/prover/smt/solver/theory-array.ts +25 -60
- package/src/prover/smt/solver/theory-bv.ts +15 -54
- package/src/prover/smt/solver/theory-char.ts +0 -1
- package/src/prover/smt/solver/theory-datatype.ts +0 -1
- package/src/prover/smt/solver/theory-finite-set.ts +2 -2
- package/src/prover/smt/solver/theory-fpa.ts +46 -79
- package/src/prover/smt/solver/theory-lra-axioms.ts +0 -1
- package/src/prover/smt/solver/theory-lra-bounds.ts +0 -1
- package/src/prover/smt/solver/theory-lra-final-check.ts +1 -2
- package/src/prover/smt/solver/theory-lra-internalize.ts +9 -1
- package/src/prover/smt/solver/theory-lra-model.ts +0 -1
- package/src/prover/smt/solver/theory-lra-propagate.ts +6 -5
- package/src/prover/smt/solver/theory-lra-state.ts +0 -1
- package/src/prover/smt/solver/theory-lra.ts +0 -7
- package/src/prover/smt/solver/theory-pb.ts +34 -15
- package/src/prover/smt/solver/theory-polymorphism.ts +3 -4
- package/src/prover/smt/solver/theory-recfun.ts +2 -3
- package/src/prover/smt/solver/theory-seq-regex.ts +3 -7
- package/src/prover/smt/solver/theory-seq-solve.ts +6 -8
- package/src/prover/smt/solver/theory-seq-state.ts +8 -36
- package/src/prover/smt/solver/theory-seq.ts +32 -55
- package/src/prover/smt/solver/theory.ts +16 -2
- package/src/prover/smt/solver/tseitin-cnf.ts +3 -5
- package/src/prover/smt/solver/var-subst.ts +6 -6
- package/src/prover/smt/table.ts +3 -2
- package/src/prover/tlapm/cache.ts +8 -8
- package/src/prover/zenon/decide.ts +9 -13
- package/src/prover/zenon/encode.ts +0 -2
- package/src/prover/zenon/eqrel.ts +0 -2
- package/src/prover/zenon/equality-rules.ts +24 -2
- package/src/prover/zenon/expr.ts +21 -2
- package/src/prover/zenon/index-table.ts +7 -4
- package/src/prover/zenon/isar-case.ts +1 -3
- package/src/prover/zenon/isar.ts +2 -4
- package/src/prover/zenon/llproof.ts +0 -2
- package/src/prover/zenon/mltoll.ts +0 -2
- package/src/prover/zenon/node.ts +12 -13
- package/src/prover/zenon/parse.ts +0 -2
- package/src/prover/zenon/phrase.ts +1 -3
- package/src/prover/zenon/proof.ts +0 -2
- package/src/prover/zenon/propositional-rules.ts +0 -2
- package/src/prover/zenon/rules.ts +2 -3
- package/src/prover/zenon/search.ts +0 -2
- package/src/prover/zenon/tla/functions.ts +0 -2
- package/src/prover/zenon/tla/llproof.ts +0 -2
- package/src/prover/zenon/tla/records.ts +0 -2
- package/src/prover/zenon/tla/rewrites.ts +0 -2
- package/src/prover/zenon/tla/sets.ts +1 -3
- package/src/prover/zenon/tla/terms.ts +0 -2
- package/src/prover/zenon/tla/tla.ts +0 -2
- package/src/resolve.ts +625 -189
- package/src/runtime.ts +7 -1
- package/src/sany/builtins.ts +10 -10
- package/src/sany/generation.ts +2 -13
- package/src/sany/generator-definitions.ts +3 -1
- package/src/sany/generator-expressions.ts +36 -30
- package/src/sany/generator-proofs.ts +5 -3
- package/src/sany/generator.ts +2 -1
- package/src/sany/levels.ts +0 -2
- package/src/sany/lexer.ts +3 -3
- package/src/sany/linter.ts +0 -2
- package/src/sany/modules.ts +4 -2
- package/src/sany/nodes.ts +1 -1
- package/src/sany/selectors.ts +11 -6
- package/src/sany/xml.ts +2 -3
- package/src/search.ts +209 -56
- package/src/simulate.ts +3 -0
- package/src/spec-description.ts +2 -2
- package/src/standard-definitions.ts +4 -0
- package/src/state-graph.ts +0 -2
- package/src/subexpressions.ts +265 -94
- package/src/successors.ts +2 -1
- package/src/symmetry.ts +3 -3
- package/src/tableau.ts +2 -2
- package/src/tlc/fingerprint.ts +81 -9
- package/src/tlc/jar-data.ts +10 -0
- package/src/tlc/messages.ts +3 -3
- package/src/tlc/order.ts +14 -3
- package/src/tlc/summary.ts +29 -14
- package/src/tlc/tlc-operators.ts +3 -1
- package/src/tlc/tlcext-operators.ts +61 -16
- package/src/tlc/trace-spec.ts +5 -5
- package/src/typed-tier.ts +6541 -0
- package/src/typescript/types.ts +2 -2
- package/src/values.ts +46 -27
- package/src/prover/smt/solver/seq-regex-witness.ts +0 -100
- package/src/prover/smt/solver/z3-license.txt +0 -10
- package/src/prover/zenon/LICENSE +0 -32
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
SmtDefaultError,
|
|
3
|
+
SmtParseError,
|
|
4
|
+
type SmtPosition,
|
|
5
|
+
SmtUnsupportedError,
|
|
6
|
+
} from "../../../errors";
|
|
4
7
|
import {
|
|
5
8
|
type AstManager,
|
|
6
9
|
getSymbolHash,
|
|
7
10
|
FAMILY_ARITH,
|
|
8
11
|
FAMILY_BASIC,
|
|
9
|
-
|
|
12
|
+
KIND_APP,
|
|
10
13
|
KIND_QUANTIFIER,
|
|
11
14
|
KIND_VAR,
|
|
12
15
|
OP_ABS,
|
|
@@ -23,6 +26,7 @@ import {
|
|
|
23
26
|
OP_DISTINCT,
|
|
24
27
|
OP_DIV,
|
|
25
28
|
OP_DT_ACCESSOR,
|
|
29
|
+
OP_DT_CONSTRUCTOR,
|
|
26
30
|
OP_EQ,
|
|
27
31
|
OP_GE,
|
|
28
32
|
OP_GT,
|
|
@@ -37,6 +41,7 @@ import {
|
|
|
37
41
|
OP_MUL,
|
|
38
42
|
OP_NOT,
|
|
39
43
|
OP_OR,
|
|
44
|
+
OP_PATTERN,
|
|
40
45
|
OP_POWER,
|
|
41
46
|
OP_POWER0,
|
|
42
47
|
OP_SIN,
|
|
@@ -62,8 +67,6 @@ import {
|
|
|
62
67
|
OP_TRUE,
|
|
63
68
|
OP_FALSE,
|
|
64
69
|
OP_UMINUS,
|
|
65
|
-
OP_UNINTERPRETED,
|
|
66
|
-
OP_FUN_DEFINED,
|
|
67
70
|
OP_XOR,
|
|
68
71
|
SORT_BOOL,
|
|
69
72
|
SORT_INT,
|
|
@@ -74,7 +77,7 @@ import {
|
|
|
74
77
|
QUANTIFIER_LAMBDA,
|
|
75
78
|
} from "./ast";
|
|
76
79
|
import { getArraySignature, getMapSignature, mkAsArray } from "./array-decl-plugin";
|
|
77
|
-
import { BV_OP_NAMES, getBvSignature } from "./bv-decl-plugin";
|
|
80
|
+
import { BV_OP_NAMES, getBvSignature, getMismatchedArgument } from "./bv-decl-plugin";
|
|
78
81
|
import {
|
|
79
82
|
type ConstructorDef,
|
|
80
83
|
type DatatypeDef,
|
|
@@ -90,6 +93,7 @@ import {
|
|
|
90
93
|
mkDatatypes,
|
|
91
94
|
mkUpdateField,
|
|
92
95
|
removeDatatype,
|
|
96
|
+
resetDatatypePlugin,
|
|
93
97
|
substituteSort,
|
|
94
98
|
} from "./datatype-decl-plugin";
|
|
95
99
|
import {
|
|
@@ -100,6 +104,7 @@ import {
|
|
|
100
104
|
mkFpaAppOf,
|
|
101
105
|
} from "./fpa-decl-plugin";
|
|
102
106
|
import { createLogicChecker } from "./check-logic";
|
|
107
|
+
import { shrink } from "./array";
|
|
103
108
|
import { ObjMap } from "./hashtable";
|
|
104
109
|
import {
|
|
105
110
|
CHAR_OP_NAMES,
|
|
@@ -120,6 +125,8 @@ import {
|
|
|
120
125
|
isSupportedLogic,
|
|
121
126
|
} from "./smt-logics";
|
|
122
127
|
import { setRecFunDefinition } from "./recfun-decl-plugin";
|
|
128
|
+
import { DEFAULT_PRINT_OPTIONS, printExpr } from "./smt2-printer";
|
|
129
|
+
import { InvVarShifter } from "./rewriter-tpl";
|
|
123
130
|
import { replaceFreeVars, VarSubst } from "./var-subst";
|
|
124
131
|
import { UpolynomialManager } from "./nlsat/upolynomial";
|
|
125
132
|
|
|
@@ -131,12 +138,13 @@ const DEFAULT_PARSER_OPTIONS: ParserOptions = { isIgnoringBadPatterns: true };
|
|
|
131
138
|
|
|
132
139
|
// Z3 counts the columns of the first line from 1 and of the others from 0.
|
|
133
140
|
export interface SmtToken {
|
|
134
|
-
kind: "(" | ")" | "symbol" | "keyword" | "string" | "numeral" | "decimal" | "bitvector";
|
|
141
|
+
kind: "(" | ")" | "symbol" | "keyword" | "string" | "numeral" | "decimal" | "bitvector" | "eof";
|
|
135
142
|
text: string;
|
|
136
143
|
line: number;
|
|
137
144
|
column: number;
|
|
138
145
|
offset: number;
|
|
139
146
|
endOffset: number;
|
|
147
|
+
lastId: string;
|
|
140
148
|
}
|
|
141
149
|
|
|
142
150
|
export interface SmtList {
|
|
@@ -145,27 +153,30 @@ export interface SmtList {
|
|
|
145
153
|
line: number;
|
|
146
154
|
column: number;
|
|
147
155
|
offset: number;
|
|
156
|
+
lastId: string;
|
|
148
157
|
// Z3 reports an error in making an application at its closing parenthesis.
|
|
149
158
|
end: SmtToken;
|
|
159
|
+
// The token after a root-obj or an indexed or qualified identifier, where Z3 reports an error in
|
|
160
|
+
// making it.
|
|
150
161
|
follower?: SmtToken;
|
|
162
|
+
// The command that a list a command reader read is part of.
|
|
163
|
+
root?: SmtList;
|
|
151
164
|
}
|
|
152
165
|
|
|
153
166
|
export type SExpr = SmtToken | SmtList;
|
|
154
167
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
168
|
+
// smt2parser's local: a term, and the number of binders around it where it was bound.
|
|
169
|
+
interface Local {
|
|
170
|
+
expr: number;
|
|
171
|
+
level: number;
|
|
159
172
|
}
|
|
160
173
|
|
|
161
|
-
interface
|
|
162
|
-
kind: "let";
|
|
163
|
-
depth: number;
|
|
174
|
+
interface ParsedTerm {
|
|
164
175
|
expr: number;
|
|
176
|
+
isOwned: boolean;
|
|
177
|
+
root: SmtList | undefined;
|
|
165
178
|
}
|
|
166
179
|
|
|
167
|
-
type Binding = VarBinding | LetBinding;
|
|
168
|
-
|
|
169
180
|
interface Macro {
|
|
170
181
|
domain: number[];
|
|
171
182
|
range: number;
|
|
@@ -206,23 +217,121 @@ type SortDecl = ConstantSortDecl | UserSortDecl | DatatypeSortDecl | DefinedSort
|
|
|
206
217
|
|
|
207
218
|
const NO_BINDINGS: ReadonlyMap<string, number> = new Map();
|
|
208
219
|
|
|
209
|
-
const UPOLYNOMIALS = new UpolynomialManager();
|
|
210
|
-
|
|
211
220
|
interface SmtProblem {
|
|
212
221
|
assertions: number[];
|
|
213
222
|
hasCheckSat: boolean;
|
|
214
223
|
rlimit: number;
|
|
215
224
|
}
|
|
216
225
|
|
|
217
|
-
interface
|
|
226
|
+
interface QualifiedHead {
|
|
218
227
|
head: SmtToken;
|
|
219
228
|
indices: number[];
|
|
220
229
|
build?: (args: number[]) => number;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
interface ApplicationFrame extends QualifiedHead {
|
|
233
|
+
kind: "application";
|
|
234
|
+
list: SmtList;
|
|
235
|
+
isTail: boolean;
|
|
236
|
+
start: number;
|
|
237
|
+
next: number;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// An application whose head is a term, which selects from the array it stands for.
|
|
241
|
+
interface SelectionFrame {
|
|
242
|
+
kind: "selection";
|
|
221
243
|
list: SmtList;
|
|
244
|
+
isTail: boolean;
|
|
222
245
|
start: number;
|
|
223
246
|
next: number;
|
|
224
247
|
}
|
|
225
248
|
|
|
249
|
+
interface LetFrame {
|
|
250
|
+
kind: "let";
|
|
251
|
+
list: SmtList;
|
|
252
|
+
bindings: SmtList;
|
|
253
|
+
names: string[];
|
|
254
|
+
isInDecls: boolean;
|
|
255
|
+
isTail: boolean;
|
|
256
|
+
start: number;
|
|
257
|
+
next: number;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
interface LetDeclFrame {
|
|
261
|
+
kind: "let-decl";
|
|
262
|
+
list: SmtList;
|
|
263
|
+
next: number;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
interface QuantifierFrame {
|
|
267
|
+
kind: "quantifier";
|
|
268
|
+
list: SmtList;
|
|
269
|
+
quantifierKind: number;
|
|
270
|
+
names: string[];
|
|
271
|
+
varSorts: number[];
|
|
272
|
+
weight: number;
|
|
273
|
+
qid: string;
|
|
274
|
+
skid: string | undefined;
|
|
275
|
+
isTail: boolean;
|
|
276
|
+
start: number;
|
|
277
|
+
patternStart: number;
|
|
278
|
+
noPatternStart: number;
|
|
279
|
+
next: number;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
interface AttributeFrame {
|
|
283
|
+
kind: "attribute";
|
|
284
|
+
list: SmtList;
|
|
285
|
+
quantifier: QuantifierFrame | undefined;
|
|
286
|
+
lastKeyword: string;
|
|
287
|
+
isTail: boolean;
|
|
288
|
+
start: number;
|
|
289
|
+
next: number;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
interface PatternFrame {
|
|
293
|
+
kind: "pattern";
|
|
294
|
+
list: SmtList;
|
|
295
|
+
start: number;
|
|
296
|
+
next: number;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
interface MatchFrame {
|
|
300
|
+
kind: "match";
|
|
301
|
+
list: SmtList;
|
|
302
|
+
cases: SExpr[];
|
|
303
|
+
isCaseForm: boolean;
|
|
304
|
+
depth: number;
|
|
305
|
+
isTail: boolean;
|
|
306
|
+
start: number;
|
|
307
|
+
next: number;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// smt2parser.cpp's expr_frame.
|
|
311
|
+
type TermFrame =
|
|
312
|
+
| ApplicationFrame
|
|
313
|
+
| SelectionFrame
|
|
314
|
+
| LetFrame
|
|
315
|
+
| LetDeclFrame
|
|
316
|
+
| QuantifierFrame
|
|
317
|
+
| AttributeFrame
|
|
318
|
+
| PatternFrame
|
|
319
|
+
| MatchFrame;
|
|
320
|
+
|
|
321
|
+
const QUANTIFIER_KINDS = new Map([
|
|
322
|
+
["forall", QUANTIFIER_FORALL],
|
|
323
|
+
["exists", QUANTIFIER_EXISTS],
|
|
324
|
+
["lambda", QUANTIFIER_LAMBDA],
|
|
325
|
+
]);
|
|
326
|
+
|
|
327
|
+
const LET_MESSAGE = "invalid let declaration, symbol expected";
|
|
328
|
+
|
|
329
|
+
// The attributes that consume_attributes takes only in the body of a quantifier.
|
|
330
|
+
const QUANTIFIER_ATTRIBUTES = new Set([":weight", ":skolemid", ":qid", ":pattern", ":no-pattern"]);
|
|
331
|
+
|
|
332
|
+
const IS_PARAMETER_MESSAGE =
|
|
333
|
+
"invalid parameter to datatype function arity == 1 && num_parameters == 1 && parameters[0].is_ast() && is_func_decl(parameters[0].get_ast())";
|
|
334
|
+
|
|
226
335
|
const BUILTIN_OPS = new Map<string, number>([
|
|
227
336
|
["and", OP_AND],
|
|
228
337
|
["-", OP_SUB],
|
|
@@ -389,17 +498,19 @@ const THEORY_OPERATORS = new Set([
|
|
|
389
498
|
"transitive-closure",
|
|
390
499
|
]);
|
|
391
500
|
|
|
392
|
-
//
|
|
393
|
-
// left.
|
|
394
|
-
const
|
|
501
|
+
// func_decl_info of the builtin declarations: associative to both sides, flat, and associative to
|
|
502
|
+
// the left only. => alone is associative to the right only.
|
|
503
|
+
const ASSOCIATIVE_OPS = new Set([OP_AND, OP_OR, OP_XOR, OP_ADD, OP_MUL]);
|
|
504
|
+
const FLAT_OPS = new Set([OP_AND, OP_OR, OP_ADD, OP_MUL]);
|
|
505
|
+
const LEFT_ASSOCIATIVE_OPS = new Set([OP_SUB, OP_DIV, OP_IDIV]);
|
|
395
506
|
|
|
507
|
+
// arith_decl_plugin's use_coercion.
|
|
396
508
|
const COERCING_OPS = new Set([
|
|
397
509
|
OP_ADD,
|
|
398
510
|
OP_SUB,
|
|
399
511
|
OP_UMINUS,
|
|
400
512
|
OP_MUL,
|
|
401
513
|
OP_POWER,
|
|
402
|
-
OP_POWER0,
|
|
403
514
|
OP_LE,
|
|
404
515
|
OP_GE,
|
|
405
516
|
OP_LT,
|
|
@@ -424,30 +535,12 @@ const REAL_FUNCTION_OPS = new Set([
|
|
|
424
535
|
OP_LOG,
|
|
425
536
|
]);
|
|
426
537
|
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
[
|
|
430
|
-
[OP_ITE, [3, 3]],
|
|
431
|
-
[OP_EQ, [2, Infinity]],
|
|
432
|
-
[OP_DISTINCT, [1, Infinity]],
|
|
538
|
+
// The arity of each builtin declaration but distinct, which takes the arguments it is given.
|
|
539
|
+
const ARITIES = new Map<number, number>([
|
|
540
|
+
[OP_ITE, 3],
|
|
433
541
|
...[OP_NOT, OP_UMINUS, OP_ABS, OP_TO_REAL, OP_TO_INT, OP_IS_INT, ...REAL_FUNCTION_OPS]
|
|
434
542
|
.filter((op) => op !== OP_ATAN2)
|
|
435
|
-
.map((op): [number,
|
|
436
|
-
...[
|
|
437
|
-
OP_IMPLIES,
|
|
438
|
-
OP_XOR,
|
|
439
|
-
OP_IDIV,
|
|
440
|
-
OP_MOD,
|
|
441
|
-
OP_REM,
|
|
442
|
-
OP_DIV,
|
|
443
|
-
OP_LE,
|
|
444
|
-
OP_GE,
|
|
445
|
-
OP_LT,
|
|
446
|
-
OP_GT,
|
|
447
|
-
OP_POWER,
|
|
448
|
-
OP_POWER0,
|
|
449
|
-
OP_ATAN2,
|
|
450
|
-
].map((op): [number, [number, number]] => [op, [2, 2]]),
|
|
543
|
+
.map((op): [number, number] => [op, 1]),
|
|
451
544
|
]);
|
|
452
545
|
|
|
453
546
|
const RANGES = new Map<number, number>([
|
|
@@ -483,6 +576,7 @@ const CHAINABLE_OPS = new Map<string, number>([
|
|
|
483
576
|
["<", OP_LT],
|
|
484
577
|
[">", OP_GT],
|
|
485
578
|
]);
|
|
579
|
+
const CHAINABLE_DECLS = new Set(CHAINABLE_OPS.values());
|
|
486
580
|
|
|
487
581
|
const BV_EXTENSION_NAMES = new Set([
|
|
488
582
|
"bvumul_noovfl",
|
|
@@ -513,6 +607,14 @@ const ARRAY_OPS = new Map([
|
|
|
513
607
|
]);
|
|
514
608
|
const ARRAY_EXTENSION_OPS = new Map([["default", OP_ARRAY_DEFAULT]]);
|
|
515
609
|
|
|
610
|
+
const isPortedTheoryOperator = (name: string) =>
|
|
611
|
+
BV_OP_NAMES.has(name) ||
|
|
612
|
+
FPA_OP_NAMES.has(name) ||
|
|
613
|
+
SEQ_OP_NAMES.has(name) ||
|
|
614
|
+
CHAR_OP_NAMES.has(name) ||
|
|
615
|
+
ARRAY_OPS.has(name) ||
|
|
616
|
+
ARRAY_EXTENSION_OPS.has(name);
|
|
617
|
+
|
|
516
618
|
const UNARY_BOOL_REFS = new Map([["not", OP_NOT]]);
|
|
517
619
|
const BINARY_BOOL_REFS = new Map([
|
|
518
620
|
["and", OP_AND],
|
|
@@ -544,6 +646,9 @@ interface MappedDecl {
|
|
|
544
646
|
}
|
|
545
647
|
const ARRAY_EXTENSION_LOGICS = new Set(["HORN", "ALL"]);
|
|
546
648
|
|
|
649
|
+
// arith_decl_plugin::get_sort_names gives these logics no Int.
|
|
650
|
+
const INT_FREE_LOGICS = new Set(["NRA", "QF_NRA", "QF_NTA", "QF_UFNRA"]);
|
|
651
|
+
|
|
547
652
|
const BUILTIN_NAMES = new Set([
|
|
548
653
|
"true",
|
|
549
654
|
"false",
|
|
@@ -558,10 +663,20 @@ const BUILTIN_NAMES = new Set([
|
|
|
558
663
|
...CHAR_OP_NAMES.keys(),
|
|
559
664
|
]);
|
|
560
665
|
|
|
666
|
+
const FOLLOWED_HEADS = new Set(["root-obj", "_", "as"]);
|
|
667
|
+
|
|
668
|
+
const FF_LITERAL = /^#f-?[0-9]+m[0-9]+$/;
|
|
669
|
+
const FF_LOGICS = new Set(["QF_FF", "QF_FFA", "ALL", "HO_ALL"]);
|
|
670
|
+
|
|
671
|
+
// rational::is_unsigned of a numeral token.
|
|
672
|
+
export const isUnsigned = (numeral: string) =>
|
|
673
|
+
BigInt(numeral) >= 0n && BigInt(numeral) <= 0xffffffffn;
|
|
674
|
+
|
|
561
675
|
const SYMBOL_CHARACTER = /[A-Za-z0-9~!@$%^&*_\-+=<>.?/,]/;
|
|
562
676
|
|
|
563
677
|
const createScanner = (text: string) => {
|
|
564
|
-
|
|
678
|
+
// Z3 prints the null symbol its scanner starts with as null.
|
|
679
|
+
const state = { index: 0, line: 1, lineStart: -1, lastId: "null" };
|
|
565
680
|
const getColumn = () => state.index - state.lineStart - (state.line === 1 ? 0 : 1);
|
|
566
681
|
const advance = () => {
|
|
567
682
|
if (text[state.index] === "\n") {
|
|
@@ -587,13 +702,17 @@ const createScanner = (text: string) => {
|
|
|
587
702
|
}
|
|
588
703
|
const start = state.index;
|
|
589
704
|
const position = { line: state.line, column: getColumn() };
|
|
590
|
-
const getToken = (kind: SmtToken["kind"], tokenText = text.slice(start, state.index)) =>
|
|
591
|
-
kind
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
705
|
+
const getToken = (kind: SmtToken["kind"], tokenText = text.slice(start, state.index)) => {
|
|
706
|
+
if (kind === "symbol" || kind === "keyword") state.lastId = tokenText;
|
|
707
|
+
return {
|
|
708
|
+
kind,
|
|
709
|
+
text: tokenText,
|
|
710
|
+
...position,
|
|
711
|
+
offset: start,
|
|
712
|
+
endOffset: state.index,
|
|
713
|
+
lastId: state.lastId,
|
|
714
|
+
};
|
|
715
|
+
};
|
|
597
716
|
if (character === "(" || character === ")") {
|
|
598
717
|
advance();
|
|
599
718
|
return getToken(character);
|
|
@@ -607,11 +726,19 @@ const createScanner = (text: string) => {
|
|
|
607
726
|
{ line: state.line, column: getColumn() },
|
|
608
727
|
);
|
|
609
728
|
const current = text[state.index];
|
|
729
|
+
if (character === "|" && current === "\\")
|
|
730
|
+
throw new SmtParseError("invalid character '\\' in quoted symbol", {
|
|
731
|
+
line: state.line,
|
|
732
|
+
column: getColumn(),
|
|
733
|
+
});
|
|
610
734
|
advance();
|
|
611
735
|
// Z3's scanner starts the line before it reads past a newline in a quoted symbol or a
|
|
612
736
|
// string, so the columns of the rest of the line count one more.
|
|
613
737
|
if (current === "\n") state.lineStart--;
|
|
614
738
|
if (current !== character) continue;
|
|
739
|
+
// Z3's scanner rereads the last character at the end of the file, as if the quote were doubled.
|
|
740
|
+
if (character === '"' && state.index === text.length)
|
|
741
|
+
throw new SmtParseError("unexpected end of file", position);
|
|
615
742
|
if (character !== '"' || text[state.index] !== '"') break;
|
|
616
743
|
advance();
|
|
617
744
|
}
|
|
@@ -630,8 +757,35 @@ const createScanner = (text: string) => {
|
|
|
630
757
|
}
|
|
631
758
|
if (character === "#") {
|
|
632
759
|
advance();
|
|
633
|
-
|
|
634
|
-
|
|
760
|
+
const radix = text[state.index];
|
|
761
|
+
if (radix === "|") {
|
|
762
|
+
advance();
|
|
763
|
+
while (state.index < text.length) {
|
|
764
|
+
const current = text[state.index];
|
|
765
|
+
advance();
|
|
766
|
+
if (current !== "|" || text[state.index] !== "#") continue;
|
|
767
|
+
advance();
|
|
768
|
+
break;
|
|
769
|
+
}
|
|
770
|
+
continue;
|
|
771
|
+
}
|
|
772
|
+
if (radix !== "f" && radix !== "x" && radix !== "b")
|
|
773
|
+
throw new SmtParseError("invalid bit-vector literal, expecting 'x' or 'b'", {
|
|
774
|
+
line: state.line,
|
|
775
|
+
column: getColumn(),
|
|
776
|
+
});
|
|
777
|
+
advance();
|
|
778
|
+
const digitsStart = state.index;
|
|
779
|
+
readWhile(radix === "f" ? /[0-9m-]/ : radix === "x" ? /[0-9a-fA-F]/ : /[01]/);
|
|
780
|
+
if (state.index === digitsStart && radix !== "f")
|
|
781
|
+
throw new SmtParseError("invalid empty bit-vector literal", {
|
|
782
|
+
line: state.line,
|
|
783
|
+
column: getColumn(),
|
|
784
|
+
});
|
|
785
|
+
// Z3's scanner rereads the last digit at the end of the file.
|
|
786
|
+
if (state.index === text.length && state.index !== digitsStart)
|
|
787
|
+
throw new SmtParseError("unexpected end of file", position);
|
|
788
|
+
return getToken(radix === "f" ? "symbol" : "bitvector");
|
|
635
789
|
}
|
|
636
790
|
if (character === ":" || SYMBOL_CHARACTER.test(character)) {
|
|
637
791
|
advance();
|
|
@@ -642,7 +796,11 @@ const createScanner = (text: string) => {
|
|
|
642
796
|
throw new SmtParseError("unexpected character", position);
|
|
643
797
|
}
|
|
644
798
|
};
|
|
645
|
-
return {
|
|
799
|
+
return {
|
|
800
|
+
next,
|
|
801
|
+
getPosition: () => ({ line: state.line, column: getColumn() }),
|
|
802
|
+
getLastId: () => state.lastId,
|
|
803
|
+
};
|
|
646
804
|
};
|
|
647
805
|
|
|
648
806
|
export const createCommandReader = (text: string) => {
|
|
@@ -664,15 +822,31 @@ export const createCommandReader = (text: string) => {
|
|
|
664
822
|
line: open.line,
|
|
665
823
|
column: open.column,
|
|
666
824
|
offset: open.offset,
|
|
825
|
+
lastId: open.lastId,
|
|
667
826
|
end: open,
|
|
668
827
|
};
|
|
669
|
-
let
|
|
828
|
+
let followed: SmtList | undefined;
|
|
670
829
|
for (let current = root; ;) {
|
|
671
830
|
const token = take();
|
|
672
|
-
if (token === undefined)
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
831
|
+
if (token === undefined) {
|
|
832
|
+
// Z3 parses a command as it reads it, and sees the end of the file where it wants a token.
|
|
833
|
+
const eof: SmtToken = {
|
|
834
|
+
kind: "eof",
|
|
835
|
+
text: "",
|
|
836
|
+
...scanner.getPosition(),
|
|
837
|
+
offset: text.length,
|
|
838
|
+
endOffset: text.length,
|
|
839
|
+
lastId: scanner.getLastId(),
|
|
840
|
+
};
|
|
841
|
+
if (followed !== undefined) followed.follower = eof;
|
|
842
|
+
current.items.push(eof);
|
|
843
|
+
const end = { ...eof };
|
|
844
|
+
current.end = end;
|
|
845
|
+
for (const list of stack) list.end = end;
|
|
846
|
+
return root;
|
|
847
|
+
}
|
|
848
|
+
if (followed !== undefined) followed.follower = token;
|
|
849
|
+
followed = undefined;
|
|
676
850
|
if (token.kind === "(") {
|
|
677
851
|
const list: SmtList = {
|
|
678
852
|
kind: "list",
|
|
@@ -680,7 +854,9 @@ export const createCommandReader = (text: string) => {
|
|
|
680
854
|
line: token.line,
|
|
681
855
|
column: token.column,
|
|
682
856
|
offset: token.offset,
|
|
857
|
+
lastId: token.lastId,
|
|
683
858
|
end: token,
|
|
859
|
+
root,
|
|
684
860
|
};
|
|
685
861
|
current.items.push(list);
|
|
686
862
|
stack.push(current);
|
|
@@ -693,19 +869,36 @@ export const createCommandReader = (text: string) => {
|
|
|
693
869
|
continue;
|
|
694
870
|
}
|
|
695
871
|
current.end = token;
|
|
696
|
-
if (isSymbol(current.items[0]
|
|
872
|
+
if (isSymbol(current.items[0]) && FOLLOWED_HEADS.has(current.items[0].text))
|
|
873
|
+
followed = current;
|
|
697
874
|
state.depth--;
|
|
698
875
|
const parent = stack.pop();
|
|
699
876
|
if (parent === undefined) return root;
|
|
700
877
|
current = parent;
|
|
701
878
|
}
|
|
702
879
|
};
|
|
703
|
-
const
|
|
880
|
+
const readOpen = () => {
|
|
704
881
|
const token = take();
|
|
705
882
|
if (token === undefined) return undefined;
|
|
706
883
|
if (token.kind !== "(") throw new SmtParseError("invalid command, '(' expected", token);
|
|
707
884
|
state.depth = 1;
|
|
708
|
-
return
|
|
885
|
+
return token;
|
|
886
|
+
};
|
|
887
|
+
const read = () => {
|
|
888
|
+
const open = readOpen();
|
|
889
|
+
return open === undefined ? undefined : readList(open);
|
|
890
|
+
};
|
|
891
|
+
// parse_cmd checks the head of a command before it reads the rest.
|
|
892
|
+
const readCommand = () => {
|
|
893
|
+
const open = readOpen();
|
|
894
|
+
if (open === undefined) return undefined;
|
|
895
|
+
state.lookahead = take();
|
|
896
|
+
if (!isSymbol(state.lookahead))
|
|
897
|
+
throw new SmtParseError(
|
|
898
|
+
"invalid command, symbol expected",
|
|
899
|
+
state.lookahead ?? scanner.getPosition(),
|
|
900
|
+
);
|
|
901
|
+
return readList(open);
|
|
709
902
|
};
|
|
710
903
|
const skip = (report: (error: SmtParseError) => void) => {
|
|
711
904
|
for (;;) {
|
|
@@ -724,22 +917,43 @@ export const createCommandReader = (text: string) => {
|
|
|
724
917
|
}
|
|
725
918
|
}
|
|
726
919
|
};
|
|
727
|
-
return { read, skip };
|
|
920
|
+
return { read, readCommand, skip };
|
|
921
|
+
};
|
|
922
|
+
|
|
923
|
+
export const expectClosed = (sexpr: SExpr) => {
|
|
924
|
+
const end = sexpr.kind === "list" ? sexpr.end : sexpr;
|
|
925
|
+
if (end.kind === "eof")
|
|
926
|
+
throw new SmtParseError("invalid s-expression, unexpected end of file", end);
|
|
728
927
|
};
|
|
729
928
|
|
|
730
929
|
export const isSymbol = (sexpr: SExpr | undefined, text?: string): sexpr is SmtToken =>
|
|
731
930
|
sexpr !== undefined && sexpr.kind === "symbol" && (text === undefined || sexpr.text === text);
|
|
732
931
|
|
|
932
|
+
const isSimpleIndex = (index: SExpr) =>
|
|
933
|
+
index.kind === "numeral" ||
|
|
934
|
+
index.kind === "bitvector" ||
|
|
935
|
+
index.kind === "decimal" ||
|
|
936
|
+
index.kind === "keyword";
|
|
937
|
+
|
|
733
938
|
const expectList = (sexpr: SExpr | undefined, message: string, at: SExpr): SmtList => {
|
|
734
939
|
if (sexpr?.kind !== "list") throw new SmtParseError(message, sexpr ?? at);
|
|
735
940
|
return sexpr;
|
|
736
941
|
};
|
|
737
942
|
|
|
943
|
+
const expectListNext = (sexpr: SExpr, message: string) => {
|
|
944
|
+
if (sexpr.kind !== "list") throw new SmtParseError(`${message} got ${sexpr.lastId}`, sexpr);
|
|
945
|
+
return sexpr;
|
|
946
|
+
};
|
|
947
|
+
|
|
738
948
|
const expectSymbol = (sexpr: SExpr | undefined, message: string, at: SExpr): SmtToken => {
|
|
739
949
|
if (!isSymbol(sexpr)) throw new SmtParseError(message, sexpr ?? at);
|
|
740
950
|
return sexpr;
|
|
741
951
|
};
|
|
742
952
|
|
|
953
|
+
const expectEnd = (extra: SExpr | undefined, message: string) => {
|
|
954
|
+
if (extra !== undefined) throw new SmtParseError(message, extra);
|
|
955
|
+
};
|
|
956
|
+
|
|
743
957
|
export const createSmtlibReader = (
|
|
744
958
|
manager: AstManager,
|
|
745
959
|
logic?: string,
|
|
@@ -747,16 +961,13 @@ export const createSmtlibReader = (
|
|
|
747
961
|
) => {
|
|
748
962
|
const hasArith = logic === undefined || logicHasArith(logic);
|
|
749
963
|
const hasBv = logic === undefined || logicHasBv(logic);
|
|
750
|
-
const isNumeralAsReal = logic !== undefined && logicHasRealsOnly(logic);
|
|
751
964
|
const logicChecker = createLogicChecker(manager, logic);
|
|
752
965
|
const sortDecls = new Map<string, SortDecl>([
|
|
753
966
|
["Bool", { kind: "sort", sort: SORT_BOOL }],
|
|
754
|
-
...(hasArith
|
|
755
|
-
? [
|
|
756
|
-
["Int", { kind: "sort", sort: SORT_INT }] as const,
|
|
757
|
-
["Real", { kind: "sort", sort: SORT_REAL }] as const,
|
|
758
|
-
]
|
|
967
|
+
...(hasArith && !(logic !== undefined && INT_FREE_LOGICS.has(logic))
|
|
968
|
+
? [["Int", { kind: "sort", sort: SORT_INT }] as const]
|
|
759
969
|
: []),
|
|
970
|
+
...(hasArith ? [["Real", { kind: "sort", sort: SORT_REAL }] as const] : []),
|
|
760
971
|
...(logic === undefined ? [["List", { kind: "list" }] as const] : []),
|
|
761
972
|
]);
|
|
762
973
|
const funcs = new Map<string, readonly number[]>();
|
|
@@ -765,8 +976,28 @@ export const createSmtlibReader = (
|
|
|
765
976
|
const notifiedSorts = new Set<number>();
|
|
766
977
|
const undo: (() => void)[] = [];
|
|
767
978
|
const scopeStarts: number[] = [];
|
|
768
|
-
|
|
979
|
+
// smt2parser's m_env, a scoped symbol table: one map, and the trail of what each scope shadowed.
|
|
980
|
+
const locals = new Map<string, Local>();
|
|
981
|
+
const shadowedNames: string[] = [];
|
|
982
|
+
const shadowedLocals: (Local | undefined)[] = [];
|
|
983
|
+
const localScopes: number[] = [];
|
|
769
984
|
const binders = { depth: 0 };
|
|
985
|
+
// smt2parser's expr_stack, pattern_stack and nopattern_stack, which hold a reference to each term.
|
|
986
|
+
// -1 on the first stands for a pattern that Z3 ignores.
|
|
987
|
+
const exprStack: number[] = [];
|
|
988
|
+
const patternStack: number[] = [];
|
|
989
|
+
const noPatternStack: number[] = [];
|
|
990
|
+
// The term that parseTerm returns leaves the stack before its caller takes a reference. One that
|
|
991
|
+
// only the stack held keeps a reference in pending until a term of another command is parsed, and
|
|
992
|
+
// one that nothing held, in floating or, where its command is not known, in unrooted, gets one
|
|
993
|
+
// there when another term is parsed while its caller may still read it.
|
|
994
|
+
const parsed: ParsedTerm = { expr: -1, isOwned: false, root: undefined };
|
|
995
|
+
const floating: number[] = [];
|
|
996
|
+
const unrooted: number[] = [];
|
|
997
|
+
const pending: number[] = [];
|
|
998
|
+
|
|
999
|
+
const scopedFuncs: number[] = [];
|
|
1000
|
+
const scopedFuncStarts: number[] = [];
|
|
770
1001
|
|
|
771
1002
|
const declare = <Value>(names: Map<string, Value>, name: string, value: Value) => {
|
|
772
1003
|
const previous = names.get(name);
|
|
@@ -781,9 +1012,20 @@ export const createSmtlibReader = (
|
|
|
781
1012
|
const hasFpa = logic === undefined || logicHasFpa(logic);
|
|
782
1013
|
const hasArrayExtensions = logic === undefined || ARRAY_EXTENSION_LOGICS.has(logic);
|
|
783
1014
|
const hasSeq = logic === undefined || logicHasSeq(logic);
|
|
1015
|
+
const restricted = {
|
|
1016
|
+
isNumeralAsReal: logic !== undefined && logicHasRealsOnly(logic),
|
|
1017
|
+
hasSetSort: hasArrayExtensions,
|
|
1018
|
+
hasFf: logic === undefined || FF_LOGICS.has(logic),
|
|
1019
|
+
};
|
|
784
1020
|
|
|
785
1021
|
const getFirstFunc = (name: string) => funcs.get(name)?.[0];
|
|
786
1022
|
|
|
1023
|
+
// func_decls::signatures_collide: the domain, and the range unless it is -1.
|
|
1024
|
+
const hasSignature = (decl: number, domain: readonly number[], range: number) =>
|
|
1025
|
+
(range === -1 || manager.funcDecls[decl].range === range) &&
|
|
1026
|
+
manager.funcDecls[decl].domain.length === domain.length &&
|
|
1027
|
+
manager.funcDecls[decl].domain.every((sort, index) => sort === domain[index]);
|
|
1028
|
+
|
|
787
1029
|
const checkDecl = (decl: number, at: SExpr) => {
|
|
788
1030
|
const error = logicChecker.checkDecl(decl);
|
|
789
1031
|
if (error !== undefined) throw new SmtParseError(error, at);
|
|
@@ -805,6 +1047,7 @@ export const createSmtlibReader = (
|
|
|
805
1047
|
at,
|
|
806
1048
|
);
|
|
807
1049
|
declare(funcs, name, [...existing, decl]);
|
|
1050
|
+
scopedFuncs.push(decl);
|
|
808
1051
|
};
|
|
809
1052
|
|
|
810
1053
|
const insertDatatypeDecls = (sort: number, at: SExpr) => {
|
|
@@ -861,38 +1104,40 @@ export const createSmtlibReader = (
|
|
|
861
1104
|
? decl.parameters.length
|
|
862
1105
|
: decl.arity;
|
|
863
1106
|
|
|
1107
|
+
const registerList = () => {
|
|
1108
|
+
const element = manager.mkTypeParameter(0);
|
|
1109
|
+
mkDatatypes(manager, [
|
|
1110
|
+
mkDatatypeDef(
|
|
1111
|
+
manager,
|
|
1112
|
+
"List",
|
|
1113
|
+
[element],
|
|
1114
|
+
[
|
|
1115
|
+
{ name: "nil", recognizer: "is-nil", accessors: [] },
|
|
1116
|
+
{
|
|
1117
|
+
name: "insert",
|
|
1118
|
+
recognizer: "is-insert",
|
|
1119
|
+
accessors: [
|
|
1120
|
+
{ name: "head", range: element },
|
|
1121
|
+
{ name: "tail", range: -1 },
|
|
1122
|
+
],
|
|
1123
|
+
},
|
|
1124
|
+
],
|
|
1125
|
+
),
|
|
1126
|
+
]);
|
|
1127
|
+
const list: DatatypeSortDecl = {
|
|
1128
|
+
kind: "datatype",
|
|
1129
|
+
name: "List",
|
|
1130
|
+
arity: 1,
|
|
1131
|
+
siblings: [],
|
|
1132
|
+
instances: new Map(),
|
|
1133
|
+
};
|
|
1134
|
+
sortDecls.set("List", list);
|
|
1135
|
+
return list;
|
|
1136
|
+
};
|
|
1137
|
+
|
|
864
1138
|
const instantiateSort = (decl: SortDecl, parameters: number[], at: SExpr): number => {
|
|
865
1139
|
if (decl.kind === "sort") return decl.sort;
|
|
866
|
-
if (decl.kind === "list")
|
|
867
|
-
const element = manager.mkTypeParameter(0);
|
|
868
|
-
mkDatatypes(manager, [
|
|
869
|
-
mkDatatypeDef(
|
|
870
|
-
manager,
|
|
871
|
-
"List",
|
|
872
|
-
[element],
|
|
873
|
-
[
|
|
874
|
-
{ name: "nil", recognizer: "is-nil", accessors: [] },
|
|
875
|
-
{
|
|
876
|
-
name: "insert",
|
|
877
|
-
recognizer: "is-insert",
|
|
878
|
-
accessors: [
|
|
879
|
-
{ name: "head", range: element },
|
|
880
|
-
{ name: "tail", range: -1 },
|
|
881
|
-
],
|
|
882
|
-
},
|
|
883
|
-
],
|
|
884
|
-
),
|
|
885
|
-
]);
|
|
886
|
-
const list: DatatypeSortDecl = {
|
|
887
|
-
kind: "datatype",
|
|
888
|
-
name: "List",
|
|
889
|
-
arity: 1,
|
|
890
|
-
siblings: [],
|
|
891
|
-
instances: new Map(),
|
|
892
|
-
};
|
|
893
|
-
sortDecls.set("List", list);
|
|
894
|
-
return instantiateSort(list, parameters, at);
|
|
895
|
-
}
|
|
1140
|
+
if (decl.kind === "list") return instantiateSort(registerList(), parameters, at);
|
|
896
1141
|
if (decl.kind === "user") return manager.mkUninterpretedSort(decl.name, parameters);
|
|
897
1142
|
if (decl.kind === "datatype") return instantiateDatatype(decl, parameters, at);
|
|
898
1143
|
return parseSort(
|
|
@@ -908,8 +1153,13 @@ export const createSmtlibReader = (
|
|
|
908
1153
|
bindings: ReadonlyMap<string, number>,
|
|
909
1154
|
): number => {
|
|
910
1155
|
const head = sexpr.items[0];
|
|
911
|
-
if (!isSymbol(head))
|
|
912
|
-
|
|
1156
|
+
if (!isSymbol(head))
|
|
1157
|
+
throw new SmtParseError(
|
|
1158
|
+
`${context === "" ? "" : `${context} `}invalid sort, symbol or '_' expected`,
|
|
1159
|
+
head ?? sexpr.end,
|
|
1160
|
+
);
|
|
1161
|
+
const isArray =
|
|
1162
|
+
ARRAY_SORT_NAMES.has(head.text) || (head.text === "Set" && restricted.hasSetSort);
|
|
913
1163
|
if (isArray && hasArrays) {
|
|
914
1164
|
const parameters = sexpr.items.slice(1).map((item) => parseSort(item, context, bindings));
|
|
915
1165
|
if (head.text === "Set" ? parameters.length !== 1 : parameters.length < 2)
|
|
@@ -941,7 +1191,7 @@ export const createSmtlibReader = (
|
|
|
941
1191
|
return parseSort(head, context, bindings);
|
|
942
1192
|
}
|
|
943
1193
|
if (decl === undefined) {
|
|
944
|
-
if (THEORY_SORTS.has(head.text) && !
|
|
1194
|
+
if (THEORY_SORTS.has(head.text) && !isLackingSort(head.text))
|
|
945
1195
|
throw new SmtUnsupportedError(`the sort ${head.text}`);
|
|
946
1196
|
throw new SmtParseError(`unknown sort '${head.text}'`, head);
|
|
947
1197
|
}
|
|
@@ -968,8 +1218,20 @@ export const createSmtlibReader = (
|
|
|
968
1218
|
for (const item of (sexpr as SmtList).items.slice(1)) checkPsort(item, bindings);
|
|
969
1219
|
};
|
|
970
1220
|
|
|
1221
|
+
// Z3 does not know the sorts of a theory that the logic lacks.
|
|
1222
|
+
const isLackingSort = (name: string) =>
|
|
1223
|
+
name === "Set"
|
|
1224
|
+
? !hasArrays || !restricted.hasSetSort
|
|
1225
|
+
: ARRAY_SORT_NAMES.has(name)
|
|
1226
|
+
? !hasArrays
|
|
1227
|
+
: name === "BitVec"
|
|
1228
|
+
? !hasBv
|
|
1229
|
+
: SEQ_SORT_NAMES.has(name) || name === "Unicode"
|
|
1230
|
+
? !hasSeq
|
|
1231
|
+
: FPA_SORT_NAMES.has(name) && !hasFpa;
|
|
1232
|
+
|
|
971
1233
|
const isBuiltinParametricSort = (name: string) =>
|
|
972
|
-
(hasArrays && (ARRAY_SORT_NAMES.has(name) || (name === "Set" &&
|
|
1234
|
+
(hasArrays && (ARRAY_SORT_NAMES.has(name) || (name === "Set" && restricted.hasSetSort))) ||
|
|
973
1235
|
(hasSeq && (name === "Seq" || name === "RegEx")) ||
|
|
974
1236
|
(hasFpa && FPA_SORT_NAMES.has(name));
|
|
975
1237
|
|
|
@@ -993,23 +1255,40 @@ export const createSmtlibReader = (
|
|
|
993
1255
|
context: string,
|
|
994
1256
|
bindings: ReadonlyMap<string, number> = NO_BINDINGS,
|
|
995
1257
|
): number => {
|
|
1258
|
+
if (sexpr.kind === ")")
|
|
1259
|
+
throw new SmtParseError(`${context} invalid sort, unexpected ')'`, sexpr);
|
|
996
1260
|
if (sexpr.kind === "list") {
|
|
997
1261
|
if (!isSymbol(sexpr.items[0], "_")) return parseParametricSort(sexpr, context, bindings);
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
)
|
|
1008
|
-
|
|
1262
|
+
// parse_indexed_sort.
|
|
1263
|
+
const name = sexpr.items[1];
|
|
1264
|
+
if (!isSymbol(name))
|
|
1265
|
+
throw new SmtParseError("invalid indexed sort, symbol expected", name ?? sexpr.end);
|
|
1266
|
+
if (hasFpa && name.text === "FloatingPoint") return mkFloatSort(sexpr.items.slice(2), sexpr);
|
|
1267
|
+
const indices = sexpr.items.slice(2);
|
|
1268
|
+
if (isLackingSort(name.text) || !(THEORY_SORTS.has(name.text) || sortDecls.has(name.text)))
|
|
1269
|
+
throw new SmtParseError(`unknown sort '${name.text}'`, indices[0] ?? sexpr.end);
|
|
1270
|
+
if (name.text !== "BitVec") throw new SmtUnsupportedError("indexed sorts");
|
|
1271
|
+
for (const index of indices) {
|
|
1272
|
+
if (index.kind !== "numeral")
|
|
1273
|
+
throw new SmtParseError("invalid indexed sort, integer or ')' expected", index);
|
|
1274
|
+
if (!isUnsigned(index.text))
|
|
1275
|
+
throw new SmtParseError(
|
|
1276
|
+
"invalid indexed identifier, index is too big to fit in an unsigned machine integer",
|
|
1277
|
+
index,
|
|
1278
|
+
);
|
|
1279
|
+
}
|
|
1280
|
+
const width = indices[0];
|
|
1281
|
+
if (indices.length !== 1 || width.kind !== "numeral")
|
|
1282
|
+
throw new SmtParseError("expecting one integer parameter to bit-vector sort", sexpr.end);
|
|
1009
1283
|
if (BigInt(width.text) === 0n)
|
|
1010
1284
|
throw new SmtParseError("bit-vector size must be greater than zero", sexpr.end);
|
|
1011
1285
|
return manager.mkBvSort(Number(width.text));
|
|
1012
1286
|
}
|
|
1287
|
+
if (sexpr.kind !== "symbol")
|
|
1288
|
+
throw new SmtParseError(
|
|
1289
|
+
`invalid sort, symbol, '_' or '(' expected got ${sexpr.lastId}`,
|
|
1290
|
+
sexpr,
|
|
1291
|
+
);
|
|
1013
1292
|
const decl = sortDecls.get(sexpr.text);
|
|
1014
1293
|
if (decl !== undefined) {
|
|
1015
1294
|
if (getSortDeclArity(decl) !== 0)
|
|
@@ -1034,106 +1313,221 @@ export const createSmtlibReader = (
|
|
|
1034
1313
|
const bits = FPA_SORT_NAMES.get(sexpr.text);
|
|
1035
1314
|
return bits === undefined ? mkFloatSort([], sexpr) : manager.mkFpSort(bits[0], bits[1]);
|
|
1036
1315
|
}
|
|
1037
|
-
if (THEORY_SORTS.has(sexpr.text)
|
|
1316
|
+
if (THEORY_SORTS.has(sexpr.text) && !isLackingSort(sexpr.text))
|
|
1317
|
+
throw new SmtUnsupportedError(`the sort ${sexpr.text}`);
|
|
1038
1318
|
throw new SmtParseError(
|
|
1039
1319
|
`${context === "" ? "" : `${context}: `}unknown sort '${sexpr.text}'`,
|
|
1040
1320
|
sexpr,
|
|
1041
1321
|
);
|
|
1042
1322
|
};
|
|
1043
1323
|
|
|
1044
|
-
const
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1324
|
+
const beginScope = () => localScopes.push(shadowedNames.length);
|
|
1325
|
+
|
|
1326
|
+
const insertLocal = (name: string, expr: number) => {
|
|
1327
|
+
shadowedNames.push(name);
|
|
1328
|
+
shadowedLocals.push(locals.get(name));
|
|
1329
|
+
locals.set(name, { expr, level: binders.depth });
|
|
1330
|
+
};
|
|
1331
|
+
|
|
1332
|
+
const endScope = () => {
|
|
1333
|
+
const start = localScopes.pop() ?? 0;
|
|
1334
|
+
for (let index = shadowedNames.length - 1; index >= start; index--) {
|
|
1335
|
+
const shadowed = shadowedLocals[index];
|
|
1336
|
+
if (shadowed === undefined) locals.delete(shadowedNames[index]);
|
|
1337
|
+
else locals.set(shadowedNames[index], shadowed);
|
|
1048
1338
|
}
|
|
1049
|
-
|
|
1339
|
+
shrink(shadowedNames, start);
|
|
1340
|
+
shrink(shadowedLocals, start);
|
|
1050
1341
|
};
|
|
1051
1342
|
|
|
1052
|
-
const
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
return argSorts.includes(SORT_REAL) ? SORT_REAL : SORT_INT;
|
|
1343
|
+
const pushRef = (stack: number[], expr: number) => {
|
|
1344
|
+
if (expr !== -1) manager.incRef(expr);
|
|
1345
|
+
stack.push(expr);
|
|
1056
1346
|
};
|
|
1057
1347
|
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1348
|
+
// ref_vector::shrink, which releases from the new end on.
|
|
1349
|
+
const shrinkRefs = (stack: number[], size: number) => {
|
|
1350
|
+
for (let index = size; index < stack.length; index++)
|
|
1351
|
+
if (stack[index] !== -1) manager.decRef(stack[index]);
|
|
1352
|
+
shrink(stack, size);
|
|
1353
|
+
};
|
|
1354
|
+
|
|
1355
|
+
const releasePending = () => {
|
|
1356
|
+
for (const expr of pending) manager.decRef(expr);
|
|
1357
|
+
shrink(pending, 0);
|
|
1358
|
+
};
|
|
1359
|
+
|
|
1360
|
+
const protect = (exprs: number[]) => {
|
|
1361
|
+
for (const expr of exprs)
|
|
1362
|
+
if (manager.ids[expr] !== -1 && manager.getRefCount(expr) === 0) pushRef(pending, expr);
|
|
1363
|
+
shrink(exprs, 0);
|
|
1364
|
+
};
|
|
1365
|
+
|
|
1366
|
+
// The parser's var_shifter, whose cache holds the terms it makes, which replaceFreeVars rebuilds.
|
|
1367
|
+
const shiftFreeVars = (expr: number, amount: number) =>
|
|
1368
|
+
manager.kinds[expr] === KIND_VAR
|
|
1369
|
+
? manager.mkVar(manager.values[expr] + amount, manager.sorts[expr])
|
|
1370
|
+
: replaceFreeVars(manager, expr, (variable, index, shift) =>
|
|
1371
|
+
manager.mkVar(index + shift + amount, manager.sorts[variable]),
|
|
1372
|
+
);
|
|
1373
|
+
|
|
1374
|
+
const getLocalTerm = (local: Local) =>
|
|
1375
|
+
local.level === binders.depth
|
|
1376
|
+
? local.expr
|
|
1377
|
+
: shiftFreeVars(local.expr, binders.depth - local.level);
|
|
1378
|
+
|
|
1379
|
+
// basic_decl_plugin::join.
|
|
1380
|
+
const getJoin = (left: number, right: number, at: SExpr) => {
|
|
1381
|
+
if (left === right) return left;
|
|
1382
|
+
if (isArithSort(left) && isArithSort(right)) return left === SORT_REAL ? left : right;
|
|
1383
|
+
if (left === SORT_BOOL && isArithSort(right)) return right;
|
|
1384
|
+
if (right === SORT_BOOL && isArithSort(left)) return left;
|
|
1385
|
+
throw new SmtParseError(
|
|
1386
|
+
`Sorts ${manager.getSortName(left)} and ${manager.getSortName(right)} are incompatible`,
|
|
1387
|
+
at,
|
|
1388
|
+
);
|
|
1389
|
+
};
|
|
1390
|
+
|
|
1391
|
+
const getJoinOfArgs = (args: number[], at: SExpr) =>
|
|
1392
|
+
args.reduce((join, arg) => getJoin(join, manager.sorts[arg], at), manager.sorts[args[0]]);
|
|
1393
|
+
|
|
1394
|
+
// basic_decl_plugin::mk_func_decl and arith_decl_plugin::mk_func_decl: the sort of the arguments
|
|
1395
|
+
// that the declaration takes, the condition of ite aside, or -1 where the plugin makes none.
|
|
1396
|
+
const getDomainSort = (op: number, args: number[], at: SExpr) => {
|
|
1397
|
+
if (op === OP_ITE)
|
|
1398
|
+
return args.length === 3 ? getJoin(manager.sorts[args[1]], manager.sorts[args[2]], at) : -1;
|
|
1399
|
+
if (op === OP_EQ) return args.length >= 2 ? getJoinOfArgs(args, at) : -1;
|
|
1400
|
+
if (op === OP_DISTINCT) return args.length === 0 ? SORT_BOOL : getJoinOfArgs(args, at);
|
|
1401
|
+
if (manager.funcDecls[op].family === FAMILY_BASIC) return SORT_BOOL;
|
|
1402
|
+
if (COERCING_OPS.has(op))
|
|
1403
|
+
return args.some((arg) => manager.sorts[arg] === SORT_REAL) ? SORT_REAL : SORT_INT;
|
|
1064
1404
|
if (op === OP_DIV || op === OP_IS_INT || REAL_FUNCTION_OPS.has(op)) return SORT_REAL;
|
|
1065
|
-
return
|
|
1405
|
+
if (op === OP_IDIV || op === OP_MOD || op === OP_REM) return SORT_INT;
|
|
1406
|
+
return manager.sorts[args[0]] === SORT_REAL ? SORT_REAL : SORT_INT;
|
|
1066
1407
|
};
|
|
1067
1408
|
|
|
1409
|
+
// ast_manager::coerce_to.
|
|
1068
1410
|
const coerce = (arg: number, sort: number) => {
|
|
1069
1411
|
const argSort = manager.sorts[arg];
|
|
1070
|
-
if (argSort === sort || !isArithSort(
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1412
|
+
if (argSort === sort || !isArithSort(sort)) return arg;
|
|
1413
|
+
if (isArithSort(argSort))
|
|
1414
|
+
return sort === SORT_REAL
|
|
1415
|
+
? manager.mkApp(OP_TO_REAL, [arg], SORT_REAL)
|
|
1416
|
+
: manager.mkApp(OP_TO_INT, [arg], SORT_INT);
|
|
1417
|
+
if (argSort !== SORT_BOOL) return arg;
|
|
1418
|
+
const one = manager.mkNumeralOfSort(Rational.of(1n), sort);
|
|
1419
|
+
return manager.mkApp(OP_ITE, [arg, one, manager.mkNumeralOfSort(Rational.of(0n), sort)], sort);
|
|
1420
|
+
};
|
|
1421
|
+
|
|
1422
|
+
// A declaration of the script has its own domain, and a builtin one takes domainSort.
|
|
1423
|
+
const getArity = (decl: number, numArgs: number, domainSort: number) =>
|
|
1424
|
+
domainSort === -1
|
|
1425
|
+
? manager.funcDecls[decl].domain.length
|
|
1426
|
+
: decl === OP_DISTINCT
|
|
1427
|
+
? numArgs
|
|
1428
|
+
: (ARITIES.get(decl) ?? 2);
|
|
1429
|
+
|
|
1430
|
+
const getExpectedSort = (decl: number, index: number, domainSort: number) =>
|
|
1431
|
+
domainSort === -1
|
|
1432
|
+
? manager.funcDecls[decl].domain[index]
|
|
1433
|
+
: decl === OP_ITE && index === 0
|
|
1434
|
+
? SORT_BOOL
|
|
1435
|
+
: domainSort;
|
|
1436
|
+
|
|
1437
|
+
const formatDecl = (decl: number, numArgs: number, domainSort: number) => {
|
|
1438
|
+
const domain = Array.from({ length: getArity(decl, numArgs, domainSort) }, (_unused, index) =>
|
|
1439
|
+
manager.getSortName(getExpectedSort(decl, index, domainSort)),
|
|
1089
1440
|
);
|
|
1090
|
-
const
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1441
|
+
const range =
|
|
1442
|
+
domainSort === -1 ? manager.funcDecls[decl].range : (RANGES.get(decl) ?? domainSort);
|
|
1443
|
+
return `(declare-fun ${String(manager.funcDecls[decl].name)} (${domain.join(" ")}) ${manager.getSortName(range)})`;
|
|
1444
|
+
};
|
|
1445
|
+
|
|
1446
|
+
// ast_manager::mk_app_core: coercion_needed, coerce_to and check_args.
|
|
1447
|
+
const mkAppCore = (decl: number, args: number[], at: SExpr, domainSort: number) => {
|
|
1448
|
+
const isAssociative = domainSort !== -1 && ASSOCIATIVE_OPS.has(decl);
|
|
1449
|
+
const isCoercing =
|
|
1450
|
+
(isAssociative || getArity(decl, args.length, domainSort) === args.length) &&
|
|
1451
|
+
args.some((arg, index) => {
|
|
1452
|
+
const expected = getExpectedSort(decl, index, domainSort);
|
|
1453
|
+
return isArithSort(expected) && expected !== manager.sorts[arg];
|
|
1454
|
+
});
|
|
1455
|
+
const coerced = isCoercing
|
|
1456
|
+
? args.map((arg, index) => coerce(arg, getExpectedSort(decl, index, domainSort)))
|
|
1457
|
+
: args;
|
|
1458
|
+
for (let index = 0; index < coerced.length; index++) {
|
|
1459
|
+
const sort = manager.sorts[coerced[index]];
|
|
1460
|
+
if (sort !== getExpectedSort(decl, index, domainSort))
|
|
1461
|
+
throw new SmtParseError(
|
|
1462
|
+
`Sort mismatch at argument #${index + 1} for function ${formatDecl(decl, args.length, domainSort)} supplied sort is ${manager.getSortName(sort)}`,
|
|
1463
|
+
at,
|
|
1464
|
+
);
|
|
1465
|
+
}
|
|
1466
|
+
// Z3 keeps xor, / and div of fewer than two arguments until its rewriters make false or the
|
|
1467
|
+
// argument of them, which those of this port do not.
|
|
1468
|
+
if (
|
|
1469
|
+
coerced.length < 2 &&
|
|
1470
|
+
domainSort !== -1 &&
|
|
1471
|
+
(decl === OP_XOR || LEFT_ASSOCIATIVE_OPS.has(decl))
|
|
1472
|
+
)
|
|
1473
|
+
return coerced[0] ?? manager.falseExpr;
|
|
1100
1474
|
return manager.mkApp(
|
|
1101
1475
|
decl,
|
|
1102
|
-
|
|
1103
|
-
|
|
1476
|
+
coerced,
|
|
1477
|
+
domainSort === -1 ? manager.funcDecls[decl].range : (RANGES.get(decl) ?? domainSort),
|
|
1104
1478
|
);
|
|
1105
1479
|
};
|
|
1106
1480
|
|
|
1107
|
-
|
|
1108
|
-
|
|
1481
|
+
// ast_manager::mk_app.
|
|
1482
|
+
const mkApp = (decl: number, args: number[], at: SExpr, domainSort = -1): number => {
|
|
1483
|
+
const isBuiltin = domainSort !== -1;
|
|
1484
|
+
const isAssociative = isBuiltin && ASSOCIATIVE_OPS.has(decl);
|
|
1485
|
+
const isLeftAssociative = isAssociative || (isBuiltin && LEFT_ASSOCIATIVE_OPS.has(decl));
|
|
1486
|
+
const isRightAssociative = isAssociative || (isBuiltin && decl === OP_IMPLIES);
|
|
1487
|
+
const isChainable = isBuiltin && CHAINABLE_DECLS.has(decl);
|
|
1488
|
+
if (
|
|
1489
|
+
getArity(decl, args.length, domainSort) !== args.length &&
|
|
1490
|
+
((!isLeftAssociative && !isRightAssociative && !isChainable) ||
|
|
1491
|
+
(args.length < 2 && manager.funcDecls[decl].family === FAMILY_BASIC && !isAssociative))
|
|
1492
|
+
) {
|
|
1493
|
+
const environment = { options: DEFAULT_PRINT_OPTIONS, isUsed, isClashing };
|
|
1494
|
+
// Z3 prints an error without the newlines that end it.
|
|
1495
|
+
throw new SmtParseError(
|
|
1496
|
+
`Wrong number of arguments (${args.length}) passed to function ${formatDecl(decl, args.length, domainSort)} ${args
|
|
1497
|
+
.map((arg) => `\narg: ${printExpr(manager, environment, arg)}\n`)
|
|
1498
|
+
.join("")}`.replace(/\n+$/, ""),
|
|
1499
|
+
at,
|
|
1500
|
+
);
|
|
1501
|
+
}
|
|
1502
|
+
if (args.length === 1 && isChainable) return manager.trueExpr;
|
|
1503
|
+
if (args.length <= 2 || (isBuiltin && FLAT_OPS.has(decl)))
|
|
1504
|
+
return mkAppCore(decl, args, at, domainSort);
|
|
1505
|
+
if (isRightAssociative)
|
|
1506
|
+
return args
|
|
1507
|
+
.slice(0, -2)
|
|
1508
|
+
.reduceRight(
|
|
1509
|
+
(right, left) => mkAppCore(decl, [left, right], at, domainSort),
|
|
1510
|
+
mkAppCore(decl, args.slice(-2), at, domainSort),
|
|
1511
|
+
);
|
|
1512
|
+
if (isLeftAssociative)
|
|
1513
|
+
return args
|
|
1514
|
+
.slice(2)
|
|
1515
|
+
.reduce(
|
|
1516
|
+
(left, right) => mkAppCore(decl, [left, right], at, domainSort),
|
|
1517
|
+
mkAppCore(decl, args.slice(0, 2), at, domainSort),
|
|
1518
|
+
);
|
|
1519
|
+
if (!isChainable) return mkAppCore(decl, args, at, domainSort);
|
|
1109
1520
|
const pairs: number[] = [];
|
|
1110
|
-
for (let index =
|
|
1111
|
-
pairs.push(
|
|
1112
|
-
return
|
|
1521
|
+
for (let index = 1; index < args.length; index++)
|
|
1522
|
+
pairs.push(mkAppCore(decl, [args[index - 1], args[index]], at, domainSort));
|
|
1523
|
+
return mkApp(OP_AND, pairs, at, SORT_BOOL);
|
|
1113
1524
|
};
|
|
1114
1525
|
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
const parsePattern = (sexpr: SExpr, at: SExpr) => {
|
|
1121
|
-
if (sexpr.kind === ")") {
|
|
1122
|
-
// Z3 skips a bad pattern as an s-expression, which cannot start with ')'.
|
|
1123
|
-
if (options.isIgnoringBadPatterns)
|
|
1124
|
-
throw new SmtParseError("invalid s-expression, unexpected ')'", sexpr);
|
|
1125
|
-
throw new SmtParseError("invalid pattern, '(' expected", sexpr);
|
|
1126
|
-
}
|
|
1127
|
-
if (sexpr.kind !== "list") return rejectPattern("invalid pattern, '(' expected", sexpr);
|
|
1128
|
-
if (sexpr.items.length === 0) return rejectPattern("invalid empty pattern", at);
|
|
1129
|
-
const head = sexpr.items[0];
|
|
1130
|
-
if (head.kind === "list") return manager.mkPattern(sexpr.items.map(parseTerm));
|
|
1131
|
-
const decl = head.text === "true" || head.text === "false" ? -1 : getFirstFunc(head.text);
|
|
1132
|
-
if (decl === -1 || (decl !== undefined && manager.funcDecls[decl].domain.length === 0))
|
|
1133
|
-
return rejectPattern("invalid constant pattern", head);
|
|
1134
|
-
if (head.kind !== "symbol")
|
|
1135
|
-
throw new SmtParseError("invalid pattern, '(' or identifier expected", head);
|
|
1136
|
-
return manager.mkPattern([parseTerm(sexpr)]);
|
|
1526
|
+
// ast_manager::mk_pattern.
|
|
1527
|
+
const mkPattern = (terms: number[], at: SExpr) => {
|
|
1528
|
+
if (terms.some((term) => manager.kinds[term] !== KIND_APP))
|
|
1529
|
+
throw new SmtParseError("patterns cannot be variables or quantifiers", at);
|
|
1530
|
+
return manager.mkPattern(terms);
|
|
1137
1531
|
};
|
|
1138
1532
|
|
|
1139
1533
|
const isValidPattern = (pattern: number, numDecls: number) => {
|
|
@@ -1158,151 +1552,87 @@ export const createSmtlibReader = (
|
|
|
1158
1552
|
return manager.everyArg(pattern, isValid) && found.size === numDecls;
|
|
1159
1553
|
};
|
|
1160
1554
|
|
|
1555
|
+
// parse_sorted_vars: the variables are created the first declared with the largest index, and
|
|
1556
|
+
// the stack holds them.
|
|
1161
1557
|
const bindSortedVars = (sexpr: SExpr | undefined, at: SExpr) => {
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
const names =
|
|
1168
|
-
|
|
1169
|
-
)
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1558
|
+
if (sexpr?.kind !== "list")
|
|
1559
|
+
throw new SmtParseError(
|
|
1560
|
+
`invalid list of sorted variables, '(' expected got ${(sexpr ?? at).lastId}`,
|
|
1561
|
+
sexpr ?? at,
|
|
1562
|
+
);
|
|
1563
|
+
const names: string[] = [];
|
|
1564
|
+
const varSorts: number[] = [];
|
|
1565
|
+
for (const declaration of sexpr.items) {
|
|
1566
|
+
if (declaration.kind !== "list")
|
|
1567
|
+
throw new SmtParseError(
|
|
1568
|
+
`invalid sorted variable, '(' expected got ${declaration.lastId}`,
|
|
1569
|
+
declaration,
|
|
1570
|
+
);
|
|
1571
|
+
const name = declaration.items[0];
|
|
1572
|
+
if (!isSymbol(name))
|
|
1573
|
+
throw new SmtParseError(
|
|
1574
|
+
"invalid sorted variable, symbol expected",
|
|
1575
|
+
name ?? declaration.end,
|
|
1576
|
+
);
|
|
1577
|
+
names.push(name.text);
|
|
1578
|
+
varSorts.push(parseSort(declaration.items[1] ?? declaration.end, "invalid sorted variables"));
|
|
1579
|
+
const extra = declaration.items[2];
|
|
1580
|
+
if (extra !== undefined)
|
|
1581
|
+
throw new SmtParseError(`invalid sorted variable, ')' expected got ${extra.lastId}`, extra);
|
|
1582
|
+
}
|
|
1583
|
+
beginScope();
|
|
1177
1584
|
binders.depth += varSorts.length;
|
|
1585
|
+
for (const [index, sort] of varSorts.entries()) {
|
|
1586
|
+
const boundVar = manager.mkVar(varSorts.length - 1 - index, sort);
|
|
1587
|
+
pushRef(exprStack, boundVar);
|
|
1588
|
+
insertLocal(names[index], boundVar);
|
|
1589
|
+
}
|
|
1178
1590
|
return { names, varSorts };
|
|
1179
1591
|
};
|
|
1180
1592
|
|
|
1181
1593
|
const unbindSortedVars = (count: number) => {
|
|
1182
|
-
|
|
1594
|
+
endScope();
|
|
1183
1595
|
binders.depth -= count;
|
|
1184
1596
|
};
|
|
1185
1597
|
|
|
1186
|
-
|
|
1187
|
-
|
|
1598
|
+
// pop_quant_frame, up to the quantifier.
|
|
1599
|
+
const mkParsedQuantifier = (frame: QuantifierFrame) => {
|
|
1600
|
+
const list = frame.list;
|
|
1601
|
+
const numDecls = frame.varSorts.length;
|
|
1602
|
+
if (exprStack.length - frame.start !== numDecls + 1)
|
|
1188
1603
|
throw new SmtParseError(
|
|
1189
1604
|
"invalid quantified expression, syntax error: (forall|exists ((<symbol> <sort>)*) <expr>) expected",
|
|
1190
1605
|
list.end,
|
|
1191
1606
|
);
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
manager.mkVar(varSorts.length - 1 - index, sort),
|
|
1198
|
-
);
|
|
1199
|
-
for (const boundVar of boundVars) manager.incRef(boundVar);
|
|
1200
|
-
const bodySExpr = list.items[2];
|
|
1201
|
-
const isAnnotated = bodySExpr.kind === "list" && isSymbol(bodySExpr.items[0], "!");
|
|
1202
|
-
const annotations = bodySExpr.kind === "list" && isAnnotated ? bodySExpr.items : [];
|
|
1203
|
-
const parsedBody = parseTerm(isAnnotated ? annotations[1] : bodySExpr);
|
|
1204
|
-
if (kind !== QUANTIFIER_LAMBDA && manager.sorts[parsedBody] !== SORT_BOOL)
|
|
1205
|
-
throw new SmtParseError("expected a formula", bodySExpr);
|
|
1206
|
-
const attributes = Array.from(
|
|
1207
|
-
{ length: Math.ceil((annotations.length - 2) / 2) },
|
|
1208
|
-
(_unused, index) => ({
|
|
1209
|
-
keyword: annotations[2 + 2 * index],
|
|
1210
|
-
value: annotations[3 + 2 * index],
|
|
1211
|
-
}),
|
|
1212
|
-
);
|
|
1213
|
-
const body = attributes.reduce(
|
|
1214
|
-
(labeled, attribute) =>
|
|
1215
|
-
attribute.keyword.kind === "keyword" &&
|
|
1216
|
-
(attribute.keyword.text === ":lblpos" || attribute.keyword.text === ":lblneg")
|
|
1217
|
-
? mkLabel(labeled, attribute.keyword.text === ":lblpos", attribute.value, bodySExpr)
|
|
1218
|
-
: labeled,
|
|
1219
|
-
parsedBody,
|
|
1220
|
-
);
|
|
1221
|
-
const patterns: number[] = [];
|
|
1222
|
-
const noPatterns: number[] = [];
|
|
1223
|
-
for (const attribute of attributes) {
|
|
1224
|
-
if (attribute.keyword.kind !== "keyword") continue;
|
|
1225
|
-
if (attribute.keyword.text === ":no-pattern") {
|
|
1226
|
-
const noPattern = parseTerm(attribute.value ?? list.end);
|
|
1227
|
-
manager.incRef(noPattern);
|
|
1228
|
-
noPatterns.push(noPattern);
|
|
1229
|
-
continue;
|
|
1230
|
-
}
|
|
1231
|
-
if (attribute.keyword.text !== ":pattern") continue;
|
|
1232
|
-
const pattern = parsePattern(
|
|
1233
|
-
attribute.value ?? (bodySExpr.kind === "list" ? bodySExpr.end : list.end),
|
|
1234
|
-
list.end,
|
|
1235
|
-
);
|
|
1236
|
-
if (pattern === undefined) continue;
|
|
1237
|
-
manager.incRef(pattern);
|
|
1238
|
-
patterns.push(pattern);
|
|
1239
|
-
}
|
|
1240
|
-
const getAttribute = (name: string) => {
|
|
1241
|
-
const value = attributes
|
|
1242
|
-
.filter(
|
|
1243
|
-
(attribute) =>
|
|
1244
|
-
attribute.keyword.kind === "keyword" &&
|
|
1245
|
-
attribute.keyword.text === name &&
|
|
1246
|
-
attribute.value?.kind !== "list",
|
|
1247
|
-
)
|
|
1248
|
-
.at(-1)?.value;
|
|
1249
|
-
return value?.kind === "list" ? undefined : value?.text;
|
|
1250
|
-
};
|
|
1251
|
-
const weight = Number(getAttribute(":weight") ?? 1);
|
|
1252
|
-
const qid = getAttribute(":qid") ?? "";
|
|
1253
|
-
const skid = getAttribute(":skolemid");
|
|
1254
|
-
unbindSortedVars(varSorts.length);
|
|
1255
|
-
// pop_quant_frame: the invalid patterns leave the parser's stack before the quantifier is made,
|
|
1256
|
-
// and the valid ones after.
|
|
1257
|
-
let numKept = 0;
|
|
1258
|
-
for (const pattern of patterns) {
|
|
1259
|
-
if (!isValidPattern(pattern, varSorts.length)) {
|
|
1260
|
-
rejectPattern("invalid pattern", list.end);
|
|
1607
|
+
let numKept = frame.patternStart;
|
|
1608
|
+
for (let index = frame.patternStart; index < patternStack.length; index++) {
|
|
1609
|
+
const pattern = patternStack[index];
|
|
1610
|
+
if (!isValidPattern(pattern, numDecls)) {
|
|
1611
|
+
if (!options.isIgnoringBadPatterns) throw new SmtParseError("invalid pattern", list.end);
|
|
1261
1612
|
continue;
|
|
1262
1613
|
}
|
|
1263
1614
|
manager.incRef(pattern);
|
|
1264
|
-
manager.decRef(
|
|
1265
|
-
|
|
1615
|
+
manager.decRef(patternStack[numKept]);
|
|
1616
|
+
patternStack[numKept] = pattern;
|
|
1266
1617
|
numKept++;
|
|
1267
1618
|
}
|
|
1268
|
-
|
|
1269
|
-
|
|
1619
|
+
shrinkRefs(patternStack, numKept);
|
|
1620
|
+
const body = exprStack[exprStack.length - 1];
|
|
1621
|
+
if (frame.quantifierKind !== QUANTIFIER_LAMBDA && manager.sorts[body] !== SORT_BOOL)
|
|
1622
|
+
throw new SmtParseError("quantifier body must be a Boolean expression", list.end);
|
|
1623
|
+
if (patternStack.length > frame.patternStart && noPatternStack.length > frame.noPatternStart)
|
|
1270
1624
|
throw new SmtParseError("simultaneous patterns and no-patterns not supported", list.end);
|
|
1271
|
-
|
|
1272
|
-
kind,
|
|
1273
|
-
sorts: varSorts,
|
|
1274
|
-
names:
|
|
1625
|
+
return manager.mkQuantifier({
|
|
1626
|
+
kind: frame.quantifierKind,
|
|
1627
|
+
sorts: frame.varSorts,
|
|
1628
|
+
names: frame.names,
|
|
1275
1629
|
body,
|
|
1276
|
-
patterns,
|
|
1277
|
-
noPatterns,
|
|
1278
|
-
weight,
|
|
1279
|
-
qid,
|
|
1280
|
-
...(skid === undefined ? {} : { skid }),
|
|
1630
|
+
patterns: patternStack.slice(frame.patternStart),
|
|
1631
|
+
noPatterns: noPatternStack.slice(frame.noPatternStart),
|
|
1632
|
+
weight: frame.weight,
|
|
1633
|
+
qid: frame.qid,
|
|
1634
|
+
...(frame.skid === undefined ? {} : { skid: frame.skid }),
|
|
1281
1635
|
});
|
|
1282
|
-
for (const pattern of patterns) manager.decRef(pattern);
|
|
1283
|
-
for (const noPattern of noPatterns) manager.decRef(noPattern);
|
|
1284
|
-
for (const boundVar of boundVars) manager.decRef(boundVar);
|
|
1285
|
-
return quantifier;
|
|
1286
|
-
};
|
|
1287
|
-
|
|
1288
|
-
const parseLet = (list: SmtList) => {
|
|
1289
|
-
const message = "invalid let declaration, symbol expected";
|
|
1290
|
-
const scope = new Map<string, Binding>();
|
|
1291
|
-
const exprs: number[] = [];
|
|
1292
|
-
for (const binding of expectList(list.items[1], message, list).items) {
|
|
1293
|
-
const pair = expectList(binding, message, binding);
|
|
1294
|
-
const name = expectSymbol(pair.items[0], message, pair);
|
|
1295
|
-
const expr = parseTerm(pair.items[1] ?? pair.end);
|
|
1296
|
-
exprs.push(expr);
|
|
1297
|
-
scope.set(name.text, { kind: "let", depth: binders.depth, expr });
|
|
1298
|
-
}
|
|
1299
|
-
scopes.push(scope);
|
|
1300
|
-
// Z3 takes the last expression on its stack, so a let without a body is its last binding.
|
|
1301
|
-
for (const body of list.items.slice(2)) exprs.push(parseTerm(body));
|
|
1302
|
-
scopes.pop();
|
|
1303
|
-
const result = exprs.at(-1);
|
|
1304
|
-
if (result === undefined) throw new SmtParseError("invalid let expression", list.end);
|
|
1305
|
-
return result;
|
|
1306
1636
|
};
|
|
1307
1637
|
|
|
1308
1638
|
const expandMacro = (macro: Macro, args: number[]) =>
|
|
@@ -1322,13 +1652,15 @@ export const createSmtlibReader = (
|
|
|
1322
1652
|
|
|
1323
1653
|
const mkBvApp = (name: string, args: number[], indices: number[], at: SExpr) => {
|
|
1324
1654
|
const op = BV_OP_NAMES.get(name) ?? -1;
|
|
1325
|
-
const
|
|
1326
|
-
|
|
1327
|
-
op,
|
|
1328
|
-
args.map((arg) => manager.sorts[arg]),
|
|
1329
|
-
indices,
|
|
1330
|
-
);
|
|
1655
|
+
const argSorts = args.map((arg) => manager.sorts[arg]);
|
|
1656
|
+
const signature = getBvSignature(manager, op, argSorts, indices);
|
|
1331
1657
|
if (typeof signature === "string") throw new SmtParseError(signature, at);
|
|
1658
|
+
const mismatched = getMismatchedArgument(signature, argSorts);
|
|
1659
|
+
if (mismatched !== -1)
|
|
1660
|
+
throw new SmtParseError(
|
|
1661
|
+
`Argument ${printExpr(manager, { options: DEFAULT_PRINT_OPTIONS, isUsed, isClashing }, args[mismatched])} at position ${mismatched} has sort ${manager.getSortName(argSorts[mismatched])} it does not match declaration (declare-fun ${signature.name} (${signature.domain.map((sort) => manager.getSortName(sort)).join(" ")}) ${manager.getSortName(signature.range)})`,
|
|
1662
|
+
at,
|
|
1663
|
+
);
|
|
1332
1664
|
const decl = manager.mkBvDecl(op, signature.name, indices, signature.domain, signature.range);
|
|
1333
1665
|
return manager.mkApp(decl, args, signature.range);
|
|
1334
1666
|
};
|
|
@@ -1376,7 +1708,7 @@ export const createSmtlibReader = (
|
|
|
1376
1708
|
const pair = [args[index], args[index + 1]];
|
|
1377
1709
|
pairs.push(mkFpaAppOf(manager, getSignature(pair), pair));
|
|
1378
1710
|
}
|
|
1379
|
-
return mkApp(OP_AND, pairs, at);
|
|
1711
|
+
return mkApp(OP_AND, pairs, at, SORT_BOOL);
|
|
1380
1712
|
};
|
|
1381
1713
|
|
|
1382
1714
|
const isSeqOpName = (name: string) =>
|
|
@@ -1400,8 +1732,10 @@ export const createSmtlibReader = (
|
|
|
1400
1732
|
return mkSeqAppOf(manager, signature, args);
|
|
1401
1733
|
};
|
|
1402
1734
|
|
|
1735
|
+
const upolynomials = new UpolynomialManager(manager.limit);
|
|
1736
|
+
|
|
1403
1737
|
const parseUpolynomial = (sexpr: SExpr): bigint[] => {
|
|
1404
|
-
if (sexpr.kind === "numeral") return
|
|
1738
|
+
if (sexpr.kind === "numeral") return upolynomials.set([BigInt(sexpr.text)]);
|
|
1405
1739
|
if (sexpr.kind === "decimal") {
|
|
1406
1740
|
const parts = sexpr.text.split(".");
|
|
1407
1741
|
const value = Rational.of(BigInt(parts[0] + parts[1]), 10n ** BigInt(parts[1].length));
|
|
@@ -1410,7 +1744,7 @@ export const createSmtlibReader = (
|
|
|
1410
1744
|
"invalid univariate polynomial, integer coefficient expected",
|
|
1411
1745
|
sexpr,
|
|
1412
1746
|
);
|
|
1413
|
-
return
|
|
1747
|
+
return upolynomials.set([value.num]);
|
|
1414
1748
|
}
|
|
1415
1749
|
if (sexpr.kind === "symbol") {
|
|
1416
1750
|
if (sexpr.text !== "x")
|
|
@@ -1435,15 +1769,15 @@ export const createSmtlibReader = (
|
|
|
1435
1769
|
"invalid univariate polynomial, exponent must be an unsigned integer",
|
|
1436
1770
|
exponent,
|
|
1437
1771
|
);
|
|
1438
|
-
return
|
|
1772
|
+
return upolynomials.pw(parseUpolynomial(operands[0]), Number(exponent.text));
|
|
1439
1773
|
}
|
|
1440
1774
|
const combine =
|
|
1441
1775
|
head.text === "+"
|
|
1442
|
-
?
|
|
1776
|
+
? upolynomials.add
|
|
1443
1777
|
: head.text === "-"
|
|
1444
|
-
?
|
|
1778
|
+
? upolynomials.sub
|
|
1445
1779
|
: head.text === "*"
|
|
1446
|
-
?
|
|
1780
|
+
? upolynomials.mul
|
|
1447
1781
|
: undefined;
|
|
1448
1782
|
if (combine === undefined)
|
|
1449
1783
|
throw new SmtParseError(
|
|
@@ -1456,11 +1790,11 @@ export const createSmtlibReader = (
|
|
|
1456
1790
|
sexpr,
|
|
1457
1791
|
);
|
|
1458
1792
|
const first = parseUpolynomial(operands[0]);
|
|
1459
|
-
if (head.text === "-" && operands.length === 1) return
|
|
1793
|
+
if (head.text === "-" && operands.length === 1) return upolynomials.neg(first);
|
|
1460
1794
|
return operands
|
|
1461
1795
|
.slice(1)
|
|
1462
1796
|
.reduce(
|
|
1463
|
-
(result, operand) => combine.call(
|
|
1797
|
+
(result, operand) => combine.call(upolynomials, result, parseUpolynomial(operand)),
|
|
1464
1798
|
first,
|
|
1465
1799
|
);
|
|
1466
1800
|
};
|
|
@@ -1478,7 +1812,10 @@ export const createSmtlibReader = (
|
|
|
1478
1812
|
if (BigInt(index.text) === 0n)
|
|
1479
1813
|
throw new SmtParseError("invalid root-obj, index must be >= 1", index);
|
|
1480
1814
|
if (list.items.length > 3)
|
|
1481
|
-
throw new SmtParseError(
|
|
1815
|
+
throw new SmtParseError(
|
|
1816
|
+
`invalid root-obj, ')' expected got ${list.items[3].lastId}`,
|
|
1817
|
+
list.items[3],
|
|
1818
|
+
);
|
|
1482
1819
|
const coeffs = parseUpolynomial(polynomial);
|
|
1483
1820
|
const follower = list.follower ?? list.end;
|
|
1484
1821
|
if (coeffs.length === 0)
|
|
@@ -1496,43 +1833,137 @@ export const createSmtlibReader = (
|
|
|
1496
1833
|
return manager.mkAlgebraicNumeral(root);
|
|
1497
1834
|
};
|
|
1498
1835
|
|
|
1499
|
-
const
|
|
1836
|
+
const isKnownOperator = (name: string) => BUILTIN_NAMES.has(name) || THEORY_OPERATOR.test(name);
|
|
1837
|
+
|
|
1838
|
+
// parse_indexed_identifier_core.
|
|
1839
|
+
const getIndexedName = (list: SmtList) => {
|
|
1500
1840
|
const name = list.items[1];
|
|
1841
|
+
if (!isSymbol(name))
|
|
1842
|
+
throw new SmtParseError("invalid indexed identifier, symbol expected", name ?? list.end);
|
|
1843
|
+
for (const index of list.items.slice(2)) {
|
|
1844
|
+
if (index.kind === "string" || index.kind === "eof")
|
|
1845
|
+
throw new SmtParseError(
|
|
1846
|
+
"invalid indexed identifier, integer, identifier or '(' expected",
|
|
1847
|
+
index,
|
|
1848
|
+
);
|
|
1849
|
+
// parse_func_decl_ref of an index that is a symbol.
|
|
1850
|
+
if (
|
|
1851
|
+
index.kind === "symbol" &&
|
|
1852
|
+
name.text !== "is" &&
|
|
1853
|
+
!isUsed(index.text) &&
|
|
1854
|
+
!macros.has(index.text)
|
|
1855
|
+
)
|
|
1856
|
+
throw new SmtParseError(
|
|
1857
|
+
`invalid function declaration reference, unknown function ${index.text}`,
|
|
1858
|
+
index,
|
|
1859
|
+
);
|
|
1860
|
+
}
|
|
1861
|
+
return name;
|
|
1862
|
+
};
|
|
1863
|
+
|
|
1864
|
+
// parse_qualified_identifier_core on (as <identifier> <sort>), up to the sort.
|
|
1865
|
+
const parseQualifierSort = (list: SmtList) => {
|
|
1866
|
+
const target = list.items[1];
|
|
1867
|
+
if (target === undefined || (target.kind !== "symbol" && target.kind !== "list"))
|
|
1868
|
+
throw new SmtParseError(
|
|
1869
|
+
`invalid (indexed) identifier, '(_' or symbol expected got ${(target ?? list.end).lastId}`,
|
|
1870
|
+
target ?? list.end,
|
|
1871
|
+
);
|
|
1872
|
+
if (target.kind === "list") {
|
|
1873
|
+
if (!isSymbol(target.items[0], "_"))
|
|
1874
|
+
throw new SmtParseError(
|
|
1875
|
+
"invalid indexed identifier, '_' expected",
|
|
1876
|
+
target.items[0] ?? target.end,
|
|
1877
|
+
);
|
|
1878
|
+
getIndexedName(target);
|
|
1879
|
+
}
|
|
1880
|
+
const sort = parseSort(list.items[2] ?? list.end, "Invalid qualified identifier");
|
|
1881
|
+
const extra = list.items[3];
|
|
1882
|
+
if (extra !== undefined)
|
|
1883
|
+
throw new SmtParseError(
|
|
1884
|
+
`invalid qualified identifier, ')' expected got ${extra.lastId}`,
|
|
1885
|
+
extra,
|
|
1886
|
+
);
|
|
1887
|
+
return sort;
|
|
1888
|
+
};
|
|
1889
|
+
|
|
1890
|
+
// parse_qualified_name on (_ <symbol> <index>*). Z3 makes the term once it has read past the
|
|
1891
|
+
// closing parenthesis, where at is.
|
|
1892
|
+
const parseIndexedTerm = (list: SmtList, at: SExpr, range?: number) => {
|
|
1893
|
+
const name = getIndexedName(list);
|
|
1501
1894
|
const indices = list.items.slice(2);
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1895
|
+
const local = locals.get(name.text);
|
|
1896
|
+
if (local !== undefined) {
|
|
1897
|
+
if (indices.length > 0)
|
|
1898
|
+
throw new SmtParseError("invalid indexed identifier, symbol is a local declaration", at);
|
|
1899
|
+
return getLocalTerm(local);
|
|
1900
|
+
}
|
|
1901
|
+
const value = /^bv([0-9]+)$/.exec(name.text);
|
|
1902
|
+
if (value !== null) {
|
|
1903
|
+
const width = indices[0];
|
|
1904
|
+
const digits =
|
|
1905
|
+
indices.length !== 1
|
|
1906
|
+
? "-1"
|
|
1907
|
+
: width.kind === "bitvector"
|
|
1908
|
+
? `0${width.text.slice(1)}`
|
|
1909
|
+
: width.kind === "numeral"
|
|
1910
|
+
? width.text
|
|
1911
|
+
: "-1";
|
|
1912
|
+
if (!isUnsigned(digits))
|
|
1913
|
+
throw new SmtParseError("invalid bit-vector constant, index expected", at);
|
|
1914
|
+
if (BigInt(digits) === 0n)
|
|
1915
|
+
throw new SmtParseError("bit-vector size must be greater than zero", at);
|
|
1916
|
+
return manager.mkBvNumeral(BigInt(value[1]), Number(BigInt(digits)));
|
|
1917
|
+
}
|
|
1918
|
+
const isNumbered = indices.every((index) => index.kind === "numeral");
|
|
1919
|
+
if (isNumbered && isSeqOpName(name.text))
|
|
1507
1920
|
return mkSeqTerm(
|
|
1508
1921
|
name.text,
|
|
1509
1922
|
[],
|
|
1510
1923
|
indices.map((index) => (index.kind === "list" ? 0 : Number(index.text))),
|
|
1511
|
-
|
|
1924
|
+
at,
|
|
1512
1925
|
);
|
|
1513
|
-
if (
|
|
1514
|
-
isSymbol(name) &&
|
|
1515
|
-
isFpaOpName(name.text) &&
|
|
1516
|
-
indices.every((index) => index.kind === "numeral")
|
|
1517
|
-
) {
|
|
1926
|
+
if (isNumbered && isFpaOpName(name.text)) {
|
|
1518
1927
|
const signature = getFpaSignature(
|
|
1519
1928
|
manager,
|
|
1520
1929
|
FPA_OP_NAMES.get(name.text) ?? -1,
|
|
1521
1930
|
indices.map((index) => (index.kind === "list" ? 0 : Number(index.text))),
|
|
1522
1931
|
[],
|
|
1523
1932
|
);
|
|
1524
|
-
if (typeof signature === "string")
|
|
1525
|
-
throw new SmtParseError(signature, { line: list.end.line, column: list.end.column + 1 });
|
|
1933
|
+
if (typeof signature === "string") throw new SmtParseError(signature, at);
|
|
1526
1934
|
return mkFpaAppOf(manager, signature, []);
|
|
1527
1935
|
}
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1936
|
+
if (isKnownOperator(name.text) || !indices.every(isSimpleIndex))
|
|
1937
|
+
throw new SmtUnsupportedError("indexed identifiers");
|
|
1938
|
+
return parseApp(name, [], at, [], range);
|
|
1939
|
+
};
|
|
1940
|
+
|
|
1941
|
+
// parse_qualified_name.
|
|
1942
|
+
const parseQualifiedName = (list: SmtList) => {
|
|
1943
|
+
const at = list.follower ?? list.end;
|
|
1944
|
+
if (isSymbol(list.items[0], "_")) return parseIndexedTerm(list, at);
|
|
1945
|
+
const sort = parseQualifierSort(list);
|
|
1946
|
+
const target = list.items[1];
|
|
1947
|
+
const local = isSymbol(target) ? locals.get(target.text) : undefined;
|
|
1948
|
+
if (isSymbol(target) && local === undefined && hasArrays && target.text === "const")
|
|
1949
|
+
return mkArrayTerm(OP_CONST_ARRAY, [], [sort], at);
|
|
1950
|
+
// A macro takes no range, so check_qualifier catches the sort of the term it stands for.
|
|
1951
|
+
const term =
|
|
1952
|
+
local !== undefined
|
|
1953
|
+
? getLocalTerm(local)
|
|
1954
|
+
: isSymbol(target)
|
|
1955
|
+
? parseApp(target, [], at, [], sort)
|
|
1956
|
+
: parseIndexedTerm(
|
|
1957
|
+
expectList(target, "invalid indexed identifier, '_' expected", list),
|
|
1958
|
+
at,
|
|
1959
|
+
sort,
|
|
1960
|
+
);
|
|
1961
|
+
if (manager.sorts[term] !== sort)
|
|
1962
|
+
throw new SmtParseError(
|
|
1963
|
+
`sort mismatch in qualified identifier, expected: ${manager.getSortName(sort)}, got: ${manager.getSortName(manager.sorts[term])}`,
|
|
1964
|
+
at,
|
|
1965
|
+
);
|
|
1966
|
+
return term;
|
|
1536
1967
|
};
|
|
1537
1968
|
|
|
1538
1969
|
const mkArrayTerm = (op: number, inputArgs: number[], parameters: number[], at: SExpr) => {
|
|
@@ -1595,10 +2026,7 @@ export const createSmtlibReader = (
|
|
|
1595
2026
|
sort === argSorts[index] || (isArithSort(sort) && isArithSort(argSorts[index])),
|
|
1596
2027
|
),
|
|
1597
2028
|
);
|
|
1598
|
-
const found =
|
|
1599
|
-
candidates.find((decl) =>
|
|
1600
|
-
manager.funcDecls[decl].domain.every((sort, index) => sort === argSorts[index]),
|
|
1601
|
-
) ?? candidates.at(-1);
|
|
2029
|
+
const found = candidates.find((decl) => hasSignature(decl, argSorts, -1)) ?? candidates.at(-1);
|
|
1602
2030
|
if (found !== undefined) return mkApp(found, args, at);
|
|
1603
2031
|
if (args.length === 0 || range !== undefined) return undefined;
|
|
1604
2032
|
if (decls.length > 1) throwAmbiguousConstant(name, at);
|
|
@@ -1649,11 +2077,32 @@ export const createSmtlibReader = (
|
|
|
1649
2077
|
|
|
1650
2078
|
const mkIsApp = (constructorName: SmtToken, args: number[], at: SExpr) => {
|
|
1651
2079
|
const declared = findFuncDecl(constructorName);
|
|
1652
|
-
|
|
2080
|
+
// datatype::decl::plugin::mk_is.
|
|
2081
|
+
if (declared !== undefined) {
|
|
2082
|
+
if (args.length !== 1) throw new SmtParseError(IS_PARAMETER_MESSAGE, at);
|
|
2083
|
+
if (!manager.isDatatypeSort(manager.sorts[args[0]]))
|
|
2084
|
+
throw new SmtParseError(
|
|
2085
|
+
"invalid parameter to datatype function u().is_datatype(domain[0])",
|
|
2086
|
+
at,
|
|
2087
|
+
);
|
|
2088
|
+
if (manager.sorts[args[0]] !== manager.funcDecls[declared].range)
|
|
2089
|
+
throw new SmtParseError("invalid sort argument passed to recognizer", at);
|
|
2090
|
+
if (manager.funcDecls[declared].op !== OP_DT_CONSTRUCTOR)
|
|
2091
|
+
throw new SmtParseError("expecting constructor argument to recognizer", at);
|
|
2092
|
+
return manager.mkApp(getConstructorIs(manager, declared), args, SORT_BOOL);
|
|
2093
|
+
}
|
|
1653
2094
|
const argSort = args.length === 1 ? manager.sorts[args[0]] : -1;
|
|
1654
2095
|
if (argSort === -1 || !manager.isDatatypeSort(argSort))
|
|
1655
|
-
throw new
|
|
1656
|
-
const
|
|
2096
|
+
throw new SmtParseError(IS_PARAMETER_MESSAGE, at);
|
|
2097
|
+
const constructors = (() => {
|
|
2098
|
+
try {
|
|
2099
|
+
return getDatatypeConstructors(manager, argSort);
|
|
2100
|
+
} catch (error) {
|
|
2101
|
+
if (!(error instanceof SmtDefaultError)) throw error;
|
|
2102
|
+
throw new SmtParseError(error.message, at);
|
|
2103
|
+
}
|
|
2104
|
+
})();
|
|
2105
|
+
const constructor = constructors.find(
|
|
1657
2106
|
(decl) => manager.funcDecls[decl].name === constructorName.text,
|
|
1658
2107
|
);
|
|
1659
2108
|
if (constructor === undefined)
|
|
@@ -1671,9 +2120,23 @@ export const createSmtlibReader = (
|
|
|
1671
2120
|
`invalid function declaration reference, unknown function ${accessorName.text}`,
|
|
1672
2121
|
accessorName,
|
|
1673
2122
|
);
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
2123
|
+
// datatype::decl::plugin::mk_update_field.
|
|
2124
|
+
if (args.length !== 2)
|
|
2125
|
+
throw new SmtParseError("invalid number of arguments for datatype field update", at);
|
|
2126
|
+
const funcDecl = manager.funcDecls[accessor];
|
|
2127
|
+
if (funcDecl.op !== OP_DT_ACCESSOR)
|
|
2128
|
+
throw new SmtParseError(
|
|
2129
|
+
"datatype field update requires a datatype accessor as the second argument",
|
|
2130
|
+
at,
|
|
2131
|
+
);
|
|
2132
|
+
if (funcDecl.domain[0] !== manager.sorts[args[0]])
|
|
2133
|
+
throw new SmtParseError("first argument to field update should be a data-type", at);
|
|
2134
|
+
if (funcDecl.range !== manager.sorts[args[1]])
|
|
2135
|
+
throw new SmtParseError(
|
|
2136
|
+
`second argument to field update should be ${manager.getSortName(funcDecl.range)} instead of ${manager.getSortName(manager.sorts[args[1]])}`,
|
|
2137
|
+
at,
|
|
2138
|
+
);
|
|
2139
|
+
return manager.mkApp(mkUpdateField(manager, accessor), args, funcDecl.domain[0]);
|
|
1677
2140
|
};
|
|
1678
2141
|
|
|
1679
2142
|
const getUnknownConstantMessage = (name: string, args: number[], range: number | undefined) => {
|
|
@@ -1706,14 +2169,7 @@ export const createSmtlibReader = (
|
|
|
1706
2169
|
throw new SmtUnsupportedError("the declaration reference");
|
|
1707
2170
|
const domain = domainList.items.map((item) => parseSort(item, "Invalid function name"));
|
|
1708
2171
|
const range = parseSort(rangeSort, "Invalid function name");
|
|
1709
|
-
const declared = funcs
|
|
1710
|
-
.get(name.text)
|
|
1711
|
-
?.find(
|
|
1712
|
-
(decl) =>
|
|
1713
|
-
manager.funcDecls[decl].range === range &&
|
|
1714
|
-
manager.funcDecls[decl].domain.length === domain.length &&
|
|
1715
|
-
manager.funcDecls[decl].domain.every((sort, index) => sort === domain[index]),
|
|
1716
|
-
);
|
|
2172
|
+
const declared = funcs.get(name.text)?.find((decl) => hasSignature(decl, domain, range));
|
|
1717
2173
|
if (declared !== undefined) return { decl: declared, domain, range };
|
|
1718
2174
|
const builtin = CHAINABLE_OPS.get(name.text) ?? BUILTIN_OPS.get(name.text);
|
|
1719
2175
|
if (builtin === undefined)
|
|
@@ -1752,10 +2208,11 @@ export const createSmtlibReader = (
|
|
|
1752
2208
|
) => {
|
|
1753
2209
|
const name = head.text;
|
|
1754
2210
|
// A bound variable applied to arguments selects from the array it stands for, one at a time.
|
|
1755
|
-
|
|
2211
|
+
const local = locals.get(name);
|
|
2212
|
+
if (args.length > 0 && local !== undefined)
|
|
1756
2213
|
return args.reduce(
|
|
1757
2214
|
(array, arg) => mkArrayTerm(OP_SELECT, [array, arg], [], at),
|
|
1758
|
-
|
|
2215
|
+
getLocalTerm(local),
|
|
1759
2216
|
);
|
|
1760
2217
|
if (indices.length > 0)
|
|
1761
2218
|
return isFpaOpName(name)
|
|
@@ -1764,19 +2221,31 @@ export const createSmtlibReader = (
|
|
|
1764
2221
|
? mkSeqTerm(name, args, indices, at)
|
|
1765
2222
|
: mkBvApp(name, args, indices, at);
|
|
1766
2223
|
const macro = macros.get(name);
|
|
1767
|
-
// macros_find: a macro
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
2224
|
+
// macros_find: a macro takes its own sorts, and Int for Real or Real for Int. Any other
|
|
2225
|
+
// application leaves the name to a declaration.
|
|
2226
|
+
if (
|
|
2227
|
+
macro !== undefined &&
|
|
2228
|
+
macro.domain.length === args.length &&
|
|
2229
|
+
args.every(
|
|
2230
|
+
(arg, index) =>
|
|
2231
|
+
manager.sorts[arg] === macro.domain[index] ||
|
|
2232
|
+
(isArithSort(manager.sorts[arg]) && isArithSort(macro.domain[index])),
|
|
1773
2233
|
)
|
|
1774
|
-
|
|
1775
|
-
return expandMacro(
|
|
1776
|
-
|
|
2234
|
+
)
|
|
2235
|
+
return expandMacro(
|
|
2236
|
+
macro,
|
|
2237
|
+
args.map((arg, index) => coerce(arg, macro.domain[index])),
|
|
2238
|
+
);
|
|
1777
2239
|
const decls = funcs.get(name);
|
|
1778
2240
|
const declared = decls === undefined ? undefined : mkDeclaredApp(name, decls, args, range, at);
|
|
1779
2241
|
if (declared !== undefined) return declared;
|
|
2242
|
+
// cmd_context::mk_app: a constant that starts with #f is a finite-field literal.
|
|
2243
|
+
if (args.length === 0 && name.startsWith("#f")) {
|
|
2244
|
+
if (!FF_LITERAL.test(name))
|
|
2245
|
+
throw new SmtParseError("invalid finite-field literal, expected #f<integer>m<prime>", at);
|
|
2246
|
+
if (!restricted.hasFf) throw new SmtParseError("logic does not support finite fields", at);
|
|
2247
|
+
throw new SmtUnsupportedError("finite-field literals");
|
|
2248
|
+
}
|
|
1780
2249
|
if (isSeqOpName(name)) return mkSeqTerm(name, args, indices, at, range);
|
|
1781
2250
|
if (range !== undefined)
|
|
1782
2251
|
throw new SmtParseError(getUnknownConstantMessage(name, args, range), at);
|
|
@@ -1791,56 +2260,45 @@ export const createSmtlibReader = (
|
|
|
1791
2260
|
const transcendentalOp = isTranscendental ? TRANSCENDENTAL_OPS.get(builtin) : undefined;
|
|
1792
2261
|
if (isTranscendental && transcendentalOp === undefined)
|
|
1793
2262
|
throw new SmtUnsupportedError(`the operator ${name}`);
|
|
1794
|
-
const
|
|
1795
|
-
|
|
1796
|
-
|
|
2263
|
+
const builtinOp =
|
|
2264
|
+
builtin === "~"
|
|
2265
|
+
? OP_UMINUS
|
|
2266
|
+
: (CHAINABLE_OPS.get(builtin) ?? BUILTIN_OPS.get(builtin) ?? transcendentalOp);
|
|
2267
|
+
// load_plugin registers the operators of arithmetic only for a logic that has it.
|
|
2268
|
+
const named =
|
|
2269
|
+
builtinOp !== undefined && manager.funcDecls[builtinOp].family === FAMILY_ARITH && !hasArith
|
|
2270
|
+
? undefined
|
|
2271
|
+
: builtinOp;
|
|
1797
2272
|
if (
|
|
1798
2273
|
args.length === 0 &&
|
|
1799
|
-
|
|
1800
|
-
manager.funcDecls[
|
|
2274
|
+
named !== undefined &&
|
|
2275
|
+
manager.funcDecls[named].family === FAMILY_ARITH
|
|
1801
2276
|
)
|
|
1802
2277
|
throw new SmtParseError("no arguments supplied to arithmetical operator", head);
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
if (args.some((arg) => manager.sorts[arg] !== SORT_BOOL))
|
|
1826
|
-
throw new SmtParseError(`ill-sorted application of ${name}`, at);
|
|
1827
|
-
return args[0] ?? manager.falseExpr;
|
|
1828
|
-
}
|
|
1829
|
-
if (args.length <= 2 || !NESTED_OPS.has(op)) return mkApp(op, args, at);
|
|
1830
|
-
const domainSort = getDomainSort(op, args);
|
|
1831
|
-
return op === OP_XOR || op === OP_IMPLIES
|
|
1832
|
-
? args
|
|
1833
|
-
.slice(0, -1)
|
|
1834
|
-
.reduceRight(
|
|
1835
|
-
(right, left) => mkApp(op, [left, right], at, domainSort),
|
|
1836
|
-
args[args.length - 1],
|
|
1837
|
-
)
|
|
1838
|
-
: args.slice(1).reduce((left, right) => mkApp(op, [left, right], at, domainSort), args[0]);
|
|
1839
|
-
};
|
|
1840
|
-
|
|
1841
|
-
const parseLeaf = (sexpr: SExpr): number => {
|
|
2278
|
+
// arith_decl_plugin::fix_kind.
|
|
2279
|
+
const op = named === OP_SUB && args.length === 1 ? OP_UMINUS : named;
|
|
2280
|
+
const domainSort = op === undefined ? -1 : getDomainSort(op, args, at);
|
|
2281
|
+
if (op !== undefined && domainSort !== -1) return mkApp(op, args, at, domainSort);
|
|
2282
|
+
if (
|
|
2283
|
+
op === undefined &&
|
|
2284
|
+
!isPortedTheoryOperator(name) &&
|
|
2285
|
+
((THEORY_OPERATOR.test(name) &&
|
|
2286
|
+
(name.startsWith("bv")
|
|
2287
|
+
? hasBv
|
|
2288
|
+
: name.startsWith("fp.")
|
|
2289
|
+
? hasFpa
|
|
2290
|
+
: name.startsWith("ff.") || hasSeq)) ||
|
|
2291
|
+
THEORY_OPERATORS.has(name))
|
|
2292
|
+
)
|
|
2293
|
+
throw new SmtUnsupportedError(`the operator ${name}`);
|
|
2294
|
+
const instance = mkDatatypeInstanceApp(name, args, at);
|
|
2295
|
+
if (instance !== undefined) return instance;
|
|
2296
|
+
throw new SmtParseError(getUnknownConstantMessage(name, args, undefined), at);
|
|
2297
|
+
};
|
|
2298
|
+
|
|
2299
|
+
const parseLeaf = (sexpr: SmtToken): number => {
|
|
1842
2300
|
if (sexpr.kind === "numeral")
|
|
1843
|
-
return isNumeralAsReal
|
|
2301
|
+
return restricted.isNumeralAsReal
|
|
1844
2302
|
? manager.mkRealNumeral(Rational.of(BigInt(sexpr.text), 1n))
|
|
1845
2303
|
: manager.mkNumeral(BigInt(sexpr.text));
|
|
1846
2304
|
if (sexpr.kind === "decimal") {
|
|
@@ -1859,231 +2317,638 @@ export const createSmtlibReader = (
|
|
|
1859
2317
|
}
|
|
1860
2318
|
if (sexpr.kind === "string") return manager.mkString(parseZstring(sexpr.text, manager.maxChar));
|
|
1861
2319
|
if (sexpr.kind === "symbol") {
|
|
2320
|
+
const local = locals.get(sexpr.text);
|
|
2321
|
+
if (local !== undefined) return getLocalTerm(local);
|
|
1862
2322
|
if (sexpr.text === "true") return manager.trueExpr;
|
|
1863
2323
|
if (sexpr.text === "false") return manager.falseExpr;
|
|
1864
|
-
const binding = lookup(sexpr.text);
|
|
1865
|
-
if (binding?.kind === "var")
|
|
1866
|
-
return manager.mkVar(binders.depth - 1 - binding.depth, binding.sort);
|
|
1867
|
-
// Z3's var_shifter moves the free variables of a let binding up by the binders since. Its cache
|
|
1868
|
-
// holds the terms it makes, but this parser holds no references, so it rebuilds the binding
|
|
1869
|
-
// with replaceFreeVars.
|
|
1870
|
-
if (binding !== undefined)
|
|
1871
|
-
return binders.depth === binding.depth
|
|
1872
|
-
? binding.expr
|
|
1873
|
-
: replaceFreeVars(manager, binding.expr, (variable, index, shift) =>
|
|
1874
|
-
manager.mkVar(index + shift + binders.depth - binding.depth, manager.sorts[variable]),
|
|
1875
|
-
);
|
|
1876
2324
|
return parseApp(sexpr, [], sexpr);
|
|
1877
2325
|
}
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
: head.text === "exists"
|
|
1886
|
-
? QUANTIFIER_EXISTS
|
|
1887
|
-
: QUANTIFIER_LAMBDA,
|
|
1888
|
-
);
|
|
1889
|
-
if (isSymbol(head, "let")) return parseLet(sexpr);
|
|
1890
|
-
// Each attribute applies to the expression the attributes before it made.
|
|
1891
|
-
return sexpr.items.slice(2).reduce(
|
|
1892
|
-
(annotated, keyword, index, attributes) => {
|
|
1893
|
-
if (keyword.kind !== "keyword") return annotated;
|
|
1894
|
-
const value = attributes[index + 1];
|
|
1895
|
-
if (keyword.text === ":lblpos" || keyword.text === ":lblneg")
|
|
1896
|
-
return mkLabel(annotated, keyword.text === ":lblpos", value, sexpr);
|
|
1897
|
-
if (keyword.text !== ":named") return annotated;
|
|
1898
|
-
const name = expectSymbol(value, "invalid attribute value, symbol expected", sexpr).text;
|
|
1899
|
-
manager.incRef(annotated);
|
|
1900
|
-
lastNamed.name = name;
|
|
1901
|
-
lastNamed.expr = annotated;
|
|
1902
|
-
manager.mkMacro(name, annotated);
|
|
1903
|
-
declare(macros, name, { domain: [], range: manager.sorts[annotated], body: annotated });
|
|
1904
|
-
return annotated;
|
|
1905
|
-
},
|
|
1906
|
-
parseTerm(sexpr.items[1] ?? sexpr.end),
|
|
2326
|
+
throw new SmtParseError(
|
|
2327
|
+
sexpr.kind === "keyword"
|
|
2328
|
+
? "invalid expression, unexpected keyword"
|
|
2329
|
+
: sexpr.kind === "eof"
|
|
2330
|
+
? "invalid expression, unexpected input"
|
|
2331
|
+
: "invalid expression, unexpected ')'",
|
|
2332
|
+
sexpr,
|
|
1907
2333
|
);
|
|
1908
2334
|
};
|
|
1909
2335
|
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
2336
|
+
// name_expr and cmd_context::insert of a named term. Z3 reports an error at the token after the
|
|
2337
|
+
// name.
|
|
2338
|
+
const nameExpr = (expr: number, name: string, at: SExpr) => {
|
|
2339
|
+
if (manager.freeVarBounds[expr] > 0)
|
|
2340
|
+
throw new SmtParseError("invalid named expression, expression contains free variables", at);
|
|
2341
|
+
if (macros.get(name)?.domain.length === 0)
|
|
2342
|
+
throw new SmtParseError("named expression already defined", at);
|
|
2343
|
+
if ((funcs.get(name) ?? []).some((decl) => hasSignature(decl, [], manager.sorts[expr])))
|
|
2344
|
+
throw new SmtParseError(
|
|
2345
|
+
`invalid named expression, declaration already defined with this name ${name}`,
|
|
2346
|
+
at,
|
|
2347
|
+
);
|
|
2348
|
+
manager.incRef(expr);
|
|
2349
|
+
lastNamed.name = name;
|
|
2350
|
+
lastNamed.expr = expr;
|
|
2351
|
+
const decl = manager.mkMacro(name, expr);
|
|
2352
|
+
declare(funcs, name, [...(funcs.get(name) ?? []), decl]);
|
|
2353
|
+
scopedFuncs.push(decl);
|
|
2354
|
+
declare(macros, name, { domain: [], range: manager.sorts[expr], body: expr });
|
|
2355
|
+
};
|
|
2356
|
+
|
|
2357
|
+
// push_app_frame's parse_qualified_identifier_core, on a head that is (_ <symbol> <index>*) or
|
|
2358
|
+
// (as <identifier> <sort>).
|
|
2359
|
+
const parseQualifiedHead = (list: SmtList, head: SmtList): QualifiedHead => {
|
|
2360
|
+
if (isSymbol(head.items[0], "as")) {
|
|
2361
|
+
const range = parseQualifierSort(head);
|
|
2362
|
+
const target = head.items[1];
|
|
2363
|
+
if (!isSymbol(target)) throw new SmtUnsupportedError("indexed and qualified identifiers");
|
|
2364
|
+
return {
|
|
2365
|
+
head: target,
|
|
2366
|
+
indices: [],
|
|
2367
|
+
build:
|
|
2368
|
+
hasArrays && target.text === "const"
|
|
2369
|
+
? (args) => mkArrayTerm(OP_CONST_ARRAY, args, [range], list.end)
|
|
2370
|
+
: (args) => parseApp(target, args, list.end, [], range),
|
|
2371
|
+
};
|
|
2372
|
+
}
|
|
2373
|
+
const name = getIndexedName(head);
|
|
2374
|
+
const indices = head.items.slice(2);
|
|
2375
|
+
const indexed = indices[0];
|
|
2376
|
+
if (hasArrays && hasArrayExtensions && name.text === "map" && indices.length === 1) {
|
|
2377
|
+
const mapped = parseFuncDeclRef(indexed);
|
|
2378
|
+
return { head: name, indices: [], build: (args) => mkMapTerm(mapped, args, list.end) };
|
|
2379
|
+
}
|
|
2380
|
+
if ((name.text === "is" || name.text === "update-field") && indices.length === 1) {
|
|
2381
|
+
if (!isSymbol(indexed)) throw new SmtUnsupportedError("indexed and qualified identifiers");
|
|
2382
|
+
return {
|
|
2383
|
+
head: name,
|
|
2384
|
+
indices: [],
|
|
2385
|
+
build: (args) =>
|
|
2386
|
+
name.text === "is"
|
|
2387
|
+
? mkIsApp(indexed, args, list.end)
|
|
2388
|
+
: mkUpdateFieldApp(indexed, args, list.end),
|
|
2389
|
+
};
|
|
2390
|
+
}
|
|
2391
|
+
const isNumbered = indices.every((index) => index.kind === "numeral");
|
|
2392
|
+
if (isNumbered && isPbOpName(name.text)) {
|
|
2393
|
+
const parameters = indices.map((index) =>
|
|
2394
|
+
Rational.of(BigInt(index.kind === "list" ? 0 : index.text)),
|
|
2395
|
+
);
|
|
2396
|
+
return {
|
|
2397
|
+
head: name,
|
|
2398
|
+
indices: [],
|
|
2399
|
+
build: (args) => mkPbTerm(name.text, args, parameters, list.end),
|
|
2400
|
+
};
|
|
2401
|
+
}
|
|
2402
|
+
if (isNumbered && (isBvOpName(name.text) || isFpaOpName(name.text) || isSeqOpName(name.text)))
|
|
2403
|
+
return {
|
|
2404
|
+
head: name,
|
|
2405
|
+
indices: indices.map((index) => (index.kind === "list" ? 0 : Number(index.text))),
|
|
2406
|
+
};
|
|
2407
|
+
// cmd_context::mk_app finds a name that no theory knows among the declarations, whatever its
|
|
2408
|
+
// indices are.
|
|
2409
|
+
if (isKnownOperator(name.text) || !indices.every(isSimpleIndex))
|
|
2410
|
+
throw new SmtUnsupportedError("indexed and qualified identifiers");
|
|
2411
|
+
return { head: name, indices: [] };
|
|
2412
|
+
};
|
|
2413
|
+
|
|
2414
|
+
const parseMatchPattern = (sexpr: SExpr, sort: number, after: SExpr) => {
|
|
2415
|
+
if (sexpr.kind !== "list" && sexpr.kind !== "symbol")
|
|
2416
|
+
throw new SmtParseError(
|
|
2417
|
+
"expecting a constructor, _, variable or constructor application",
|
|
2418
|
+
sexpr,
|
|
2419
|
+
);
|
|
2420
|
+
const name = sexpr.kind === "list" ? (sexpr.items[0] ?? sexpr.end) : sexpr;
|
|
2421
|
+
if (!isSymbol(name)) throw new SmtParseError("constructor symbol expected", name);
|
|
2422
|
+
const vars: string[] = [];
|
|
2423
|
+
if (sexpr.kind === "list")
|
|
2424
|
+
for (const [index, item] of sexpr.items.slice(1).entries()) {
|
|
2425
|
+
if (!isSymbol(item)) throw new SmtParseError("variable symbol expected", item);
|
|
2426
|
+
if (item.text !== "_" && vars.includes(item.text))
|
|
2427
|
+
throw new SmtParseError(
|
|
2428
|
+
"unexpected repeated variable in pattern expression",
|
|
2429
|
+
sexpr.items[index + 2] ?? sexpr.end,
|
|
2430
|
+
);
|
|
2431
|
+
vars.push(item.text);
|
|
2432
|
+
}
|
|
2433
|
+
const decl = funcs
|
|
2434
|
+
.get(name.text)
|
|
2435
|
+
?.find(
|
|
2436
|
+
(candidate) =>
|
|
2437
|
+
manager.funcDecls[candidate].range === sort &&
|
|
2438
|
+
manager.funcDecls[candidate].domain.length === vars.length,
|
|
2439
|
+
);
|
|
2440
|
+
if (decl === undefined && vars.length > 0)
|
|
2441
|
+
throw new SmtParseError(
|
|
2442
|
+
`invalid function declaration reference, unknown indexed function ${name.text}`,
|
|
2443
|
+
after,
|
|
2444
|
+
);
|
|
2445
|
+
if (decl === undefined && (name.text === "true" || name.text === "false"))
|
|
2446
|
+
throw new SmtParseError("expecting a constructor", after);
|
|
2447
|
+
if (decl === undefined && BUILTIN_NAMES.has(name.text))
|
|
2448
|
+
throw new SmtUnsupportedError("a builtin name as a pattern of match");
|
|
2449
|
+
if (decl === undefined) {
|
|
2450
|
+
binders.depth++;
|
|
2451
|
+
const variable = manager.mkVar(0, sort);
|
|
2452
|
+
if (name.text !== "_") insertLocal(name.text, variable);
|
|
2453
|
+
return variable;
|
|
2454
|
+
}
|
|
2455
|
+
if (manager.funcDecls[decl].op !== OP_DT_CONSTRUCTOR)
|
|
2456
|
+
throw new SmtParseError("expecting a constructor", after);
|
|
2457
|
+
binders.depth += vars.length;
|
|
2458
|
+
const args = vars.map((variable, index) => {
|
|
2459
|
+
const boundVar = manager.mkVar(index, manager.funcDecls[decl].domain[index]);
|
|
2460
|
+
if (variable !== "_") insertLocal(variable, boundVar);
|
|
2461
|
+
return boundVar;
|
|
2462
|
+
});
|
|
2463
|
+
return manager.mkApp(decl, args, sort);
|
|
2464
|
+
};
|
|
2465
|
+
|
|
2466
|
+
const compileMatch = (term: number, patterns: number[], bodies: number[], at: SExpr) => {
|
|
2467
|
+
const sort = manager.sorts[term];
|
|
2468
|
+
if (!manager.isDatatypeSort(sort))
|
|
2469
|
+
throw new SmtParseError("pattern matching is only supported for algebraic datatypes", at);
|
|
2470
|
+
const constructors = getDatatypeConstructors(manager, sort);
|
|
2471
|
+
if (!patterns.some((pattern) => manager.kinds[pattern] === KIND_VAR)) {
|
|
2472
|
+
if (patterns.length < constructors.length)
|
|
2473
|
+
throw new SmtParseError("non-exhaustive pattern match", at);
|
|
2474
|
+
const marked = new Set(patterns.map((pattern) => manager.decls[pattern]));
|
|
2475
|
+
if (constructors.some((constructor) => !marked.has(constructor)))
|
|
2476
|
+
throw new SmtParseError("a constructor is missing from pattern match", at);
|
|
2477
|
+
}
|
|
2478
|
+
const subst = new VarSubst(manager, false);
|
|
2479
|
+
let result = -1;
|
|
2480
|
+
for (let index = patterns.length - 1; index >= 0; index--) {
|
|
2481
|
+
const pattern = patterns[index];
|
|
2482
|
+
const isVar = manager.kinds[pattern] === KIND_VAR;
|
|
2483
|
+
const recognizer = isVar ? -1 : getConstructorIs(manager, manager.decls[pattern]);
|
|
2484
|
+
const accessors = isVar ? [] : getConstructorAccessors(manager, manager.decls[pattern]);
|
|
2485
|
+
const shifted = shiftFreeVars(term, isVar ? 1 : accessors.length);
|
|
2486
|
+
manager.incRef(shifted);
|
|
2487
|
+
const substitution = isVar
|
|
2488
|
+
? [shifted]
|
|
2489
|
+
: accessors.map((accessor) =>
|
|
2490
|
+
manager.mkApp(accessor, [shifted], manager.funcDecls[accessor].range),
|
|
2491
|
+
);
|
|
2492
|
+
for (const expr of substitution) manager.incRef(expr);
|
|
2493
|
+
const condition = isVar ? manager.trueExpr : manager.mkApp(recognizer, [term], SORT_BOOL);
|
|
2494
|
+
manager.incRef(condition);
|
|
2495
|
+
manager.decRef(shifted);
|
|
2496
|
+
const substituted = subst.apply(bodies[index], substitution);
|
|
2497
|
+
const shifter = new InvVarShifter(manager);
|
|
2498
|
+
const body = shifter.shift(substituted, substitution.length);
|
|
2499
|
+
manager.decRef(substituted);
|
|
2500
|
+
shifter.release();
|
|
2501
|
+
const args = [condition, body, result];
|
|
2502
|
+
const next = result === -1 ? body : mkApp(OP_ITE, args, at, getDomainSort(OP_ITE, args, at));
|
|
2503
|
+
manager.incRef(next);
|
|
2504
|
+
if (result !== -1) manager.decRef(result);
|
|
2505
|
+
result = next;
|
|
2506
|
+
manager.decRef(body);
|
|
2507
|
+
manager.decRef(condition);
|
|
2508
|
+
for (const expr of substitution) manager.decRef(expr);
|
|
2509
|
+
}
|
|
2510
|
+
subst.release();
|
|
2511
|
+
return result;
|
|
1915
2512
|
};
|
|
1916
2513
|
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
2514
|
+
// parse_expr. Z3 leaves the term on its stack until the command ends. A tail term is one whose
|
|
2515
|
+
// value is the value of the whole: it stays off the stack, in parsed, so that the caller of
|
|
2516
|
+
// parseTerm can have a term that nothing else holds without a reference of the parser's.
|
|
2517
|
+
const runTerm = (sexpr: SExpr, isRootTail: boolean) => {
|
|
2518
|
+
const root = sexpr.kind === "list" ? sexpr.root : undefined;
|
|
2519
|
+
if (root === undefined || root === parsed.root) protect(floating);
|
|
2520
|
+
else {
|
|
2521
|
+
releasePending();
|
|
2522
|
+
shrink(floating, 0);
|
|
2523
|
+
parsed.root = root;
|
|
2524
|
+
}
|
|
2525
|
+
protect(unrooted);
|
|
2526
|
+
const frames: TermFrame[] = [];
|
|
2527
|
+
// The value of a frame replaces what the frame left on the stack. Z3 holds it in an expr_ref
|
|
2528
|
+
// meanwhile.
|
|
2529
|
+
const deliver = (expr: number, isTail: boolean, start: number) => {
|
|
2530
|
+
const isOwned = !isTail || manager.getRefCount(expr) > 0;
|
|
2531
|
+
if (isOwned) manager.incRef(expr);
|
|
2532
|
+
shrinkRefs(exprStack, start);
|
|
2533
|
+
if (!isTail) {
|
|
2534
|
+
exprStack.push(expr);
|
|
2535
|
+
return;
|
|
2536
|
+
}
|
|
2537
|
+
parsed.expr = expr;
|
|
2538
|
+
parsed.isOwned = isOwned;
|
|
2539
|
+
};
|
|
2540
|
+
// push_pattern_frame.
|
|
2541
|
+
const enterPattern = (value: SExpr, frame: AttributeFrame) => {
|
|
2542
|
+
if (value.kind !== "list") {
|
|
2543
|
+
if (!options.isIgnoringBadPatterns)
|
|
2544
|
+
throw new SmtParseError("invalid pattern, '(' expected", value);
|
|
2545
|
+
// Z3 skips a bad pattern as an s-expression, which cannot start with ')'.
|
|
2546
|
+
if (value.kind === ")")
|
|
2547
|
+
throw new SmtParseError("invalid s-expression, unexpected ')'", value);
|
|
2548
|
+
expectClosed(value);
|
|
2549
|
+
frame.next++;
|
|
2550
|
+
exprStack.push(-1);
|
|
2551
|
+
return;
|
|
2552
|
+
}
|
|
2553
|
+
frame.next++;
|
|
2554
|
+
const first = value.items[0];
|
|
2555
|
+
if (first === undefined) {
|
|
2556
|
+
exprStack.push(-1);
|
|
2557
|
+
return;
|
|
2558
|
+
}
|
|
2559
|
+
if (first.kind === "list") {
|
|
2560
|
+
frames.push({ kind: "pattern", list: value, start: exprStack.length, next: 0 });
|
|
2561
|
+
return;
|
|
2562
|
+
}
|
|
2563
|
+
const decl = first.text === "true" || first.text === "false" ? -1 : getFirstFunc(first.text);
|
|
2564
|
+
if (decl === -1 || (decl !== undefined && manager.funcDecls[decl].domain.length === 0)) {
|
|
2565
|
+
if (!options.isIgnoringBadPatterns)
|
|
2566
|
+
throw new SmtParseError("invalid constant pattern", first);
|
|
2567
|
+
exprStack.push(-1);
|
|
2568
|
+
return;
|
|
2569
|
+
}
|
|
2570
|
+
if (first.kind !== "symbol")
|
|
2571
|
+
throw new SmtParseError("invalid pattern, '(' or identifier expected", first);
|
|
2572
|
+
frames.push({
|
|
2573
|
+
kind: "application",
|
|
2574
|
+
list: value,
|
|
2575
|
+
head: first,
|
|
2576
|
+
indices: [],
|
|
2577
|
+
isTail: false,
|
|
2578
|
+
start: exprStack.length,
|
|
2579
|
+
next: 1,
|
|
2580
|
+
});
|
|
2581
|
+
};
|
|
2582
|
+
const enter = (current: SExpr, isTail: boolean) => {
|
|
1921
2583
|
if (current.kind !== "list") {
|
|
1922
|
-
|
|
2584
|
+
deliver(parseLeaf(current), isTail, exprStack.length);
|
|
1923
2585
|
return;
|
|
1924
2586
|
}
|
|
1925
2587
|
const head = current.items[0];
|
|
1926
|
-
if (head === undefined)
|
|
1927
|
-
throw new SmtParseError("invalid expression,
|
|
2588
|
+
if (head === undefined || (head.kind !== "symbol" && head.kind !== "list"))
|
|
2589
|
+
throw new SmtParseError("invalid expression, '(' or symbol expected", head ?? current.end);
|
|
1928
2590
|
if (head.kind === "list") {
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
if (
|
|
1932
|
-
hasArrays &&
|
|
1933
|
-
isSymbol(head.items[0], "as") &&
|
|
1934
|
-
isSymbol(name, "const") &&
|
|
1935
|
-
head.items.length === 3
|
|
1936
|
-
) {
|
|
1937
|
-
const sort = parseSort(head.items[2], "");
|
|
1938
|
-
frames.push({
|
|
1939
|
-
head: name,
|
|
1940
|
-
indices: [],
|
|
1941
|
-
build: (args) => mkArrayTerm(OP_CONST_ARRAY, args, [sort], current.end),
|
|
1942
|
-
list: current,
|
|
1943
|
-
start: results.length,
|
|
1944
|
-
next: 1,
|
|
1945
|
-
});
|
|
1946
|
-
return;
|
|
1947
|
-
}
|
|
1948
|
-
if (
|
|
1949
|
-
hasArrays &&
|
|
1950
|
-
hasArrayExtensions &&
|
|
1951
|
-
isSymbol(head.items[0], "_") &&
|
|
1952
|
-
isSymbol(name, "map") &&
|
|
1953
|
-
head.items.length === 3
|
|
1954
|
-
) {
|
|
1955
|
-
const mapped = parseFuncDeclRef(head.items[2]);
|
|
1956
|
-
frames.push({
|
|
1957
|
-
head: name,
|
|
1958
|
-
indices: [],
|
|
1959
|
-
build: (args) => mkMapTerm(mapped, args, current.end),
|
|
1960
|
-
list: current,
|
|
1961
|
-
start: results.length,
|
|
1962
|
-
next: 1,
|
|
1963
|
-
});
|
|
1964
|
-
return;
|
|
1965
|
-
}
|
|
1966
|
-
const indexed = head.items[2];
|
|
1967
|
-
if (
|
|
1968
|
-
isSymbol(head.items[0], "_") &&
|
|
1969
|
-
(isSymbol(name, "is") || isSymbol(name, "update-field")) &&
|
|
1970
|
-
isSymbol(indexed) &&
|
|
1971
|
-
head.items.length === 3
|
|
1972
|
-
) {
|
|
1973
|
-
frames.push({
|
|
1974
|
-
head: name,
|
|
1975
|
-
indices: [],
|
|
1976
|
-
build: (args) =>
|
|
1977
|
-
name.text === "is"
|
|
1978
|
-
? mkIsApp(indexed, args, current.end)
|
|
1979
|
-
: mkUpdateFieldApp(indexed, args, current.end),
|
|
1980
|
-
list: current,
|
|
1981
|
-
start: results.length,
|
|
1982
|
-
next: 1,
|
|
1983
|
-
});
|
|
1984
|
-
return;
|
|
1985
|
-
}
|
|
1986
|
-
if (isSymbol(head.items[0], "as") && isSymbol(name) && head.items.length === 3) {
|
|
1987
|
-
const range = parseSort(head.items[2], "Invalid qualified identifier");
|
|
1988
|
-
frames.push({
|
|
1989
|
-
head: name,
|
|
1990
|
-
indices: [],
|
|
1991
|
-
build: (args) => parseApp(name, args, current.end, [], range),
|
|
1992
|
-
list: current,
|
|
1993
|
-
start: results.length,
|
|
1994
|
-
next: 1,
|
|
1995
|
-
});
|
|
1996
|
-
return;
|
|
1997
|
-
}
|
|
1998
|
-
if (
|
|
1999
|
-
isSymbol(head.items[0], "_") &&
|
|
2000
|
-
isSymbol(name) &&
|
|
2001
|
-
isPbOpName(name.text) &&
|
|
2002
|
-
indices.every((index) => index.kind === "numeral")
|
|
2003
|
-
) {
|
|
2004
|
-
const parameters = indices.map((index) =>
|
|
2005
|
-
Rational.of(BigInt(index.kind === "list" ? 0 : index.text)),
|
|
2006
|
-
);
|
|
2007
|
-
frames.push({
|
|
2008
|
-
head: name,
|
|
2009
|
-
indices: [],
|
|
2010
|
-
build: (args) => mkPbTerm(name.text, args, parameters, current.end),
|
|
2011
|
-
list: current,
|
|
2012
|
-
start: results.length,
|
|
2013
|
-
next: 1,
|
|
2014
|
-
});
|
|
2015
|
-
return;
|
|
2016
|
-
}
|
|
2017
|
-
if (
|
|
2018
|
-
!isSymbol(head.items[0], "_") ||
|
|
2019
|
-
!isSymbol(name) ||
|
|
2020
|
-
!(isBvOpName(name.text) || isFpaOpName(name.text) || isSeqOpName(name.text)) ||
|
|
2021
|
-
!indices.every((index) => index.kind === "numeral")
|
|
2022
|
-
)
|
|
2591
|
+
// push_app_frame: Z3 reads a head that is neither indexed nor qualified as a term.
|
|
2592
|
+
if (isSymbol(head.items[0], "lambda"))
|
|
2023
2593
|
throw new SmtUnsupportedError("indexed and qualified identifiers");
|
|
2594
|
+
frames.push(
|
|
2595
|
+
isSymbol(head.items[0], "_") || isSymbol(head.items[0], "as")
|
|
2596
|
+
? {
|
|
2597
|
+
kind: "application",
|
|
2598
|
+
list: current,
|
|
2599
|
+
...parseQualifiedHead(current, head),
|
|
2600
|
+
isTail,
|
|
2601
|
+
start: exprStack.length,
|
|
2602
|
+
next: 1,
|
|
2603
|
+
}
|
|
2604
|
+
: { kind: "selection", list: current, isTail, start: exprStack.length, next: 0 },
|
|
2605
|
+
);
|
|
2606
|
+
return;
|
|
2607
|
+
}
|
|
2608
|
+
if (head.text === "_" || head.text === "as") {
|
|
2609
|
+
deliver(parseQualifiedName(current), isTail, exprStack.length);
|
|
2610
|
+
return;
|
|
2611
|
+
}
|
|
2612
|
+
if (head.text === "root-obj") {
|
|
2613
|
+
deliver(parseRootObj(current), isTail, exprStack.length);
|
|
2614
|
+
return;
|
|
2615
|
+
}
|
|
2616
|
+
if (head.text === "match") {
|
|
2024
2617
|
frames.push({
|
|
2025
|
-
|
|
2026
|
-
indices: indices.map((index) => (index.kind === "list" ? 0 : Number(index.text))),
|
|
2618
|
+
kind: "match",
|
|
2027
2619
|
list: current,
|
|
2028
|
-
|
|
2029
|
-
|
|
2620
|
+
cases: [],
|
|
2621
|
+
isCaseForm: false,
|
|
2622
|
+
depth: -1,
|
|
2623
|
+
isTail,
|
|
2624
|
+
start: exprStack.length,
|
|
2625
|
+
next: -1,
|
|
2030
2626
|
});
|
|
2627
|
+
enter(current.items[1] ?? current.end, false);
|
|
2031
2628
|
return;
|
|
2032
2629
|
}
|
|
2033
|
-
if (head.
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2630
|
+
if (head.text === "let") {
|
|
2631
|
+
const bindings = current.items[1];
|
|
2632
|
+
if (bindings?.kind !== "list")
|
|
2633
|
+
throw new SmtParseError(
|
|
2634
|
+
`invalid let declaration, '(' expected got ${(bindings ?? current.end).lastId}`,
|
|
2635
|
+
bindings ?? current.end,
|
|
2636
|
+
);
|
|
2637
|
+
frames.push({
|
|
2638
|
+
kind: "let",
|
|
2639
|
+
list: current,
|
|
2640
|
+
bindings,
|
|
2641
|
+
names: [],
|
|
2642
|
+
isInDecls: true,
|
|
2643
|
+
isTail,
|
|
2644
|
+
start: exprStack.length,
|
|
2645
|
+
next: 0,
|
|
2646
|
+
});
|
|
2037
2647
|
return;
|
|
2038
2648
|
}
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
);
|
|
2649
|
+
if (head.text === "!") {
|
|
2650
|
+
const parent = frames[frames.length - 1];
|
|
2651
|
+
frames.push({
|
|
2652
|
+
kind: "attribute",
|
|
2653
|
+
list: current,
|
|
2654
|
+
quantifier: parent?.kind === "quantifier" ? parent : undefined,
|
|
2655
|
+
lastKeyword: "",
|
|
2656
|
+
isTail,
|
|
2657
|
+
start: exprStack.length,
|
|
2658
|
+
next: 1,
|
|
2659
|
+
});
|
|
2050
2660
|
return;
|
|
2051
2661
|
}
|
|
2052
|
-
|
|
2053
|
-
|
|
2662
|
+
const quantifierKind = QUANTIFIER_KINDS.get(head.text);
|
|
2663
|
+
if (quantifierKind === undefined) {
|
|
2664
|
+
frames.push({
|
|
2665
|
+
kind: "application",
|
|
2666
|
+
list: current,
|
|
2667
|
+
head,
|
|
2668
|
+
indices: [],
|
|
2669
|
+
isTail,
|
|
2670
|
+
start: exprStack.length,
|
|
2671
|
+
next: 1,
|
|
2672
|
+
});
|
|
2054
2673
|
return;
|
|
2055
2674
|
}
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2675
|
+
// push_quant_frame.
|
|
2676
|
+
const start = exprStack.length;
|
|
2677
|
+
const bound = bindSortedVars(current.items[1], current.end);
|
|
2678
|
+
if (bound.varSorts.length === 0)
|
|
2679
|
+
throw new SmtParseError(
|
|
2680
|
+
"invalid quantifier, list of sorted variables is empty",
|
|
2681
|
+
current.items[2] ?? current.end,
|
|
2682
|
+
);
|
|
2683
|
+
frames.push({
|
|
2684
|
+
kind: "quantifier",
|
|
2685
|
+
list: current,
|
|
2686
|
+
quantifierKind,
|
|
2687
|
+
names: bound.names,
|
|
2688
|
+
varSorts: bound.varSorts,
|
|
2689
|
+
weight: 1,
|
|
2690
|
+
qid: "",
|
|
2691
|
+
skid: undefined,
|
|
2692
|
+
isTail,
|
|
2693
|
+
start,
|
|
2694
|
+
patternStart: patternStack.length,
|
|
2695
|
+
noPatternStart: noPatternStack.length,
|
|
2696
|
+
next: 2,
|
|
2697
|
+
});
|
|
2061
2698
|
};
|
|
2062
|
-
enter(sexpr);
|
|
2699
|
+
enter(sexpr, isRootTail);
|
|
2063
2700
|
while (frames.length > 0) {
|
|
2064
2701
|
const frame = frames[frames.length - 1];
|
|
2065
|
-
if (frame.
|
|
2066
|
-
|
|
2702
|
+
if (frame.kind === "let") {
|
|
2703
|
+
if (frame.isInDecls) {
|
|
2704
|
+
const declaration = frame.bindings.items[frame.next];
|
|
2705
|
+
if (declaration !== undefined) {
|
|
2706
|
+
// push_let_decl_frame.
|
|
2707
|
+
if (declaration.kind !== "list")
|
|
2708
|
+
throw new SmtParseError(
|
|
2709
|
+
`invalid let declaration, '(' expected got ${declaration.lastId}`,
|
|
2710
|
+
declaration,
|
|
2711
|
+
);
|
|
2712
|
+
const name = declaration.items[0];
|
|
2713
|
+
if (!isSymbol(name)) throw new SmtParseError(LET_MESSAGE, name ?? declaration.end);
|
|
2714
|
+
frame.names.push(name.text);
|
|
2715
|
+
frame.next++;
|
|
2716
|
+
frames.push({ kind: "let-decl", list: declaration, next: 1 });
|
|
2717
|
+
continue;
|
|
2718
|
+
}
|
|
2719
|
+
// pop_let_frame at the end of the declarations.
|
|
2720
|
+
if (frame.names.length !== exprStack.length - frame.start)
|
|
2721
|
+
throw new SmtParseError("malformed let expression", frame.bindings.end);
|
|
2722
|
+
beginScope();
|
|
2723
|
+
for (const [index, name] of frame.names.entries())
|
|
2724
|
+
insertLocal(name, exprStack[frame.start + index]);
|
|
2725
|
+
frame.isInDecls = false;
|
|
2726
|
+
frame.next = 2;
|
|
2727
|
+
continue;
|
|
2728
|
+
}
|
|
2729
|
+
const body = frame.list.items[frame.next];
|
|
2730
|
+
if (body !== undefined) {
|
|
2731
|
+
frame.next++;
|
|
2732
|
+
enter(body, frame.isTail && frame.next === frame.list.items.length);
|
|
2733
|
+
continue;
|
|
2734
|
+
}
|
|
2735
|
+
frames.pop();
|
|
2736
|
+
// Z3 takes the last expression on its stack, so a let without a body is its last binding.
|
|
2737
|
+
if (frame.isTail && frame.list.items.length > 2) shrinkRefs(exprStack, frame.start);
|
|
2738
|
+
else if (exprStack.length === frame.start)
|
|
2739
|
+
throw new SmtParseError("invalid let expression", frame.list.end);
|
|
2740
|
+
else deliver(exprStack[exprStack.length - 1], frame.isTail, frame.start);
|
|
2741
|
+
endScope();
|
|
2742
|
+
continue;
|
|
2743
|
+
}
|
|
2744
|
+
const items = frame.list.items;
|
|
2745
|
+
if (frame.kind === "match") {
|
|
2746
|
+
if (frame.next === -1) {
|
|
2747
|
+
const bindings = items[2] ?? frame.list.end;
|
|
2748
|
+
if (bindings.kind !== "list")
|
|
2749
|
+
throw new SmtParseError(
|
|
2750
|
+
`pattern bindings should be enclosed in a parenthesis got ${bindings.lastId}`,
|
|
2751
|
+
bindings,
|
|
2752
|
+
);
|
|
2753
|
+
// curr_id_is_case reads the last identifier, which a '(' leaves as it was.
|
|
2754
|
+
frame.isCaseForm = (bindings.items[0] ?? bindings.end).lastId === "case";
|
|
2755
|
+
frame.cases = frame.isCaseForm ? items.slice(2) : bindings.items;
|
|
2756
|
+
frame.next = 0;
|
|
2757
|
+
} else if (frame.depth !== -1) {
|
|
2758
|
+
binders.depth = frame.depth;
|
|
2759
|
+
frame.depth = -1;
|
|
2760
|
+
endScope();
|
|
2761
|
+
const binding = frame.cases[frame.next - 1];
|
|
2762
|
+
const extra =
|
|
2763
|
+
binding.kind === "list" ? binding.items[frame.isCaseForm ? 3 : 2] : undefined;
|
|
2764
|
+
if (extra !== undefined)
|
|
2765
|
+
throw new SmtParseError(
|
|
2766
|
+
`invalid pattern binding, ')' expected got ${extra.lastId}`,
|
|
2767
|
+
extra,
|
|
2768
|
+
);
|
|
2769
|
+
}
|
|
2770
|
+
const binding = frame.cases[frame.next];
|
|
2771
|
+
if (binding !== undefined) {
|
|
2772
|
+
if (frame.isCaseForm && !(binding.kind === "list" && isSymbol(binding.items[0], "case")))
|
|
2773
|
+
throw new SmtUnsupportedError("the terms after the cases of match");
|
|
2774
|
+
if (binding.kind !== "list")
|
|
2775
|
+
throw new SmtParseError(
|
|
2776
|
+
`invalid pattern binding, '(' expected got ${binding.lastId}`,
|
|
2777
|
+
binding,
|
|
2778
|
+
);
|
|
2779
|
+
frame.next++;
|
|
2780
|
+
beginScope();
|
|
2781
|
+
frame.depth = binders.depth;
|
|
2782
|
+
const offset = frame.isCaseForm ? 1 : 0;
|
|
2783
|
+
const body = binding.items[offset + 1] ?? binding.end;
|
|
2784
|
+
const sort = manager.sorts[exprStack[frame.start]];
|
|
2785
|
+
pushRef(exprStack, parseMatchPattern(binding.items[offset] ?? binding.end, sort, body));
|
|
2786
|
+
enter(body, false);
|
|
2787
|
+
continue;
|
|
2788
|
+
}
|
|
2789
|
+
if (!frame.isCaseForm && items.length > 3)
|
|
2790
|
+
throw new SmtUnsupportedError("the terms after the cases of match");
|
|
2791
|
+
frames.pop();
|
|
2792
|
+
const term = exprStack[frame.start];
|
|
2793
|
+
const cases = exprStack.slice(frame.start + 1);
|
|
2794
|
+
const patterns = cases.filter((_expr, index) => index % 2 === 0);
|
|
2795
|
+
const bodies = cases.filter((_expr, index) => index % 2 === 1);
|
|
2796
|
+
const result = compileMatch(term, patterns, bodies, frame.list.end);
|
|
2797
|
+
// push_match_frame releases the bodies, then the patterns, then the term.
|
|
2798
|
+
exprStack.splice(frame.start, cases.length + 1, ...bodies, ...patterns, term);
|
|
2799
|
+
deliver(result, frame.isTail, frame.start);
|
|
2800
|
+
manager.decRef(result);
|
|
2801
|
+
continue;
|
|
2802
|
+
}
|
|
2803
|
+
if (frame.kind === "attribute") {
|
|
2804
|
+
// consume_attributes.
|
|
2805
|
+
if (exprStack.length === frame.start) {
|
|
2806
|
+
if (frame.next >= items.length)
|
|
2807
|
+
throw new SmtParseError("invalid expression", frame.list.end);
|
|
2808
|
+
enter(items[frame.next++], false);
|
|
2809
|
+
continue;
|
|
2810
|
+
}
|
|
2811
|
+
// process_last_symbol.
|
|
2812
|
+
const last = exprStack[exprStack.length - 1];
|
|
2813
|
+
if (frame.lastKeyword === ":pattern") {
|
|
2814
|
+
const at = items[frame.next] ?? frame.list.end;
|
|
2815
|
+
if (last === -1 && !options.isIgnoringBadPatterns)
|
|
2816
|
+
throw new SmtParseError("invalid empty pattern", at);
|
|
2817
|
+
if (last !== -1)
|
|
2818
|
+
pushRef(
|
|
2819
|
+
patternStack,
|
|
2820
|
+
manager.kinds[last] === KIND_APP && manager.decls[last] === OP_PATTERN
|
|
2821
|
+
? last
|
|
2822
|
+
: mkPattern([last], at),
|
|
2823
|
+
);
|
|
2824
|
+
shrinkRefs(exprStack, exprStack.length - 1);
|
|
2825
|
+
} else if (frame.lastKeyword === ":no-pattern") {
|
|
2826
|
+
pushRef(noPatternStack, last);
|
|
2827
|
+
shrinkRefs(exprStack, exprStack.length - 1);
|
|
2828
|
+
}
|
|
2829
|
+
frame.lastKeyword = "";
|
|
2830
|
+
if (frame.next >= items.length) {
|
|
2831
|
+
frames.pop();
|
|
2832
|
+
if (frame.isTail) deliver(exprStack[exprStack.length - 1], true, frame.start);
|
|
2833
|
+
continue;
|
|
2834
|
+
}
|
|
2835
|
+
while (frame.next < items.length && frame.lastKeyword === "") {
|
|
2836
|
+
const keyword = items[frame.next];
|
|
2837
|
+
if (keyword.kind !== "keyword")
|
|
2838
|
+
throw new SmtParseError("invalid attributed expression, keyword expected", keyword);
|
|
2839
|
+
const value = items[frame.next + 1] ?? frame.list.end;
|
|
2840
|
+
const annotated = exprStack[exprStack.length - 1];
|
|
2841
|
+
const quantifier = frame.quantifier;
|
|
2842
|
+
if (keyword.text === ":named") {
|
|
2843
|
+
if (!isSymbol(value))
|
|
2844
|
+
throw new SmtParseError("invalid attribute value, symbol expected", value);
|
|
2845
|
+
nameExpr(annotated, value.text, items[frame.next + 2] ?? frame.list.end);
|
|
2846
|
+
frame.next += 2;
|
|
2847
|
+
} else if (keyword.text === ":lblpos" || keyword.text === ":lblneg") {
|
|
2848
|
+
if (!isSymbol(value))
|
|
2849
|
+
throw new SmtParseError("invalid attribute value, symbol expected", value);
|
|
2850
|
+
if (manager.sorts[annotated] !== SORT_BOOL)
|
|
2851
|
+
throw new SmtParseError(
|
|
2852
|
+
"invalid labeled expression, expression must have Bool sort",
|
|
2853
|
+
value,
|
|
2854
|
+
);
|
|
2855
|
+
deliver(
|
|
2856
|
+
manager.mkLabel(keyword.text === ":lblpos", [value.text], annotated),
|
|
2857
|
+
false,
|
|
2858
|
+
exprStack.length - 1,
|
|
2859
|
+
);
|
|
2860
|
+
frame.next += 2;
|
|
2861
|
+
} else if (!QUANTIFIER_ATTRIBUTES.has(keyword.text)) {
|
|
2862
|
+
// Z3 warns of an unknown attribute and skips its value as an s-expression.
|
|
2863
|
+
if (value.kind === ")")
|
|
2864
|
+
throw new SmtParseError("invalid s-expression, unexpected ')'", value);
|
|
2865
|
+
expectClosed(value);
|
|
2866
|
+
frame.next += 2;
|
|
2867
|
+
} else if (quantifier === undefined)
|
|
2868
|
+
throw new SmtParseError("invalid attribute, not in the scope of a quantifier", keyword);
|
|
2869
|
+
else if (keyword.text === ":weight") {
|
|
2870
|
+
// check_int, and curr_unsigned.
|
|
2871
|
+
if (value.kind !== "numeral")
|
|
2872
|
+
throw new SmtParseError("invalid weight attribute, integer expected", value);
|
|
2873
|
+
if (!isUnsigned(value.text))
|
|
2874
|
+
throw new SmtParseError(
|
|
2875
|
+
"invalid indexed identifier, index is too big to fit in an unsigned machine integer",
|
|
2876
|
+
value,
|
|
2877
|
+
);
|
|
2878
|
+
quantifier.weight = Number(value.text);
|
|
2879
|
+
frame.next += 2;
|
|
2880
|
+
} else if (keyword.text === ":skolemid" || keyword.text === ":qid") {
|
|
2881
|
+
if (!isSymbol(value))
|
|
2882
|
+
throw new SmtParseError("invalid attribute value, symbol expected", value);
|
|
2883
|
+
if (keyword.text === ":qid") quantifier.qid = value.text;
|
|
2884
|
+
else quantifier.skid = value.text;
|
|
2885
|
+
frame.next += 2;
|
|
2886
|
+
} else {
|
|
2887
|
+
frame.lastKeyword = keyword.text;
|
|
2888
|
+
frame.next++;
|
|
2889
|
+
if (keyword.text === ":pattern") enterPattern(value, frame);
|
|
2890
|
+
else if (value.kind === ")")
|
|
2891
|
+
throw new SmtParseError("invalid expression, unexpected input", value);
|
|
2892
|
+
else enter(items[frame.next++], false);
|
|
2893
|
+
}
|
|
2894
|
+
}
|
|
2895
|
+
continue;
|
|
2896
|
+
}
|
|
2897
|
+
if (frame.next < items.length) {
|
|
2898
|
+
enter(items[frame.next++], false);
|
|
2067
2899
|
continue;
|
|
2068
2900
|
}
|
|
2069
2901
|
frames.pop();
|
|
2070
|
-
if (frame.
|
|
2902
|
+
if (frame.kind === "let-decl") continue;
|
|
2903
|
+
if (frame.kind === "pattern") {
|
|
2904
|
+
deliver(mkPattern(exprStack.slice(frame.start), frame.list.end), false, frame.start);
|
|
2905
|
+
continue;
|
|
2906
|
+
}
|
|
2907
|
+
if (frame.kind === "quantifier") {
|
|
2908
|
+
// pop_quant_frame.
|
|
2909
|
+
deliver(mkParsedQuantifier(frame), frame.isTail, frame.start);
|
|
2910
|
+
shrinkRefs(patternStack, frame.patternStart);
|
|
2911
|
+
shrinkRefs(noPatternStack, frame.noPatternStart);
|
|
2912
|
+
unbindSortedVars(frame.varSorts.length);
|
|
2913
|
+
continue;
|
|
2914
|
+
}
|
|
2915
|
+
// pop_app_frame.
|
|
2916
|
+
const args = exprStack.slice(frame.start);
|
|
2917
|
+
if (args.length < (frame.kind === "selection" ? 2 : 1))
|
|
2071
2918
|
throw new SmtParseError("invalid function application, arguments missing", frame.list.end);
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2919
|
+
deliver(
|
|
2920
|
+
frame.kind === "selection"
|
|
2921
|
+
? args
|
|
2922
|
+
.slice(1)
|
|
2923
|
+
.reduce(
|
|
2924
|
+
(array, arg) => mkArrayTerm(OP_SELECT, [array, arg], [], frame.list.end),
|
|
2925
|
+
args[0],
|
|
2926
|
+
)
|
|
2927
|
+
: (frame.build?.(args) ?? parseApp(frame.head, args, frame.list.end, frame.indices)),
|
|
2928
|
+
frame.isTail,
|
|
2929
|
+
frame.start,
|
|
2075
2930
|
);
|
|
2076
2931
|
}
|
|
2077
|
-
return results[0];
|
|
2078
2932
|
};
|
|
2079
2933
|
|
|
2080
|
-
const
|
|
2934
|
+
const parseTerm = (sexpr: SExpr) => {
|
|
2935
|
+
runTerm(sexpr, true);
|
|
2936
|
+
const expr = parsed.expr;
|
|
2937
|
+
parsed.expr = -1;
|
|
2938
|
+
if (!parsed.isOwned)
|
|
2939
|
+
(sexpr.kind === "list" && sexpr.root !== undefined ? floating : unrooted).push(expr);
|
|
2940
|
+
else if (manager.getRefCount(expr) > 1) manager.decRef(expr);
|
|
2941
|
+
else pending.push(expr);
|
|
2942
|
+
return expr;
|
|
2943
|
+
};
|
|
2944
|
+
|
|
2945
|
+
const parseDomain = (sexpr: SExpr) => {
|
|
2081
2946
|
const context = "Parsing function declaration. Expecting sort list '('";
|
|
2082
|
-
return
|
|
2947
|
+
return expectListNext(sexpr, context).items.map((item) => parseSort(item, context));
|
|
2083
2948
|
};
|
|
2084
2949
|
|
|
2085
|
-
const parseSortParameters = (sexpr: SExpr
|
|
2086
|
-
|
|
2950
|
+
const parseSortParameters = (sexpr: SExpr, message: string) =>
|
|
2951
|
+
expectListNext(sexpr, "invalid sort declaration, parameters missing").items.map(
|
|
2087
2952
|
(item) => expectSymbol(item, message, item).text,
|
|
2088
2953
|
);
|
|
2089
2954
|
|
|
@@ -2097,8 +2962,12 @@ export const createSmtlibReader = (
|
|
|
2097
2962
|
missing: string[],
|
|
2098
2963
|
) => {
|
|
2099
2964
|
if (sexpr.kind === "list") return parseSort(sexpr, "", bindings);
|
|
2965
|
+
if (sexpr.kind === ")") throw new SmtParseError("invalid sort, unexpected ')'", sexpr);
|
|
2100
2966
|
if (sexpr.kind !== "symbol")
|
|
2101
|
-
throw new SmtParseError(
|
|
2967
|
+
throw new SmtParseError(
|
|
2968
|
+
`invalid sort, symbol, '_' or '(' expected got ${sexpr.lastId}`,
|
|
2969
|
+
sexpr,
|
|
2970
|
+
);
|
|
2102
2971
|
if (sortDecls.has(sexpr.text) || bindings.has(sexpr.text))
|
|
2103
2972
|
return parseSort(sexpr, "", bindings);
|
|
2104
2973
|
const index = datatypeIndexes.get(sexpr.text);
|
|
@@ -2121,21 +2990,16 @@ export const createSmtlibReader = (
|
|
|
2121
2990
|
);
|
|
2122
2991
|
return items.map((item) => {
|
|
2123
2992
|
if (isSymbol(item)) return { name: item.text, recognizer: `is-${item.text}`, accessors: [] };
|
|
2124
|
-
const constructor =
|
|
2125
|
-
item,
|
|
2126
|
-
"invalid datatype declaration, '(' or ')' expected",
|
|
2127
|
-
item,
|
|
2128
|
-
);
|
|
2993
|
+
const constructor = expectListNext(item, "invalid datatype declaration, '(' or ')' expected");
|
|
2129
2994
|
const name = expectSymbol(
|
|
2130
2995
|
constructor.items[0],
|
|
2131
2996
|
"invalid constructor declaration, symbol (constructor name) expected",
|
|
2132
2997
|
constructor,
|
|
2133
2998
|
).text;
|
|
2134
2999
|
const accessors = constructor.items.slice(1).map((accessorItem) => {
|
|
2135
|
-
const accessor =
|
|
3000
|
+
const accessor = expectListNext(
|
|
2136
3001
|
accessorItem,
|
|
2137
3002
|
"invalid datatype declaration, '(' or ')' expected",
|
|
2138
|
-
accessorItem,
|
|
2139
3003
|
);
|
|
2140
3004
|
const accessorName = expectSymbol(
|
|
2141
3005
|
accessor.items[0],
|
|
@@ -2149,7 +3013,10 @@ export const createSmtlibReader = (
|
|
|
2149
3013
|
missing,
|
|
2150
3014
|
);
|
|
2151
3015
|
if (accessor.items.length > 2)
|
|
2152
|
-
throw new SmtParseError(
|
|
3016
|
+
throw new SmtParseError(
|
|
3017
|
+
`invalid accessor declaration, ')' expected got ${accessor.items[2].lastId}`,
|
|
3018
|
+
accessor.items[2],
|
|
3019
|
+
);
|
|
2153
3020
|
return { name: accessorName, range };
|
|
2154
3021
|
});
|
|
2155
3022
|
return { name, recognizer: `is-${name}`, accessors };
|
|
@@ -2157,27 +3024,29 @@ export const createSmtlibReader = (
|
|
|
2157
3024
|
};
|
|
2158
3025
|
|
|
2159
3026
|
const parseDatatypeBody = (
|
|
2160
|
-
sexpr: SExpr
|
|
3027
|
+
sexpr: SExpr,
|
|
2161
3028
|
datatypeIndexes: ReadonlyMap<string, number>,
|
|
2162
3029
|
missing: string[],
|
|
2163
|
-
|
|
3030
|
+
name?: string,
|
|
2164
3031
|
) => {
|
|
2165
|
-
const body =
|
|
2166
|
-
if (!isSymbol(body.items[0], "par"))
|
|
3032
|
+
const body = expectListNext(sexpr, "invalid datatype declaration, '(' expected");
|
|
3033
|
+
if (!isSymbol(body.items[0], "par")) {
|
|
3034
|
+
if (name !== undefined) declareDatatypeSort(name, 0, body.items[0] ?? body.end);
|
|
2167
3035
|
return {
|
|
2168
3036
|
parameters: [],
|
|
2169
3037
|
constructors: parseConstructors(body.items, NO_BINDINGS, datatypeIndexes, missing, body),
|
|
2170
3038
|
};
|
|
3039
|
+
}
|
|
2171
3040
|
const parameters = parseSortParameters(
|
|
2172
|
-
body.items[1],
|
|
3041
|
+
body.items[1] ?? body.end,
|
|
2173
3042
|
"invalid sort parameter, symbol or ')' expected",
|
|
2174
|
-
body,
|
|
2175
3043
|
);
|
|
2176
|
-
const constructors =
|
|
2177
|
-
body.items[2],
|
|
3044
|
+
const constructors = expectListNext(
|
|
3045
|
+
body.items[2] ?? body.end,
|
|
2178
3046
|
"invalid constructor declaration after par, '(' expected",
|
|
2179
|
-
body,
|
|
2180
3047
|
);
|
|
3048
|
+
if (name !== undefined && parameters.length > 0)
|
|
3049
|
+
declareDatatypeSort(name, parameters.length, constructors.items[0] ?? constructors.end);
|
|
2181
3050
|
return {
|
|
2182
3051
|
parameters: parameters.map((_name, index) => manager.mkTypeParameter(index)),
|
|
2183
3052
|
constructors: parseConstructors(
|
|
@@ -2217,11 +3086,17 @@ export const createSmtlibReader = (
|
|
|
2217
3086
|
declare(sortDecls, name, decl);
|
|
2218
3087
|
};
|
|
2219
3088
|
|
|
3089
|
+
const declareDatatypeSort = (name: string, arity: number, at: SExpr) =>
|
|
3090
|
+
declareSortDecl(
|
|
3091
|
+
name,
|
|
3092
|
+
{ kind: "datatype", name, arity, siblings: [], instances: new Map() },
|
|
3093
|
+
at,
|
|
3094
|
+
);
|
|
3095
|
+
|
|
2220
3096
|
const declareDatatypes = (list: SmtList) => {
|
|
2221
|
-
const declaration =
|
|
2222
|
-
list.items[1],
|
|
3097
|
+
const declaration = expectListNext(
|
|
3098
|
+
list.items[1] ?? list.end,
|
|
2223
3099
|
"invalid sort declaration, parameters missing",
|
|
2224
|
-
list,
|
|
2225
3100
|
);
|
|
2226
3101
|
const isSmt26 = declaration.items[0]?.kind === "list";
|
|
2227
3102
|
const datatypeIndexes = new Map<string, number>();
|
|
@@ -2235,11 +3110,11 @@ export const createSmtlibReader = (
|
|
|
2235
3110
|
);
|
|
2236
3111
|
return;
|
|
2237
3112
|
}
|
|
2238
|
-
const sortDeclaration =
|
|
3113
|
+
const sortDeclaration = expectListNext(item, "invalid sort declaration, '(' expected");
|
|
2239
3114
|
const name = expectSymbol(
|
|
2240
3115
|
sortDeclaration.items[0],
|
|
2241
3116
|
"invalid sort name, identified expected",
|
|
2242
|
-
sortDeclaration,
|
|
3117
|
+
sortDeclaration.end,
|
|
2243
3118
|
).text;
|
|
2244
3119
|
const arity = sortDeclaration.items[1];
|
|
2245
3120
|
if (arity?.kind !== "numeral")
|
|
@@ -2247,26 +3122,25 @@ export const createSmtlibReader = (
|
|
|
2247
3122
|
"invalid sort declaration, arity expected",
|
|
2248
3123
|
arity ?? sortDeclaration.end,
|
|
2249
3124
|
);
|
|
2250
|
-
if (sortDeclaration.items.length > 2)
|
|
2251
|
-
throw new SmtParseError("invalid sort declaration, ')' expected", sortDeclaration.items[2]);
|
|
2252
3125
|
datatypeIndexes.set(name, index);
|
|
2253
3126
|
names.push(name);
|
|
2254
3127
|
arities.push(Number(arity.text));
|
|
2255
|
-
|
|
3128
|
+
declareDatatypeSort(
|
|
2256
3129
|
name,
|
|
2257
|
-
|
|
2258
|
-
sortDeclaration,
|
|
3130
|
+
Number(arity.text),
|
|
3131
|
+
sortDeclaration.items[2] ?? sortDeclaration.end,
|
|
2259
3132
|
);
|
|
3133
|
+
if (sortDeclaration.items.length > 2)
|
|
3134
|
+
throw new SmtParseError("invalid sort declaration, ')' expected", sortDeclaration.items[2]);
|
|
2260
3135
|
});
|
|
2261
|
-
const bodies =
|
|
3136
|
+
const bodies = expectListNext(
|
|
3137
|
+
list.items[2] ?? list.end,
|
|
3138
|
+
"invalid datatype declaration, '(' expected",
|
|
3139
|
+
);
|
|
2262
3140
|
// A datatype of the older syntax may refer to any datatype of its declaration.
|
|
2263
3141
|
if (!isSmt26)
|
|
2264
3142
|
bodies.items.forEach((item, index) => {
|
|
2265
|
-
const datatype =
|
|
2266
|
-
item,
|
|
2267
|
-
"invalid datatype declaration, '(' or ')' expected",
|
|
2268
|
-
item,
|
|
2269
|
-
);
|
|
3143
|
+
const datatype = expectListNext(item, "invalid datatype declaration, '(' or ')' expected");
|
|
2270
3144
|
const name = expectSymbol(
|
|
2271
3145
|
datatype.items[0],
|
|
2272
3146
|
"invalid datatype declaration, symbol (datatype name) expected",
|
|
@@ -2291,10 +3165,10 @@ export const createSmtlibReader = (
|
|
|
2291
3165
|
Array.from({ length: arities[index] }, (_unused, parameter) =>
|
|
2292
3166
|
manager.mkTypeParameter(parameter),
|
|
2293
3167
|
),
|
|
2294
|
-
parseDatatypeBody(item, datatypeIndexes, missing
|
|
3168
|
+
parseDatatypeBody(item, datatypeIndexes, missing).constructors,
|
|
2295
3169
|
);
|
|
2296
3170
|
}
|
|
2297
|
-
const datatype =
|
|
3171
|
+
const datatype = expectListNext(item, "invalid datatype declaration, '(' or ')' expected");
|
|
2298
3172
|
return mkDatatypeDef(
|
|
2299
3173
|
manager,
|
|
2300
3174
|
names[index],
|
|
@@ -2327,32 +3201,25 @@ export const createSmtlibReader = (
|
|
|
2327
3201
|
};
|
|
2328
3202
|
|
|
2329
3203
|
const declareDatatype = (list: SmtList) => {
|
|
2330
|
-
const name = expectSymbol(list.items[1], "unexpected token used as datatype name", list);
|
|
3204
|
+
const name = expectSymbol(list.items[1], "unexpected token used as datatype name", list.end);
|
|
2331
3205
|
const missing: string[] = [];
|
|
2332
|
-
const
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
bodyList.items[1]?.kind === "list"
|
|
2337
|
-
? bodyList.items[1].items.length
|
|
2338
|
-
: 0;
|
|
2339
|
-
declareSortDecl(
|
|
3206
|
+
const body = parseDatatypeBody(
|
|
3207
|
+
list.items[2] ?? list.end,
|
|
3208
|
+
new Map([[name.text, 0]]),
|
|
3209
|
+
missing,
|
|
2340
3210
|
name.text,
|
|
2341
|
-
{ kind: "datatype", name: name.text, arity, siblings: [], instances: new Map() },
|
|
2342
|
-
name,
|
|
2343
3211
|
);
|
|
2344
|
-
const body = parseDatatypeBody(bodyList, new Map([[name.text, 0]]), missing, list);
|
|
2345
|
-
if (list.items.length > 3)
|
|
2346
|
-
throw new SmtParseError("invalid end of datatype declaration, ')' expected", list.items[3]);
|
|
2347
3212
|
commitDatatypes(
|
|
2348
3213
|
[mkDatatypeDef(manager, name.text, body.parameters, body.constructors)],
|
|
2349
3214
|
missing,
|
|
2350
3215
|
name,
|
|
2351
|
-
list.end,
|
|
3216
|
+
list.items[3] ?? list.end,
|
|
2352
3217
|
);
|
|
3218
|
+
expectEnd(list.items[3], "invalid end of datatype declaration, ')' expected");
|
|
2353
3219
|
};
|
|
2354
3220
|
|
|
2355
|
-
// parse_rec_fun_decl: the variables are bound only while the range is parsed
|
|
3221
|
+
// parse_rec_fun_decl: the variables are bound only while the range is parsed, and Z3 holds them
|
|
3222
|
+
// until the command ends, as the stack does here.
|
|
2356
3223
|
const declareRecFun = (items: SExpr[], at: SExpr) => {
|
|
2357
3224
|
const symbol = expectSymbol(
|
|
2358
3225
|
items[0],
|
|
@@ -2367,16 +3234,19 @@ export const createSmtlibReader = (
|
|
|
2367
3234
|
|
|
2368
3235
|
// parse_rec_fun_body: Z3 reports a body of another sort at the token after it.
|
|
2369
3236
|
const defineRecFun = (decl: number, variables: SExpr, body: SExpr, next: SExpr) => {
|
|
3237
|
+
const start = exprStack.length;
|
|
2370
3238
|
const bound = bindSortedVars(variables, body);
|
|
2371
|
-
|
|
3239
|
+
runTerm(body, false);
|
|
3240
|
+
const parsedBody = exprStack[exprStack.length - 1];
|
|
2372
3241
|
unbindSortedVars(bound.varSorts.length);
|
|
2373
3242
|
const range = manager.funcDecls[decl].range;
|
|
2374
|
-
if (manager.sorts[
|
|
3243
|
+
if (manager.sorts[parsedBody] !== range)
|
|
2375
3244
|
throw new SmtParseError(
|
|
2376
|
-
`invalid function definition, sort mismatch. Expcected ${manager.getSortName(range)} but function body has sort ${manager.getSortName(manager.sorts[
|
|
3245
|
+
`invalid function definition, sort mismatch. Expcected ${manager.getSortName(range)} but function body has sort ${manager.getSortName(manager.sorts[parsedBody])}`,
|
|
2377
3246
|
next,
|
|
2378
3247
|
);
|
|
2379
|
-
setRecFunDefinition(manager, manager.recFunDefs.get(decl)!, false,
|
|
3248
|
+
setRecFunDefinition(manager, manager.recFunDefs.get(decl)!, false, parsedBody);
|
|
3249
|
+
shrinkRefs(exprStack, start);
|
|
2380
3250
|
};
|
|
2381
3251
|
|
|
2382
3252
|
// parse_define and insert_macro: Z3 declares a macro as a recursive function with one case, which
|
|
@@ -2393,20 +3263,26 @@ export const createSmtlibReader = (
|
|
|
2393
3263
|
subst.release();
|
|
2394
3264
|
}
|
|
2395
3265
|
for (const [index, sort] of domain.entries()) manager.incRef(manager.mkVar(index, sort));
|
|
2396
|
-
const reversedVars = domain.map((
|
|
3266
|
+
const reversedVars = domain.map((_value, index) =>
|
|
3267
|
+
manager.mkVar(index, domain[count - index - 1]),
|
|
3268
|
+
);
|
|
2397
3269
|
for (const reversedVar of reversedVars) manager.incRef(reversedVar);
|
|
2398
3270
|
const decl = manager.mkRecFuncDecl(name, domain, manager.sorts[body]);
|
|
2399
3271
|
for (const reversedVar of reversedVars) manager.decRef(reversedVar);
|
|
2400
3272
|
setRecFunDefinition(manager, manager.recFunDefs.get(decl)!, true, body);
|
|
2401
3273
|
declare(funcs, name, [...(funcs.get(name) ?? []), decl]);
|
|
3274
|
+
scopedFuncs.push(decl);
|
|
2402
3275
|
};
|
|
2403
3276
|
|
|
2404
3277
|
const declareCommand = (list: SmtList) => {
|
|
3278
|
+
releasePending();
|
|
2405
3279
|
const name = list.items[0].kind === "list" ? "" : list.items[0].text;
|
|
2406
3280
|
if (name === "define-fun-rec") {
|
|
2407
3281
|
const decl = declareRecFun(list.items.slice(1), list.end);
|
|
2408
3282
|
insertFunc(decl, list.items[4] ?? list.end);
|
|
2409
3283
|
defineRecFun(decl, list.items[2], list.items[4] ?? list.end, list.items[5] ?? list.end);
|
|
3284
|
+
expectEnd(list.items[5], "invalid function/constant definition, ')' expected");
|
|
3285
|
+
shrinkRefs(exprStack, 0);
|
|
2410
3286
|
return;
|
|
2411
3287
|
}
|
|
2412
3288
|
if (name === "define-funs-rec") {
|
|
@@ -2434,9 +3310,12 @@ export const createSmtlibReader = (
|
|
|
2434
3310
|
bodies.items[index + 1] ?? bodies.end,
|
|
2435
3311
|
);
|
|
2436
3312
|
});
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
3313
|
+
expectEnd(
|
|
3314
|
+
bodies.items[signatures.length],
|
|
3315
|
+
"invalid recursive function definition, ')' expected",
|
|
3316
|
+
);
|
|
3317
|
+
expectEnd(list.items[3], "invalid function/constant definition, ')' expected");
|
|
3318
|
+
shrinkRefs(exprStack, 0);
|
|
2440
3319
|
return;
|
|
2441
3320
|
}
|
|
2442
3321
|
if (name === "declare-datatypes") {
|
|
@@ -2447,7 +3326,26 @@ export const createSmtlibReader = (
|
|
|
2447
3326
|
declareDatatype(list);
|
|
2448
3327
|
return;
|
|
2449
3328
|
}
|
|
2450
|
-
const symbol =
|
|
3329
|
+
const symbol = list.items[1];
|
|
3330
|
+
// check_nonreserved_identifier rejects _ and as, which define-const's check_identifier takes.
|
|
3331
|
+
if (
|
|
3332
|
+
!isSymbol(symbol) ||
|
|
3333
|
+
(name !== "define-const" && (symbol.text === "_" || symbol.text === "as"))
|
|
3334
|
+
)
|
|
3335
|
+
throw new SmtParseError(
|
|
3336
|
+
name === "declare-sort"
|
|
3337
|
+
? "invalid sort declaration, symbol expected"
|
|
3338
|
+
: name === "define-sort"
|
|
3339
|
+
? "invalid sort definition, symbol expected"
|
|
3340
|
+
: name === "define-fun"
|
|
3341
|
+
? "invalid function/constant definition, symbol expected"
|
|
3342
|
+
: name === "define-const"
|
|
3343
|
+
? "invalid constant definition, symbol expected"
|
|
3344
|
+
: name === "declare-fun"
|
|
3345
|
+
? "invalid function declaration, symbol expected"
|
|
3346
|
+
: "invalid constant declaration, symbol expected",
|
|
3347
|
+
symbol ?? list.end,
|
|
3348
|
+
);
|
|
2451
3349
|
if (name === "declare-sort") {
|
|
2452
3350
|
if (sortDecls.has(symbol.text))
|
|
2453
3351
|
throw new SmtParseError("invalid sort declaration, sort already declared/defined", symbol);
|
|
@@ -2457,8 +3355,6 @@ export const createSmtlibReader = (
|
|
|
2457
3355
|
"invalid sort declaration, arity (<numeral>) or ')' expected",
|
|
2458
3356
|
arity,
|
|
2459
3357
|
);
|
|
2460
|
-
if (list.items.length > 3)
|
|
2461
|
-
throw new SmtParseError("invalid sort declaration, ')' expected", list.items[3]);
|
|
2462
3358
|
declare(
|
|
2463
3359
|
sortDecls,
|
|
2464
3360
|
symbol.text,
|
|
@@ -2466,44 +3362,53 @@ export const createSmtlibReader = (
|
|
|
2466
3362
|
? { kind: "sort", sort: manager.mkSort(symbol.text) }
|
|
2467
3363
|
: { kind: "user", name: symbol.text, arity: Number(arity.text) },
|
|
2468
3364
|
);
|
|
3365
|
+
expectEnd(list.items[3], "invalid sort declaration, ')' expected");
|
|
2469
3366
|
return;
|
|
2470
3367
|
}
|
|
2471
3368
|
if (name === "define-sort") {
|
|
2472
3369
|
if (sortDecls.has(symbol.text))
|
|
2473
3370
|
throw new SmtParseError("invalid sort definition, sort already declared/defined", symbol);
|
|
2474
3371
|
const parameters = parseSortParameters(
|
|
2475
|
-
list.items[2],
|
|
3372
|
+
list.items[2] ?? list.end,
|
|
2476
3373
|
"invalid sort parameter, symbol or ')' expected",
|
|
2477
|
-
list,
|
|
2478
3374
|
);
|
|
2479
3375
|
const body = list.items[3] ?? list.end;
|
|
2480
3376
|
checkPsort(body, bindTypeParameters(parameters));
|
|
2481
3377
|
declare(sortDecls, symbol.text, { kind: "definition", parameters, body });
|
|
3378
|
+
expectEnd(list.items[4], "invalid sort definition, ')' expected");
|
|
2482
3379
|
return;
|
|
2483
3380
|
}
|
|
2484
3381
|
if (name === "define-fun" || name === "define-const") {
|
|
2485
3382
|
const isConst = name === "define-const";
|
|
2486
|
-
const bound = isConst ? { names: [], varSorts: [] } : bindSortedVars(list.items[2], list);
|
|
3383
|
+
const bound = isConst ? { names: [], varSorts: [] } : bindSortedVars(list.items[2], list.end);
|
|
2487
3384
|
const range = parseSort(
|
|
2488
3385
|
list.items[isConst ? 2 : 3] ?? list.end,
|
|
2489
3386
|
isConst ? "Invalid constant definition" : "Invalid function definition",
|
|
2490
3387
|
);
|
|
2491
|
-
|
|
3388
|
+
runTerm(list.items[isConst ? 3 : 4] ?? list.end, false);
|
|
3389
|
+
const body = exprStack[exprStack.length - 1];
|
|
2492
3390
|
if (!isConst) unbindSortedVars(bound.varSorts.length);
|
|
2493
|
-
const
|
|
2494
|
-
if (manager.sorts[
|
|
3391
|
+
const extra = list.items[isConst ? 4 : 5];
|
|
3392
|
+
if (manager.sorts[body] !== range)
|
|
2495
3393
|
throw new SmtParseError(
|
|
2496
3394
|
isConst
|
|
2497
3395
|
? "invalid constant definition, sort mismatch"
|
|
2498
3396
|
: "invalid function/constant definition, sort mismatch",
|
|
2499
|
-
list.end,
|
|
3397
|
+
extra ?? list.end,
|
|
2500
3398
|
);
|
|
2501
|
-
manager.incRef(
|
|
2502
|
-
declare(macros, symbol.text, { domain: bound.varSorts, range, body
|
|
2503
|
-
defineMacroFunc(symbol.text, bound.varSorts,
|
|
3399
|
+
manager.incRef(body);
|
|
3400
|
+
declare(macros, symbol.text, { domain: bound.varSorts, range, body });
|
|
3401
|
+
defineMacroFunc(symbol.text, bound.varSorts, body);
|
|
3402
|
+
expectEnd(
|
|
3403
|
+
extra,
|
|
3404
|
+
isConst
|
|
3405
|
+
? "invalid constant definition, ')' expected"
|
|
3406
|
+
: "invalid function/constant definition, ')' expected",
|
|
3407
|
+
);
|
|
3408
|
+
shrinkRefs(exprStack, 0);
|
|
2504
3409
|
return;
|
|
2505
3410
|
}
|
|
2506
|
-
const domain = name === "declare-fun" ? parseDomain(list.items[2]
|
|
3411
|
+
const domain = name === "declare-fun" ? parseDomain(list.items[2] ?? list.end) : [];
|
|
2507
3412
|
const range = parseSort(
|
|
2508
3413
|
list.items[name === "declare-fun" ? 3 : 2] ?? list.end,
|
|
2509
3414
|
name === "declare-fun" ? "Invalid function declaration" : "Invalid constant declaration",
|
|
@@ -2515,45 +3420,91 @@ export const createSmtlibReader = (
|
|
|
2515
3420
|
for (const domainVar of vars) manager.decRef(domainVar);
|
|
2516
3421
|
}
|
|
2517
3422
|
const decl = manager.mkFuncDecl(symbol.text, domain, range);
|
|
2518
|
-
|
|
3423
|
+
const extra = list.items[name === "declare-fun" ? 4 : 3];
|
|
3424
|
+
checkDecl(decl, extra ?? list.end);
|
|
2519
3425
|
if (macros.has(symbol.text))
|
|
2520
3426
|
throw new SmtUnsupportedError(`the overloaded symbol ${symbol.text}`);
|
|
2521
3427
|
const existing = funcs.get(symbol.text) ?? [];
|
|
2522
|
-
if (
|
|
2523
|
-
existing.some(
|
|
2524
|
-
(decl) =>
|
|
2525
|
-
manager.funcDecls[decl].range === range &&
|
|
2526
|
-
manager.funcDecls[decl].domain.length === domain.length &&
|
|
2527
|
-
manager.funcDecls[decl].domain.every((sort, index) => sort === domain[index]),
|
|
2528
|
-
)
|
|
2529
|
-
)
|
|
3428
|
+
if (existing.some((other) => hasSignature(other, domain, range)))
|
|
2530
3429
|
throw new SmtParseError(
|
|
2531
3430
|
`invalid declaration, ${domain.length === 0 ? "constant" : "function"} '${symbol.text}' (with the given signature) already declared`,
|
|
2532
|
-
list.end,
|
|
3431
|
+
extra ?? list.end,
|
|
2533
3432
|
);
|
|
2534
3433
|
declare(funcs, symbol.text, [...existing, decl]);
|
|
3434
|
+
expectEnd(
|
|
3435
|
+
extra,
|
|
3436
|
+
name === "declare-fun"
|
|
3437
|
+
? "invalid function declaration, ')' expected"
|
|
3438
|
+
: "invalid constant declaration, ')' expected",
|
|
3439
|
+
);
|
|
2535
3440
|
};
|
|
2536
3441
|
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
3442
|
+
// The caller takes the stack's reference. Z3 reports a non-Boolean term at the token after it.
|
|
3443
|
+
const parseFormula = (
|
|
3444
|
+
sexpr: SExpr,
|
|
3445
|
+
follower: SmtPosition,
|
|
3446
|
+
message = "invalid assert command, term is not Boolean",
|
|
3447
|
+
) => {
|
|
3448
|
+
runTerm(sexpr, false);
|
|
3449
|
+
const assertion = exprStack[exprStack.length - 1];
|
|
3450
|
+
if (manager.sorts[assertion] !== SORT_BOOL) throw new SmtParseError(message, follower);
|
|
3451
|
+
exprStack.pop();
|
|
2542
3452
|
return assertion;
|
|
2543
3453
|
};
|
|
2544
3454
|
|
|
2545
3455
|
// An assertion is named when the last name of its term is its own.
|
|
2546
|
-
const parseAssertion = (sexpr: SExpr) => {
|
|
3456
|
+
const parseAssertion = (sexpr: SExpr, follower: SmtPosition) => {
|
|
3457
|
+
releasePending();
|
|
2547
3458
|
lastNamed.expr = -1;
|
|
2548
|
-
const formula = parseFormula(sexpr);
|
|
3459
|
+
const formula = parseFormula(sexpr, follower);
|
|
2549
3460
|
return { formula, name: lastNamed.expr === formula ? lastNamed.name : undefined };
|
|
2550
3461
|
};
|
|
2551
3462
|
|
|
2552
|
-
const push = () =>
|
|
3463
|
+
const push = () => {
|
|
3464
|
+
releasePending();
|
|
3465
|
+
scopeStarts.push(undo.length);
|
|
3466
|
+
scopedFuncStarts.push(scopedFuncs.length);
|
|
3467
|
+
};
|
|
2553
3468
|
|
|
2554
|
-
const pop = () => {
|
|
2555
|
-
|
|
3469
|
+
const pop = (count: number) => {
|
|
3470
|
+
releasePending();
|
|
3471
|
+
const funcStart = scopedFuncStarts.splice(scopedFuncStarts.length - count)[0];
|
|
3472
|
+
for (const decl of scopedFuncs.splice(funcStart)) manager.eraseRecFunDef(decl);
|
|
3473
|
+
const start = scopeStarts.splice(scopeStarts.length - count)[0];
|
|
2556
3474
|
for (const restore of undo.splice(start).reverse()) restore();
|
|
3475
|
+
// cmd_context::pop resets the plugin through its datatype handler.
|
|
3476
|
+
resetDatatypePlugin(manager);
|
|
3477
|
+
};
|
|
3478
|
+
|
|
3479
|
+
// parser::reset, after an error: Z3 frees its stacks, and with them the terms that only the
|
|
3480
|
+
// command that failed held.
|
|
3481
|
+
const reset = () => {
|
|
3482
|
+
protect(floating);
|
|
3483
|
+
protect(unrooted);
|
|
3484
|
+
releasePending();
|
|
3485
|
+
shrinkRefs(exprStack, 0);
|
|
3486
|
+
if (parsed.expr !== -1) {
|
|
3487
|
+
if (!parsed.isOwned) manager.incRef(parsed.expr);
|
|
3488
|
+
manager.decRef(parsed.expr);
|
|
3489
|
+
parsed.expr = -1;
|
|
3490
|
+
}
|
|
3491
|
+
shrinkRefs(patternStack, 0);
|
|
3492
|
+
shrinkRefs(noPatternStack, 0);
|
|
3493
|
+
locals.clear();
|
|
3494
|
+
shrink(shadowedNames, 0);
|
|
3495
|
+
shrink(shadowedLocals, 0);
|
|
3496
|
+
shrink(localScopes, 0);
|
|
3497
|
+
binders.depth = 0;
|
|
3498
|
+
};
|
|
3499
|
+
|
|
3500
|
+
// cmd_context::set_logic on a manager that is in use: restrict_builtin_sorts takes the sorts the
|
|
3501
|
+
// logic lacks, and the declarations and the operators stay.
|
|
3502
|
+
const restrictSorts = (name: string) => {
|
|
3503
|
+
releasePending();
|
|
3504
|
+
if (logicHasRealsOnly(name)) restricted.isNumeralAsReal = true;
|
|
3505
|
+
if (!ARRAY_EXTENSION_LOGICS.has(name)) restricted.hasSetSort = false;
|
|
3506
|
+
if (INT_FREE_LOGICS.has(name)) sortDecls.delete("Int");
|
|
3507
|
+
restricted.hasFf = FF_LOGICS.has(name);
|
|
2557
3508
|
};
|
|
2558
3509
|
|
|
2559
3510
|
const isUsed = (name: string) => funcs.has(name) || BUILTIN_NAMES.has(name);
|
|
@@ -2563,12 +3514,7 @@ export const createSmtlibReader = (
|
|
|
2563
3514
|
const decls = funcs.get(String(manager.funcDecls[decl].name)) ?? [];
|
|
2564
3515
|
return (
|
|
2565
3516
|
decls.includes(decl) &&
|
|
2566
|
-
decls.some(
|
|
2567
|
-
(other) =>
|
|
2568
|
-
other !== decl &&
|
|
2569
|
-
manager.funcDecls[other].domain.length === domain.length &&
|
|
2570
|
-
manager.funcDecls[other].domain.every((sort, index) => sort === domain[index]),
|
|
2571
|
-
)
|
|
3517
|
+
decls.some((other) => other !== decl && hasSignature(other, domain, -1))
|
|
2572
3518
|
);
|
|
2573
3519
|
};
|
|
2574
3520
|
|
|
@@ -2596,6 +3542,9 @@ export const createSmtlibReader = (
|
|
|
2596
3542
|
getLogicError: logicChecker.checkExpr,
|
|
2597
3543
|
push,
|
|
2598
3544
|
pop,
|
|
3545
|
+
reset,
|
|
3546
|
+
restrictSorts,
|
|
3547
|
+
registerList,
|
|
2599
3548
|
isUsed,
|
|
2600
3549
|
isClashing,
|
|
2601
3550
|
getDeclaredFuncs,
|
|
@@ -2625,7 +3574,7 @@ export const parseSmtlib = (
|
|
|
2625
3574
|
report: (error: SmtParseError) => void,
|
|
2626
3575
|
): SmtProblem => {
|
|
2627
3576
|
const commands = createCommandReader(text);
|
|
2628
|
-
const state = { reader: createSmtlibReader(manager), logic: "", rlimit: 0 };
|
|
3577
|
+
const state = { reader: createSmtlibReader(manager), logic: "", rlimit: 0, isInUse: false };
|
|
2629
3578
|
const assertions: number[] = [];
|
|
2630
3579
|
const runCommand = (list: SmtList) => {
|
|
2631
3580
|
const name = expectSymbol(list.items[0], "invalid command, symbol expected", list).text;
|
|
@@ -2639,20 +3588,30 @@ export const parseSmtlib = (
|
|
|
2639
3588
|
)
|
|
2640
3589
|
state.rlimit = Number(value.text);
|
|
2641
3590
|
if (name === "set-logic") {
|
|
3591
|
+
if (option === undefined)
|
|
3592
|
+
throw new SmtParseError("invalid command, argument(s) missing", list.end);
|
|
2642
3593
|
if (!isSymbol(option))
|
|
2643
|
-
throw new SmtParseError("invalid
|
|
2644
|
-
if (
|
|
3594
|
+
throw new SmtParseError("invalid command argument, symbol expected", option);
|
|
3595
|
+
if (value !== undefined)
|
|
3596
|
+
throw new SmtParseError("invalid command, too many arguments", value);
|
|
3597
|
+
if (state.logic !== "") throw new SmtParseError("the logic has already been set", option);
|
|
2645
3598
|
if (assertions.length > 0)
|
|
2646
|
-
throw new SmtParseError("logic must be set before initialization",
|
|
3599
|
+
throw new SmtParseError("logic must be set before initialization", option);
|
|
2647
3600
|
if (!isSupportedLogic(option.text)) return;
|
|
2648
3601
|
state.logic = option.text;
|
|
2649
|
-
state.reader
|
|
3602
|
+
if (state.isInUse) state.reader.restrictSorts(option.text);
|
|
3603
|
+
else state.reader = createSmtlibReader(manager, option.text);
|
|
2650
3604
|
} else if (DECLARATIONS.has(name)) {
|
|
3605
|
+
state.isInUse = true;
|
|
2651
3606
|
if (name.startsWith("define-"))
|
|
2652
3607
|
throw new SmtUnsupportedError(`the command ${name} is not supported`);
|
|
2653
3608
|
state.reader.declareCommand(list);
|
|
2654
3609
|
} else if (name === "assert") {
|
|
2655
|
-
|
|
3610
|
+
state.isInUse = true;
|
|
3611
|
+
const assertion = state.reader.parseFormula(
|
|
3612
|
+
list.items[1] ?? list.end,
|
|
3613
|
+
list.items[2] ?? list.end,
|
|
3614
|
+
);
|
|
2656
3615
|
const logicError = state.reader.getLogicError(assertion);
|
|
2657
3616
|
if (logicError !== undefined) {
|
|
2658
3617
|
manager.decRef(assertion);
|
|
@@ -2665,7 +3624,7 @@ export const parseSmtlib = (
|
|
|
2665
3624
|
};
|
|
2666
3625
|
for (;;) {
|
|
2667
3626
|
try {
|
|
2668
|
-
const list = commands.
|
|
3627
|
+
const list = commands.readCommand();
|
|
2669
3628
|
if (list === undefined) return { assertions, hasCheckSat: false, rlimit: state.rlimit };
|
|
2670
3629
|
if (isSymbol(list.items[0], "check-sat"))
|
|
2671
3630
|
return { assertions, hasCheckSat: true, rlimit: state.rlimit };
|
|
@@ -2673,6 +3632,7 @@ export const parseSmtlib = (
|
|
|
2673
3632
|
} catch (error) {
|
|
2674
3633
|
if (!(error instanceof SmtParseError)) throw error;
|
|
2675
3634
|
report(error);
|
|
3635
|
+
state.reader.reset();
|
|
2676
3636
|
commands.skip(report);
|
|
2677
3637
|
}
|
|
2678
3638
|
}
|