ASTNode* XQCastAs::staticResolution(StaticContext *context) { XPath2MemoryManager *mm = context->getMemoryManager(); _exprType->staticResolution(context); const SequenceType::ItemType *itemType = _exprType->getItemType(); if(itemType != NULL) { if((XPath2Utils::equals(itemType->getTypeURI(), XERCES_CPP_NAMESPACE_QUALIFIER SchemaSymbols::fgURI_SCHEMAFORSCHEMA) && XPath2Utils::equals(itemType->getType()->getName(), szNOTATION)) || (XPath2Utils::equals(itemType->getTypeURI(), FunctionConstructor::XMLChXPath2DatatypesURI) && XPath2Utils::equals(itemType->getType()->getName(), AnyAtomicType::fgDT_ANYATOMICTYPE))) XQThrow(TypeErrorException,X("XQCastAs::CastAsResult::getSingleResult"), X("The target type of a cast expression must be an atomic type that is in the in-scope schema types and is not xs:NOTATION or xdt:anyAtomicType [err:XPST0080]")); } if(_exprType->getItemTestType() != SequenceType::ItemType::TEST_ATOMIC_TYPE) XQThrow(TypeErrorException,X("XQCastAs::staticResolution"),X("Cannot cast to a non atomic type")); _typeIndex = context->getItemFactory()-> getPrimitiveTypeIndex(_exprType->getTypeURI(), _exprType->getConstrainingType()->getName(), _isPrimitive); // If this is a cast to xs:QName or xs:NOTATION and the argument is a string literal // evaluate immediately, since they aren't allowed otherwise if((_typeIndex == AnyAtomicType::QNAME || _typeIndex == AnyAtomicType::NOTATION) && _expr->getType() == LITERAL && ((XQLiteral*)_expr)->getPrimitiveType() == AnyAtomicType::STRING) { AutoDelete<DynamicContext> dContext(context->createDynamicContext()); dContext->setMemoryManager(mm); AnyAtomicType::Ptr item = (AnyAtomicType*)_expr->createResult(dContext)->next(dContext).get(); try { if(_isPrimitive) { item = item->castAsNoCheck(_typeIndex, 0, 0, dContext); } else { item = item->castAsNoCheck(_typeIndex, _exprType->getTypeURI(), _exprType->getConstrainingType()->getName(), dContext); } } catch(XQException &e) { if(e.getXQueryLine() == 0) e.setXQueryPosition(this); throw; } return XQLiteral::create(item, dContext, mm, this)->staticResolution(context); } _expr = new (mm) XQAtomize(_expr, mm); _expr->setLocationInfo(this); _expr = _expr->staticResolution(context); return this; }
ASTNode* XQLiteral::staticResolution(StaticContext *context) { switch(primitiveType_) { case AnyAtomicType::DECIMAL: case AnyAtomicType::FLOAT: case AnyAtomicType::DOUBLE: { // Constant fold, to parse numeric literals XPath2MemoryManager* mm = context->getMemoryManager(); AutoDelete<DynamicContext> dContext(context->createDynamicContext()); dContext->setMemoryManager(mm); Result result = createResult(dContext); ASTNode *newBlock = XQSequence::constantFold(result, dContext, mm, this); this->release(); return newBlock; } default: break; } return this; }
bool XQLiteral::isDateOrTimeAndHasNoTimezone(StaticContext *context) const { switch(primitiveType_) { case AnyAtomicType::DATE: case AnyAtomicType::DATE_TIME: case AnyAtomicType::TIME: case AnyAtomicType::G_DAY: case AnyAtomicType::G_MONTH: case AnyAtomicType::G_MONTH_DAY: case AnyAtomicType::G_YEAR: case AnyAtomicType::G_YEAR_MONTH: { if(context == 0) return true; AutoDelete<DynamicContext> dContext(context->createDynamicContext()); dContext->setMemoryManager(context->getMemoryManager()); Item::Ptr item = dContext->getItemFactory()->createDerivedFromAtomicType(primitiveType_, typeURI_, typeName_, value_, dContext); return !((const DateOrTimeType*)item.get())->hasTimezone(); } default: break; } return false; }
ASTNode *FunctionCount::staticTypingImpl(StaticContext *context) { _src.clearExceptType(); calculateSRCForArguments(context); if(context) { const StaticAnalysis &sa = _args[0]->getStaticAnalysis(); const StaticType &sType = sa.getStaticType(); if(sType.getMin() == sType.getMax() && !sa.areDocsOrCollectionsUsed() && !sa.isNoFoldingForced()) { XPath2MemoryManager* mm = context->getMemoryManager(); try { AutoDelete<DynamicContext> dContext(context->createDynamicContext()); dContext->setMemoryManager(mm); return XQLiteral::create(mm->createInteger(sType.getMin()), dContext, mm, this); } catch(XQException &ex) { // Constant folding failed } } } return this; }