34#ifndef __GECODE_FLATZINC_AST_HH__
35#define __GECODE_FLATZINC_AST_HH__
47namespace Gecode {
namespace FlatZinc {
namespace AST {
61 std::string
what(
void)
const {
return _what; }
76 bool hasAtom(
const std::string&
id);
80 bool isFloat(
double& i);
82 bool isCall(
const std::string&
id);
86 bool hasCall(
const std::string&
id);
88 Call* getCall(
const std::string&
id);
90 Array* getArray(
void);
94 std::string getVarName(
void);
100 int getFloatVar(
void);
109 double getFloat(
void);
114 std::string getString(
void);
119 bool isBoolVar(
void);
123 bool isFloatVar(
void);
140 virtual void print(std::ostream&) = 0;
148 virtual void print(std::ostream& os) {
149 os <<
"b(" << (
b ?
"true" :
"false") <<
")";
157 virtual void print(std::ostream& os) {
166 virtual void print(std::ostream& os) {
177 SetLit(
int min0,
int max0) : interval(true), min(min0), max(max0) {}
178 SetLit(
const std::vector<int>& s0) : interval(false), s(s0) {}
179 explicit SetLit(
SetLit* s0) : interval(s0->interval), min(s0->min), max(s0->max), s(s0->s) {}
181 return ( (interval && min>max) || (!interval && s.size() == 0));
183 virtual void print(std::ostream& os) {
194 Var(
int i0,
const std::string& n0) : i(i0),
n(n0) {}
201 virtual void print(std::ostream& os) {
208 IntVar(
int i0,
const std::string& n0=
"") :
Var(i0,n0) {}
209 virtual void print(std::ostream& os) {
217 virtual void print(std::ostream& os) {
224 SetVar(
int i0,
const std::string& n0=
"") :
Var(i0,n0) {}
225 virtual void print(std::ostream& os) {
233 std::vector<Node*>
a;
239 virtual void print(std::ostream& os) {
241 for (
unsigned int i=0; i<
a.
size(); i++) {
249 for (
int i=
a.
size(); i--;)
260 : id(id0), args(args0) {}
262 virtual void print(std::ostream& os) {
263 os <<
id <<
"("; args->
print(os); os <<
")";
267 if (
a->a.size() !=
n)
279 :
a(a0), idx(idx0) {}
281 virtual void print(std::ostream& os) {
293 Atom(
const std::string& id0) : id(id0) {}
294 virtual void print(std::ostream& os) {
304 virtual void print(std::ostream& os) {
305 os <<
"s(\"" << s <<
"\")";
317 a->a.push_back(newNode);
323 for (
int i=
a->
a.size(); i--;)
324 if (
Atom* at =
dynamic_cast<Atom*
>(
a->a[i]))
327 }
else if (
Atom*
a =
dynamic_cast<Atom*
>(
this)) {
335 if (
Call*
a =
dynamic_cast<Call*
>(
this)) {
352 for (
int i=
a->
a.size(); i--;)
353 if (
Call* at =
dynamic_cast<Call*
>(
a->a[i]))
357 }
else if (
Call*
a =
dynamic_cast<Call*
>(
this)) {
384 for (
int i=
a->
a.size(); i--;)
385 if (
Call* at =
dynamic_cast<Call*
>(
a->a[i]))
388 }
else if (
Call*
a =
dynamic_cast<Call*
>(
this)) {
411 if (
Var*
a =
dynamic_cast<Var*
>(
this))
419 throw TypeError(
"integer variable expected");
425 throw TypeError(
"bool variable expected");
431 throw TypeError(
"integer variable expected");
437 throw TypeError(
"set variable expected");
443 throw TypeError(
"integer literal expected");
449 throw TypeError(
"bool literal expected");
455 throw TypeError(
"float literal expected");
467 throw TypeError(
"string literal expected");
471 return (
dynamic_cast<IntVar*
>(
this) != NULL);
475 return (
dynamic_cast<BoolVar*
>(
this) != NULL);
479 return (
dynamic_cast<SetVar*
>(
this) != NULL);
483 return (
dynamic_cast<FloatVar*
>(
this) != NULL);
487 return (
dynamic_cast<IntLit*
>(
this) != NULL);
491 return (
dynamic_cast<BoolLit*
>(
this) != NULL);
495 return (
dynamic_cast<FloatLit*
>(
this) != NULL);
499 return (
dynamic_cast<SetLit*
>(
this) != NULL);
503 return (
dynamic_cast<String*
>(
this) != NULL);
507 return (
dynamic_cast<Array*
>(
this) != NULL);
511 return (
dynamic_cast<Atom*
>(
this) != NULL);
517 if (
a->a.size() == 1) {
struct Gecode::@603::NNF::@65::@66 b
For binary nodes (and, or, eqv)
int n
Number of negative literals for node type.
struct Gecode::@603::NNF::@65::@67 a
For atomic nodes.
int size(void) const
Return size of array (number of elements)
Node representing an array access
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.
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.
virtual ~Node(void)
Destructor.
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.
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.
Node * extractSingleton(Node *n)
Gecode toplevel namespace
#define GECODE_VTABLE_EXPORT