34#ifndef GECODE_FLATZINC_AST_HH
35#define GECODE_FLATZINC_AST_HH
61 std::string
what(
void)
const {
return _what; }
85 bool hasAtom(
const std::string&
id);
91 bool isCall(
const std::string&
id);
95 bool hasCall(
const std::string&
id);
149 virtual void print(std::ostream&) = 0;
157 virtual void print(std::ostream& os) {
158 os <<
"b(" << (
b ?
"true" :
"false") <<
")";
166 virtual void print(std::ostream& os) {
175 virtual void print(std::ostream& os) {
192 virtual void print(std::ostream& os) {
203 Var(
int i0,
const std::string& n0) :
i(i0),
n(n0) {}
210 virtual void print(std::ostream& os) {
217 IntVar(
int i0,
const std::string& n0=
"") :
Var(i0,n0) {}
218 virtual void print(std::ostream& os) {
226 virtual void print(std::ostream& os) {
233 SetVar(
int i0,
const std::string& n0=
"") :
Var(i0,n0) {}
234 virtual void print(std::ostream& os) {
242 std::vector<Node*>
a;
248 virtual void print(std::ostream& os) {
250 for (
unsigned int i=0; i<
a.size(); i++) {
301 virtual void print(std::ostream& os) {
302 os <<
id <<
"(";
args->
print(os); os <<
")";
306 if (a->
a.size() != n)
318 :
a(a0),
idx(idx0) {}
320 virtual void print(std::ostream& os) {
332 Atom(
const std::string& id0) :
id(id0) {}
333 virtual void print(std::ostream& os) {
343 virtual void print(std::ostream& os) {
344 os <<
"s(\"" <<
s <<
"\")";
358 for (
int i=
a.size(); i--;)
367 a->
a.push_back(newNode);
373 for (
int i=a->a.size(); i--;)
374 if (
Atom* at =
dynamic_cast<Atom*
>(a->a[i]))
377 }
else if (
Atom* a =
dynamic_cast<Atom*
>(
this)) {
385 if (
Call* a =
dynamic_cast<Call*
>(
this)) {
394 if (
Call* a =
dynamic_cast<Call*
>(
this))
402 for (
int i=a->a.size(); i--;)
403 if (
Call* at =
dynamic_cast<Call*
>(a->a[i]))
407 }
else if (
Call* a =
dynamic_cast<Call*
>(
this)) {
434 for (
int i=a->a.size(); i--;)
435 if (
Call* at =
dynamic_cast<Call*
>(a->a[i]))
438 }
else if (
Call* a =
dynamic_cast<Call*
>(
this)) {
454 if (
Atom* a =
dynamic_cast<Atom*
>(
this))
461 if (
Var* a =
dynamic_cast<Var*
>(
this))
469 throw TypeError(
"integer variable expected");
475 throw TypeError(
"bool variable expected");
481 throw TypeError(
"integer variable expected");
487 throw TypeError(
"set variable expected");
493 throw TypeError(
"integer literal expected");
499 throw TypeError(
"bool literal expected");
505 throw TypeError(
"float literal expected");
517 throw TypeError(
"string literal expected");
521 return (
dynamic_cast<IntVar*
>(
this) !=
nullptr);
525 return (
dynamic_cast<BoolVar*
>(
this) !=
nullptr);
529 return (
dynamic_cast<SetVar*
>(
this) !=
nullptr);
533 return (
dynamic_cast<FloatVar*
>(
this) !=
nullptr);
537 return (
dynamic_cast<IntLit*
>(
this) !=
nullptr);
541 return (
dynamic_cast<BoolLit*
>(
this) !=
nullptr);
545 return (
dynamic_cast<FloatLit*
>(
this) !=
nullptr);
549 return (
dynamic_cast<SetLit*
>(
this) !=
nullptr);
553 return (
dynamic_cast<String*
>(
this) !=
nullptr);
557 return (
dynamic_cast<Array*
>(
this) !=
nullptr);
561 return (
dynamic_cast<Atom*
>(
this) !=
nullptr);
570 if (a->a.size() == 1) {
virtual void print(std::ostream &os)
Output string representation.
ArrayAccess(Node *a0, Node *idx0)
Array(const std::vector< Node * > &a0)
virtual void print(std::ostream &os)
Output string representation.
Node representing an atom
Atom(const std::string &id0)
virtual void print(std::ostream &os)
Output string representation.
virtual void print(std::ostream &os)
Output string representation.
BoolVar(int i0, const std::string &n0="")
Constructor.
virtual void print(std::ostream &os)
Output string representation.
Node representing a function call
Call(const std::string &id0, Node *args0)
virtual void print(std::ostream &os)
Output string representation.
Array * getArgs(unsigned int n)
virtual void print(std::ostream &os)
Output string representation.
virtual void print(std::ostream &os)
Output string representation.
FloatVar(int i0, const std::string &n0="")
virtual void print(std::ostream &os)
Output string representation.
virtual void print(std::ostream &os)
Output string representation.
IntVar(int i0, const std::string &n0="")
A node in a FlatZinc abstract syntax tree.
bool isSetVar(void)
Test if node is a set variable node.
virtual void release(void)
Give up one owner's hold on this node.
Array * getArray(void)
Cast this node to an array node.
bool isBool(void)
Test if node is a Boolean node.
bool isFloatVar(void)
Test if node is a float variable node.
bool isSet(void)
Test if node is a set literal node.
double getFloat(void)
Cast this node to a Float node.
bool hasCall(const std::string &id)
Test if node is function call or array containing function call id.
int getFloatVar(void)
Cast this node to a Float variable node.
bool isArray(void)
Test if node is an array node.
void append(Node *n)
Append n to an array node.
SetLit * getSet(void)
Cast this node to a set literal node.
bool isFloat(void)
Test if node is a float node.
bool isString(void)
Test if node is a string node.
bool hasAtom(const std::string &id)
Test if node has atom with id.
bool isInt(void)
Test if node is an integer node.
bool isCall(const std::string &id)
Test if node is function call with id.
bool isFloat(double &i)
Test if node is float, if yes set d to the value.
virtual ~Node(void)
Destructor.
bool isInt(int &i)
Test if node is int, if yes set i to the value.
int getInt(void)
Cast this node to an integer node.
bool isAtom(void)
Test if node is an atom node.
bool isIntVar(void)
Test if node is an integer variable node.
Atom * getAtom(void)
Cast this node to an Atom node.
int getIntVar(void)
Cast this node to an integer variable node.
bool isBoolVar(void)
Test if node is a Boolean variable node.
Call * getCall(void)
Return function call.
std::string getVarName(void)
Return name of variable represented by this node.
int getBoolVar(void)
Cast this node to a Boolean variable node.
virtual void print(std::ostream &)=0
Output string representation.
int getSetVar(void)
Cast this node to a set variable node.
bool getBool(void)
Cast this node to a Boolean node.
std::string getString(void)
Cast this node to a string node.
SetLit(const std::vector< int > &s0)
SetLit(int min0, int max0)
virtual void print(std::ostream &os)
Output string representation.
SetVar(int i0, const std::string &n0="")
virtual void print(std::ostream &os)
Output string representation.
Array node shared by all references to an array parameter
unsigned int refs
Number of owners.
SharedArray(int n)
Construct with n elements and one owner.
virtual void release(void)
Remove an owner, deleting the node when none is left.
SharedArray * share(void)
Add an owner and return this node.
String(const std::string &s0)
virtual void print(std::ostream &os)
Output string representation.
Exception signaling type error
TypeError(std::string what)
std::string what(void) const
Variable node base class.
Var(int i0, const std::string &n0)
Constructor.
Abstract syntax trees for the FlatZinc interpreter.
Node * extractSingleton(Node *n)
void release_node(Node *n)
Release n if it is not null (see Node::release).
Interpreter for the FlatZinc language.
Gecode toplevel namespace
#define GECODE_VTABLE_EXPORT