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/09/24 14:27:39 UTC

cvs commit: xml-xalan/java/src/org/apache/xalan/xsltc/compiler Import.java Param.java Stylesheet.java

morten      01/09/24 05:27:39

  Modified:    java/src/org/apache/xalan/xsltc/compiler Import.java
                        Param.java Stylesheet.java
  Log:
  Fix for resolving mutiple defined global parameters and variables. The
  Import class has been fixed to set import precedences properly, and the
  Param class has been changed to use the import precedence to resolve
  between multiple definitions of the same variable/parameter.
  PR:		bugzilla 3404
  Obtained from:	n/a
  Submitted by:	morten@xml.apache.org
  Reviewed by:	morten@xml.apache.org
  
  Revision  Changes    Path
  1.10      +2 -1      xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Import.java
  
  Index: Import.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Import.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- Import.java	2001/09/06 13:45:06	1.9
  +++ Import.java	2001/09/24 12:27:39	1.10
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: Import.java,v 1.9 2001/09/06 13:45:06 tmiller Exp $
  + * @(#)$Id: Import.java,v 1.10 2001/09/24 12:27:39 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -120,6 +120,7 @@
   	    _imported.setSourceLoader(loader);
   	    _imported.setSystemId(docToLoad);
   	    _imported.setParentStylesheet(context);
  +	    _imported.setImportingStylesheet(context);
   
   	    // precedence for the including stylesheet
   	    final int currPrecedence = parser.getCurrentImportPrecedence();
  
  
  
  1.13      +52 -24    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.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- Param.java	2001/09/17 08:20:54	1.12
  +++ Param.java	2001/09/24 12:27:39	1.13
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: Param.java,v 1.12 2001/09/17 08:20:54 morten Exp $
  + * @(#)$Id: Param.java,v 1.13 2001/09/24 12:27:39 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -122,7 +122,7 @@
   	    reportError(this, parser, ErrorMsg.NREQATTR_ERR, "name");
           }
   
  -	// check whether variable/param of the same name is already in scope
  +	// Check whether variable/param of the same name is already in scope
   	if (parser.lookupVariable(_name) != null) {
   	    ErrorMsg msg = new ErrorMsg(ErrorMsg.VARREDEF_ERR, _name, this);
   	    parser.reportError(Constants.ERROR, msg);
  @@ -139,9 +139,35 @@
   	// Add a ref to this param to its enclosing construct
   	final SyntaxTreeNode parent = getParent();
   	if (parent instanceof Stylesheet) {
  +	    // Mark this as a global parameter
   	    _isLocal = false;
  +	    // Check if a global variable with this name already exists...
  +	    Param param = parser.getSymbolTable().lookupParam(_name);
  +	    // ...and if it does we need to check import precedence
  +	    if (param != null) {
  +		final int us = this.getImportPrecedence();
  +		final int them = param.getImportPrecedence();
  +		// It is an error if the two have the same import precedence
  +		if (us == them) {
  +		    System.err.println("FOOOOOOOOOOOOOO!");
  +		    System.err.println("us = "+this);
  +		    System.err.println("us parent = "+
  +				       ((Stylesheet)getParent()).getSystemId());
  +		    System.err.println("us prec. = "+us);
  +		    System.err.println("them = "+param);
  +		    System.err.println("them parent = "+
  +				       ((Stylesheet)param.getParent()).getSystemId());
  +		    System.err.println("them prec = "+them);
  +		    reportError(this, parser, ErrorMsg.VARREDEF_ERR,
  +				_name.toString());
  +		}
  +		// Ignore this if previous definition has higher precedence
  +		else if (them > us) {
  +		    return;
  +		}
  +	    }
  +	    // Add this variable if we have higher precedence
   	    ((Stylesheet)parent).addParam(this);
  -	    //!! check for redef
   	    parser.getSymbolTable().addParam(this);
   	}
   	else if (parent instanceof Template) {
  @@ -216,28 +242,30 @@
   	    }
   	}
   	else {
  -	    classGen.addField(new Field(ACC_PUBLIC, cpg.addUtf8(name),
  -					cpg.addUtf8(signature),
  -					null, cpg.getConstantPool()));
  -	    il.append(classGen.loadTranslet());
  -	    il.append(DUP);
  -	    il.append(new PUSH(cpg, name));
  -	    translateValue(classGen, methodGen);
  -	    il.append(new PUSH(cpg, true));
  -
  -	    // Call addParameter() from this class
  -	    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)));
  +	    if (classGen.containsField(name) == null) {
  +		classGen.addField(new Field(ACC_PUBLIC, cpg.addUtf8(name),
  +					    cpg.addUtf8(signature),
  +					    null, cpg.getConstantPool()));
  +		il.append(classGen.loadTranslet());
  +		il.append(DUP);
  +		il.append(new PUSH(cpg, name));
  +		translateValue(classGen, methodGen);
  +		il.append(new PUSH(cpg, true));
  +
  +		// Call addParameter() from this class
  +		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)));
   	    }
  -	    il.append(new PUTFIELD(cpg.addFieldref(classGen.getClassName(),
  -						   name, signature)));
   	}
       }
   
  
  
  
  1.17      +34 -5     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.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- Stylesheet.java	2001/08/27 09:07:19	1.16
  +++ Stylesheet.java	2001/09/24 12:27:39	1.17
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: Stylesheet.java,v 1.16 2001/08/27 09:07:19 morten Exp $
  + * @(#)$Id: Stylesheet.java,v 1.17 2001/09/24 12:27:39 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -110,6 +110,7 @@
       private final Hashtable _modes = new Hashtable();
       private final Hashtable _extensions = new Hashtable();
   
  +    public  Stylesheet _importedFrom = null;
       private int _importPrecedence = 1;
       private Mode _defaultMode;
       private boolean _multiDocument = false;
  @@ -136,10 +137,11 @@
   	_multiDocument = flag;
       }
   
  -    public boolean isMultiDOM() {
  +    public boolean isMultiDocument() {
   	return _multiDocument;
       }
   
  +    /*
       public boolean isImported() {
   	final SyntaxTreeNode parent = getParent();
   	return ((parent != null) && (parent instanceof Import));
  @@ -149,14 +151,17 @@
   	final SyntaxTreeNode parent = getParent();
   	return ((parent != null) && (parent instanceof Include));
       }
  +    */
   
       public void numberFormattingUsed() {
   	_numberFormattingUsed = true;
       }
   
       public void setImportPrecedence(final int precedence) {
  +	// Set import precedence for this stylesheet
   	_importPrecedence = precedence;
   
  +	// Set import precedence for all included stylesheets
   	final Enumeration elements = elements();
   	while (elements.hasMoreElements()) {
   	    final TopLevelElement child =
  @@ -169,6 +174,14 @@
   	    }
   	}
   
  +	// Set import precedence for the stylesheet that imported this one
  +	if (_importedFrom != null) {
  +	    if (_importedFrom.getImportPrecedence() < precedence) {
  +		final Parser parser = getParser();
  +		final int nextPrecedence = parser.getNextImportPrecedence();
  +		_importedFrom.setImportPrecedence(nextPrecedence);
  +	    }
  +	}
       }
       
       public int getImportPrecedence() {
  @@ -199,6 +212,10 @@
   	return _parentStylesheet;
       }
   
  +    public void setImportingStylesheet(Stylesheet parent) {
  +	_importedFrom = parent;
  +    }
  +
       public void setSystemId(String systemId) {
   	_systemId = systemId;
       }
  @@ -328,6 +345,16 @@
   	// variables and/or parameters before we parse the other elements...
   	for (int i=0; i<count; i++) {
   	    SyntaxTreeNode child = (SyntaxTreeNode)contents.elementAt(i);
  +	    if ((child instanceof Import) || (child instanceof Include)) {
  +		parser.getSymbolTable().setCurrentNode(child);
  +		child.parseContents(parser);
  +	    }
  +	}
  +
  +	// We have to scan the stylesheet element's top-level elements for
  +	// variables and/or parameters before we parse the other elements...
  +	for (int i=0; i<count; i++) {
  +	    SyntaxTreeNode child = (SyntaxTreeNode)contents.elementAt(i);
   	    if (child instanceof VariableBase) {
   		parser.getSymbolTable().setCurrentNode(child);
   		child.parseContents(parser);
  @@ -337,7 +364,9 @@
   	// Now go through all the other top-level elements...
   	for (int i=0; i<count; i++) {
   	    SyntaxTreeNode child = (SyntaxTreeNode)contents.elementAt(i);
  -	    if (!(child instanceof VariableBase)) {
  +	    if (!(child instanceof VariableBase) &&
  +		!(child instanceof Import) &&
  +		!(child instanceof Include)) {
   		parser.getSymbolTable().setCurrentNode(child);
   		child.parseContents(parser);
   	    }
  @@ -752,7 +781,7 @@
   	il.append(classGen.loadTranslet());
   	// prepare appropriate DOM implementation
   	
  -	if (isMultiDOM()) {
  +	if (isMultiDocument()) {
   	    il.append(new NEW(cpg.addClass(MULTI_DOM_CLASS)));
   	    il.append(DUP);
   	}
  @@ -765,7 +794,7 @@
   						     DOM_ADAPTER_SIG)));
   	// DOMAdapter is on the stack
   
  -	if (isMultiDOM()) {
  +	if (isMultiDocument()) {
   	    final int init = cpg.addMethodref(MULTI_DOM_CLASS,
   					      "<init>",
   					      "("+DOM_INTF_SIG+")V");
  
  
  

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