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/10/18 11:43:44 UTC
cvs commit: xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util ErrorMsg.java
morten 01/10/18 02:43:44
Modified: java/src/org/apache/xalan/xsltc/compiler CallTemplate.java
DecimalFormatting.java Param.java SymbolTable.java
Template.java Variable.java VariableBase.java
WithParam.java
java/src/org/apache/xalan/xsltc/compiler/util ErrorMsg.java
Log:
Cleaned up the compiler's symbol table. Added support for detecting multiple
defined decimal formatting symbols.
PR: bugzilla 3872
Obtained from: n/a
Submitted by: morten@xml.apache.org
Reviewed by: morten@xml.apache.org
Revision Changes Path
1.6 +16 -19 xml-xalan/java/src/org/apache/xalan/xsltc/compiler/CallTemplate.java
Index: CallTemplate.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/CallTemplate.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- CallTemplate.java 2001/08/27 09:07:19 1.5
+++ CallTemplate.java 2001/10/18 09:43:44 1.6
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: CallTemplate.java,v 1.5 2001/08/27 09:07:19 morten Exp $
+ * @(#)$Id: CallTemplate.java,v 1.6 2001/10/18 09:43:44 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -117,23 +117,21 @@
final ConstantPoolGen cpg = classGen.getConstantPool();
final InstructionList il = methodGen.getInstructionList();
- // Push a new parameter frame
- if (stylesheet.hasLocalParams() || hasContents()) {
- il.append(classGen.loadTranslet()); // push param frame
- il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS,
- PUSH_PARAM_FRAME,
- PUSH_PARAM_FRAME_SIG)
- ));
- // translate with-params
+ if (stylesheet.hasLocalParams() || hasContents()) {
+ // Push parameter frame
+ final int push = cpg.addMethodref(TRANSLET_CLASS,
+ PUSH_PARAM_FRAME,
+ PUSH_PARAM_FRAME_SIG);
+ il.append(classGen.loadTranslet());
+ il.append(new INVOKEVIRTUAL(push));
+ // Translate with-params
translateContents(classGen, methodGen);
}
final String className = stylesheet.getClassName();
// Generate a valid Java method name
- String methodName = _name.toString();
- methodName = methodName.replace('.', '$');
- methodName = methodName.replace('-', '$');
+ String methodName = EscapeString.escape(_name.toString());
il.append(classGen.loadTranslet());
il.append(methodGen.loadDOM());
@@ -150,14 +148,13 @@
+")V")));
- // Pop parameter frame
if (stylesheet.hasLocalParams() || hasContents()) {
- il.append(classGen.loadTranslet()); // pop param frame
- il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS,
- POP_PARAM_FRAME,
- POP_PARAM_FRAME_SIG)
- ));
-
+ // Pop parameter frame
+ final int pop = cpg.addMethodref(TRANSLET_CLASS,
+ POP_PARAM_FRAME,
+ POP_PARAM_FRAME_SIG);
+ il.append(classGen.loadTranslet());
+ il.append(new INVOKEVIRTUAL(pop));
}
}
}
1.5 +22 -2 xml-xalan/java/src/org/apache/xalan/xsltc/compiler/DecimalFormatting.java
Index: DecimalFormatting.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/DecimalFormatting.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DecimalFormatting.java 2001/06/06 10:44:52 1.4
+++ DecimalFormatting.java 2001/10/18 09:43:44 1.5
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: DecimalFormatting.java,v 1.4 2001/06/06 10:44:52 morten Exp $
+ * @(#)$Id: DecimalFormatting.java,v 1.5 2001/10/18 09:43:44 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -84,11 +84,31 @@
private static final String DFS_CLASS = "java.text.DecimalFormatSymbols";
private static final String DFS_SIG = "Ljava/text/DecimalFormatSymbols;";
+ private String _name = null;
+
+ /**
+ * No type check needed for the <xsl:decimal-formatting/> element
+ */
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
return Type.Void;
}
/**
+ * Parse the name of the <xsl:decimal-formatting/> element
+ */
+ public void parseContents(Parser parser) {
+ // Get the name of these decimal formatting symbols
+ if ((_name = getAttribute("name")) == null) _name = EMPTYSTRING;
+
+ // Check if a set of symbols has already been registered under this name
+ SymbolTable stable = parser.getSymbolTable();
+ if (stable.getDecimalFormatting(_name) != null)
+ reportWarning(this, parser, ErrorMsg.DFSREDEF_ERR,_name.toString());
+ else
+ stable.addDecimalFormatting(_name, this);
+ }
+
+ /**
* This method is called when the constructor is compiled in
* Stylesheet.compileConstructor() and not as the syntax tree is traversed.
*/
@@ -102,7 +122,7 @@
// Push the format name on the stack for call to addDecimalFormat()
il.append(classGen.loadTranslet());
- il.append(new PUSH(cpg, getAttribute("name")));
+ il.append(new PUSH(cpg, _name));
// Manufacture a DecimalFormatSymbols on the stack
// for call to addDecimalFormat()
1.17 +3 -32 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.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- Param.java 2001/09/25 16:20:39 1.16
+++ Param.java 2001/10/18 09:43:44 1.17
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: Param.java,v 1.16 2001/09/25 16:20:39 morten Exp $
+ * @(#)$Id: Param.java,v 1.17 2001/10/18 09:43:44 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -100,42 +100,13 @@
}
/**
- * 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) {
- setName(parser.getQName(name));
- }
- else {
- reportError(this, parser, ErrorMsg.NREQATTR_ERR, "name");
- }
-
- // 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);
- }
-
- select = getAttribute("select");
- if (select.length() > 0) {
- _select = getParser().parseExpression(this, "select", null);
- }
-
- // Children must be parsed first -> static scoping
- parseChildren(parser);
+ // Parse 'name' and 'select' attributes plus parameter contents
+ super.parseContents(parser);
// Add a ref to this param to its enclosing construct
final SyntaxTreeNode parent = getParent();
1.5 +55 -21 xml-xalan/java/src/org/apache/xalan/xsltc/compiler/SymbolTable.java
Index: SymbolTable.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/SymbolTable.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SymbolTable.java 2001/06/19 10:44:11 1.4
+++ SymbolTable.java 2001/10/18 09:43:44 1.5
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: SymbolTable.java,v 1.4 2001/06/19 10:44:11 morten Exp $
+ * @(#)$Id: SymbolTable.java,v 1.5 2001/10/18 09:43:44 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -58,6 +58,7 @@
*
* @author Jacek Ambroziak
* @author Santiago Pericas-Geertsen
+ * @author Morten Jorgensen
*
*/
@@ -71,17 +72,28 @@
import org.apache.xalan.xsltc.compiler.util.*;
final class SymbolTable {
- private final Hashtable _templates = new Hashtable();
+
+ // These hashtables are used for all stylesheets
private final Hashtable _stylesheets = new Hashtable();
private final Hashtable _primops = new Hashtable();
- private final Hashtable _variables = new Hashtable();
- private final Hashtable _atsets = new Hashtable();
- private final Hashtable _namespaces = new Hashtable();
- private final Hashtable _prefixes = new Hashtable();
- private final Hashtable _aliases = new Hashtable();
- private final Hashtable _excludedURI = new Hashtable();
- private int nsCounter = 0;
+ // These hashtables are used for some stylesheets
+ private Hashtable _variables = null;
+ private Hashtable _templates = null;
+ private Hashtable _attributeSets = null;
+ private Hashtable _aliases = null;
+ private Hashtable _excludedURI = null;
+ private Hashtable _decimalFormats = null;
+
+ public DecimalFormatting getDecimalFormatting(String name) {
+ if (_decimalFormats == null) return null;
+ return((DecimalFormatting)_decimalFormats.get(name));
+ }
+
+ public void addDecimalFormatting(String name, DecimalFormatting symbols) {
+ if (_decimalFormats == null) _decimalFormats = new Hashtable();
+ _decimalFormats.put(name, symbols);
+ }
public Stylesheet addStylesheet(QName name, Stylesheet node) {
return (Stylesheet)_stylesheets.put(name, node);
@@ -94,47 +106,56 @@
public Template addTemplate(Template template) {
final QName name = template.getName();
name.clearDefaultNamespace();
+ if (_templates == null) _templates = new Hashtable();
return (Template)_templates.put(name, template);
}
public Template lookupTemplate(QName name) {
+ if (_templates == null) return null;
name.clearDefaultNamespace();
return (Template)_templates.get(name);
}
public Variable addVariable(Variable variable) {
+ if (_variables == null) _variables = new Hashtable();
final String name = variable.getName().getStringRep();
return (Variable)_variables.put(name, variable);
}
public Param addParam(Param parameter) {
+ if (_variables == null) _variables = new Hashtable();
final String name = parameter.getName().getStringRep();
return (Param)_variables.put(name, parameter);
}
public Variable lookupVariable(QName qname) {
+ if (_variables == null) return null;
final String name = qname.getStringRep();
final Object obj = _variables.get(name);
return obj instanceof Variable ? (Variable)obj : null;
}
public Param lookupParam(QName qname) {
+ if (_variables == null) return null;
final String name = qname.getStringRep();
final Object obj = _variables.get(name);
return obj instanceof Param ? (Param)obj : null;
}
public SyntaxTreeNode lookupName(QName qname) {
+ if (_variables == null) return null;
final String name = qname.getStringRep();
return (SyntaxTreeNode)_variables.get(name);
}
public AttributeSet addAttributeSet(AttributeSet atts) {
- return (AttributeSet)_atsets.put(atts.getName(), atts);
+ if (_attributeSets == null) _attributeSets = new Hashtable();
+ return (AttributeSet)_attributeSets.put(atts.getName(), atts);
}
public AttributeSet lookupAttributeSet(QName name) {
- return (AttributeSet)_atsets.get(name);
+ if (_attributeSets == null) return null;
+ return (AttributeSet)_attributeSets.get(name);
}
/**
@@ -162,30 +183,31 @@
* This is used for xsl:attribute elements that have a "namespace"
* attribute that is currently not defined using xmlns:
*/
+ private int _nsCounter = 0;
+
public String generateNamespacePrefix() {
- final String prefix = new String("ns"+(nsCounter++));
- return(prefix);
+ return(new String("ns"+(_nsCounter++)));
}
/**
* Use a namespace prefix to lookup a namespace URI
*/
private SyntaxTreeNode _current = null;
+
public void setCurrentNode(SyntaxTreeNode node) {
_current = node;
}
public String lookupNamespace(String prefix) {
- if (_current != null)
- return(_current.lookupNamespace(prefix));
- else
- return(Constants.EMPTYSTRING);
+ if (_current == null) return(Constants.EMPTYSTRING);
+ return(_current.lookupNamespace(prefix));
}
/**
* Adds an alias for a namespace prefix
*/
public void addPrefixAlias(String prefix, String alias) {
+ if (_aliases == null) _aliases = new Hashtable();
_aliases.put(prefix,alias);
}
@@ -193,14 +215,22 @@
* Retrieves any alias for a given namespace prefix
*/
public String lookupPrefixAlias(String prefix) {
+ if (_aliases == null) return null;
return (String)_aliases.get(prefix);
}
/**
- *
+ * Register a namespace URI so that it will not be declared in the output
+ * unless it is actually referenced in the output.
*/
public void excludeURI(String uri) {
+ // The null-namespace cannot be excluded
if (uri == null) return;
+
+ // Create new hashtable of exlcuded URIs if none exists
+ if (_excludedURI == null) _excludedURI = new Hashtable();
+
+ // Register the namespace URI
Integer refcnt = (Integer)_excludedURI.get(uri);
if (refcnt == null)
refcnt = new Integer(1);
@@ -210,7 +240,8 @@
}
/**
- *
+ * Exclude a series of namespaces given by a list of whitespace
+ * separated namespace prefixes.
*/
public void excludeNamespaces(String prefixes) {
if (prefixes != null) {
@@ -228,10 +259,11 @@
}
/**
- *
+ * Check if a namespace should not be declared in the output (unless used)
*/
public boolean isExcludedNamespace(String uri) {
if (uri == null) return false;
+ if (_excludedURI == null) return false;
final Integer refcnt = (Integer)_excludedURI.get(uri);
if (refcnt == null) return false;
if (refcnt.intValue() > 0) return true;
@@ -239,9 +271,10 @@
}
/**
- *
+ * Turn of namespace declaration exclusion
*/
public void unExcludeNamespaces(String prefixes) {
+ if (_excludedURI == null) return;
if (prefixes != null) {
StringTokenizer tokens = new StringTokenizer(prefixes);
while (tokens.hasMoreTokens()) {
@@ -257,5 +290,6 @@
}
}
}
+
}
1.11 +2 -4 xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Template.java
Index: Template.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Template.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- Template.java 2001/08/27 09:07:19 1.10
+++ Template.java 2001/10/18 09:43:44 1.11
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: Template.java,v 1.10 2001/08/27 09:07:19 morten Exp $
+ * @(#)$Id: Template.java,v 1.11 2001/10/18 09:43:44 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -314,9 +314,7 @@
if (_compiled && isNamed()){
- String methodName = _name.toString();
- methodName = methodName.replace('.', '$');
- methodName = methodName.replace('-', '$');
+ String methodName = EscapeString.escape(_name.toString());
il.append(classGen.loadTranslet());
il.append(methodGen.loadDOM());
1.20 +3 -22 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.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- Variable.java 2001/09/25 16:20:39 1.19
+++ Variable.java 2001/10/18 09:43:44 1.20
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: Variable.java,v 1.19 2001/09/25 16:20:39 morten Exp $
+ * @(#)$Id: Variable.java,v 1.20 2001/10/18 09:43:44 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -107,28 +107,9 @@
* Parse the contents of the variable
*/
public void parseContents(Parser parser) {
- // parse attributes name and select (if present)
- final String name = getAttribute("name");
- if (name.length() > 0) {
- setName(parser.getQName(name));
- }
- else {
- reportError(this, parser, ErrorMsg.NREQATTR_ERR, "name");
- }
-
- // check whether variable/param of the same name is already in scope
- if (parser.lookupVariable(_name) != null) {
- reportError(this, parser, ErrorMsg.VARREDEF_ERR, _name.toString());
- }
-
- select = getAttribute("select");
- if (select.length() > 0) {
- _select = getParser().parseExpression(this, "select", null);
- }
-
- // Children must be parsed first -> static scoping
- parseChildren(parser);
+ // Parse 'name' and 'select' attributes plus parameter contents
+ super.parseContents(parser);
// Add a ref to this var to its enclosing construct
SyntaxTreeNode parent = getParent();
1.8 +30 -29 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.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- VariableBase.java 2001/09/25 15:57:22 1.7
+++ VariableBase.java 2001/10/18 09:43:44 1.8
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: VariableBase.java,v 1.7 2001/09/25 15:57:22 morten Exp $
+ * @(#)$Id: VariableBase.java,v 1.8 2001/10/18 09:43:44 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -85,7 +85,6 @@
protected Instruction _loadInstruction; // Instruction to load JVM variable
protected Expression _select; // Reference to variable expression
protected String select; // Textual repr. of variable expr.
- protected int _stackIndex = -1; // Stack index relative to base ptr.
// References to this variable (when local)
protected Vector _refs = new Vector(2);
@@ -202,39 +201,13 @@
return _variable;
}
- public 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;
+ _variable = EscapeString.escape(name.getLocalPart());
}
/**
@@ -242,6 +215,34 @@
*/
public boolean isLocal() {
return _isLocal;
+ }
+
+ /**
+ * Parse the contents of the <xsl:decimal-format> element.
+ */
+ public void parseContents(Parser parser) {
+ // Get the 'name attribute
+ String name = getAttribute("name");
+ if (name == null) name = EMPTYSTRING;
+
+ if (name.length() > 0)
+ setName(parser.getQName(name));
+ else
+ reportError(this, parser, ErrorMsg.NREQATTR_ERR, "name");
+
+ // 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);
+ }
+
+ select = getAttribute("select");
+ if (select.length() > 0) {
+ _select = getParser().parseExpression(this, "select", null);
+ }
+
+ // Children must be parsed first -> static scoping
+ parseChildren(parser);
}
/**
1.7 +2 -9 xml-xalan/java/src/org/apache/xalan/xsltc/compiler/WithParam.java
Index: WithParam.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/WithParam.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- WithParam.java 2001/09/20 14:55:42 1.6
+++ WithParam.java 2001/10/18 09:43:44 1.7
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: WithParam.java,v 1.6 2001/09/20 14:55:42 morten Exp $
+ * @(#)$Id: WithParam.java,v 1.7 2001/10/18 09:43:44 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -149,13 +149,6 @@
}
}
- private String escapeName(QName qname) {
- String local = qname.getLocalPart();
- local = Variable.replace(local, '.', "$dot$");
- local = Variable.replace(local, '-', "$dash$");
- return(local);
- }
-
/**
* This code generates a sequence of bytecodes that call the
* addParameter() method in AbstractTranslet. The method call will add
@@ -166,7 +159,7 @@
final InstructionList il = methodGen.getInstructionList();
// Make name acceptable for use as field name in class
- String name = escapeName(_name);
+ String name = EscapeString.escape(_name.getLocalPart());
// Load reference to the translet (method is in AbstractTranslet)
il.append(classGen.loadTranslet());
1.5 +4 -2 xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util/ErrorMsg.java
Index: ErrorMsg.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util/ErrorMsg.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ErrorMsg.java 2001/08/27 09:07:21 1.4
+++ ErrorMsg.java 2001/10/18 09:43:44 1.5
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: ErrorMsg.java,v 1.4 2001/08/27 09:07:21 morten Exp $
+ * @(#)$Id: ErrorMsg.java,v 1.5 2001/10/18 09:43:44 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -100,6 +100,7 @@
public static final int ILL_ATTR_ERR = 20;
public static final int CIRCULAR_INC = 21;
public static final int TREESORT_ERR = 22;
+ public static final int DFSREDEF_ERR = 23;
static final String messages_d[] = {
"More than one stylesheet defined in the same file.",
@@ -126,7 +127,8 @@
"Circular import/include. Stylesheet ''{0}'' already loaded.",
"Applying <xsl:sort> to a result tree is not supported (<xsl:sort> "+
"elements are ignored). You can, and should, sort the nodes when "+
- "creating the result tree."
+ "creating the result tree.",
+ "Decimal formatting ''{0}'' is already defined."
};
public ErrorMsg(int code) {
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org