You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by mo...@apache.org on 2001/08/28 14:43:08 UTC

cvs commit: xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util NodeSetType.java NodeType.java ReferenceType.java ResultTreeType.java StringType.java Type.java

morten      01/08/28 05:43:08

  Modified:    java/src/org/apache/xalan/xsltc/compiler Param.java
                        ParameterRef.java Variable.java VariableBase.java
                        VariableRef.java
               java/src/org/apache/xalan/xsltc/compiler/util
                        NodeSetType.java NodeType.java ReferenceType.java
                        ResultTreeType.java StringType.java Type.java
  Log:
  A few fixes for the regression caused by my last (huge) putback.
  PR:		n/a
  Obtained from:	n/a
  Submitted by:	morten@xml.apache.org
  Reviewed by:	morten@xml.apache.org
  
  Revision  Changes    Path
  1.11      +45 -11    xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Param.java
  
  Index: Param.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Param.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- Param.java	2001/08/27 09:07:19	1.10
  +++ Param.java	2001/08/28 12:43:08	1.11
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: Param.java,v 1.10 2001/08/27 09:07:19 morten Exp $
  + * @(#)$Id: Param.java,v 1.11 2001/08/28 12:43:08 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -99,13 +99,24 @@
   	displayContents(indent + IndentIncrement);
       }
   
  +    /**
  +     * Returns the parameter's type. This is needed by ParameterRef to
  +     * determine the type of the parameter
  +     */
  +    public Type getType() {
  +	return _type;
  +    }
  +
  +    /**
  +     * Parse the contents of the <xsl:param> element. This method must read
  +     * the 'name' (required) and 'select' (optional) attributes.
  +     */
       public void parseContents(Parser parser) {
   	// Parse attributes name and select (if present)
   	final String name = getAttribute("name");
   
   	if (name.length() > 0) {
  -	    _name = parser.getQName(name);
  -	    _name.clearDefaultNamespace();
  +	    setName(parser.getQName(name));
   	}
           else {
   	    reportError(this, parser, ErrorMsg.NREQATTR_ERR, "name");
  @@ -139,14 +150,27 @@
   	}
       }
   
  +    /**
  +     * Type-checks the parameter. The parameter type is determined by the
  +     * 'select' expression (if present) or is a result tree if the parameter
  +     * element has a body and no 'select' expression.
  +     */
       public Type typeCheck(SymbolTable stable) throws TypeCheckError {
  +	// Get the type from the select exrepssion...
   	if (_select != null) {
   	    _type = _select.typeCheck(stable); 
  +	    if (_type instanceof ReferenceType == false) {
  +		_select = new CastExpr(_select, Type.Reference);
  +	    }
   	}
  -	else {
  +	// ...or set the type to result tree
  +	else if (hasContents()) {
   	    typeCheckContents(stable);
  -	    _type = Type.ResultTree;
   	}
  +	_type = Type.Reference;
  +
  +	// This element has no type (the parameter does, but the parameter
  +	// element itself does not).
   	return Type.Void;
       }
   
  @@ -159,6 +183,7 @@
   	// Compile expression is 'select' attribute if present
   	if (_select != null) {
   	    _select.translate(classGen, methodGen);
  +	    _type.translateBox(classGen, methodGen);
   	    _select.startResetIterator(classGen, methodGen);
   	}
   	// If not, compile result tree from parameter body if present.
  @@ -182,11 +207,9 @@
   	if (_compiled) return;
   	_compiled = true;
   
  -	// Make name acceptable for use as field name in class
  -	// TODO: convert to escape sequence like $dot$ and $dash$
  -	String name = _name.getLocalPart(); // TODO: namespace ?
  -	name = name.replace('.', '_');
  -	name = name.replace('-', '_');
  +	final String name = getVariable();
  +	final String signature = _type.toSignature();
  +	final String className = _type.getClassName();
   
   	if (isLocal()) {
   
  @@ -199,6 +222,11 @@
   	    il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS,
   							 ADD_PARAMETER,
   							 ADD_PARAMETER_SIG)));
  +	    if (className != EMPTYSTRING) {
  +		il.append(new CHECKCAST(cpg.addClass(className)));
  +	    }
  +
  +	    _type.translateUnBox(classGen, methodGen);
   
   	    if (_refs.isEmpty()) { // nobody uses the value
   		il.append(_type.POP());
  @@ -213,7 +241,6 @@
   	    }
   	}
   	else {
  -	    String signature = _type.toSignature();
   	    classGen.addField(new Field(ACC_PUBLIC, cpg.addUtf8(name),
   					cpg.addUtf8(signature),
   					null, cpg.getConstantPool()));
  @@ -227,9 +254,16 @@
   	    il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS,
   							 ADD_PARAMETER,
   							 ADD_PARAMETER_SIG)));
  +
  +	    _type.translateUnBox(classGen, methodGen);
  +
   	    // Cache the result of addParameter() in a field
  +	    if (className != EMPTYSTRING) {
  +		il.append(new CHECKCAST(cpg.addClass(className)));
  +	    }
   	    il.append(new PUTFIELD(cpg.addFieldref(classGen.getClassName(),
   						   name, signature)));
   	}
       }
  +
   }
  
  
  
  1.6       +6 -9      xml-xalan/java/src/org/apache/xalan/xsltc/compiler/ParameterRef.java
  
  Index: ParameterRef.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/ParameterRef.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ParameterRef.java	2001/08/27 09:07:19	1.5
  +++ ParameterRef.java	2001/08/28 12:43:08	1.6
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: ParameterRef.java,v 1.5 2001/08/27 09:07:19 morten Exp $
  + * @(#)$Id: ParameterRef.java,v 1.6 2001/08/28 12:43:08 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -83,19 +83,17 @@
   	final ConstantPoolGen cpg = classGen.getConstantPool();
   	final InstructionList il = methodGen.getInstructionList();
   		
  -	final Type parType = _variable.getType();
  -	String parName = _variable.getName().getLocalPart();
  -	parName = parName.replace('.', '_');
  -	parName = parName.replace('-', '_');
  +	String name = _variable.getVariable();
   
   	if (_variable.isLocal()) {
   	    if (classGen.isExternal()) {
   		il.append(classGen.loadTranslet());
  -		il.append(new PUSH(cpg, parName));
  +		il.append(new PUSH(cpg, name));
   		final int index = cpg.addMethodref(TRANSLET_CLASS, 
   						   GET_PARAMETER,
   						   GET_PARAMETER_SIG);
   		il.append(new INVOKEVIRTUAL(index));
  +		_type.translateUnBox(classGen, methodGen);
   	    }
   	    else {
   		il.append(_variable.loadInstruction());
  @@ -103,15 +101,14 @@
   	    }
   	}
   	else {
  +	    final String signature = _type.toSignature();
   	    final String className = classGen.getClassName();
   	    il.append(classGen.loadTranslet());
   	    // If inside a predicate we must cast this ref down
   	    if (classGen.isExternal()) {
   		il.append(new CHECKCAST(cpg.addClass(className)));
   	    }
  -	    il.append(new GETFIELD(cpg.addFieldref(className,
  -						   parName,
  -						   parType.toSignature())));
  +	    il.append(new GETFIELD(cpg.addFieldref(className,name,signature)));
   	}
       }
   }
  
  
  
  1.14      +9 -11     xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Variable.java
  
  Index: Variable.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Variable.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- Variable.java	2001/08/27 09:07:20	1.13
  +++ Variable.java	2001/08/28 12:43:08	1.14
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: Variable.java,v 1.13 2001/08/27 09:07:20 morten Exp $
  + * @(#)$Id: Variable.java,v 1.14 2001/08/28 12:43:08 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -110,8 +110,7 @@
   	// parse attributes name and select (if present)
   	final String name = getAttribute("name");
   	if (name.length() > 0) {
  -	    _name = parser.getQName(name);
  -	    _name.clearDefaultNamespace();
  +	    setName(parser.getQName(name));
   	}
           else {
   	    reportError(this, parser, ErrorMsg.NREQATTR_ERR, "name");
  @@ -170,10 +169,13 @@
   	    _type = _select.typeCheck(stable);
   	}
   	// Type check the element contents otherwise
  -	else {
  +	else if (hasContents()) {
   	    typeCheckContents(stable);
   	    _type = Type.ResultTree;
   	}
  +	else {
  +	    _type = Type.Reference;
  +	}
   
   	// The return type is void as the variable element does not leave
   	// anything on the JVM's stack. The '_type' global will be returned
  @@ -194,10 +196,7 @@
   	if (isLocal() && !_refs.isEmpty()) {
   	    // Create a variable slot if none is allocated
   	    if (_local == null) {
  -		String name = _name.getLocalPart();
  -		name = name.replace('.', '_');
  -		name = name.replace('-', '_');
  -		_local = methodGen.addLocalVariable2(name,
  +		_local = methodGen.addLocalVariable2(_name.getLocalPart(),
   						     _type.toJCType(),
   						     il.getEnd());
   	    }
  @@ -240,9 +239,8 @@
       public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
   	final ConstantPoolGen cpg = classGen.getConstantPool();
   	final InstructionList il = methodGen.getInstructionList();
  -	String name = _name.getLocalPart();
  -	name = name.replace('.', '_');
  -        name = name.replace('-', '_');
  +
  +	final String name = getVariable();
   
   	// Make sure that a variable instance is only compiled once
   	if (_compiled) return;
  
  
  
  1.3       +48 -5     xml-xalan/java/src/org/apache/xalan/xsltc/compiler/VariableBase.java
  
  Index: VariableBase.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/VariableBase.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- VariableBase.java	2001/07/31 18:13:23	1.2
  +++ VariableBase.java	2001/08/28 12:43:08	1.3
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: VariableBase.java,v 1.2 2001/07/31 18:13:23 morten Exp $
  + * @(#)$Id: VariableBase.java,v 1.3 2001/08/28 12:43:08 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -78,6 +78,7 @@
   class VariableBase extends TopLevelElement {
   
       protected QName       _name;            // The name of the variable.
  +    protected String      _variable;        // The real name of the variable.
       protected Type        _type;            // The type of this variable.
       protected boolean     _isLocal;         // True if the variable is local.
       protected LocalVariableGen _local;      // Reference to JVM variable
  @@ -113,9 +114,7 @@
       public void mapRegister(MethodGenerator methodGen) {
           if (_local == null) {
               final InstructionList il = methodGen.getInstructionList();
  -	    String name = _name.getLocalPart(); // TODO: namespace ?
  -            name = name.replace('.', '_');
  -            name = name.replace('-', '_');
  +	    final String name = _name.getLocalPart(); // TODO: namespace ?
   	    final de.fub.bytecode.generic.Type varType = _type.toJCType();
               _local = methodGen.addLocalVariable2(name, varType, il.getEnd());
           }
  @@ -180,10 +179,54 @@
       }
   
       /**
  -     * Returns the name of the variable
  +     * Returns the name of the variable or parameter as it will occur in the
  +     * compiled translet.
        */
       public QName getName() {
   	return _name;
  +    }
  +
  +    /**
  +     * Returns the name of the variable or parameter as it occured in the
  +     * stylesheet.
  +     */
  +    public String getVariable() {
  +	return _variable;
  +    }
  +
  +    private static String replace(String base, char c, String str) {
  +	final int len = base.length() - 1;
  +	int pos;
  +	while ((pos = base.indexOf(c)) > -1) {
  +	    if (pos == 0) {
  +		final String after = base.substring(1);
  +		base = str + after;
  +	    }
  +	    else if (pos == len) {
  +		final String before = base.substring(0, pos);
  +		base = before + str;
  +	    }
  +	    else {
  +		final String before = base.substring(0, pos);
  +		final String after = base.substring(pos+1);
  +		base = before + str + after;
  +	    }
  +	}
  +	return base;
  +    }
  +
  +    /**
  +     * Set the name of the variable or paremeter. Escape all special chars.
  +     */
  +    public void setName(QName name) {
  +	_name = name;
  +	_name.clearDefaultNamespace();
  +
  +	String prefix = name.getPrefix();
  +	String local = name.getLocalPart();
  +	local = replace(local, '.', "$dot$");
  +	local = replace(local, '-', "$dash$");
  +	_variable = local;
       }
   
       /**
  
  
  
  1.7       +5 -9      xml-xalan/java/src/org/apache/xalan/xsltc/compiler/VariableRef.java
  
  Index: VariableRef.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/VariableRef.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- VariableRef.java	2001/08/27 09:07:20	1.6
  +++ VariableRef.java	2001/08/28 12:43:08	1.7
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: VariableRef.java,v 1.6 2001/08/27 09:07:20 morten Exp $
  + * @(#)$Id: VariableRef.java,v 1.7 2001/08/28 12:43:08 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -102,12 +102,9 @@
   	final ConstantPoolGen cpg = classGen.getConstantPool();
   	final InstructionList il = methodGen.getInstructionList();
   		
  -	final Type varType = _variable.getType();
  -	String varName = _variable.getName().getLocalPart();
  -	varName = varName.replace('.', '_');
  -        varName = varName.replace('-', '_');
  +	String name = _variable.getVariable();
   
  -	if (varType.implementedAsMethod()) {
  +	if (_type.implementedAsMethod()) {
   	    // Fall-through for variables that are implemented as methods
   	    return;
   	}
  @@ -129,15 +126,14 @@
   	    }
   	}
   	else {
  +	    final String signature = _type.toSignature();
   	    final String className = classGen.getClassName();
   	    il.append(classGen.loadTranslet());
   	    // If inside a predicate we must cast this ref down
   	    if (classGen.isExternal()) {
   		il.append(new CHECKCAST(cpg.addClass(className)));
   	    }
  -	    il.append(new GETFIELD(cpg.addFieldref(className,
  -						   varName,
  -						   varType.toSignature())));
  +	    il.append(new GETFIELD(cpg.addFieldref(className,name,signature)));
   	}
       }
   }
  
  
  
  1.7       +9 -1      xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util/NodeSetType.java
  
  Index: NodeSetType.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util/NodeSetType.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- NodeSetType.java	2001/08/27 09:07:21	1.6
  +++ NodeSetType.java	2001/08/28 12:43:08	1.7
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: NodeSetType.java,v 1.6 2001/08/27 09:07:21 morten Exp $
  + * @(#)$Id: NodeSetType.java,v 1.7 2001/08/28 12:43:08 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -277,6 +277,14 @@
   			       MethodGenerator methodGen) {
   	methodGen.getInstructionList().append(NOP);
       }
  +
  +    /**
  +     * Returns the class name of an internal type's external representation.
  +     */
  +    public String getClassName() {
  +	return(NODE_ITERATOR);
  +    }
  +
   
       public Instruction LOAD(int slot) {
   	return new ALOAD(slot);
  
  
  
  1.5       +8 -1      xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util/NodeType.java
  
  Index: NodeType.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util/NodeType.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- NodeType.java	2001/08/27 09:07:21	1.4
  +++ NodeType.java	2001/08/28 12:43:08	1.5
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: NodeType.java,v 1.4 2001/08/27 09:07:21 morten Exp $
  + * @(#)$Id: NodeType.java,v 1.5 2001/08/28 12:43:08 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -304,6 +304,13 @@
   	il.append(new GETFIELD(cpg.addFieldref(RUNTIME_NODE_CLASS,
   					       NODE_FIELD,
   					       NODE_FIELD_SIG)));
  +    }
  +
  +    /**
  +     * Returns the class name of an internal type's external representation.
  +     */
  +    public String getClassName() {
  +	return(RUNTIME_NODE_CLASS);
       }
   
       public Instruction LOAD(int slot) {
  
  
  
  1.5       +16 -1     xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util/ReferenceType.java
  
  Index: ReferenceType.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util/ReferenceType.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ReferenceType.java	2001/07/10 17:46:10	1.4
  +++ ReferenceType.java	2001/08/28 12:43:08	1.5
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: ReferenceType.java,v 1.4 2001/07/10 17:46:10 morten Exp $
  + * @(#)$Id: ReferenceType.java,v 1.5 2001/08/28 12:43:08 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -222,6 +222,21 @@
   	translateTo(classGen, methodGen, type);
   	return new FlowList(il.append(new IFEQ(null)));
       }
  +
  +    /**
  +     * Translates an object of this type to its boxed representation.
  +     */ 
  +    public void translateBox(ClassGenerator classGen,
  +			     MethodGenerator methodGen) {
  +    }
  +
  +    /**
  +     * Translates an object of this type to its unboxed representation.
  +     */ 
  +    public void translateUnBox(ClassGenerator classGen,
  +			       MethodGenerator methodGen) {
  +    }
  +
   
       public Instruction LOAD(int slot) {
   	return new ALOAD(slot);
  
  
  
  1.6       +8 -1      xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util/ResultTreeType.java
  
  Index: ResultTreeType.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util/ResultTreeType.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ResultTreeType.java	2001/08/27 09:07:21	1.5
  +++ ResultTreeType.java	2001/08/28 12:43:08	1.6
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: ResultTreeType.java,v 1.5 2001/08/27 09:07:21 morten Exp $
  + * @(#)$Id: ResultTreeType.java,v 1.6 2001/08/28 12:43:08 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -417,6 +417,13 @@
       public void translateUnBox(ClassGenerator classGen,
   			       MethodGenerator methodGen) {
   	methodGen.getInstructionList().append(NOP);
  +    }
  +
  +    /**
  +     * Returns the class name of an internal type's external representation.
  +     */
  +    public String getClassName() {
  +	return(DOM_INTF);
       }
   
       public Instruction LOAD(int slot) {
  
  
  
  1.2       +9 -1      xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util/StringType.java
  
  Index: StringType.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util/StringType.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StringType.java	2001/04/17 18:52:21	1.1
  +++ StringType.java	2001/08/28 12:43:08	1.2
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: StringType.java,v 1.1 2001/04/17 18:52:21 sboag Exp $
  + * @(#)$Id: StringType.java,v 1.2 2001/08/28 12:43:08 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -214,6 +214,14 @@
   			       MethodGenerator methodGen) {
   	methodGen.getInstructionList().append(NOP);
       }
  +
  +    /**
  +     * Returns the class name of an internal type's external representation.
  +     */
  +    public String getClassName() {
  +	return(STRING_CLASS);
  +    }
  +
   
       public Instruction LOAD(int slot) {
   	return new ALOAD(slot);
  
  
  
  1.6       +8 -1      xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util/Type.java
  
  Index: Type.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util/Type.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Type.java	2001/06/18 09:34:12	1.5
  +++ Type.java	2001/08/28 12:43:08	1.6
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: Type.java,v 1.5 2001/06/18 09:34:12 morten Exp $
  + * @(#)$Id: Type.java,v 1.6 2001/08/28 12:43:08 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -225,6 +225,13 @@
   	classGen
   	    .getParser()
   	    .notYetImplemented(toString() + " -> unboxed " + toString());
  +    }
  +
  +    /**
  +     * Returns the class name of an internal type's external representation.
  +     */
  +    public String getClassName() {
  +	return(EMPTYSTRING);
       }
   
       public Instruction ADD() {
  
  
  

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