You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by db...@apache.org on 2002/04/03 07:13:10 UTC

cvs commit: xml-xalan/c/src/XPath XPath.cpp XPathExpression.cpp XPathExpression.hpp XPathProcessorImpl.cpp XPathProcessorImpl.hpp

dbertoni    02/04/02 21:13:10

  Modified:    c/src/XPath XPath.cpp XPathExpression.cpp
                        XPathExpression.hpp XPathProcessorImpl.cpp
                        XPathProcessorImpl.hpp
  Log:
  Experimental implementation that encodes information about position predicates in match patterns.
  
  Revision  Changes    Path
  1.68      +13 -6     xml-xalan/c/src/XPath/XPath.cpp
  
  Index: XPath.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XPath/XPath.cpp,v
  retrieving revision 1.67
  retrieving revision 1.68
  diff -u -r1.67 -r1.68
  --- XPath.cpp	4 Jan 2002 17:29:07 -0000	1.67
  +++ XPath.cpp	3 Apr 2002 05:13:09 -0000	1.68
  @@ -391,6 +391,7 @@
   			const int	nextOp = m_expression.m_opMap[nextStepPos];
   
   			if(nextOp == XPathExpression::eOP_PREDICATE ||
  +			   nextOp == XPathExpression::eOP_PREDICATE_WITH_POSITION ||
   			   nextOp == XPathExpression::eENDOP)
   			{
   				const int	stepType = m_expression.m_opMap[opPos];
  @@ -1270,7 +1271,8 @@
   
   	int		nextStepType = currentExpression.getOpCodeMapValue(opPos);
   
  -	if(XPathExpression::eOP_PREDICATE == nextStepType)
  +	if(XPathExpression::eOP_PREDICATE == nextStepType ||
  +	   XPathExpression::eOP_PREDICATE_WITH_POSITION == nextStepType)
   	{
   		predicates(executionContext,
   				   context,
  @@ -1631,7 +1633,8 @@
   
   	nextStepType = currentExpression.getOpCodeMapValue(opPos);
   
  -	if(score != eMatchScoreNone && XPathExpression::eOP_PREDICATE == nextStepType)
  +	if(score != eMatchScoreNone &&
  +	   (XPathExpression::eOP_PREDICATE == nextStepType || XPathExpression::eOP_PREDICATE_WITH_POSITION == nextStepType))
   	{
   		score = eMatchScoreOther;
   
  @@ -1642,11 +1645,13 @@
   		{
   			executionContext.setThrowFoundIndex(true);
   
  -			while(XPathExpression::eOP_PREDICATE == nextStepType)
  +			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 (m_expression.getOpCodeMapValue(opPos + 2) == XPathExpression::eOP_NUMBERLIT)
  +				if (m_expression.getOpCodeMapValue(opPos + 2) == XPathExpression::eOP_NUMBERLIT,
  +					XPathExpression::eOP_PREDICATE_WITH_POSITION == nextStepType)
   				{
   					score = handleFoundIndex(executionContext, context, startOpPos);
   				}
  @@ -2923,7 +2928,8 @@
   	int 	nextStepType =
   			currentExpression.getOpCodeMapValue(opPos);
   
  -	while(XPathExpression::eOP_PREDICATE == nextStepType)
  +	while(XPathExpression::eOP_PREDICATE == nextStepType ||
  +		  XPathExpression::eOP_PREDICATE_WITH_POSITION == nextStepType)
   	{
   		const NodeRefListBase::size_type	theLength = subQueryResults.getLength();
   
  @@ -3007,7 +3013,8 @@
   
   		nextStepType = currentExpression.getOpCodeMapValue(opPos);
   
  -		if(XPathExpression::eOP_PREDICATE == nextStepType)
  +		if(XPathExpression::eOP_PREDICATE == nextStepType ||
  +		   XPathExpression::eOP_PREDICATE_WITH_POSITION == nextStepType)
   		{
   			executionContext.setContextNodeList(subQueryResults);
   		}
  
  
  
  1.34      +22 -1     xml-xalan/c/src/XPath/XPathExpression.cpp
  
  Index: XPathExpression.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XPath/XPathExpression.cpp,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- XPathExpression.cpp	4 Jan 2002 17:29:07 -0000	1.33
  +++ XPathExpression.cpp	3 Apr 2002 05:13:09 -0000	1.34
  @@ -166,7 +166,8 @@
   	XPathExpression::s_opCodeMapLengthIndex + 1,
   	XPathExpression::s_opCodeMapLengthIndex + 1,
   	XPathExpression::s_opCodeMapLengthIndex + 2,
  -	XPathExpression::s_opCodeMapLengthIndex + 2
  +	XPathExpression::s_opCodeMapLengthIndex + 2,
  +	XPathExpression::s_opCodeMapLengthIndex + 1
   };
   
   static const int	theOpCodeLengthArraySize =
  @@ -537,6 +538,26 @@
   	}
   
   	assert(opCodeMapSize() == OpCodeMapSizeType(opCodeMapLength()));
  +}
  +
  +
  +
  +void
  +XPathExpression::replaceOpCode(
  +			OpCodeMapSizeType	theIndex,
  +			eOpCodes			theOldOpCode,
  +			eOpCodes			theNewOpCode)
  +{
  +	if (theIndex >= m_opMap.size() ||
  +		m_opMap[theIndex] != theOldOpCode ||
  +		getOpCodeLength(theOldOpCode) != getOpCodeLength(theNewOpCode))
  +	{
  +		throw InvalidOpCodeException(theNewOpCode);
  +	}
  +	else
  +	{
  +		m_opMap[theIndex] = theNewOpCode;
  +	}
   }
   
   
  
  
  
  1.26      +25 -1     xml-xalan/c/src/XPath/XPathExpression.hpp
  
  Index: XPathExpression.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XPath/XPathExpression.hpp,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- XPathExpression.hpp	4 Jan 2002 17:29:07 -0000	1.25
  +++ XPathExpression.hpp	3 Apr 2002 05:13:09 -0000	1.26
  @@ -438,7 +438,7 @@
   		 *	XBoolean or XNumber
   		 */
   		eOP_PREDICATE = 26,
  -  
  +
   		/**
   		 * [NODETYPE_COMMENT]
   		 * No size or arguments.
  @@ -555,6 +555,17 @@
   		eMATCH_ANY_ANCESTOR_WITH_PREDICATE = 53,
   		eMATCH_ANY_ANCESTOR_WITH_FUNCTION_CALL = 54,
   
  +		/**
  +		 * [OP_PREDICATE_WITH_POSITION]
  +		 * [length]
  +		 *	{expression}
  +		 * [ENDOP] (For safety)
  +		 * 
  +		 * returns: 
  +		 *	XBoolean or XNumber
  +		 */
  +		eOP_PREDICATE_WITH_POSITION = 55,
  +  
   		// Always add _before_ this one and update
   		// s_opCodeLengthArray.
   		eOpCodeNextAvailable
  @@ -896,6 +907,19 @@
   					  m_lastOpCodeIndex,
   					  theArgs);
   	}
  +
  +	/**
  +	 * Replace an operation code with supplied code.
  +	 * 
  +	 * @param theIndex  The index of the old operation code
  +	 * @param theOldOpCode The old operation code
  +	 * @param theNewOpCode The new operation code
  +	 */
  +	void
  +	replaceOpCode(
  +			OpCodeMapSizeType	theIndex,
  +			eOpCodes			theOldOpCode,
  +			eOpCodes			theNewOpCode);
   
   	/**
   	 * Insert an operation code at a specified index in the list.
  
  
  
  1.52      +34 -13    xml-xalan/c/src/XPath/XPathProcessorImpl.cpp
  
  Index: XPathProcessorImpl.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XPath/XPathProcessorImpl.cpp,v
  retrieving revision 1.51
  retrieving revision 1.52
  diff -u -r1.51 -r1.52
  --- XPathProcessorImpl.cpp	8 Mar 2002 05:11:31 -0000	1.51
  +++ XPathProcessorImpl.cpp	3 Apr 2002 05:13:10 -0000	1.52
  @@ -91,7 +91,8 @@
   	m_xpath(0),
   	m_expression(0),
   	m_prefixResolver(0),
  -	m_requireLiterals(false)
  +	m_requireLiterals(false),
  +	m_positionPredicateStack()
   {
   }
   
  @@ -139,6 +140,7 @@
   	m_expression = 0;
   	m_prefixResolver = 0;
   	m_locator = 0;
  +	m_positionPredicateStack.clear();
   }
   
   
  @@ -210,6 +212,7 @@
   		m_expression = 0;
   		m_prefixResolver = 0;
   		m_locator = 0;
  +		m_positionPredicateStack.clear();
   	}
   }
   
  @@ -1579,16 +1582,6 @@
   		m_expression->updateOpCodeLength(XPathExpression::eOP_LOCATIONPATH,
   										 opPos);
   	}
  -
  -	/*
  -	if(tokenIs(XalanUnicode::charLeftSquareBracket) == true)
  -	{
  -		Predicate();
  -
  -		m_expression->updateOpCodeLength(XPathExpression::eOP_LOCATIONPATH,
  -										 opPos);
  -	}  
  -	*/
   }
     
   
  @@ -1779,6 +1772,16 @@
   				int		theFunctionID =
   					XPath::getFunctionTable().nameToID(m_token);
   
  +				// This code is disabled for the time being, as
  +				// it needs more testing.
  +#if 0
  +				if (equals(m_token, s_positionString) == true &&
  +					m_positionPredicateStack.empty() == false)
  +				{
  +					m_positionPredicateStack.back() = true;
  +				}
  +#endif
  +
   				XPathExpression::OpCodeMapValueVectorType	theArgs(2, 0);
   		
   				theArgs[0] = theFunctionID;
  @@ -2142,6 +2145,8 @@
   
   	m_expression->appendOpCode(XPathExpression::eOP_PREDICATE);
   
  +	m_positionPredicateStack.push_back(false);
  +
   	Expr();
   
   	// Terminate for safety.
  @@ -2149,6 +2154,18 @@
   
   	m_expression->updateOpCodeLength(XPathExpression::eOP_PREDICATE,
   									 opPos);
  +
  +	assert(m_positionPredicateStack.empty() == false);
  +
  +	if (m_positionPredicateStack.back() == true)
  +	{
  +		m_expression->replaceOpCode(
  +			opPos,
  +			XPathExpression::eOP_PREDICATE,
  +			XPathExpression::eOP_PREDICATE_WITH_POSITION);
  +	}
  +
  +	m_positionPredicateStack.pop_back();
   }
   
   
  @@ -2271,8 +2288,6 @@
   
   	m_expression->appendOpCode(XPathExpression::eOP_LOCATIONPATHPATTERN);
   
  -	// These token s_functionKeyString should not be here, as it is really
  -	// part of the XSLT standard, and not the XPATH standard.
   	if(lookahead(XalanUnicode::charLeftParenthesis, 1) == true &&
   				(tokenIs(s_functionIDString) == true ||
   				 tokenIs(s_functionKeyString) == true))
  @@ -2653,6 +2668,8 @@
   
   static XalanDOMString	s_childString;
   
  +static XalanDOMString	s_positionString;
  +
   
   
   const XalanDOMString	XPathProcessorImpl::s_emptyString;
  @@ -2684,6 +2701,8 @@
   
   const XalanDOMString&	XPathProcessorImpl::s_childString = ::s_childString;
   
  +const XalanDOMString&	XPathProcessorImpl::s_positionString = ::s_positionString;
  +
   
   
   static XPathProcessorImpl::KeywordsMapType 		s_keywords;
  @@ -2719,6 +2738,7 @@
   	::s_axisString = XALAN_STATIC_UCODE_STRING("::");
   	::s_attributeString = XALAN_STATIC_UCODE_STRING("attribute");
   	::s_childString = XALAN_STATIC_UCODE_STRING("child");
  +	::s_positionString = XALAN_STATIC_UCODE_STRING("position");
   }
   
   
  @@ -2742,4 +2762,5 @@
   	releaseMemory(::s_axisString);
   	releaseMemory(::s_attributeString);
   	releaseMemory(::s_childString);
  +	releaseMemory(::s_positionString);
   }
  
  
  
  1.19      +8 -0      xml-xalan/c/src/XPath/XPathProcessorImpl.hpp
  
  Index: XPathProcessorImpl.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XPath/XPathProcessorImpl.hpp,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- XPathProcessorImpl.hpp	26 Nov 2001 23:16:02 -0000	1.18
  +++ XPathProcessorImpl.hpp	3 Apr 2002 05:13:10 -0000	1.19
  @@ -109,6 +109,8 @@
   				less<XalanDOMString> >		NodeTypesMapType;
   
   	typedef vector<XalanDOMString>			DOMStringVectorType;
  +
  +	typedef vector<bool>					BoolVectorType;
   #else
   	typedef std::map<XalanDOMString,
   					 int>							KeywordsMapType;
  @@ -120,6 +122,8 @@
   					 XPathExpression::eOpCodes>		NodeTypesMapType;
   
   	typedef std::vector<XalanDOMString>				DOMStringVectorType;
  +
  +	typedef std::vector<bool>						BoolVectorType;
   #endif
   
   	/**
  @@ -819,6 +823,8 @@
   
   	const Locator*					m_locator;
   
  +	BoolVectorType					m_positionPredicateStack;
  +
   	enum eDummy
   	{
   		TARGETEXTRA = 10000
  @@ -853,6 +859,8 @@
   	static const XalanDOMString&	s_attributeString;
   
   	static const XalanDOMString&	s_childString;
  +
  +	static const XalanDOMString&	s_positionString;
   
   	/**
   	 * Map of keyword names to token values.
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org