zorba-coders team mailing list archive
-
zorba-coders team
-
Mailing list archive
-
Message #24816
[Merge] lp:~zorba-coders/zorba/markos-scratch into lp:zorba
Markos Zaharioudakis has proposed merging lp:~zorba-coders/zorba/markos-scratch into lp:zorba.
Commit message:
removed StaticContextImpl::checkInvokable() method ==> small optimization for invoke()
Requested reviews:
Markos Zaharioudakis (markos-za)
For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/markos-scratch/+merge/178692
removed StaticContextImpl::checkInvokable() method ==> small optimization for invoke()
--
https://code.launchpad.net/~zorba-coders/zorba/markos-scratch/+merge/178692
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'bin/zorbacmd.cpp'
--- bin/zorbacmd.cpp 2013-08-05 11:24:53 +0000
+++ bin/zorbacmd.cpp 2013-08-06 08:48:31 +0000
@@ -904,13 +904,14 @@
ItemSequence_t docsSeq = docMgr->availableDocuments();
Iterator_t lIter = docsSeq->getIterator();
lIter->open();
+
Item uri;
std::vector<Item> docURIs;
- while (lIter->next(uri))
+ while (docsIter->next(uri))
{
docURIs.push_back(uri);
}
- lIter->close();
+ docsIter->close();
size_t numDocs = docURIs.size();
=== modified file 'doc/cxx/examples/datamanager.cpp'
--- doc/cxx/examples/datamanager.cpp 2013-08-05 11:24:53 +0000
+++ doc/cxx/examples/datamanager.cpp 2013-08-06 08:48:31 +0000
@@ -51,7 +51,7 @@
Item lDoc = aDataManager->parseXML(lInStream);
// (2) bind the document in the store using the DocumentManager
- DocumentManager* lDocMgr = aDataManager->getDocumentManager();
+ DocumentManager_t lDocMgr = aZorba->getDocumentManager();
lDocMgr->put("books.xml", lDoc);
// (3) doc('books.xml') accesses the previously found document
=== modified file 'src/api/staticcontextimpl.cpp'
--- src/api/staticcontextimpl.cpp 2013-08-05 11:54:06 +0000
+++ src/api/staticcontextimpl.cpp 2013-08-06 08:48:31 +0000
@@ -962,6 +962,9 @@
}
+/*******************************************************************************
+
+********************************************************************************/
void
StaticContextImpl::getFunctions(
const String& aFnNameUri,
@@ -992,6 +995,9 @@
}
+/*******************************************************************************
+
+********************************************************************************/
void
StaticContextImpl::getFunctionAnnotations(
const Item& aQName,
@@ -1020,6 +1026,9 @@
}
+/*******************************************************************************
+
+********************************************************************************/
void
StaticContextImpl::setContextItemStaticType(TypeIdentifier_t type)
{
@@ -1032,6 +1041,9 @@
}
+/*******************************************************************************
+
+********************************************************************************/
TypeIdentifier_t
StaticContextImpl::getContextItemStaticType() const
{
@@ -1044,6 +1056,9 @@
}
+/*******************************************************************************
+
+********************************************************************************/
void
StaticContextImpl::setTraceStream(std::ostream& os)
{
@@ -1051,6 +1066,9 @@
}
+/*******************************************************************************
+
+********************************************************************************/
void
StaticContextImpl::resetTraceStream()
{
@@ -1058,6 +1076,9 @@
}
+/*******************************************************************************
+
+********************************************************************************/
bool
StaticContextImpl::getOption(const Item& aQName, String& aOptionValue) const
{
@@ -1083,6 +1104,9 @@
}
+/*******************************************************************************
+
+********************************************************************************/
void
StaticContextImpl::declareOption(const Item& aQName, const String& aOptionValue)
{
@@ -1099,6 +1123,9 @@
}
+/*******************************************************************************
+
+********************************************************************************/
void StaticContextImpl::loadProlog(
const String& prolog,
const Zorba_CompilerHints_t& hints)
@@ -1119,6 +1146,9 @@
}
+/*******************************************************************************
+
+********************************************************************************/
static void
toInternalPath(
const std::vector<String>& aPublicStrings,
@@ -1140,6 +1170,9 @@
}
+/*******************************************************************************
+
+********************************************************************************/
static void
toPublicPath(
const std::vector<zstring>& aInternalStrings,
@@ -1153,6 +1186,9 @@
}
+/*******************************************************************************
+
+********************************************************************************/
void
StaticContextImpl::setURIPath(const std::vector<String> &aURIPath)
{
@@ -1168,6 +1204,10 @@
}
}
+
+/*******************************************************************************
+
+********************************************************************************/
void
StaticContextImpl::getURIPath(std::vector<String> &aURIPath) const
{
@@ -1183,6 +1223,10 @@
}
}
+
+/*******************************************************************************
+
+********************************************************************************/
void
StaticContextImpl::getFullURIPath(std::vector<String> &aURIPath) const
{
@@ -1198,6 +1242,10 @@
}
}
+
+/*******************************************************************************
+
+********************************************************************************/
void
StaticContextImpl::setLibPath(const std::vector<String> &aLibPath)
{
@@ -1213,6 +1261,10 @@
}
}
+
+/*******************************************************************************
+
+********************************************************************************/
void
StaticContextImpl::getLibPath(std::vector<String> &aLibPath) const
{
@@ -1228,6 +1280,10 @@
}
}
+
+/*******************************************************************************
+
+********************************************************************************/
void
StaticContextImpl::getFullLibPath(std::vector<String> &aLibPath) const
{
@@ -1243,6 +1299,10 @@
}
}
+
+/*******************************************************************************
+
+********************************************************************************/
void StaticContextImpl::setModulePaths(const std::vector<String>& aModulePaths)
{
try
@@ -1258,6 +1318,10 @@
}
}
+
+/*******************************************************************************
+
+********************************************************************************/
void StaticContextImpl::getModulePaths(std::vector<String>& aModulePaths) const
{
try
@@ -1276,6 +1340,9 @@
}
+/*******************************************************************************
+
+********************************************************************************/
void
StaticContextImpl::getFullModulePaths( std::vector<String>& aFullModulePaths ) const
{
@@ -1295,6 +1362,9 @@
}
+/*******************************************************************************
+
+********************************************************************************/
String
StaticContextImpl::resolve(const String& aRelativeUri) const
{
@@ -1313,6 +1383,9 @@
}
+/*******************************************************************************
+
+********************************************************************************/
String
StaticContextImpl::resolve(const String& aRelativeUri, const String& aBaseUri) const
{
@@ -1332,6 +1405,9 @@
}
+/*******************************************************************************
+
+********************************************************************************/
bool
StaticContextImpl::validate(
const Item& rootNode,
@@ -1375,6 +1451,9 @@
}
+/*******************************************************************************
+
+********************************************************************************/
bool
StaticContextImpl::validate(
const Item& rootElement,
@@ -1450,14 +1529,75 @@
}
-/**
- * construct the query to call invoke
- * for the QName of the function and for each argument,
- * the query declares an external variable ($qname, $arg_1, ..., $arg_n)
- * which needs to be bound before execution.
- */
-String
-StaticContextImpl::createInvokeQuery(const Function_t& aFunc, size_t aArity) const
+/*******************************************************************************
+
+********************************************************************************/
+ItemSequence_t StaticContextImpl::invoke(
+ const Item& aQName,
+ const std::vector<ItemSequence_t>& aArgs) const
+{
+ try
+ {
+ store::Item_t qname = Unmarshaller::getInternalItem(aQName);
+
+ if (qname->getTypeCode() != store::XS_QNAME)
+ {
+ throw XQUERY_EXCEPTION(err::XPTY0004, ERROR_PARAMS(ZED(BadType_23o), "xs:QName"));
+ }
+
+ csize numArgs = aArgs.size();
+
+ // test if function with given #args exists
+ function* func = theCtx->lookup_fn(qname.getp(), numArgs);
+
+ if (!func)
+ {
+ throw XQUERY_EXCEPTION(err::XPST0017,
+ ERROR_PARAMS(qname->getStringValue(), ZED(FunctionUndeclared_3), numArgs));
+ }
+
+ String queryStr = createInvokeQuery(func, numArgs);
+
+ XQuery_t query(new XQueryImpl());
+
+ // compile without any hints
+ Zorba_CompilerHints_t lHints;
+ StaticContext_t querySctx = new StaticContextImpl(*this);
+
+ query->compile(queryStr, querySctx, lHints);
+
+ // bind qname and params
+ DynamicContext* queryDctx = query->getDynamicContext();
+
+ queryDctx->setVariable("", "xxx-func-name", aQName);
+
+ for (csize i = 0; i < numArgs; ++i)
+ {
+ std::ostringstream argName;
+ argName << "arg" << i;
+ queryDctx->setVariable("", argName.str(), aArgs[i]->getIterator());
+ }
+
+ // the XQueryImpl object needs to live as long as its iterator
+ // because the iterator returned as a result of the query
+ // contains a reference to the query in order to do cleanup work.
+ // The same is true for this sctx
+ return new InvokeItemSequence(query, const_cast<StaticContextImpl*>(this));
+ }
+ catch (ZorbaException const& e)
+ {
+ ZorbaImpl::notifyError(theDiagnosticHandler, e);
+ return 0;
+ }
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+std::string StaticContextImpl::createInvokeQuery(
+ const function* func,
+ csize arity)
{
std::ostringstream lOut;
@@ -1467,7 +1607,7 @@
<< std::endl
<< "declare variable $xxx-func-name as xs:QName" << " external;" << std::endl;
- for (size_t i = 0; i < aArity; ++i)
+ for (csize i = 0; i < arity; ++i)
{
lOut << "declare variable $arg" << i << " external;" << std::endl;
}
@@ -1477,16 +1617,16 @@
// call updating, sequential, or simple invoke function
lOut << "ref:invoke";
- if (aFunc->isUpdating())
+ if (func->isUpdating())
lOut << "-u";
- else if (aFunc->isSequential())
+ else if (func->isSequential())
lOut << "-s";
- else if (!aFunc->isDeterministic())
+ else if (!func->isDeterministic())
lOut << "-n";
// args
lOut << "($xxx-func-name";
- for (size_t i = 0; i < aArity; ++i)
+ for (csize i = 0; i < arity; ++i)
{
lOut << ", $arg" << i;
}
@@ -1495,93 +1635,6 @@
}
-Function_t
-StaticContextImpl::checkInvokable(const Item& aQName, size_t aNumArgs) const
-{
- store::Item* qname = Unmarshaller::getInternalItem(aQName);
-
- if (qname->getTypeCode() != store::XS_QNAME)
- {
- throw XQUERY_EXCEPTION(err::XPTY0004,
- ERROR_PARAMS(ZED(BadType_23o), "xs:QName" ));
- }
-
- // test if function with given #args exists
- Function_t lFunc;
-
- std::vector<Function_t> lFunctions;
- findFunctions(aQName, lFunctions);
-
- if (lFunctions.empty())
- {
- throw XQUERY_EXCEPTION(err::XPST0017,
- ERROR_PARAMS(aQName.getStringValue(), ZED(FunctionUndeclared_3), aNumArgs));
- }
-
- for (std::vector<Function_t>::const_iterator lIter = lFunctions.begin();
- lIter != lFunctions.end(); ++lIter)
- {
- if ((*lIter)->isVariadic() || (*lIter)->getArity() == aNumArgs)
- {
- lFunc = (*lIter);
- break;
- }
- }
-
- if (!lFunc)
- {
- throw XQUERY_EXCEPTION(err::XPST0017,
- ERROR_PARAMS(aQName.getStringValue(), ZED(FunctionUndeclared_3), aNumArgs));
- }
-
- return lFunc;
-}
-
-
-ItemSequence_t
-StaticContextImpl::invoke(
- const Item& aQName,
- const std::vector<ItemSequence_t>& aArgs) const
-{
- try
- {
- Function_t lFunc = checkInvokable(aQName, aArgs.size());
-
- String lStr = createInvokeQuery(lFunc, aArgs.size());
-
- std::auto_ptr<XQueryImpl> impl(new XQueryImpl());
-
- // compile without any hints
- Zorba_CompilerHints_t lHints;
- StaticContext_t lSctx = new StaticContextImpl(*this);
-
- impl->compile(lStr, lSctx, lHints);
-
- // bind qname and params
- DynamicContext* lDCtx = impl->getDynamicContext();
- lDCtx->setVariable("xxx-func-name", aQName);
- for (size_t i = 0; i < aArgs.size(); ++i)
- {
- std::ostringstream lArgName;
- lArgName << "arg" << i;
- lDCtx->setVariable(lArgName.str(), aArgs[i]->getIterator());
- }
-
- // the XQueryImpl object needs to live as long as its iterator
- // because the iterator returned as a result of the query
- // contains a reference to the query in order to do cleanup work.
- // The same is true for this sctx
- return new InvokeItemSequence(impl.release(),
- const_cast<StaticContextImpl*>(this));
- }
- catch (ZorbaException const& e)
- {
- ZorbaImpl::notifyError(theDiagnosticHandler, e);
- return 0;
- }
-}
-
-
StaticCollectionManager*
StaticContextImpl::getStaticCollectionManager() const
{
@@ -1600,6 +1653,9 @@
}
+/*******************************************************************************
+
+********************************************************************************/
void
StaticContextImpl::setAuditEvent(audit::Event* anEvent)
{
@@ -1607,6 +1663,9 @@
}
+/*******************************************************************************
+
+********************************************************************************/
audit::Event*
StaticContextImpl::getAuditEvent() const
{
@@ -1614,6 +1673,9 @@
}
+/*******************************************************************************
+
+********************************************************************************/
void
StaticContextImpl::getExternalVariables(Iterator_t& aVarsIter) const
{
@@ -1658,6 +1720,7 @@
return fetch(aURI, aEntityKind, "UTF-8");
}
+
Item
StaticContextImpl::fetch(
const String& aURI,
@@ -1700,12 +1763,14 @@
return 0;
}
+
Item
StaticContextImpl::fetchBinary(const String& aURI) const
{
return fetchBinary(aURI, "SOME_CONTENT");
}
+
Item
StaticContextImpl::fetchBinary(
const String& aURI,
=== modified file 'src/api/staticcontextimpl.h'
--- src/api/staticcontextimpl.h 2013-03-25 23:02:19 +0000
+++ src/api/staticcontextimpl.h 2013-08-06 08:48:31 +0000
@@ -27,9 +27,11 @@
namespace zorba {
- class DiagnosticHandler;
- class StaticCollectionManagerImpl;
- class static_context;
+class DiagnosticHandler;
+class StaticCollectionManagerImpl;
+class static_context;
+class function;
+
/*******************************************************************************
@@ -72,6 +74,9 @@
// allow for lazy creation
mutable StaticCollectionManagerImpl * theCollectionMgr;
+protected:
+ static std::string createInvokeQuery(const function*, size_t aArity);
+
private:
StaticContextImpl(const StaticContextImpl&);
@@ -322,17 +327,8 @@
virtual Item
fetchBinary(const String& aURI, const String& aEntityKind) const;
-protected:
- String
- createInvokeQuery(const Function_t&, size_t aArity) const;
-
- Function_t
- checkInvokable(const Item& aQName, size_t aNumArgs) const;
-
-public:
virtual void
clearBaseURI();
-
};
} // namespace zorba
=== modified file 'src/api/zorbaimpl.cpp'
--- src/api/zorbaimpl.cpp 2013-08-05 11:54:06 +0000
+++ src/api/zorbaimpl.cpp 2013-08-06 08:48:31 +0000
@@ -19,16 +19,16 @@
#include <istream>
#include <zorba/diagnostic_list.h>
-//#include <zorba/function.h>
#include <zorba/store_manager.h>
#include <zorba/query_location.h>
#include "api/xqueryimpl.h"
#include "api/staticcontextimpl.h"
+#include "api/documentmanagerimpl.h"
#include "api/itemfactoryimpl.h"
#include "api/unmarshaller.h"
#include "api/xmldatamanagerimpl.h"
-#include "api/item_iter_vector.h"
+//#include "api/item_iter_vector.h"
#include "api/auditimpl.h"
#include "zorbautils/fatal.h"
@@ -233,8 +233,10 @@
DiagnosticHandler* aDiagnosticHandler)
{
XQuery_t lXQuery(new XQueryImpl());
+
if (aDiagnosticHandler != 0)
lXQuery->registerDiagnosticHandler(aDiagnosticHandler);
+
lXQuery->compile(aQuery, aStaticContext, aHints);
return lXQuery;
}
@@ -243,9 +245,9 @@
/*******************************************************************************
********************************************************************************/
-StaticContext_t ZorbaImpl::createStaticContext(DiagnosticHandler* aDiagnosticHandler)
+StaticContext_t ZorbaImpl::createStaticContext(DiagnosticHandler* handler)
{
- return StaticContext_t(new StaticContextImpl(aDiagnosticHandler));
+ return new StaticContextImpl(handler);
}
@@ -311,14 +313,5 @@
}
-void ZorbaImpl::checkItem(const store::Item_t& aItem)
-{
- if (!aItem)
- throw ZORBA_EXCEPTION(
- zerr::ZAPI0014_INVALID_ARGUMENT, ERROR_PARAMS( "null", ZED( BadItem ) )
- );
-}
-
-
} // namespace zorba
/* vim:set et sw=2 ts=2: */
=== modified file 'src/api/zorbaimpl.h'
--- src/api/zorbaimpl.h 2013-08-05 11:24:53 +0000
+++ src/api/zorbaimpl.h 2013-08-06 08:48:31 +0000
@@ -75,15 +75,14 @@
static void notifyWarning(DiagnosticHandler*, XQueryWarning const&);
- static void checkItem(const store::Item_t& aItem);
-
-public:
+ public:
virtual ~ZorbaImpl();
void shutdown() { shutdownInternal(true); }
int runUriTest() const;
+
int runDebuggerProtocolTest() const;
XQuery_t createQuery(DiagnosticHandler* aDiagnosticHandler = 0);
@@ -128,7 +127,7 @@
const Zorba_CompilerHints_t& aHints,
DiagnosticHandler* aDiagnosticHandler = 0);
- StaticContext_t createStaticContext(DiagnosticHandler* aDiagnosticHandler = 0);
+ StaticContext_t createStaticContext(DiagnosticHandler* handler = 0);
XmlDataManager_t getXmlDataManager();
=== modified file 'src/context/root_static_context.cpp'
--- src/context/root_static_context.cpp 2013-07-01 18:59:06 +0000
+++ src/context/root_static_context.cpp 2013-08-06 08:48:31 +0000
@@ -127,7 +127,8 @@
{
QueryLoc loc;
- theImplementationBaseUri = ZORBA_NS;
+ theImplementationBaseUri = "file:///";
+ set_entity_retrieval_uri(theImplementationBaseUri);
compute_base_uri();
set_language_kind(StaticContextConsts::language_kind_xquery);
Follow ups