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/04/17 22:25:26 UTC

cvs commit: xml-xalan/java/src/org/apache/xalan/xsltc/compiler FunctionCall.java Parser.java Stylesheet.java SyntaxTreeNode.java XSLTC.java xpath.cup

santiagopg    02/04/17 13:25:26

  Modified:    java/src/org/apache/xalan/xsltc/compiler Tag:
                        jaxp-ri-1_2_0-fcs-branch FunctionCall.java
                        Parser.java Stylesheet.java SyntaxTreeNode.java
                        XSLTC.java xpath.cup
  Log:
  Added support for extension function nodeset().
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.12.4.3  +29 -15    xml-xalan/java/src/org/apache/xalan/xsltc/compiler/FunctionCall.java
  
  Index: FunctionCall.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/FunctionCall.java,v
  retrieving revision 1.12.4.2
  retrieving revision 1.12.4.3
  diff -u -r1.12.4.2 -r1.12.4.3
  --- FunctionCall.java	9 Apr 2002 18:52:26 -0000	1.12.4.2
  +++ FunctionCall.java	17 Apr 2002 20:25:26 -0000	1.12.4.3
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: FunctionCall.java,v 1.12.4.2 2002/04/09 18:52:26 tmiller Exp $
  + * @(#)$Id: FunctionCall.java,v 1.12.4.3 2002/04/17 20:25:26 santiagopg Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -86,10 +86,19 @@
       private final static Vector EMPTY_ARG_LIST = new Vector(0);
   
       // Valid namespaces for Java function-call extension
  -    protected final static String JAVA_EXT_PREFIX = TRANSLET_URI + "/java";
  +    protected final static String EXT_XSLTC = 
  +	TRANSLET_URI;
  +
  +    protected final static String JAVA_EXT_XSLTC = 
  +	EXT_XSLTC + "/java";
  +
  +    protected final static String EXT_XALAN =
  +	"http://xml.apache.org/xalan";
  +
       protected final static String JAVA_EXT_XALAN =
   	"http://xml.apache.org/xslt/java";
   
  +
       // External Java function's class/method/signature
       private String     _className;
       private Method     _chosenMethod;
  @@ -197,7 +206,7 @@
   	throws TypeCheckError
       {
   	final int length = 
  -	    uri.startsWith(JAVA_EXT_PREFIX) ? JAVA_EXT_PREFIX.length() + 1 :
  +	    uri.startsWith(JAVA_EXT_XSLTC) ? JAVA_EXT_XSLTC.length() + 1 :
   	    uri.startsWith(JAVA_EXT_XALAN) ? JAVA_EXT_XALAN.length() + 1 : 0;
   
   	if (length == 0) {
  @@ -218,8 +227,11 @@
   	final String namespace = _fname.getNamespace();
   	final String local = _fname.getLocalPart();
   
  -	// XPath functions have no namespace
  -	if (isStandard()) {
  +	if (isExtension()) {
  +	    _fname = new QName(null, null, local);
  +	    return typeCheckStandard(stable);
  +	}
  +	else if (isStandard()) {
   	    return typeCheckStandard(stable);
   	}
   	// Handle extension functions (they all have a namespace)
  @@ -264,8 +276,7 @@
        * thrown, then catch it and re-throw it with a new "this".
        */
       public Type typeCheckStandard(SymbolTable stable) throws TypeCheckError {
  -
  -	_fname.clearNamespace(); // HACK!!!
  +	_fname.clearNamespace(); 	// HACK!!!
   
   	final int n = _arguments.size();
   	final Vector argsType = typeCheckArgs(stable);
  @@ -388,8 +399,8 @@
        * Update true/false-lists.
        */
       public void translateDesynthesized(ClassGenerator classGen,
  -				       MethodGenerator methodGen) {
  -
  +				       MethodGenerator methodGen) 
  +    {
   	Type type = Type.Boolean;
   	if (_chosenMethodType != null)
   	    type = _chosenMethodType.resultType();
  @@ -414,7 +425,7 @@
   	int index;
   
   	// Translate calls to methods in the BasisLibrary
  -	if (isStandard()) {
  +	if (isStandard() || isExtension()) {
   	    for (int i = 0; i < n; i++) {
   		final Expression exp = argument(i);
   		exp.translate(classGen, methodGen);
  @@ -491,10 +502,13 @@
   
       public boolean isStandard() {
   	final String namespace = _fname.getNamespace();
  -	if ((namespace == null) || (namespace.equals(Constants.EMPTYSTRING)))
  -	    return true;
  -	else
  -	    return false;
  +	return (namespace == null) || (namespace.equals(Constants.EMPTYSTRING));
  +    }
  +
  +    public boolean isExtension() {
  +	final String namespace = _fname.getNamespace();
  +	return (namespace != null) && (namespace.equals(EXT_XSLTC) 
  +	    || namespace.equals(EXT_XALAN));
       }
   
       /**
  @@ -506,7 +520,7 @@
   	Vector result = null;
   	final String namespace = _fname.getNamespace();
   
  -	if (namespace.startsWith(JAVA_EXT_PREFIX) ||
  +	if (namespace.startsWith(JAVA_EXT_XSLTC) ||
   	    namespace.startsWith(JAVA_EXT_XALAN)) {
   	    final int nArgs = _arguments.size();
   	    try {
  
  
  
  1.38.8.2  +5 -1      xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Parser.java
  
  Index: Parser.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Parser.java,v
  retrieving revision 1.38.8.1
  retrieving revision 1.38.8.2
  diff -u -r1.38.8.1 -r1.38.8.2
  --- Parser.java	3 Apr 2002 19:26:49 -0000	1.38.8.1
  +++ Parser.java	17 Apr 2002 20:25:26 -0000	1.38.8.2
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: Parser.java,v 1.38.8.1 2002/04/03 19:26:49 tmiller Exp $
  + * @(#)$Id: Parser.java,v 1.38.8.2 2002/04/17 20:25:26 santiagopg Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -664,6 +664,7 @@
   	MethodType B_V  = new MethodType(Type.Boolean, Type.Void);
   	MethodType B_B  = new MethodType(Type.Boolean, Type.Boolean);
   	MethodType B_S  = new MethodType(Type.Boolean, Type.String);
  +	MethodType D_T  = new MethodType(Type.NodeSet, Type.ResultTree);
   	MethodType R_RR = new MethodType(Type.Real, Type.Real, Type.Real);
   	MethodType I_II = new MethodType(Type.Int, Type.Int, Type.Int);
   	MethodType B_RR = new MethodType(Type.Boolean, Type.Real, Type.Real);
  @@ -747,6 +748,9 @@
   	_symbolTable.addPrimop("normalize-space", S_V);
   	_symbolTable.addPrimop("normalize-space", S_S);
   	_symbolTable.addPrimop("system-property", S_S);
  +
  +	// Extensions
  +	_symbolTable.addPrimop("nodeset", D_T);
   
   	// Operators +, -, *, /, % defined on real types.
   	_symbolTable.addPrimop("+", R_RR);	
  
  
  
  1.35.4.2  +11 -1     xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Stylesheet.java
  
  Index: Stylesheet.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Stylesheet.java,v
  retrieving revision 1.35.4.1
  retrieving revision 1.35.4.2
  diff -u -r1.35.4.1 -r1.35.4.2
  --- Stylesheet.java	3 Apr 2002 19:26:49 -0000	1.35.4.1
  +++ Stylesheet.java	17 Apr 2002 20:25:26 -0000	1.35.4.2
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: Stylesheet.java,v 1.35.4.1 2002/04/03 19:26:49 tmiller Exp $
  + * @(#)$Id: Stylesheet.java,v 1.35.4.2 2002/04/17 20:25:26 santiagopg Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -117,6 +117,7 @@
       private int _importPrecedence = 1;
       private Mode _defaultMode;
       private boolean _multiDocument = false;
  +    private boolean _callsNodeset = false;
   
       // All named key elements (needed by Key/IdPattern)
       private Hashtable _keys = new Hashtable();
  @@ -153,6 +154,15 @@
   
       public boolean isMultiDocument() {
   	return _multiDocument;
  +    }
  +
  +    public void setCallsNodeset(boolean flag) {
  +	if (flag) setMultiDocument(flag);
  +	_callsNodeset = flag;
  +    }
  +
  +    public boolean callsNodeset() {
  +	return _callsNodeset;
       }
   
       public void numberFormattingUsed() {
  
  
  
  1.18.4.2  +40 -10    xml-xalan/java/src/org/apache/xalan/xsltc/compiler/SyntaxTreeNode.java
  
  Index: SyntaxTreeNode.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/SyntaxTreeNode.java,v
  retrieving revision 1.18.4.1
  retrieving revision 1.18.4.2
  diff -u -r1.18.4.1 -r1.18.4.2
  --- SyntaxTreeNode.java	3 Apr 2002 19:26:49 -0000	1.18.4.1
  +++ SyntaxTreeNode.java	17 Apr 2002 20:25:26 -0000	1.18.4.2
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: SyntaxTreeNode.java,v 1.18.4.1 2002/04/03 19:26:49 tmiller Exp $
  + * @(#)$Id: SyntaxTreeNode.java,v 1.18.4.2 2002/04/17 20:25:26 santiagopg Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -552,10 +552,11 @@
        * @param methodGen BCEL Java method generator
        */
       protected void compileResultTree(ClassGenerator classGen,
  -				     MethodGenerator methodGen) {
  -
  +				     MethodGenerator methodGen) 
  +    {
   	final ConstantPoolGen cpg = classGen.getConstantPool();
   	final InstructionList il = methodGen.getInstructionList();
  +	final Stylesheet stylesheet = classGen.getStylesheet();
   
   	// Save the current handler base on the stack
   	il.append(methodGen.loadHandler());
  @@ -600,13 +601,42 @@
   	    il.append(new NEW(cpg.addClass(DOM_ADAPTER_CLASS)));
   	    il.append(new DUP_X1());
   	    il.append(SWAP);
  -	    // Give the DOM adapter an empty type mapping to start with.
  -	    // Type mapping is expensive and will only be done when casting
  -	    // a result tree fragment to a node-set.
  -	    il.append(new ICONST(0));
  -	    il.append(new ANEWARRAY(cpg.addClass(STRING)));
  -	    il.append(DUP);
  -	    il.append(new INVOKESPECIAL(index)); // leave DOMAdapter on stack
  +
  +	    /*
  +	     * Give the DOM adapter an empty type mapping if the nodeset
  +	     * extension function is never called.
  +	     */
  +	    if (!stylesheet.callsNodeset()) {
  +		il.append(new ICONST(0));
  +		il.append(new ANEWARRAY(cpg.addClass(STRING)));
  +		il.append(DUP);
  +		il.append(new INVOKESPECIAL(index));
  +	    }
  +	    else {
  +		// Push name arrays on the stack
  +		il.append(ALOAD_0);
  +		il.append(new GETFIELD(cpg.addFieldref(TRANSLET_CLASS,
  +					   NAMES_INDEX,
  +					   NAMES_INDEX_SIG))); 
  +		il.append(ALOAD_0);
  +		il.append(new GETFIELD(cpg.addFieldref(TRANSLET_CLASS,
  +					   NAMESPACE_INDEX,
  +					   NAMESPACE_INDEX_SIG)));
  +
  +		// Initialized DOM adapter
  +		il.append(new INVOKESPECIAL(index));
  +
  +		// Add DOM adapter to MultiDOM class by calling addDOMAdapter()
  +		il.append(DUP);
  +		il.append(methodGen.loadDOM());
  +		il.append(new CHECKCAST(cpg.addClass(classGen.getDOMClass())));
  +		il.append(SWAP);
  +		index = cpg.addMethodref(MULTI_DOM_CLASS,
  +					 "addDOMAdapter",
  +					 "(" + DOM_ADAPTER_SIG + ")I");
  +		il.append(new INVOKEVIRTUAL(index));
  +		il.append(POP);		// ignore mask returned by addDOMAdapter
  +	    }
   	}
   
   	// Restore old handler base from stack
  
  
  
  1.35.4.1  +16 -2     xml-xalan/java/src/org/apache/xalan/xsltc/compiler/XSLTC.java
  
  Index: XSLTC.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/XSLTC.java,v
  retrieving revision 1.35
  retrieving revision 1.35.4.1
  diff -u -r1.35 -r1.35.4.1
  --- XSLTC.java	1 Feb 2002 20:07:09 -0000	1.35
  +++ XSLTC.java	17 Apr 2002 20:25:26 -0000	1.35.4.1
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: XSLTC.java,v 1.35 2002/02/01 20:07:09 tmiller Exp $
  + * @(#)$Id: XSLTC.java,v 1.35.4.1 2002/04/17 20:25:26 santiagopg Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -139,6 +139,7 @@
       private int     _outputType = FILE_OUTPUT; // by default
   
       private Vector  _classes;
  +    private boolean _callsNodeset = false;
       private boolean _multiDocument = false;
   
       /**
  @@ -317,6 +318,7 @@
   	    }
   	    // Generate the bytecodes and output the translet class(es)
   	    if ((!_parser.errorsFound()) && (_stylesheet != null)) {
  +		_stylesheet.setCallsNodeset(_callsNodeset);
   		_stylesheet.setMultiDocument(_multiDocument);
   		_stylesheet.translate();
   	    }
  @@ -435,7 +437,6 @@
   	_parser.printWarnings();
       }
   
  -
       /**
        * This method is called by the XPathParser when it encounters a call
        * to the document() function. Affects the DOM used by the translet.
  @@ -446,6 +447,19 @@
   
       public boolean isMultiDocument() {
   	return _multiDocument;
  +    }
  +
  +    /**
  +     * This method is called by the XPathParser when it encounters a call
  +     * to the nodeset() extension function. Implies multi document.
  +     */
  +    protected void setCallsNodeset(boolean flag) {
  +	if (flag) setMultiDocument(flag);
  +	_callsNodeset = flag;
  +    }
  +
  +    public boolean callsNodeset() {
  +	return _callsNodeset;
       }
   
       /**
  
  
  
  1.33.8.1  +10 -1     xml-xalan/java/src/org/apache/xalan/xsltc/compiler/xpath.cup
  
  Index: xpath.cup
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/xpath.cup,v
  retrieving revision 1.33
  retrieving revision 1.33.8.1
  diff -u -r1.33 -r1.33.8.1
  --- xpath.cup	10 Dec 2001 12:53:07 -0000	1.33
  +++ xpath.cup	17 Apr 2002 20:25:26 -0000	1.33.8.1
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: xpath.cup,v 1.33 2001/12/10 12:53:07 morten Exp $
  + * @(#)$Id: xpath.cup,v 1.33.8.1 2002/04/17 20:25:26 santiagopg Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -119,6 +119,10 @@
             _xsltc.setMultiDocument(flag);
       }
   
  +    public void setCallsNodeset(boolean flag) {
  +          _xsltc.setCallsNodeset(flag);
  +    }
  +
       public int findNodeType(int axis, Object test) {
   
   	if (test == null) {  // *
  @@ -894,6 +898,11 @@
   	  }
             else if (fname == parser.getQName("namespace-uri")) {
               RESULT = new NamespaceUriCall(fname, argl);
  +	  }
  +	  // Special case for extension function nodeset()
  +          else if (fname.getLocalPart().equals("nodeset")) {
  +	    parser.setCallsNodeset(true);  // implies MultiDOM
  +            RESULT = new FunctionCall(fname, argl);
   	  }
             else {
               RESULT = new FunctionCall(fname, argl);
  
  
  

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