You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by zo...@apache.org on 2004/04/10 21:00:44 UTC

cvs commit: xml-xalan/java/src/org/apache/xalan/xsltc/compiler ApplyImports.java

zongaro     2004/04/10 12:00:44

  Modified:    java/src/org/apache/xalan/xsltc/compiler ApplyImports.java
  Log:
  Applying patch for bugs 27932 and 15333.
  
  Code was incorrectly calculating the set of templates to which an
  xsl:apply-imports instruction applies.  It should consider all templates that
  the current template rule could override, which means that if the template
  appeared in a stylesheet that was included in another stylesheet, any templates
  imported into the including stylesheet have to be considered as well.  The
  method Stylesheet.getMinimumDescendantPrecedence is responsible for this
  calculation.
  
  In addition, when code is generated for an xsl:apply-imports, if any template
  has local parameters, an empty stack frame has to be pushed before attempting
  to apply-imports.  Otherwise, parameters from the template that contains the
  apply-imports instruction will be passed into the matching template.
  
  Reviewed by Joanne Tong (joannet () ca ! ibm ! com)
  
  Revision  Changes    Path
  1.14      +37 -37    xml-xalan/java/src/org/apache/xalan/xsltc/compiler/ApplyImports.java
  
  Index: ApplyImports.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/ApplyImports.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- ApplyImports.java	16 Feb 2004 22:24:29 -0000	1.13
  +++ ApplyImports.java	10 Apr 2004 19:00:44 -0000	1.14
  @@ -32,13 +32,9 @@
   import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
   import org.apache.xalan.xsltc.compiler.util.Util;
   
  -/**
  - * @author Morten Jorgensen
  - */
   final class ApplyImports extends Instruction {
   
       private QName      _modeName;
  -    private String     _functionName;
       private int        _precedence;
   
       public void display(int indent) {
  @@ -66,31 +62,13 @@
        * the integer returned by this method.
        */
       private int getMinPrecedence(int max) {
  -	Stylesheet stylesheet = getStylesheet();
  -	Stylesheet root = getParser().getTopLevelStylesheet();
  -
  -	int min = max;
  +        // Move to root of include tree
  +        Stylesheet includeRoot = getStylesheet();
  +        while (includeRoot._includedFrom != null) {
  +            includeRoot = includeRoot._includedFrom;
  +        }
   
  -	Enumeration templates = root.getContents().elements();
  -	while (templates.hasMoreElements()) {
  -	    SyntaxTreeNode child = (SyntaxTreeNode)templates.nextElement();
  -	    if (child instanceof Template) {
  -		Stylesheet curr = child.getStylesheet();
  -		while ((curr != null) && (curr != stylesheet)) {
  -		    if (curr._importedFrom != null)
  -			curr = curr._importedFrom;
  -		    else if (curr._includedFrom != null)
  -			curr = curr._includedFrom;
  -		    else
  -			curr = null;
  -		}
  -		if (curr == stylesheet) {
  -		    int prec = child.getStylesheet().getImportPrecedence();
  -		    if (prec < min) min = prec;
  -		}
  -	    }
  -	}
  -	return (min);
  +        return includeRoot.getMinimumDescendantPrecedence();
       }
   
       /**
  @@ -110,13 +88,6 @@
   	// Get the method name for <xsl:apply-imports/> in this mode
   	stylesheet = parser.getTopLevelStylesheet();
   
  -	// Get the [min,max> precedence of all templates imported under the
  -	// current stylesheet
  -	final int maxPrecedence = _precedence;
  -	final int minPrecedence = getMinPrecedence(maxPrecedence);
  -	final Mode mode = stylesheet.getMode(_modeName);
  -	_functionName = mode.functionName(minPrecedence, maxPrecedence);
  -
   	parseChildren(parser);	// with-params
       }
   
  @@ -151,13 +122,42 @@
   
   	il.append(methodGen.loadHandler());
   
  +        // Push a new parameter frame in case imported template might expect
  +        // parameters.  The apply-imports has nothing that it can pass.
  +        if (stylesheet.hasLocalParams()) {
  +            il.append(classGen.loadTranslet());
  +            final int pushFrame = cpg.addMethodref(TRANSLET_CLASS,
  +                                                   PUSH_PARAM_FRAME,
  +                                                   PUSH_PARAM_FRAME_SIG);
  +            il.append(new INVOKEVIRTUAL(pushFrame));
  +        }
  +
  +	// Get the [min,max> precedence of all templates imported under the
  +	// current stylesheet
  +	final int maxPrecedence = _precedence;
  +	final int minPrecedence = getMinPrecedence(maxPrecedence);
  +	final Mode mode = stylesheet.getMode(_modeName);
  +
  +        // Get name of appropriate apply-templates function for this
  +        // xsl:apply-imports instruction
  +	String functionName = mode.functionName(minPrecedence, maxPrecedence);
  +
   	// Construct the translet class-name and the signature of the method
   	final String className = classGen.getStylesheet().getClassName();
   	final String signature = classGen.getApplyTemplatesSig();
   	final int applyTemplates = cpg.addMethodref(className,
  -						    _functionName,
  +						    functionName,
   						    signature);
   	il.append(new INVOKEVIRTUAL(applyTemplates));
  +
  +        // Pop any parameter frame that was pushed above.
  +        if (stylesheet.hasLocalParams()) {
  +            il.append(classGen.loadTranslet());
  +            final int pushFrame = cpg.addMethodref(TRANSLET_CLASS,
  +                                                   POP_PARAM_FRAME,
  +                                                   POP_PARAM_FRAME_SIG);
  +            il.append(new INVOKEVIRTUAL(pushFrame));
  +        }
       }
   
   }
  
  
  

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