You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by sa...@apache.org on 2002/06/26 23:25:35 UTC

cvs commit: xml-xalan/java/src/org/apache/xalan/xsltc/compiler ElementAvailableCall.java Expression.java FunctionAvailableCall.java If.java LogicalExpr.java When.java

santiagopg    2002/06/26 14:25:35

  Modified:    java/src/org/apache/xalan/xsltc/compiler
                        ElementAvailableCall.java Expression.java
                        FunctionAvailableCall.java If.java LogicalExpr.java
                        When.java
  Log:
  Added support for function-available()/element-available() in logical
  expressions (note that these functions are resolved at compile time
  in XSLTC).
  
  Revision  Changes    Path
  1.6       +10 -1     xml-xalan/java/src/org/apache/xalan/xsltc/compiler/ElementAvailableCall.java
  
  Index: ElementAvailableCall.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/ElementAvailableCall.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ElementAvailableCall.java	24 Apr 2002 17:03:15 -0000	1.5
  +++ ElementAvailableCall.java	26 Jun 2002 21:25:35 -0000	1.6
  @@ -88,6 +88,15 @@
       }
   
       /**
  +     * Returns an object representing the compile-time evaluation 
  +     * of an expression. We are only using this for function-available
  +     * and element-available at this time.
  +     */
  +    public Object evaluateAtCompileTime() {
  +	return getResult() ? Boolean.TRUE : Boolean.FALSE;
  +    }
  +
  +    /**
        * Returns the result that this function will return
        */
       public boolean getResult() {
  
  
  
  1.13      +10 -1     xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Expression.java
  
  Index: Expression.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Expression.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- Expression.java	24 Apr 2002 17:03:15 -0000	1.12
  +++ Expression.java	26 Jun 2002 21:25:35 -0000	1.13
  @@ -111,6 +111,15 @@
       }
   		
       /**
  +     * Returns an object representing the compile-time evaluation 
  +     * of an expression. We are only using this for function-available
  +     * and element-available at this time.
  +     */
  +    public Object evaluateAtCompileTime() {
  +	return null;
  +    }
  +
  +    /**
        * Type check all the children of this node.
        */
       public Type typeCheck(SymbolTable stable) throws TypeCheckError {
  
  
  
  1.9       +10 -1     xml-xalan/java/src/org/apache/xalan/xsltc/compiler/FunctionAvailableCall.java
  
  Index: FunctionAvailableCall.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/FunctionAvailableCall.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- FunctionAvailableCall.java	25 Jun 2002 17:05:38 -0000	1.8
  +++ FunctionAvailableCall.java	26 Jun 2002 21:25:35 -0000	1.9
  @@ -120,6 +120,15 @@
       }
   
       /**
  +     * Returns an object representing the compile-time evaluation 
  +     * of an expression. We are only using this for function-available
  +     * and element-available at this time.
  +     */
  +    public Object evaluateAtCompileTime() {
  +	return getResult() ? Boolean.TRUE : Boolean.FALSE;
  +    }
  +
  +    /**
        * (For ext. java functions only)
        * Parses the argument to function-available to extract the package 
        * qualified class name, for example, given the argument 
  
  
  
  1.10      +6 -12     xml-xalan/java/src/org/apache/xalan/xsltc/compiler/If.java
  
  Index: If.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/If.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- If.java	1 Feb 2002 20:07:08 -0000	1.9
  +++ If.java	26 Jun 2002 21:25:35 -0000	1.10
  @@ -102,17 +102,11 @@
   	    return;
           }
   
  -	// We will ignore the contents of this <xsl:if> if we know that the
  -	// test will always return 'false'.
  -	if (_test instanceof ElementAvailableCall) {
  -	    ElementAvailableCall call = (ElementAvailableCall)_test;
  -	    _ignore = !call.getResult();
  -	    return;
  -	}
  -	if (_test instanceof FunctionAvailableCall) {
  -	    FunctionAvailableCall call = (FunctionAvailableCall)_test;
  -	    _ignore = !call.getResult();
  -	    return;
  +	// Ignore xsl:if when test is false (function-available() and
  +	// element-available())
  +	Object result = _test.evaluateAtCompileTime();
  +	if (result != null && result instanceof Boolean) {
  +	    _ignore = !((Boolean) result).booleanValue();
   	}
   
   	parseChildren(parser);
  
  
  
  1.10      +26 -4     xml-xalan/java/src/org/apache/xalan/xsltc/compiler/LogicalExpr.java
  
  Index: LogicalExpr.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/LogicalExpr.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- LogicalExpr.java	1 Feb 2002 20:07:08 -0000	1.9
  +++ LogicalExpr.java	26 Jun 2002 21:25:35 -0000	1.10
  @@ -96,9 +96,31 @@
        * needed for context changes in node steps containing multiple predicates.
        */
       public boolean hasPositionCall() {
  -	if (_left.hasPositionCall()) return true;
  -	if (_right.hasPositionCall()) return true;
  -	return false;
  +	return (_left.hasPositionCall() || _right.hasPositionCall());
  +    }
  +
  +    /**
  +     * Returns an object representing the compile-time evaluation 
  +     * of an expression. We are only using this for function-available
  +     * and element-available at this time.
  +     */
  +    public Object evaluateAtCompileTime() {
  +	final Object leftb = _left.evaluateAtCompileTime();
  +	final Object rightb = _right.evaluateAtCompileTime();
  +
  +	// Return null if we can't evaluate at compile time
  +	if (leftb == null || rightb == null) {
  +	    return null;
  +	}
  +
  +	if (_op == AND) {
  +	    return (leftb == Boolean.TRUE && rightb == Boolean.TRUE) ?
  +		Boolean.TRUE : Boolean.FALSE;
  +	}
  +	else {
  +	    return (leftb == Boolean.TRUE || rightb == Boolean.TRUE) ?
  +		Boolean.TRUE : Boolean.FALSE;
  +	}
       }
   
       /**
  
  
  
  1.10      +7 -8      xml-xalan/java/src/org/apache/xalan/xsltc/compiler/When.java
  
  Index: When.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/When.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- When.java	30 Oct 2001 08:42:55 -0000	1.9
  +++ When.java	26 Jun 2002 21:25:35 -0000	1.10
  @@ -90,13 +90,12 @@
   
       public void parseContents(Parser parser) {
   	_test = parser.parseExpression(this, "test", null);
  -	if (_test instanceof ElementAvailableCall) {
  -	    ElementAvailableCall call = (ElementAvailableCall)_test;
  -	    _ignore = !call.getResult();
  -	}
  -	if (_test instanceof FunctionAvailableCall) {
  -	    FunctionAvailableCall call = (FunctionAvailableCall)_test;
  -	    _ignore = !call.getResult();
  +
  +	// Ignore xsl:if when test is false (function-available() and
  +	// element-available())
  +	Object result = _test.evaluateAtCompileTime();
  +	if (result != null && result instanceof Boolean) {
  +	    _ignore = !((Boolean) result).booleanValue();
   	}
   
   	parseChildren(parser);
  
  
  

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