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_unop(EnvI& env, Ctx ctx, Expression* e, VarDecl* r, VarDecl* b) { 17 CallStackItem _csi(env, e); 18 EE ret; 19 UnOp* uo = e->cast<UnOp>(); 20 switch (uo->op()) { 21 case UOT_NOT: { 22 Ctx nctx = ctx; 23 nctx.b = -nctx.b; 24 nctx.neg = !nctx.neg; 25 ret = flat_exp(env, nctx, uo->e(), r, b); 26 } break; 27 case UOT_PLUS: 28 ret = flat_exp(env, ctx, uo->e(), r, b); 29 break; 30 case UOT_MINUS: { 31 GC::lock(); 32 if (UnOp* uo_inner = uo->e()->dyn_cast<UnOp>()) { 33 if (uo_inner->op() == UOT_MINUS) { 34 ret = flat_exp(env, ctx, uo_inner->e(), r, b); 35 break; 36 } 37 } 38 Expression* zero; 39 if (uo->e()->type().bt() == Type::BT_INT) 40 zero = IntLit::a(0); 41 else 42 zero = FloatLit::a(0.0); 43 BinOp* bo = new BinOp(Location().introduce(), zero, BOT_MINUS, uo->e()); 44 bo->type(uo->type()); 45 KeepAlive ka(bo); 46 GC::unlock(); 47 ret = flat_exp(env, ctx, ka(), r, b); 48 } break; 49 default: 50 break; 51 } 52 return ret; 53} 54} // namespace MiniZinc