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 isCall(
const std::string&
id);
88 bool hasCall(
const std::string&
id);
90 Call* getCall(
const std::string&
id);
92 Array* getArray(
void);
107 double getFloat(
void);
112 std::string getString(
void);
117 bool isBoolVar(
void);
134 virtual void print(std::ostream&) = 0;
142 virtual void print(std::ostream& os) {
143 os <<
"b(" << (
b ?
"true" :
"false") <<
")";
151 virtual void print(std::ostream& os) {
160 virtual void print(std::ostream& os) {
172 SetLit(
const std::vector<int>& s0) : interval(false), s(s0) {}
174 return ( (interval &&
min>
max) || (!interval && s.size() == 0));
176 virtual void print(std::ostream& os) {
191 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 std::vector<Node*>
a;
229 virtual void print(std::ostream& os) {
231 for (
unsigned int i=0;
i<
a.
size();
i++) {
250 : id(id0), args(args0) {}
252 virtual void print(std::ostream& os) {
253 os <<
id <<
"("; args->print(os); os <<
")";
256 Array *
a = args->getArray();
257 if (a->
a.size() != n)
269 :
a(a0), idx(idx0) {}
271 virtual void print(std::ostream& os) {
283 Atom(
const std::string& id0) : id(id0) {}
284 virtual void print(std::ostream& os) {
294 virtual void print(std::ostream& os) {
295 os <<
"s(\"" << s <<
"\")";
307 a->
a.push_back(newNode);
312 if (
Array*
a = dynamic_cast<Array*>(
this)) {
314 if (
Atom* at = dynamic_cast<Atom*>(
a->a[
i]))
317 }
else if (
Atom*
a = dynamic_cast<Atom*>(
this)) {
325 if (
Call*
a = dynamic_cast<Call*>(
this)) {
334 if (
Call*
a = dynamic_cast<Call*>(
this))
341 if (
Array*
a = dynamic_cast<Array*>(
this)) {
343 if (
Call* at = dynamic_cast<Call*>(
a->a[
i]))
347 }
else if (
Call*
a = dynamic_cast<Call*>(
this)) {
355 if (
IntLit* il = dynamic_cast<IntLit*>(
this)) {
364 if (
Array*
a = dynamic_cast<Array*>(
this)) {
366 if (
Call* at = dynamic_cast<Call*>(
a->a[
i]))
369 }
else if (
Call*
a = dynamic_cast<Call*>(
this)) {
378 if (
Array*
a = dynamic_cast<Array*>(
this))
385 if (
Atom*
a = dynamic_cast<Atom*>(
this))
392 if (
IntVar*
a = dynamic_cast<IntVar*>(
this))
394 throw TypeError(
"integer variable expected");
398 if (
BoolVar*
a = dynamic_cast<BoolVar*>(
this))
400 throw TypeError(
"bool variable expected");
404 if (
SetVar*
a = dynamic_cast<SetVar*>(
this))
406 throw TypeError(
"set variable expected");
410 if (
IntLit*
a = dynamic_cast<IntLit*>(
this))
412 throw TypeError(
"integer literal expected");
416 if (
BoolLit*
a = dynamic_cast<BoolLit*>(
this))
418 throw TypeError(
"bool literal expected");
422 if (
FloatLit*
a = dynamic_cast<FloatLit*>(
this))
424 throw TypeError(
"float literal expected");
428 if (
SetLit*
a = dynamic_cast<SetLit*>(
this))
434 if (
String*
a = dynamic_cast<String*>(
this))
436 throw TypeError(
"string literal expected");
440 return (dynamic_cast<IntVar*>(
this) != NULL);
444 return (dynamic_cast<BoolVar*>(
this) != NULL);
448 return (dynamic_cast<SetVar*>(
this) != NULL);
452 return (dynamic_cast<IntLit*>(
this) != NULL);
456 return (dynamic_cast<BoolLit*>(
this) != NULL);
460 return (dynamic_cast<SetLit*>(
this) != NULL);
464 return (dynamic_cast<String*>(
this) != NULL);
468 return (dynamic_cast<Array*>(
this) != NULL);
472 return (dynamic_cast<Atom*>(
this) != NULL);
477 if (
Array*
a = dynamic_cast<Array*>(n)) {
478 if (
a->a.
size() == 1) {