@@ -1217,6 +1217,108 @@ IntVal* PolynomialIntVal::canonicalize(ASTBuilder* builder)
1217
1217
return this ;
1218
1218
}
1219
1219
1220
+ // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! TypeCastIntVal !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1221
+ bool TypeCastIntVal::_equalsValOverride (Val* val)
1222
+ {
1223
+ if (auto typeCastIntVal = as<TypeCastIntVal>(val))
1224
+ {
1225
+ if (!type->equals (typeCastIntVal->type ))
1226
+ return false ;
1227
+ if (!base->equalsVal (typeCastIntVal->base ))
1228
+ return false ;
1229
+ return true ;
1230
+ }
1231
+ return false ;
1232
+ }
1233
+
1234
+ void TypeCastIntVal::_toTextOverride (StringBuilder& out)
1235
+ {
1236
+ type->toText (out);
1237
+ out << " (" ;
1238
+ base->toText (out);
1239
+ out << " )" ;
1240
+ }
1241
+
1242
+ HashCode TypeCastIntVal::_getHashCodeOverride ()
1243
+ {
1244
+ HashCode result = type->getHashCode ();
1245
+ result = combineHash (result, base->getHashCode ());
1246
+ return result;
1247
+ }
1248
+
1249
+ Val* TypeCastIntVal::tryFoldImpl (ASTBuilder* astBuilder, Type* resultType, Val* base, DiagnosticSink* sink)
1250
+ {
1251
+ SLANG_UNUSED (sink);
1252
+
1253
+ if (auto c = as<ConstantIntVal>(base))
1254
+ {
1255
+ IntegerLiteralValue resultValue = c->value ;
1256
+ auto baseType = as<BasicExpressionType>(resultType);
1257
+ if (baseType)
1258
+ {
1259
+ switch (baseType->baseType )
1260
+ {
1261
+ case BaseType::Int:
1262
+ resultValue = (int )resultValue;
1263
+ break ;
1264
+ case BaseType::UInt:
1265
+ resultValue = (unsigned int )resultValue;
1266
+ break ;
1267
+ case BaseType::Int64:
1268
+ case BaseType::IntPtr:
1269
+ resultValue = (Int64)resultValue;
1270
+ break ;
1271
+ case BaseType::UInt64 :
1272
+ case BaseType::UIntPtr:
1273
+ resultValue = (UInt64 )resultValue;
1274
+ break ;
1275
+ case BaseType::Int16:
1276
+ resultValue = (int16_t )resultValue;
1277
+ break ;
1278
+ case BaseType::UInt16 :
1279
+ resultValue = (uint16_t )resultValue;
1280
+ break ;
1281
+ case BaseType::Int8:
1282
+ resultValue = (int8_t )resultValue;
1283
+ break ;
1284
+ case BaseType::UInt8 :
1285
+ resultValue = (uint8_t )resultValue;
1286
+ break ;
1287
+ default :
1288
+ return nullptr ;
1289
+ }
1290
+ }
1291
+ return astBuilder->getIntVal (resultType, resultValue);
1292
+ }
1293
+ return nullptr ;
1294
+ }
1295
+
1296
+ Val* TypeCastIntVal::_substituteImplOverride (ASTBuilder* astBuilder, SubstitutionSet subst, int * ioDiff)
1297
+ {
1298
+ int diff = 0 ;
1299
+ auto substBase = base->substituteImpl (astBuilder, subst, &diff);
1300
+ if (substBase != base)
1301
+ diff++;
1302
+ auto substType = as<Type>(type->substituteImpl (astBuilder, subst, &diff));
1303
+ if (substType != type)
1304
+ diff++;
1305
+ *ioDiff += diff;
1306
+ if (diff)
1307
+ {
1308
+ auto newVal = tryFoldImpl (astBuilder, substType, substBase, nullptr );
1309
+ if (newVal)
1310
+ return newVal;
1311
+ else
1312
+ {
1313
+ auto result = astBuilder->create <TypeCastIntVal>(substType, substBase);
1314
+ return result;
1315
+ }
1316
+ }
1317
+ // Nothing found: don't substitute.
1318
+ return this ;
1319
+ }
1320
+
1321
+
1220
1322
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! FuncCallIntVal !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1221
1323
1222
1324
bool FuncCallIntVal::_equalsValOverride (Val* val)
0 commit comments