this repo has no description
at develop 1.5 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_arraylit(EnvI& env, const Ctx& ctx, Expression* e, VarDecl* r, VarDecl* b) { 17 CallStackItem _csi(env, e); 18 EE ret; 19 auto* al = e->cast<ArrayLit>(); 20 if (al->flat()) { 21 ret.b = bind(env, Ctx(), b, constants().literalTrue); 22 ret.r = bind(env, Ctx(), r, al); 23 } else { 24 std::vector<EE> elems_ee(al->size()); 25 for (unsigned int i = al->size(); (i--) != 0U;) { 26 elems_ee[i] = flat_exp(env, ctx, (*al)[i], nullptr, nullptr); 27 } 28 std::vector<Expression*> elems(elems_ee.size()); 29 for (auto i = static_cast<unsigned int>(elems.size()); (i--) != 0U;) { 30 elems[i] = elems_ee[i].r(); 31 } 32 std::vector<std::pair<int, int> > dims(al->dims()); 33 for (unsigned int i = al->dims(); (i--) != 0U;) { 34 dims[i] = std::pair<int, int>(al->min(i), al->max(i)); 35 } 36 KeepAlive ka; 37 { 38 GCLock lock; 39 auto* alr = new ArrayLit(Location().introduce(), elems, dims); 40 alr->type(al->type()); 41 alr->flat(true); 42 ka = alr; 43 } 44 ret.b = conj(env, b, Ctx(), elems_ee); 45 ret.r = bind(env, Ctx(), r, ka()); 46 } 47 return ret; 48} 49 50} // namespace MiniZinc