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

Generated by: LCOV version 1.14