@@ -2333,95 +2333,6 @@ std::string b_show_index_sets(EnvI& env, Call* c) {
23332333 return oss.str ();
23342334}
23352335
2336- std::string b_show_enum_type (EnvI& env, Expression* e, Type t, bool dzn, bool json) {
2337- Id* ti_id = env.getEnum (t.typeId ())->e ()->id ();
2338- GCLock lock;
2339- std::vector<Expression*> args (3 );
2340- args[0 ] = e;
2341- if (Expression::type (e).dim () > 1 ) {
2342- Call* array1d = Call::a (Location ().introduce (), env.constants .ids .array1d , {e});
2343- Type array1dt = Type::arrType (env, Type::partop (1 ), t);
2344- array1d->type (array1dt);
2345- array1d->decl (env.model ->matchFn (env, array1d, false , true ));
2346- args[0 ] = array1d;
2347- }
2348- args[1 ] = env.constants .boollit (dzn);
2349- args[2 ] = env.constants .boollit (json);
2350- ASTString enumName (create_enum_to_string_name (ti_id, " _toString_" ));
2351- auto * call = Call::a (Location ().introduce (), enumName, args);
2352- auto * fi = env.model ->matchFn (env, call, false , true );
2353- call->decl (fi);
2354- Expression::type (call, Type::parstring ());
2355- return eval_string (env, call);
2356- }
2357-
2358- std::string show_with_type (EnvI& env, Expression* exp, Type t, bool showDzn) {
2359- GCLock lock;
2360- Expression* e = follow_id_to_decl (exp);
2361- if (auto * vd = Expression::dynamicCast<VarDecl>(e)) {
2362- if ((vd->e () != nullptr ) && !Expression::isa<Call>(vd->e ())) {
2363- e = vd->e ();
2364- } else {
2365- e = vd->id ();
2366- }
2367- }
2368- if (Expression::type (e).isPar ()) {
2369- e = eval_par (env, e);
2370- }
2371- if (Expression::type (e).dim () > 0 || Expression::type (e).structBT ()) {
2372- e = eval_array_lit (env, e);
2373- }
2374- if (Expression::type (e).isPar () && Expression::type (e).dim () == 0 && t.bt () == Type::BT_INT &&
2375- t.typeId () != 0 ) {
2376- return b_show_enum_type (env, e, t, showDzn, false );
2377- }
2378- std::ostringstream oss;
2379- if (auto * al = Expression::dynamicCast<ArrayLit>(e)) {
2380- auto al_t = t;
2381- if (al->isTuple () && env.getTransparentType (t) != t) {
2382- // Unwrap nested array type
2383- al = eval_array_lit (env, (*al)[0 ]);
2384- al_t = env.getTransparentType (t);
2385- }
2386- oss << (al->isTuple () ? " (" : " [" );
2387- if (al->type ().isrecord ()) {
2388- RecordType* rt = env.getRecordType (al->type ());
2389- assert (al->size () == rt->size ());
2390- for (unsigned int i = 0 ; i < al->size (); i++) {
2391- oss << Printer::quoteId (rt->fieldName (i)) << " : "
2392- << show_with_type (env, (*al)[i], (*rt)[i], showDzn);
2393- if (i < al->size () - 1 ) {
2394- oss << " , " ;
2395- }
2396- }
2397- } else if (al->type ().istuple ()) {
2398- TupleType* tt = env.getTupleType (al->type ());
2399- for (unsigned int i = 0 ; i < al->size (); i++) {
2400- oss << show_with_type (env, (*al)[i], (*tt)[i], showDzn);
2401- if (i < al->size () - 1 ) {
2402- oss << " , " ;
2403- }
2404- }
2405- if (al->size () == 1 ) {
2406- oss << " ," ;
2407- }
2408- } else {
2409- // Use element type from al_t since evaluating e may have removed the enum types
2410- auto elemType = al_t .elemType (env);
2411- for (unsigned int i = 0 ; i < al->size (); i++) {
2412- oss << show_with_type (env, (*al)[i], elemType, showDzn);
2413- if (i < al->size () - 1 ) {
2414- oss << " , " ;
2415- }
2416- }
2417- }
2418- oss << (al->isTuple () ? " )" : " ]" );
2419- } else {
2420- Printer p (oss, 0 , false , &env);
2421- p.print (e);
2422- }
2423- return oss.str ();
2424- }
24252336std::string show (EnvI& env, Expression* exp) {
24262337 return show_with_type (env, exp, Expression::type (exp), false );
24272338}
@@ -2438,7 +2349,7 @@ std::string b_show_dzn_id(EnvI& env, Call* call) {
24382349
24392350std::string b_show_json_basic (EnvI& env, Expression* e, Type t) {
24402351 if (t.bt () == Type::BT_INT && t.typeId () != 0 && t.isPar ()) {
2441- return b_show_enum_type (env, e, t, false , true );
2352+ return show_enum_type (env, e, t, false , true );
24422353 }
24432354 std::ostringstream oss;
24442355 Printer p (oss, 0 , false , &env);
0 commit comments