void SimpleLazyTempSeqIter::init( const store::TempSeq_t& seq, xs_integer startPos, xs_integer endPos) { assert(seq->isLazy()); theTempSeq = static_cast<SimpleLazyTempSeq*>(seq.getp()); try { theStartPos = to_xs_long(startPos); } catch ( std::range_error const& ) { throw ZORBA_EXCEPTION( zerr::ZSTR0060_RANGE_EXCEPTION, ERROR_PARAMS( startPos, ZED( ZSTR0060_ForSequence ) ) ); } try { theEndPos = to_xs_long(endPos); } catch ( std::range_error const& ) { throw ZORBA_EXCEPTION( zerr::ZSTR0060_RANGE_EXCEPTION, ERROR_PARAMS( endPos, ZED( ZSTR0060_ForSequence ) ) ); } theCurPos = theStartPos - 1; }
SimpleLazyTempSeqIter::SimpleLazyTempSeqIter( const SimpleLazyTempSeq* tempSeq, xs_integer startPos, xs_integer endPos) : theTempSeq(const_cast<SimpleLazyTempSeq*>(tempSeq)) { try { theStartPos = to_xs_long(startPos); } catch ( std::range_error const& ) { throw ZORBA_EXCEPTION( zerr::ZSTR0060_RANGE_EXCEPTION, ERROR_PARAMS( startPos, ZED( ZSTR0060_ForSequence ) ) ); } try { theEndPos = to_xs_long(endPos); } catch ( std::range_error const& ) { throw ZORBA_EXCEPTION( zerr::ZSTR0060_RANGE_EXCEPTION, ERROR_PARAMS( endPos, ZED( ZSTR0060_ForSequence ) ) ); } theCurPos = theStartPos - 1; }
void SimpleLazyTempSeq::purgeUpTo(xs_integer position) { xs_long pos; try { pos = to_xs_long(position); } catch (std::range_error const&) { throw ZORBA_EXCEPTION(zerr::ZSTR0060_RANGE_EXCEPTION, ERROR_PARAMS(position,ZED(ZSTR0060_ForSequence))); } ZORBA_ASSERT(pos >= thePurgedUpTo); ZORBA_ASSERT(static_cast<std::vector<store::Item*>::size_type>(pos - thePurgedUpTo) <= theItems.size()); std::vector<store::Item*>::iterator ite = theItems.begin(); std::vector<store::Item*>::iterator end = theItems.begin() + static_cast<std::vector<store::Item*>::size_type>(pos - thePurgedUpTo); for (; ite != end; ++ite) { (*ite)->removeReference(); } theItems.erase(theItems.begin(), end); thePurgedUpTo = pos; }
expr* XQueryCompiler::translate( parsenode_t parsenode, audit::ScopedRecord& auditRecord) { time::Timer timer; audit::DurationAuditor durationAudit(auditRecord, audit::XQUERY_COMPILATION_TRANSLATION_DURATION, timer); theCompilerCB->setPhase(CompilerCB::TRANSLATION); expr* rootExpr = zorba::translate(*parsenode, theCompilerCB); theCompilerCB->setPhase(CompilerCB::NONE); if (rootExpr == NULL) { // TODO: can this happen? throw ZORBA_EXCEPTION(zerr::ZAPI0002_XQUERY_COMPILATION_FAILED); } return rootExpr; }
Item ItemFactoryImpl::createBase64Binary(const char* aData, size_t aLength, bool aIsBase64) { try { store::Item_t result; xs_base64Binary b64( aData, aLength, aIsBase64 ); theItemFactory->createBase64Binary( result, b64 ); return &*result; } catch ( std::exception const &e ) { throw ZORBA_EXCEPTION( zerr::ZSTR0040_TYPE_ERROR, ERROR_PARAMS( e.what() ) ); } }
void MemArchiver::read_next_compound_field_impl( bool is_class, ArchiveFieldKind& field_treat, TypeCode& type, int& id, int& referencing) { if (current_field == NULL || is_after_last) { throw ZORBA_EXCEPTION(zerr::ZCSE0001_NONEXISTENT_INPUT_FIELD, ERROR_PARAMS(0)); } type = current_field->theType; id = current_field->theId; field_treat = current_field->theKind; referencing = (current_field->theReferredField ? current_field->theReferredField->theId : 0); is_after_last = false; if (current_field->theFirstChild) { current_field = current_field->theFirstChild; } else if (!current_field->theIsSimple && (field_treat == ARCHIVE_FIELD_BASECLASS || field_treat == ARCHIVE_FIELD_PTR)) { //class without childs temp_field.theParent = current_field; current_field = &temp_field;//prepare for read_end_current_level() } else if (current_field->theNextSibling) { current_field = current_field->theNextSibling; } else { is_after_last = true; } }
void ICCheckerImpl::actualCheck(const store::Item* collName, const store::Item* icCollName, const store::Item* icName) { if ( collName->equals(icCollName) ) { // if this ic has a dependency on current collection //std::cout << "ic check : " << icName->getStringValue() << //" coll: " << collName->getStringValue() << std::endl; std::cout.flush(); ValueIC* vic = theSctx->lookup_ic(icName); store::Item_t partialRes; store::Iterator_t iter = vic->getIterator(); iter->open(); try { iter->next(partialRes); } catch(...) { iter->close(); throw; } iter->close(); bool icConditionHolds = partialRes->getBooleanValue(); //std::cout << "ic check : result = " // << (icConditionHolds ? "true" : "false") // << std::endl; std::cout.flush(); if ( !icConditionHolds ) { throw ZORBA_EXCEPTION( zerr::ZDDY0033_IC_NOT_MET, ERROR_PARAMS( icName->getStringValue(), collName->getStringValue() ) ); } } }
void MemArchiver::read_next_simple_ptr_field_impl(TypeCode type, void** obj) { if (current_field == NULL || is_after_last) { throw ZORBA_EXCEPTION(zerr::ZCSE0001_NONEXISTENT_INPUT_FIELD, ERROR_PARAMS(0)); } assert(type == current_field->theType); switch (type) { case TYPE_STD_STRING: { *reinterpret_cast<std::string**>(obj) = new std::string(current_field->theStringValue.str()); break; } default: { ZORBA_ASSERT(false); } } is_after_last = false; if (current_field->theFirstChild) { current_field = current_field->theFirstChild; } else if (current_field->theNextSibling) { current_field = current_field->theNextSibling; } else { is_after_last = true; } }
/****************************************************************************** Create a dummy main module to wrap a library module. ******************************************************************************/ parsenode_t XQueryCompiler::createMainModule( parsenode_t aLibraryModule, std::istream& aXQuery, const zstring& aFileName) { //get the namespace from the LibraryModule LibraryModule* mod_ast = dynamic_cast<LibraryModule *>(&*aLibraryModule); if (!mod_ast) throw ZORBA_EXCEPTION(zerr::ZAPI0002_XQUERY_COMPILATION_FAILED, ERROR_PARAMS(ZED(BadLibraryModule))); const zstring& lib_namespace = mod_ast->get_decl()->get_target_namespace(); URI lURI(lib_namespace); if(!lURI.is_absolute()) { throw XQUERY_EXCEPTION(err::XQST0046, ERROR_PARAMS(lURI.toString(), ZED(MustBeAbsoluteURI)), ERROR_LOC(mod_ast->get_decl()->get_location())); } // Set up the original query stream as the result of resolving the // library module's URI aXQuery.clear(); aXQuery.seekg(0); FakeLibraryModuleURLResolver* aFakeResolver = new FakeLibraryModuleURLResolver(aFileName, aXQuery); theCompilerCB->theRootSctx->add_url_resolver(aFakeResolver); // create a dummy main module and parse it std::stringstream lDocStream; zstring tmp; zorba::xml::escape(lib_namespace, &tmp); lDocStream << "import module namespace m = '" << tmp << "'; 1"; return parse(lDocStream, aFileName); }
void MemArchiver::read_next_simple_temp_field_impl(TypeCode type, void* obj) { if (current_field == NULL || is_after_last) { throw ZORBA_EXCEPTION(zerr::ZCSE0001_NONEXISTENT_INPUT_FIELD, ERROR_PARAMS(0)); } assert(type == current_field->theType); switch (type) { case TYPE_INT64: { *static_cast<int64_t*>(obj) = current_field->theValue.int64v; break; } case TYPE_UINT64: { *static_cast<uint64_t*>(obj) = current_field->theValue.uint64v; break; } case TYPE_INT32: { *static_cast<int32_t*>(obj) = current_field->theValue.int32v; break; } case TYPE_UINT32: { *static_cast<uint32_t*>(obj) = current_field->theValue.uint32v; break; } case TYPE_ENUM: { *static_cast<uint32_t*>(obj) = current_field->theValue.uint32v; break; } case TYPE_INT16: { *static_cast<int16_t*>(obj) = current_field->theValue.int16v; break; } case TYPE_UINT16: { *static_cast<uint16_t*>(obj) = current_field->theValue.uint16v; break; } case TYPE_CHAR: { *static_cast<char*>(obj) = current_field->theValue.charv; break; } case TYPE_UCHAR: { *static_cast<unsigned char*>(obj) = current_field->theValue.ucharv; break; } case TYPE_BOOL: { *static_cast<bool*>(obj) = current_field->theValue.boolv; break; } case TYPE_ZSTRING: { *static_cast<zstring*>(obj) = current_field->theStringValue; break; } case TYPE_STD_STRING: { *static_cast<std::string*>(obj) = current_field->theStringValue.str(); break; } default: { ZORBA_ASSERT(false); } } is_after_last = false; if (current_field->theFirstChild) { current_field = current_field->theFirstChild; } else if (current_field->theNextSibling) { current_field = current_field->theNextSibling; } else { is_after_last = true; } }
void fxcharheap::ioexception( string const& msg ) const { throw ZORBA_EXCEPTION( zerr::ZXQP0013_FXCHARHEAP_EXCEPTION, ERROR_PARAMS( msg, os_error::get_err_string() ) ); }
void Lock::wlock() { #ifdef WIN32 if(ZorbaImpl::ctrl_c_signaled) return; #endif theMutex.lock(); ThreadId thisThread = Runnable::self(); retry: switch (theMode) { case NOLOCK: { assert(theHolders.size() == 0); LockRequest req(WRITE, thisThread); theHolders.push_back(req); theMode = WRITE; break; } case READ: { std::vector<LockRequest>::iterator iter = theHolders.begin(); std::vector<LockRequest>::iterator end = theHolders.end(); for (; iter != end; iter++) { if (iter->theThread == thisThread) break; } if (iter != end) { // This is an upgrade request // If the current thread is the only holder of the lock, the upgrade // request is granted immediatelly. if (theHolders.size() == 1) { iter->theMode = WRITE; iter->theCount++; theMode = WRITE; break; } // If another thread is waiting for an upgrade, allowing the current to // wait as well will result in a deadlock. Instead, we throw an exception. if (theHaveUpgradeReq) { theMutex.unlock(); throw ZORBA_EXCEPTION( zerr::ZXQP0030_DEADLOCK ); } // Else, the thread is made to wait iter->theUpgrade = true; theHaveUpgradeReq = true; } theNumWaiters++; theCondition.wait(); theNumWaiters--; goto retry; } case WRITE: { assert(theHolders.size() == 1); if (theHolders[0].theThread == thisThread) { assert(theHolders[0].theMode == WRITE); theHolders[0].theCount++; break; } else { theNumWaiters++; theCondition.wait(); theNumWaiters--; goto retry; } } default: { ZORBA_FATAL(false, "Corrupted lock structure"); } } theMutex.unlock(); }