Return-Path: Delivered-To: apmail-poi-commits-archive@locus.apache.org Received: (qmail 35358 invoked from network); 30 Aug 2008 04:34:53 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 30 Aug 2008 04:34:53 -0000 Received: (qmail 27675 invoked by uid 500); 30 Aug 2008 04:34:51 -0000 Delivered-To: apmail-poi-commits-archive@poi.apache.org Received: (qmail 27639 invoked by uid 500); 30 Aug 2008 04:34:51 -0000 Mailing-List: contact commits-help@poi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@poi.apache.org Delivered-To: mailing list commits@poi.apache.org Received: (qmail 27630 invoked by uid 99); 30 Aug 2008 04:34:51 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 29 Aug 2008 21:34:51 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 30 Aug 2008 04:34:01 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 5FBB02388986; Fri, 29 Aug 2008 21:34:02 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r690461 - in /poi/trunk/src: java/org/apache/poi/hssf/record/formula/Ptg.java testcases/org/apache/poi/hssf/record/formula/TestArrayPtg.java Date: Sat, 30 Aug 2008 04:34:02 -0000 To: commits@poi.apache.org From: josh@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080830043402.5FBB02388986@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: josh Date: Fri Aug 29 21:34:01 2008 New Revision: 690461 URL: http://svn.apache.org/viewvc?rev=690461&view=rev Log: Fixed decoding of operand class for ArrayPtg Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/Ptg.java poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/TestArrayPtg.java Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/Ptg.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/Ptg.java?rev=690461&r1=690460&r2=690461&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/record/formula/Ptg.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/Ptg.java Fri Aug 29 21:34:01 2008 @@ -43,58 +43,6 @@ public abstract class Ptg implements Cloneable { public static final Ptg[] EMPTY_PTG_ARRAY = { }; - /* convert infix order ptg list to rpn order ptg list - * @return List ptgs in RPN order - * @param infixPtgs List of ptgs in infix order - */ - - /* DO NOT REMOVE - *we keep this method in case we wish to change the way we parse - *It needs a getPrecedence in OperationsPtg - - public static List ptgsToRpn(List infixPtgs) { - java.util.Stack operands = new java.util.Stack(); - java.util.List retval = new java.util.Stack(); - - java.util.ListIterator i = infixPtgs.listIterator(); - Object p; - OperationPtg o ; - boolean weHaveABracket = false; - while (i.hasNext()) { - p=i.next(); - if (p instanceof OperationPtg) { - if (p instanceof ParenthesisPtg) { - if (!weHaveABracket) { - operands.push(p); - weHaveABracket = true; - } else { - o = (OperationPtg) operands.pop(); - while (!(o instanceof ParenthesisPtg)) { - retval.add(o); - } - weHaveABracket = false; - } - } else { - - while (!operands.isEmpty() && ((OperationPtg) operands.peek()).getPrecedence() >= ((OperationPtg) p).getPrecedence() ) { //TODO handle ^ since it is right associative - retval.add(operands.pop()); - } - operands.push(p); - } - } else { - retval.add(p); - } - } - while (!operands.isEmpty()) { - if (operands.peek() instanceof ParenthesisPtg ){ - //throw some error - } else { - retval.add(operands.pop()); - } - } - return retval; - } - */ /** * Reads size bytes of the input stream, to create an array of Ptgs. @@ -145,15 +93,15 @@ Ptg retval = createClassifiedPtg(id, in); - if (id > 0x60) { + if (id >= 0x60) { retval.setClass(CLASS_ARRAY); - } else if (id > 0x40) { + } else if (id >= 0x40) { retval.setClass(CLASS_VALUE); } else { retval.setClass(CLASS_REF); } - return retval; + return retval; } private static Ptg createClassifiedPtg(byte id, RecordInputStream in) { @@ -396,6 +344,22 @@ public final byte getPtgClass() { return ptgClass; } + + /** + * Debug / diagnostic method to get this token's 'operand class' type. + * @return 'R' for 'reference', 'V' for 'value', 'A' for 'array' and '.' for base tokens + */ + public final char getRVAType() { + if (isBaseToken()) { + return '.'; + } + switch (ptgClass) { + case Ptg.CLASS_REF: return 'R'; + case Ptg.CLASS_VALUE: return 'V'; + case Ptg.CLASS_ARRAY: return 'A'; + } + throw new RuntimeException("Unknown operand class (" + ptgClass + ")"); + } public abstract byte getDefaultOperandClass(); Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/TestArrayPtg.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/TestArrayPtg.java?rev=690461&r1=690460&r2=690461&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/TestArrayPtg.java (original) +++ poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/TestArrayPtg.java Fri Aug 29 21:34:01 2008 @@ -20,6 +20,7 @@ import java.util.Arrays; import org.apache.poi.hssf.HSSFTestDataSamples; +import org.apache.poi.hssf.record.RecordInputStream; import org.apache.poi.hssf.record.TestcaseRecordInputStream; import org.apache.poi.hssf.record.UnicodeString; import org.apache.poi.hssf.usermodel.HSSFWorkbook; @@ -128,4 +129,28 @@ } assertEquals("{TRUE,\"ABCD\";\"E\",0.0;FALSE,\"FG\"}", actualFormula); } + + /** + * worth checking since AttrPtg.sid=0x20 and Ptg.CLASS_* = (0x00, 0x20, and 0x40) + */ + public void testOperandClassDecoding() { + confirmOperandClassDecoding(Ptg.CLASS_REF); + confirmOperandClassDecoding(Ptg.CLASS_VALUE); + confirmOperandClassDecoding(Ptg.CLASS_ARRAY); + } + + private static void confirmOperandClassDecoding(byte operandClass) { + byte[] fullData = new byte[ENCODED_PTG_DATA.length + ENCODED_CONSTANT_DATA.length]; + System.arraycopy(ENCODED_PTG_DATA, 0, fullData, 0, ENCODED_PTG_DATA.length); + System.arraycopy(ENCODED_CONSTANT_DATA, 0, fullData, ENCODED_PTG_DATA.length, ENCODED_CONSTANT_DATA.length); + + // Force encoded operand class for tArray + fullData[0] = (byte) (ArrayPtg.sid + operandClass); + + RecordInputStream in = new TestcaseRecordInputStream(ArrayPtg.sid, fullData); + + Ptg[] ptgs = Ptg.readTokens(ENCODED_PTG_DATA.length, in); + ArrayPtg aPtg = (ArrayPtg) ptgs[0]; + assertEquals(operandClass, aPtg.getPtgClass()); + } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org For additional commands, e-mail: commits-help@poi.apache.org