diff options
Diffstat (limited to 'source/slang/slang-ast-val.cpp')
| -rw-r--r-- | source/slang/slang-ast-val.cpp | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/source/slang/slang-ast-val.cpp b/source/slang/slang-ast-val.cpp index c8b9d0bb8..d8886f05b 100644 --- a/source/slang/slang-ast-val.cpp +++ b/source/slang/slang-ast-val.cpp @@ -1217,6 +1217,108 @@ IntVal* PolynomialIntVal::canonicalize(ASTBuilder* builder) return this; } +// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! TypeCastIntVal !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +bool TypeCastIntVal::_equalsValOverride(Val* val) +{ + if (auto typeCastIntVal = as<TypeCastIntVal>(val)) + { + if (!type->equals(typeCastIntVal->type)) + return false; + if (!base->equalsVal(typeCastIntVal->base)) + return false; + return true; + } + return false; +} + +void TypeCastIntVal::_toTextOverride(StringBuilder& out) +{ + type->toText(out); + out << "("; + base->toText(out); + out << ")"; +} + +HashCode TypeCastIntVal::_getHashCodeOverride() +{ + HashCode result = type->getHashCode(); + result = combineHash(result, base->getHashCode()); + return result; +} + +Val* TypeCastIntVal::tryFoldImpl(ASTBuilder* astBuilder, Type* resultType, Val* base, DiagnosticSink* sink) +{ + SLANG_UNUSED(sink); + + if (auto c = as<ConstantIntVal>(base)) + { + IntegerLiteralValue resultValue = c->value; + auto baseType = as<BasicExpressionType>(resultType); + if (baseType) + { + switch (baseType->baseType) + { + case BaseType::Int: + resultValue = (int)resultValue; + break; + case BaseType::UInt: + resultValue = (unsigned int)resultValue; + break; + case BaseType::Int64: + case BaseType::IntPtr: + resultValue = (Int64)resultValue; + break; + case BaseType::UInt64: + case BaseType::UIntPtr: + resultValue = (UInt64)resultValue; + break; + case BaseType::Int16: + resultValue = (int16_t)resultValue; + break; + case BaseType::UInt16: + resultValue = (uint16_t)resultValue; + break; + case BaseType::Int8: + resultValue = (int8_t)resultValue; + break; + case BaseType::UInt8: + resultValue = (uint8_t)resultValue; + break; + default: + return nullptr; + } + } + return astBuilder->getIntVal(resultType, resultValue); + } + return nullptr; +} + +Val* TypeCastIntVal::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff) +{ + int diff = 0; + auto substBase = base->substituteImpl(astBuilder, subst, &diff); + if (substBase != base) + diff++; + auto substType = as<Type>(type->substituteImpl(astBuilder, subst, &diff)); + if (substType != type) + diff++; + *ioDiff += diff; + if (diff) + { + auto newVal = tryFoldImpl(astBuilder, substType, substBase, nullptr); + if (newVal) + return newVal; + else + { + auto result = astBuilder->create<TypeCastIntVal>(substType, substBase); + return result; + } + } + // Nothing found: don't substitute. + return this; +} + + // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! FuncCallIntVal !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! bool FuncCallIntVal::_equalsValOverride(Val* val) |
