sexpr.h
Go to the documentation of this file.
/********************* */
#include "cvc4_public.h"
#ifndef __CVC4__SEXPR_H
#define __CVC4__SEXPR_H
#include <vector>
#include <string>
#include <iomanip>
#include <sstream>
#include "util/integer.h"
#include "util/rational.h"
#include "util/exception.h"
namespace CVC4 {
class CVC4_PUBLIC SExprKeyword {
std::string d_str;
public:
SExprKeyword(const std::string& s) : d_str(s) {}
const std::string& getString() const { return d_str; }
};/* class SExpr::Keyword */
class CVC4_PUBLIC SExpr {
enum SExprTypes {
SEXPR_STRING,
SEXPR_KEYWORD,
SEXPR_INTEGER,
SEXPR_RATIONAL,
SEXPR_NOT_ATOM
} d_sexprType;
CVC4::Integer d_integerValue;
CVC4::Rational d_rationalValue;
std::string d_stringValue;
std::vector<SExpr> d_children;
public:
typedef SExprKeyword Keyword;
SExpr() :
d_sexprType(SEXPR_STRING),
d_integerValue(0),
d_rationalValue(0),
d_stringValue(""),
d_children() {
}
SExpr(const CVC4::Integer& value) :
d_sexprType(SEXPR_INTEGER),
d_integerValue(value),
d_rationalValue(0),
d_stringValue(""),
d_children() {
}
SExpr(int value) :
d_sexprType(SEXPR_INTEGER),
d_integerValue(value),
d_rationalValue(0),
d_stringValue(""),
d_children() {
}
SExpr(long int value) :
d_sexprType(SEXPR_INTEGER),
d_integerValue(value),
d_rationalValue(0),
d_stringValue(""),
d_children() {
}
SExpr(unsigned int value) :
d_sexprType(SEXPR_INTEGER),
d_integerValue(value),
d_rationalValue(0),
d_stringValue(""),
d_children() {
}
SExpr(unsigned long int value) :
d_sexprType(SEXPR_INTEGER),
d_integerValue(value),
d_rationalValue(0),
d_stringValue(""),
d_children() {
}
SExpr(const CVC4::Rational& value) :
d_sexprType(SEXPR_RATIONAL),
d_integerValue(0),
d_rationalValue(value),
d_stringValue(""),
d_children() {
}
SExpr(const std::string& value) :
d_sexprType(SEXPR_STRING),
d_integerValue(0),
d_rationalValue(0),
d_stringValue(value),
d_children() {
}
SExpr(const char* value) :
d_sexprType(SEXPR_STRING),
d_integerValue(0),
d_rationalValue(0),
d_stringValue(value),
d_children() {
}
SExpr(bool value) :
d_sexprType(SEXPR_STRING),
d_integerValue(0),
d_rationalValue(0),
d_stringValue(value ? "true" : "false"),
d_children() {
}
SExpr(const Keyword& value) :
d_sexprType(SEXPR_KEYWORD),
d_integerValue(0),
d_rationalValue(0),
d_stringValue(value.getString()),
d_children() {
}
SExpr(const std::vector<SExpr>& children) :
d_sexprType(SEXPR_NOT_ATOM),
d_integerValue(0),
d_rationalValue(0),
d_stringValue(""),
d_children(children) {
}
bool isAtom() const;
bool isInteger() const;
bool isRational() const;
bool isString() const;
bool isKeyword() const;
std::string getValue() const;
const CVC4::Integer& getIntegerValue() const;
const CVC4::Rational& getRationalValue() const;
const std::vector<SExpr>& getChildren() const;
bool operator==(const SExpr& s) const;
bool operator!=(const SExpr& s) const;
};/* class SExpr */
inline bool SExpr::isAtom() const {
return d_sexprType != SEXPR_NOT_ATOM;
}
inline bool SExpr::isInteger() const {
return d_sexprType == SEXPR_INTEGER;
}
inline bool SExpr::isRational() const {
return d_sexprType == SEXPR_RATIONAL;
}
inline bool SExpr::isString() const {
return d_sexprType == SEXPR_STRING;
}
inline bool SExpr::isKeyword() const {
return d_sexprType == SEXPR_KEYWORD;
}
inline std::string SExpr::getValue() const {
CheckArgument( isAtom(), this );
switch(d_sexprType) {
case SEXPR_INTEGER:
return d_integerValue.toString();
case SEXPR_RATIONAL: {
// We choose to represent rationals as decimal strings rather than
// "numerator/denominator." Perhaps an additional SEXPR_DECIMAL
// could be added if we need both styles, even if it's backed by
// the same Rational object.
std::stringstream ss;
ss << std::fixed << d_rationalValue.getDouble();
return ss.str();
}
case SEXPR_STRING:
case SEXPR_KEYWORD:
return d_stringValue;
case SEXPR_NOT_ATOM:
return std::string();
}
return std::string();
}
inline const CVC4::Integer& SExpr::getIntegerValue() const {
CheckArgument( isInteger(), this );
return d_integerValue;
}
inline const CVC4::Rational& SExpr::getRationalValue() const {
CheckArgument( isRational(), this );
return d_rationalValue;
}
inline const std::vector<SExpr>& SExpr::getChildren() const {
CheckArgument( !isAtom(), this );
return d_children;
}
inline bool SExpr::operator==(const SExpr& s) const {
return d_sexprType == s.d_sexprType &&
d_integerValue == s.d_integerValue &&
d_rationalValue == s.d_rationalValue &&
d_stringValue == s.d_stringValue &&
d_children == s.d_children;
}
inline bool SExpr::operator!=(const SExpr& s) const {
return !(*this == s);
}
std::ostream& operator<<(std::ostream& out, const SExpr& sexpr) CVC4_PUBLIC;
}/* CVC4 namespace */
#endif /* __CVC4__SEXPR_H */
CVC4::Integer
Definition integer_gmp_imp.h:34
CVC4::Integer::toString
std::string toString(int base=10) const
Definition integer_cln_imp.h:364
CVC4::Rational
A multi-precision rational constant.
Definition rational_gmp_imp.h:51
CVC4::Rational::getDouble
double getDouble() const
Get a double representation of this Rational, which is approximate: truncation may occur,...
Definition rational_cln_imp.h:204
CVC4::SExprKeyword
Definition sexpr.h:40
CVC4::SExprKeyword::SExprKeyword
SExprKeyword(const std::string &s)
Definition sexpr.h:43
CVC4::SExprKeyword::getString
const std::string & getString() const
Definition sexpr.h:44
CVC4::SExpr
A simple S-expression.
Definition sexpr.h:51
CVC4::SExpr::isKeyword
bool isKeyword() const
Is this S-expression a keyword?
Definition sexpr.h:246
CVC4::SExpr::isAtom
bool isAtom() const
Is this S-expression an atom?
Definition sexpr.h:230
CVC4::SExpr::isInteger
bool isInteger() const
Is this S-expression an integer?
Definition sexpr.h:234
CVC4::SExpr::SExpr
SExpr(const Keyword &value)
Definition sexpr.h:167
CVC4::SExpr::SExpr
SExpr(const CVC4::Rational &value)
Definition sexpr.h:125
CVC4::SExpr::SExpr
SExpr(int value)
Definition sexpr.h:93
CVC4::SExpr::Keyword
SExprKeyword Keyword
Definition sexpr.h:75
CVC4::SExpr::SExpr
SExpr(unsigned int value)
Definition sexpr.h:109
CVC4::SExpr::getRationalValue
const CVC4::Rational & getRationalValue() const
Get the rational value of this S-expression.
Definition sexpr.h:278
CVC4::SExpr::SExpr
SExpr(long int value)
Definition sexpr.h:101
CVC4::SExpr::getValue
std::string getValue() const
Get the string value of this S-expression.
Definition sexpr.h:250
CVC4::SExpr::getChildren
const std::vector< SExpr > & getChildren() const
Get the children of this S-expression.
Definition sexpr.h:283
CVC4::SExpr::SExpr
SExpr(const char *value)
This constructs a string expression from a const char* value.
Definition sexpr.h:147
CVC4::SExpr::SExpr
SExpr(unsigned long int value)
Definition sexpr.h:117
CVC4::SExpr::SExpr
SExpr(const std::vector< SExpr > &children)
Definition sexpr.h:175
CVC4::SExpr::isString
bool isString() const
Is this S-expression a string?
Definition sexpr.h:242
CVC4::SExpr::SExpr
SExpr(const CVC4::Integer &value)
Definition sexpr.h:85
CVC4::SExpr::getIntegerValue
const CVC4::Integer & getIntegerValue() const
Get the integer value of this S-expression.
Definition sexpr.h:273
CVC4::SExpr::operator==
bool operator==(const SExpr &s) const
Is this S-expression equal to another?
Definition sexpr.h:288
CVC4::SExpr::SExpr
SExpr(const std::string &value)
Definition sexpr.h:133
CVC4::SExpr::SExpr
SExpr(bool value)
This adds a convenience wrapper to SExpr to cast from bools.
Definition sexpr.h:159
CVC4::SExpr::isRational
bool isRational() const
Is this S-expression a rational?
Definition sexpr.h:238
CVC4::SExpr::SExpr
SExpr()
Definition sexpr.h:77
CVC4::SExpr::operator!=
bool operator!=(const SExpr &s) const
Is this S-expression different from another?
Definition sexpr.h:296
cvc4_public.h
Macros that should be defined everywhere during the building of the libraries and driver binary,...
CVC4_PUBLIC
#define CVC4_PUBLIC
Definition cvc4_public.h:30
exception.h
CVC4's exception base class and some associated utilities.
CVC4
Definition expr.h:106
CVC4::operator<<
std::ostream & operator<<(std::ostream &out, const TypeCheckingException &e)
CVC4::CheckArgument
void CheckArgument(bool cond, const T &arg, const char *fmt,...)
Definition exception.h:140