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 : : * Simple stateless conversion to s-expressions. 11 : : */ 12 : : 13 : : #include "util/sexpr.h" 14 : : 15 : : #include <iostream> 16 : : 17 : : #include "util/integer.h" 18 : : #include "util/rational.h" 19 : : #include "util/statistics_value.h" 20 : : 21 : : namespace cvc5::internal { 22 : : 23 : 130 : void toSExpr(std::ostream& out, const std::string& s) 24 : : { 25 [ + - ][ - + ]: 130 : if (s == "true" || s == "false") [ - + ] 26 : : { 27 : 0 : out << s; 28 : 0 : return; 29 : : } 30 : : try 31 : : { 32 : 130 : Integer tmp(s); 33 : 0 : out << s; 34 : 0 : return; 35 : 0 : } 36 [ - + ]: 130 : catch (std::invalid_argument&) 37 : : { 38 : 130 : } 39 : : try 40 : : { 41 : 130 : Rational tmp(s); 42 : 0 : out << s; 43 : 0 : return; 44 : 0 : } 45 [ - + ]: 130 : catch (std::invalid_argument&) 46 : : { 47 : 130 : } 48 : 130 : out << "\"" << s << "\""; 49 : : } 50 : 122 : void toSExpr(std::ostream& out, const std::unique_ptr<StatisticBaseValue>& sbv) 51 : : { 52 : 122 : out << *sbv; 53 : 122 : } 54 : : 55 : : } // namespace cvc5::internal