38 #ifndef __GECODE_FLATZINC_AST_HH__
39 #define __GECODE_FLATZINC_AST_HH__
51 namespace Gecode {
namespace FlatZinc {
namespace AST {
65 std::string
what(
void)
const {
return _what; }
80 bool hasAtom(
const std::string&
id);
84 bool isFloat(
double& i);
86 bool isCall(
const std::string&
id);
90 bool hasCall(
const std::string&
id);
92 Call* getCall(
const std::string&
id);
94 Array* getArray(
void);
98 std::string getVarName(
void);
102 int getBoolVar(
void);
104 int getFloatVar(
void);
113 double getFloat(
void);
118 std::string getString(
void);
123 bool isBoolVar(
void);
127 bool isFloatVar(
void);
144 virtual void print(std::ostream&) = 0;
152 virtual void print(std::ostream& os) {
153 os <<
"b(" << (b ?
"true" :
"false") <<
")";
161 virtual void print(std::ostream& os) {
170 virtual void print(std::ostream& os) {
181 SetLit(
int min0,
int max0) : interval(true), min(min0), max(max0) {}
182 SetLit(
const std::vector<int>& s0) : interval(false), s(s0) {}
183 explicit SetLit(
SetLit* s0) : interval(s0->interval), min(s0->min), max(s0->max), s(s0->s) {}
185 return ( (interval && min>max) || (!interval && s.size() == 0));
187 virtual void print(std::ostream& os) {
198 Var(
int i0,
const std::string& n0) : i(i0), n(n0) {}
205 virtual void print(std::ostream& os) {
212 IntVar(
int i0,
const std::string& n0=
"") :
Var(i0,n0) {}
213 virtual void print(std::ostream& os) {
221 virtual void print(std::ostream& os) {
228 SetVar(
int i0,
const std::string& n0=
"") :
Var(i0,n0) {}
229 virtual void print(std::ostream& os) {
237 std::vector<Node*>
a;
243 virtual void print(std::ostream& os) {
245 for (
unsigned int i=0;
i<a.
size();
i++) {
253 for (
int i=a.
size();
i--;)
264 : id(id0), args(args0) {}
266 virtual void print(std::ostream& os) {
267 os <<
id <<
"("; args->
print(os); os <<
")";
271 if (a->
a.size() !=
n)
283 : a(a0), idx(idx0) {}
285 virtual void print(std::ostream& os) {
297 Atom(
const std::string& id0) : id(id0) {}
298 virtual void print(std::ostream& os) {
308 virtual void print(std::ostream& os) {
309 os <<
"s(\"" << s <<
"\")";
321 a->
a.push_back(newNode);
326 if (
Array*
a = dynamic_cast<Array*>(
this)) {
327 for (
int i=
a->a.size();
i--;)
328 if (
Atom* at = dynamic_cast<Atom*>(
a->a[
i]))
331 }
else if (
Atom*
a = dynamic_cast<Atom*>(
this)) {
339 if (
Call*
a = dynamic_cast<Call*>(
this)) {
348 if (
Call*
a = dynamic_cast<Call*>(
this))
355 if (
Array*
a = dynamic_cast<Array*>(
this)) {
356 for (
int i=
a->a.size();
i--;)
357 if (
Call* at = dynamic_cast<Call*>(
a->a[
i]))
361 }
else if (
Call*
a = dynamic_cast<Call*>(
this)) {
369 if (
IntLit* il = dynamic_cast<IntLit*>(
this)) {
378 if (
FloatLit* fl = dynamic_cast<FloatLit*>(
this)) {
387 if (
Array*
a = dynamic_cast<Array*>(
this)) {
388 for (
int i=
a->a.size();
i--;)
389 if (
Call* at = dynamic_cast<Call*>(
a->a[
i]))
392 }
else if (
Call*
a = dynamic_cast<Call*>(
this)) {
401 if (
Array*
a = dynamic_cast<Array*>(
this))
408 if (
Atom*
a = dynamic_cast<Atom*>(
this))
415 if (
Var*
a = dynamic_cast<Var*>(
this))
421 if (
IntVar*
a = dynamic_cast<IntVar*>(
this))
423 throw TypeError(
"integer variable expected");
427 if (
BoolVar*
a = dynamic_cast<BoolVar*>(
this))
429 throw TypeError(
"bool variable expected");
433 if (
FloatVar*
a = dynamic_cast<FloatVar*>(
this))
435 throw TypeError(
"integer variable expected");
439 if (
SetVar*
a = dynamic_cast<SetVar*>(
this))
441 throw TypeError(
"set variable expected");
445 if (
IntLit*
a = dynamic_cast<IntLit*>(
this))
447 throw TypeError(
"integer literal expected");
451 if (
BoolLit*
a = dynamic_cast<BoolLit*>(
this))
453 throw TypeError(
"bool literal expected");
457 if (
FloatLit*
a = dynamic_cast<FloatLit*>(
this))
459 throw TypeError(
"float literal expected");
463 if (
SetLit*
a = dynamic_cast<SetLit*>(
this))
469 if (
String*
a = dynamic_cast<String*>(
this))
471 throw TypeError(
"string literal expected");
475 return (dynamic_cast<IntVar*>(
this) != NULL);
479 return (dynamic_cast<BoolVar*>(
this) != NULL);
483 return (dynamic_cast<SetVar*>(
this) != NULL);
487 return (dynamic_cast<FloatVar*>(
this) != NULL);
491 return (dynamic_cast<IntLit*>(
this) != NULL);
495 return (dynamic_cast<BoolLit*>(
this) != NULL);
499 return (dynamic_cast<FloatLit*>(
this) != NULL);
503 return (dynamic_cast<SetLit*>(
this) != NULL);
507 return (dynamic_cast<String*>(
this) != NULL);
511 return (dynamic_cast<Array*>(
this) != NULL);
515 return (dynamic_cast<Atom*>(
this) != NULL);
520 if (
Array*
a = dynamic_cast<Array*>(n)) {
521 if (
a->a.size() == 1) {
SetVar(int i0, const std::string &n0="")
Var(int i0, const std::string &n0)
Constructor.
virtual void print(std::ostream &os)
Output string representation.
std::string what(void) const
virtual void print(std::ostream &os)
Output string representation.
bool isBool(void)
Test if node is a Boolean node.
bool getBool(void)
Cast this node to a Boolean node.
Array(const std::vector< Node * > &a0)
SetLit(const std::vector< int > &s0)
virtual void print(std::ostream &os)
Output string representation.
int size(void) const
Return size of array (number of elements)
SetLit * getSet(void)
Cast this node to a set literal node.
std::string getVarName(void)
Return name of variable represented by this node.
Call * getCall(void)
Return function call.
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
int getFloatVar(void)
Cast this node to a Float variable node.
virtual void print(std::ostream &os)
Output string representation.
bool isAtom(void)
Test if node is an atom node.
bool isInt(void)
Test if node is an integer node.
Node * extractSingleton(Node *n)
SetLit(int min0, int max0)
Atom(const std::string &id0)
Variable node base class.
bool isSetVar(void)
Test if node is a set variable node.
bool isBoolVar(void)
Test if node is a Boolean variable node.
Node representing an array access
Atom * getAtom(void)
Cast this node to an Atom node.
virtual void print(std::ostream &os)
Output string representation.
Array * getArray(void)
Cast this node to an array node.
int getSetVar(void)
Cast this node to a set variable node.
double getFloat(void)
Cast this node to a Float node.
ArrayAccess(Node *a0, Node *idx0)
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
virtual ~Node(void)
Destructor.
String(const std::string &s0)
Node representing an atom
int getIntVar(void)
Cast this node to an integer variable node.
int getBoolVar(void)
Cast this node to a Boolean variable node.
virtual void print(std::ostream &os)
Output string representation.
bool isSet(void)
Test if node is a set literal node.
virtual void print(std::ostream &os)
Output string representation.
virtual void print(std::ostream &os)
Output string representation.
Array * getArgs(unsigned int n)
virtual void print(std::ostream &os)
Output string representation.
bool isIntVar(void)
Test if node is an integer variable node.
bool isString(void)
Test if node is a string node.
bool hasCall(const std::string &id)
Test if node is function call or array containing function call id.
int getInt(void)
Cast this node to an integer node.
void print(std::basic_ostream< Char, Traits > &s, bool assigned, IL &lb, IU &ub, unsigned int cardMin, unsigned int cardMax)
Print set view.
virtual void print(std::ostream &)=0
Output string representation.
Exception signaling type error
bool hasAtom(const std::string &id)
Test if node has atom with id.
virtual void print(std::ostream &os)
Output string representation.
bool isFloatVar(void)
Test if node is a float variable node.
Call(const std::string &id0, Node *args0)
bool isArray(void)
Test if node is an array node.
IntVar(int i0, const std::string &n0="")
Gecode toplevel namespace
bool isFloat(void)
Test if node is a float node.
FloatVar(int i0, const std::string &n0="")
Node representing a function call
#define GECODE_VTABLE_EXPORT
A node in a FlatZinc abstract syntax tree.
TypeError(std::string what)
virtual void print(std::ostream &os)
Output string representation.
bool isCall(const std::string &id)
Test if node is function call with id.
void append(Node *n)
Append n to an array node.
BoolVar(int i0, const std::string &n0="")
Constructor.
std::string getString(void)
Cast this node to a string node.
struct Gecode::@518::NNF::@57::@59 a
For atomic nodes.
virtual void print(std::ostream &os)
Output string representation.
virtual void print(std::ostream &os)
Output string representation.