this repo has no description
at develop 2.0 kB view raw
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2 3/* 4 * Main authors: 5 * Guido Tack <guido.tack@monash.edu> 6 */ 7 8/* This Source Code Form is subject to the terms of the Mozilla Public 9 * License, v. 2.0. If a copy of the MPL was not distributed with this 10 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 11 12#include <minizinc/flat_exp.hh> 13 14namespace MiniZinc { 15 16EE flatten_vardecl(EnvI& env, Ctx ctx, Expression* e, VarDecl* r, VarDecl* b) { 17 CallStackItem _csi(env, e); 18 EE ret; 19 GCLock lock; 20 if (ctx.b != C_ROOT) throw FlatteningError(env, e->loc(), "not in root context"); 21 VarDecl* v = e->cast<VarDecl>(); 22 VarDecl* it = v->flat(); 23 if (it == NULL) { 24 TypeInst* ti = eval_typeinst(env, v); 25 bool reuseVarId = 26 v->type().isann() || (v->toplevel() && v->id()->idn() == -1 && 27 v->id()->v().c_str()[0] != '\'' && v->id()->v().c_str()[0] != '_'); 28 VarDecl* vd = newVarDecl(env, ctx, ti, reuseVarId ? v->id() : NULL, v, NULL); 29 v->flat(vd); 30 Ctx nctx; 31 if (v->e() && v->e()->type().bt() == Type::BT_BOOL) nctx.b = C_MIX; 32 if (v->e()) { 33 (void)flat_exp(env, nctx, v->e(), vd, constants().var_true); 34 if (v->e()->type().dim() > 0) { 35 Expression* ee = follow_id_to_decl(vd->e()); 36 if (ee->isa<VarDecl>()) ee = ee->cast<VarDecl>()->e(); 37 assert(ee && ee->isa<ArrayLit>()); 38 ArrayLit* al = ee->cast<ArrayLit>(); 39 if (vd->ti()->domain()) { 40 for (unsigned int i = 0; i < al->size(); i++) { 41 if (Id* ali_id = (*al)[i]->dyn_cast<Id>()) { 42 if (ali_id->decl()->ti()->domain() == NULL) { 43 ali_id->decl()->ti()->domain(vd->ti()->domain()); 44 } 45 } 46 } 47 } 48 } 49 } 50 51 ret.r = bind(env, Ctx(), r, vd->id()); 52 } else { 53 ret.r = bind(env, Ctx(), r, it); 54 } 55 ret.b = bind(env, Ctx(), b, constants().lit_true); 56 return ret; 57} 58} // namespace MiniZinc