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);
100 int getBoolVar(
void);
102 int getFloatVar(
void);
111 double getFloat(
void);
116 std::string getString(
void);
121 bool isBoolVar(
void);
125 bool isFloatVar(
void);
142 virtual void print(std::ostream&) = 0;
150 virtual void print(std::ostream& os) {
151 os <<
"b(" << (
b ?
"true" :
"false") <<
")";
159 virtual void print(std::ostream& os) {
168 virtual void print(std::ostream& os) {
180 SetLit(
const std::vector<int>& s0) : interval(false), s(s0) {}
182 return ( (interval &&
min>
max) || (!interval && s.size() == 0));
184 virtual void print(std::ostream& os) {
199 virtual void print(std::ostream& os) {
207 virtual void print(std::ostream& os) {
215 virtual void print(std::ostream& os) {
223 virtual void print(std::ostream& os) {
231 std::vector<Node*>
a;
237 virtual void print(std::ostream& os) {
239 for (
unsigned int i=0;
i<
a.size();
i++) {
247 for (
int i=
a.size();
i--;)
258 : id(id0), args(args0) {}
260 virtual void print(std::ostream& os) {
261 os <<
id <<
"("; args->print(os); os <<
")";
264 Array *
a = args->getArray();
265 if (a->
a.size() !=
n)
277 :
a(a0), idx(idx0) {}
279 virtual void print(std::ostream& os) {
291 Atom(
const std::string& id0) : id(id0) {}
292 virtual void print(std::ostream& os) {
302 virtual void print(std::ostream& os) {
303 os <<
"s(\"" << s <<
"\")";
315 a->
a.push_back(newNode);
320 if (
Array*
a = dynamic_cast<Array*>(
this)) {
321 for (
int i=
a->a.size();
i--;)
322 if (
Atom* at = dynamic_cast<Atom*>(
a->a[
i]))
325 }
else if (
Atom*
a = dynamic_cast<Atom*>(
this)) {
333 if (
Call*
a = dynamic_cast<Call*>(
this)) {
342 if (
Call*
a = dynamic_cast<Call*>(
this))
349 if (
Array*
a = dynamic_cast<Array*>(
this)) {
350 for (
int i=
a->a.size();
i--;)
351 if (
Call* at = dynamic_cast<Call*>(
a->a[
i]))
355 }
else if (
Call*
a = dynamic_cast<Call*>(
this)) {
363 if (
IntLit* il = dynamic_cast<IntLit*>(
this)) {
372 if (
FloatLit* fl = dynamic_cast<FloatLit*>(
this)) {
381 if (
Array*
a = dynamic_cast<Array*>(
this)) {
382 for (
int i=
a->a.size();
i--;)
383 if (
Call* at = dynamic_cast<Call*>(
a->a[
i]))
386 }
else if (
Call*
a = dynamic_cast<Call*>(
this)) {
395 if (
Array*
a = dynamic_cast<Array*>(
this))
402 if (
Atom*
a = dynamic_cast<Atom*>(
this))
409 if (
IntVar*
a = dynamic_cast<IntVar*>(
this))
411 throw TypeError(
"integer variable expected");
415 if (
BoolVar*
a = dynamic_cast<BoolVar*>(
this))
417 throw TypeError(
"bool variable expected");
421 if (
FloatVar*
a = dynamic_cast<FloatVar*>(
this))
423 throw TypeError(
"integer variable expected");
427 if (
SetVar*
a = dynamic_cast<SetVar*>(
this))
429 throw TypeError(
"set variable expected");
433 if (
IntLit*
a = dynamic_cast<IntLit*>(
this))
435 throw TypeError(
"integer literal expected");
439 if (
BoolLit*
a = dynamic_cast<BoolLit*>(
this))
441 throw TypeError(
"bool literal expected");
445 if (
FloatLit*
a = dynamic_cast<FloatLit*>(
this))
447 throw TypeError(
"float literal expected");
451 if (
SetLit*
a = dynamic_cast<SetLit*>(
this))
457 if (
String*
a = dynamic_cast<String*>(
this))
459 throw TypeError(
"string literal expected");
463 return (dynamic_cast<IntVar*>(
this) != NULL);
467 return (dynamic_cast<BoolVar*>(
this) != NULL);
471 return (dynamic_cast<SetVar*>(
this) != NULL);
475 return (dynamic_cast<FloatVar*>(
this) != NULL);
479 return (dynamic_cast<IntLit*>(
this) != NULL);
483 return (dynamic_cast<BoolLit*>(
this) != NULL);
487 return (dynamic_cast<FloatLit*>(
this) != NULL);
491 return (dynamic_cast<SetLit*>(
this) != NULL);
495 return (dynamic_cast<String*>(
this) != NULL);
499 return (dynamic_cast<Array*>(
this) != NULL);
503 return (dynamic_cast<Atom*>(
this) != NULL);
508 if (
Array*
a = dynamic_cast<Array*>(n)) {
509 if (
a->a.size() == 1) {