this repo has no description
at develop 3.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/flatten_internal.hh> 13#include <minizinc/type.hh> 14 15namespace MiniZinc { 16 17std::string Type::toString(EnvI& env) const { 18 std::ostringstream oss; 19 if (_dim > 0) { 20 oss << "array["; 21 if (_enumId != 0) { 22 const std::vector<unsigned int>& arrayEnumIds = env.getArrayEnum(_enumId); 23 for (unsigned int i = 0; i < arrayEnumIds.size() - 1; i++) { 24 if (i != 0) oss << ","; 25 unsigned int enumId = arrayEnumIds[i]; 26 if (enumId == 0) { 27 oss << "int"; 28 } else { 29 oss << *env.getEnum(enumId)->e()->id(); 30 } 31 } 32 } else { 33 for (int i = 0; i < _dim; i++) oss << (i == 0 ? "" : ",") << "int"; 34 } 35 oss << "] of "; 36 } 37 if (_dim < 0) oss << "array[$_] of "; 38 switch (_ti) { 39 case TI_PAR: 40 break; 41 case TI_VAR: 42 oss << "var "; 43 break; 44 } 45 if (_ot == OT_OPTIONAL) oss << "opt "; 46 if (_st == ST_SET) oss << "set of "; 47 switch (_bt) { 48 case BT_INT: { 49 unsigned int enumId; 50 if (_enumId != 0 && _dim > 0) { 51 const std::vector<unsigned int>& arrayEnumIds = env.getArrayEnum(_enumId); 52 enumId = arrayEnumIds[arrayEnumIds.size() - 1]; 53 } else { 54 enumId = _enumId; 55 } 56 if (enumId == 0) { 57 oss << "int"; 58 } else { 59 oss << *env.getEnum(enumId)->e()->id(); 60 } 61 } break; 62 case BT_BOOL: 63 oss << "bool"; 64 break; 65 case BT_FLOAT: 66 oss << "float"; 67 break; 68 case BT_STRING: 69 oss << "string"; 70 break; 71 case BT_ANN: 72 oss << "ann"; 73 break; 74 case BT_BOT: 75 oss << "bot"; 76 break; 77 case BT_TOP: 78 oss << "top"; 79 break; 80 case BT_UNKNOWN: 81 oss << "??? "; 82 break; 83 } 84 return oss.str(); 85} 86 87std::string Type::nonEnumToString(void) const { 88 std::ostringstream oss; 89 if (_dim > 0) { 90 oss << "array[int"; 91 for (int i = 1; i < _dim; i++) oss << ",int"; 92 oss << "] of "; 93 } 94 if (_dim < 0) oss << "array[$_] of "; 95 switch (_ti) { 96 case TI_PAR: 97 break; 98 case TI_VAR: 99 oss << "var "; 100 break; 101 } 102 if (_ot == OT_OPTIONAL) oss << "opt "; 103 if (_st == ST_SET) oss << "set of "; 104 switch (_bt) { 105 case BT_INT: 106 oss << "int"; 107 break; 108 case BT_BOOL: 109 oss << "bool"; 110 break; 111 case BT_FLOAT: 112 oss << "float"; 113 break; 114 case BT_STRING: 115 oss << "string"; 116 break; 117 case BT_ANN: 118 oss << "ann"; 119 break; 120 case BT_BOT: 121 oss << "bot"; 122 break; 123 case BT_TOP: 124 oss << "top"; 125 break; 126 case BT_UNKNOWN: 127 oss << "??? "; 128 break; 129 } 130 return oss.str(); 131} 132 133} // namespace MiniZinc