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 parsed operators. 11 : : */ 12 : : 13 : : #include "cvc5parser_public.h" 14 : : 15 : : #ifndef CVC5__PARSER__PARSE_OP_H 16 : : #define CVC5__PARSER__PARSE_OP_H 17 : : 18 : : #include <cvc5/cvc5.h> 19 : : 20 : : #include <string> 21 : : #include <vector> 22 : : 23 : : namespace cvc5 { 24 : : 25 : : /** A parsed operator 26 : : * 27 : : * The purpose of this struct is to store information regarding a parsed term 28 : : * that might not be ready to associate with an expression. 29 : : * 30 : : * While parsing terms in smt2, we may store a combination of one or more of 31 : : * the following to track how to process this term: 32 : : * (1) A kind. 33 : : * (2) A string name. 34 : : * (3) An expression expr. 35 : : * 36 : : * Examples: 37 : : * 38 : : * - For declared functions f that we have not yet looked up in a symbol table, 39 : : * we store (2). We may store a name in a state if f is overloaded and we have 40 : : * not yet parsed its arguments to know how to disambiguate f. 41 : : * - For tuple selectors (_ tuple_select n), we store (1) and (3). Kind is set to 42 : : * APPLY_SELECTOR, and expr is set to n, which is to be interpreted by the 43 : : * caller as the n^th generic tuple selector. We do this since there is no 44 : : * AST expression representing generic tuple select, and we do not have enough 45 : : * type information at this point to know the type of the tuple we will be 46 : : * selecting from. 47 : : * - For array constant specifications (as const (Array T1 T2)), we store (1) 48 : : * and (3), where kind is set to INTERNAL_KIND and expr is set to a placeholder 49 : : * variable of type (Array T1 T2). 50 : : * When parsing this as an operator e.g. ((as const (Array T1 T2)) t), we 51 : : * interpret this operator by converting the next parsed constant of type T2 to 52 : : * an Array of type (Array T1 T2) over that constant. 53 : : */ 54 : : struct ParseOp 55 : : { 56 : 6594535 : ParseOp(cvc5::Kind k = cvc5::Kind::NULL_TERM) : d_kind(k) {} 57 : : /** The kind associated with the parsed operator, if it exists */ 58 : : cvc5::Kind d_kind; 59 : : /** The name associated with the parsed operator, if it exists */ 60 : : std::string d_name; 61 : : /** The expression associated with the parsed operator, if it exists */ 62 : : cvc5::Term d_expr; 63 : : /** 64 : : * The indices if the operator is indexed, but cvc5::Op is the null operator. 65 : : * This is the case for operator symbols that cannot be resolved to a kind 66 : : * without parsing the arguments. This is currently only the case for 67 : : * `to_fp`. 68 : : */ 69 : : std::vector<uint32_t> d_indices; 70 : : 71 : : /* Return true if this is equal to 'p'. */ 72 : : bool operator==(const ParseOp& p) const 73 : : { 74 : : return d_kind == p.d_kind && d_name == p.d_name && d_expr == p.d_expr 75 : : && d_indices == p.d_indices; 76 : : } 77 : : }; 78 : : 79 : : std::ostream& operator<<(std::ostream& os, const ParseOp& p); 80 : : 81 : : } // namespace cvc5 82 : : 83 : : #endif /* CVC5__PARSER__PARSE_OP_H */