Markos Zaharioudakis has proposed merging lp:~zorba-coders/zorba/markos-annotations into lp:zorba.
Requested reviews: Markos Zaharioudakis (markos-za) For more details, see: https://code.launchpad.net/~zorba-coders/zorba/markos-annotations/+merge/80899 simplified and optimized the implementation for annotations -- https://code.launchpad.net/~zorba-coders/zorba/markos-annotations/+merge/80899 Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/annotations/annotations.cpp' --- src/annotations/annotations.cpp 2011-08-11 17:19:25 +0000 +++ src/annotations/annotations.cpp 2011-11-01 13:50:27 +0000 @@ -15,21 +15,17 @@ */ #include "stdafx.h" -#include <cmath> - #include "annotations/annotations.h" -#include "system/globalenv.h" #include "store/api/item.h" #include "store/api/item_factory.h" -#include "context/static_context.h" -#include "context/static_context_consts.h" #include "compiler/expression/expr.h" #include "zorbaserialization/serialization_engine.h" #include "diagnostics/assert.h" +#include "diagnostics/util_macros.h" #include "system/globalenv.h" @@ -38,90 +34,270 @@ SERIALIZABLE_CLASS_VERSIONS(AnnotationInternal) END_SERIALIZABLE_CLASS_VERSIONS(AnnotationInternal) -SERIALIZABLE_CLASS_VERSIONS(AnnotationLiteral) -END_SERIALIZABLE_CLASS_VERSIONS(AnnotationLiteral) - SERIALIZABLE_CLASS_VERSIONS(AnnotationList) END_SERIALIZABLE_CLASS_VERSIONS(AnnotationList); -/******************************************************************************* - -********************************************************************************/ -AnnotationInternal::AnnotationInternal(const store::Item_t& aExpandedQName) +std::vector<store::Item_t> +AnnotationInternal::theAnnotId2NameMap; + +ItemHandleHashMap<AnnotationInternal::AnnotationId> +AnnotationInternal::theAnnotName2IdMap(0, NULL, 64, false); + +std::vector<AnnotationInternal::RuleBitSet> +AnnotationInternal::theRuleSet; + + +/******************************************************************************* + Static method, called from GlobalEnvironment::init() +********************************************************************************/ +void AnnotationInternal::createBuiltIn() +{ + store::Item_t qname; + AnnotationId id; + + theAnnotId2NameMap.resize(zann_end); + + // + // W3C annotations + // + GENV_ITEMFACTORY->createQName(qname, static_context::W3C_FN_NS, "fn", "public"); + id = fn_public; + theAnnotId2NameMap[id] = qname; + theAnnotName2IdMap.insert(qname, id); + + GENV_ITEMFACTORY->createQName(qname, static_context::W3C_FN_NS, "fn", "private"); + id = fn_private; + theAnnotId2NameMap[id] = qname; + theAnnotName2IdMap.insert(qname, id); + +#define ZANN(a, b) \ + GENV_ITEMFACTORY->createQName(qname, ZORBA_ANNOTATIONS_NS, "", #a); \ + id = zann_##b; \ + theAnnotId2NameMap[id] = qname; \ + theAnnotName2IdMap.insert(qname, id); + + + // + // Zorba annotations - deterministic/nondeterministic + // + ZANN(deterministic, deterministic); + ZANN(nondeterministic, nondeterministic); + + // + // Zorba annotations - xquery scripting + // + ZANN(assignable, assignable); + ZANN(nonassignable, nonassignable); + + ZANN(sequential, sequential); + ZANN(nonsequential, nonsequential); + + // + // Zorba annotations - misc + // + ZANN(variadic, variadic); + + ZANN(streamable, streamable); + + // + // Zorba annotations - xqddf + // + ZANN(unique, unique); + ZANN(nonunique, nonunique); + + ZANN(value-equality, value_equality); + ZANN(general-equality, general_equality); + ZANN(value-range, value_range); + ZANN(general-range, general_range); + + ZANN(automatic, automatic); + ZANN(manual, manual); + + ZANN(mutable, mutable); + ZANN(queue, queue); + ZANN(append-only, append_only); + ZANN(const, const); + + ZANN(ordered, ordered); + ZANN(unordered, unordered); + + ZANN(read-only-nodes, read_only_nodes); + ZANN(mutable-nodes, mutable_nodes); + +#undef ZANN + + // create a set of rules to detect conflicts between annotations +#define ZANN(a) \ + ( 1 << static_cast<uint64_t>(AnnotationInternal::a) ) + + theRuleSet.push_back( + ZANN(zann_unique) | + ZANN(zann_nonunique)); + + theRuleSet.push_back( + ZANN(zann_value_equality) | + ZANN(zann_general_equality) | + ZANN(zann_value_range) | + ZANN(zann_general_range)); + + theRuleSet.push_back( + ZANN(zann_automatic) | + ZANN(zann_manual)); + + theRuleSet.push_back( + ZANN(zann_mutable) | + ZANN(zann_queue) | + ZANN(zann_append_only) | + ZANN(zann_const)); + + theRuleSet.push_back( + ZANN(zann_ordered) | + ZANN(zann_unordered)); + + theRuleSet.push_back( + ZANN(zann_assignable) | + ZANN(zann_nonassignable)); + + theRuleSet.push_back( + ZANN(zann_deterministic) | + ZANN(zann_nondeterministic)); + + theRuleSet.push_back( + ZANN(zann_sequential) | + ZANN(zann_nonsequential)); + + theRuleSet.push_back( + ZANN(fn_private) | + ZANN(fn_public)); + + theRuleSet.push_back( + ZANN(zann_unordered) | + ZANN(zann_queue)); + + theRuleSet.push_back( + ZANN(zann_unordered) | + ZANN(zann_append_only)); + + theRuleSet.push_back( + ZANN(zann_queue) | + ZANN(zann_append_only)); + + theRuleSet.push_back( + ZANN(zann_read_only_nodes) | + ZANN(zann_mutable_nodes)); +#undef ZANN +} + + +/******************************************************************************* + Static method, called from GlobalEnvironment::init() +********************************************************************************/ +void AnnotationInternal::destroyBuiltIn() +{ + theAnnotId2NameMap.clear(); + theAnnotName2IdMap.clear(); +} + + +/******************************************************************************* + +********************************************************************************/ +AnnotationInternal::AnnotationId AnnotationInternal::lookup( + const store::Item_t& qname) +{ + ItemHandleHashMap<AnnotationId>::iterator ite = theAnnotName2IdMap.find(qname); + + if (ite == theAnnotName2IdMap.end()) + return zann_end; + + return (*ite).second; +} + + +/******************************************************************************* + +********************************************************************************/ +store::Item* AnnotationInternal::lookup(AnnotationInternal::AnnotationId id) +{ + assert(id < zann_end); + assert(id < theAnnotId2NameMap.size()); + + return theAnnotId2NameMap[id].getp(); +} + + +/******************************************************************************* + +********************************************************************************/ +AnnotationInternal::AnnotationInternal(const store::Item_t& qname) : - theQName(aExpandedQName) + theId(zann_end), + theQName(qname) { + ItemHandleHashMap<AnnotationId>::iterator ite = theAnnotName2IdMap.find(qname); + if (ite != theAnnotName2IdMap.end()) + theId = (*ite).second; } +/******************************************************************************* + +********************************************************************************/ AnnotationInternal::AnnotationInternal( - const store::Item_t& aExpandedQName, - const std::vector<AnnotationLiteral_t>& aLiteralList) + const store::Item_t& qname, + std::vector<store::Item_t>& literals) : - theQName(aExpandedQName), - theLiteralList(aLiteralList) + theId(zann_end), + theQName(qname) { + theLiterals.swap(literals); + + ItemHandleHashMap<AnnotationId>::iterator ite = theAnnotName2IdMap.find(qname); + if (ite != theAnnotName2IdMap.end()) + theId = (*ite).second; } +/******************************************************************************* + +********************************************************************************/ void AnnotationInternal::serialize(::zorba::serialization::Archiver& ar) { + SERIALIZE_ENUM(AnnotationId, theId); ar & theQName; - ar & theLiteralList; + ar & theLiterals; } +/******************************************************************************* + +********************************************************************************/ const store::Item* AnnotationInternal::getQName() const { return theQName.getp(); } -unsigned int AnnotationInternal::getNumLiterals() const -{ - return (unsigned int)theLiteralList.size(); -} - - -const AnnotationLiteral* AnnotationInternal::getLiteral(unsigned int index) const -{ - if (index < theLiteralList.size()) - return theLiteralList[index]; - else - return NULL; -} - - -/******************************************************************************* - -********************************************************************************/ -void AnnotationLiteral::serialize(::zorba::serialization::Archiver& ar) -{ - ar & theLiteral; -} - - -AnnotationLiteral::AnnotationLiteral(const store::Item_t& aLiteralValue) - : theLiteral(aLiteralValue) -{ -} - - -store::Item_t AnnotationLiteral::getLiteralItem() const -{ - return theLiteral; -} - - -AnnotationInternal* AnnotationList::getAnnotation(unsigned int index) const -{ - if (index < theAnnotationList.size()) - return theAnnotationList[index].getp(); - else - return NULL; -} - +/******************************************************************************* + +********************************************************************************/ +csize AnnotationInternal::getNumLiterals() const +{ + return theLiterals.size(); +} + + +/******************************************************************************* + +********************************************************************************/ +store::Item* AnnotationInternal::getLiteral(csize index) const +{ + if (index < theLiterals.size()) + return theLiterals[index].getp(); + else + return NULL; +} /******************************************************************************* @@ -152,38 +328,45 @@ /******************************************************************************* ********************************************************************************/ +AnnotationInternal* AnnotationList::getAnnotation(csize index) const +{ + if (index < theAnnotationList.size()) + return theAnnotationList[index].getp(); + else + return NULL; +} + + +/******************************************************************************* + +********************************************************************************/ void AnnotationList::push_back( - const store::Item_t& aExpQName, - const std::vector<rchandle<const_expr> >& aLiterals) + const store::Item_t& qname, + const std::vector<rchandle<const_expr> >& literals) { - std::vector<AnnotationLiteral_t> lLiterals; + std::vector<store::Item_t> lLiterals; - for (std::vector<rchandle<const_expr> >::const_iterator it = aLiterals.begin(); - it != aLiterals.end(); + for (std::vector<rchandle<const_expr> >::const_iterator it = literals.begin(); + it != literals.end(); ++it) { - lLiterals.push_back(new AnnotationLiteral((*it)->get_val())); + lLiterals.push_back((*it)->get_val()); } - theAnnotationList.push_back(new AnnotationInternal(aExpQName, lLiterals)); + theAnnotationList.push_back(new AnnotationInternal(qname, lLiterals)); } /******************************************************************************* ********************************************************************************/ -bool AnnotationList::contains(const store::Item_t& aSearchQName) const +bool AnnotationList::contains(AnnotationInternal::AnnotationId id) const { - if (aSearchQName.getp() == NULL) - return false; - - // sequential search might not be the most efficient but - // how many annotations might a function or variable have? 5? - for (ListConstIter_t lIter = theAnnotationList.begin(); - lIter != theAnnotationList.end(); - ++lIter) + for (ListConstIter_t ite = theAnnotationList.begin(); + ite != theAnnotationList.end(); + ++ite) { - if ((*lIter)->getQName()->equals(aSearchQName)) + if ((*ite)->getId() == id) return true; } @@ -196,232 +379,61 @@ ********************************************************************************/ void AnnotationList::checkConflictingDeclarations(const QueryLoc& loc) const { - static_context& lCtx = GENV_ROOT_STATIC_CONTEXT; - // make sure we don't have more annotations then max 64 bit - assert( static_cast<uint64_t>(StaticContextConsts::zann_end) < + assert( static_cast<uint64_t>(AnnotationInternal::zann_end) < std::numeric_limits<uint64_t>::max() ); RuleBitSet lCurrAnn; // mark and detect duplicates - for (ListConstIter_t lIter = theAnnotationList.begin(); - lIter != theAnnotationList.end(); - ++lIter) + for (ListConstIter_t ite = theAnnotationList.begin(); + ite != theAnnotationList.end(); + ++ite) { - store::Item_t lQName = const_cast<store::Item*>((*lIter)->getQName()); - StaticContextConsts::annotations_t lAnn = lCtx.lookup_ann(lQName); + const store::Item* qname = (*ite)->getQName(); + AnnotationId id = (*ite)->getId(); // detect duplicate annotations (if we "know" them) - if ( lAnn != StaticContextConsts::zann_end && lCurrAnn.test( lAnn ) ) + if (id != AnnotationInternal::zann_end && lCurrAnn.test(id)) { - throw XQUERY_EXCEPTION( - err::XQST0106, - ERROR_PARAMS( - lQName->getStringValue(), - ZED(XQST0106_THE_SAME) - ), - ERROR_LOC(loc)); + RAISE_ERROR(err::XQST0106, loc, + ERROR_PARAMS(qname->getStringValue(), ZED(XQST0106_THE_SAME))); } - lCurrAnn.set( lAnn ); + lCurrAnn.set(id); } // check rules - for ( std::vector<RuleBitSet>::const_iterator lIter = theRuleSet.begin(); - lIter != theRuleSet.end(); - ++lIter ) + std::vector<RuleBitSet>::const_iterator ite = AnnotationInternal::theRuleSet.begin(); + std::vector<RuleBitSet>::const_iterator end = AnnotationInternal::theRuleSet.end(); + + for (; ite != end; ++ite) { - const RuleBitSet lCurrSet = *lIter; - if ( ( lCurrAnn & lCurrSet ).count() > 1 ) + const RuleBitSet& lCurrSet = *ite; + + if ((lCurrAnn & lCurrSet).count() > 1) { // build error string to return set of conflicting annotations std::ostringstream lProblems; - for ( size_t i = 0, j = 0; i < StaticContextConsts::zann_end; ++i ) + for (csize i = 0, j = 0; i < AnnotationInternal::zann_end; ++i) { - if ( lCurrSet.test( i ) ) + if (lCurrSet.test(i)) { - lProblems - << lCtx.lookup_ann( - static_cast<StaticContextConsts::annotations_t>(i) - )->getStringValue() - << ((j == lCurrSet.count() - 1) ? "" : ", "); + AnnotationId id = static_cast<AnnotationId>(i); + + lProblems << AnnotationInternal::lookup(id)->getStringValue() + << ((j == lCurrSet.count() - 1) ? "" : ", "); ++j; } } - throw XQUERY_EXCEPTION( - err::XQST0106, - ERROR_PARAMS( - lProblems.str(), - ZED(XQST0106_CONFLICTING) - ), - ERROR_LOC(loc)); + + RAISE_ERROR(err::XQST0106, loc, + ERROR_PARAMS(lProblems.str(), ZED(XQST0106_CONFLICTING))); } } } -void AnnotationList::createBuiltIn(static_context* aCtx) -{ - store::Item_t lTmp; - - // - // W3C annotations - // - GENV_ITEMFACTORY->createQName(lTmp, static_context::W3C_FN_NS, "fn", "public"); - aCtx->add_ann(StaticContextConsts::fn_public, lTmp); - - GENV_ITEMFACTORY->createQName(lTmp, static_context::W3C_FN_NS, "fn", "private"); - aCtx->add_ann(StaticContextConsts::fn_private, lTmp); - - // - // Zorba annotations - deterministic/nondeterministic - // - GENV_ITEMFACTORY->createQName(lTmp, ZORBA_ANNOTATIONS_NS, "", "deterministic"); - aCtx->add_ann(StaticContextConsts::zann_deterministic, lTmp); - - GENV_ITEMFACTORY->createQName(lTmp, ZORBA_ANNOTATIONS_NS, "", "nondeterministic"); - aCtx->add_ann(StaticContextConsts::zann_nondeterministic, lTmp); - - // - // Zorba annotations - xquery scripting - // - GENV_ITEMFACTORY->createQName(lTmp, ZORBA_ANNOTATIONS_NS, "", "assignable"); - aCtx->add_ann(StaticContextConsts::zann_assignable, lTmp); - - GENV_ITEMFACTORY->createQName(lTmp, ZORBA_ANNOTATIONS_NS, "", "nonassignable"); - aCtx->add_ann(StaticContextConsts::zann_nonassignable, lTmp); - - GENV_ITEMFACTORY->createQName(lTmp, ZORBA_ANNOTATIONS_NS, "", "sequential"); - aCtx->add_ann(StaticContextConsts::zann_sequential, lTmp); - - GENV_ITEMFACTORY->createQName(lTmp, ZORBA_ANNOTATIONS_NS, "", "nonsequential"); - aCtx->add_ann(StaticContextConsts::zann_nonsequential, lTmp); - - // - // Zorba annotations - misc - // - GENV_ITEMFACTORY->createQName(lTmp, ZORBA_ANNOTATIONS_NS, "", "variadic"); - aCtx->add_ann(StaticContextConsts::zann_variadic, lTmp); - - GENV_ITEMFACTORY->createQName(lTmp, ZORBA_ANNOTATIONS_NS, "", "streamable"); - aCtx->add_ann(StaticContextConsts::zann_streamable, lTmp); - - // - // Zorba annotations - xqddf - // - GENV_ITEMFACTORY->createQName(lTmp, ZORBA_ANNOTATIONS_NS, "", "unique"); - aCtx->add_ann(StaticContextConsts::zann_unique, lTmp); - - GENV_ITEMFACTORY->createQName(lTmp, ZORBA_ANNOTATIONS_NS, "", "nonunique"); - aCtx->add_ann(StaticContextConsts::zann_nonunique, lTmp); - - GENV_ITEMFACTORY->createQName(lTmp, ZORBA_ANNOTATIONS_NS, "", "value-equality"); - aCtx->add_ann(StaticContextConsts::zann_value_equality, lTmp); - - GENV_ITEMFACTORY->createQName(lTmp, ZORBA_ANNOTATIONS_NS, "", "general-equality"); - aCtx->add_ann(StaticContextConsts::zann_general_equality, lTmp); - - GENV_ITEMFACTORY->createQName(lTmp, ZORBA_ANNOTATIONS_NS, "", "value-range"); - aCtx->add_ann(StaticContextConsts::zann_value_range, lTmp); - - GENV_ITEMFACTORY->createQName(lTmp, ZORBA_ANNOTATIONS_NS, "", "general-range"); - aCtx->add_ann(StaticContextConsts::zann_general_range, lTmp); - - GENV_ITEMFACTORY->createQName(lTmp, ZORBA_ANNOTATIONS_NS, "", "automatic"); - aCtx->add_ann(StaticContextConsts::zann_automatic, lTmp); - - GENV_ITEMFACTORY->createQName(lTmp, ZORBA_ANNOTATIONS_NS, "", "manual"); - aCtx->add_ann(StaticContextConsts::zann_manual, lTmp); - - GENV_ITEMFACTORY->createQName(lTmp, ZORBA_ANNOTATIONS_NS, "", "mutable"); - aCtx->add_ann(StaticContextConsts::zann_mutable, lTmp); - - GENV_ITEMFACTORY->createQName(lTmp, ZORBA_ANNOTATIONS_NS, "", "queue"); - aCtx->add_ann(StaticContextConsts::zann_queue, lTmp); - - GENV_ITEMFACTORY->createQName(lTmp, ZORBA_ANNOTATIONS_NS, "", "append-only"); - aCtx->add_ann(StaticContextConsts::zann_append_only, lTmp); - - GENV_ITEMFACTORY->createQName(lTmp, ZORBA_ANNOTATIONS_NS, "", "const"); - aCtx->add_ann(StaticContextConsts::zann_const, lTmp); - - GENV_ITEMFACTORY->createQName(lTmp, ZORBA_ANNOTATIONS_NS, "", "ordered"); - aCtx->add_ann(StaticContextConsts::zann_ordered, lTmp); - - GENV_ITEMFACTORY->createQName(lTmp, ZORBA_ANNOTATIONS_NS, "", "unordered"); - aCtx->add_ann(StaticContextConsts::zann_unordered, lTmp); - - GENV_ITEMFACTORY->createQName(lTmp, ZORBA_ANNOTATIONS_NS, "", "read-only-nodes"); - aCtx->add_ann(StaticContextConsts::zann_read_only_nodes, lTmp); - - GENV_ITEMFACTORY->createQName(lTmp, ZORBA_ANNOTATIONS_NS, "", "mutable-nodes"); - aCtx->add_ann(StaticContextConsts::zann_mutable_nodes, lTmp); - - // create a set of rules to detect conflicts between annotations -#define ZANN(a) \ - ( 1 << static_cast<uint64_t>(StaticContextConsts:: a) ) - theRuleSet.push_back( - ZANN(zann_unique) | - ZANN(zann_nonunique) - ); - theRuleSet.push_back( - ZANN(zann_value_equality) | - ZANN(zann_general_equality) | - ZANN(zann_value_range) | - ZANN(zann_general_range) - ); - theRuleSet.push_back( - ZANN(zann_automatic) | - ZANN(zann_manual) - ); - theRuleSet.push_back( - ZANN(zann_mutable) | - ZANN(zann_queue) | - ZANN(zann_append_only) | - ZANN(zann_const) - ); - theRuleSet.push_back( - ZANN(zann_ordered) | - ZANN(zann_unordered) - ); - theRuleSet.push_back( - ZANN(zann_assignable) | - ZANN(zann_nonassignable) - ); - theRuleSet.push_back( - ZANN(zann_deterministic) | - ZANN(zann_nondeterministic) - ); - theRuleSet.push_back( - ZANN(zann_sequential) | - ZANN(zann_nonsequential) - ); - theRuleSet.push_back( - ZANN(fn_private) | - ZANN(fn_public) - ); - theRuleSet.push_back( - ZANN(zann_unordered) | - ZANN(zann_queue) - ); - theRuleSet.push_back( - ZANN(zann_unordered) | - ZANN(zann_append_only) - ); - theRuleSet.push_back( - ZANN(zann_queue) | - ZANN(zann_append_only) - ); - theRuleSet.push_back( - ZANN(zann_read_only_nodes) | - ZANN(zann_mutable_nodes) - ); -#undef ZANN -} - -std::vector<AnnotationList::RuleBitSet> AnnotationList::theRuleSet; - } /* namespace zorba */ /* vim:set et sw=2 ts=2: */ === modified file 'src/annotations/annotations.h' --- src/annotations/annotations.h 2011-07-21 01:30:19 +0000 +++ src/annotations/annotations.h 2011-11-01 13:50:27 +0000 @@ -19,39 +19,95 @@ #include <vector> #include <bitset> + #include "common/shared_types.h" + #include "compiler/parsetree/parsenodes.h" +#include "zorbautils/hashmap_itemh.h" + namespace zorba { -class AnnotationLiteral; class AnnotationInternal; class AnnotationList; typedef rchandle<AnnotationInternal> AnnotationInternal_t; typedef rchandle<AnnotationList> AnnotationList_t; -typedef rchandle<AnnotationLiteral> AnnotationLiteral_t; class const_expr; /******************************************************************************* - + Annotation ::= "%" EQName ("(" Literal ("," Literal)* ")")? ********************************************************************************/ class AnnotationInternal : public SimpleRCObject { friend class AnnotationList; -protected: - store::Item_t theQName; - std::vector<AnnotationLiteral_t> theLiteralList; - -public: - AnnotationInternal(const store::Item_t& aExpandedQName); +public: + enum AnnotationId + { + fn_public = 0, + fn_private, + zann_deterministic, + zann_nondeterministic, + zann_assignable, + zann_nonassignable, + zann_sequential, + zann_nonsequential, + zann_variadic, + zann_streamable, + zann_unique, + zann_nonunique, + zann_value_equality, + zann_general_equality, + zann_value_range, + zann_general_range, + zann_automatic, + zann_manual, + zann_mutable, + zann_queue, + zann_append_only, + zann_const, + zann_ordered, + zann_unordered, + zann_read_only_nodes, + zann_mutable_nodes, + + // must be at the end + zann_end + }; + +protected: + typedef std::bitset<zann_end + 1> RuleBitSet; + +protected: + static std::vector<store::Item_t> theAnnotId2NameMap; + + static ItemHandleHashMap<AnnotationId> theAnnotName2IdMap; + + static std::vector<RuleBitSet> theRuleSet; + +protected: + AnnotationId theId; + store::Item_t theQName; + std::vector<store::Item_t> theLiterals; + +public: + static void createBuiltIn(); + + static void destroyBuiltIn(); + + static AnnotationId lookup(const store::Item_t& qname); + + static store::Item* lookup(AnnotationId id); + +public: + AnnotationInternal(const store::Item_t& qname); AnnotationInternal( - const store::Item_t& aExpandedQName, - const std::vector<AnnotationLiteral_t>& aLiteralList); + const store::Item_t& qname, + std::vector<store::Item_t>& literals); public: SERIALIZABLE_CLASS(AnnotationInternal); @@ -59,55 +115,37 @@ void serialize(::zorba::serialization::Archiver& ar); public: - virtual ~AnnotationInternal() { }; + ~AnnotationInternal() { }; + + AnnotationId getId() const { return theId; } const store::Item* getQName() const; - unsigned int getNumLiterals() const; - - const AnnotationLiteral* getLiteral(unsigned int index) const; -}; - - - -/******************************************************************************* - -********************************************************************************/ -class AnnotationLiteral : public SimpleRCObject -{ -protected: - store::Item_t theLiteral; - -public: - AnnotationLiteral(const store::Item_t& aLiteral); - -public: - SERIALIZABLE_CLASS(AnnotationLiteral); - SERIALIZABLE_CLASS_CONSTRUCTOR2(AnnotationLiteral, SimpleRCObject) - void serialize(::zorba::serialization::Archiver& ar); - -public: - virtual ~AnnotationLiteral() {}; - - store::Item_t getLiteralItem() const; -}; - - -/******************************************************************************* - + csize getNumLiterals() const; + + store::Item* getLiteral(csize index) const; +}; + + +/******************************************************************************* + AnnotationList := Annotation* + + Annotation ::= "%" EQName ("(" Literal ("," Literal)* ")")? ********************************************************************************/ class AnnotationList : public SimpleRCObject { public: + typedef AnnotationInternal::RuleBitSet RuleBitSet; + + typedef AnnotationInternal::AnnotationId AnnotationId; + typedef std::vector<AnnotationInternal_t> List_t; + typedef List_t::const_iterator ListConstIter_t; protected: List_t theAnnotationList; - typedef std::bitset<StaticContextConsts::zann_end + 1> RuleBitSet; - static std::vector<RuleBitSet> theRuleSet; - public: SERIALIZABLE_CLASS(AnnotationList); SERIALIZABLE_CLASS_CONSTRUCTOR2(AnnotationList, SimpleRCObject) @@ -116,22 +154,19 @@ public: AnnotationList(); - virtual ~AnnotationList(); - - size_t size() const { return theAnnotationList.size(); } - - AnnotationInternal* getAnnotation(unsigned int index) const; + ~AnnotationList(); + + csize size() const { return theAnnotationList.size(); } + + AnnotationInternal* getAnnotation(csize index) const; void push_back( - const store::Item_t& aExpQName, - const std::vector<rchandle<const_expr> >& aLiterals); + const store::Item_t& qname, + const std::vector<rchandle<const_expr> >& literals); - bool contains(const store::Item_t& aSearchQName) const; + bool contains(AnnotationInternal::AnnotationId id) const; void checkConflictingDeclarations(const QueryLoc& loc) const; - -public: - static void createBuiltIn(static_context* aCtx); }; === modified file 'src/api/annotationimpl.cpp' --- src/api/annotationimpl.cpp 2011-06-14 17:26:33 +0000 +++ src/api/annotationimpl.cpp 2011-11-01 13:50:27 +0000 @@ -50,7 +50,7 @@ if (i >= theAnnotation->getNumLiterals()) return Item(NULL); - Item lItem(theAnnotation->getLiteral(i)->getLiteralItem().getp()); + Item lItem(theAnnotation->getLiteral(i)); return lItem; } === modified file 'src/api/collectionimpl.cpp' --- src/api/collectionimpl.cpp 2011-09-15 13:11:51 +0000 +++ src/api/collectionimpl.cpp 2011-11-01 13:50:27 +0000 @@ -444,17 +444,10 @@ { store::Annotation_t lSAnn = *lIter; - std::vector<AnnotationLiteral_t> lILiterals; - std::vector<store::Item_t>::const_iterator lLiteral; - for (lLiteral = lSAnn->theLiterals.begin(); - lLiteral != lSAnn->theLiterals.end(); - ++lLiteral) - { - lILiterals.push_back(new AnnotationLiteral(*lLiteral)); - } + std::vector<store::Item_t> lLiterals = lSAnn->theLiterals; aAnnotations.push_back( - new AnnotationImpl(new AnnotationInternal(lSAnn->theName, lILiterals))); + new AnnotationImpl(new AnnotationInternal(lSAnn->theName, lLiterals))); } } ZORBA_DM_CATCH === modified file 'src/compiler/translator/translator.cpp' --- src/compiler/translator/translator.cpp 2011-10-21 22:53:06 +0000 +++ src/compiler/translator/translator.cpp 2011-11-01 13:50:27 +0000 @@ -161,8 +161,7 @@ /******************************************************************************* ********************************************************************************/ -#define ZANN_CONTAINS( ann ) \ - theAnnotations->contains(theSctx->lookup_ann(StaticContextConsts:: ann)) +#define ZANN_CONTAINS( ann ) theAnnotations->contains(AnnotationInternal::ann) /******************************************************************************* @@ -3554,8 +3553,7 @@ let_clause_t lc = wrap_in_letclause(&*arg_var, subst_var); - // theCurrentPrologVFDecl might be null in case - // of inline functions + // theCurrentPrologVFDecl might be null in case of inline functions // inline functions currently can't be sequential anyway // hence, we can always lazy evaluation if (!theCurrentPrologVFDecl.isNull()) @@ -3668,19 +3666,15 @@ { if (v.is_global()) { - if (theAnnotations->contains( - - theSctx->lookup_ann(StaticContextConsts::fn_private))) + if (ZANN_CONTAINS(fn_private)) ve->set_private(true); } - if (theAnnotations->contains( - theSctx->lookup_ann(StaticContextConsts::zann_assignable))) + if (ZANN_CONTAINS(zann_assignable)) { ve->set_mutable(true); } - else if (theAnnotations->contains( - theSctx->lookup_ann(StaticContextConsts::zann_nonassignable))) + else if (ZANN_CONTAINS(zann_nonassignable)) { ve->set_mutable(false); } @@ -3807,22 +3801,22 @@ store::Item_t lExpandedQName; expand_function_qname(lExpandedQName, v.get_qname().getp(), loc); - if (lExpandedQName->getNamespace() == static_context::W3C_XML_NS || - lExpandedQName->getNamespace() == XML_SCHEMA_NS || - lExpandedQName->getNamespace() == XSI_NS || - lExpandedQName->getNamespace() == static_context::W3C_FN_NS || - lExpandedQName->getNamespace() == XQUERY_MATH_FN_NS || - lExpandedQName->getNamespace() == ZORBA_ANNOTATIONS_NS) + zstring annotNS = lExpandedQName->getNamespace(); + + if (annotNS == static_context::W3C_XML_NS || + annotNS == XML_SCHEMA_NS || + annotNS == XSI_NS || + annotNS == static_context::W3C_FN_NS || + annotNS == XQUERY_MATH_FN_NS || + annotNS == ZORBA_ANNOTATIONS_NS) { - if ( theSctx->lookup_ann(lExpandedQName) == StaticContextConsts::zann_end) + if (AnnotationInternal::lookup(lExpandedQName) == AnnotationInternal::zann_end) { - throw XQUERY_EXCEPTION( - err::XQST0045, - ERROR_PARAMS( "%" + (lExpandedQName->getPrefix().empty() ? - "\'" + lExpandedQName->getNamespace() + "\'" - : lExpandedQName->getPrefix()) - + ":" + lExpandedQName->getLocalName()), - ERROR_LOC(loc)); + RAISE_ERROR(err::XQST0045, loc, + ERROR_PARAMS( "%" + (lExpandedQName->getPrefix().empty() ? + "\'" + lExpandedQName->getNamespace() + "\'" + : lExpandedQName->getPrefix()) + + ":" + lExpandedQName->getLocalName())); } } else @@ -3839,6 +3833,7 @@ } std::vector<rchandle<const_expr> > lLiterals; + if (v.get_literals()) { std::vector<rchandle<exprnode> >::const_iterator lIter; @@ -4031,62 +4026,62 @@ StaticContextConsts::node_modifier_t lNodeModifier; std::vector<rchandle<const_expr> > lLiterals; - if ( ZANN_CONTAINS (zann_queue) ) + if (ZANN_CONTAINS(zann_queue)) { lUpdateMode = StaticContextConsts::decl_queue; } - else if ( ZANN_CONTAINS ( zann_append_only) ) + else if (ZANN_CONTAINS(zann_append_only)) { lUpdateMode = StaticContextConsts::decl_append_only; } - else if ( ZANN_CONTAINS ( zann_const ) ) + else if (ZANN_CONTAINS(zann_const)) { lUpdateMode = StaticContextConsts::decl_const; } - else if ( ZANN_CONTAINS ( zann_mutable ) ) + else if (ZANN_CONTAINS(zann_mutable)) { lUpdateMode = StaticContextConsts::decl_mutable; } else { - theAnnotations->push_back( - theSctx->lookup_ann( StaticContextConsts::zann_mutable ), - lLiterals - ); + theAnnotations-> + push_back(AnnotationInternal::lookup(AnnotationInternal::zann_mutable), + lLiterals); + lUpdateMode = StaticContextConsts::decl_mutable; } - if ( ZANN_CONTAINS ( zann_ordered) ) + if (ZANN_CONTAINS(zann_ordered)) { lOrderMode = StaticContextConsts::decl_ordered; } - else if ( ZANN_CONTAINS ( zann_unordered ) ) + else if (ZANN_CONTAINS(zann_unordered)) { lOrderMode = StaticContextConsts::decl_unordered; } else { - theAnnotations->push_back( - theSctx->lookup_ann( StaticContextConsts::zann_unordered ), - lLiterals - ); + theAnnotations-> + push_back(AnnotationInternal::lookup(AnnotationInternal::zann_unordered), + lLiterals); + lOrderMode = StaticContextConsts::decl_unordered; } - if ( ZANN_CONTAINS ( zann_read_only_nodes) ) + if (ZANN_CONTAINS(zann_read_only_nodes)) { lNodeModifier = StaticContextConsts::read_only; } - else if ( ZANN_CONTAINS ( zann_mutable_nodes ) ) + else if (ZANN_CONTAINS(zann_mutable_nodes)) { lNodeModifier = StaticContextConsts::mutable_node; } else { - theAnnotations->push_back( - theSctx->lookup_ann( StaticContextConsts::zann_mutable_nodes ), - lLiterals - ); + theAnnotations-> + push_back(AnnotationInternal::lookup(AnnotationInternal::zann_mutable_nodes), + lLiterals); + lNodeModifier = StaticContextConsts::mutable_node; } @@ -10343,15 +10338,13 @@ if ( !theSctx->is_feature_set(feature::hof) ) { - throw XQUERY_EXCEPTION( - zerr::ZXQP0050_FEATURE_NOT_AVAILABLE, - ERROR_PARAMS( "higher-order functions (hof)" ), - ERROR_LOC( v.get_location() ) - ); + RAISE_ERROR(zerr::ZXQP0050_FEATURE_NOT_AVAILABLE, v.get_location(), + ERROR_PARAMS("higher-order functions (hof)")); } return no_state; } + void end_visit(const LiteralFunctionItem& v, void* /*visit_state*/) { TRACE_VISIT_OUT(); @@ -10359,10 +10352,12 @@ rchandle<QName> qname = v.getQName(); uint32_t arity = 0; - try { + try + { arity = to_xs_unsignedInt(v.getArity()); } - catch ( std::range_error const& ) { + catch ( std::range_error const& ) + { RAISE_ERROR(err::XPST0017, loc, ERROR_PARAMS(v.getArity(), ZED(NoParseFnArity))); } @@ -10476,6 +10471,7 @@ var_expr_t arg_var = create_var(loc, qname, var_expr::arg_var); var_expr_t subst_var = bind_var(loc, qname, var_expr::let_var); + let_clause_t lc = wrap_in_letclause(&*arg_var, subst_var); arg_var->set_type(varExpr->get_return_type()); === modified file 'src/context/static_context.cpp' --- src/context/static_context.cpp 2011-10-18 19:06:06 +0000 +++ src/context/static_context.cpp 2011-11-01 13:50:27 +0000 @@ -475,7 +475,6 @@ theImportedPrivateVariablesMap(NULL), theFunctionMap(NULL), theFunctionArityMap(NULL), - theAnnotationMap(NULL), theCollectionMap(NULL), theW3CCollectionMap(NULL), theIndexMap(NULL), @@ -523,7 +522,6 @@ theImportedPrivateVariablesMap(NULL), theFunctionMap(NULL), theFunctionArityMap(NULL), - theAnnotationMap(NULL), theCollectionMap(0), theW3CCollectionMap(NULL), theIndexMap(NULL), @@ -576,7 +574,6 @@ theImportedPrivateVariablesMap(NULL), theFunctionMap(NULL), theFunctionArityMap(NULL), - theAnnotationMap(NULL), theCollectionMap(0), theW3CCollectionMap(NULL), theIndexMap(0), @@ -652,9 +649,6 @@ delete theFunctionArityMap; } - if (theAnnotationMap) - delete theAnnotationMap; - if (theW3CCollectionMap) delete theW3CCollectionMap; @@ -890,8 +884,6 @@ ar & theFunctionArityMap; ar.set_serialize_only_for_eval(false); - ar & theAnnotationMap; - ar & theCollectionMap; ar & theW3CCollectionMap; @@ -2616,49 +2608,6 @@ return lModule->getExternalFunction(aLocalName.str()); } -///////////////////////////////////////////////////////////////////////////////// -// // -// Annotations // -// // -///////////////////////////////////////////////////////////////////////////////// -void -static_context::add_ann( - StaticContextConsts::annotations_t aAnnotation, - const store::Item_t& aQName) -{ - if (!theAnnotationMap) { - theAnnotationMap = new AnnotationMap(); - } - (*theAnnotationMap)[static_cast<uint64_t>(aAnnotation)] = aQName; -} - -store::Item_t -static_context::lookup_ann(StaticContextConsts::annotations_t aAnnotation) const -{ - std::map<uint64_t, store::Item_t>::const_iterator lIter; - if (!theAnnotationMap || - (lIter = theAnnotationMap->find(static_cast<uint64_t>(aAnnotation))) == theAnnotationMap->end()) { - return theParent?theParent->lookup_ann(aAnnotation):NULL; - } - return lIter->second; -} - -StaticContextConsts::annotations_t -static_context::lookup_ann(const store::Item_t& aQName) const -{ - if ( theAnnotationMap ) - { - std::map<uint64_t, store::Item_t>::const_iterator lIter; - for (lIter = theAnnotationMap->begin(); lIter != theAnnotationMap->end(); ++lIter) - { - if (aQName->equals(lIter->second)) - { - return static_cast<StaticContextConsts::annotations_t>(lIter->first); - } - } - } - return theParent?theParent->lookup_ann(aQName):StaticContextConsts::zann_end; -} ///////////////////////////////////////////////////////////////////////////////// // // === modified file 'src/context/static_context.h' --- src/context/static_context.h 2011-10-18 19:06:06 +0000 +++ src/context/static_context.h 2011-11-01 13:50:27 +0000 @@ -321,13 +321,6 @@ different arities. One of these versions is stored in the theFunctionMap, and the rest are regisreded in theFunctionArityMap. - theAnnotations: - -------------- - annotations_t -> store::Item_t map that contains a list of built-in annotations - Those annotations are used in the translator to check if a function, - variable, index, or collection declares any of these annotations. - - theCollectionMap : ------------------ A hash mash map mapping XQDDF collection qnames to the objs storing the info @@ -413,8 +406,6 @@ typedef std::map<std::string, XQPCollator*> CollationMap; - typedef std::map<uint64_t, store::Item_t> AnnotationMap; - public: struct ctx_module_t : public ::zorba::serialization::SerializeBaseClass @@ -538,8 +529,6 @@ FunctionMap * theFunctionMap; FunctionArityMap * theFunctionArityMap; - AnnotationMap * theAnnotationMap; - CollectionMap * theCollectionMap; W3CCollectionMap * theW3CCollectionMap; @@ -838,16 +827,6 @@ // - // Annotation - // - void add_ann(StaticContextConsts::annotations_t ann, const store::Item_t& aQName); - - store::Item_t lookup_ann(StaticContextConsts::annotations_t ann) const; - - StaticContextConsts::annotations_t lookup_ann(const store::Item_t& aQName) const; - - - // // Documents // void bind_document(const zstring& uri, xqtref_t& t); === modified file 'src/functions/function.cpp' --- src/functions/function.cpp 2011-07-29 06:13:28 +0000 +++ src/functions/function.cpp 2011-11-01 13:50:27 +0000 @@ -104,22 +104,16 @@ if (!theAnnotationList) return; - static_context& lCtx = GENV_ROOT_STATIC_CONTEXT; - - if (theAnnotationList->contains( - lCtx.lookup_ann(StaticContextConsts::zann_nondeterministic))) + if (theAnnotationList->contains(AnnotationInternal::zann_nondeterministic)) setDeterministic(false); - setPrivate(theAnnotationList->contains( - lCtx.lookup_ann(StaticContextConsts::fn_private))); + setPrivate(theAnnotationList->contains(AnnotationInternal::fn_private)); - if (isUpdating() - && - theAnnotationList->contains( - lCtx.lookup_ann(StaticContextConsts::zann_sequential))) + if (isUpdating() && + theAnnotationList->contains(AnnotationInternal::zann_sequential)) { throw XQUERY_EXCEPTION(zerr::XSST0001, - ERROR_PARAMS(getName()->getStringValue())); + ERROR_PARAMS(getName()->getStringValue())); } } === modified file 'src/runtime/collections/collections_impl.cpp' --- src/runtime/collections/collections_impl.cpp 2011-10-19 15:28:51 +0000 +++ src/runtime/collections/collections_impl.cpp 2011-11-01 13:50:27 +0000 @@ -554,15 +554,15 @@ // dynamic collections have some default properties lAnn = new store::Annotation(); - lAnn->theName = theSctx->lookup_ann(StaticContextConsts::zann_mutable); - lAnnotations.push_back(lAnn); - - lAnn = new store::Annotation(); - lAnn->theName = theSctx->lookup_ann(StaticContextConsts::zann_ordered); - lAnnotations.push_back(lAnn); - - lAnn = new store::Annotation(); - lAnn->theName = theSctx->lookup_ann(StaticContextConsts::zann_mutable_nodes); + lAnn->theName = AnnotationInternal::lookup(AnnotationInternal::zann_mutable); + lAnnotations.push_back(lAnn); + + lAnn = new store::Annotation(); + lAnn->theName = AnnotationInternal::lookup(AnnotationInternal::zann_ordered); + lAnnotations.push_back(lAnn); + + lAnn = new store::Annotation(); + lAnn->theName = AnnotationInternal::lookup(AnnotationInternal::zann_mutable_nodes); lAnnotations.push_back(lAnn); pul->addCreateCollection( @@ -584,9 +584,9 @@ lAnn->theName = lTmp->getQName(); - for (size_t j = 0; j < lTmp->getNumLiterals(); ++j) + for (csize j = 0; j < lTmp->getNumLiterals(); ++j) { - lAnn->theLiterals.push_back(lTmp->getLiteral(j)->getLiteralItem()); + lAnn->theLiterals.push_back(lTmp->getLiteral(j)); } lAnnotations.push_back(lAnn); } === modified file 'src/store/api/annotation.h' --- src/store/api/annotation.h 2011-09-12 22:42:28 +0000 +++ src/store/api/annotation.h 2011-11-01 13:50:27 +0000 @@ -23,22 +23,24 @@ namespace zorba { namespace store { - class Annotation : public RCObject - { - protected: - SYNC_CODE(mutable RCLock theRCLock;) + +class Annotation : public RCObject +{ +protected: + SYNC_CODE(mutable RCLock theRCLock;) - public: - SYNC_CODE(RCLock* getRCLock() const { return &theRCLock; }) - - long* getSharedRefCounter() const { return NULL; } - - virtual ~Annotation() {} - - public: - Item_t theName; - std::vector<Item_t> theLiterals; - }; +public: + Item_t theName; + std::vector<Item_t> theLiterals; + +public: + SYNC_CODE(RCLock* getRCLock() const { return &theRCLock; }) + + long* getSharedRefCounter() const { return NULL; } + + virtual ~Annotation() {} +}; + } /* namespace store */ } /* namespace zorba */ === modified file 'src/system/globalenv.cpp' --- src/system/globalenv.cpp 2011-06-26 09:43:12 +0000 +++ src/system/globalenv.cpp 2011-11-01 13:50:27 +0000 @@ -75,10 +75,11 @@ m_globalEnv->m_rootStaticContext = new root_static_context(); m_globalEnv->m_rootStaticContext->init(); - RCHelper::addReference (m_globalEnv->m_rootStaticContext); + RCHelper::addReference(m_globalEnv->m_rootStaticContext); BuiltinFunctionLibrary::create(m_globalEnv->m_rootStaticContext); - AnnotationList::createBuiltIn(m_globalEnv->m_rootStaticContext); + + AnnotationInternal::createBuiltIn(); #ifdef ZORBA_XQUERYX //libxml2 and libxslt are needed @@ -93,9 +94,10 @@ std::auto_ptr<XQueryCompilerSubsystem> lSubSystem = XQueryCompilerSubsystem::create(); + m_globalEnv->m_compilerSubSys = lSubSystem.release(); - m_globalEnv->m_http_resolver = new impl::HTTPURLResolver(); + m_globalEnv->m_http_resolver = new impl::HTTPURLResolver(); } @@ -118,9 +120,11 @@ delete m_globalEnv->xqueryx_convertor; #endif - RCHelper::removeReference (m_globalEnv->m_rootStaticContext); + RCHelper::removeReference(m_globalEnv->m_rootStaticContext); m_globalEnv->m_rootStaticContext = 0; + AnnotationInternal::destroyBuiltIn(); + m_globalEnv->m_store = NULL; // we shutdown icu @@ -133,6 +137,8 @@ BuiltinFunctionLibrary::destroy(); + AnnotationInternal::destroyBuiltIn(); + delete m_globalEnv; m_globalEnv = NULL;
-- Mailing list: https://launchpad.net/~zorba-coders Post to : zorba-coders@lists.launchpad.net Unsubscribe : https://launchpad.net/~zorba-coders More help : https://help.launchpad.net/ListHelp