Go to the documentation of this file.
34 #ifndef __GECODE_FLATZINC_AST_HH__
35 #define __GECODE_FLATZINC_AST_HH__
47 namespace 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) {
178 SetLit(
const std::vector<int>& s0) : interval(false), s(s0) {}
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 <<
"\")";
314 Array*
a = dynamic_cast<Array*>(
this);
317 a->a.push_back(newNode);
322 if (
Array*
a = dynamic_cast<Array*>(
this)) {
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)) {
344 if (
Call*
a = dynamic_cast<Call*>(
this))
351 if (
Array*
a = dynamic_cast<Array*>(
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)) {
365 if (
IntLit* il = dynamic_cast<IntLit*>(
this)) {
374 if (
FloatLit* fl = dynamic_cast<FloatLit*>(
this)) {
383 if (
Array*
a = dynamic_cast<Array*>(
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)) {
397 if (
Array*
a = dynamic_cast<Array*>(
this))
404 if (
Atom*
a = dynamic_cast<Atom*>(
this))
411 if (
Var*
a = dynamic_cast<Var*>(
this))
417 if (
IntVar*
a = dynamic_cast<IntVar*>(
this))
419 throw TypeError(
"integer variable expected");
423 if (
BoolVar*
a = dynamic_cast<BoolVar*>(
this))
425 throw TypeError(
"bool variable expected");
429 if (
FloatVar*
a = dynamic_cast<FloatVar*>(
this))
431 throw TypeError(
"integer variable expected");
435 if (
SetVar*
a = dynamic_cast<SetVar*>(
this))
437 throw TypeError(
"set variable expected");
441 if (
IntLit*
a = dynamic_cast<IntLit*>(
this))
443 throw TypeError(
"integer literal expected");
447 if (
BoolLit*
a = dynamic_cast<BoolLit*>(
this))
449 throw TypeError(
"bool literal expected");
453 if (
FloatLit*
a = dynamic_cast<FloatLit*>(
this))
455 throw TypeError(
"float literal expected");
459 if (
SetLit*
a = dynamic_cast<SetLit*>(
this))
465 if (
String*
a = dynamic_cast<String*>(
this))
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);
516 if (
Array*
a = dynamic_cast<Array*>(
n)) {
517 if (
a->a.size() == 1) {
struct Gecode::@602::NNF::@65::@66 b
For binary nodes (and, or, eqv)
bool isSetVar(void)
Test if node is a set variable node.
A node in a FlatZinc abstract syntax tree.
bool isArray(void)
Test if node is an array node.
Exception signaling type error
bool isIntVar(void)
Test if node is an integer variable node.
std::string what(void) const
virtual void print(std::ostream &os)
Output string representation.
virtual ~Node(void)
Destructor.
SetVar(int i0, const std::string &n0="")
bool hasAtom(const std::string &id)
Test if node has atom with id.
#define GECODE_VTABLE_EXPORT
SetLit * getSet(void)
Cast this node to a set literal node.
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
virtual void print(std::ostream &os)
Output string representation.
virtual void print(std::ostream &os)
Output string representation.
virtual void print(std::ostream &os)
Output string representation.
SetLit(int min0, int max0)
Array * getArgs(unsigned int n)
Node * extractSingleton(Node *n)
FloatVar(int i0, const std::string &n0="")
Call * getCall(void)
Return function call.
virtual void print(std::ostream &os)
Output string representation.
SetLit(const std::vector< int > &s0)
int getBoolVar(void)
Cast this node to a Boolean variable node.
bool isBoolVar(void)
Test if node is a Boolean variable node.
BoolVar(int i0, const std::string &n0="")
Constructor.
virtual void print(std::ostream &os)
Output string representation.
bool isInt(void)
Test if node is an integer node.
virtual void print(std::ostream &)=0
Output string representation.
bool isString(void)
Test if node is a string node.
int getIntVar(void)
Cast this node to an integer variable node.
bool isSet(void)
Test if node is a set literal node.
Var(int i0, const std::string &n0)
Constructor.
bool isBool(void)
Test if node is a Boolean node.
virtual void print(std::ostream &os)
Output string representation.
bool isFloatVar(void)
Test if node is a float variable node.
Gecode toplevel namespace
TypeError(std::string what)
Node representing an atom
struct Gecode::@602::NNF::@65::@67 a
For atomic nodes.
virtual void print(std::ostream &os)
Output string representation.
String(const std::string &s0)
bool isFloat(void)
Test if node is a float node.
Array * getArray(void)
Cast this node to an array node.
std::string getVarName(void)
Return name of variable represented by this node.
Atom(const std::string &id0)
Node representing an array access
int getSetVar(void)
Cast this node to a set variable node.
bool hasCall(const std::string &id)
Test if node is function call or array containing function call id.
bool isCall(const std::string &id)
Test if node is function call with id.
void append(Node *n)
Append n to an array node.
double getFloat(void)
Cast this node to a Float node.
bool isAtom(void)
Test if node is an atom node.
virtual void print(std::ostream &os)
Output string representation.
ArrayAccess(Node *a0, Node *idx0)
virtual void print(std::ostream &os)
Output string representation.
Variable node base class.
IntVar(int i0, const std::string &n0="")
int getFloatVar(void)
Cast this node to a Float variable node.
virtual void print(std::ostream &os)
Output string representation.
Node representing a function call
Call(const std::string &id0, Node *args0)
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
int n
Number of negative literals for node type.
int getInt(void)
Cast this node to an integer node.
virtual void print(std::ostream &os)
Output string representation.
Gecode::IntArgs i({1, 2, 3, 4})
std::string getString(void)
Cast this node to a string node.
bool getBool(void)
Cast this node to a Boolean node.
Array(const std::vector< Node * > &a0)
virtual void print(std::ostream &os)
Output string representation.
void print(const Search::Statistics &stat, bool restart)
Print statistics.
Atom * getAtom(void)
Cast this node to an Atom node.