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