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 2004/02/11 07:53:49 UTC

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

dbertoni    2004/02/10 22:53:49

  Modified:    c/src/xalanc/XPath XPathExpression.cpp XPathExpression.hpp
                        XPathProcessorImpl.cpp
  Log:
  General cleanup to prepare for op map iterators.
  
  Revision  Changes    Path
  1.8       +13 -39    xml-xalan/c/src/xalanc/XPath/XPathExpression.cpp
  
  Index: XPathExpression.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/xalanc/XPath/XPathExpression.cpp,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- XPathExpression.cpp	11 Feb 2004 01:08:30 -0000	1.7
  +++ XPathExpression.cpp	11 Feb 2004 06:53:49 -0000	1.8
  @@ -235,7 +235,7 @@
   
   
   
  -XPathExpression::InvalidOpCodeException::InvalidOpCodeException(int		theOpCode) :
  +XPathExpression::InvalidOpCodeException::InvalidOpCodeException(OpCodeMapValueType	theOpCode) :
   	XPathExpressionException(FormatErrorMessage(theOpCode))
   {
   }
  @@ -249,7 +249,7 @@
   
   
   XalanDOMString
  -XPathExpression::InvalidOpCodeException::FormatErrorMessage(int		theOpCode)
  +XPathExpression::InvalidOpCodeException::FormatErrorMessage(OpCodeMapValueType  theOpCode)
   {
   	XalanDOMString	theOpcode; 
   
  @@ -261,9 +261,9 @@
   
   
   XPathExpression::InvalidArgumentCountException::InvalidArgumentCountException(
  -			int		theOpCode,
  -			int		theExpectedCount,
  -			int		theSuppliedCount) :
  +			OpCodeMapValueType	theOpCode,
  +			OpCodeMapValueType	theExpectedCount,
  +			OpCodeMapValueType	theSuppliedCount) :
   	XPathExpressionException(FormatErrorMessage(theOpCode, theExpectedCount, theSuppliedCount))
   {
   }
  @@ -278,9 +278,9 @@
   
   XalanDOMString
   XPathExpression::InvalidArgumentCountException::FormatErrorMessage(
  -			int		theOpCode,
  -			int		theExpectedCount,
  -			int		theSuppliedCount)
  +			OpCodeMapValueType	theOpCode,
  +			OpCodeMapValueType	theExpectedCount,
  +			OpCodeMapValueType	theSuppliedCount)
   {
   	XalanDOMString	theResult;
   
  @@ -299,8 +299,8 @@
   
   
   XPathExpression::InvalidArgumentException::InvalidArgumentException(
  -			int	theOpCode,
  -			int	theValue) :
  +			OpCodeMapValueType	theOpCode,
  +			OpCodeMapValueType	theValue) :
   	XPathExpressionException(FormatErrorMessage(theOpCode, theValue))
   {
   }
  @@ -315,8 +315,8 @@
   
   XalanDOMString
   XPathExpression::InvalidArgumentException::FormatErrorMessage(
  -				int		theOpCode,
  -				int		theValue)
  +				OpCodeMapValueType	theOpCode,
  +				OpCodeMapValueType	theValue)
   {
   	XalanDOMString	theResult; 
   
  @@ -324,35 +324,9 @@
   
   	
   	XalanDOMString	theResult1;
  -	LongToDOMString(theOpCode, theResult1);
  -
  +	UnsignedLongToDOMString(theOpCode, theResult1);
   
   	return XalanMessageLoader::getMessage(XalanMessages::InvalidNumberOfArgsWasSupplied_2Param, theResult, theResult1) ;
  -}
  -
  -
  -
  -XPathExpression::InvalidRelativeTokenPosition::InvalidRelativeTokenPosition(int		theOffset) :
  -	XPathExpressionException(FormatErrorMessage(theOffset))
  -{
  -}
  -
  -
  -
  -XPathExpression::InvalidRelativeTokenPosition::~InvalidRelativeTokenPosition()
  -{
  -}
  -
  -
  -
  -XalanDOMString
  -XPathExpression::InvalidRelativeTokenPosition::FormatErrorMessage(int	theOffset)
  -{
  -	XalanDOMString	theResult; 
  -
  -	LongToDOMString(theOffset, theResult);
  -
  -	return XalanMessageLoader::getMessage(XalanMessages::InvalidOffsetWasSupplied_1Param, theResult);
   }
   
   
  
  
  
  1.6       +86 -97    xml-xalan/c/src/xalanc/XPath/XPathExpression.hpp
  
  Index: XPathExpression.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/xalanc/XPath/XPathExpression.hpp,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- XPathExpression.hpp	11 Feb 2004 01:08:30 -0000	1.5
  +++ XPathExpression.hpp	11 Feb 2004 06:53:49 -0000	1.6
  @@ -97,11 +97,34 @@
   public:
   
   #if defined(XALAN_NO_STD_NAMESPACE)
  -	typedef ostream			OstreamType;
  +	typedef ostream			                OstreamType;
  +
  +    typedef vector<int>						OpCodeMapType;
  +	typedef vector<XToken>					TokenQueueType;
  +
  +	typedef OpCodeMapType::value_type		OpCodeMapValueType;
  +	typedef OpCodeMapValueType		        OpCodeMapSizeType;
  +
  +	typedef vector<OpCodeMapValueType>		OpCodeMapValueVectorType;
  +
  +	typedef vector<double>					NumberLiteralValueVectorType;
   #else
  -	typedef std::ostream	OstreamType;
  +	typedef std::ostream	                OstreamType;
  +
  +    typedef std::vector<int>				OpCodeMapType;
  +	typedef std::vector<XToken>				TokenQueueType;
  +
  +	typedef OpCodeMapType::value_type		OpCodeMapValueType;
  +	typedef OpCodeMapValueType		        OpCodeMapSizeType;
  +
  +	typedef std::vector<OpCodeMapValueType> OpCodeMapValueVectorType;
  +
  +	typedef std::vector<double>				NumberLiteralValueVectorType;
   #endif
   
  +	typedef TokenQueueType::value_type		TokenQueueValueType;
  +	typedef int		                        TokenQueueSizeType;
  +
   	/**
   	 * List of operations codes.
   	 *
  @@ -641,7 +664,7 @@
   		 * 
   		 * @param theOpCode operation code that caused the exception
   		 */
  -		InvalidOpCodeException(int	theOpCode);
  +		InvalidOpCodeException(OpCodeMapValueType	theOpCode);
   
   		virtual~
   		InvalidOpCodeException();
  @@ -649,7 +672,7 @@
   	private:
   
   		static XalanDOMString
  -		FormatErrorMessage(int	theOpCode);
  +		FormatErrorMessage(OpCodeMapValueType	theOpCode);
   	};
   
   	/**
  @@ -668,9 +691,9 @@
   		 * @param theSuppliedCount the number of arguments supplied
   		 */
   		InvalidArgumentCountException(
  -			int		theOpCode,
  -			int		theExpectedCount,
  -			int		theSuppliedCount);
  +			OpCodeMapValueType	theOpCode,
  +			OpCodeMapValueType	theExpectedCount,
  +			OpCodeMapValueType	theSuppliedCount);
   
   		virtual~
   		InvalidArgumentCountException();
  @@ -679,9 +702,9 @@
   
   		static XalanDOMString
   		FormatErrorMessage(
  -			int		theOpCode,
  -			int		theExpectedCount,
  -			int		theSuppliedCount);
  +			OpCodeMapValueType	theOpCode,
  +			OpCodeMapValueType	theExpectedCount,
  +			OpCodeMapValueType	theSuppliedCount);
   	};
   
   	/**
  @@ -698,8 +721,8 @@
   		 * @param theValue invalid argument value
   		 */
   		InvalidArgumentException(
  -			int	theOpCode,
  -			int	theValue);
  +			OpCodeMapValueType	theOpCode,
  +			OpCodeMapValueType	theValue);
   
   		virtual~
   		InvalidArgumentException();
  @@ -708,60 +731,12 @@
   
   		static XalanDOMString
   		FormatErrorMessage(
  -				int		theOpCode,
  -				int		theValue);
  +				OpCodeMapValueType	theOpCode,
  +				OpCodeMapValueType	theValue);
   	};
   
  -	/**
  -	 * Exception class thrown when an invalid token position is encountered
  -	 */
  -	class XALAN_XPATH_EXPORT InvalidRelativeTokenPosition : public XPathExpressionException
  -	{
  -	public:
   
  -		/**
  -		 * Construct an InvalidRelativeTokenPosition object.
  -		 * 
  -		 * @param theOffset the offset that caused the problem.
  -		 */
  -		InvalidRelativeTokenPosition(int	theOffset);
  -
  -		virtual~
  -		InvalidRelativeTokenPosition();
  -
  -	private:
  -
  -		static XalanDOMString
  -		FormatErrorMessage(int	theOffset);
  -	};
  -
  -
  -#if defined(XALAN_NO_STD_NAMESPACE)
  -	typedef vector<int>						OpCodeMapType;
  -	typedef vector<XToken>					TokenQueueType;
  -
  -	typedef OpCodeMapType::value_type		OpCodeMapValueType;
  -	typedef OpCodeMapValueType		        OpCodeMapSizeType;
  -
  -	typedef vector<OpCodeMapValueType>		OpCodeMapValueVectorType;
  -
  -	typedef vector<double>					NumberLiteralValueVectorType;
  -#else
  -	typedef std::vector<int>				OpCodeMapType;
  -	typedef std::vector<XToken>				TokenQueueType;
  -
  -	typedef OpCodeMapType::value_type		OpCodeMapValueType;
  -	typedef OpCodeMapValueType		        OpCodeMapSizeType;
  -
  -	typedef std::vector<OpCodeMapValueType> OpCodeMapValueVectorType;
  -
  -	typedef std::vector<double>				NumberLiteralValueVectorType;
  -#endif
  -
  -	typedef TokenQueueType::value_type		TokenQueueValueType;
  -	typedef int		                        TokenQueueSizeType;
  -
  -	/**
  +    /**
   	 * The length is always the opcode position + 1. Length is always expressed
   	 * as the opcode+length bytes, so it is always 2 or greater.  This is the
   	 * offset from the op code where the length is stored.  It will always
  @@ -1120,20 +1095,29 @@
   		}
   	}
   
  +    enum eRelativeDirection
  +    {
  +        eRelativeBackward,
  +        eRelativeForward
  +    };
  +
   	/**
   	 * Retrieve a token at the specified offset relative to the current
   	 * position in the token queue.
   	 * 
   	 * @param theOffset offset from current position
  +     * @param theDirection the direction in which to move
   	 * @return pointer to XObject token
   	 */
   	const XToken*
  -	getRelativeToken(int	theOffset) const
  +	getRelativeToken(
  +        TokenQueueSizeType	theOffset,
  +        eRelativeDirection  theDirection) const
   	{
  -		const int	thePosition = int(m_currentPosition) + theOffset;
  +		const TokenQueueSizeType	thePosition =
  +            calculateRelativePosition(theOffset, theDirection);
   
  -		if (thePosition < 0 ||
  -			thePosition >= int(tokenQueueSize()))
  +		if (thePosition == tokenQueueSize())
   		{
   			return 0;
   		}
  @@ -1199,42 +1183,17 @@
   	 * Replace a token in the token queue.
   	 * 
   	 * @param theOffset the offset at which to replace the token.
  -	 * @param theToken The new token
  -	 */
  -	void
  -	replaceRelativeToken(
  -			int				theOffset,
  -			const XToken&	theToken)
  -	{
  -		const int	thePosition = int(m_currentPosition) + theOffset;
  -
  -		if (thePosition < 0 ||
  -			thePosition >= int(tokenQueueSize()))
  -		{
  -			throw InvalidRelativeTokenPosition(theOffset);
  -		}
  -
  -		m_tokenQueue[thePosition] = theToken;
  -	}
  -
  -	/**
  -	 * Replace a token in the token queue.
  -	 * 
  -	 * @param theOffset the offset at which to replace the token.
   	 * @param theString The string data for the token.  The instance will keep a pointer to this string, so it must be persistent.
   	 */
   	void
   	replaceRelativeToken(
  -			int						theOffset,
  +            TokenQueueSizeType	    theOffset,
  +            eRelativeDirection      theDirection,
   			const XalanDOMString&	theString)
   	{
  -		const int	thePosition = int(m_currentPosition) + theOffset;
  -
  -		if (thePosition < 0 ||
  -			thePosition >= int(tokenQueueSize()))
  -		{
  -			throw InvalidRelativeTokenPosition(theOffset);
  -		}
  +		const TokenQueueSizeType	thePosition =
  +            calculateRelativePosition(theOffset, theDirection);
  +        assert(thePosition < tokenQueueSize());
   
   		m_tokenQueue[thePosition].set(theString);
   	}
  @@ -1402,6 +1361,36 @@
   private:
   
   	/**
  +	 * Calculate the relative token position given the offset
  +	 * and direction.  Returns the size of the token queue
  +	 * if the offset is not valid.
  +     *
  +	 * @param theOffset offset from current position
  +     * @param theDirection the direction in which to move
  +	 * @return thePosition
  +	 */
  +	TokenQueueSizeType
  +	calculateRelativePosition(
  +        TokenQueueSizeType	theOffset,
  +        eRelativeDirection  theDirection) const
  +	{
  +        if (theDirection == eRelativeBackward &&
  +            theOffset <= m_currentPosition)
  +        {
  +            return m_currentPosition - theOffset;
  +        }
  +        else if (theDirection == eRelativeForward &&
  +                 m_currentPosition + theOffset < tokenQueueSize())
  +        {
  +            return m_currentPosition + theOffset;
  +        }
  +        else
  +        {
  +            return tokenQueueSize();
  +        }
  +    }
  +
  +    /**
   	 * An operations map is used instead of a proper parse tree.  It contains
   	 * operations codes and indexes into the m_tokenQueue. We use an array
   	 * instead of a full parse tree in order to cut down on the number of
  
  
  
  1.7       +18 -3     xml-xalan/c/src/xalanc/XPath/XPathProcessorImpl.cpp
  
  Index: XPathProcessorImpl.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/xalanc/XPath/XPathProcessorImpl.cpp,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- XPathProcessorImpl.cpp	11 Feb 2004 01:08:30 -0000	1.6
  +++ XPathProcessorImpl.cpp	11 Feb 2004 06:53:49 -0000	1.7
  @@ -507,7 +507,8 @@
   	assert(theNamespaceURI != 0 && theNamespaceURI->empty() == false);
   
   	m_expression->replaceRelativeToken(
  -			-1,
  +			1,
  +            XPathExpression::eRelativeBackward,
   			m_constructionContext->getPooledString(*theNamespaceURI));
   }
   
  @@ -745,8 +746,22 @@
   {
   	assert(m_expression != 0);
   
  -	const XObject* const	theToken =
  -		m_expression->getRelativeToken(theOffset);
  +    const XObject*  theToken = 0;
  +
  +    if (theOffset < 0)
  +    {
  +        theToken = 
  +            m_expression->getRelativeToken(
  +                    XPathExpression::TokenQueueSizeType(-theOffset),
  +                    XPathExpression::eRelativeBackward);
  +    }
  +    else
  +    {
  +        theToken =
  +            m_expression->getRelativeToken(
  +                    XPathExpression::TokenQueueSizeType(theOffset),
  +                    XPathExpression::eRelativeForward);
  +    }
   
   	return theToken == 0 ? s_emptyString : theToken->str();
   }
  
  
  

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