dbertoni    2003/11/05 14:18:17

  Modified:    c/src/xalanc/XPath XPath.cpp XPath.hpp
                        XPathExecutionContext.hpp
                        XPathExecutionContextDefault.cpp
                        XPathExecutionContextDefault.hpp
  Removed:     c/src/xalanc/XPath FoundIndex.cpp FoundIndex.hpp
  Log:
  Cleaned up obsolete code that used exceptions to handle indexes in patterns.  
push and pop the context node list to an internal stack for better stack 
management.
  
  Revision  Changes    Path
  1.6       +55 -76    xml-xalan/c/src/xalanc/XPath/XPath.cpp
  
  Index: XPath.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/xalanc/XPath/XPath.cpp,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- XPath.cpp 19 Sep 2003 21:05:26 -0000      1.5
  +++ XPath.cpp 5 Nov 2003 22:18:17 -0000       1.6
  @@ -85,7 +85,6 @@
   
   
   #include "FormatterStringLengthCounter.hpp"
  -#include "FoundIndex.hpp"
   #include "MutableNodeRefList.hpp"
   #include "XalanQNameByReference.hpp"
   #include "XObject.hpp"
  @@ -2893,15 +2892,15 @@
                break;
        }
   
  -     // Push and pop the context node list...
  -     XPathExecutionContext::ContextNodeListSetAndRestore             
theSetAndRestore(
  -                                                                     
executionContext,
  -                                                                     
*subQueryResults);
  -
        opPos += argLen;
   
        int             nextStepType = 
currentExpression.getOpCodeMapValue(opPos);
   
  +     // Push and pop the context node list...
  +             XPathExecutionContext::ContextNodeListPushAndPop        
thePushAndPop(
  +                                                                             
executionContext,
  +                                                                             
*subQueryResults);
  +
        if(XPathExpression::eOP_PREDICATE == nextStepType ||
           XPathExpression::eOP_PREDICATE_WITH_POSITION == nextStepType)
        {
  @@ -2917,35 +2916,38 @@
        {
                const NodeRefListBase::size_type        nContexts = 
subQueryResults->getLength();
   
  -             for(NodeRefListBase::size_type i = 0; i < nContexts; i++)
  +             if (nContexts > 0)
                {
  -                     XalanNode* const        node = subQueryResults->item(i);
  -                     assert(node != 0);
  +                     for(NodeRefListBase::size_type i = 0; i < nContexts; 
i++)
  +                     {
  +                             XalanNode* const        node = 
subQueryResults->item(i);
  +                             assert(node != 0);
   
  -                     BorrowReturnMutableNodeRefList  mnl(executionContext);
  +                             BorrowReturnMutableNodeRefList  
mnl(executionContext);
   
  -                     step(executionContext, node, opPos, *mnl);
  +                             step(executionContext, node, opPos, *mnl);
   
  -                     if (mnl->empty() == false)
  -                     {
  -                             if(queryResults.empty() == false)
  +                             if (mnl->empty() == false)
                                {
  -                                     queryResults.addNodesInDocOrder(*mnl, 
executionContext);
  +                                     if(queryResults.empty() == false)
  +                                     {
  +                                             
queryResults.addNodesInDocOrder(*mnl, executionContext);
   
  -                                     queryResults.setDocumentOrder();
  -                             }
  -                             else
  -                             {
  -                                     assert(mnl->getDocumentOrder() == true);
  +                                             queryResults.setDocumentOrder();
  +                                     }
  +                                     else
  +                                     {
  +                                             assert(mnl->getDocumentOrder() 
== true);
   
  -                                     queryResults.swap(*mnl);
  +                                             queryResults.swap(*mnl);
  +                                     }
                                }
                        }
  -             }
   
  -             if (queryResults.empty() == true)
  -             {
  -                     queryResults.setDocumentOrder();
  +                     if (queryResults.empty() == true)
  +                     {
  +                             queryResults.setDocumentOrder();
  +                     }
                }
        }
        else
  @@ -3247,68 +3249,48 @@
        {
                score = eMatchScoreOther;
   
  -             // Execute the xpath.predicates, but if we have an index, then 
we have 
  -             // to start over and do a search from the parent.  It would be 
nice 
  -             // if I could sense this condition earlier...
  -#if 0
  -             try
  +             while(XPathExpression::eOP_PREDICATE == nextStepType ||
  +                       XPathExpression::eOP_PREDICATE_WITH_POSITION == 
nextStepType)
                {
  -                     executionContext.setThrowFoundIndex(true);
  -#endif
  -
  -                     while(XPathExpression::eOP_PREDICATE == nextStepType ||
  -                               XPathExpression::eOP_PREDICATE_WITH_POSITION 
== nextStepType)
  +                     // This is a quick hack to look ahead and see if we have
  +                     // number literal as the predicate, i.e. match="foo[1]".
  +                     if (XPathExpression::eOP_PREDICATE_WITH_POSITION == 
nextStepType)
                        {
  -                             // This is a quick hack to look ahead and see 
if we have
  -                             // number literal as the predicate, i.e. 
match="foo[1]".
  -                             if 
(XPathExpression::eOP_PREDICATE_WITH_POSITION == nextStepType)
  +                             if (m_expression.getOpCodeMapValue(opPos + 2) 
== XPathExpression::eOP_NUMBERLIT)
                                {
  -                                     if 
(m_expression.getOpCodeMapValue(opPos + 2) == XPathExpression::eOP_NUMBERLIT)
  -                                     {
  -                                             score = 
handleFoundIndexPositional(
  +                                     score = handleFoundIndexPositional(
                                                        executionContext,
                                                        context,
                                                        startOpPos);
  -                                     }
  -                                     else
  -                                     {
  -                                             score = handleFoundIndex(
  +                             }
  +                             else
  +                             {
  +                                     score = handleFoundIndex(
                                                        executionContext,
                                                        context,
                                                        startOpPos);
  -                                     }
                                }
  -                             else
  -                             {
  -                                     const XObjectPtr        
pred(predicate(context, opPos, executionContext));
  -                                     assert(pred.get() != 0);
  -
  -                                     if(XObject::eTypeNumber == 
pred->getType())
  -                                     {
  -                                             score = 
handleFoundIndex(executionContext, context, startOpPos);
  -                                     }
  -                                     else if(pred->boolean() == false)
  -                                     {
  -                                             score = eMatchScoreNone;
  +                     }
  +                     else
  +                     {
  +                             const XObjectPtr        pred(predicate(context, 
opPos, executionContext));
  +                             assert(pred.get() != 0);
   
  -                                             break;
  -                                     }
  +                             if(XObject::eTypeNumber == pred->getType())
  +                             {
  +                                     score = 
handleFoundIndex(executionContext, context, startOpPos);
                                }
  +                             else if(pred->boolean() == false)
  +                             {
  +                                     score = eMatchScoreNone;
   
  -                             opPos = 
currentExpression.getNextOpCodePosition(opPos);
  -                             nextStepType = 
currentExpression.getOpCodeMapValue(opPos);
  +                                     break;
  +                             }
                        }
   
  -#if 0
  -                     executionContext.setThrowFoundIndex(false);
  +                     opPos = currentExpression.getNextOpCodePosition(opPos);
  +                     nextStepType = 
currentExpression.getOpCodeMapValue(opPos);
                }
  -             catch(const FoundIndex&)
  -             {
  -                     executionContext.setThrowFoundIndex(false);
  -
  -                     score = handleFoundIndex(executionContext, context, 
startOpPos);
  -             }
  -#endif
        }
   
        if (scoreHolder == eMatchScoreNone || 
  @@ -4690,6 +4672,8 @@
                        int                                     opPos,
                        MutableNodeRefList&     subQueryResults) const
   {
  +     assert(&executionContext.getContextNodeList() == &subQueryResults);
  +
        const XPathExpression&  currentExpression = getExpression();
   
        assert(currentExpression.getOpCodeMapValue(opPos) == 
XPathExpression::eOP_PREDICATE ||
  @@ -4789,11 +4773,6 @@
                else
                {
                        theLength = subQueryResults.getLength();
  -
  -                     if(theLength != 0)
  -                     {
  -                             
executionContext.setContextNodeList(subQueryResults);
  -                     }
                }
        }
   
  
  
  
  1.3       +12 -12    xml-xalan/c/src/xalanc/XPath/XPath.hpp
  
  Index: XPath.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/xalanc/XPath/XPath.hpp,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- XPath.hpp 19 Sep 2003 21:05:26 -0000      1.2
  +++ XPath.hpp 5 Nov 2003 22:18:17 -0000       1.3
  @@ -330,8 +330,8 @@
                        const NodeRefListBase&  contextNodeList,
                        XPathExecutionContext&  executionContext) const
        {
  -             // Set and restore the context node list...
  -             XPathExecutionContext::ContextNodeListSetAndRestore             
theSetAndRestore(
  +             // Push and pop the context node list...
  +             XPathExecutionContext::ContextNodeListPushAndPop        
thePushAndPop(
                                                                                
executionContext,
                                                                                
contextNodeList);
   
  @@ -355,8 +355,8 @@
                        XPathExecutionContext&  executionContext,
                        bool&                                   result) const
        {
  -             // Set and restore the context node list...
  -             XPathExecutionContext::ContextNodeListSetAndRestore             
theSetAndRestore(
  +             // Push and pop the context node list...
  +             XPathExecutionContext::ContextNodeListPushAndPop        
thePushAndPop(
                                                                                
executionContext,
                                                                                
contextNodeList);
   
  @@ -380,8 +380,8 @@
                        XPathExecutionContext&  executionContext,
                        double&                                 result) const
        {
  -             // Set and restore the context node list...
  -             XPathExecutionContext::ContextNodeListSetAndRestore             
theSetAndRestore(
  +             // Push and pop the context node list...
  +             XPathExecutionContext::ContextNodeListPushAndPop        
thePushAndPop(
                                                                                
executionContext,
                                                                                
contextNodeList);
   
  @@ -406,8 +406,8 @@
                        XPathExecutionContext&  executionContext,
                        XalanDOMString&                 result) const
        {
  -             // Set and restore the context node list...
  -             XPathExecutionContext::ContextNodeListSetAndRestore             
theSetAndRestore(
  +             // Push and pop the context node list...
  +             XPathExecutionContext::ContextNodeListPushAndPop        
thePushAndPop(
                                                                                
executionContext,
                                                                                
contextNodeList);
   
  @@ -433,8 +433,8 @@
                        FormatterListener&              formatterListener,
                        MemberFunctionPtr               function) const
        {
  -             // Set and restore the context node list...
  -             XPathExecutionContext::ContextNodeListSetAndRestore             
theSetAndRestore(
  +             // Push and pop the context node list...
  +             XPathExecutionContext::ContextNodeListPushAndPop        
thePushAndPop(
                                                                                
executionContext,
                                                                                
contextNodeList);
   
  @@ -469,8 +469,8 @@
                        XPathExecutionContext&  executionContext,
                        MutableNodeRefList&             result) const
        {
  -             // Set and restore the context node list...
  -             XPathExecutionContext::ContextNodeListSetAndRestore             
theSetAndRestore(
  +             // Push and pop the context node list...
  +             XPathExecutionContext::ContextNodeListPushAndPop        
thePushAndPop(
                                                                                
executionContext,
                                                                                
contextNodeList);
   
  
  
  
  1.5       +23 -33    xml-xalan/c/src/xalanc/XPath/XPathExecutionContext.hpp
  
  Index: XPathExecutionContext.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/xalanc/XPath/XPathExecutionContext.hpp,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- XPathExecutionContext.hpp 26 Oct 2003 00:41:04 -0000      1.4
  +++ XPathExecutionContext.hpp 5 Nov 2003 22:18:17 -0000       1.5
  @@ -201,45 +201,49 @@
                        const XalanNode&        node2) const = 0;
   
        /**
  -      * Retrieve node list for current context.
  +      * Push the node list for current context.
         * 
  -      * @return node list
  +      * @param theList new node list
         */
  -     virtual const NodeRefListBase&
  -     getContextNodeList() const = 0;
  +     virtual void
  +     pushContextNodeList(const NodeRefListBase&      theList) = 0;
   
        /**
  -      * Set node list for current context.
  -      * 
  -      * @param theList new node list
  +      * Pop the node list for current context.
         */
        virtual void    
  -     setContextNodeList(const NodeRefListBase&       theList) = 0;
  +     popContextNodeList() = 0;
   
  -     class ContextNodeListSetAndRestore
  +     class ContextNodeListPushAndPop
        {
        public:
   
  -             ContextNodeListSetAndRestore(
  +             ContextNodeListPushAndPop(
                                XPathExecutionContext&          
theExecutionContext,
                                const NodeRefListBase&          theNodeList) :
  -                     m_executionContext(theExecutionContext),
  -                     
m_savedNodeList(theExecutionContext.getContextNodeList())
  +                     m_executionContext(theExecutionContext)
                {
  -                     m_executionContext.setContextNodeList(theNodeList);
  +                     m_executionContext.pushContextNodeList(theNodeList);
                }
   
  -             ~ContextNodeListSetAndRestore()
  +             ~ContextNodeListPushAndPop()
                {
  -                     m_executionContext.setContextNodeList(m_savedNodeList);
  +                     m_executionContext.popContextNodeList();
                }
   
        private:
   
                XPathExecutionContext&  m_executionContext;
  -             const NodeRefListBase&  m_savedNodeList;
        };
   
  +     /**
  +      * Get the node list for current context.
  +      * 
  +      * @return node list
  +      */
  +     virtual const NodeRefListBase&
  +     getContextNodeList() const = 0;
  +
        /*
         * Get the count of nodes in the current context node list.
         *
  @@ -671,25 +675,11 @@
        shouldStripSourceNode(const XalanNode&  node) = 0;
   
        /**
  -      * Tells if FoundIndex should be thrown if index is found. This is an
  -      * optimization for match patterns, and is used internally by the XPath
  -      * engine.
  +      * Get the document associated with the given URI.
         *
  -      * @return true to throw FoundIndex
  +      * @param theURI      document URI
  +      * @return a pointer to the document instance, if any.
         */
  -     virtual bool
  -     getThrowFoundIndex() const = 0;
  -
  -     /**
  -      * Changes whether FoundIndex should be thrown if index is found. This 
is an
  -      * optimization for match patterns, and is used internally by the XPath
  -      * engine.
  -      *
  -      * @param fThrow true to throw FoundIndex
  -      */
  -     virtual void
  -     setThrowFoundIndex(bool         fThrow) = 0;
  -
        virtual XalanDocument*
        getSourceDocument(const XalanDOMString&         theURI) const = 0;
   
  
  
  
  1.4       +31 -52    
xml-xalan/c/src/xalanc/XPath/XPathExecutionContextDefault.cpp
  
  Index: XPathExecutionContextDefault.cpp
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/c/src/xalanc/XPath/XPathExecutionContextDefault.cpp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- XPathExecutionContextDefault.cpp  19 Sep 2003 21:05:26 -0000      1.3
  +++ XPathExecutionContextDefault.cpp  5 Nov 2003 22:18:17 -0000       1.4
  @@ -79,7 +79,6 @@
   
   
   
  -#include "FoundIndex.hpp"
   #include "XObjectFactory.hpp"
   #include "XalanQName.hpp"
   #include "XPathEnvSupport.hpp"
  @@ -105,15 +104,16 @@
        m_xpathEnvSupport(&theXPathEnvSupport),
        m_domSupport(&theDOMSupport),
        m_currentNodeStack(),
  -     m_contextNodeList(theContextNodeList == 0 ? &s_dummyList : 
theContextNodeList),
  +     m_contextNodeListStack(),
        m_prefixResolver(thePrefixResolver),
  -     m_throwFoundIndex(false),
        m_nodeListCache(eNodeListCacheListSize),
        m_stringCache(),
        m_cachedPosition(),
        m_scratchQName()
   {
        m_currentNodeStack.push_back(theCurrentNode);
  +
  +     m_contextNodeListStack.push_back(theContextNodeList == 0 ? &s_dummyList 
: theContextNodeList);
   }
   
   
  @@ -126,15 +126,16 @@
        m_xpathEnvSupport(0),
        m_domSupport(0),
        m_currentNodeStack(),
  -     m_contextNodeList(theContextNodeList == 0 ? &s_dummyList : 
theContextNodeList),
  +     m_contextNodeListStack(),
        m_prefixResolver(thePrefixResolver),
  -     m_throwFoundIndex(false),
        m_nodeListCache(eNodeListCacheListSize),
        m_stringCache(),
        m_cachedPosition(),
        m_scratchQName()
   {
        m_currentNodeStack.push_back(theCurrentNode);
  +
  +     m_contextNodeListStack.push_back(theContextNodeList == 0 ? &s_dummyList 
: theContextNodeList);
   }
   
   
  @@ -166,10 +167,9 @@
        }
   
        m_currentNodeStack.clear();
  +     m_contextNodeListStack.clear();
   
  -     m_contextNodeList = &s_dummyList;
        m_prefixResolver = 0;
  -     m_throwFoundIndex = false;
   
        m_nodeListCache.reset(),
   
  @@ -214,23 +214,32 @@
   
   
   
  -const NodeRefListBase&
  -XPathExecutionContextDefault::getContextNodeList() const
  +void 
  +XPathExecutionContextDefault::pushContextNodeList(const NodeRefListBase&     
theList)
   {
  -     return *m_contextNodeList;
  +     m_cachedPosition.clear();
  +
  +     m_contextNodeListStack.push_back(&theList);
   }
   
   
   
   void 
  -XPathExecutionContextDefault::setContextNodeList(const NodeRefListBase&      
        theList)
  +XPathExecutionContextDefault::popContextNodeList()
   {
  -     if (&theList != m_contextNodeList)
  -     {
  -             m_contextNodeList = &theList;
  +     m_cachedPosition.clear();
   
  -             m_cachedPosition.clear();
  -     }
  +     m_contextNodeListStack.pop_back();
  +}
  +
  +
  +
  +const NodeRefListBase&
  +XPathExecutionContextDefault::getContextNodeList() const
  +{
  +     assert(m_contextNodeListStack.empty() == false);
  +
  +     return *m_contextNodeListStack.back();
   }
   
   
  @@ -238,16 +247,9 @@
   XPathExecutionContextDefault::size_type
   XPathExecutionContextDefault::getContextNodeListLength() const
   {
  -#if 1
  -     assert(m_throwFoundIndex == false);
  -#else
  -     if (m_throwFoundIndex == true)
  -     {
  -             throw FoundIndex();
  -     }
  -#endif
  +     assert(m_contextNodeListStack.empty() == false);
   
  -     return m_contextNodeList->getLength();
  +     return m_contextNodeListStack.back()->getLength();
   }
   
   
  @@ -255,24 +257,17 @@
   XPathExecutionContextDefault::size_type
   XPathExecutionContextDefault::getContextNodeListPosition(const XalanNode&    
contextNode) const
   {
  -#if 1
  -     assert(m_throwFoundIndex == false);
  -#else
  -     if (m_throwFoundIndex == true)
  -     {
  -             throw FoundIndex();
  -     }
  -#endif
  +     assert(m_contextNodeListStack.empty() == false);
   
        if (m_cachedPosition.m_node == &contextNode)
        {
  -             assert((m_cachedPosition.m_index == 0 && 
m_contextNodeList->indexOf(&contextNode) == NodeRefListBase::npos) ||
  -                        (m_contextNodeList->indexOf(&contextNode) + 1 == 
m_cachedPosition.m_index));
  +             assert((m_cachedPosition.m_index == 0 && 
m_contextNodeListStack.back()->indexOf(&contextNode) == NodeRefListBase::npos) 
||
  +                        
(m_contextNodeListStack.back()->indexOf(&contextNode) + 1 == 
m_cachedPosition.m_index));
        }
        else
        {
                // Get the index of the node...
  -             const size_type         theIndex = 
m_contextNodeList->indexOf(&contextNode);
  +             const size_type         theIndex = 
m_contextNodeListStack.back()->indexOf(&contextNode);
   
                // If not found, it's 0.  Otherwise, it's the index + 1
   #if defined(XALAN_NO_MUTABLE)
  @@ -682,22 +677,6 @@
                        const LocatorType*      locator) const
   {
        message(TranscodeFromLocalCodePage(msg), sourceNode, locator);
  -}
  -
  -                     
  -                     
  -bool
  -XPathExecutionContextDefault::getThrowFoundIndex() const
  -{
  -     return m_throwFoundIndex;
  -}
  -
  -
  -
  -void
  -XPathExecutionContextDefault::setThrowFoundIndex(bool        fThrow)
  -{
  -     m_throwFoundIndex = fThrow;
   }
   
   
  
  
  
  1.4       +11 -14    
xml-xalan/c/src/xalanc/XPath/XPathExecutionContextDefault.hpp
  
  Index: XPathExecutionContextDefault.hpp
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/c/src/xalanc/XPath/XPathExecutionContextDefault.hpp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- XPathExecutionContextDefault.hpp  19 Sep 2003 21:05:26 -0000      1.3
  +++ XPathExecutionContextDefault.hpp  5 Nov 2003 22:18:17 -0000       1.4
  @@ -113,9 +113,11 @@
   public:
   
   #if defined(XALAN_NO_STD_NAMESPACE)
  -     typedef deque<XalanNode*>                       CurrentNodeStackType;
  +     typedef deque<XalanNode*>                               
CurrentNodeStackType;
  +     typedef deque<const NodeRefListBase*>   ContextNodeListStackType;
   #else
  -     typedef std::deque<XalanNode*>          CurrentNodeStackType;
  +     typedef std::deque<XalanNode*>                          
CurrentNodeStackType;
  +     typedef std::deque<const NodeRefListBase*>      
ContextNodeListStackType;
   #endif
   
        /**
  @@ -233,11 +235,14 @@
                        const XalanNode&        node1,
                        const XalanNode&        node2) const;
   
  -     virtual const NodeRefListBase&
  -     getContextNodeList() const;
  +     virtual void
  +     pushContextNodeList(const NodeRefListBase&      theList);
   
        virtual void    
  -     setContextNodeList(const NodeRefListBase&       theList);
  +     popContextNodeList();
  +
  +     virtual const NodeRefListBase&
  +     getContextNodeList() const;
   
        virtual size_type
        getContextNodeListLength() const;
  @@ -329,12 +334,6 @@
        virtual bool
        shouldStripSourceNode(const XalanNode&  node);
   
  -     virtual bool
  -     getThrowFoundIndex() const;
  -
  -     virtual void
  -     setThrowFoundIndex(bool         fThrow);
  -
        virtual XalanDocument*
        getSourceDocument(const XalanDOMString&         theURI) const;
   
  @@ -419,11 +418,9 @@
   
        CurrentNodeStackType                                    
m_currentNodeStack;
   
  -     const NodeRefListBase*                                  
m_contextNodeList;
  +     ContextNodeListStackType                                
m_contextNodeListStack;
   
        const PrefixResolver*                                   
m_prefixResolver;
  -
  -     bool                                                                    
m_throwFoundIndex;
   
        XalanDOMString                                                  
m_currentPattern;
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to