LCOV - code coverage report
Current view: top level - buildbot/coverage/build/src/parser/smt2 - smt2_state.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 985 1154 85.4 %
Date: 2026-06-02 01:25:26 Functions: 52 61 85.2 %
Branches: 504 678 74.3 %

           Branch data     Line data    Source code
       1                 :            : /******************************************************************************
       2                 :            :  * This file is part of the cvc5 project.
       3                 :            :  *
       4                 :            :  * Copyright (c) 2009-2026 by the authors listed in the file AUTHORS
       5                 :            :  * in the top-level source directory and their institutional affiliations.
       6                 :            :  * All rights reserved.  See the file COPYING in the top-level source
       7                 :            :  * directory for licensing information.
       8                 :            :  * ****************************************************************************
       9                 :            :  *
      10                 :            :  * Definitions of SMT2 constants.
      11                 :            :  */
      12                 :            : #include "parser/smt2/smt2_state.h"
      13                 :            : 
      14                 :            : #include <algorithm>
      15                 :            : 
      16                 :            : #include "base/check.h"
      17                 :            : #include "base/output.h"
      18                 :            : #include "parser/commands.h"
      19                 :            : #include "util/floatingpoint_size.h"
      20                 :            : 
      21                 :            : namespace cvc5 {
      22                 :            : namespace parser {
      23                 :            : 
      24                 :      24562 : Smt2State::Smt2State(ParserStateCallback* psc,
      25                 :            :                      Solver* solver,
      26                 :            :                      SymManager* sm,
      27                 :            :                      ParsingMode parsingMode,
      28                 :      24562 :                      bool isSygus)
      29                 :            :     : ParserState(psc, solver, sm, parsingMode),
      30                 :      24562 :       d_isSygus(isSygus),
      31                 :      24562 :       d_logicSet(false)
      32                 :            : {
      33                 :      24562 :   d_freshBinders = (d_solver->getOption("fresh-binders") == "true");
      34                 :      24562 : }
      35                 :            : 
      36                 :      24541 : Smt2State::~Smt2State() {}
      37                 :            : 
      38                 :      30213 : void Smt2State::addArithmeticOperators()
      39                 :            : {
      40                 :      30213 :   addOperator(Kind::ADD, "+");
      41                 :      30213 :   addOperator(Kind::SUB, "-");
      42                 :            :   // SUB is converted to NEG if there is only a single operand
      43                 :      30213 :   ParserState::addOperator(Kind::NEG);
      44                 :      30213 :   addOperator(Kind::MULT, "*");
      45                 :      30213 :   addOperator(Kind::LT, "<");
      46                 :      30213 :   addOperator(Kind::LEQ, "<=");
      47                 :      30213 :   addOperator(Kind::GT, ">");
      48                 :      30213 :   addOperator(Kind::GEQ, ">=");
      49                 :            : 
      50         [ +  + ]:      30213 :   if (!strictModeEnabled())
      51                 :            :   {
      52                 :            :     // NOTE: this operator is non-standard
      53                 :      30176 :     addOperator(Kind::POW, "^");
      54                 :            :   }
      55                 :      30213 : }
      56                 :            : 
      57                 :      11637 : void Smt2State::addTranscendentalOperators()
      58                 :            : {
      59                 :      11637 :   addOperator(Kind::EXPONENTIAL, "exp");
      60                 :      11637 :   addOperator(Kind::SINE, "sin");
      61                 :      11637 :   addOperator(Kind::COSINE, "cos");
      62                 :      11637 :   addOperator(Kind::TANGENT, "tan");
      63                 :      11637 :   addOperator(Kind::COSECANT, "csc");
      64                 :      11637 :   addOperator(Kind::SECANT, "sec");
      65                 :      11637 :   addOperator(Kind::COTANGENT, "cot");
      66                 :      11637 :   addOperator(Kind::ARCSINE, "arcsin");
      67                 :      11637 :   addOperator(Kind::ARCCOSINE, "arccos");
      68                 :      11637 :   addOperator(Kind::ARCTANGENT, "arctan");
      69                 :      11637 :   addOperator(Kind::ARCCOSECANT, "arccsc");
      70                 :      11637 :   addOperator(Kind::ARCSECANT, "arcsec");
      71                 :      11637 :   addOperator(Kind::ARCCOTANGENT, "arccot");
      72                 :      11637 :   addOperator(Kind::SQRT, "sqrt");
      73                 :      11637 : }
      74                 :            : 
      75                 :      14205 : void Smt2State::addQuantifiersOperators() {}
      76                 :            : 
      77                 :      15940 : void Smt2State::addBitvectorOperators()
      78                 :            : {
      79                 :      15940 :   addOperator(Kind::BITVECTOR_CONCAT, "concat");
      80                 :      15940 :   addOperator(Kind::BITVECTOR_NOT, "bvnot");
      81                 :      15940 :   addOperator(Kind::BITVECTOR_AND, "bvand");
      82                 :      15940 :   addOperator(Kind::BITVECTOR_OR, "bvor");
      83                 :      15940 :   addOperator(Kind::BITVECTOR_NEG, "bvneg");
      84                 :      15940 :   addOperator(Kind::BITVECTOR_ADD, "bvadd");
      85                 :      15940 :   addOperator(Kind::BITVECTOR_MULT, "bvmul");
      86                 :      15940 :   addOperator(Kind::BITVECTOR_UDIV, "bvudiv");
      87                 :      15940 :   addOperator(Kind::BITVECTOR_UREM, "bvurem");
      88                 :      15940 :   addOperator(Kind::BITVECTOR_SHL, "bvshl");
      89                 :      15940 :   addOperator(Kind::BITVECTOR_LSHR, "bvlshr");
      90                 :      15940 :   addOperator(Kind::BITVECTOR_ULT, "bvult");
      91                 :      15940 :   addOperator(Kind::BITVECTOR_NAND, "bvnand");
      92                 :      15940 :   addOperator(Kind::BITVECTOR_NOR, "bvnor");
      93                 :      15940 :   addOperator(Kind::BITVECTOR_XOR, "bvxor");
      94                 :      15940 :   addOperator(Kind::BITVECTOR_XNOR, "bvxnor");
      95                 :      15940 :   addOperator(Kind::BITVECTOR_COMP, "bvcomp");
      96                 :      15940 :   addOperator(Kind::BITVECTOR_SUB, "bvsub");
      97                 :      15940 :   addOperator(Kind::BITVECTOR_SDIV, "bvsdiv");
      98                 :      15940 :   addOperator(Kind::BITVECTOR_SREM, "bvsrem");
      99                 :      15940 :   addOperator(Kind::BITVECTOR_SMOD, "bvsmod");
     100                 :      15940 :   addOperator(Kind::BITVECTOR_ASHR, "bvashr");
     101                 :      15940 :   addOperator(Kind::BITVECTOR_ULE, "bvule");
     102                 :      15940 :   addOperator(Kind::BITVECTOR_UGT, "bvugt");
     103                 :      15940 :   addOperator(Kind::BITVECTOR_UGE, "bvuge");
     104                 :      15940 :   addOperator(Kind::BITVECTOR_SLT, "bvslt");
     105                 :      15940 :   addOperator(Kind::BITVECTOR_SLE, "bvsle");
     106                 :      15940 :   addOperator(Kind::BITVECTOR_SGT, "bvsgt");
     107                 :      15940 :   addOperator(Kind::BITVECTOR_SGE, "bvsge");
     108                 :      15940 :   addOperator(Kind::BITVECTOR_REDOR, "bvredor");
     109                 :      15940 :   addOperator(Kind::BITVECTOR_REDAND, "bvredand");
     110                 :      15940 :   addOperator(Kind::BITVECTOR_NEGO, "bvnego");
     111                 :      15940 :   addOperator(Kind::BITVECTOR_UADDO, "bvuaddo");
     112                 :      15940 :   addOperator(Kind::BITVECTOR_SADDO, "bvsaddo");
     113                 :      15940 :   addOperator(Kind::BITVECTOR_UMULO, "bvumulo");
     114                 :      15940 :   addOperator(Kind::BITVECTOR_SMULO, "bvsmulo");
     115                 :      15940 :   addOperator(Kind::BITVECTOR_USUBO, "bvusubo");
     116                 :      15940 :   addOperator(Kind::BITVECTOR_SSUBO, "bvssubo");
     117                 :      15940 :   addOperator(Kind::BITVECTOR_SDIVO, "bvsdivo");
     118         [ +  + ]:      15940 :   if (!strictModeEnabled())
     119                 :            :   {
     120                 :      15919 :     addOperator(Kind::BITVECTOR_ITE, "bvite");
     121                 :            :   }
     122                 :            : 
     123                 :      15940 :   addIndexedOperator(Kind::BITVECTOR_EXTRACT, "extract");
     124                 :      15940 :   addIndexedOperator(Kind::BITVECTOR_REPEAT, "repeat");
     125                 :      15940 :   addIndexedOperator(Kind::BITVECTOR_ZERO_EXTEND, "zero_extend");
     126                 :      15940 :   addIndexedOperator(Kind::BITVECTOR_SIGN_EXTEND, "sign_extend");
     127                 :      15940 :   addIndexedOperator(Kind::BITVECTOR_ROTATE_LEFT, "rotate_left");
     128                 :      15940 :   addIndexedOperator(Kind::BITVECTOR_ROTATE_RIGHT, "rotate_right");
     129                 :      15940 : }
     130                 :            : 
     131                 :      11697 : void Smt2State::addFiniteFieldOperators()
     132                 :            : {
     133                 :      11697 :   addOperator(cvc5::Kind::FINITE_FIELD_ADD, "ff.add");
     134                 :      11697 :   addOperator(cvc5::Kind::FINITE_FIELD_MULT, "ff.mul");
     135                 :      11697 :   addOperator(cvc5::Kind::FINITE_FIELD_NEG, "ff.neg");
     136                 :      11697 :   addOperator(cvc5::Kind::FINITE_FIELD_BITSUM, "ff.bitsum");
     137                 :      11697 : }
     138                 :            : 
     139                 :      11732 : void Smt2State::addDatatypesOperators()
     140                 :            : {
     141                 :      11732 :   ParserState::addOperator(Kind::APPLY_CONSTRUCTOR);
     142                 :      11732 :   ParserState::addOperator(Kind::APPLY_TESTER);
     143                 :      11732 :   ParserState::addOperator(Kind::APPLY_SELECTOR);
     144                 :            : 
     145                 :      11732 :   addIndexedOperator(Kind::APPLY_TESTER, "is");
     146         [ +  + ]:      11732 :   if (!strictModeEnabled())
     147                 :            :   {
     148                 :      11723 :     ParserState::addOperator(Kind::APPLY_UPDATER);
     149                 :      11723 :     addIndexedOperator(Kind::APPLY_UPDATER, "update");
     150                 :            :     // Tuple projection is both indexed and non-indexed (when indices are empty)
     151                 :      11723 :     addOperator(Kind::TUPLE_PROJECT, "tuple.project");
     152                 :      11723 :     addIndexedOperator(Kind::TUPLE_PROJECT, "tuple.project");
     153                 :            :     // Notice that tuple operators, we use the UNDEFINED_KIND kind.
     154                 :            :     // These are processed based on the context in which they are parsed, e.g.
     155                 :            :     // when parsing identifiers.
     156                 :            :     // For the tuple constructor "tuple", this is both a nullary operator
     157                 :            :     // (for the 0-ary tuple), and a operator, hence we call both addOperator
     158                 :            :     // and defineVar here.
     159                 :      11723 :     addOperator(Kind::APPLY_CONSTRUCTOR, "tuple");
     160                 :      11723 :     defineVar("tuple.unit", d_tm.mkTuple({}));
     161                 :      11723 :     addIndexedOperator(Kind::UNDEFINED_KIND, "tuple.select");
     162                 :      11723 :     addIndexedOperator(Kind::UNDEFINED_KIND, "tuple.update");
     163                 :      11723 :     Sort btype = d_tm.getBooleanSort();
     164                 :      11723 :     defineVar("nullable.null", d_tm.mkNullableNull(d_tm.mkNullableSort(btype)));
     165                 :      11723 :     addOperator(Kind::APPLY_CONSTRUCTOR, "nullable.some");
     166                 :      11723 :     addOperator(Kind::APPLY_SELECTOR, "nullable.val");
     167                 :      11723 :     addOperator(Kind::NULLABLE_LIFT, "nullable.lift");
     168                 :      11723 :     addOperator(Kind::APPLY_TESTER, "nullable.is_null");
     169                 :      11723 :     addOperator(Kind::APPLY_TESTER, "nullable.is_some");
     170                 :      11723 :     addIndexedOperator(Kind::NULLABLE_LIFT, "nullable.lift");
     171                 :      11723 :   }
     172                 :      11732 : }
     173                 :            : 
     174                 :      13029 : void Smt2State::addStringOperators()
     175                 :            : {
     176                 :      13029 :   defineVar("re.all", d_tm.mkRegexpAll());
     177                 :      13029 :   addOperator(Kind::STRING_CONCAT, "str.++");
     178                 :      13029 :   addOperator(Kind::STRING_LENGTH, "str.len");
     179                 :      13029 :   addOperator(Kind::STRING_SUBSTR, "str.substr");
     180                 :      13029 :   addOperator(Kind::STRING_CONTAINS, "str.contains");
     181                 :      13029 :   addOperator(Kind::STRING_CHARAT, "str.at");
     182                 :      13029 :   addOperator(Kind::STRING_INDEXOF, "str.indexof");
     183                 :      13029 :   addOperator(Kind::STRING_REPLACE, "str.replace");
     184                 :      13029 :   addOperator(Kind::STRING_PREFIX, "str.prefixof");
     185                 :      13029 :   addOperator(Kind::STRING_SUFFIX, "str.suffixof");
     186                 :      13029 :   addOperator(Kind::STRING_FROM_CODE, "str.from_code");
     187                 :      13029 :   addOperator(Kind::STRING_IS_DIGIT, "str.is_digit");
     188                 :      13029 :   addOperator(Kind::STRING_REPLACE_RE, "str.replace_re");
     189                 :      13029 :   addOperator(Kind::STRING_REPLACE_RE_ALL, "str.replace_re_all");
     190         [ +  + ]:      13029 :   if (!strictModeEnabled())
     191                 :            :   {
     192                 :      13020 :     addOperator(Kind::STRING_INDEXOF_RE, "str.indexof_re");
     193                 :      13020 :     addOperator(Kind::STRING_UPDATE, "str.update");
     194                 :      13020 :     addOperator(Kind::STRING_TO_LOWER, "str.to_lower");
     195                 :      13020 :     addOperator(Kind::STRING_TO_UPPER, "str.to_upper");
     196                 :      13020 :     addOperator(Kind::STRING_REV, "str.rev");
     197                 :            :     // sequence versions
     198                 :      13020 :     addOperator(Kind::SEQ_CONCAT, "seq.++");
     199                 :      13020 :     addOperator(Kind::SEQ_LENGTH, "seq.len");
     200                 :      13020 :     addOperator(Kind::SEQ_EXTRACT, "seq.extract");
     201                 :      13020 :     addOperator(Kind::SEQ_UPDATE, "seq.update");
     202                 :      13020 :     addOperator(Kind::SEQ_AT, "seq.at");
     203                 :      13020 :     addOperator(Kind::SEQ_CONTAINS, "seq.contains");
     204                 :      13020 :     addOperator(Kind::SEQ_INDEXOF, "seq.indexof");
     205                 :      13020 :     addOperator(Kind::SEQ_REPLACE, "seq.replace");
     206                 :      13020 :     addOperator(Kind::SEQ_PREFIX, "seq.prefixof");
     207                 :      13020 :     addOperator(Kind::SEQ_SUFFIX, "seq.suffixof");
     208                 :      13020 :     addOperator(Kind::SEQ_REV, "seq.rev");
     209                 :      13020 :     addOperator(Kind::SEQ_REPLACE_ALL, "seq.replace_all");
     210                 :      13020 :     addOperator(Kind::SEQ_UNIT, "seq.unit");
     211                 :      13020 :     addOperator(Kind::SEQ_NTH, "seq.nth");
     212                 :            :   }
     213                 :      13029 :   addOperator(Kind::STRING_FROM_INT, "str.from_int");
     214                 :      13029 :   addOperator(Kind::STRING_TO_INT, "str.to_int");
     215                 :      13029 :   addOperator(Kind::STRING_IN_REGEXP, "str.in_re");
     216                 :      13029 :   addOperator(Kind::STRING_TO_REGEXP, "str.to_re");
     217                 :      13029 :   addOperator(Kind::STRING_TO_CODE, "str.to_code");
     218                 :      13029 :   addOperator(Kind::STRING_REPLACE_ALL, "str.replace_all");
     219                 :            : 
     220                 :      13029 :   addOperator(Kind::REGEXP_CONCAT, "re.++");
     221                 :      13029 :   addOperator(Kind::REGEXP_UNION, "re.union");
     222                 :      13029 :   addOperator(Kind::REGEXP_INTER, "re.inter");
     223                 :      13029 :   addOperator(Kind::REGEXP_STAR, "re.*");
     224                 :      13029 :   addOperator(Kind::REGEXP_PLUS, "re.+");
     225                 :      13029 :   addOperator(Kind::REGEXP_OPT, "re.opt");
     226                 :      13029 :   addIndexedOperator(Kind::REGEXP_REPEAT, "re.^");
     227                 :      13029 :   addIndexedOperator(Kind::REGEXP_LOOP, "re.loop");
     228                 :      13029 :   addOperator(Kind::REGEXP_RANGE, "re.range");
     229                 :      13029 :   addOperator(Kind::REGEXP_COMPLEMENT, "re.comp");
     230                 :      13029 :   addOperator(Kind::REGEXP_DIFF, "re.diff");
     231                 :      13029 :   addOperator(Kind::STRING_LT, "str.<");
     232                 :      13029 :   addOperator(Kind::STRING_LEQ, "str.<=");
     233                 :      13029 : }
     234                 :            : 
     235                 :      11535 : void Smt2State::addFloatingPointOperators()
     236                 :            : {
     237                 :      11535 :   addOperator(Kind::FLOATINGPOINT_FP, "fp");
     238                 :      11535 :   addOperator(Kind::FLOATINGPOINT_EQ, "fp.eq");
     239                 :      11535 :   addOperator(Kind::FLOATINGPOINT_ABS, "fp.abs");
     240                 :      11535 :   addOperator(Kind::FLOATINGPOINT_NEG, "fp.neg");
     241                 :      11535 :   addOperator(Kind::FLOATINGPOINT_ADD, "fp.add");
     242                 :      11535 :   addOperator(Kind::FLOATINGPOINT_SUB, "fp.sub");
     243                 :      11535 :   addOperator(Kind::FLOATINGPOINT_MULT, "fp.mul");
     244                 :      11535 :   addOperator(Kind::FLOATINGPOINT_DIV, "fp.div");
     245                 :      11535 :   addOperator(Kind::FLOATINGPOINT_FMA, "fp.fma");
     246                 :      11535 :   addOperator(Kind::FLOATINGPOINT_SQRT, "fp.sqrt");
     247                 :      11535 :   addOperator(Kind::FLOATINGPOINT_REM, "fp.rem");
     248                 :      11535 :   addOperator(Kind::FLOATINGPOINT_RTI, "fp.roundToIntegral");
     249                 :      11535 :   addOperator(Kind::FLOATINGPOINT_MIN, "fp.min");
     250                 :      11535 :   addOperator(Kind::FLOATINGPOINT_MAX, "fp.max");
     251                 :      11535 :   addOperator(Kind::FLOATINGPOINT_LEQ, "fp.leq");
     252                 :      11535 :   addOperator(Kind::FLOATINGPOINT_LT, "fp.lt");
     253                 :      11535 :   addOperator(Kind::FLOATINGPOINT_GEQ, "fp.geq");
     254                 :      11535 :   addOperator(Kind::FLOATINGPOINT_GT, "fp.gt");
     255                 :      11535 :   addOperator(Kind::FLOATINGPOINT_IS_NORMAL, "fp.isNormal");
     256                 :      11535 :   addOperator(Kind::FLOATINGPOINT_IS_SUBNORMAL, "fp.isSubnormal");
     257                 :      11535 :   addOperator(Kind::FLOATINGPOINT_IS_ZERO, "fp.isZero");
     258                 :      11535 :   addOperator(Kind::FLOATINGPOINT_IS_INF, "fp.isInfinite");
     259                 :      11535 :   addOperator(Kind::FLOATINGPOINT_IS_NAN, "fp.isNaN");
     260                 :      11535 :   addOperator(Kind::FLOATINGPOINT_IS_NEG, "fp.isNegative");
     261                 :      11535 :   addOperator(Kind::FLOATINGPOINT_IS_POS, "fp.isPositive");
     262                 :      11535 :   addOperator(Kind::FLOATINGPOINT_TO_REAL, "fp.to_real");
     263                 :            : 
     264                 :      11535 :   addIndexedOperator(Kind::UNDEFINED_KIND, "to_fp");
     265                 :      11535 :   addIndexedOperator(Kind::FLOATINGPOINT_TO_FP_FROM_UBV, "to_fp_unsigned");
     266                 :      11535 :   addIndexedOperator(Kind::FLOATINGPOINT_TO_UBV, "fp.to_ubv");
     267                 :      11535 :   addIndexedOperator(Kind::FLOATINGPOINT_TO_SBV, "fp.to_sbv");
     268                 :            : 
     269         [ +  + ]:      11535 :   if (!strictModeEnabled())
     270                 :            :   {
     271                 :      11522 :     addIndexedOperator(Kind::FLOATINGPOINT_TO_FP_FROM_IEEE_BV, "to_fp_bv");
     272                 :      11522 :     addIndexedOperator(Kind::FLOATINGPOINT_TO_FP_FROM_FP, "to_fp_fp");
     273                 :      11522 :     addIndexedOperator(Kind::FLOATINGPOINT_TO_FP_FROM_REAL, "to_fp_real");
     274                 :      11522 :     addIndexedOperator(Kind::FLOATINGPOINT_TO_FP_FROM_SBV, "to_fp_signed");
     275                 :            :   }
     276                 :      11535 : }
     277                 :            : 
     278                 :      11344 : void Smt2State::addSepOperators()
     279                 :            : {
     280                 :      11344 :   defineVar("sep.emp", d_tm.mkSepEmp());
     281                 :            :   // the Boolean sort is a placeholder here since we don't have type info
     282                 :            :   // without type annotation
     283                 :      11344 :   defineVar("sep.nil", d_tm.mkSepNil(d_tm.getBooleanSort()));
     284                 :      11344 :   addOperator(Kind::SEP_STAR, "sep");
     285                 :      11344 :   addOperator(Kind::SEP_PTO, "pto");
     286                 :      11344 :   addOperator(Kind::SEP_WAND, "wand");
     287                 :      11344 :   ParserState::addOperator(Kind::SEP_STAR);
     288                 :      11344 :   ParserState::addOperator(Kind::SEP_PTO);
     289                 :      11344 :   ParserState::addOperator(Kind::SEP_WAND);
     290                 :      11344 : }
     291                 :            : 
     292                 :      24517 : void Smt2State::addCoreSymbols()
     293                 :            : {
     294                 :      24517 :   defineType("Bool", d_tm.getBooleanSort(), false);
     295                 :      24517 :   Sort tupleSort = d_tm.mkTupleSort({});
     296                 :      24517 :   defineType("Relation", d_tm.mkSetSort(tupleSort), false);
     297                 :      24517 :   defineType("Table", d_tm.mkBagSort(tupleSort), false);
     298                 :      24517 :   defineVar("true", d_tm.mkTrue(), true);
     299                 :      24517 :   defineVar("false", d_tm.mkFalse(), true);
     300                 :      24517 :   addOperator(Kind::AND, "and");
     301                 :      24517 :   addOperator(Kind::DISTINCT, "distinct");
     302                 :      24517 :   addOperator(Kind::EQUAL, "=");
     303                 :      24517 :   addOperator(Kind::IMPLIES, "=>");
     304                 :      24517 :   addOperator(Kind::ITE, "ite");
     305                 :      24517 :   addOperator(Kind::NOT, "not");
     306                 :      24517 :   addOperator(Kind::OR, "or");
     307                 :      24517 :   addOperator(Kind::XOR, "xor");
     308                 :      24517 :   addClosureKind(Kind::FORALL, "forall");
     309                 :      24517 :   addClosureKind(Kind::EXISTS, "exists");
     310                 :      24517 : }
     311                 :            : 
     312                 :         16 : void Smt2State::addSkolemSymbols()
     313                 :            : {
     314                 :        992 :   for (int32_t s = static_cast<int32_t>(SkolemId::INTERNAL);
     315         [ +  + ]:        992 :        s <= static_cast<int32_t>(SkolemId::NONE);
     316                 :            :        ++s)
     317                 :            :   {
     318                 :        976 :     auto skolem = static_cast<SkolemId>(s);
     319                 :        976 :     std::stringstream ss;
     320                 :        976 :     ss << "@" << skolem;
     321                 :        976 :     addSkolemId(skolem, ss.str());
     322                 :        976 :   }
     323                 :         16 : }
     324                 :            : 
     325                 :    3275953 : void Smt2State::addOperator(Kind kind, const std::string& name)
     326                 :            : {
     327         [ +  - ]:    6551906 :   Trace("parser") << "Smt2State::addOperator( " << kind << ", " << name << " )"
     328                 :    3275953 :                   << std::endl;
     329                 :    3275953 :   ParserState::addOperator(kind);
     330                 :    3275953 :   d_operatorKindMap[name] = kind;
     331                 :    3275953 : }
     332                 :            : 
     333                 :     434191 : void Smt2State::addIndexedOperator(Kind tKind, const std::string& name)
     334                 :            : {
     335                 :     434191 :   ParserState::addOperator(tKind);
     336                 :     434191 :   d_indexedOpKindMap[name] = tKind;
     337                 :     434191 : }
     338                 :            : 
     339                 :      61652 : void Smt2State::addClosureKind(Kind tKind, const std::string& name)
     340                 :            : {
     341                 :            :   // also include it as a normal operator
     342                 :      61652 :   addOperator(tKind, name);
     343                 :      61652 :   d_closureKindMap[name] = tKind;
     344                 :      61652 : }
     345                 :            : 
     346                 :        976 : void Smt2State::addSkolemId(SkolemId skolemID, const std::string& name)
     347                 :            : {
     348                 :        976 :   addOperator(Kind::SKOLEM, name);
     349                 :        976 :   d_skolemMap[name] = skolemID;
     350                 :        976 : }
     351                 :            : 
     352                 :          0 : bool Smt2State::isIndexedOperatorEnabled(const std::string& name) const
     353                 :            : {
     354                 :          0 :   return d_indexedOpKindMap.find(name) != d_indexedOpKindMap.end();
     355                 :            : }
     356                 :            : 
     357                 :    5181549 : Kind Smt2State::getOperatorKind(const std::string& name) const
     358                 :            : {
     359                 :            :   // precondition: isOperatorEnabled(name)
     360                 :    5181549 :   return d_operatorKindMap.find(name)->second;
     361                 :            : }
     362                 :            : 
     363                 :    6347672 : bool Smt2State::isOperatorEnabled(const std::string& name) const
     364                 :            : {
     365                 :    6347672 :   return d_operatorKindMap.find(name) != d_operatorKindMap.end();
     366                 :            : }
     367                 :            : 
     368                 :         38 : modes::BlockModelsMode Smt2State::getBlockModelsMode(const std::string& mode)
     369                 :            : {
     370         [ +  + ]:         38 :   if (mode == "literals")
     371                 :            :   {
     372                 :         22 :     return modes::BlockModelsMode::LITERALS;
     373                 :            :   }
     374         [ +  - ]:         16 :   else if (mode == "values")
     375                 :            :   {
     376                 :         16 :     return modes::BlockModelsMode::VALUES;
     377                 :            :   }
     378                 :          0 :   parseError(std::string("Unknown block models mode `") + mode + "'");
     379                 :          0 :   return modes::BlockModelsMode::LITERALS;
     380                 :            : }
     381                 :            : 
     382                 :         23 : modes::LearnedLitType Smt2State::getLearnedLitType(const std::string& mode)
     383                 :            : {
     384         [ +  + ]:         23 :   if (mode == "preprocess_solved")
     385                 :            :   {
     386                 :          4 :     return modes::LearnedLitType::PREPROCESS_SOLVED;
     387                 :            :   }
     388         [ +  + ]:         19 :   else if (mode == "preprocess")
     389                 :            :   {
     390                 :          4 :     return modes::LearnedLitType::PREPROCESS;
     391                 :            :   }
     392         [ +  + ]:         15 :   else if (mode == "input")
     393                 :            :   {
     394                 :          3 :     return modes::LearnedLitType::INPUT;
     395                 :            :   }
     396         [ +  + ]:         12 :   else if (mode == "solvable")
     397                 :            :   {
     398                 :          4 :     return modes::LearnedLitType::SOLVABLE;
     399                 :            :   }
     400         [ +  + ]:          8 :   else if (mode == "constant_prop")
     401                 :            :   {
     402                 :          4 :     return modes::LearnedLitType::CONSTANT_PROP;
     403                 :            :   }
     404         [ +  - ]:          4 :   else if (mode == "internal")
     405                 :            :   {
     406                 :          4 :     return modes::LearnedLitType::INTERNAL;
     407                 :            :   }
     408                 :          0 :   parseError(std::string("Unknown learned literal type `") + mode + "'");
     409                 :          0 :   return modes::LearnedLitType::UNKNOWN;
     410                 :            : }
     411                 :            : 
     412                 :         25 : modes::ProofComponent Smt2State::getProofComponent(const std::string& pc)
     413                 :            : {
     414         [ +  + ]:         25 :   if (pc == "raw_preprocess")
     415                 :            :   {
     416                 :          5 :     return modes::ProofComponent::RAW_PREPROCESS;
     417                 :            :   }
     418         [ +  + ]:         20 :   else if (pc == "preprocess")
     419                 :            :   {
     420                 :          5 :     return modes::ProofComponent::PREPROCESS;
     421                 :            :   }
     422         [ +  + ]:         15 :   else if (pc == "sat")
     423                 :            :   {
     424                 :          6 :     return modes::ProofComponent::SAT;
     425                 :            :   }
     426         [ +  + ]:          9 :   else if (pc == "theory_lemmas")
     427                 :            :   {
     428                 :          5 :     return modes::ProofComponent::THEORY_LEMMAS;
     429                 :            :   }
     430         [ +  - ]:          4 :   else if (pc == "full")
     431                 :            :   {
     432                 :          4 :     return modes::ProofComponent::FULL;
     433                 :            :   }
     434                 :          0 :   parseError(std::string("Unknown proof component `") + pc + "'");
     435                 :          0 :   return modes::ProofComponent::FULL;
     436                 :            : }
     437                 :            : 
     438                 :         93 : modes::FindSynthTarget Smt2State::getFindSynthTarget(const std::string& fst)
     439                 :            : {
     440         [ +  + ]:         93 :   if (fst == "enum")
     441                 :            :   {
     442                 :          3 :     return modes::FindSynthTarget::ENUM;
     443                 :            :   }
     444         [ +  + ]:         90 :   else if (fst == "rewrite")
     445                 :            :   {
     446                 :         24 :     return modes::FindSynthTarget::REWRITE;
     447                 :            :   }
     448         [ +  + ]:         66 :   else if (fst == "rewrite_unsound")
     449                 :            :   {
     450                 :         24 :     return modes::FindSynthTarget::REWRITE_UNSOUND;
     451                 :            :   }
     452         [ +  + ]:         42 :   else if (fst == "rewrite_input")
     453                 :            :   {
     454                 :         30 :     return modes::FindSynthTarget::REWRITE_INPUT;
     455                 :            :   }
     456         [ +  - ]:         12 :   else if (fst == "query")
     457                 :            :   {
     458                 :         12 :     return modes::FindSynthTarget::QUERY;
     459                 :            :   }
     460                 :          0 :   parseError(std::string("Unknown find synth target `") + fst + "'");
     461                 :          0 :   return modes::FindSynthTarget::ENUM;
     462                 :            : }
     463                 :            : 
     464                 :      12819 : bool Smt2State::isTheoryEnabled(internal::theory::TheoryId theory) const
     465                 :            : {
     466                 :      12819 :   return d_logic.isTheoryEnabled(theory);
     467                 :            : }
     468                 :            : 
     469                 :    1199634 : bool Smt2State::isHoEnabled() const { return d_logic.isHigherOrder(); }
     470                 :            : 
     471                 :          0 : bool Smt2State::hasCardinalityConstraints() const
     472                 :            : {
     473                 :          0 :   return d_logic.hasCardinalityConstraints();
     474                 :            : }
     475                 :            : 
     476                 :     615770 : bool Smt2State::logicIsSet() { return d_logicSet; }
     477                 :            : 
     478                 :          0 : bool Smt2State::getTesterName(Term cons, std::string& name)
     479                 :            : {
     480         [ -  - ]:          0 :   if (strictModeEnabled())
     481                 :            :   {
     482                 :            :     // 2.6 or above uses indexed tester symbols, if we are in strict mode,
     483                 :            :     // we do not automatically define is-cons for constructor cons.
     484                 :          0 :     return false;
     485                 :            :   }
     486                 :          0 :   std::stringstream ss;
     487                 :          0 :   ss << "is-" << cons;
     488                 :          0 :   name = ss.str();
     489                 :          0 :   return true;
     490                 :          0 : }
     491                 :            : 
     492                 :     185257 : Term Smt2State::mkIndexedConstant(const std::string& name,
     493                 :            :                                   const std::vector<uint32_t>& numerals)
     494                 :            : {
     495         [ +  + ]:     185257 :   if (d_logic.isTheoryEnabled(internal::theory::THEORY_FP))
     496                 :            :   {
     497         [ +  + ]:       3331 :     if (name == "+oo")
     498                 :            :     {
     499         [ -  + ]:          9 :       if (numerals.size() != 2)
     500                 :            :       {
     501                 :          0 :         parseError("Unexpected number of numerals for +oo.");
     502                 :            :       }
     503                 :          9 :       return d_tm.mkFloatingPointPosInf(numerals[0], numerals[1]);
     504                 :            :     }
     505         [ +  + ]:       3322 :     else if (name == "-oo")
     506                 :            :     {
     507         [ -  + ]:         18 :       if (numerals.size() != 2)
     508                 :            :       {
     509                 :          0 :         parseError("Unexpected number of numerals for -oo.");
     510                 :            :       }
     511                 :         18 :       return d_tm.mkFloatingPointNegInf(numerals[0], numerals[1]);
     512                 :            :     }
     513         [ +  + ]:       3304 :     else if (name == "NaN")
     514                 :            :     {
     515         [ -  + ]:         15 :       if (numerals.size() != 2)
     516                 :            :       {
     517                 :          0 :         parseError("Unexpected number of numerals for NaN.");
     518                 :            :       }
     519                 :         15 :       return d_tm.mkFloatingPointNaN(numerals[0], numerals[1]);
     520                 :            :     }
     521         [ +  + ]:       3289 :     else if (name == "+zero")
     522                 :            :     {
     523         [ +  + ]:         29 :       if (numerals.size() != 2)
     524                 :            :       {
     525                 :          3 :         parseError("Unexpected number of numerals for +zero.");
     526                 :            :       }
     527                 :         28 :       return d_tm.mkFloatingPointPosZero(numerals[0], numerals[1]);
     528                 :            :     }
     529         [ +  + ]:       3260 :     else if (name == "-zero")
     530                 :            :     {
     531         [ -  + ]:         30 :       if (numerals.size() != 2)
     532                 :            :       {
     533                 :          0 :         parseError("Unexpected number of numerals for -zero.");
     534                 :            :       }
     535                 :         30 :       return d_tm.mkFloatingPointNegZero(numerals[0], numerals[1]);
     536                 :            :     }
     537                 :            :   }
     538                 :            : 
     539                 :     185156 :   if (d_logic.isTheoryEnabled(internal::theory::THEORY_BV)
     540 [ +  - ][ +  - ]:     185156 :       && name.find("bv") == 0)
                 [ +  - ]
     541                 :            :   {
     542         [ -  + ]:     185156 :     if (numerals.size() != 1)
     543                 :            :     {
     544                 :          0 :       parseError("Unexpected number of numerals for bit-vector constant.");
     545                 :            :     }
     546                 :     185156 :     std::string bvStr = name.substr(2);
     547                 :     185156 :     return d_tm.mkBitVector(numerals[0], bvStr, 10);
     548                 :     185156 :   }
     549                 :            : 
     550                 :            :   // NOTE: Theory parametric constants go here
     551                 :            : 
     552                 :          0 :   parseError(std::string("Unknown indexed literal `") + name + "'");
     553                 :          0 :   return Term();
     554                 :            : }
     555                 :            : 
     556                 :        118 : Term Smt2State::mkIndexedConstant(const std::string& name,
     557                 :            :                                   const std::vector<std::string>& symbols)
     558                 :            : {
     559         [ +  + ]:        118 :   if (d_logic.isTheoryEnabled(internal::theory::THEORY_STRINGS))
     560                 :            :   {
     561         [ +  - ]:         14 :     if (name == "char")
     562                 :            :     {
     563         [ -  + ]:         14 :       if (symbols.size() != 1)
     564                 :            :       {
     565                 :          0 :         parseError("Unexpected number of indices for char");
     566                 :            :       }
     567 [ +  - ][ -  + ]:         14 :       if (symbols[0].length() <= 2 || symbols[0].substr(0, 2) != "#x")
         [ +  - ][ -  + ]
                 [ -  - ]
     568                 :            :       {
     569                 :          0 :         parseError(std::string("Unexpected index for char: `") + symbols[0]
     570                 :          0 :                    + "'");
     571                 :            :       }
     572                 :         28 :       return mkCharConstant(symbols[0].substr(2));
     573                 :            :     }
     574                 :            :   }
     575         [ +  - ]:        104 :   else if (d_logic.hasCardinalityConstraints())
     576                 :            :   {
     577         [ +  - ]:        104 :     if (name == "fmf.card")
     578                 :            :     {
     579         [ -  + ]:        104 :       if (symbols.size() != 2)
     580                 :            :       {
     581                 :          0 :         parseError("Unexpected number of indices for fmf.card");
     582                 :            :       }
     583                 :        104 :       Sort t = getSort(symbols[0]);
     584                 :            :       // convert second symbol back to a numeral
     585                 :        104 :       uint32_t ubound = parseStringToUnsigned(symbols[1]);
     586                 :        104 :       return d_tm.mkCardinalityConstraint(t, ubound);
     587                 :        104 :     }
     588                 :            :   }
     589                 :          0 :   parseError(std::string("Unknown indexed literal `") + name + "'");
     590                 :          0 :   return Term();
     591                 :            : }
     592                 :            : 
     593                 :       4443 : Term Smt2State::mkIndexedOp(Kind k,
     594                 :            :                             const std::vector<std::string>& symbols,
     595                 :            :                             const std::vector<Term>& args)
     596                 :            : {
     597 [ +  + ][ +  - ]:       4443 :   if (k == Kind::APPLY_TESTER || k == Kind::APPLY_UPDATER)
     598                 :            :   {
     599 [ -  + ][ -  + ]:       4443 :     Assert(symbols.size() == 1);
                 [ -  - ]
     600         [ +  + ]:       4443 :     if (args.empty())
     601                 :            :     {
     602                 :          3 :       parseError("Expected argument to tester/updater");
     603                 :            :     }
     604                 :       4442 :     const std::string& cname = symbols[0];
     605                 :            :     // must be declared
     606                 :       4442 :     checkDeclaration(cname, CHECK_DECLARED, SYM_VARIABLE);
     607                 :       4442 :     Term f = getExpressionForNameAndType(cname, args[0].getSort());
     608 [ +  + ][ +  - ]:       4442 :     if (f.getKind() == Kind::APPLY_CONSTRUCTOR && f.getNumChildren() == 1)
                 [ +  + ]
     609                 :            :     {
     610                 :            :       // for nullary constructors, must get the operator
     611                 :       1010 :       f = f[0];
     612                 :            :     }
     613         [ +  + ]:       4442 :     if (k == Kind::APPLY_TESTER)
     614                 :            :     {
     615         [ -  + ]:       4328 :       if (!f.getSort().isDatatypeConstructor())
     616                 :            :       {
     617                 :          0 :         parseError("Bad syntax for (_ is X), X must be a constructor.");
     618                 :            :       }
     619                 :            :       // get the datatype that f belongs to
     620                 :       4328 :       Sort sf = f.getSort().getDatatypeConstructorCodomainSort();
     621                 :       4328 :       Datatype d = sf.getDatatype();
     622                 :            :       // lookup by name
     623                 :       4328 :       DatatypeConstructor dc = d.getConstructor(f.toString());
     624                 :       4328 :       return dc.getTesterTerm();
     625                 :       4328 :     }
     626                 :            :     else
     627                 :            :     {
     628 [ -  + ][ -  + ]:        114 :       Assert(k == Kind::APPLY_UPDATER);
                 [ -  - ]
     629         [ -  + ]:        114 :       if (!f.getSort().isDatatypeSelector())
     630                 :            :       {
     631                 :          0 :         parseError("Bad syntax for (_ update X), X must be a selector.");
     632                 :            :       }
     633                 :        114 :       std::string sname = f.toString();
     634                 :            :       // get the datatype that f belongs to
     635                 :        114 :       Sort sf = f.getSort().getDatatypeSelectorDomainSort();
     636                 :        114 :       Datatype d = sf.getDatatype();
     637                 :            :       // find the selector
     638                 :        114 :       DatatypeSelector ds = d.getSelector(f.toString());
     639                 :            :       // get the updater term
     640                 :        114 :       return ds.getUpdaterTerm();
     641                 :        114 :     }
     642                 :       4442 :   }
     643                 :          0 :   std::stringstream ss;
     644                 :          0 :   ss << "Unknown indexed op kind " << k;
     645                 :          0 :   parseError(ss.str());
     646                 :          0 :   return Term();
     647                 :          0 : }
     648                 :            : 
     649                 :     178553 : Kind Smt2State::getIndexedOpKind(const std::string& name)
     650                 :            : {
     651                 :     178553 :   const auto& kIt = d_indexedOpKindMap.find(name);
     652         [ +  - ]:     178553 :   if (kIt != d_indexedOpKindMap.end())
     653                 :            :   {
     654                 :     178553 :     return (*kIt).second;
     655                 :            :   }
     656                 :          0 :   parseError(std::string("Unknown indexed function `") + name + "'");
     657                 :          0 :   return Kind::UNDEFINED_KIND;
     658                 :            : }
     659                 :            : 
     660                 :          0 : Kind Smt2State::getClosureKind(const std::string& name)
     661                 :            : {
     662                 :          0 :   const auto& kIt = d_closureKindMap.find(name);
     663         [ -  - ]:          0 :   if (kIt != d_closureKindMap.end())
     664                 :            :   {
     665                 :          0 :     return (*kIt).second;
     666                 :            :   }
     667                 :          0 :   parseError(std::string("Unknown closure `") + name + "'");
     668                 :          0 :   return Kind::UNDEFINED_KIND;
     669                 :            : }
     670                 :            : 
     671                 :        766 : Term Smt2State::setupDefineFunRecScope(
     672                 :            :     const std::string& fname,
     673                 :            :     const std::vector<std::pair<std::string, Sort>>& sortedVarNames,
     674                 :            :     Sort t,
     675                 :            :     std::vector<Term>& flattenVars)
     676                 :            : {
     677                 :        766 :   std::vector<Sort> sorts;
     678         [ +  + ]:       2198 :   for (const std::pair<std::string, Sort>& svn : sortedVarNames)
     679                 :            :   {
     680                 :       1432 :     sorts.push_back(svn.second);
     681                 :            :   }
     682                 :            : 
     683                 :            :   // make the flattened function type, add bound variables
     684                 :            :   // to flattenVars if the defined function was given a function return type.
     685                 :        766 :   Sort ft = flattenFunctionType(sorts, t, flattenVars);
     686                 :            : 
     687         [ +  + ]:        766 :   if (!sorts.empty())
     688                 :            :   {
     689                 :        726 :     ft = d_tm.mkFunctionSort(sorts, ft);
     690                 :            :   }
     691                 :            :   // bind now, with overloading
     692                 :       1532 :   return bindVar(fname, ft, true);
     693                 :        766 : }
     694                 :            : 
     695                 :        766 : void Smt2State::pushDefineFunRecScope(
     696                 :            :     const std::vector<std::pair<std::string, Sort>>& sortedVarNames,
     697                 :            :     const std::vector<Term>& flattenVars,
     698                 :            :     std::vector<Term>& bvs)
     699                 :            : {
     700                 :        766 :   pushScope();
     701                 :            :   // bound variables are those that are explicitly named in the preamble
     702                 :            :   // of the define-fun(s)-rec command, we define them here
     703         [ +  + ]:       2198 :   for (const std::pair<std::string, Sort>& svn : sortedVarNames)
     704                 :            :   {
     705                 :       1432 :     Term v = bindBoundVar(svn.first, svn.second, d_freshBinders);
     706                 :       1432 :     bvs.push_back(v);
     707                 :       1432 :   }
     708                 :            : 
     709                 :        766 :   bvs.insert(bvs.end(), flattenVars.begin(), flattenVars.end());
     710                 :        766 : }
     711                 :            : 
     712                 :         83 : void Smt2State::reset()
     713                 :            : {
     714                 :         83 :   d_logicSet = false;
     715                 :         83 :   d_logic = internal::LogicInfo();
     716                 :         83 :   d_operatorKindMap.clear();
     717                 :         83 :   d_lastNamedTerm = std::pair<Term, std::string>();
     718                 :         83 : }
     719                 :            : 
     720                 :         52 : std::unique_ptr<Cmd> Smt2State::invConstraint(
     721                 :            :     const std::vector<std::string>& names)
     722                 :            : {
     723                 :         52 :   checkThatLogicIsSet();
     724         [ +  - ]:         52 :   Trace("parser-sygus") << "Sygus : define sygus funs..." << std::endl;
     725         [ +  - ]:         52 :   Trace("parser-sygus") << "Sygus : read inv-constraint..." << std::endl;
     726                 :            : 
     727         [ -  + ]:         52 :   if (names.size() != 4)
     728                 :            :   {
     729                 :          0 :     parseError(
     730                 :            :         "Bad syntax for inv-constraint: expected 4 "
     731                 :            :         "arguments.");
     732                 :            :   }
     733                 :            : 
     734                 :         52 :   std::vector<Term> terms;
     735         [ +  + ]:        260 :   for (const std::string& name : names)
     736                 :            :   {
     737         [ -  + ]:        208 :     if (!isDeclared(name))
     738                 :            :     {
     739                 :          0 :       std::stringstream ss;
     740                 :          0 :       ss << "Function " << name << " in inv-constraint is not defined.";
     741                 :          0 :       parseError(ss.str());
     742                 :          0 :     }
     743                 :            : 
     744                 :        208 :     terms.push_back(getVariable(name));
     745                 :            :   }
     746                 :            : 
     747                 :        104 :   return std::unique_ptr<Cmd>(new SygusInvConstraintCommand(terms));
     748                 :         52 : }
     749                 :            : 
     750                 :      24522 : void Smt2State::setLogic(std::string name)
     751                 :            : {
     752                 :      24522 :   bool smLogicAlreadySet = getSymbolManager()->isLogicSet();
     753                 :            :   // if logic is already set, this is an error
     754         [ +  + ]:      24522 :   if (d_logicSet)
     755                 :            :   {
     756                 :         15 :     parseError("Only one set-logic is allowed.");
     757                 :            :   }
     758                 :      24517 :   d_logicSet = true;
     759                 :      24517 :   d_logic = name;
     760                 :            : 
     761                 :            :   // if sygus is enabled, we must enable UF, datatypes, and integer arithmetic
     762         [ +  + ]:      24517 :   if (sygus())
     763                 :            :   {
     764         [ -  + ]:        966 :     if (!d_logic.isQuantified())
     765                 :            :     {
     766                 :          0 :       warning("Logics in sygus are assumed to contain quantifiers.");
     767                 :          0 :       warning("Omit QF_ from the logic to avoid this warning.");
     768                 :            :     }
     769                 :            :   }
     770                 :            : 
     771                 :            :   // Core theory belongs to every logic
     772                 :      24517 :   addCoreSymbols();
     773                 :            : 
     774                 :            :   // add skolems
     775         [ +  + ]:      24517 :   if (d_solver->getOption("parse-skolem-definitions") == "true")
     776                 :            :   {
     777                 :         16 :     addSkolemSymbols();
     778                 :            :   }
     779                 :            : 
     780         [ +  + ]:      24517 :   if (d_logic.isTheoryEnabled(internal::theory::THEORY_UF))
     781                 :            :   {
     782                 :      15458 :     ParserState::addOperator(Kind::APPLY_UF);
     783                 :            :   }
     784                 :            : 
     785         [ +  + ]:      24517 :   if (d_logic.isHigherOrder())
     786                 :            :   {
     787                 :       1089 :     addOperator(Kind::HO_APPLY, "@");
     788                 :            :     // lambda is a closure kind
     789                 :       1089 :     addClosureKind(Kind::LAMBDA, "lambda");
     790                 :            :   }
     791                 :            : 
     792         [ +  + ]:      24517 :   if (d_logic.isTheoryEnabled(internal::theory::THEORY_ARITH))
     793                 :            :   {
     794         [ +  + ]:      18297 :     if (d_logic.areIntegersUsed())
     795                 :            :     {
     796                 :      16762 :       defineType("Int", d_tm.getIntegerSort(), false);
     797                 :      16762 :       addArithmeticOperators();
     798 [ +  + ][ +  + ]:      16762 :       if (!strictModeEnabled() || !d_logic.isLinear())
                 [ +  + ]
     799                 :            :       {
     800                 :      16751 :         addOperator(Kind::INTS_DIVISION, "div");
     801                 :      16751 :         addOperator(Kind::INTS_MODULUS, "mod");
     802                 :      16751 :         addOperator(Kind::ABS, "abs");
     803                 :            :       }
     804         [ +  + ]:      16762 :       if (!strictModeEnabled())
     805                 :            :       {
     806                 :      16742 :         addOperator(Kind::INTS_DIVISION_TOTAL, "div_total");
     807                 :      16742 :         addOperator(Kind::INTS_MODULUS_TOTAL, "mod_total");
     808                 :            :       }
     809                 :      16762 :       addIndexedOperator(Kind::DIVISIBLE, "divisible");
     810                 :            :     }
     811                 :            : 
     812         [ +  + ]:      18297 :     if (d_logic.areRealsUsed())
     813                 :            :     {
     814                 :      13451 :       defineType("Real", d_tm.getRealSort(), false);
     815                 :      13451 :       addArithmeticOperators();
     816                 :      13451 :       addOperator(Kind::DIVISION, "/");
     817         [ +  + ]:      13451 :       if (!strictModeEnabled())
     818                 :            :       {
     819                 :      13434 :         addOperator(Kind::ABS, "abs");
     820                 :      13434 :         addOperator(Kind::DIVISION_TOTAL, "/_total");
     821                 :            :       }
     822                 :            :     }
     823                 :            : 
     824 [ +  + ][ +  + ]:      18297 :     if (d_logic.areIntegersUsed() && d_logic.areRealsUsed())
                 [ +  + ]
     825                 :            :     {
     826                 :      11916 :       addOperator(Kind::TO_INTEGER, "to_int");
     827                 :      11916 :       addOperator(Kind::IS_INTEGER, "is_int");
     828                 :      11916 :       addOperator(Kind::TO_REAL, "to_real");
     829                 :            :     }
     830                 :            : 
     831         [ +  + ]:      18297 :     if (d_logic.areTranscendentalsUsed())
     832                 :            :     {
     833                 :      11637 :       defineVar("real.pi", d_tm.mkPi());
     834                 :      11637 :       addTranscendentalOperators();
     835                 :            :     }
     836         [ +  + ]:      18297 :     if (!strictModeEnabled())
     837                 :            :     {
     838                 :            :       // integer version of AND
     839                 :      18273 :       addIndexedOperator(Kind::IAND, "iand");
     840                 :            :       // parametric integer version of AND
     841                 :      18273 :       addOperator(Kind::PIAND, "piand");
     842                 :            :       // pow2
     843                 :      18273 :       addOperator(Kind::POW2, "int.pow2");
     844                 :            :       // log2
     845                 :      18273 :       addOperator(Kind::LOG2, "int.log2");
     846                 :            :     }
     847                 :            :   }
     848                 :            : 
     849         [ +  + ]:      24517 :   if (d_logic.isTheoryEnabled(internal::theory::THEORY_ARRAYS))
     850                 :            :   {
     851                 :      13280 :     addOperator(Kind::SELECT, "select");
     852                 :      13280 :     addOperator(Kind::STORE, "store");
     853                 :      13280 :     addOperator(Kind::EQ_RANGE, "eqrange");
     854                 :            :   }
     855                 :            : 
     856         [ +  + ]:      24517 :   if (d_logic.isTheoryEnabled(internal::theory::THEORY_BV))
     857                 :            :   {
     858                 :      15940 :     addBitvectorOperators();
     859                 :            : 
     860                 :      15940 :     if (d_logic.isTheoryEnabled(internal::theory::THEORY_ARITH)
     861 [ +  + ][ +  + ]:      15940 :         && d_logic.areIntegersUsed())
                 [ +  + ]
     862                 :            :     {
     863                 :            :       // Conversions between bit-vectors and integers
     864         [ +  + ]:      11722 :       if (!strictModeEnabled())
     865                 :            :       {
     866                 :            :         // For the sake of backwards compatability at the moment we support
     867                 :            :         // the old syntax, which in the case of bv2nat maps directly to
     868                 :            :         // Kind::BITVECTOR_UBV_TO_INT.
     869                 :      11713 :         addOperator(Kind::BITVECTOR_UBV_TO_INT, "bv2nat");
     870                 :      11713 :         addIndexedOperator(Kind::INT_TO_BITVECTOR, "int2bv");
     871                 :            :       }
     872                 :      11722 :       addIndexedOperator(Kind::INT_TO_BITVECTOR, "int_to_bv");
     873                 :      11722 :       addOperator(Kind::BITVECTOR_UBV_TO_INT, "ubv_to_int");
     874                 :      11722 :       addOperator(Kind::BITVECTOR_SBV_TO_INT, "sbv_to_int");
     875                 :            :     }
     876                 :            :   }
     877                 :            : 
     878         [ +  + ]:      24517 :   if (d_logic.isTheoryEnabled(internal::theory::THEORY_DATATYPES))
     879                 :            :   {
     880                 :      11732 :     const std::vector<Sort> types;
     881                 :      11732 :     defineType("UnitTuple", d_tm.mkTupleSort(types), false);
     882                 :      11732 :     addDatatypesOperators();
     883                 :      11732 :   }
     884                 :            : 
     885         [ +  + ]:      24517 :   if (d_logic.isTheoryEnabled(internal::theory::THEORY_SETS))
     886                 :            :   {
     887                 :            :     // the Boolean sort is a placeholder here since we don't have type info
     888                 :            :     // without type annotation
     889                 :      11529 :     Sort btype = d_tm.getBooleanSort();
     890                 :      11529 :     defineVar("set.empty", d_tm.mkEmptySet(d_tm.mkSetSort(btype)));
     891                 :      11529 :     defineVar("set.universe", d_tm.mkUniverseSet(btype));
     892                 :            : 
     893                 :      11529 :     addOperator(Kind::SET_UNION, "set.union");
     894                 :      11529 :     addOperator(Kind::SET_INTER, "set.inter");
     895                 :      11529 :     addOperator(Kind::SET_MINUS, "set.minus");
     896                 :      11529 :     addOperator(Kind::SET_SUBSET, "set.subset");
     897                 :      11529 :     addOperator(Kind::SET_MEMBER, "set.member");
     898                 :      11529 :     addOperator(Kind::SET_SINGLETON, "set.singleton");
     899                 :      11529 :     addOperator(Kind::SET_INSERT, "set.insert");
     900                 :      11529 :     addOperator(Kind::SET_CARD, "set.card");
     901                 :      11529 :     addOperator(Kind::SET_COMPLEMENT, "set.complement");
     902                 :      11529 :     addOperator(Kind::SET_CHOOSE, "set.choose");
     903                 :      11529 :     addOperator(Kind::SET_IS_EMPTY, "set.is_empty");
     904                 :      11529 :     addOperator(Kind::SET_IS_SINGLETON, "set.is_singleton");
     905                 :      11529 :     addOperator(Kind::SET_MAP, "set.map");
     906                 :      11529 :     addOperator(Kind::SET_FILTER, "set.filter");
     907                 :      11529 :     addOperator(Kind::SET_ALL, "set.all");
     908                 :      11529 :     addOperator(Kind::SET_SOME, "set.some");
     909                 :      11529 :     addOperator(Kind::SET_FOLD, "set.fold");
     910                 :      11529 :     addOperator(Kind::RELATION_JOIN, "rel.join");
     911                 :      11529 :     addOperator(Kind::RELATION_TABLE_JOIN, "rel.table_join");
     912                 :      11529 :     addOperator(Kind::RELATION_PRODUCT, "rel.product");
     913                 :      11529 :     addOperator(Kind::RELATION_TRANSPOSE, "rel.transpose");
     914                 :      11529 :     addOperator(Kind::RELATION_TCLOSURE, "rel.tclosure");
     915                 :      11529 :     addOperator(Kind::RELATION_JOIN_IMAGE, "rel.join_image");
     916                 :      11529 :     addOperator(Kind::RELATION_IDEN, "rel.iden");
     917                 :            :     // these operators can be with/without indices
     918                 :      11529 :     addOperator(Kind::RELATION_GROUP, "rel.group");
     919                 :      11529 :     addOperator(Kind::RELATION_AGGREGATE, "rel.aggr");
     920                 :      11529 :     addOperator(Kind::RELATION_PROJECT, "rel.project");
     921                 :      11529 :     addIndexedOperator(Kind::RELATION_GROUP, "rel.group");
     922                 :      11529 :     addIndexedOperator(Kind::RELATION_TABLE_JOIN, "rel.table_join");
     923                 :      11529 :     addIndexedOperator(Kind::RELATION_AGGREGATE, "rel.aggr");
     924                 :      11529 :     addIndexedOperator(Kind::RELATION_PROJECT, "rel.project");
     925                 :            :     // set.comprehension is a closure kind
     926                 :      11529 :     addClosureKind(Kind::SET_COMPREHENSION, "set.comprehension");
     927                 :      11529 :   }
     928                 :            : 
     929         [ +  + ]:      24517 :   if (d_logic.isTheoryEnabled(internal::theory::THEORY_BAGS))
     930                 :            :   {
     931                 :            :     // the Boolean sort is a placeholder here since we don't have type info
     932                 :            :     // without type annotation
     933                 :      11333 :     Sort btype = d_tm.getBooleanSort();
     934                 :      11333 :     defineVar("bag.empty", d_tm.mkEmptyBag(d_tm.mkBagSort(btype)));
     935                 :      11333 :     addOperator(Kind::BAG_UNION_MAX, "bag.union_max");
     936                 :      11333 :     addOperator(Kind::BAG_UNION_DISJOINT, "bag.union_disjoint");
     937                 :      11333 :     addOperator(Kind::BAG_INTER_MIN, "bag.inter_min");
     938                 :      11333 :     addOperator(Kind::BAG_DIFFERENCE_SUBTRACT, "bag.difference_subtract");
     939                 :      11333 :     addOperator(Kind::BAG_DIFFERENCE_REMOVE, "bag.difference_remove");
     940                 :      11333 :     addOperator(Kind::BAG_SUBBAG, "bag.subbag");
     941                 :      11333 :     addOperator(Kind::BAG_COUNT, "bag.count");
     942                 :      11333 :     addOperator(Kind::BAG_MEMBER, "bag.member");
     943                 :      11333 :     addOperator(Kind::BAG_SETOF, "bag.setof");
     944                 :      11333 :     addOperator(Kind::BAG_MAKE, "bag");
     945                 :      11333 :     addOperator(Kind::BAG_CARD, "bag.card");
     946                 :      11333 :     addOperator(Kind::BAG_CHOOSE, "bag.choose");
     947                 :      11333 :     addOperator(Kind::BAG_MAP, "bag.map");
     948                 :      11333 :     addOperator(Kind::BAG_FILTER, "bag.filter");
     949                 :      11333 :     addOperator(Kind::BAG_ALL, "bag.all");
     950                 :      11333 :     addOperator(Kind::BAG_SOME, "bag.some");
     951                 :      11333 :     addOperator(Kind::BAG_FOLD, "bag.fold");
     952                 :      11333 :     addOperator(Kind::BAG_PARTITION, "bag.partition");
     953                 :      11333 :     addOperator(Kind::TABLE_PRODUCT, "table.product");
     954                 :      11333 :     addOperator(Kind::BAG_PARTITION, "table.group");
     955                 :            :     // these operators can be with/without indices
     956                 :      11333 :     addOperator(Kind::TABLE_PROJECT, "table.project");
     957                 :      11333 :     addOperator(Kind::TABLE_AGGREGATE, "table.aggr");
     958                 :      11333 :     addOperator(Kind::TABLE_JOIN, "table.join");
     959                 :      11333 :     addOperator(Kind::TABLE_GROUP, "table.group");
     960                 :      11333 :     addIndexedOperator(Kind::TABLE_PROJECT, "table.project");
     961                 :      11333 :     addIndexedOperator(Kind::TABLE_AGGREGATE, "table.aggr");
     962                 :      11333 :     addIndexedOperator(Kind::TABLE_JOIN, "table.join");
     963                 :      11333 :     addIndexedOperator(Kind::TABLE_GROUP, "table.group");
     964                 :      11333 :   }
     965         [ +  + ]:      24517 :   if (d_logic.isTheoryEnabled(internal::theory::THEORY_STRINGS))
     966                 :            :   {
     967                 :      13029 :     defineType("String", d_tm.getStringSort(), false);
     968                 :      13029 :     defineType("RegLan", d_tm.getRegExpSort(), false);
     969                 :      13029 :     defineType("Int", d_tm.getIntegerSort(), false);
     970                 :            : 
     971                 :      13029 :     defineVar("re.none", d_tm.mkRegexpNone());
     972                 :      13029 :     defineVar("re.allchar", d_tm.mkRegexpAllchar());
     973                 :            : 
     974                 :            :     // Boolean is a placeholder
     975                 :      13029 :     defineVar("seq.empty", d_tm.mkEmptySequence(d_tm.getBooleanSort()));
     976                 :            : 
     977                 :      13029 :     addStringOperators();
     978                 :            :   }
     979                 :            : 
     980         [ +  + ]:      24517 :   if (d_logic.isQuantified())
     981                 :            :   {
     982                 :      14205 :     addQuantifiersOperators();
     983                 :            :   }
     984                 :            : 
     985         [ +  + ]:      24517 :   if (d_logic.isTheoryEnabled(internal::theory::THEORY_FP))
     986                 :            :   {
     987                 :      11535 :     defineType("RoundingMode", d_tm.getRoundingModeSort(), false);
     988                 :      11535 :     defineType("Float16", d_tm.mkFloatingPointSort(5, 11), false);
     989                 :      11535 :     defineType("Float32", d_tm.mkFloatingPointSort(8, 24), false);
     990                 :      11535 :     defineType("Float64", d_tm.mkFloatingPointSort(11, 53), false);
     991                 :      11535 :     defineType("Float128", d_tm.mkFloatingPointSort(15, 113), false);
     992                 :            : 
     993                 :      11535 :     defineVar("RNE",
     994                 :      23070 :               d_tm.mkRoundingMode(RoundingMode::ROUND_NEAREST_TIES_TO_EVEN));
     995                 :      11535 :     defineVar("roundNearestTiesToEven",
     996                 :      23070 :               d_tm.mkRoundingMode(RoundingMode::ROUND_NEAREST_TIES_TO_EVEN));
     997                 :      11535 :     defineVar("RNA",
     998                 :      23070 :               d_tm.mkRoundingMode(RoundingMode::ROUND_NEAREST_TIES_TO_AWAY));
     999                 :      11535 :     defineVar("roundNearestTiesToAway",
    1000                 :      23070 :               d_tm.mkRoundingMode(RoundingMode::ROUND_NEAREST_TIES_TO_AWAY));
    1001                 :      11535 :     defineVar("RTP", d_tm.mkRoundingMode(RoundingMode::ROUND_TOWARD_POSITIVE));
    1002                 :      11535 :     defineVar("roundTowardPositive",
    1003                 :      23070 :               d_tm.mkRoundingMode(RoundingMode::ROUND_TOWARD_POSITIVE));
    1004                 :      11535 :     defineVar("RTN", d_tm.mkRoundingMode(RoundingMode::ROUND_TOWARD_NEGATIVE));
    1005                 :      11535 :     defineVar("roundTowardNegative",
    1006                 :      23070 :               d_tm.mkRoundingMode(RoundingMode::ROUND_TOWARD_NEGATIVE));
    1007                 :      11535 :     defineVar("RTZ", d_tm.mkRoundingMode(RoundingMode::ROUND_TOWARD_ZERO));
    1008                 :      11535 :     defineVar("roundTowardZero",
    1009                 :      23070 :               d_tm.mkRoundingMode(RoundingMode::ROUND_TOWARD_ZERO));
    1010                 :            : 
    1011                 :      11535 :     addFloatingPointOperators();
    1012                 :            :   }
    1013                 :            : 
    1014         [ +  + ]:      24517 :   if (d_logic.isTheoryEnabled(internal::theory::THEORY_FF))
    1015                 :            :   {
    1016                 :      11697 :     addFiniteFieldOperators();
    1017                 :            :   }
    1018                 :            : 
    1019         [ +  + ]:      24517 :   if (d_logic.isTheoryEnabled(internal::theory::THEORY_SEP))
    1020                 :            :   {
    1021                 :      11344 :     addSepOperators();
    1022                 :            :   }
    1023                 :            : 
    1024                 :            :   // Builtin symbols of the logic are declared at context level zero, hence
    1025                 :            :   // we push the outermost scope in the symbol manager here.
    1026                 :            :   // We only do this if the logic has not already been set, in which case we
    1027                 :            :   // have already pushed the outermost context (and this method redeclares the
    1028                 :            :   // symbols which does not impact the symbol manager).
    1029                 :            :   // TODO (cvc5-projects #693): refactor this so that this method is moved to
    1030                 :            :   // the symbol manager and only called once per symbol manager.
    1031         [ +  + ]:      24517 :   if (!smLogicAlreadySet)
    1032                 :            :   {
    1033                 :      24300 :     pushScope(true);
    1034                 :            :   }
    1035                 :      24517 : }
    1036                 :            : 
    1037                 :        800 : Grammar* Smt2State::mkGrammar(const std::vector<Term>& boundVars,
    1038                 :            :                               const std::vector<Term>& ntSymbols)
    1039                 :            : {
    1040                 :       1600 :   d_allocGrammars.emplace_back(
    1041                 :        800 :       new Grammar(d_solver->mkGrammar(boundVars, ntSymbols)));
    1042                 :        800 :   return d_allocGrammars.back().get();
    1043                 :            : }
    1044                 :            : 
    1045                 :      51196 : bool Smt2State::sygus() const { return d_isSygus; }
    1046                 :            : 
    1047                 :          0 : bool Smt2State::hasGrammars() const
    1048                 :            : {
    1049                 :          0 :   return sygus() || d_solver->getOption("produce-abducts") == "true"
    1050                 :          0 :          || d_solver->getOption("produce-interpolants") == "true";
    1051                 :            : }
    1052                 :            : 
    1053                 :      94414 : bool Smt2State::usingFreshBinders() const { return d_freshBinders; }
    1054                 :            : 
    1055                 :     615770 : void Smt2State::checkThatLogicIsSet()
    1056                 :            : {
    1057         [ +  + ]:     615770 :   if (!logicIsSet())
    1058                 :            :   {
    1059         [ +  + ]:         51 :     if (strictModeEnabled())
    1060                 :            :     {
    1061                 :          6 :       parseError("set-logic must appear before this point.");
    1062                 :            :     }
    1063                 :            :     else
    1064                 :            :     {
    1065                 :         49 :       SymManager* sm = getSymbolManager();
    1066                 :            :       // the calls to setLogic below set the logic on the solver directly
    1067         [ +  + ]:         49 :       if (sm->isLogicForced())
    1068                 :            :       {
    1069                 :          4 :         setLogic(sm->getLogic());
    1070                 :            :       }
    1071                 :            :       else
    1072                 :            :       {
    1073                 :         45 :         warning("No set-logic command was given before this point.");
    1074                 :         45 :         warning("cvc5 will make all theories available.");
    1075                 :         45 :         warning(
    1076                 :            :             "Consider setting a stricter logic for (likely) better "
    1077                 :            :             "performance.");
    1078                 :         45 :         warning("To suppress this warning in the future use (set-logic ALL).");
    1079                 :            : 
    1080                 :         45 :         setLogic("ALL");
    1081                 :            :       }
    1082                 :            :       // Set the logic directly in the solver, without a command. Notice this is
    1083                 :            :       // important since we do not want to enqueue a set-logic command and
    1084                 :            :       // fully initialize the underlying SolverEngine in the meantime before the
    1085                 :            :       // command has a chance to execute, which would lead to an error.
    1086                 :         49 :       std::string logic = d_logic.getLogicString();
    1087                 :         49 :       d_solver->setLogic(logic);
    1088                 :            :       // set the logic on the symbol manager as well, non-forced
    1089                 :         49 :       sm->setLogic(logic);
    1090                 :         49 :     }
    1091                 :            :   }
    1092                 :     615768 : }
    1093                 :            : 
    1094                 :      11549 : void Smt2State::checkLogicAllowsFreeSorts()
    1095                 :            : {
    1096                 :      11549 :   if (!d_logic.isTheoryEnabled(internal::theory::THEORY_UF)
    1097         [ +  + ]:        108 :       && !d_logic.isTheoryEnabled(internal::theory::THEORY_ARRAYS)
    1098         [ -  + ]:          8 :       && !d_logic.isTheoryEnabled(internal::theory::THEORY_DATATYPES)
    1099         [ -  - ]:          0 :       && !d_logic.isTheoryEnabled(internal::theory::THEORY_SETS)
    1100 [ +  + ][ -  - ]:      11657 :       && !d_logic.isTheoryEnabled(internal::theory::THEORY_BAGS))
                 [ -  + ]
    1101                 :            :   {
    1102                 :          0 :     parseErrorLogic("Free sort symbols not allowed in ");
    1103                 :            :   }
    1104                 :      11549 : }
    1105                 :            : 
    1106                 :      41586 : void Smt2State::checkLogicAllowsFunctions()
    1107                 :            : {
    1108 [ +  + ][ -  + ]:      41586 :   if (!d_logic.isTheoryEnabled(internal::theory::THEORY_UF) && !isHoEnabled())
                 [ -  + ]
    1109                 :            :   {
    1110                 :          0 :     parseError(
    1111                 :            :         "Functions (of non-zero arity) cannot "
    1112                 :            :         "be declared in logic "
    1113                 :          0 :         + d_logic.getLogicString()
    1114                 :          0 :         + ". Try including UF or adding the prefix HO_.");
    1115                 :            :   }
    1116                 :      41586 : }
    1117                 :            : 
    1118                 :    1247562 : bool Smt2State::isAbstractValue(const std::string& name)
    1119                 :            : {
    1120 [ +  + ][ +  - ]:    2420696 :   return name.length() >= 2 && name[0] == '@' && name[1] != '0'
    1121 [ +  + ][ -  + ]:    2420696 :          && name.find_first_not_of("0123456789", 1) == std::string::npos;
    1122                 :            : }
    1123                 :            : 
    1124                 :     840391 : Term Smt2State::mkRealOrIntFromNumeral(const std::string& str)
    1125                 :            : {
    1126                 :            :   // if arithmetic is enabled, and integers are disabled
    1127                 :     840391 :   if (d_logic.isTheoryEnabled(internal::theory::THEORY_ARITH)
    1128 [ +  + ][ +  + ]:     840391 :       && !d_logic.areIntegersUsed())
                 [ +  + ]
    1129                 :            :   {
    1130                 :      77604 :     return d_tm.mkReal(str);
    1131                 :            :   }
    1132                 :     762787 :   return d_tm.mkInteger(str);
    1133                 :            : }
    1134                 :            : 
    1135                 :       2091 : void Smt2State::parseOpApplyTypeAscription(ParseOp& p, Sort type)
    1136                 :            : {
    1137         [ +  - ]:       4182 :   Trace("parser") << "parseOpApplyTypeAscription : " << p << " " << type
    1138                 :       2091 :                   << std::endl;
    1139         [ +  - ]:       2091 :   if (p.d_expr.isNull())
    1140                 :            :   {
    1141         [ +  - ]:       4182 :     Trace("parser-overloading")
    1142                 :          0 :         << "Getting variable expression with name " << p.d_name << " and type "
    1143                 :       2091 :         << type << std::endl;
    1144                 :            :     // get the variable expression for the type
    1145         [ +  + ]:       2091 :     if (isDeclared(p.d_name, SYM_VARIABLE))
    1146                 :            :     {
    1147                 :       1283 :       p.d_expr = getExpressionForNameAndType(p.d_name, type);
    1148                 :       1283 :       p.d_name = std::string("");
    1149                 :            :     }
    1150         [ +  + ]:       2091 :     if (p.d_name == "const")
    1151                 :            :     {
    1152                 :            :       // We use a placeholder as a way to store the type of the constant array.
    1153                 :            :       // Since ParseOp only contains a Term field, it is stored as a constant
    1154                 :            :       // of the given type. The kind INTERNAL_KIND is used to mark that we
    1155                 :            :       // are a placeholder.
    1156                 :        221 :       p.d_kind = Kind::INTERNAL_KIND;
    1157                 :        221 :       p.d_expr = d_tm.mkConst(type, "_placeholder_");
    1158                 :        221 :       return;
    1159                 :            :     }
    1160         [ +  + ]:       1870 :     else if (p.d_name.find("ff") == 0)
    1161                 :            :     {
    1162                 :        587 :       std::string rest = p.d_name.substr(2);
    1163         [ -  + ]:        587 :       if (!type.isFiniteField())
    1164                 :            :       {
    1165                 :          0 :         std::stringstream ss;
    1166                 :          0 :         ss << "expected finite field sort to ascribe " << p.d_name
    1167                 :          0 :            << " but found sort: " << type;
    1168                 :          0 :         parseError(ss.str());
    1169                 :          0 :       }
    1170                 :        587 :       p.d_expr = d_tm.mkFiniteFieldElem(rest, type);
    1171                 :        587 :       return;
    1172                 :        587 :     }
    1173         [ -  + ]:       1283 :     if (p.d_expr.isNull())
    1174                 :            :     {
    1175                 :          0 :       std::stringstream ss;
    1176                 :          0 :       ss << "Could not resolve expression with name " << p.d_name
    1177                 :          0 :          << " and type " << type << std::endl;
    1178                 :          0 :       parseError(ss.str());
    1179                 :          0 :     }
    1180                 :            :   }
    1181         [ +  - ]:       1283 :   Trace("parser-qid") << "Resolve ascription " << type << " on " << p.d_expr;
    1182 [ +  - ][ -  + ]:       1283 :   Trace("parser-qid") << " " << p.d_expr.getKind() << " " << p.d_expr.getSort();
                 [ -  - ]
    1183         [ +  - ]:       1283 :   Trace("parser-qid") << std::endl;
    1184                 :            :   // otherwise, we process the type ascription
    1185                 :       1283 :   p.d_expr = applyTypeAscription(p.d_expr, type);
    1186                 :            : }
    1187                 :            : 
    1188                 :          0 : Term Smt2State::parseOpToExpr(ParseOp& p)
    1189                 :            : {
    1190         [ -  - ]:          0 :   Trace("parser") << "parseOpToExpr: " << p << std::endl;
    1191                 :          0 :   Term expr;
    1192         [ -  - ]:          0 :   if (p.d_kind != Kind::NULL_TERM)
    1193                 :            :   {
    1194                 :          0 :     parseError(
    1195                 :            :         "Bad syntax for qualified identifier operator in term position.");
    1196                 :            :   }
    1197         [ -  - ]:          0 :   else if (!p.d_expr.isNull())
    1198                 :            :   {
    1199                 :          0 :     expr = p.d_expr;
    1200                 :            :   }
    1201                 :            :   else
    1202                 :            :   {
    1203                 :          0 :     checkDeclaration(p.d_name, CHECK_DECLARED, SYM_VARIABLE);
    1204                 :          0 :     expr = getVariable(p.d_name);
    1205                 :            :   }
    1206                 :          0 :   Assert(!expr.isNull());
    1207                 :          0 :   return expr;
    1208                 :          0 : }
    1209                 :            : 
    1210                 :    6170924 : Term Smt2State::applyParseOp(const ParseOp& p, std::vector<Term>& args)
    1211                 :            : {
    1212                 :    6170924 :   bool isBuiltinOperator = false;
    1213                 :            :   // the builtin kind of the overall return expression
    1214                 :    6170924 :   Kind kind = Kind::NULL_TERM;
    1215                 :            :   // First phase: process the operator
    1216         [ -  + ]:    6170924 :   if (TraceIsOn("parser"))
    1217                 :            :   {
    1218         [ -  - ]:          0 :     Trace("parser") << "applyParseOp: " << p << " to:" << std::endl;
    1219         [ -  - ]:          0 :     for (std::vector<Term>::iterator i = args.begin(); i != args.end(); ++i)
    1220                 :            :     {
    1221         [ -  - ]:          0 :       Trace("parser") << "++ " << *i << std::endl;
    1222                 :            :     }
    1223                 :            :   }
    1224         [ +  + ]:    6170924 :   if (p.d_kind == Kind::NULLABLE_LIFT)
    1225                 :            :   {
    1226                 :         12 :     auto it = d_operatorKindMap.find(p.d_name);
    1227         [ +  + ]:         12 :     if (it == d_operatorKindMap.end())
    1228                 :            :     {
    1229                 :            :       // the lifted symbol is not a defined kind. So we construct a normal
    1230                 :            :       // term.
    1231                 :            :       // Input : ((_ nullable.lift f) x y)
    1232                 :            :       // output: (nullable.lift f x y)
    1233                 :          9 :       ParserState::checkDeclaration(p.d_name, DeclarationCheck::CHECK_DECLARED);
    1234                 :          9 :       Term function = getVariable(p.d_name);
    1235                 :          9 :       args.insert(args.begin(), function);
    1236                 :          9 :       return d_tm.mkTerm(Kind::NULLABLE_LIFT, args);
    1237                 :          9 :     }
    1238                 :            :     else
    1239                 :            :     {
    1240                 :          3 :       Kind liftedKind = getOperatorKind(p.d_name);
    1241                 :          3 :       return d_tm.mkNullableLift(liftedKind, args);
    1242                 :            :     }
    1243                 :            :   }
    1244         [ +  + ]:    6170912 :   if (!p.d_indices.empty())
    1245                 :            :   {
    1246                 :     174098 :     Op op;
    1247                 :     174098 :     Kind k = getIndexedOpKind(p.d_name);
    1248         [ +  + ]:     174098 :     if (k == Kind::UNDEFINED_KIND)
    1249                 :            :     {
    1250                 :            :       // Resolve indexed symbols that cannot be resolved without knowing the
    1251                 :            :       // type of the arguments. This is currently limited to `to_fp`,
    1252                 :            :       // `tuple.select`, and `tuple.update`.
    1253                 :       1287 :       size_t nchildren = args.size();
    1254         [ +  + ]:       1287 :       if (p.d_name == "to_fp")
    1255                 :            :       {
    1256         [ +  + ]:        296 :         if (nchildren == 1)
    1257                 :            :         {
    1258                 :        107 :           kind = Kind::FLOATINGPOINT_TO_FP_FROM_IEEE_BV;
    1259                 :        107 :           op = d_tm.mkOp(kind, p.d_indices);
    1260                 :            :         }
    1261 [ +  - ][ +  + ]:        189 :         else if (nchildren > 2 || nchildren == 0)
    1262                 :            :         {
    1263                 :          1 :           std::stringstream ss;
    1264                 :            :           ss << "Wrong number of arguments for indexed operator to_fp, "
    1265                 :            :                 "expected "
    1266                 :          1 :                 "1 or 2, got "
    1267                 :          1 :              << nchildren;
    1268                 :          2 :           parseError(ss.str());
    1269                 :          1 :         }
    1270         [ -  + ]:        188 :         else if (!args[0].getSort().isRoundingMode())
    1271                 :            :         {
    1272                 :          0 :           std::stringstream ss;
    1273                 :          0 :           ss << "Expected a rounding mode as the first argument, got "
    1274                 :          0 :              << args[0].getSort();
    1275                 :          0 :           parseError(ss.str());
    1276                 :          0 :         }
    1277                 :            :         else
    1278                 :            :         {
    1279                 :        188 :           Sort t = args[1].getSort();
    1280                 :            : 
    1281         [ +  + ]:        188 :           if (t.isFloatingPoint())
    1282                 :            :           {
    1283                 :         24 :             kind = Kind::FLOATINGPOINT_TO_FP_FROM_FP;
    1284                 :         24 :             op = d_tm.mkOp(kind, p.d_indices);
    1285                 :            :           }
    1286 [ +  - ][ +  + ]:        164 :           else if (t.isInteger() || t.isReal())
                 [ +  + ]
    1287                 :            :           {
    1288                 :        101 :             kind = Kind::FLOATINGPOINT_TO_FP_FROM_REAL;
    1289                 :        101 :             op = d_tm.mkOp(kind, p.d_indices);
    1290                 :            :           }
    1291                 :            :           else
    1292                 :            :           {
    1293                 :         63 :             kind = Kind::FLOATINGPOINT_TO_FP_FROM_SBV;
    1294                 :         63 :             op = d_tm.mkOp(kind, p.d_indices);
    1295                 :            :           }
    1296                 :        188 :         }
    1297                 :            :       }
    1298 [ +  + ][ +  - ]:        991 :       else if (p.d_name == "tuple.select" || p.d_name == "tuple.update")
                 [ +  - ]
    1299                 :            :       {
    1300                 :        991 :         bool isSelect = (p.d_name == "tuple.select");
    1301         [ -  + ]:        991 :         if (p.d_indices.size() != 1)
    1302                 :            :         {
    1303                 :          0 :           parseError("wrong number of indices for tuple select or update");
    1304                 :            :         }
    1305                 :        991 :         uint64_t n = p.d_indices[0];
    1306 [ +  + ][ -  + ]:        991 :         if (args.size() != (isSelect ? 1 : 2))
    1307                 :            :         {
    1308                 :          0 :           parseError("wrong number of arguments for tuple select or update");
    1309                 :            :         }
    1310                 :        991 :         Sort t = args[0].getSort();
    1311         [ -  + ]:        991 :         if (!t.isTuple())
    1312                 :            :         {
    1313                 :          0 :           parseError("tuple select or update applied to non-tuple");
    1314                 :            :         }
    1315                 :        991 :         size_t length = t.getTupleLength();
    1316         [ -  + ]:        991 :         if (n >= length)
    1317                 :            :         {
    1318                 :          0 :           std::stringstream ss;
    1319                 :          0 :           ss << "tuple is of length " << length << "; cannot access index "
    1320                 :          0 :              << n;
    1321                 :          0 :           parseError(ss.str());
    1322                 :          0 :         }
    1323                 :        991 :         const Datatype& dt = t.getDatatype();
    1324                 :        991 :         Term ret;
    1325         [ +  + ]:        991 :         if (isSelect)
    1326                 :            :         {
    1327                 :            :           ret =
    1328 [ +  + ][ -  - ]:       2853 :               d_tm.mkTerm(Kind::APPLY_SELECTOR, {dt[0][n].getTerm(), args[0]});
    1329                 :            :         }
    1330                 :            :         else
    1331                 :            :         {
    1332 [ +  + ][ -  - ]:        280 :           ret = d_tm.mkTerm(Kind::APPLY_UPDATER,
    1333                 :        120 :                             {dt[0][n].getUpdaterTerm(), args[0], args[1]});
    1334                 :            :         }
    1335         [ +  - ]:       1982 :         Trace("parser") << "applyParseOp: return selector/updater " << ret
    1336                 :        991 :                         << std::endl;
    1337                 :        991 :         return ret;
    1338                 :        991 :       }
    1339                 :            :       else
    1340                 :            :       {
    1341                 :          0 :         DebugUnhandled() << "Failed to resolve indexed operator " << p.d_name;
    1342                 :            :       }
    1343                 :            :     }
    1344                 :            :     else
    1345                 :            :     {
    1346                 :            :       // otherwise, an ordinary operator
    1347                 :     172811 :       op = d_tm.mkOp(k, p.d_indices);
    1348                 :            :     }
    1349                 :     173103 :     return d_tm.mkTerm(op, args);
    1350                 :     174098 :   }
    1351         [ +  + ]:    5996814 :   else if (p.d_kind != Kind::NULL_TERM)
    1352                 :            :   {
    1353                 :            :     // It is a special case, e.g. tuple.select or array constant specification.
    1354                 :            :     // We have to wait until the arguments are parsed to resolve it.
    1355                 :            :   }
    1356         [ +  + ]:    5982113 :   else if (!p.d_expr.isNull())
    1357                 :            :   {
    1358                 :            :     // An explicit operator, e.g. an apply function
    1359                 :         27 :     Kind fkind = getKindForFunction(p.d_expr);
    1360         [ +  - ]:         27 :     if (fkind != Kind::UNDEFINED_KIND)
    1361                 :            :     {
    1362                 :            :       // Some operators may require a specific kind.
    1363                 :            :       // Testers are handled differently than other indexed operators,
    1364                 :            :       // since they require a kind.
    1365                 :         27 :       kind = fkind;
    1366         [ +  - ]:         54 :       Trace("parser") << "Got function kind " << kind << " for expression "
    1367                 :         27 :                       << std::endl;
    1368                 :            :     }
    1369                 :         27 :     args.insert(args.begin(), p.d_expr);
    1370                 :            :   }
    1371                 :            :   else
    1372                 :            :   {
    1373                 :    5982086 :     isBuiltinOperator = isOperatorEnabled(p.d_name);
    1374         [ +  + ]:    5982086 :     if (isBuiltinOperator)
    1375                 :            :     {
    1376                 :            :       // a builtin operator, convert to kind
    1377                 :    5181546 :       kind = getOperatorKind(p.d_name);
    1378                 :            :       // special case: indexed operators with zero arguments
    1379 [ +  + ][ +  + ]:    5181546 :       if (kind == Kind::TUPLE_PROJECT || kind == Kind::TABLE_PROJECT
    1380 [ +  - ][ +  - ]:    5181538 :           || kind == Kind::TABLE_AGGREGATE || kind == Kind::TABLE_JOIN
    1381 [ +  + ][ +  + ]:    5181538 :           || kind == Kind::TABLE_GROUP || kind == Kind::RELATION_GROUP
    1382 [ +  - ][ +  + ]:    5181526 :           || kind == Kind::RELATION_AGGREGATE || kind == Kind::RELATION_PROJECT
    1383         [ -  + ]:    5181508 :           || kind == Kind::RELATION_TABLE_JOIN)
    1384                 :            :       {
    1385                 :         38 :         std::vector<uint32_t> indices;
    1386                 :         38 :         Op op = d_tm.mkOp(kind, indices);
    1387                 :         38 :         return d_tm.mkTerm(op, args);
    1388                 :         38 :       }
    1389         [ +  + ]:    5181508 :       else if (kind == Kind::APPLY_CONSTRUCTOR)
    1390                 :            :       {
    1391         [ +  + ]:       5558 :         if (p.d_name == "tuple")
    1392                 :            :         {
    1393                 :            :           // tuple application
    1394                 :       5381 :           return d_tm.mkTuple(args);
    1395                 :            :         }
    1396         [ +  - ]:        177 :         else if (p.d_name == "nullable.some")
    1397                 :            :         {
    1398         [ +  + ]:        177 :           if (args.size() == 1)
    1399                 :            :           {
    1400                 :        176 :             return d_tm.mkNullableSome(args[0]);
    1401                 :            :           }
    1402                 :          3 :           parseError("nullable.some requires exactly one argument.");
    1403                 :            :         }
    1404                 :            :         else
    1405                 :            :         {
    1406                 :          0 :           std::stringstream ss;
    1407                 :          0 :           ss << "Unknown APPLY_CONSTRUCTOR symbol '" << p.d_name << "'";
    1408                 :          0 :           parseError(ss.str());
    1409                 :          0 :         }
    1410                 :            :       }
    1411         [ +  + ]:    5175950 :       else if (kind == Kind::APPLY_SELECTOR)
    1412                 :            :       {
    1413         [ +  - ]:         63 :         if (p.d_name == "nullable.val")
    1414                 :            :         {
    1415         [ +  - ]:         63 :           if (args.size() == 1)
    1416                 :            :           {
    1417                 :         63 :             return d_tm.mkNullableVal(args[0]);
    1418                 :            :           }
    1419                 :          0 :           parseError("nullable.val requires exactly one argument.");
    1420                 :            :         }
    1421                 :            :         else
    1422                 :            :         {
    1423                 :          0 :           std::stringstream ss;
    1424                 :          0 :           ss << "Unknown APPLY_SELECTOR symbol '" << p.d_name << "'";
    1425                 :          0 :           parseError(ss.str());
    1426                 :          0 :         }
    1427                 :            :       }
    1428         [ +  + ]:    5175887 :       else if (kind == Kind::APPLY_TESTER)
    1429                 :            :       {
    1430         [ +  + ]:         67 :         if (p.d_name == "nullable.is_null")
    1431                 :            :         {
    1432         [ +  - ]:         53 :           if (args.size() == 1)
    1433                 :            :           {
    1434                 :         53 :             return d_tm.mkNullableIsNull(args[0]);
    1435                 :            :           }
    1436                 :          0 :           parseError("nullable.is_null requires exactly one argument.");
    1437                 :            :         }
    1438         [ +  - ]:         14 :         else if (p.d_name == "nullable.is_some")
    1439                 :            :         {
    1440         [ +  - ]:         14 :           if (args.size() == 1)
    1441                 :            :           {
    1442                 :         14 :             return d_tm.mkNullableIsSome(args[0]);
    1443                 :            :           }
    1444                 :          0 :           parseError("nullable.is_some requires exactly one argument.");
    1445                 :            :         }
    1446                 :            :         else
    1447                 :            :         {
    1448                 :          0 :           std::stringstream ss;
    1449                 :          0 :           ss << "Unknown APPLY_TESTER symbol '" << p.d_name << "'";
    1450                 :          0 :           parseError(ss.str());
    1451                 :          0 :         }
    1452                 :            :       }
    1453         [ +  - ]:   10351640 :       Trace("parser") << "Got builtin kind " << kind << " for name"
    1454                 :    5175820 :                       << std::endl;
    1455                 :            :     }
    1456                 :            :     else
    1457                 :            :     {
    1458                 :            :       // A non-built-in function application, get the expression
    1459                 :     800566 :       checkDeclaration(p.d_name, CHECK_DECLARED, SYM_VARIABLE);
    1460                 :     800527 :       Term v = getVariable(p.d_name);
    1461         [ +  + ]:     800527 :       if (!v.isNull())
    1462                 :            :       {
    1463                 :     799630 :         checkFunctionLike(v);
    1464                 :     799628 :         kind = getKindForFunction(v);
    1465                 :     799628 :         args.insert(args.begin(), v);
    1466                 :            :       }
    1467                 :            :       else
    1468                 :            :       {
    1469                 :            :         // Overloaded symbol?
    1470                 :            :         // Could not find the expression. It may be an overloaded symbol,
    1471                 :            :         // in which case we may find it after knowing the types of its
    1472                 :            :         // arguments.
    1473                 :        898 :         std::vector<Sort> argTypes;
    1474         [ +  + ]:       2276 :         for (std::vector<Term>::iterator i = args.begin(); i != args.end(); ++i)
    1475                 :            :         {
    1476                 :       1378 :           argTypes.push_back((*i).getSort());
    1477                 :            :         }
    1478                 :        898 :         Term fop = getOverloadedFunctionForTypes(p.d_name, argTypes);
    1479         [ +  - ]:        898 :         if (!fop.isNull())
    1480                 :            :         {
    1481                 :        898 :           checkFunctionLike(fop);
    1482                 :        898 :           kind = getKindForFunction(fop);
    1483                 :        898 :           args.insert(args.begin(), fop);
    1484                 :            :         }
    1485                 :            :         else
    1486                 :            :         {
    1487                 :          0 :           parseError(
    1488                 :            :               "Cannot find unambiguous overloaded function for argument "
    1489                 :            :               "types.");
    1490                 :            :         }
    1491                 :        898 :       }
    1492                 :     800527 :     }
    1493                 :            :   }
    1494                 :            :   // handle special cases
    1495                 :            :   // If we marked the operator as "INTERNAL_KIND", then the name/expr
    1496                 :            :   // determine the operator. This handles constant arrays.
    1497         [ +  + ]:    5991074 :   if (p.d_kind == Kind::INTERNAL_KIND)
    1498                 :            :   {
    1499                 :            :     // (as const (Array T1 T2))
    1500         [ +  - ]:        440 :     if (!strictModeEnabled() && p.d_name == "const"
    1501 [ +  - ][ +  - ]:        440 :         && isTheoryEnabled(internal::theory::THEORY_ARRAYS))
                 [ +  - ]
    1502                 :            :     {
    1503         [ -  + ]:        220 :       if (args.size() != 1)
    1504                 :            :       {
    1505                 :          0 :         parseError("Too many arguments to array constant.");
    1506                 :            :       }
    1507                 :        220 :       Term constVal = args[0];
    1508                 :            : 
    1509 [ -  + ][ -  + ]:        220 :       Assert(!p.d_expr.isNull());
                 [ -  - ]
    1510                 :        220 :       Sort sort = p.d_expr.getSort();
    1511         [ -  + ]:        220 :       if (!sort.isArray())
    1512                 :            :       {
    1513                 :          0 :         std::stringstream ss;
    1514                 :          0 :         ss << "expected array constant term, but cast is not of array type"
    1515                 :          0 :            << std::endl
    1516                 :          0 :            << "cast type: " << sort;
    1517                 :          0 :         parseError(ss.str());
    1518                 :          0 :       }
    1519         [ -  + ]:        220 :       if (sort.getArrayElementSort() != constVal.getSort())
    1520                 :            :       {
    1521                 :          0 :         std::stringstream ss;
    1522                 :          0 :         ss << "type mismatch inside array constant term:" << std::endl
    1523                 :          0 :            << "array type:          " << sort << std::endl
    1524                 :          0 :            << "expected const type: " << sort.getArrayElementSort() << std::endl
    1525                 :          0 :            << "computed const type: " << constVal.getSort();
    1526                 :          0 :         parseError(ss.str());
    1527                 :          0 :       }
    1528                 :        220 :       Term ret = d_tm.mkConstArray(sort, constVal);
    1529         [ +  - ]:        220 :       Trace("parser") << "applyParseOp: return store all " << ret << std::endl;
    1530                 :        220 :       return ret;
    1531                 :        220 :     }
    1532                 :            :     else
    1533                 :            :     {
    1534                 :            :       // should never happen
    1535                 :          0 :       parseError("Could not process internal parsed operator");
    1536                 :            :     }
    1537                 :            :   }
    1538 [ +  + ][ +  + ]:    5990854 :   else if (p.d_kind == Kind::APPLY_TESTER || p.d_kind == Kind::APPLY_UPDATER)
    1539                 :            :   {
    1540                 :      13332 :     Term iop = mkIndexedOp(p.d_kind, {p.d_name}, args);
    1541                 :       4442 :     kind = p.d_kind;
    1542                 :       4442 :     args.insert(args.begin(), iop);
    1543                 :       4442 :   }
    1544         [ +  + ]:    5986411 :   else if (p.d_kind != Kind::NULL_TERM)
    1545                 :            :   {
    1546                 :            :     // it should not have an expression or type specified at this point
    1547         [ -  + ]:      10038 :     if (!p.d_expr.isNull())
    1548                 :            :     {
    1549                 :          0 :       std::stringstream ss;
    1550                 :          0 :       ss << "Could not process parsed qualified identifier kind " << p.d_kind;
    1551                 :          0 :       parseError(ss.str());
    1552                 :          0 :     }
    1553                 :            :     // otherwise it is a simple application
    1554                 :      10038 :     kind = p.d_kind;
    1555                 :            :   }
    1556         [ +  + ]:    5976373 :   else if (isBuiltinOperator)
    1557                 :            :   {
    1558 [ +  + ][ +  + ]:    5175820 :     if (kind == Kind::EQUAL || kind == Kind::DISTINCT)
    1559                 :            :     {
    1560                 :     583407 :       bool isReal = false;
    1561                 :            :       // need hol if these operators are applied over function args
    1562         [ +  + ]:    1762347 :       for (const Term& i : args)
    1563                 :            :       {
    1564                 :    1178940 :         Sort s = i.getSort();
    1565         [ +  + ]:    1178940 :         if (!isHoEnabled())
    1566                 :            :         {
    1567         [ -  + ]:    1139609 :           if (s.isFunction())
    1568                 :            :           {
    1569                 :          0 :             parseError(
    1570                 :            :                 "Cannot apply equality to functions unless logic is prefixed "
    1571                 :            :                 "by HO_.");
    1572                 :            :           }
    1573                 :            :         }
    1574         [ +  + ]:    1178940 :         if (s.isReal())
    1575                 :            :         {
    1576                 :     110269 :           isReal = true;
    1577                 :            :         }
    1578                 :    1178940 :       }
    1579                 :            :       // If strict mode is not enabled, we are permissive for Int and Real
    1580                 :            :       // subtyping. Note that other arithmetic operators and relations are
    1581                 :            :       // already permissive, e.g. <=, +.
    1582 [ +  + ][ +  + ]:     583407 :       if (isReal && !strictModeEnabled())
                 [ +  + ]
    1583                 :            :       {
    1584         [ +  + ]:     165475 :         for (Term& i : args)
    1585                 :            :         {
    1586                 :     110343 :           Sort s = i.getSort();
    1587         [ +  + ]:     110343 :           if (s.isInteger())
    1588                 :            :           {
    1589                 :        166 :             i = d_tm.mkTerm(Kind::TO_REAL, {i});
    1590                 :            :           }
    1591                 :     110343 :         }
    1592                 :            :       }
    1593                 :            :     }
    1594         [ +  + ]:    5175820 :     if (strictModeEnabled())
    1595                 :            :     {
    1596                 :            :       // Catch cases of mixed arithmetic, which our internal type checker is
    1597                 :            :       // lenient for. In particular, any case that is ill-typed according to
    1598                 :            :       // the SMT standard but not in our internal type checker are handled
    1599                 :            :       // here.
    1600                 :        240 :       Sort sreq;  // if applicable, the sort which all arguments must be.
    1601                 :        240 :       bool sameType = false;
    1602 [ +  + ][ +  - ]:        240 :       if (kind == Kind::ADD || kind == Kind::MULT || kind == Kind::SUB
                 [ +  - ]
    1603 [ +  - ][ +  - ]:        239 :           || kind == Kind::GEQ || kind == Kind::GT || kind == Kind::LEQ
                 [ +  - ]
    1604         [ -  + ]:        239 :           || kind == Kind::LT)
    1605                 :            :       {
    1606                 :            :         // no mixed arithmetic
    1607                 :          1 :         sreq = args[0].getSort();
    1608                 :          1 :         sameType = true;
    1609                 :            :       }
    1610 [ +  - ][ +  - ]:        239 :       else if (kind == Kind::DIVISION || kind == Kind::TO_INTEGER
    1611         [ -  + ]:        239 :                || kind == Kind::IS_INTEGER)
    1612                 :            :       {
    1613                 :            :         // must apply division, to_int, is_int to real only
    1614                 :          0 :         sreq = d_tm.getRealSort();
    1615                 :            :       }
    1616 [ +  + ][ -  + ]:        239 :       else if (kind == Kind::TO_REAL || kind == Kind::ABS)
    1617                 :            :       {
    1618                 :            :         // must apply to_real, abs to integer only
    1619                 :          1 :         sreq = d_tm.getIntegerSort();
    1620                 :            :       }
    1621         [ +  + ]:        240 :       if (!sreq.isNull())
    1622                 :            :       {
    1623         [ +  - ]:          3 :         for (Term& i : args)
    1624                 :            :         {
    1625                 :          3 :           Sort s = i.getSort();
    1626         [ +  + ]:          3 :           if (s != sreq)
    1627                 :            :           {
    1628                 :          2 :             std::stringstream ss;
    1629                 :          2 :             ss << "Due to strict parsing, we require the arguments of " << kind;
    1630         [ +  + ]:          2 :             if (sameType)
    1631                 :            :             {
    1632                 :          1 :               ss << " to have the same type";
    1633                 :            :             }
    1634                 :            :             else
    1635                 :            :             {
    1636                 :          1 :               ss << " to have type " << sreq;
    1637                 :            :             }
    1638                 :          4 :             parseError(ss.str());
    1639                 :          2 :           }
    1640                 :          3 :         }
    1641                 :            :       }
    1642                 :        240 :     }
    1643 [ +  + ][ +  + ]:   10351398 :     if (!strictModeEnabled() && (kind == Kind::AND || kind == Kind::OR)
    1644 [ +  + ][ +  + ]:   10351398 :         && args.size() == 1)
                 [ +  + ]
    1645                 :            :     {
    1646                 :            :       // Unary AND/OR can be replaced with the argument.
    1647         [ +  - ]:       1478 :       Trace("parser") << "applyParseOp: return unary " << args[0] << std::endl;
    1648                 :       1478 :       return args[0];
    1649                 :            :     }
    1650 [ +  + ][ +  + ]:    5174340 :     else if (kind == Kind::SUB && args.size() == 1)
                 [ +  + ]
    1651                 :            :     {
    1652                 :     777147 :       Term ret = d_tm.mkTerm(Kind::NEG, {args[0]});
    1653         [ +  - ]:     259049 :       Trace("parser") << "applyParseOp: return uminus " << ret << std::endl;
    1654                 :     259049 :       return ret;
    1655                 :     259049 :     }
    1656         [ +  + ]:    4915291 :     else if (kind == Kind::FLOATINGPOINT_FP)
    1657                 :            :     {
    1658                 :            :       // (fp #bX #bY #bZ) denotes a floating-point value
    1659         [ +  + ]:        211 :       if (args.size() != 3)
    1660                 :            :       {
    1661                 :          1 :         parseError("expected 3 arguments to 'fp', got "
    1662                 :          4 :                    + std::to_string(args.size()));
    1663                 :            :       }
    1664 [ +  + ][ +  - ]:        210 :       if (isConstBv(args[0]) && isConstBv(args[1]) && isConstBv(args[2]))
         [ +  + ][ +  + ]
    1665                 :            :       {
    1666                 :        198 :         Term ret = d_tm.mkFloatingPoint(args[0], args[1], args[2]);
    1667         [ +  - ]:        394 :         Trace("parser") << "applyParseOp: return floating-point value " << ret
    1668                 :        197 :                         << std::endl;
    1669                 :        197 :         return ret;
    1670                 :        197 :       }
    1671                 :            :     }
    1672         [ +  + ]:    4915080 :     else if (kind == Kind::SKOLEM)
    1673                 :            :     {
    1674                 :         30 :       Term ret;
    1675                 :         30 :       SkolemId skolemId = d_skolemMap[p.d_name];
    1676                 :         30 :       size_t numSkolemIndices = d_tm.getNumIndicesForSkolemId(skolemId);
    1677         [ +  + ]:         30 :       if (numSkolemIndices == args.size())
    1678                 :            :       {
    1679                 :         18 :         ret = d_tm.mkSkolem(skolemId, args);
    1680                 :            :       }
    1681         [ +  + ]:         12 :       else if (numSkolemIndices < args.size())
    1682                 :            :       {
    1683                 :            :         std::vector<Term> skolemArgs(args.begin(),
    1684                 :         11 :                                      args.begin() + numSkolemIndices);
    1685                 :         11 :         Term skolem = d_tm.mkSkolem(skolemId, skolemArgs);
    1686                 :         33 :         std::vector<Term> finalArgs = {skolem};
    1687                 :         33 :         finalArgs.insert(
    1688                 :         22 :             finalArgs.end(), args.begin() + numSkolemIndices, args.end());
    1689                 :         11 :         ret = d_tm.mkTerm(Kind::APPLY_UF, finalArgs);
    1690                 :         11 :       }
    1691                 :            :       else
    1692                 :            :       {
    1693                 :          1 :         std::stringstream ss;
    1694                 :          1 :         ss << "Not enough indices for skolem operator " << skolemId
    1695                 :          1 :            << ". Expects " << numSkolemIndices << ", received " << args.size()
    1696                 :          1 :            << ".";
    1697                 :          2 :         parseError(ss.str());
    1698                 :          1 :       }
    1699         [ +  - ]:         29 :       Trace("parser") << "applyParseOp: return skolem " << ret << std::endl;
    1700                 :         29 :       return ret;
    1701                 :         30 :     }
    1702                 :    4915062 :     Term ret = d_tm.mkTerm(kind, args);
    1703         [ +  - ]:    9830100 :     Trace("parser") << "applyParseOp: return default builtin " << ret
    1704                 :    4915050 :                     << std::endl;
    1705                 :    4915050 :     return ret;
    1706                 :    4915050 :   }
    1707                 :            : 
    1708         [ +  + ]:     815033 :   if (args.size() >= 2)
    1709                 :            :   {
    1710                 :            :     // may be partially applied function, in this case we use HO_APPLY
    1711                 :     806140 :     Sort argt = args[0].getSort();
    1712         [ +  + ]:     806140 :     if (argt.isFunction())
    1713                 :            :     {
    1714                 :     760590 :       unsigned arity = argt.getFunctionArity();
    1715         [ +  + ]:     760590 :       if (args.size() - 1 < arity)
    1716                 :            :       {
    1717         [ -  + ]:        800 :         if (!isHoEnabled())
    1718                 :            :         {
    1719                 :          0 :           parseError(
    1720                 :            :               "Cannot partially apply functions unless logic is prefixed by "
    1721                 :            :               "HO_.");
    1722                 :            :         }
    1723         [ +  - ]:        800 :         Trace("parser") << "Partial application of " << args[0];
    1724         [ +  - ]:        800 :         Trace("parser") << " : #argTypes = " << arity;
    1725         [ +  - ]:        800 :         Trace("parser") << ", #args = " << args.size() - 1 << std::endl;
    1726                 :        800 :         Term ret = d_tm.mkTerm(Kind::HO_APPLY, args);
    1727         [ +  - ]:       1600 :         Trace("parser") << "applyParseOp: return curry higher order " << ret
    1728                 :        800 :                         << std::endl;
    1729                 :            :         // must curry the partial application
    1730                 :        800 :         return ret;
    1731                 :        800 :       }
    1732                 :            :     }
    1733         [ +  + ]:     806140 :   }
    1734         [ -  + ]:     814233 :   if (kind == Kind::NULL_TERM)
    1735                 :            :   {
    1736                 :            :     // should never happen in the new API
    1737                 :          0 :     parseError("do not know how to process parse op");
    1738                 :            :   }
    1739         [ +  - ]:    1628466 :   Trace("parser") << "Try default term construction for kind " << kind
    1740                 :     814233 :                   << " #args = " << args.size() << "..." << std::endl;
    1741                 :     814233 :   Term ret = d_tm.mkTerm(kind, args);
    1742         [ +  - ]:     814228 :   Trace("parser") << "applyParseOp: return : " << ret << std::endl;
    1743                 :     814228 :   return ret;
    1744                 :     814228 : }
    1745                 :            : 
    1746                 :      40904 : Sort Smt2State::getParametricSort(const std::string& name,
    1747                 :            :                                   const std::vector<Sort>& args)
    1748                 :            : {
    1749         [ -  + ]:      40904 :   if (args.empty())
    1750                 :            :   {
    1751                 :          0 :     parseError(
    1752                 :            :         "Extra parentheses around sort name not "
    1753                 :            :         "permitted in SMT-LIB");
    1754                 :            :   }
    1755                 :            :   // builtin parametric sorts are handled manually
    1756                 :      40904 :   Sort t;
    1757 [ +  + ][ +  + ]:      40904 :   if (name == "Array" && isTheoryEnabled(internal::theory::THEORY_ARRAYS))
                 [ +  + ]
    1758                 :            :   {
    1759         [ -  + ]:       6543 :     if (args.size() != 2)
    1760                 :            :     {
    1761                 :          0 :       parseError("Illegal array type.");
    1762                 :            :     }
    1763                 :       6543 :     t = d_tm.mkArraySort(args[0], args[1]);
    1764                 :            :   }
    1765 [ +  + ][ +  + ]:      34361 :   else if (name == "Set" && isTheoryEnabled(internal::theory::THEORY_SETS))
                 [ +  + ]
    1766                 :            :   {
    1767         [ -  + ]:       3819 :     if (args.size() != 1)
    1768                 :            :     {
    1769                 :          0 :       parseError("Illegal set type.");
    1770                 :            :     }
    1771                 :       3819 :     t = d_tm.mkSetSort(args[0]);
    1772                 :            :   }
    1773 [ +  + ][ +  - ]:      30542 :   else if (name == "Bag" && isTheoryEnabled(internal::theory::THEORY_BAGS))
                 [ +  + ]
    1774                 :            :   {
    1775         [ -  + ]:        714 :     if (args.size() != 1)
    1776                 :            :     {
    1777                 :          0 :       parseError("Illegal bag type.");
    1778                 :            :     }
    1779                 :        714 :     t = d_tm.mkBagSort(args[0]);
    1780                 :            :   }
    1781         [ +  - ]:      31179 :   else if (name == "Seq" && !strictModeEnabled()
    1782 [ +  + ][ +  - ]:      31179 :            && isTheoryEnabled(internal::theory::THEORY_STRINGS))
                 [ +  + ]
    1783                 :            :   {
    1784         [ -  + ]:       1351 :     if (args.size() != 1)
    1785                 :            :     {
    1786                 :          0 :       parseError("Illegal sequence type.");
    1787                 :            :     }
    1788                 :       1351 :     t = d_tm.mkSequenceSort(args[0]);
    1789                 :            :   }
    1790 [ +  + ][ +  - ]:      28477 :   else if (name == "Tuple" && !strictModeEnabled())
                 [ +  + ]
    1791                 :            :   {
    1792                 :       4161 :     t = d_tm.mkTupleSort(args);
    1793                 :            :   }
    1794 [ +  + ][ +  - ]:      24316 :   else if (name == "Nullable" && !strictModeEnabled())
                 [ +  + ]
    1795                 :            :   {
    1796         [ -  + ]:        718 :     if (args.size() != 1)
    1797                 :            :     {
    1798                 :          0 :       parseError("Illegal nullable type.");
    1799                 :            :     }
    1800                 :        718 :     t = d_tm.mkNullableSort(args[0]);
    1801                 :            :   }
    1802 [ +  + ][ +  - ]:      23598 :   else if (name == "Relation" && !strictModeEnabled())
                 [ +  + ]
    1803                 :            :   {
    1804                 :       1942 :     Sort tupleSort = d_tm.mkTupleSort(args);
    1805                 :       1942 :     t = d_tm.mkSetSort(tupleSort);
    1806                 :       1942 :   }
    1807 [ +  + ][ +  - ]:      21656 :   else if (name == "Table" && !strictModeEnabled())
                 [ +  + ]
    1808                 :            :   {
    1809                 :        182 :     Sort tupleSort = d_tm.mkTupleSort(args);
    1810                 :        182 :     t = d_tm.mkBagSort(tupleSort);
    1811                 :        182 :   }
    1812 [ +  + ][ +  + ]:      21474 :   else if (name == "->" && isHoEnabled())
                 [ +  + ]
    1813                 :            :   {
    1814         [ -  + ]:      19889 :     if (args.size() < 2)
    1815                 :            :     {
    1816                 :          0 :       parseError("Arrow types must have at least 2 arguments");
    1817                 :            :     }
    1818                 :            :     // flatten the type
    1819                 :      19889 :     Sort rangeType = args.back();
    1820                 :      19889 :     std::vector<Sort> dargs(args.begin(), args.end() - 1);
    1821                 :      19889 :     t = mkFlatFunctionType(dargs, rangeType);
    1822                 :      19889 :   }
    1823                 :            :   else
    1824                 :            :   {
    1825                 :       1585 :     t = ParserState::getParametricSort(name, args);
    1826                 :            :   }
    1827                 :      40901 :   return t;
    1828                 :          3 : }
    1829                 :            : 
    1830                 :      34651 : Sort Smt2State::getIndexedSort(const std::string& name,
    1831                 :            :                                const std::vector<std::string>& numerals)
    1832                 :            : {
    1833                 :      34651 :   Sort ret;
    1834         [ +  + ]:      34651 :   if (name == "BitVec")
    1835                 :            :   {
    1836         [ -  + ]:      33018 :     if (numerals.size() != 1)
    1837                 :            :     {
    1838                 :          0 :       parseError("Illegal bitvector type.");
    1839                 :            :     }
    1840                 :      33018 :     uint32_t n0 = parseStringToUnsigned(numerals[0]);
    1841         [ -  + ]:      33017 :     if (n0 == 0)
    1842                 :            :     {
    1843                 :          0 :       parseError("Illegal bitvector size: 0");
    1844                 :            :     }
    1845                 :      33017 :     ret = d_tm.mkBitVectorSort(n0);
    1846                 :            :   }
    1847         [ +  + ]:       1633 :   else if (name == "FiniteField")
    1848                 :            :   {
    1849         [ -  + ]:       1120 :     if (numerals.size() != 1)
    1850                 :            :     {
    1851                 :          0 :       parseError("Illegal finite field type.");
    1852                 :            :     }
    1853                 :       1120 :     ret = d_tm.mkFiniteFieldSort(numerals.front());
    1854                 :            :   }
    1855         [ +  - ]:        513 :   else if (name == "FloatingPoint")
    1856                 :            :   {
    1857         [ -  + ]:        513 :     if (numerals.size() != 2)
    1858                 :            :     {
    1859                 :          0 :       parseError("Illegal floating-point type.");
    1860                 :            :     }
    1861                 :        513 :     uint32_t n0 = parseStringToUnsigned(numerals[0]);
    1862                 :        513 :     uint32_t n1 = parseStringToUnsigned(numerals[1]);
    1863         [ -  + ]:        513 :     if (!internal::validExponentSize(n0))
    1864                 :            :     {
    1865                 :          0 :       parseError("Illegal floating-point exponent size");
    1866                 :            :     }
    1867         [ -  + ]:        513 :     if (!internal::validSignificandSize(n1))
    1868                 :            :     {
    1869                 :          0 :       parseError("Illegal floating-point significand size");
    1870                 :            :     }
    1871                 :        513 :     ret = d_tm.mkFloatingPointSort(n0, n1);
    1872                 :            :   }
    1873                 :            :   else
    1874                 :            :   {
    1875                 :          0 :     std::stringstream ss;
    1876                 :          0 :     ss << "unknown indexed sort symbol `" << name << "'";
    1877                 :          0 :     parseError(ss.str());
    1878                 :          0 :   }
    1879                 :      34650 :   return ret;
    1880                 :          1 : }
    1881                 :            : 
    1882                 :    5982150 : bool Smt2State::isClosure(const std::string& name)
    1883                 :            : {
    1884                 :    5982150 :   return d_closureKindMap.find(name) != d_closureKindMap.end();
    1885                 :            : }
    1886                 :            : 
    1887                 :       5681 : std::unique_ptr<Cmd> Smt2State::handlePush(std::optional<uint32_t> nscopes)
    1888                 :            : {
    1889                 :       5681 :   checkThatLogicIsSet();
    1890                 :            : 
    1891         [ +  + ]:       5681 :   if (!nscopes)
    1892                 :            :   {
    1893         [ -  + ]:        453 :     if (strictModeEnabled())
    1894                 :            :     {
    1895                 :          0 :       parseError(
    1896                 :            :           "Strict compliance mode demands an integer to be provided to "
    1897                 :            :           "(push).  Maybe you want (push 1)?");
    1898                 :            :     }
    1899                 :        453 :     nscopes = 1;
    1900                 :            :   }
    1901                 :            : 
    1902         [ +  + ]:      11385 :   for (uint32_t i = 0; i < *nscopes; i++)
    1903                 :            :   {
    1904                 :       5704 :     pushScope(true);
    1905                 :            :   }
    1906                 :       5681 :   return std::make_unique<PushCommand>(*nscopes);
    1907                 :            : }
    1908                 :            : 
    1909                 :       4564 : std::unique_ptr<Cmd> Smt2State::handlePop(std::optional<uint32_t> nscopes)
    1910                 :            : {
    1911                 :       4564 :   checkThatLogicIsSet();
    1912                 :            : 
    1913         [ +  + ]:       4564 :   if (!nscopes)
    1914                 :            :   {
    1915         [ -  + ]:        359 :     if (strictModeEnabled())
    1916                 :            :     {
    1917                 :          0 :       parseError(
    1918                 :            :           "Strict compliance mode demands an integer to be provided to "
    1919                 :            :           "(pop).  Maybe you want (pop 1)?");
    1920                 :            :     }
    1921                 :        359 :     nscopes = 1;
    1922                 :            :   }
    1923                 :            : 
    1924         [ +  + ]:       9275 :   for (uint32_t i = 0; i < *nscopes; i++)
    1925                 :            :   {
    1926                 :       4711 :     popScope();
    1927                 :            :   }
    1928                 :       4564 :   return std::make_unique<PopCommand>(*nscopes);
    1929                 :            : }
    1930                 :            : 
    1931                 :      11261 : void Smt2State::notifyNamedExpression(Term& expr, std::string name)
    1932                 :            : {
    1933                 :      11261 :   checkUserSymbol(name);
    1934                 :            :   // remember the expression name in the symbol manager
    1935                 :      11261 :   NamingResult nr = getSymbolManager()->setExpressionName(expr, name, false);
    1936         [ +  + ]:      11261 :   if (nr == NamingResult::ERROR_IN_BINDER)
    1937                 :            :   {
    1938                 :          3 :     parseError(
    1939                 :            :         "Cannot name a term in a binder (e.g., quantifiers, definitions)");
    1940                 :            :   }
    1941                 :            :   // define the variable. This needs to be done here so that in the rest of the
    1942                 :            :   // command we can use this name, which is required by the semantics of :named.
    1943                 :            :   //
    1944                 :            :   // Note that as we are defining the name to the expression here, names never
    1945                 :            :   // show up in "-o raw-benchmark" nor in proofs. To be able to do it it'd be
    1946                 :            :   // necessary to not define this variable here and create a
    1947                 :            :   // DefineFunctionCommand with the binding, so that names are handled as
    1948                 :            :   // defined functions. However, these commands would need to be processed
    1949                 :            :   // *before* the rest of the command in which the :named attribute appears, so
    1950                 :            :   // the name can be defined in the rest of the command. This would greatly
    1951                 :            :   // complicate the design of the parser and provide little gain, so we opt to
    1952                 :            :   // handle :named as a macro processed directly in the parser.
    1953                 :      11260 :   defineVar(name, expr);
    1954                 :            :   // set the last named term, which ensures that we catch when assertions are
    1955                 :            :   // named
    1956                 :      11260 :   setLastNamedTerm(expr, name);
    1957                 :      11260 : }
    1958                 :            : 
    1959                 :          0 : Term Smt2State::mkAnd(const std::vector<Term>& es) const
    1960                 :            : {
    1961         [ -  - ]:          0 :   if (es.size() == 0)
    1962                 :            :   {
    1963                 :          0 :     return d_tm.mkTrue();
    1964                 :            :   }
    1965         [ -  - ]:          0 :   else if (es.size() == 1)
    1966                 :            :   {
    1967                 :          0 :     return es[0];
    1968                 :            :   }
    1969                 :          0 :   return d_tm.mkTerm(Kind::AND, es);
    1970                 :            : }
    1971                 :            : 
    1972                 :          0 : bool Smt2State::isConstInt(const Term& t)
    1973                 :            : {
    1974                 :          0 :   return t.getKind() == Kind::CONST_INTEGER;
    1975                 :            : }
    1976                 :            : 
    1977                 :        622 : bool Smt2State::isConstBv(const Term& t)
    1978                 :            : {
    1979                 :        622 :   return t.getKind() == Kind::CONST_BITVECTOR;
    1980                 :            : }
    1981                 :            : 
    1982                 :            : }  // namespace parser
    1983                 :            : }  // namespace cvc5

Generated by: LCOV version 1.14