void CastingPlatform<TSubClass, issueError>::issueCastError(const Item &validationError, const Item &sourceValue, const ReportContext::Ptr &context) const { Q_ASSERT(validationError); Q_ASSERT(context); Q_ASSERT(validationError.isAtomicValue()); Q_ASSERT(validationError.template as<AtomicValue>()->hasError()); const ValidationError::Ptr err(validationError.template as<ValidationError>()); QString msg(err->message()); if(msg.isNull()) { msg = QtXmlPatterns::tr("It's not possible to cast the value %1 of type %2 to %3") .arg(formatData(sourceValue.stringValue())) .arg(formatType(context->namePool(), sourceValue.type())) .arg(formatType(context->namePool(), targetType())); } else { Q_ASSERT(!msg.isEmpty()); msg = QtXmlPatterns::tr("Failure when casting from %1 to %2: %3") .arg(formatType(context->namePool(), sourceValue.type())) .arg(formatType(context->namePool(), targetType())) .arg(msg); } /* If m_errorCode is FORG0001, we assume our sub-classer doesn't have a * special wish about error code, so then we use the error object's code. */ context->error(msg, m_errorCode == ReportContext::FORG0001 ? err->errorCode() : m_errorCode, static_cast<const TSubClass*>(this)); }
AtomicComparator::Ptr ComparisonPlatform<TSubClass, issueError, comparisonType, errorCode>:: fetchComparator(const ItemType::Ptr &t1, const ItemType::Ptr &t2, const ReportContext::Ptr &context) const { Q_ASSERT(t1); Q_ASSERT(t2); if(*BuiltinTypes::xsAnyAtomicType == *t1 || *BuiltinTypes::xsAnyAtomicType == *t2 || *BuiltinTypes::item == *t1 || *BuiltinTypes::item == *t2 || *BuiltinTypes::numeric == *t1 || *BuiltinTypes::numeric == *t2 || *CommonSequenceTypes::Empty == *t1 || *CommonSequenceTypes::Empty == *t2) { /* The static type of(at least) one of the operands could not * be narrowed further, so we do the operator * lookup at runtime. */ return AtomicComparator::Ptr(); } const AtomicComparatorLocator::Ptr locator (static_cast<const AtomicType *>(t1.data())->comparatorLocator()); if(!locator) { if(issueError) { context->error(QtXmlPatterns::tr("No comparisons can be done involving the type %1.") .arg(formatType(context->namePool(), t1)), errorCode, static_cast<const TSubClass *>(this)->actualReflection()); } return AtomicComparator::Ptr(); } const AtomicComparator::Ptr comp(static_cast<const AtomicType *>(t2.data())->accept(locator, operatorID(), static_cast<const TSubClass *>(this)->actualReflection())); if(comp) return comp; else if(issueError) { context->error(QtXmlPatterns::tr("Operator %1 is not available between atomic values of type %2 and %3.") .arg(formatKeyword(AtomicComparator::displayName(operatorID(), comparisonType)), formatType(context->namePool(), t1), formatType(context->namePool(), t2)), errorCode, static_cast<const TSubClass *>(this)->actualReflection()); } return AtomicComparator::Ptr(); }
AtomicCaster::Ptr CastingPlatform<TSubClass, issueError>::locateCaster(const ItemType::Ptr &sourceType, const ReportContext::Ptr &context, bool &castImpossible, const SourceLocationReflection *const location, const ItemType::Ptr &targetType) { Q_ASSERT(sourceType); Q_ASSERT(targetType); const AtomicCasterLocator::Ptr locator(static_cast<AtomicType *>( targetType.data())->casterLocator()); if(!locator) { if(issueError) { context->error(QtXmlPatterns::tr("No casting is possible with %1 as the target type.") .arg(formatType(context->namePool(), targetType)), ReportContext::XPTY0004, location); } else castImpossible = true; return AtomicCaster::Ptr(); } const AtomicCaster::Ptr caster(static_cast<const AtomicType *>(sourceType.data())->accept(locator, location)); if(!caster) { if(issueError) { context->error(QtXmlPatterns::tr("It is not possible to cast from %1 to %2.") .arg(formatType(context->namePool(), sourceType)) .arg(formatType(context->namePool(), targetType)), ReportContext::XPTY0004, location); } else castImpossible = true; return AtomicCaster::Ptr(); } return caster; }
void Template::raiseXTSE0680(const ReportContext::Ptr &context, const QXmlName &name, const SourceLocationReflection *const reflection) { context->error(QtXmlPatterns::tr("The parameter %1 is passed, but no corresponding %2 exists.") .arg(formatKeyword(context->namePool(), name), formatKeyword(QLatin1String("xsl:param"))), ReportContext::XTSE0680, reflection); }
void CastingPlatform<TSubClass, issueError>::checkTargetType(const ReportContext::Ptr &context) const { Q_ASSERT(context); const ItemType::Ptr tType(targetType()); Q_ASSERT(tType); Q_ASSERT(tType->isAtomicType()); const AtomicType::Ptr asAtomic(tType); /* This catches casting to xs:NOTATION and xs:anyAtomicType. */ if(asAtomic->isAbstract()) { context->error(QtXmlPatterns::tr("Casting to %1 is not possible because it " "is an abstract type, and can therefore never be instantiated.") .arg(formatType(context->namePool(), tType)), ReportContext::XPST0080, static_cast<const TSubClass*>(this)); } }
AtomicMathematician::Ptr ArithmeticExpression::fetchMathematician(Expression::Ptr &op1, Expression::Ptr &op2, const AtomicMathematician::Operator op, const bool issueError, const ReportContext::Ptr &context, const SourceLocationReflection *const reflection, const ReportContext::ErrorCode code, const bool isCompat) { ItemType::Ptr t1(op1->staticType()->itemType()); ItemType::Ptr t2(op2->staticType()->itemType()); if(BuiltinTypes::xsUntypedAtomic->xdtTypeMatches(t1) || (isCompat && (BuiltinTypes::xsString->xdtTypeMatches(t1) || BuiltinTypes::xsDecimal->xdtTypeMatches(t1)))) { op1 = Expression::Ptr(new UntypedAtomicConverter(op1, BuiltinTypes::xsDouble)); /* The types might have changed, reload. */ t1 = op1->staticType()->itemType(); } if(BuiltinTypes::xsUntypedAtomic->xdtTypeMatches(t2) || (isCompat && (BuiltinTypes::xsString->xdtTypeMatches(t1) || BuiltinTypes::xsDecimal->xdtTypeMatches(t1)))) { op2 = Expression::Ptr(new UntypedAtomicConverter(op2, BuiltinTypes::xsDouble)); /* The types might have changed, reload. */ t2 = op2->staticType()->itemType(); } const AtomicMathematicianLocator::Ptr locator (static_cast<const AtomicType *>(t1.data())->mathematicianLocator()); if(!locator) { if(!issueError) return AtomicMathematician::Ptr(); context->error(QtXmlPatterns::tr( "Operator %1 cannot be used on type %2.") .arg(formatKeyword(AtomicMathematician::displayName(op))) .arg(formatType(context->namePool(), t1)), code, reflection); return AtomicMathematician::Ptr(); } const AtomicMathematician::Ptr comp (static_cast<const AtomicType *>(t2.data())->accept(locator, op, reflection)); if(comp) return comp; if(!issueError) return AtomicMathematician::Ptr(); context->error(QtXmlPatterns::tr("Operator %1 cannot be used on " "atomic values of type %2 and %3.") .arg(formatKeyword(AtomicMathematician::displayName(op))) .arg(formatType(context->namePool(), t1)) .arg(formatType(context->namePool(), t2)), code, reflection); return AtomicMathematician::Ptr(); }