this repo has no description
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, Ctx ctx, Expression* e, VarDecl* r, VarDecl* b) {
17 CallStackItem _csi(env, e);
18 EE ret;
19 ArrayLit* al = e->cast<ArrayLit>();
20 if (al->flat()) {
21 ret.b = bind(env, Ctx(), b, constants().lit_true);
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--;) elems_ee[i] = flat_exp(env, ctx, (*al)[i], NULL, NULL);
26 std::vector<Expression*> elems(elems_ee.size());
27 for (unsigned int i = static_cast<unsigned int>(elems.size()); i--;) elems[i] = elems_ee[i].r();
28 std::vector<std::pair<int, int> > dims(al->dims());
29 for (unsigned int i = al->dims(); i--;) dims[i] = std::pair<int, int>(al->min(i), al->max(i));
30 KeepAlive ka;
31 {
32 GCLock lock;
33 ArrayLit* alr = new ArrayLit(Location().introduce(), elems, dims);
34 alr->type(al->type());
35 alr->flat(true);
36 ka = alr;
37 }
38 ret.b = conj(env, b, Ctx(), elems_ee);
39 ret.r = bind(env, Ctx(), r, ka());
40 }
41 return ret;
42}
43
44} // namespace MiniZinc