santiagopg 2003/01/24 11:37:00
Modified: java/src/org/apache/xalan/xsltc/cmdline Tag: xslt20
Compile.java
java/src/org/apache/xalan/xsltc/compiler Tag: xslt20
AttributeSet.java CompilerContext.java
Constants.java DecimalFormatting.java
DocumentCall.java FormatNumberCall.java
FunctionCall.java Import.java Include.java
LiteralElement.java Mode.java Number.java
Output.java Parser.java Predicate.java QName.java
Sort.java StaticContext.java Step.java
StepPattern.java Stylesheet.java
SyntaxTreeNode.java Template.java
UnionPathExpr.java UnresolvedRef.java Variable.java
VariableBase.java Whitespace.java XSLTC.java
XslAttribute.java XslElement.java xpath.cup
java/src/org/apache/xalan/xsltc/compiler/util Tag: xslt20
ErrorMsg.java
java/src/org/apache/xalan/xsltc/trax Tag: xslt20
TemplatesHandlerImpl.java
TransformerFactoryImpl.java
Removed: java/src/org/apache/xalan/xsltc/compiler Tag: xslt20
CompilerContextImpl.java StaticContextImpl.java
Log:
More global changes for XSLTC in xslt20 branch
Revision Changes Path
No revision
No revision
1.11.2.1.2.3 +10 -10
xml-xalan/java/src/org/apache/xalan/xsltc/cmdline/Compile.java
Index: Compile.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/cmdline/Compile.java,v
retrieving revision 1.11.2.1.2.2
retrieving revision 1.11.2.1.2.3
diff -u -r1.11.2.1.2.2 -r1.11.2.1.2.3
--- Compile.java 10 Jan 2003 16:50:37 -0000 1.11.2.1.2.2
+++ Compile.java 24 Jan 2003 19:36:47 -0000 1.11.2.1.2.3
@@ -84,24 +84,24 @@
private static int VERSION_MAJOR = 1;
private static int VERSION_MINOR = 2;
private static int VERSION_DELTA = 1;
-
- // This variable should be set to false to prevent any methods in this
+
+ // This variable should be set to false to prevent any methods in this
// class from calling System.exit(). As this is a command-line tool,
// calling System.exit() is normally OK, but we also want to allow for
// this class being used in other ways as well.
private static boolean _allowExit = true;
public static void printUsage() {
- StringBuffer vers = new StringBuffer("XSLTC version " +
- VERSION_MAJOR + "." + VERSION_MINOR +
+ StringBuffer vers = new StringBuffer("XSLTC version " +
+ VERSION_MAJOR + "." + VERSION_MINOR +
((VERSION_DELTA > 0) ? ("."+VERSION_DELTA) : ("")));
- System.err.println(vers + "\n" +
+ System.err.println(vers + "\n" +
new ErrorMsg(ErrorMsg.COMPILE_USAGE_STR));
if (_allowExit) System.exit(-1);
}
- /**
+ /**
* This method implements the command line compiler. See the USAGE_STRING
* constant for a description. It may make sense to move the command-line
* handling to a separate package (ie. make one xsltc.cmdline.Compiler
@@ -135,7 +135,7 @@
case 'p':
xsltc.setPackageName(getopt.getOptionArg());
break;
- case 'j':
+ case 'j':
xsltc.setJarFileName(getopt.getOptionArg());
break;
case 'x':
@@ -148,14 +148,14 @@
_allowExit = false;
break;
case 'n':
- xsltc.setTemplateInlining(true); // used to be 'false'
+ xsltc.getCompilerContext().setTemplateInlining(true);
break;
case 'v':
// fall through to case h
case 'h':
default:
printUsage();
- break;
+ break;
}
}
No revision
No revision
1.12.2.1.2.5 +9 -3
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/AttributeSet.java
Index: AttributeSet.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/AttributeSet.java,v
retrieving revision 1.12.2.1.2.4
retrieving revision 1.12.2.1.2.5
diff -u -r1.12.2.1.2.4 -r1.12.2.1.2.5
--- AttributeSet.java 15 Jan 2003 14:43:03 -0000 1.12.2.1.2.4
+++ AttributeSet.java 24 Jan 2003 19:36:50 -0000 1.12.2.1.2.5
@@ -78,6 +78,12 @@
final class AttributeSet extends TopLevelElement {
+ /**
+ * A thread local variable that holds a serial number for
+ * attribute sets.
+ */
+ static private SerialNumber _attributeSetSerial = new SerialNumber(0);
+
// This prefix is used for the method name of attribute set methods
private static final String AttributeSetPrefix = "$as$";
@@ -119,7 +125,7 @@
*/
public void parse(CompilerContext ccontext) {
final Parser parser = ccontext.getParser();
- final StaticContextImpl scontext = getStaticContext();
+ final StaticContext scontext = getStaticContext();
// Get this attribute set's name
_name = parser.getQNameIgnoreDefaultNs(getAttribute("name"));
@@ -166,7 +172,7 @@
// _mergeSet Point to any previous definition of this attribute set
_mergeSet = getStaticContext().addAttributeSet(this);
- _method = AttributeSetPrefix + getXSLTC().nextAttributeSetSerial();
+ _method = AttributeSetPrefix + _attributeSetSerial.getNextValue();
if (_useSets != null) _useSets.typeCheck(ccontext);
typeCheckContents(ccontext);
1.1.2.3 +291 -9
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Attic/CompilerContext.java
Index: CompilerContext.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Attic/CompilerContext.java,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -r1.1.2.2 -r1.1.2.3
--- CompilerContext.java 15 Jan 2003 14:43:04 -0000 1.1.2.2
+++ CompilerContext.java 24 Jan 2003 19:36:51 -0000 1.1.2.3
@@ -62,37 +62,319 @@
package org.apache.xalan.xsltc.compiler;
+import java.util.HashMap;
+import java.util.ArrayList;
+
+import org.apache.xalan.xsltc.DOM;
import org.apache.xalan.xsltc.compiler.codemodel.CmClassDecl;
import org.apache.xalan.xsltc.compiler.codemodel.CmMethodDecl;
-interface CompilerContext {
+public class CompilerContext {
+
+ /**
+ * A thread local variable that holds the compiler context. Multiple
+ * calls to getInstance() will return the same variable.
+ */
+ static private ThreadLocal _compilerContext = new ThreadLocal();
+
+ /**
+ * A reference to the XSLTC object.
+ */
+ private XSLTC _xsltc;
+
+ /**
+ * A reference to the parser object.
+ */
+ private Parser _parser;
+
+ /**
+ * The method getInstance() should be used instead.
+ */
+ private CompilerContext() {
+ init();
+ }
+
+ /**
+ * Resets the state of the compiler context.
+ */
+ public void init() {
+ _nextGType = DOM.NTYPES;
+ _elements = new HashMap();
+ _attributes = new HashMap();
+ _namespaces = new HashMap();
+ _namespaces.put("", new Integer(_nextNSType));
+ _namesIndex = new ArrayList(128);
+ _namespaceIndex = new ArrayList(32);
+ }
+
+ /**
+ * This method must be called the first time an instance of the
+ * compiler context is created to ensure that a reference to the
+ * parser is provided.
+ */
+ static CompilerContext getInstance(XSLTC xsltc) {
+ CompilerContext result = (CompilerContext) _compilerContext.get();
+ if (result == null) {
+ _compilerContext.set(result = new CompilerContext());
+ }
+ result._xsltc = xsltc;
+ result._parser = xsltc.getParser();
+ return result;
+ }
+
+ /**
+ * This method can be called to obtain a instance to the compiler
+ * context after getInstance(XSLTC) has been invoked (otherwise
+ * it will throw an exception).
+ */
+ static CompilerContext getInstance() {
+ CompilerContext result = (CompilerContext) _compilerContext.get();
+ if (result == null) {
+ throw new IllegalStateException(
+ "CompilerContext.getInstance(XSLTC) must be called first.");
+ }
+ return (CompilerContext) _compilerContext.get();
+ }
/**
* Returns a reference to the XSLTC object.
*/
- public XSLTC getXSLTC();
+ public XSLTC getXSLTC() {
+ return _xsltc;
+ }
/**
* Returns a reference to the parser object.
*/
- public Parser getParser();
+ public Parser getParser() {
+ return _parser;
+ }
+
+ // -- Current CM Class ----------------------------------------------
+
+ /**
+ * A reference to the "current" codemodel class object.
+ */
+ private CmClassDecl _currentClass;
/**
* Returns a reference to the "current" class object from the
* codemodel package.
*/
- public CmClassDecl getCurrentClass();
+ public CmClassDecl getCurrentClass() {
+ return _currentClass;
+ }
+
+ /**
+ * Set the current codemodel class object. This method must be
+ * called whenever a new class is generated.
+ */
+ public void setCurrentClass(CmClassDecl currentClass) {
+ _currentClass = currentClass;
+ }
+
+ // -- Current CM Method ----------------------------------------------
+
+ /**
+ * A refernece to the "current" codemodel method object.
+ */
+ private CmMethodDecl _currentMethod;
/**
* Returns a reference to the "current" method object from the
* codemodel package.
*/
- public CmMethodDecl getCurrentMethod();
+ public CmMethodDecl getCurrentMethod() {
+ return _currentMethod;
+ }
/**
- * Returns a fresh namespace prefix (used by xsl:attribute and
- * xsl:element).
+ * Set the current codemodel method object. This method must be
+ * called whenever a new method is generated.
*/
- public String generateNamespacePrefix();
-}
+ public void setCurrentMethod(CmMethodDecl currentMethod) {
+ _currentMethod = currentMethod;
+ }
+
+ // -- Fresh NS prefixes -----------------------------------------------
+
+ /**
+ * 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 getFreshNsPrefix() {
+ return new String("ns" + _nsCounter++);
+ }
+
+ // -- Template inlining -----------------------------------------------
+
+ private boolean _templateInlining = false;
+
+ public boolean getTemplateInlining() {
+ return _templateInlining;
+ }
+
+ public void setTemplateInlining(boolean value) {
+ _templateInlining = value;
+ }
+
+ // -- Nodeset call ----------------------------------------------------
+
+ private boolean _callsNodeset = false;
+
+ public boolean getCallsNodeset() {
+ return _callsNodeset;
+ }
+
+ public void setCallsNodeset(boolean value) {
+ _callsNodeset = value;
+ }
+
+ // -- Multi-document --------------------------------------------------
+
+ private boolean _multiDocument = false;
+ public boolean getMultiDocument() {
+ return _multiDocument;
+ }
+
+ public void setMultiDocument(boolean value) {
+ _multiDocument = value;
+ }
+
+ // -- Fresh helper class names ---------------------------------------
+
+ private int _helperClassSerial = 0;
+
+ public String getFreshClassName() {
+ return new String(_xsltc.getClassName() + _helperClassSerial++);
+ }
+
+ // -- Name mapping ---------------------------------------------------
+
+ /**
+ * Next available attribute/element type.
+ */
+ private int _nextGType;
+
+ /**
+ * Mapping between expanded element qnames (Strings) and generalized
+ * types (Integers).
+ */
+ private HashMap _elements;
+
+ /**
+ * Mapping between expanded attribute qnames (Strings) and generalized
+ * types (Integers).
+ */
+ private HashMap _attributes;
+
+ /**
+ * List of all elements that are known at compile. Can be regarded
+ * as a reverse mapping between generalized types and expanded
+ * qnames (by adding DOM.NTYPES to the index).
+ */
+ private ArrayList _namesIndex;
+
+ /**
+ * Next available namespace type.
+ */
+ private int _nextNSType;
+
+ /**
+ * Mapping between namespace URIs (Strings) and generalized
+ * NS types (Integers).
+ */
+ private HashMap _namespaces;
+
+ /**
+ * List of all namespace URIs that are known at compile. Can be
+ * regarded as a reverse mapping between generalized types and
+ * expanded qnames.
+ */
+ private ArrayList _namespaceIndex;
+
+ /**
+ * Registers an attribute and gives it a type so that it can be
+ * mapped to DOM attribute types at run-time.
+ */
+ public int registerAttribute(QName name) {
+ String expandedQName = name.toString();
+ Integer code = (Integer)_attributes.get(expandedQName);
+
+ if (code == null) {
+ code = new Integer(_nextGType++);
+ _attributes.put(name.toString(), code);
+
+ // Insert a '@' between ':' and local part
+ final String uri = name.getNamespace();
+ final String local = "@" + name.getLocalPart();
+ if (uri != null && uri.length() > 0) {
+ _namesIndex.add(uri + ":" + local);
+ }
+ else {
+ _namesIndex.add(local);
+ }
+
+ if (name.getLocalPart().equals("*")) {
+ registerNamespace(name.getNamespace());
+ }
+ }
+ return code.intValue();
+ }
+
+ /**
+ * Registers an element and gives it a type so that it can be
+ * mapped to DOM element types at run-time.
+ */
+ public int registerElement(QName name) {
+ // Register element (full QName)
+ Integer code = (Integer)_elements.get(name.toString());
+ if (code == null) {
+ _elements.put(name.toString(), code = new Integer(_nextGType++));
+ _namesIndex.add(name.toString());
+ }
+ if (name.getLocalPart().equals("*")) {
+ registerNamespace(name.getNamespace());
+ }
+ return code.intValue();
+ }
+
+ /**
+ * Registers a namespace and gives it a type so that it can be mapped to
+ * DOM namespace types at run-time.
+ */
+ public int registerNamespace(String namespaceURI) {
+ Integer code = (Integer)_namespaces.get(namespaceURI);
+ if (code == null) {
+ code = new Integer(_nextNSType++);
+ _namespaces.put(namespaceURI,code);
+ _namespaceIndex.add(namespaceURI);
+ }
+ return code.intValue();
+ }
+
+ /**
+ * Registers a namespace prefix. This is needed to handle an XPath
+ * expression of the form "namespace::prefix".
+ */
+ public int registerPrefix(String prefix) {
+ return 0; // TODO
+ }
+
+ /**
+ * Returns the list of statically known element/attribute names.
+ */
+ public ArrayList getNamesIndex() {
+ return _namesIndex;
+ }
+
+ /**
+ * Returns the list of statically known namespace URIs.
+ */
+ public ArrayList getNamespaceIndex() {
+ return _namespaceIndex;
+ }
+}
1.24.2.1.2.2 +133 -121
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Constants.java
Index: Constants.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Constants.java,v
retrieving revision 1.24.2.1.2.1
retrieving revision 1.24.2.1.2.2
diff -u -r1.24.2.1.2.1 -r1.24.2.1.2.2
--- Constants.java 2 Dec 2002 15:51:16 -0000 1.24.2.1.2.1
+++ Constants.java 24 Jan 2003 19:36:51 -0000 1.24.2.1.2.2
@@ -92,10 +92,10 @@
public static final String TRANSLET_INTF
= "org.apache.xalan.xsltc.Translet";
- public static final String TRANSLET_INTF_SIG
+ public static final String TRANSLET_INTF_SIG
= "Lorg/apache/xalan/xsltc/Translet;";
-
- public static final String ATTRIBUTES_SIG
+
+ public static final String ATTRIBUTES_SIG
= "Lorg/apache/xalan/xsltc/runtime/Attributes;";
public static final String NODE_ITERATOR_SIG
= "Lorg/apache/xalan/xsltc/NodeIterator;";
@@ -114,68 +114,68 @@
public static final String MULTI_DOM_SIG
= "Lorg/apache/xalan/xsltc/dom/MultiDOM;";
- public static final String STRING
+ public static final String STRING
= "java.lang.String";
- public static final int ACC_PUBLIC
+ public static final int ACC_PUBLIC
= org.apache.bcel.Constants.ACC_PUBLIC;
- public static final int ACC_SUPER
+ public static final int ACC_SUPER
= org.apache.bcel.Constants.ACC_SUPER;
- public static final int ACC_FINAL
+ public static final int ACC_FINAL
= org.apache.bcel.Constants.ACC_FINAL;
- public static final int ACC_PRIVATE
+ public static final int ACC_PRIVATE
= org.apache.bcel.Constants.ACC_PRIVATE;
- public static final int ACC_PROTECTED
+ public static final int ACC_PROTECTED
= org.apache.bcel.Constants.ACC_PROTECTED;
public static final int ACC_STATIC
= org.apache.bcel.Constants.ACC_STATIC;
- public static final String STRING_SIG
+ public static final String STRING_SIG
= "Ljava/lang/String;";
- public static final String STRING_BUFFER_SIG
+ public static final String STRING_BUFFER_SIG
= "Ljava/lang/StringBuffer;";
- public static final String OBJECT_SIG
+ public static final String OBJECT_SIG
= "Ljava/lang/Object;";
- public static final String DOUBLE_SIG
+ public static final String DOUBLE_SIG
= "Ljava/lang/Double;";
- public static final String INTEGER_SIG
+ public static final String INTEGER_SIG
= "Ljava/lang/Integer;";
public static final String COLLATOR_CLASS
= "java/text/Collator";
public static final String COLLATOR_SIG
= "Ljava/text/Collator;";
- public static final String NODE
+ public static final String NODE
= "int";
- public static final String NODE_ITERATOR
+ public static final String NODE_ITERATOR
= "org.apache.xalan.xsltc.NodeIterator";
public static final String NODE_ITERATOR_BASE
= "org.apache.xalan.xsltc.dom.NodeIteratorBase";
- public static final String SORT_ITERATOR
+ public static final String SORT_ITERATOR
= "org.apache.xalan.xsltc.dom.SortingIterator";
- public static final String SORT_ITERATOR_SIG
+ public static final String SORT_ITERATOR_SIG
= "Lorg.apache.xalan.xsltc.dom.SortingIterator;";
- public static final String FORWARD_POSITION_ITERATOR
+ public static final String FORWARD_POSITION_ITERATOR
= "org.apache.xalan.xsltc.dom.ForwardPositionIterator";
- public static final String NODE_SORT_RECORD
+ public static final String NODE_SORT_RECORD
= "org.apache.xalan.xsltc.dom.NodeSortRecord";
public static final String NODE_SORT_FACTORY
= "org/apache/xalan/xsltc/dom/NodeSortRecordFactory";
- public static final String NODE_SORT_RECORD_SIG
+ public static final String NODE_SORT_RECORD_SIG
= "Lorg/apache/xalan/xsltc/dom/NodeSortRecord;";
public static final String NODE_SORT_FACTORY_SIG
= "Lorg/apache/xalan/xsltc/dom/NodeSortRecordFactory;";
public static final String STRING_VALUE_HANDLER
= "org.apache.xalan.xsltc.runtime.StringValueHandler";
- public static final String STRING_VALUE_HANDLER_SIG
+ public static final String STRING_VALUE_HANDLER_SIG
= "Lorg/apache/xalan/xsltc/runtime/StringValueHandler;";
public static final String OUTPUT_HANDLER
= "org/apache/xalan/xsltc/TransletOutputHandler";
public static final String OUTPUT_HANDLER_SIG
= "Lorg/apache/xalan/xsltc/TransletOutputHandler;";
- public static final String FILTER_INTERFACE
+ public static final String FILTER_INTERFACE
= "org.apache.xalan.xsltc.dom.Filter";
- public static final String FILTER_INTERFACE_SIG
+ public static final String FILTER_INTERFACE_SIG
= "Lorg/apache/xalan/xsltc/dom/Filter;";
public static final String UNION_ITERATOR_CLASS
= "org.apache.xalan.xsltc.dom.UnionIterator";
@@ -191,65 +191,65 @@
= "org.apache.xalan.xsltc.dom.CurrentNodeListIterator";
public static final String CURRENT_NODE_LIST_FILTER
= "org.apache.xalan.xsltc.dom.CurrentNodeListFilter";
- public static final String CURRENT_NODE_LIST_ITERATOR_SIG
+ public static final String CURRENT_NODE_LIST_ITERATOR_SIG
= "Lorg/apache/xalan/xsltc/dom/CurrentNodeListIterator;";
public static final String CURRENT_NODE_LIST_FILTER_SIG
= "Lorg/apache/xalan/xsltc/dom/CurrentNodeListFilter;";
- public static final String FILTER_STEP_ITERATOR
+ public static final String FILTER_STEP_ITERATOR
= "org.apache.xalan.xsltc.dom.FilteredStepIterator";
- public static final String FILTER_ITERATOR
+ public static final String FILTER_ITERATOR
= "org.apache.xalan.xsltc.dom.FilterIterator";
- public static final String SINGLETON_ITERATOR
+ public static final String SINGLETON_ITERATOR
= "org.apache.xalan.xsltc.dom.SingletonIterator";
- public static final String MATCHING_ITERATOR
+ public static final String MATCHING_ITERATOR
= "org.apache.xalan.xsltc.dom.MatchingIterator";
- public static final String NODE_SIG
+ public static final String NODE_SIG
= "I";
- public static final String GET_PARENT
+ public static final String GET_PARENT
= "getParent";
- public static final String GET_PARENT_SIG
+ public static final String GET_PARENT_SIG
= "(" + NODE_SIG + ")" + NODE_SIG;
- public static final String NEXT_SIG
+ public static final String NEXT_SIG
= "()" + NODE_SIG;
- public static final String NEXT
+ public static final String NEXT
= "next";
- public static final String MAKE_NODE
+ public static final String MAKE_NODE
= "makeNode";
- public static final String MAKE_NODE_LIST
+ public static final String MAKE_NODE_LIST
= "makeNodeList";
- public static final String STRING_TO_REAL
+ public static final String STRING_TO_REAL
= "stringToReal";
- public static final String STRING_TO_REAL_SIG
+ public static final String STRING_TO_REAL_SIG
= "(" + STRING_SIG + ")D";
- public static final String STRING_TO_INT
+ public static final String STRING_TO_INT
= "stringToInt";
- public static final String STRING_TO_INT_SIG
+ public static final String STRING_TO_INT_SIG
= "(" + STRING_SIG + ")I";
- public static final String XSLT_PACKAGE
+ public static final String XSLT_PACKAGE
= "org.apache.xalan.xsltc";
- public static final String COMPILER_PACKAGE
+ public static final String COMPILER_PACKAGE
= XSLT_PACKAGE + ".compiler";
- public static final String RUNTIME_PACKAGE
+ public static final String RUNTIME_PACKAGE
= XSLT_PACKAGE + ".runtime";
- public static final String TRANSLET_CLASS
+ public static final String TRANSLET_CLASS
= RUNTIME_PACKAGE + ".AbstractTranslet";
- public static final String TRANSLET_SIG
+ public static final String TRANSLET_SIG
= "Lorg/apache/xalan/xsltc/runtime/AbstractTranslet;";
- public static final String UNION_ITERATOR_SIG
+ public static final String UNION_ITERATOR_SIG
= "Lorg/apache/xalan/xsltc/dom/UnionIterator;";
- public static final String TRANSLET_OUTPUT_BASE_SIG
+ public static final String TRANSLET_OUTPUT_BASE_SIG
= "Lorg/apache/xalan/xsltc/TransletOutputBase;";
- public static final String TRANSLET_OUTPUT_SIG
+ public static final String TRANSLET_OUTPUT_SIG
= "Lorg/apache/xalan/xsltc/TransletOutputHandler;";
- public static final String MAKE_NODE_SIG
+ public static final String MAKE_NODE_SIG
= "(I)Lorg/w3c/dom/Node;";
- public static final String MAKE_NODE_SIG2
+ public static final String MAKE_NODE_SIG2
= "(" + NODE_ITERATOR_SIG + ")Lorg/w3c/dom/Node;";
- public static final String MAKE_NODE_LIST_SIG
+ public static final String MAKE_NODE_LIST_SIG
= "(I)Lorg/w3c/dom/NodeList;";
- public static final String MAKE_NODE_LIST_SIG2
+ public static final String MAKE_NODE_LIST_SIG2
= "(" + NODE_ITERATOR_SIG + ")Lorg/w3c/dom/NodeList;";
public static final String LOAD_DOCUMENT_CLASS
@@ -264,94 +264,94 @@
= "org.apache.xalan.xsltc.DOM";
public static final String DOM_IMPL
= "org.apache.xalan.xsltc.dom.DOMImpl";
- public static final String STRING_CLASS
+ public static final String STRING_CLASS
= "java.lang.String";
- public static final String OBJECT_CLASS
+ public static final String OBJECT_CLASS
= "java.lang.Object";
- public static final String BOOLEAN_CLASS
+ public static final String BOOLEAN_CLASS
= "java.lang.Boolean";
public static final String STRING_BUFFER_CLASS
= "java.lang.StringBuffer";
- public static final String TRANSLET_OUTPUT_BASE
+ public static final String TRANSLET_OUTPUT_BASE
= "org.apache.xalan.xsltc.TransletOutputBase";
// output interface
public static final String TRANSLET_OUTPUT_INTERFACE
= "org.apache.xalan.xsltc.TransletOutputHandler";
- public static final String BASIS_LIBRARY_CLASS
+ public static final String BASIS_LIBRARY_CLASS
= "org.apache.xalan.xsltc.runtime.BasisLibrary";
- public static final String ATTRIBUTE_LIST_IMPL_CLASS
+ public static final String ATTRIBUTE_LIST_IMPL_CLASS
= "org.apache.xalan.xsltc.runtime.AttributeListImpl";
- public static final String DOUBLE_CLASS
+ public static final String DOUBLE_CLASS
= "java.lang.Double";
- public static final String INTEGER_CLASS
+ public static final String INTEGER_CLASS
= "java.lang.Integer";
- public static final String RUNTIME_NODE_CLASS
+ public static final String RUNTIME_NODE_CLASS
= "org.apache.xalan.xsltc.runtime.Node";
- public static final String MATH_CLASS
+ public static final String MATH_CLASS
= "java.lang.Math";
- public static final String BOOLEAN_VALUE
+ public static final String BOOLEAN_VALUE
= "booleanValue";
- public static final String BOOLEAN_VALUE_SIG
+ public static final String BOOLEAN_VALUE_SIG
= "()Z";
- public static final String INT_VALUE
+ public static final String INT_VALUE
= "intValue";
- public static final String INT_VALUE_SIG
+ public static final String INT_VALUE_SIG
= "()I";
- public static final String DOUBLE_VALUE
+ public static final String DOUBLE_VALUE
= "doubleValue";
- public static final String DOUBLE_VALUE_SIG
+ public static final String DOUBLE_VALUE_SIG
= "()D";
- public static final String NODE_PNAME
+ public static final String NODE_PNAME
= "node";
- public static final String TRANSLET_OUTPUT_PNAME
+ public static final String TRANSLET_OUTPUT_PNAME
= "handler";
- public static final String ITERATOR_PNAME
+ public static final String ITERATOR_PNAME
= "iterator";
- public static final String DOCUMENT_PNAME
+ public static final String DOCUMENT_PNAME
= "document";
- public static final String TRANSLET_PNAME
+ public static final String TRANSLET_PNAME
= "translet";
- public static final String GET_NODE_NAME
+ public static final String GET_NODE_NAME
= "getNodeName";
- public static final String CHARACTERSW
+ public static final String CHARACTERSW
= "characters";
- public static final String GET_CHILDREN
+ public static final String GET_CHILDREN
= "getChildren";
- public static final String GET_TYPED_CHILDREN
+ public static final String GET_TYPED_CHILDREN
= "getTypedChildren";
- public static final String CHARACTERS
+ public static final String CHARACTERS
= "characters";
- public static final String APPLY_TEMPLATES
+ public static final String APPLY_TEMPLATES
= "applyTemplates";
- public static final String GET_NODE_TYPE
+ public static final String GET_NODE_TYPE
= "getNodeType";
- public static final String GET_NODE_VALUE
+ public static final String GET_NODE_VALUE
= "getNodeValue";
- public static final String GET_ELEMENT_VALUE
+ public static final String GET_ELEMENT_VALUE
= "getElementValue";
- public static final String GET_ATTRIBUTE_VALUE
+ public static final String GET_ATTRIBUTE_VALUE
= "getAttributeValue";
- public static final String HAS_ATTRIBUTE
+ public static final String HAS_ATTRIBUTE
= "hasAttribute";
- public static final String ADD_ITERATOR
+ public static final String ADD_ITERATOR
= "addIterator";
- public static final String SET_START_NODE
+ public static final String SET_START_NODE
= "setStartNode";
- public static final String RESET
+ public static final String RESET
= "reset";
public static final String ATTR_SET_SIG
= "(" + TRANSLET_OUTPUT_SIG + NODE_ITERATOR_SIG + ")V";
- public static final String GET_NODE_NAME_SIG
+ public static final String GET_NODE_NAME_SIG
= "(" + NODE_SIG + ")" + STRING_SIG;
- public static final String CHARACTERSW_SIG
+ public static final String CHARACTERSW_SIG
= "(" + STRING_SIG + TRANSLET_OUTPUT_SIG + ")V";
- public static final String CHARACTERS_SIG
+ public static final String CHARACTERS_SIG
= "(" + NODE_SIG + TRANSLET_OUTPUT_SIG + ")V";
public static final String GET_CHILDREN_SIG
= "(" + NODE_SIG +")" + NODE_ITERATOR_SIG;
@@ -381,70 +381,70 @@
public static final String DOM_FIELD
= "_dom";
- public static final String FORMAT_SYMBOLS_FIELD
+ public static final String FORMAT_SYMBOLS_FIELD
= "format_symbols";
- public static final String ITERATOR_FIELD_SIG
+ public static final String ITERATOR_FIELD_SIG
= NODE_ITERATOR_SIG;
- public static final String NODE_FIELD
+ public static final String NODE_FIELD
= "node";
- public static final String NODE_FIELD_SIG
+ public static final String NODE_FIELD_SIG
= "I";
-
- public static final String EMPTYATTR_FIELD
+
+ public static final String EMPTYATTR_FIELD
= "EmptyAttributes";
- public static final String ATTRIBUTE_LIST_FIELD
+ public static final String ATTRIBUTE_LIST_FIELD
= "attributeList";
- public static final String CLEAR_ATTRIBUTES
+ public static final String CLEAR_ATTRIBUTES
= "clear";
- public static final String ADD_ATTRIBUTE
+ public static final String ADD_ATTRIBUTE
= "addAttribute";
- public static final String ATTRIBUTE_LIST_IMPL_SIG
+ public static final String ATTRIBUTE_LIST_IMPL_SIG
= "Lorg/apache/xalan/xsltc/runtime/AttributeListImpl;";
- public static final String CLEAR_ATTRIBUTES_SIG
+ public static final String CLEAR_ATTRIBUTES_SIG
= "()" + ATTRIBUTE_LIST_IMPL_SIG;
- public static final String ADD_ATTRIBUTE_SIG
+ public static final String ADD_ATTRIBUTE_SIG
= "(" + STRING_SIG + STRING_SIG + ")" + ATTRIBUTE_LIST_IMPL_SIG;
-
- public static final String ADD_ITERATOR_SIG
+
+ public static final String ADD_ITERATOR_SIG
= "(" + NODE_ITERATOR_SIG +")" + UNION_ITERATOR_SIG;
public static final String ORDER_ITERATOR
= "orderNodes";
public static final String ORDER_ITERATOR_SIG
= "("+NODE_ITERATOR_SIG+"I)"+NODE_ITERATOR_SIG;
-
- public static final String SET_START_NODE_SIG
+
+ public static final String SET_START_NODE_SIG
= "(" + NODE_SIG + ")" + NODE_ITERATOR_SIG;
- public static final String NODE_COUNTER
+ public static final String NODE_COUNTER
= "org.apache.xalan.xsltc.dom.NodeCounter";
- public static final String NODE_COUNTER_SIG
+ public static final String NODE_COUNTER_SIG
= "Lorg/apache/xalan/xsltc/dom/NodeCounter;";
- public static final String DEFAULT_NODE_COUNTER
+ public static final String DEFAULT_NODE_COUNTER
= "org.apache.xalan.xsltc.dom.DefaultNodeCounter";
- public static final String DEFAULT_NODE_COUNTER_SIG
+ public static final String DEFAULT_NODE_COUNTER_SIG
= "Lorg/apache/xalan/xsltc/dom/DefaultNodeCounter;";
- public static final String TRANSLET_FIELD
+ public static final String TRANSLET_FIELD
= "translet";
- public static final String TRANSLET_FIELD_SIG
+ public static final String TRANSLET_FIELD_SIG
= TRANSLET_SIG;
- public static final String RESET_SIG
+ public static final String RESET_SIG
= "()" + NODE_ITERATOR_SIG;
- public static final String GET_PARAMETER
+ public static final String GET_PARAMETER
= "getParameter";
- public static final String ADD_PARAMETER
+ public static final String ADD_PARAMETER
= "addParameter";
public static final String PUSH_PARAM_FRAME
= "pushParamFrame";
- public static final String PUSH_PARAM_FRAME_SIG
+ public static final String PUSH_PARAM_FRAME_SIG
= "()V";
- public static final String POP_PARAM_FRAME
+ public static final String POP_PARAM_FRAME
= "popParamFrame";
- public static final String POP_PARAM_FRAME_SIG
+ public static final String POP_PARAM_FRAME_SIG
= "()V";
- public static final String GET_PARAMETER_SIG
+ public static final String GET_PARAMETER_SIG
= "(" + STRING_SIG + ")" + OBJECT_SIG;
public static final String ADD_PARAMETER_SIG
= "(" + STRING_SIG + OBJECT_SIG + "Z)" + OBJECT_SIG;
@@ -468,7 +468,7 @@
public static final String XMLNS_PREFIX = "xmlns";
public static final String XMLNS_STRING = "xmlns:";
- public static final String XMLNS_URI
+ public static final String XMLNS_URI
= "http://www.w3.org/2000/xmlns/";
public static final String XSLT_URI
= "http://www.w3.org/1999/XSL/Transform";
@@ -480,6 +480,18 @@
= "http://xml.apache.org/xalan/redirect";
public static final String FALLBACK_CLASS
= "org.apache.xalan.xsltc.compiler.Fallback";
+
+ // XSLT 2.0
+ public static final String STANDARD_FUNCTION_URI
+ = "http://www.w3.org/2002/08/xquery-functions";
+ public static final String STANDARD_OPERATOR_URI
+ = "http://www.w3.org/2002/08/xquery-operators";
+ public static final String SCHEMA_URI
+ = "http://www.w3.org/2001/XMLSchema";
+ public static final String SCHEMA_DATATYPES_URI
+ = "http://www.w3.org/2001/XMLSchema-datatypes";
+ public static final String SCHEMA_INSTANCE_URI
+ = "http://www.w3.org/2001/XMLSchema-instance";
public static final int RTF_INITIAL_SIZE = 64;
}
1.9.2.1.2.3 +3 -3
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.9.2.1.2.2
retrieving revision 1.9.2.1.2.3
diff -u -r1.9.2.1.2.2 -r1.9.2.1.2.3
--- DecimalFormatting.java 15 Jan 2003 14:43:04 -0000 1.9.2.1.2.2
+++ DecimalFormatting.java 24 Jan 2003 19:36:51 -0000 1.9.2.1.2.3
@@ -105,9 +105,9 @@
_name = parser.getQNameIgnoreDefaultNs(EMPTYSTRING);
}
- // Check if a set of symbols has already been registered
+ // Check if a set of symbols has already been registered
// under this name
- StaticContextImpl scontext = getStaticContext();
+ StaticContext scontext = getStaticContext();
if (scontext.getDecimalFormatting(_name) != null) {
reportWarning(this, parser, ErrorMsg.SYMBOLS_REDEF_ERR,
_name.toString());
1.13.2.1.2.3 +7 -5
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/DocumentCall.java
Index: DocumentCall.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/DocumentCall.java,v
retrieving revision 1.13.2.1.2.2
retrieving revision 1.13.2.1.2.3
diff -u -r1.13.2.1.2.2 -r1.13.2.1.2.3
--- DocumentCall.java 15 Jan 2003 14:43:04 -0000 1.13.2.1.2.2
+++ DocumentCall.java 24 Jan 2003 19:36:51 -0000 1.13.2.1.2.3
@@ -103,7 +103,8 @@
if (_uri instanceof LiteralExpr) {
LiteralExpr expr = (LiteralExpr)_uri;
if (expr.getValue().equals(EMPTYSTRING)) {
- Stylesheet stylesheet = getStylesheet();
+ final Stylesheet stylesheet = getStylesheet();
+
if (stylesheet == null) {
ErrorMsg msg = new ErrorMsg(ErrorMsg.ILLEGAL_ARG_ERR, this);
throw new TypeCheckError(msg);
@@ -121,7 +122,7 @@
if (ac == 2) {
_base = argument(1);
final Type baseType = _base.typeCheck(ccontext);
-
+
if (baseType.identicalTo(Type.Node)) {
_base = new CastExpr(_base, Type.NodeSet);
}
@@ -136,7 +137,7 @@
return _type = Type.NodeSet;
}
-
+
/**
* Translates the document() function call to a call to LoadDocument()'s
* static method document().
@@ -176,7 +177,8 @@
il.append(methodGen.loadContextNode());
}
il.append(new INVOKEINTERFACE(uriIdx, 2));
- il.append(new PUSH(cpg, getStylesheet().getSystemId()));
+ Stylesheet stylesheet = getStylesheet();
+ il.append(new PUSH(cpg, stylesheet.getSystemId()));
// Feck the rest of the parameters on the stack
il.append(classGen.loadTranslet());
1.8.2.1.2.3 +4 -5
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/FormatNumberCall.java
Index: FormatNumberCall.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/FormatNumberCall.java,v
retrieving revision 1.8.2.1.2.2
retrieving revision 1.8.2.1.2.3
diff -u -r1.8.2.1.2.2 -r1.8.2.1.2.3
--- FormatNumberCall.java 15 Jan 2003 14:43:04 -0000 1.8.2.1.2.2
+++ FormatNumberCall.java 24 Jan 2003 19:36:51 -0000 1.8.2.1.2.3
@@ -84,7 +84,6 @@
}
public Type typeCheck(CompilerContext ccontext) throws TypeCheckError {
-
// Inform stylesheet to instantiate a DecimalFormat object
getStylesheet().numberFormattingUsed();
@@ -101,7 +100,7 @@
if (_name instanceof LiteralExpr) {
final LiteralExpr literal = (LiteralExpr) _name;
- _resolvedQName =
+ _resolvedQName =
getParser().getQNameIgnoreDefaultNs(literal.getValue());
}
else if (tname instanceof StringType == false) {
@@ -110,7 +109,7 @@
}
return _type = Type.String;
}
-
+
public void translate(ClassGenerator classGen, MethodGenerator
methodGen) {
final ConstantPoolGen cpg = classGen.getConstantPool();
final InstructionList il = methodGen.getInstructionList();
@@ -127,7 +126,7 @@
"getDecimalFormat",
"(Ljava/lang/String;)"+
"Ljava/text/DecimalFormat;");
-
+
il.append(classGen.loadTranslet());
if (_name == null) {
il.append(new PUSH(cpg, EMPTYSTRING));
1.22.2.1.2.5 +2 -2
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.22.2.1.2.4
retrieving revision 1.22.2.1.2.5
diff -u -r1.22.2.1.2.4 -r1.22.2.1.2.5
--- FunctionCall.java 15 Jan 2003 14:43:04 -0000 1.22.2.1.2.4
+++ FunctionCall.java 24 Jan 2003 19:36:51 -0000 1.22.2.1.2.5
@@ -655,7 +655,7 @@
if (_type != null) {
if (_type == Type.NodeSet) {
- getXSLTC().setMultiDocument(true);
+ ccontext.setMultiDocument(true);
}
return _type;
}
1.16.2.1.2.5 +11 -10
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.16.2.1.2.4
retrieving revision 1.16.2.1.2.5
diff -u -r1.16.2.1.2.4 -r1.16.2.1.2.5
--- Import.java 15 Jan 2003 14:43:04 -0000 1.16.2.1.2.4
+++ Import.java 24 Jan 2003 19:36:52 -0000 1.16.2.1.2.5
@@ -89,19 +89,20 @@
public void parse(CompilerContext ccontext) {
final Parser parser = ccontext.getParser();
- final Stylesheet context = parser.getCurrentStylesheet();
+ final StaticContext scontext = getStaticContext();
+ final Stylesheet stylesheet = getStylesheet();
try {
String docToLoad = getAttribute("href");
- if (context.checkForLoop(docToLoad)) {
+ if (stylesheet.checkForLoop(docToLoad)) {
final int errno = ErrorMsg.CIRCULAR_INCLUDE_ERR;
final ErrorMsg msg = new ErrorMsg(errno, docToLoad, this);
parser.reportError(Constants.FATAL, msg);
return;
}
- String currLoadedDoc = context.getSystemId();
- SourceLoader loader = context.getSourceLoader();
+ String currLoadedDoc = stylesheet.getSystemId();
+ SourceLoader loader = stylesheet.getSourceLoader();
InputSource input = null;
if (loader != null) {
@@ -132,15 +133,15 @@
_imported.setSourceLoader(loader);
_imported.setSystemId(docToLoad);
- _imported.setParentStylesheet(context);
- _imported.setImportingStylesheet(context);
+ _imported.setParentStylesheet(stylesheet);
+ _imported.setImportingStylesheet(stylesheet);
// precedence for the including stylesheet
final int currPrecedence = parser.getCurrentImportPrecedence();
final int nextPrecedence = parser.getNextImportPrecedence();
_imported.setImportPrecedence(currPrecedence);
- context.setImportPrecedence(nextPrecedence);
- parser.setCurrentStylesheet(_imported);
+ stylesheet.setImportPrecedence(nextPrecedence);
+ scontext.setCurrentStylesheet(_imported);
_imported.parse(ccontext);
final Iterator elements = _imported.iterator();
@@ -164,7 +165,7 @@
e.printStackTrace();
}
finally {
- parser.setCurrentStylesheet(context);
+ scontext.setCurrentStylesheet(stylesheet);
}
}
1.19.2.1.2.5 +5 -4
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Include.java
Index: Include.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Include.java,v
retrieving revision 1.19.2.1.2.4
retrieving revision 1.19.2.1.2.5
diff -u -r1.19.2.1.2.4 -r1.19.2.1.2.5
--- Include.java 15 Jan 2003 14:43:04 -0000 1.19.2.1.2.4
+++ Include.java 24 Jan 2003 19:36:52 -0000 1.19.2.1.2.5
@@ -89,7 +89,8 @@
public void parse(CompilerContext ccontext) {
final Parser parser = ccontext.getParser();
- final Stylesheet context = parser.getCurrentStylesheet();
+ final StaticContext scontext = getStaticContext();
+ final Stylesheet context = getStylesheet();
String docToLoad = getAttribute("href");
try {
@@ -159,7 +160,7 @@
// as the stylesheet that included it.
final int precedence = context.getImportPrecedence();
_included.setImportPrecedence(precedence);
- parser.setCurrentStylesheet(_included);
+ scontext.setCurrentStylesheet(_included);
_included.parse(ccontext);
final Iterator elements = _included.iterator();
@@ -199,7 +200,7 @@
e.printStackTrace();
}
finally {
- parser.setCurrentStylesheet(context);
+ scontext.setCurrentStylesheet(context);
}
}
1.18.2.1.2.4 +18 -12
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/LiteralElement.java
Index: LiteralElement.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/LiteralElement.java,v
retrieving revision 1.18.2.1.2.3
retrieving revision 1.18.2.1.2.4
diff -u -r1.18.2.1.2.3 -r1.18.2.1.2.4
--- LiteralElement.java 15 Jan 2003 14:43:04 -0000 1.18.2.1.2.3
+++ LiteralElement.java 24 Jan 2003 19:36:52 -0000 1.18.2.1.2.4
@@ -78,13 +78,19 @@
final class LiteralElement extends Instruction {
+ private static final String XMLNS_STRING = "xmlns";
+ private static final QName USE_ATTRIBUTE_SETS =
+ new QName(XSLT_URI, "xsl", "use-attribute-sets");
+ private static final QName EXCLUDE_RESULT_PREFIXES =
+ new QName(XSLT_URI, "xsl", "exclude-result-prefixes");
+ private static final QName EXTENSION_ELEMENT_PREFIXES =
+ new QName(XSLT_URI, "xsl", "extension-element-prefixes");
+
private String _name;
private LiteralElement _literalElemParent;
private ArrayList _attributeElements = null;
private HashMap _accessedPrefixes = null;
- private final static String XMLNS_STRING = "xmlns";
-
/**
* Returns the QName for this literal element
*/
@@ -108,7 +114,7 @@
* definition for each namespace, so we stuff them in a hashtable.
*/
public void registerNamespace(String prefix, String uri, boolean
declared) {
- StaticContextImpl scontext = getStaticContext();
+ StaticContext scontext = getStaticContext();
// Check if the parent has a declaration for this namespace
if (_literalElemParent != null) {
@@ -132,7 +138,7 @@
if (old.equals(uri))
return;
else
- prefix = getCompilerContext().generateNamespacePrefix();
+ prefix = getCompilerContext().getFreshNsPrefix();
}
}
}
@@ -161,7 +167,7 @@
}
// Check if we must translate the prefix
- StaticContextImpl scontext = getStaticContext();
+ StaticContext scontext = getStaticContext();
final String alternative = scontext.getPrefixAlias(prefix);
if (alternative != null) {
scontext.setExcludePrefixes(prefix);
@@ -250,7 +256,7 @@
*/
public void parse(CompilerContext ccontext) {
final Parser parser = ccontext.getParser();
- final StaticContextImpl scontext = getStaticContext();
+ final StaticContext scontext = getStaticContext();
// Find the closest literal element ancestor (if there is one)
SyntaxTreeNode _literalElemParent = getParent();
@@ -274,15 +280,15 @@
// Handle xsl:use-attribute-sets. Attribute sets are placed first
// in the vector or attributes to make sure that later local
// attributes can override an attributes in the set.
- if (qname == parser.getUseAttributeSets()) {
+ if (qname.equals(USE_ATTRIBUTE_SETS)) {
setFirstAttribute(new UseAttributeSets(val, parser));
}
// Handle xsl:extension-element-prefixes
- else if (qname == parser.getExtensionElementPrefixes()) {
+ else if (qname.equals(EXTENSION_ELEMENT_PREFIXES)) {
scontext.setExcludePrefixes(val);
}
// Handle xsl:exclude-result-prefixes
- else if (qname == parser.getExcludeResultPrefixes()) {
+ else if (qname.equals(EXCLUDE_RESULT_PREFIXES)) {
scontext.setExcludePrefixes(val);
}
else {
@@ -325,11 +331,11 @@
final String val = _attributes.getValue(i);
// Handle xsl:extension-element-prefixes
- if (qname == parser.getExtensionElementPrefixes()) {
+ if (qname.equals(EXTENSION_ELEMENT_PREFIXES)) {
scontext.setUnexcludePrefixes(val);
}
// Handle xsl:exclude-result-prefixes
- else if (qname == parser.getExcludeResultPrefixes()) {
+ else if (qname.equals(EXCLUDE_RESULT_PREFIXES)) {
scontext.setUnexcludePrefixes(val);
}
}
1.24.2.1.2.3 +11 -7
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Mode.java
Index: Mode.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Mode.java,v
retrieving revision 1.24.2.1.2.2
retrieving revision 1.24.2.1.2.3
diff -u -r1.24.2.1.2.2 -r1.24.2.1.2.3
--- Mode.java 10 Jan 2003 16:50:40 -0000 1.24.2.1.2.2
+++ Mode.java 24 Jan 2003 19:36:52 -0000 1.24.2.1.2.3
@@ -487,7 +487,8 @@
// Complete test sequence for "@*" with "attribute::node()"
completeTestSequences(DOM.ATTRIBUTE, _attribNodeGroup);
- final ArrayList names = _stylesheet.getXSLTC().getNamesIndex();
+ final ArrayList names =
+ CompilerContext.getInstance().getNamesIndex();
if (starGroup != null || atStarGroup != null ||
_childNodeGroup != null || _attribNodeGroup != null)
{
@@ -713,8 +714,9 @@
final ConstantPoolGen cpg = classGen.getConstantPool();
// Append switch() statement - namespace test dispatch loop
- final ArrayList namespaces = xsltc.getNamespaceIndex();
- final ArrayList names = xsltc.getNamesIndex();
+ CompilerContext ccontext = CompilerContext.getInstance();
+ final ArrayList namespaces = ccontext.getNamespaceIndex();
+ final ArrayList names = ccontext.getNamesIndex();
final int namespaceCount = namespaces.size() + 1;
final int namesCount = names.size();
@@ -736,7 +738,7 @@
if ((isNamespace[i]) && (isAttribute[i] == attrFlag)) {
String name = (String)names.get(i-DOM.NTYPES);
String namespace = name.substring(0,name.lastIndexOf(':'));
- final int type = xsltc.registerNamespace(namespace);
+ final int type = ccontext.registerNamespace(namespace);
if ((i < _testSeq.length) &&
(_testSeq[i] != null)) {
@@ -774,7 +776,8 @@
public void compileApplyTemplates(ClassGenerator classGen) {
final XSLTC xsltc = classGen.getParser().getXSLTC();
final ConstantPoolGen cpg = classGen.getConstantPool();
- final ArrayList names = xsltc.getNamesIndex();
+ final ArrayList names =
+ CompilerContext.getInstance().getNamesIndex();
// Create the applyTemplates() method
final org.apache.bcel.generic.Type[] argTypes =
@@ -1085,7 +1088,8 @@
public void compileApplyImports(ClassGenerator classGen, int min, int
max) {
final XSLTC xsltc = classGen.getParser().getXSLTC();
final ConstantPoolGen cpg = classGen.getConstantPool();
- final ArrayList names = xsltc.getNamesIndex();
+ final ArrayList names =
+ CompilerContext.getInstance().getNamesIndex();
// Clear some datastructures
_namedTemplates = new HashMap();
1.9.2.1.2.5 +20 -3
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Number.java
Index: Number.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Number.java,v
retrieving revision 1.9.2.1.2.4
retrieving revision 1.9.2.1.2.5
diff -u -r1.9.2.1.2.4 -r1.9.2.1.2.5
--- Number.java 15 Jan 2003 14:43:04 -0000 1.9.2.1.2.4
+++ Number.java 24 Jan 2003 19:36:52 -0000 1.9.2.1.2.5
@@ -90,6 +90,11 @@
"___any_node_counter" // LEVEL_ANY
};
+ /**
+ * A thread local variable that holds an array of field indexes.
+ */
+ static private ThreadLocal _numberFieldIndexes = new ThreadLocal();
+
private Pattern _from = null;
private Pattern _count = null;
private Expression _value = null;
@@ -123,6 +128,18 @@
return null;
}
+ private int[] getNumberFieldIndexes() {
+ int[] result = (int[]) _numberFieldIndexes.get();
+ if (result == null) {
+ _numberFieldIndexes.set(result = new int[] {
+ -1, // LEVEL_SINGLE
+ -1, // LEVEL_MULTIPLE
+ -1 // LEVEL_ANY
+ });
+ }
+ return result;
+ }
+
/**
* Returns the name of the auxiliary class or null if this predicate
* is compiled inside the Translet.
@@ -250,7 +267,7 @@
ConstantPoolGen cpg = classGen.getConstantPool();
InstructionList il = methodGen.getInstructionList();
- int[] fieldIndexes = getXSLTC().getNumberFieldIndexes();
+ int[] fieldIndexes = getNumberFieldIndexes();
if (fieldIndexes[_level] == -1) {
Field defaultNode = new Field(ACC_PRIVATE,
@@ -399,7 +416,7 @@
MatchGenerator matchGen;
NodeCounterGenerator nodeCounterGen;
- _className = getXSLTC().getHelperClassName();
+ _className = CompilerContext.getInstance().getFreshClassName();
nodeCounterGen = new NodeCounterGenerator(_className,
ClassNames[_level],
toString(),
1.16.2.1.2.5 +2 -2
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Output.java
Index: Output.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Output.java,v
retrieving revision 1.16.2.1.2.4
retrieving revision 1.16.2.1.2.5
diff -u -r1.16.2.1.2.4 -r1.16.2.1.2.5
--- Output.java 15 Jan 2003 14:43:04 -0000 1.16.2.1.2.4
+++ Output.java 24 Jan 2003 19:36:53 -0000 1.16.2.1.2.5
@@ -275,7 +275,7 @@
}
// Set output properties in current stylesheet
- parser.getCurrentStylesheet().setOutputProperties(outputProperties);
+ getStylesheet().setOutputProperties(outputProperties);
}
/**
1.51.2.1.2.5 +153 -239
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.51.2.1.2.4
retrieving revision 1.51.2.1.2.5
diff -u -r1.51.2.1.2.4 -r1.51.2.1.2.5
--- Parser.java 15 Jan 2003 14:43:04 -0000 1.51.2.1.2.4
+++ Parser.java 24 Jan 2003 19:36:53 -0000 1.51.2.1.2.5
@@ -89,39 +89,92 @@
public class Parser implements Constants, ContentHandler {
- private static final String XSL = "xsl"; // standard prefix
- private static final String TRANSLET = "translet"; // extension prefix
+ /**
+ * Standard prefix bound to XSL uri.
+ */
+ private static final String XSL = "xsl";
+
+ /**
+ * Extension prefix.
+ */
+ private static final String TRANSLET = "translet";
+ /**
+ * SAX locator object. Used to obtain the location of any content
+ * handler event in the XML source document.
+ */
private Locator _locator = null;
- private XSLTC _xsltc; // Reference to the compiler object.
- private XPathParser _xpathParser; // Reference to the XPath parser.
- private ArrayList _errors; // Contains all compilation errors
- private ArrayList _warnings; // Contains all compilation errors
-
- private HashMap _instructionClasses; // Maps instructions to classes
- private HashMap _instructionAttrs;; // reqd and opt attrs
- private HashMap _qNames;
- private HashMap _namespaces;
- private QName _useAttributeSets;
- private QName _excludeResultPrefixes;
- private QName _extensionElementPrefixes;
- private HashMap _variableScope;
- private Stylesheet _currentStylesheet;
- private Output _output = null;
- private Template _template; // Reference to the template being
parsed.
+ /**
+ * Mapping between an instruction name (e.g. template) to the
+ * name of the class implementing that instruction. Java
+ * reflection is used to load the class from its name.
+ */
+ private HashMap _instructionClasses;
/**
- * A reference to the static context implementation.
+ * Mapping between an instruction name (e.g. template) to an
+ * array of strings contaning all the attributes allowed for
+ * that instruction. Used for error reporting.
*/
- private StaticContextImpl _staticContext;
+ private HashMap _instructionAttrs;
- private boolean _rootNamespaceDef = false; // Used for validity check
+ /**
+ * A reference to the XSLTC object.
+ */
+ private XSLTC _xsltc;
+ /**
+ * A list of all the errors encountered during compilation.
+ */
+ private ArrayList _errors;
+
+ /**
+ * A list of all the warnings encountered during compilation.
+ */
+ private ArrayList _warnings;
+
+ /**
+ * A reference to the XPath parser generated using Javacup/JLex.
+ */
+ private XPathParser _xpathParser;
+
+ /**
+ * A reference to the static context.
+ */
+ private StaticContext _staticContext;
+
+ /**
+ * A reference to the parsed xsl:output object. Multiple output
+ * declarations are merged as defined in the XSLT spec.
+ */
+ private Output _output = null;
+
+ /**
+ * A reference to the template being parsed.
+ */
+ private Template _template;
+
+ /**
+ * A reference to the stylesheet's root element.
+ */
private SyntaxTreeNode _root = null;
+ /**
+ * Set to true if the XSL namespace is defined in the stylesheet.
+ * Used to handle stylsheets specified via the xml-stylesheet PI.
+ */
+ private boolean _rootNamespaceDef = false;
+
+ /**
+ * Target of xml-stylesheet PI (if present).
+ */
private String _target;
+ /**
+ * Current import precendence. This is incremented every time a
+ * stylesheet is imported.
+ */
private int _currentImportPrecedence = 1;
public Parser(XSLTC xsltc) {
@@ -129,31 +182,20 @@
}
public void init() {
- _qNames = new HashMap(512);
- _namespaces = new HashMap();
_instructionClasses = new HashMap();
_instructionAttrs = new HashMap();
- _variableScope = new HashMap();
_template = null;
_errors = new ArrayList();
_warnings = new ArrayList();
- _currentStylesheet = null;
_currentImportPrecedence = 1;
- _staticContext = StaticContextImpl.getInstance(null);
+ _staticContext = StaticContext.getInstance(null);
_xpathParser =
- new XPathParser(CompilerContextImpl.getInstance(),
_staticContext);
+ new XPathParser(CompilerContext.getInstance(), _staticContext);
initStdClasses();
initInstructionAttrs();
initExtClasses();
initStaticContextPrimops();
-
- _useAttributeSets =
- getQName(XSLT_URI, XSL, "use-attribute-sets");
- _excludeResultPrefixes =
- getQName(XSLT_URI, XSL, "exclude-result-prefixes");
- _extensionElementPrefixes =
- getQName(XSLT_URI, XSL, "extension-element-prefixes");
}
public void setOutput(Output output) {
@@ -181,53 +223,12 @@
return getTopLevelStylesheet().getOutputProperties();
}
- public void addVariable(Variable var) {
- addVariableOrParam(var);
- }
-
- public void addParameter(Param param) {
- addVariableOrParam(param);
- }
-
- private void addVariableOrParam(VariableBase var) {
- Object existing = _variableScope.get(var.getName());
- if (existing != null) {
- if (existing instanceof Stack) {
- Stack stack = (Stack)existing;
- stack.push(var);
- }
- else if (existing instanceof VariableBase) {
- Stack stack = new Stack();
- stack.push(existing);
- stack.push(var);
- _variableScope.put(var.getName(), stack);
- }
- }
- else {
- _variableScope.put(var.getName(), var);
- }
- }
-
- public void removeVariable(QName name) {
- Object existing = _variableScope.get(name);
- if (existing instanceof Stack) {
- Stack stack = (Stack)existing;
- if (!stack.isEmpty()) stack.pop();
- if (!stack.isEmpty()) return;
- }
- _variableScope.remove(name);
- }
-
- public VariableBase lookupVariable(QName name) {
- Object existing = _variableScope.get(name);
- if (existing instanceof VariableBase) {
- return((VariableBase)existing);
- }
- else if (existing instanceof Stack) {
- Stack stack = (Stack)existing;
- return((VariableBase)stack.peek());
- }
- return(null);
+ /**
+ * Store the document locator to later retrieve line numbers of all
+ * elements from the stylesheet
+ */
+ public void setDocumentLocator(Locator locator) {
+ _locator = locator;
}
public void setXSLTC(XSLTC xsltc) {
@@ -238,6 +239,10 @@
return _xsltc;
}
+ public Stylesheet getTopLevelStylesheet() {
+ return _xsltc.getStylesheet();
+ }
+
public int getCurrentImportPrecedence() {
return _currentImportPrecedence;
}
@@ -246,135 +251,6 @@
return ++_currentImportPrecedence;
}
- public void setCurrentStylesheet(Stylesheet stylesheet) {
- _currentStylesheet = stylesheet;
- }
-
- public Stylesheet getCurrentStylesheet() {
- return _currentStylesheet;
- }
-
- public Stylesheet getTopLevelStylesheet() {
- return _xsltc.getStylesheet();
- }
-
- public QName getQNameSafe(final String stringRep) {
- StaticContext scontext =
- StaticContextImpl.getInstance(_currentStylesheet);
-
- // parse and retrieve namespace
- final int colon = stringRep.lastIndexOf(':');
- if (colon != -1) {
- final String prefix = stringRep.substring(0, colon);
- final String localname = stringRep.substring(colon + 1);
- String namespace = null;
-
- // Get the namespace uri from the symbol table
- if (prefix.equals(XMLNS_PREFIX) == false) {
- namespace = _staticContext.getNamespace(prefix);
- if (namespace == null) namespace = EMPTYSTRING;
- }
- return getQName(namespace, prefix, localname);
- }
- else {
- final String uri = stringRep.equals(XMLNS_PREFIX) ? null
- : _staticContext.getNamespace(EMPTYSTRING);
- return getQName(uri, null, stringRep);
- }
- }
-
- public QName getQName(final String stringRep) {
- return getQName(stringRep, true, false);
- }
-
- public QName getQNameIgnoreDefaultNs(final String stringRep) {
- return getQName(stringRep, true, true);
- }
-
- public QName getQName(final String stringRep, boolean reportError) {
- return getQName(stringRep, reportError, false);
- }
-
- private QName getQName(final String stringRep, boolean reportError,
- boolean ignoreDefaultNs)
- {
- // parse and retrieve namespace
- final int colon = stringRep.lastIndexOf(':');
- if (colon != -1) {
- final String prefix = stringRep.substring(0, colon);
- final String localname = stringRep.substring(colon + 1);
- String namespace = null;
-
- // Get the namespace uri from the symbol table
- if (prefix.equals(XMLNS_PREFIX) == false) {
- namespace = _staticContext.getNamespace(prefix);
- if (namespace == null && reportError) {
- final int line = _locator.getLineNumber();
- ErrorMsg err = new ErrorMsg(ErrorMsg.NAMESPACE_UNDEF_ERR,
- line, prefix);
- reportError(ERROR, err);
- }
- }
- return getQName(namespace, prefix, localname);
- }
- else {
- if (stringRep.equals(XMLNS_PREFIX)) {
- ignoreDefaultNs = true;
- }
- final String defURI = ignoreDefaultNs ? null
- : _staticContext.getNamespace(EMPTYSTRING);
- return getQName(defURI, null, stringRep);
- }
- }
-
- public QName getQName(String namespace, String prefix, String localname)
{
- if (namespace == null || namespace.equals(EMPTYSTRING)) {
- QName name = (QName)_qNames.get(localname);
- if (name == null) {
- name = new QName(null, prefix, localname);
- _qNames.put(localname, name);
- }
- return name;
- }
- else {
- HashMap space = (HashMap) _namespaces.get(namespace);
- if (space == null) {
- final QName name = new QName(namespace, prefix, localname);
- _namespaces.put(namespace, space = new HashMap());
- space.put(localname, name);
- return name;
- }
- else {
- QName name = (QName)space.get(localname);
- if (name == null) {
- name = new QName(namespace, prefix, localname);
- space.put(localname, name);
- }
- return name;
- }
- }
- }
-
- public QName getQName(String scope, String name) {
- return getQName(scope + name);
- }
-
- public QName getQName(QName scope, QName name) {
- return getQName(scope.toString() + name.toString());
- }
-
- public QName getUseAttributeSets() {
- return _useAttributeSets;
- }
-
- public QName getExtensionElementPrefixes() {
- return _extensionElementPrefixes;
- }
-
- public QName getExcludeResultPrefixes() {
- return _excludeResultPrefixes;
- }
-
/**
* Create an instance of the <code>Stylesheet</code> class,
* and then parse, typecheck and compile the instance.
@@ -413,7 +289,7 @@
public void createAST(Stylesheet stylesheet) {
try {
if (stylesheet != null) {
- stylesheet.parse(CompilerContextImpl.getInstance());
+ stylesheet.parse(CompilerContext.getInstance());
final int precedence = stylesheet.getImportPrecedence();
final Iterator elements = stylesheet.iterator();
while (elements.hasNext()) {
@@ -426,7 +302,7 @@
}
}
if (!errorsFound()) {
- stylesheet.typeCheck(CompilerContextImpl.getInstance());
+ stylesheet.typeCheck(CompilerContext.getInstance());
}
}
}
@@ -450,23 +326,23 @@
return (SyntaxTreeNode)getStylesheet(_root);
}
catch (IOException e) {
- if (_xsltc.debug()) e.printStackTrace();
+ if (_xsltc.getDebug()) e.printStackTrace();
reportError(ERROR,new ErrorMsg(e.getMessage()));
}
catch (SAXException e) {
Throwable ex = e.getException();
- if (_xsltc.debug()) {
+ if (_xsltc.getDebug()) {
e.printStackTrace();
if (ex != null) ex.printStackTrace();
}
reportError(ERROR, new ErrorMsg(e.getMessage()));
}
catch (CompilerException e) {
- if (_xsltc.debug()) e.printStackTrace();
+ if (_xsltc.getDebug()) e.printStackTrace();
reportError(ERROR, new ErrorMsg(e.getMessage()));
}
catch (Exception e) {
- if (_xsltc.debug()) e.printStackTrace();
+ if (_xsltc.getDebug()) e.printStackTrace();
reportError(ERROR, new ErrorMsg(e.getMessage()));
}
return null;
@@ -669,8 +545,6 @@
new String[] {"stylesheet-prefix", "result-prefix"});
}
-
-
/**
* Initialize the _instructionClasses HashMap, which maps XSL element
* names to Java classes in this package.
@@ -719,7 +593,8 @@
}
public boolean elementSupported(String namespace, String localName) {
- return(_instructionClasses.get(getQName(namespace, XSL, localName)) !=
null);
+ return(_instructionClasses.get(getQName(namespace, XSL, localName))
+ != null);
}
public boolean functionSupported(String fname) {
@@ -930,7 +805,7 @@
String local, Attributes attributes)
{
SyntaxTreeNode node = null;
- QName qname = getQName(uri, prefix, local);
+ QName qname = getQName(uri, prefix, local);
String className = (String)_instructionClasses.get(qname);
if (className != null) {
@@ -1038,7 +913,6 @@
}
}
-
/**
* Parse an XPath expression:
* @parent - XSL element where the expression occured
@@ -1114,7 +988,7 @@
expression, parent));
}
catch (Exception e) {
- if (_xsltc.debug()) e.printStackTrace();
+ if (_xsltc.getDebug()) e.printStackTrace();
reportError(ERROR, new ErrorMsg(ErrorMsg.XPATH_PARSER_ERR,
expression, parent));
}
@@ -1123,7 +997,7 @@
return SyntaxTreeNode.Dummy;
}
- /************************ ERROR HANDLING SECTION
************************/
+ // -- Error Handling -------------------------------------------------
/**
* Returns true if there were any errors during compilation
@@ -1199,7 +1073,56 @@
return _warnings;
}
- /************************ SAX2 ContentHandler INTERFACE
*****************/
+ // -- QName creation -------------------------------------------------
+
+ public QName getQName(final String stringRep) {
+ return getQName(stringRep, true, false);
+ }
+
+ public QName getQNameIgnoreDefaultNs(final String stringRep) {
+ return getQName(stringRep, true, true);
+ }
+
+ public QName getQName(final String stringRep, boolean reportError) {
+ return getQName(stringRep, reportError, false);
+ }
+
+ private QName getQName(final String stringRep, boolean reportError,
+ boolean ignoreDefaultNs)
+ {
+ // parse and retrieve namespace
+ final int colon = stringRep.lastIndexOf(':');
+ if (colon != -1) {
+ String namespace = "";
+ String prefix = stringRep.substring(0, colon);
+ String localname = stringRep.substring(colon + 1);
+
+ // Get the namespace uri from the symbol table
+ if (!prefix.equals(XMLNS_PREFIX)) {
+ namespace = _staticContext.getNamespace(prefix);
+ if (namespace == null && reportError) {
+ final int line = _locator.getLineNumber();
+ ErrorMsg err = new ErrorMsg(ErrorMsg.NAMESPACE_UNDEF_ERR,
+ line, prefix);
+ reportError(ERROR, err);
+ }
+ }
+ return getQName(namespace, prefix, localname);
+ }
+ else {
+ if (stringRep.equals(XMLNS_PREFIX)) {
+ ignoreDefaultNs = true;
+ }
+ return getQName(ignoreDefaultNs ? "" :
+ _staticContext.getNamespace(""), "", stringRep);
+ }
+ }
+
+ public QName getQName(String namespace, String prefix, String localname)
{
+ return new QName(namespace, prefix, localname);
+ }
+
+ // -- SAX2 ContentHandler implementation -----------------------------
private Stack _parentStack = null;
private HashMap _prefixMapping = null;
@@ -1219,7 +1142,6 @@
*/
public void endDocument() { }
-
/**
* SAX2: Begin the scope of a prefix-URI Namespace mapping.
* This has to be passed on to the symbol table!
@@ -1312,11 +1234,12 @@
if (parent instanceof Stylesheet) return;
// Get last element of parent
- SyntaxTreeNode bro = parent.get(parent.elementCount() - 1);
- if ((bro != null) && (bro instanceof Text)) {
- Text text = (Text)bro;
+ int n = parent.elementCount();
+ SyntaxTreeNode bro = (n > 0) ? parent.get(n - 1) : null;
+ if (bro != null && bro instanceof Text) {
+ Text text = (Text) bro;
if (!text.isTextElement()) {
- if ((length > 1) || ( ((int)ch[0]) < 0x100)) {
+ if (length > 1 || ((int) ch[0]) < 0x100) {
text.setText(string);
return;
}
@@ -1379,13 +1302,4 @@
* IGNORED - we do not have to do anything with skipped entities
*/
public void skippedEntity(String name) { }
-
- /**
- * Store the document locator to later retrieve line numbers of all
- * elements from the stylesheet
- */
- public void setDocumentLocator(Locator locator) {
- _locator = locator;
- }
-
}
1.24.2.1.2.5 +2 -2
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Predicate.java
Index: Predicate.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Predicate.java,v
retrieving revision 1.24.2.1.2.4
retrieving revision 1.24.2.1.2.5
diff -u -r1.24.2.1.2.4 -r1.24.2.1.2.5
--- Predicate.java 15 Jan 2003 14:43:04 -0000 1.24.2.1.2.4
+++ Predicate.java 24 Jan 2003 19:36:53 -0000 1.24.2.1.2.5
@@ -318,7 +318,7 @@
LocalVariableGen local;
FilterGenerator filterGen;
- _className = getXSLTC().getHelperClassName();
+ _className = CompilerContext.getInstance().getFreshClassName();
filterGen = new FilterGenerator(_className,
"java.lang.Object",
toString(),
1.4.2.1.2.1 +38 -11
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/QName.java
Index: QName.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/QName.java,v
retrieving revision 1.4.2.1
retrieving revision 1.4.2.1.2.1
diff -u -r1.4.2.1 -r1.4.2.1.2.1
--- QName.java 14 Aug 2002 19:21:33 -0000 1.4.2.1
+++ QName.java 24 Jan 2003 19:36:53 -0000 1.4.2.1.2.1
@@ -65,26 +65,46 @@
package org.apache.xalan.xsltc.compiler;
final class QName {
- private final String _localname;
+
+ /**
+ * The local part of this qname.
+ */
+ private String _localname;
+
+ /**
+ * The prefix of this qname.
+ */
private String _prefix;
+
+ /**
+ * The namespace URI of this qname.
+ */
private String _namespace;
+
+ /**
+ * A string representation of the expanded qname. Either
+ * prefix:localname or localname if no prefix is available.
+ */
private String _stringRep;
- private int _hashCode;
+
+ /**
+ * A cached hash code value computed from the expanded
+ * qname.
+ */
+ private int _hashCode;
public QName(String namespace, String prefix, String localname) {
_namespace = namespace;
_prefix = prefix;
_localname = localname;
- _stringRep =
- (namespace != null && !namespace.equals(Constants.EMPTYSTRING)) ?
- (namespace + ':' + localname) : localname;
-
- _hashCode = _stringRep.hashCode() + 19; // cached for speed
+ _stringRep = (namespace.length() == 0) ? localname :
+ (namespace + ':' + localname);
+ _hashCode = _stringRep.hashCode() + 19; // cached for speed
}
public void clearNamespace() {
- _namespace = Constants.EMPTYSTRING;
+ _namespace = "";
}
public String toString() {
@@ -96,7 +116,14 @@
}
public boolean equals(Object other) {
- return (this == other);
+ try {
+ final QName temp = (QName) other;
+ return (_namespace.equals(temp._namespace) &&
+ _localname.equals(temp._localname));
+ }
+ catch (ClassCastException e) {
+ return false;
+ }
}
public String getLocalPart() {
@@ -116,7 +143,7 @@
}
public String dump() {
- return new String("QName: " + _namespace + "(" + _prefix + "):"
+ return new String("QName: " + _namespace + "(" + _prefix + "):"
+ _localname);
}
}
1.15.2.1.2.5 +5 -3
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Sort.java
Index: Sort.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Sort.java,v
retrieving revision 1.15.2.1.2.4
retrieving revision 1.15.2.1.2.5
diff -u -r1.15.2.1.2.4 -r1.15.2.1.2.5
--- Sort.java 15 Jan 2003 14:43:05 -0000 1.15.2.1.2.4
+++ Sort.java 24 Jan 2003 19:36:53 -0000 1.15.2.1.2.5
@@ -386,7 +386,8 @@
String sortRecordClass)
{
final XSLTC xsltc = ((Sort)sortObjects.get(0)).getXSLTC();
- final String className = xsltc.getHelperClassName();
+ final String className =
+ CompilerContext.getInstance().getFreshClassName();
final NodeSortRecordFactGenerator sortRecordFactory =
new NodeSortRecordFactGenerator(className,
@@ -521,7 +522,8 @@
ClassGenerator classGen,
MethodGenerator methodGen) {
final XSLTC xsltc = ((Sort)sortObjects.get(0)).getXSLTC();
- final String className = xsltc.getHelperClassName();
+ final String className =
+ CompilerContext.getInstance().getFreshClassName();
// This generates a new class for handling this specific sort
final NodeSortRecordGenerator sortRecord =
1.1.2.3 +419 -53
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Attic/StaticContext.java
Index: StaticContext.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Attic/StaticContext.java,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -r1.1.2.2 -r1.1.2.3
--- StaticContext.java 15 Jan 2003 14:43:05 -0000 1.1.2.2
+++ StaticContext.java 24 Jan 2003 19:36:53 -0000 1.1.2.3
@@ -4,7 +4,7 @@
* The Apache Software License, Version 1.1
*
*
- * Copyright (c) 2003 The Apache Software Foundation. All rights
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -63,115 +63,481 @@
package org.apache.xalan.xsltc.compiler;
import java.text.Collator;
+import java.util.Stack;
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.StringTokenizer;
-import org.apache.xalan.xsltc.compiler.util.Type;
+import org.apache.xalan.xsltc.compiler.util.*;
-interface StaticContext {
+public final class StaticContext {
/**
- * Returns a reference to the stylesheet object.
+ * A reference to the current node. This is needed to search for
+ * scoped info such as namespace declarations.
*/
- public Stylesheet getStylesheet();
+ private SyntaxTreeNode _currentNode = null;
/**
- * Returns true if XPath 1.0 compatibility is on.
+ * A thread local variable that holds the static context. Multiple
+ * calls to getInstance() will return the same variable.
*/
- public boolean getXPath10CompatibleFlag();
+ static private ThreadLocal _staticContext = new ThreadLocal();
/**
- * Base URI for the stylesheet. This is used by fn:document to
- * resolve relative URIs.
+ * The method getInstance() should be used instead.
*/
- public String getBaseURI();
+ private StaticContext() {
+ }
/**
- * Default namespace for elements.
+ * Clear cached values every time a new node is set as current.
*/
- public String getDefaultElementNamespace();
+ private void clearCache() {
+ _cachedTemplate = null;
+ }
/**
- * Default namespace for types (same as for elements).
+ * An instance of the this class can be obtained only by calling
+ * this static method.
*/
- public String getDefaultTypeNamespace();
+ public static StaticContext getInstance(SyntaxTreeNode current) {
+ StaticContext result = (StaticContext) _staticContext.get();
+ if (result == null) {
+ _staticContext.set(result = new StaticContext());
+ }
+ result.setCurrentNode(current);
+ result.clearCache();
+ return result;
+ }
/**
- * Default namespace for functions.
+ * Set current node.
*/
- public String getDefaultFunctionNamespace();
+ public void setCurrentNode(SyntaxTreeNode currentNode) {
+ _currentNode = currentNode;
+ }
+
+ // -- Decimal Formats ------------------------------------------------
+
+ private HashMap _decimalFormats = null;
+
+ public DecimalFormatting getDecimalFormatting(QName name) {
+ if (_decimalFormats == null) return null;
+ return (DecimalFormatting)_decimalFormats.get(name);
+ }
+
+ public void addDecimalFormatting(QName name, DecimalFormatting symbols) {
+ if (_decimalFormats == null) _decimalFormats = new HashMap();
+ _decimalFormats.put(name, symbols);
+ }
+
+ // -- Stylesheet -----------------------------------------------------
/**
- * Returns the in-scope namespace declaration bound to 'prefix'.
- * If prefix is the empty string, the default namespace is returned.
+ * A reference to the stylesheet object.
*/
- public String getNamespace(String prefix);
+ private Stylesheet _stylesheet = null;
/**
- * Returns the in-scope type definition bound to 'name'. Return
- * type is implementation dependent.
+ * Returns a reference to the current stylesheet. If not set, then
+ * search for an ancestor of the current node.
*/
- public Type getSchemaType(QName name);
+ public Stylesheet getCurrentStylesheet() {
+ if (_stylesheet == null) {
+ SyntaxTreeNode parent = _currentNode;
+ while (parent != null && parent instanceof Stylesheet == false) {
+ parent = parent.getParent();
+ }
+ _stylesheet = (Stylesheet) parent;
+ }
+ return _stylesheet;
+ }
/**
- * Returns an instance of the default collator.
+ * Sets the stylesheet object.
*/
- public Collator getDefaultCollator();
+ public void setCurrentStylesheet(Stylesheet stylesheet) {
+ _stylesheet = stylesheet;
+ }
+
+ // -- Templates ------------------------------------------------------
/**
- * Returns the collator object associated to 'URI'.
+ * A mapping between qnames and template objects.
*/
- public Collator getCollator(String URI);
+ private HashMap _templates = null;
/**
- * Returns the decimal formatting object of a given name. These
- * objects are defined using xsl:decimal-format. The name of
- * a decimal formatting object is used by format-number().
+ * A cached reference to the current template.
*/
- public DecimalFormatting getDecimalFormatting(QName name);
+ private Template _cachedTemplate = null;
+
+ /**
+ * Adds a named template to the static context.
+ */
+ public Template addTemplate(Template template) {
+ final QName name = template.getName();
+ if (_templates == null) _templates = new HashMap();
+ return (Template)_templates.put(name, template);
+ }
/**
* Returns the template object associated to 'name'. These names
* are used by xsl:call-template.
*/
- public Template getTemplate(QName name);
+ public Template getTemplate(QName name) {
+ if (_templates == null) return null;
+ return (Template)_templates.get(name);
+ }
+
+ /**
+ * Returns a reference to the "current" template or null if
+ * the current node is top-level and it is not a template.
+ */
+ public Template getCurrentTemplate() {
+ if (_cachedTemplate == null) {
+ SyntaxTreeNode parent = _currentNode;
+ while (parent != null && parent instanceof Template == false) {
+ parent = parent.getParent();
+ }
+ _cachedTemplate = (Template) parent;
+ }
+ return _cachedTemplate;
+ }
+
+ // -- Variables/Parameters -------------------------------------------
+
+ private HashMap _variables = null;
+
+ /**
+ * Add a variable or a parameter to the static context. A stack
+ * is used for scoping.
+ */
+ public void addVariable(VariableBase var) {
+ if (_variables == null) {
+ _variables = new HashMap();
+ }
+ final QName qname = var.getName();
+ Object oldvar = _variables.put(qname, var);
+ if (oldvar instanceof Stack) {
+ ((Stack) oldvar).push(var);
+ }
+ else if (oldvar instanceof VariableBase) {
+ Stack scopes = new Stack();
+ scopes.push(oldvar);
+ scopes.push(var);
+ _variables.put(qname, scopes);
+ }
+ else {
+ // assert(var == null);
+ }
+ }
+
+ /**
+ * Get the variable or parameter bound to 'qname'. Returns null
+ * if the name is unbound.
+ */
+ public VariableBase getVariable(QName qname) {
+ if (_variables == null) return null;
+ final Object var = _variables.get(qname);
+ if (var instanceof Stack) {
+ return (VariableBase) ((Stack) var).peek();
+ }
+ return (VariableBase) var;
+ }
+
+ /**
+ * Remove a variable from the static context (if present).
+ */
+ public void removeVariable(QName qname) {
+ if (_variables != null) {
+ Object var = _variables.get(qname);
+ if (var instanceof Stack) {
+ final Stack stack = (Stack) var;
+ stack.pop();
+ if (stack.isEmpty()) {
+ _variables.remove(qname);
+ }
+ }
+ else if (var instanceof VariableBase) {
+ _variables.remove(qname);
+ }
+ else {
+ // assert(var == null);
+ }
+ }
+ }
+
+ // -- Attribute Sets ------------------------------------------------
+
+ private HashMap _attributeSets = null;
+
+ public AttributeSet addAttributeSet(AttributeSet atts) {
+ if (_attributeSets == null) _attributeSets = new HashMap();
+ return (AttributeSet)_attributeSets.put(atts.getName(), atts);
+ }
+
+ public AttributeSet getAttributeSet(QName name) {
+ if (_attributeSets == null) return null;
+ return (AttributeSet)_attributeSets.get(name);
+ }
+
+ // -- Primops -------------------------------------------------------
+
+ private final HashMap _primops = new HashMap();
+
+ /**
+ * Add a primitive operator or function to the symbol table. To avoid
+ * name clashes with user-defined names, the prefix <tt>PrimopPrefix</tt>
+ * is prepended.
+ */
+ public void addPrimop(String name, MethodType mtype) {
+ ArrayList methods = (ArrayList)_primops.get(name);
+ if (methods == null) {
+ _primops.put(name, methods = new ArrayList());
+ }
+ methods.add(mtype);
+ }
+
+ /**
+ * Lookup a primitive operator or function in the symbol table by
+ * prepending the prefix <tt>PrimopPrefix</tt>.
+ */
+ public ArrayList getPrimop(String name) {
+ return (ArrayList)_primops.get(name);
+ }
+
+ // -- Namespaces ----------------------------------------------------
+
+ /**
+ * Found the URI bound to 'prefix' starting at the current node
+ * and going upwards. Returns null if 'prefix' is undefined.
+ */
+ public String getNamespace(String prefix) {
+ String result = null;
+
+ SyntaxTreeNode parent = _currentNode;
+ while (parent != null && result == null) {
+ HashMap map = _currentNode.getPrefixMapping();
+ if (map != null) {
+ result = (String) map.get(prefix);
+ }
+ parent = parent.getParent();
+ }
+
+ // If not bound, check default namespace
+ if (result == null && prefix.length() == 0) {
+ return Constants.EMPTYSTRING;
+ }
+ return result;
+ }
/**
- * Returns a reference to the "current" template.
+ * Returns one of the prefixes mapped to 'uri' or null if no prefix
+ * is found.
*/
- public Template getCurrentTemplate();
+ public String getPrefix(String uri) {
+ SyntaxTreeNode parent = _currentNode;
+
+ while (parent != null) {
+ HashMap prefixMapping = _currentNode.getPrefixMapping();
+
+ if (prefixMapping != null) {
+ Iterator prefixes = prefixMapping.keySet().iterator();
+ while (prefixes.hasNext()) {
+ final String prefix = (String) prefixes.next();
+ final String mapsTo = (String) prefixMapping.get(prefix);
+ if (mapsTo.equals(uri)) return prefix;
+ }
+ }
+ parent = parent.getParent();
+ }
+ return null;
+ }
+
+ // -- Prefix aliases ------------------------------------------------
+
+ private HashMap _aliases = null;
/**
- * Returns the variable/param object associated to 'name'.
+ * Adds an alias for a namespace prefix
*/
- public VariableBase getVariable(QName qname);
+ public void addPrefixAlias(String prefix, String alias) {
+ if (_aliases == null) _aliases = new HashMap();
+ _aliases.put(prefix,alias);
+ }
/**
- * Returns the attribute set object associated to 'name'. Attribute
- * sets are defined via xsl:attribute-set. Attribute sets can be
- * referenced from xsl:copy and xsl:element.
+ * Retrieves any alias for a given namespace prefix
*/
- public AttributeSet getAttributeSet(QName name);
+ public String getPrefixAlias(String prefix) {
+ if (_aliases == null) return null;
+ return (String)_aliases.get(prefix);
+ }
+
+ // -- Collations ----------------------------------------------------
+
+ public Collator getCollator(String uri) {
+ return null; // TODO
+ }
+
+ public Collator getDefaultCollator() {
+ return null; // TODO
+ }
+
+ // -- XPath 1.0 compatible flag --------------------------------------
+
+ private boolean _xpath10CompatibleFlag = true;
+
+ public boolean getXPath10CompatibleFlag() {
+ return _xpath10CompatibleFlag;
+ }
+
+ public void setXPath10CompatibleFlag(boolean flag) {
+ _xpath10CompatibleFlag = flag;
+ }
+
+ // -- Base URI -------------------------------------------------------
+
+ private String _baseURI;
+
+ public String getBaseURI() {
+ return _baseURI;
+ }
+
+ public void setBaseURI(String uri) {
+ _baseURI = uri;
+ }
+
+ // -- Default NS for elements and types ------------------------------
+
+ private String _defaultElementNamespace;
+
+ public String getDefaultElementNamespace() {
+ return _defaultElementNamespace;
+ }
+
+ public void setDefaultElementNamespace(String uri) {
+ _defaultElementNamespace = uri;
+ }
+
+ public String getDefaultTypeNamespace() {
+ return getDefaultElementNamespace();
+ }
+
+ public void setDefaultTypeNamespace(String uri) {
+ setDefaultElementNamespace(uri);
+ }
+
+ // -- Default NS for functions --------------------------------------
+
+ private String _defaultFunctionNamespace;
+
+ public String getDefaultFunctionNamespace() {
+ return _defaultFunctionNamespace;
+ }
+
+ public void setDefaultFunctionNamespace(String uri) {
+ _defaultFunctionNamespace = uri;
+ }
+
+ // -- Schema type definitions ---------------------------------------
+
+ public Type getSchemaType(QName name) {
+ return null; // TODO
+ }
+
+ public void setSchemaType(QName name, Type type) {
+ // TODO;
+ }
+
+ // -- Namespace exclusions ------------------------------------------
+
+ private HashMap _excludedURI = null;
/**
- * Returns a list of all primitive operations (i.e. operators
- * and functions) associated to 'name'. Primops can be overloaded;
- * the first element of the list returned is deemed to be the
- * default (note that there can be more than one implementation
- * with the same name and the same arity even though this is not
- * supported in XSLT/XPath).
+ * Register a namespace URI so that it will not be declared in the
+ * output unless it is actually referenced in the output.
*/
- public ArrayList getPrimop(String name);
+ public void setExcludeURI(String uri) {
+ // The null-namespace cannot be excluded
+ if (uri == null) return;
+
+ // Create new HashMap of exlcuded URIs if none exists
+ if (_excludedURI == null) _excludedURI = new HashMap();
+
+ // Register the namespace URI
+ Integer refcnt = (Integer)_excludedURI.get(uri);
+ if (refcnt == null)
+ refcnt = new Integer(1);
+ else
+ refcnt = new Integer(refcnt.intValue() + 1);
+ _excludedURI.put(uri, refcnt);
+ }
/**
- * Returns the alias for a namespace prefix. Namespace aliases
- * can be defined using xsl:namespace-alias.
+ * Exclude a series of namespaces given by a list of whitespace
+ * separated namespace prefixes.
*/
- public String getPrefixAlias(String prefix);
+ public void setExcludePrefixes(String prefixes) {
+ if (prefixes != null) {
+ StringTokenizer tokens = new StringTokenizer(prefixes);
+ while (tokens.hasMoreTokens()) {
+ final String prefix = tokens.nextToken();
+ final String uri;
+ if (prefix.equals("#default"))
+ uri = getNamespace(Constants.EMPTYSTRING);
+ else
+ uri = getNamespace(prefix);
+ if (uri != null) setExcludeURI(uri);
+ }
+ }
+ }
/**
* Check if a namespace should not be declared in the output
- * (unless used)
+ * (unless used).
*/
- public boolean getExcludeUri(String uri);
+ public boolean getExcludeUri(String uri) {
+ if (uri != null && _excludedURI != null) {
+ final Integer refcnt = (Integer)_excludedURI.get(uri);
+ return (refcnt != null && refcnt.intValue() > 0);
+ }
+ return false;
+ }
+
+ /**
+ * Turn off namespace declaration exclusion.
+ */
+ public void setUnexcludePrefixes(String prefixes) {
+ if (_excludedURI == null) return;
+ if (prefixes != null) {
+ StringTokenizer tokens = new StringTokenizer(prefixes);
+ while (tokens.hasMoreTokens()) {
+ final String prefix = tokens.nextToken();
+ final String uri;
+ if (prefix.equals("#default"))
+ uri = getNamespace(Constants.EMPTYSTRING);
+ else
+ uri = getNamespace(prefix);
+ Integer refcnt = (Integer)_excludedURI.get(uri);
+ if (refcnt != null)
+ _excludedURI.put(uri, new Integer(refcnt.intValue() -
1));
+ }
+ }
+ }
+
+ // -- SHOULD BE MOVED OUT OF THIS CLASS !!!! -------------------------
+
+ private final HashMap _stylesheets = new HashMap();
+
+ public Stylesheet addStylesheet(QName name, Stylesheet node) {
+ return (Stylesheet)_stylesheets.put(name, node);
+ }
+
+ public Stylesheet getStylesheet(QName name) {
+ return (Stylesheet)_stylesheets.get(name);
+ }
}
-
1.37.2.1.2.5 +6 -4
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Step.java
Index: Step.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Step.java,v
retrieving revision 1.37.2.1.2.4
retrieving revision 1.37.2.1.2.5
diff -u -r1.37.2.1.2.4 -r1.37.2.1.2.5
--- Step.java 15 Jan 2003 14:43:05 -0000 1.37.2.1.2.4
+++ Step.java 24 Jan 2003 19:36:53 -0000 1.37.2.1.2.5
@@ -309,7 +309,8 @@
break;
default:
final XSLTC xsltc = getParser().getXSLTC();
- final ArrayList ni = xsltc.getNamesIndex();
+ final ArrayList ni =
+ CompilerContext.getInstance().getNamesIndex();
String name = null;
int star = 0;
@@ -325,7 +326,8 @@
else
namespace = name.substring(0,star-1);
- final int nsType = xsltc.registerNamespace(namespace);
+ final int nsType = CompilerContext.getInstance()
+ .registerNamespace(namespace);
final int ns = cpg.addInterfaceMethodref(DOM_INTF,
"getNamespaceAxisIterator",
"(II)"+NODE_ITERATOR_SIG);
@@ -395,7 +397,7 @@
else {
ParentLocationPath path = new ParentLocationPath(this,step);
try {
- path.typeCheck(CompilerContextImpl.getInstance());
+ path.typeCheck(CompilerContext.getInstance());
}
catch (TypeCheckError e) { }
path.translate(classGen, methodGen);
1.17.2.1.2.5 +8 -2
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/StepPattern.java
Index: StepPattern.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/StepPattern.java,v
retrieving revision 1.17.2.1.2.4
retrieving revision 1.17.2.1.2.5
diff -u -r1.17.2.1.2.4 -r1.17.2.1.2.5
--- StepPattern.java 15 Jan 2003 14:43:05 -0000 1.17.2.1.2.4
+++ StepPattern.java 24 Jan 2003 19:36:53 -0000 1.17.2.1.2.5
@@ -75,6 +75,12 @@
class StepPattern extends RelativePathPattern {
+ /**
+ * A thread local variable that holds a serial number for
+ * step patterns.
+ */
+ static private SerialNumber _stepPatternSerial = new SerialNumber(1);
+
private static final int NO_CONTEXT = 0;
private static final int SIMPLE_CONTEXT = 1;
private static final int GENERAL_CONTEXT = 2;
@@ -181,7 +187,7 @@
}
private String getNextFieldName() {
- return "__step_pattern_iter_" + getXSLTC().nextStepPatternSerial();
+ return "__step_pattern_iter_" + _stepPatternSerial.getNextValue();
}
public Type typeCheck(CompilerContext ccontext) throws TypeCheckError {
1.43.2.1.2.5 +16 -6
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.43.2.1.2.4
retrieving revision 1.43.2.1.2.5
diff -u -r1.43.2.1.2.4 -r1.43.2.1.2.5
--- Stylesheet.java 15 Jan 2003 14:43:05 -0000 1.43.2.1.2.4
+++ Stylesheet.java 24 Jan 2003 19:36:53 -0000 1.43.2.1.2.5
@@ -87,11 +87,18 @@
import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
import org.apache.xalan.xsltc.compiler.util.ErrorMsg;
import org.apache.xalan.xsltc.compiler.util.Util;
+import org.apache.xalan.xsltc.compiler.util.SerialNumber;
import org.apache.xalan.xsltc.DOM;
public final class Stylesheet extends SyntaxTreeNode {
+ /**
+ * A thread local variable that holds a serial number for
+ * stylesheets.
+ */
+ static private SerialNumber _stylesheetSerial = new SerialNumber(1);
+
private String _version;
private QName _name;
private String _systemId;
@@ -276,7 +283,8 @@
}
private QName makeStylesheetName(String prefix) {
- return getParser().getQName(prefix+getXSLTC().nextStylesheetSerial());
+ return getParser().getQName(prefix +
+ _stylesheetSerial.getNextValue());
}
/**
@@ -340,7 +348,7 @@
}
public void excludeExtensionPrefixes(Parser parser) {
- final StaticContextImpl scontext = getStaticContext();
+ final StaticContext scontext = getStaticContext();
final String excludePrefixes = getAttribute("exclude-result-prefixes");
final String extensionPrefixes =
getAttribute("extension-element-prefixes");
@@ -358,7 +366,7 @@
*/
public void parse(CompilerContext ccontext) {
final Parser parser = ccontext.getParser();
- final StaticContextImpl scontext = getStaticContext();
+ final StaticContext scontext = getStaticContext();
/*
// Make sure the XSL version set in this stylesheet
@@ -575,7 +583,8 @@
"<init>", "()V")));
// Put the names array into the translet - used for dom/translet mapping
- final ArrayList names = getXSLTC().getNamesIndex();
+ final ArrayList names =
+ CompilerContext.getInstance().getNamesIndex();
il.append(classGen.loadTranslet());
il.append(new PUSH(cpg, names.size()));
il.append(new ANEWARRAY(cpg.addClass(STRING)));
@@ -592,7 +601,8 @@
NAMES_INDEX_SIG)));
// Put the namespace names array into the translet
- final ArrayList namespaces = getXSLTC().getNamespaceIndex();
+ final ArrayList namespaces =
+ CompilerContext.getInstance().getNamespaceIndex();
il.append(classGen.loadTranslet());
il.append(new PUSH(cpg, namespaces.size()));
il.append(new ANEWARRAY(cpg.addClass(STRING)));
1.20.2.1.2.5 +54 -21
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.20.2.1.2.4
retrieving revision 1.20.2.1.2.5
diff -u -r1.20.2.1.2.4 -r1.20.2.1.2.5
--- SyntaxTreeNode.java 15 Jan 2003 14:43:05 -0000 1.20.2.1.2.4
+++ SyntaxTreeNode.java 24 Jan 2003 19:36:53 -0000 1.20.2.1.2.5
@@ -110,6 +110,16 @@
private int _line;
/**
+ * Reference to the owning template (null if top-level).
+ */
+ private Template _template;
+
+ /**
+ * Reference to the owning stylesheet.
+ */
+ private Stylesheet _stylesheet;
+
+ /**
* A "sentinel" that is used to denote unrecognised syntaxt
* tree nodes.
*/
@@ -122,19 +132,23 @@
public SyntaxTreeNode() {
_line = 0;
_qname = null;
+ init();
}
/**
* Creates a new SyntaxTreeNode with a 'null' QName.
+ *
* @param line Source file line number reference
*/
public SyntaxTreeNode(int line) {
_line = line;
_qname = null;
+ init();
}
/**
* Creates a new SyntaxTreeNode with no source file line number
reference.
+ *
* @param uri The element's namespace URI
* @param prefix The element's namespace prefix
* @param local The element's local name
@@ -142,6 +156,17 @@
public SyntaxTreeNode(String uri, String prefix, String local) {
_line = 0;
setQName(uri, prefix, local);
+ init();
+ }
+
+ /**
+ * Sets stylesheet and template references based on the static
+ * context.
+ */
+ private void init() {
+ final StaticContext scontext = getStaticContext();
+ _template = scontext.getCurrentTemplate();
+ _stylesheet = scontext.getCurrentStylesheet();
}
/**
@@ -152,6 +177,23 @@
return this == Dummy;
}
+ // -- Stylsheet and Template -----------------------------------------
+
+ /**
+ * Returns a reference to the stylesheet that holds this node.
+ */
+ public Stylesheet getStylesheet() {
+ return _stylesheet;
+ }
+
+ /**
+ * Returns a reference to the template that holds this node,
+ * or null if the node is a top-level element.
+ */
+ public Template getTemplate() {
+ return _template;
+ }
+
// -- Line number info ----------------------------------------------
/**
@@ -316,11 +358,12 @@
*/
protected final void parseContents(CompilerContext ccontext) {
ArrayList locals = null;
- StaticContextImpl scontext = getStaticContext();
+ StaticContext scontext = getStaticContext();
final int count = _contents.size();
for (int i = 0; i < count; i++) {
SyntaxTreeNode child = (SyntaxTreeNode) _contents.get(i);
+ scontext.setCurrentNode(child);
child.parse(ccontext);
// Is variable or parameter?
@@ -415,12 +458,12 @@
/**
* Get the import precedence of this element. The import precedence
equals
* the import precedence of the stylesheet in which this element occured.
+ *
* @return The import precedence of this syntax tree node.
*/
protected int getImportPrecedence() {
- Stylesheet stylesheet = getStylesheet();
- if (stylesheet == null) return Integer.MIN_VALUE;
- return stylesheet.getImportPrecedence();
+ if (_stylesheet == null) return Integer.MIN_VALUE;
+ return _stylesheet.getImportPrecedence();
}
// -- Dependency on evaluation context ------------------------------
@@ -532,15 +575,15 @@
* Returns a reference to the static context using this node as
* current.
*/
- public StaticContextImpl getStaticContext() {
- return StaticContextImpl.getInstance(this);
+ public StaticContext getStaticContext() {
+ return StaticContext.getInstance(this);
}
/**
* Returns a reference to the compiler context.
*/
- public CompilerContextImpl getCompilerContext() {
- return CompilerContextImpl.getInstance();
+ public CompilerContext getCompilerContext() {
+ return CompilerContext.getInstance();
}
// -------------------------------------------------------------------
@@ -564,7 +607,7 @@
// TEMP - this should go away !
public final Parser getParser() {
- return CompilerContextImpl.getInstance().getParser();
+ return CompilerContext.getInstance().getParser();
}
// TEMP - this should go away !
@@ -573,16 +616,6 @@
}
// TEMP - this should go away !
- protected Template getTemplate() {
- return getStaticContext().getCurrentTemplate();
- }
-
- // TEMP - this should go away !
- public Stylesheet getStylesheet() {
- return getStaticContext().getStylesheet();
- }
-
- // TEMP - this should go away !
protected String lookupNamespace(String prefix) {
return getStaticContext().getNamespace(prefix);
}
@@ -596,4 +629,4 @@
protected void compileResultTree(ClassGenerator classGen,
MethodGenerator methodGen) {
}
-}
\ No newline at end of file
+}
1.17.2.1.2.5 +3 -3
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.17.2.1.2.4
retrieving revision 1.17.2.1.2.5
diff -u -r1.17.2.1.2.4 -r1.17.2.1.2.5
--- Template.java 15 Jan 2003 14:43:05 -0000 1.17.2.1.2.4
+++ Template.java 24 Jan 2003 19:36:53 -0000 1.17.2.1.2.5
@@ -190,7 +190,7 @@
final String priority = getAttribute("priority");
final Parser parser = ccontext.getParser();
- _stylesheet = super.getStylesheet();
+ _stylesheet = getStylesheet();
if (name.length() > 0) {
_name = parser.getQNameIgnoreDefaultNs(name);
@@ -245,7 +245,7 @@
*/
public void parseSimplified(CompilerContext ccontext) {
final Parser parser = ccontext.getParser();
- final Stylesheet stylesheet = getStaticContext().getStylesheet();
+ final Stylesheet stylesheet = getStylesheet();
_stylesheet = stylesheet;
setParent(stylesheet);
1.6.8.1.2.4 +22 -17
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/UnionPathExpr.java
Index: UnionPathExpr.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/UnionPathExpr.java,v
retrieving revision 1.6.8.1.2.3
retrieving revision 1.6.8.1.2.4
diff -u -r1.6.8.1.2.3 -r1.6.8.1.2.4
--- UnionPathExpr.java 15 Jan 2003 14:43:05 -0000 1.6.8.1.2.3
+++ UnionPathExpr.java 24 Jan 2003 19:36:53 -0000 1.6.8.1.2.4
@@ -87,12 +87,26 @@
_rest = rest;
}
- public void setParent(Parser parser) {
- // find all expressions in this Union
+ public Type typeCheck(CompilerContext ccontext) throws TypeCheckError {
+ // Collect and flatten components first
+ prepareComponents(ccontext);
+
+ final int length = _components.length;
+ for (int i = 0; i < length; i++) {
+ if (_components[i].typeCheck(ccontext) != Type.NodeSet) {
+ _components[i] = new CastExpr(_components[i], Type.NodeSet);
+ }
+ }
+ return _type = Type.NodeSet;
+ }
+
+ private void prepareComponents(CompilerContext ccontext) {
+ // Find all expressions in this Union
final ArrayList components = new ArrayList();
flatten(components);
final int size = components.size();
_components = (Expression[])components.toArray(new Expression[size]);
+
for (int i = 0; i < size; i++) {
_components[i].setParent(this);
if (_components[i] instanceof Step) {
@@ -108,24 +122,11 @@
if (Axis.isReverse[axis]) _reverse = true;
}
}
+
// No need to reverse anything if another expression lies on top of this
if (getParent() instanceof Expression) _reverse = false;
}
- public Type typeCheck(CompilerContext ccontext) throws TypeCheckError {
- final int length = _components.length;
- for (int i = 0; i < length; i++) {
- if (_components[i].typeCheck(ccontext) != Type.NodeSet) {
- _components[i] = new CastExpr(_components[i], Type.NodeSet);
- }
- }
- return _type = Type.NodeSet;
- }
-
- public String toString() {
- return "union(" + _pathExpr + ", " + _rest + ')';
- }
-
private void flatten(ArrayList components) {
components.add(_pathExpr);
if (_rest != null) {
@@ -173,5 +174,9 @@
il.append(new INVOKEINTERFACE(order, 3));
}
+ }
+
+ public String toString() {
+ return "union(" + _pathExpr + ", " + _rest + ')';
}
}
1.3.2.1.2.2 +17 -13
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/UnresolvedRef.java
Index: UnresolvedRef.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/UnresolvedRef.java,v
retrieving revision 1.3.2.1.2.1
retrieving revision 1.3.2.1.2.2
diff -u -r1.3.2.1.2.1 -r1.3.2.1.2.2
--- UnresolvedRef.java 15 Jan 2003 14:43:05 -0000 1.3.2.1.2.1
+++ UnresolvedRef.java 24 Jan 2003 19:36:53 -0000 1.3.2.1.2.2
@@ -91,11 +91,11 @@
}
private VariableRefBase resolve(CompilerContext ccontext) {
- final Parser parser = ccontext.getParser();
+ final StaticContext scontext = getStaticContext();
// At this point the AST is already built and we should be able to
// find any declared global variable or parameter
- VariableBase ref = parser.lookupVariable(_variableName);
+ VariableBase ref = scontext.getVariable(_variableName);
if (ref == null) {
ref = getStaticContext().getVariable(_variableName);
}
@@ -106,15 +106,17 @@
// Insert the referenced variable as something the parent variable
// is dependent of (this class should only be used under variables)
- if ((_var = findParentVariable()) != null) _var.addDependency(ref);
+ if ((_var = findParentVariable()) != null) {
+ _var.addDependency(ref);
+ }
- // Instanciate a true variable/parameter ref
- if (ref instanceof Variable)
- return(new VariableRef((Variable)ref));
- else if (ref instanceof Param)
- return(new ParameterRef((Param)ref));
- else
- return null;
+ if (ref instanceof Variable) {
+ return(new VariableRef((Variable) ref));
+ }
+ else if (ref instanceof Param) {
+ return(new ParameterRef((Param) ref));
+ }
+ return null;
}
public Type typeCheck(CompilerContext ccontext) throws TypeCheckError {
@@ -130,10 +132,12 @@
}
public void translate(ClassGenerator classGen, MethodGenerator
methodGen) {
- if (_ref != null)
+ if (_ref != null) {
_ref.translate(classGen, methodGen);
- else
+ }
+ else {
reportError();
+ }
}
public String toString() {
1.22.8.1.2.5 +2 -2
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.22.8.1.2.4
retrieving revision 1.22.8.1.2.5
diff -u -r1.22.8.1.2.4 -r1.22.8.1.2.5
--- Variable.java 15 Jan 2003 14:43:05 -0000 1.22.8.1.2.4
+++ Variable.java 24 Jan 2003 19:36:53 -0000 1.22.8.1.2.5
@@ -86,7 +86,7 @@
*/
public void parse(CompilerContext ccontext) {
final Parser parser = ccontext.getParser();
- final StaticContextImpl scontext = getStaticContext();
+ final StaticContext scontext = getStaticContext();
// Parse 'name' and 'select' attributes plus parameter contents
super.parse(ccontext);
1.16.2.1.2.4 +3 -2
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.16.2.1.2.3
retrieving revision 1.16.2.1.2.4
diff -u -r1.16.2.1.2.3 -r1.16.2.1.2.4
--- VariableBase.java 15 Jan 2003 14:43:05 -0000 1.16.2.1.2.3
+++ VariableBase.java 24 Jan 2003 19:36:53 -0000 1.16.2.1.2.4
@@ -233,6 +233,7 @@
*/
public void parse(CompilerContext ccontext) {
final Parser parser = ccontext.getParser();
+ final StaticContext scontext = getStaticContext();
// Get the 'name attribute
String name = getAttribute("name");
@@ -244,7 +245,7 @@
reportError(this, parser, ErrorMsg.REQUIRED_ATTR_ERR, "name");
// Check whether variable/param of the same name is already in scope
- VariableBase other = parser.lookupVariable(_name);
+ VariableBase other = scontext.getVariable(_name);
if ((other != null) && (other.getParent() == getParent())) {
reportError(this, parser, ErrorMsg.VARIABLE_REDEF_ERR, name);
}
1.7.8.1.2.4 +3 -2
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Whitespace.java
Index: Whitespace.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Whitespace.java,v
retrieving revision 1.7.8.1.2.3
retrieving revision 1.7.8.1.2.4
diff -u -r1.7.8.1.2.3 -r1.7.8.1.2.4
--- Whitespace.java 15 Jan 2003 14:43:05 -0000 1.7.8.1.2.3
+++ Whitespace.java 24 Jan 2003 19:36:53 -0000 1.7.8.1.2.4
@@ -438,7 +438,8 @@
qname = parser.getQName(rule.getElement());
// Register the element.
- final int elementType = xsltc.registerElement(qname);
+ final int elementType =
+ CompilerContext.getInstance().registerElement(qname);
il.append(new ILOAD(paramType));
il.append(new PUSH(cpg, elementType));
1.42.2.1.2.5 +213 -314
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.42.2.1.2.4
retrieving revision 1.42.2.1.2.5
diff -u -r1.42.2.1.2.4 -r1.42.2.1.2.5
--- XSLTC.java 15 Jan 2003 14:43:05 -0000 1.42.2.1.2.4
+++ XSLTC.java 24 Jan 2003 19:36:53 -0000 1.42.2.1.2.5
@@ -92,160 +92,178 @@
public final class XSLTC {
- // A reference to the main stylesheet parser object.
+ /**
+ * These constants define the various translet output methods.
+ */
+ public static final int FILE_OUTPUT = 0;
+ public static final int JAR_OUTPUT = 1;
+ public static final int BYTEARRAY_OUTPUT = 2;
+ public static final int CLASSLOADER_OUTPUT = 3;
+ public static final int BYTEARRAY_AND_FILE_OUTPUT = 4;
+ public static final int BYTEARRAY_AND_JAR_OUTPUT = 5;
+
+ /**
+ * A reference to the parser object.
+ */
private Parser _parser;
- // A reference to an external XMLReader (SAX parser) passed to us
+ /**
+ * A reference to the XMLReader (producer of SAX events) from
+ * which the stylesheet will be read.
+ */
private XMLReader _reader = null;
- // A reference to an external SourceLoader (for use with include/import)
+ /**
+ * The source loader used for xsl:include and xsl:import.
+ */
private SourceLoader _loader = null;
- // A reference to the stylesheet being compiled.
+ /**
+ * A reference to the stylesheet being compiled.
+ */
private Stylesheet _stylesheet = null;
- // Counters used by various classes to generate unique names.
- // private int _variableSerial = 1;
- private int _modeSerial = 1;
- private int _stylesheetSerial = 1;
- private int _stepPatternSerial = 1;
- private int _helperClassSerial = 0;
- private int _attributeSetSerial = 0;
-
- private int[] _numberFieldIndexes;
-
- // Name index tables
- private int _nextGType; // Next available element type
- private ArrayList _namesIndex; // Index of all registered QNames
- private HashMap _elements; // HashMap of all registered elements
- private HashMap _attributes; // HashMap of all registered attributes
-
- // Namespace index tables
- private int _nextNSType; // Next available namespace type
- private ArrayList _namespaceIndex; // Index of all registered
namespaces
- private HashMap _namespaces; // HashMap of all registered namespaces
+ /**
+ * Class name either set by -o <class-name> or inferred
+ * from stylesheet name.
+ */
+ private String _className = null;
- // These define the various methods for outputting the translet
- public static final int FILE_OUTPUT = 0;
- public static final int JAR_OUTPUT = 1;
- public static final int BYTEARRAY_OUTPUT = 2;
- public static final int CLASSLOADER_OUTPUT = 3;
- public static final int BYTEARRAY_AND_FILE_OUTPUT = 4;
- public static final int BYTEARRAY_AND_JAR_OUTPUT = 5;
+ /**
+ * Command-line option -x.
+ */
+ private boolean _debug = false;
+ /**
+ * Command-line option -j <jar-file-name>
+ */
+ private String _jarFileName = null;
- // Compiler options (passed from command line or XSLTC client)
- private boolean _debug = false; // -x
- private String _jarFileName = null; // -j <jar-file-name>
- private String _className = null; // -o <class-name>
- private String _packageName = null; // -p <package-name>
- private File _destDir = null; // -d <directory-name>
- private int _outputType = FILE_OUTPUT; // by default
-
- private ArrayList _classes;
- private ArrayList _bcelClasses;
- private boolean _callsNodeset = false;
- private boolean _multiDocument = false;
-
- /**
- * Set to true if template inlining is requested. Template
- * inlining used to be the default, but we have found that
- * Hotspots does a better job with shorter methods, so the
- * default is *not* to inline now.
+ /**
+ * Command-line option -p <package-name>
+ */
+ private String _packageName = null;
+
+ /**
+ * Command-line option -d <directory-name>
+ */
+ private File _destDir = null;
+
+ /**
+ * Compiler's output type.
+ */
+ private int _outputType = FILE_OUTPUT;
+
+ /**
+ * Array of classes represented as byte arrays. This array holds
+ * all the classes compiled by XSLTC.
*/
- private boolean _templateInlining = false;
+ private ArrayList _classes;
+
+ /**
+ * Array needed for the generation of jar files (-j option).
+ */
+ private ArrayList _bcelClasses;
+
+ /**
+ * A reference to the (single) instance of the compiler context.
+ */
+ private CompilerContext _ccontext;
/**
* XSLTC compiler constructor
*/
public XSLTC() {
_parser = new Parser(this);
+ _ccontext = CompilerContext.getInstance(this);
}
+ /**
+ * Initializes the compiler to compile a new stylesheet
+ */
+ public void init() {
+ reset();
+ _reader = null;
+ _classes = new ArrayList();
+ _bcelClasses = new ArrayList();
+ }
+
+ /**
+ * Initializes the compiler to produce a new translet
+ */
+ private void reset() {
+ _parser.init();
+ _ccontext.init();
+
+ // IMPORTANT TODO - reset all thread variables here!!!
+ // How are we going to do this. Can we get a list
+ // of all the thread variables???
+ }
+
+ /**
+ * Returns a reference to the parser object.
+ */
public Parser getParser() {
return _parser;
}
/**
- * Only for user by the internal TrAX implementation.
+ * Sets a new parser object (used by TrAX).
*/
public void setParser(Parser parser) {
- _parser = parser;
+ _parser = parser;
}
/**
- * Only for user by the internal TrAX implementation.
+ * Returns a reference to the compiler context (used by TrAX).
*/
- public void setOutputType(int type) {
- _outputType = type;
+ public CompilerContext getCompilerContext() {
+ return _ccontext;
}
/**
- * Only for user by the internal TrAX implementation.
+ * Set the output type of the transform (used by TrAX).
*/
- public Properties getOutputProperties() {
- return _parser.getOutputProperties();
+ public void setOutputType(int type) {
+ _outputType = type;
}
/**
- * Initializes the compiler to compile a new stylesheet
+ * Turn debugging messages on/off.
*/
- public void init() {
- reset();
- _reader = null;
- _classes = new ArrayList();
- _bcelClasses = new ArrayList();
+ public void setDebug(boolean debug) {
+ _debug = debug;
}
/**
- * Initializes the compiler to produce a new translet
+ * Get current debugging message setting.
*/
- private void reset() {
- _nextGType = DOM.NTYPES;
- _elements = new HashMap();
- _attributes = new HashMap();
- _namespaces = new HashMap();
- _namespaces.put("",new Integer(_nextNSType));
- _namesIndex = new ArrayList(128);
- _namespaceIndex = new ArrayList(32);
- _parser.init();
- //_variableSerial = 1;
- _modeSerial = 1;
- _stylesheetSerial = 1;
- _stepPatternSerial = 1;
- _helperClassSerial = 0;
- _attributeSetSerial = 0;
- _multiDocument = false;
- _numberFieldIndexes = new int[] {
- -1, // LEVEL_SINGLE
- -1, // LEVEL_MULTIPLE
- -1 // LEVEL_ANY
- };
+ public boolean getDebug() {
+ return _debug;
}
/**
- * Defines an external SourceLoader to provide the compiler with
documents
- * referenced in xsl:include/import
- * @param loader The SourceLoader to use for include/import
+ * Returns the output properties (used by TrAX).
*/
- public void setSourceLoader(SourceLoader loader) {
- _loader = loader;
+ public Properties getOutputProperties() {
+ return _parser.getOutputProperties();
}
/**
- * Set a flag indicating if templates are to be inlined or not. The
- * default is to do inlining, but this causes problems when the
- * stylesheets have a large number of templates (e.g. branch targets
- * exceeding 64K or a length of a method exceeding 64K).
+ * Defines an external SourceLoader to provide the compiler with
+ * documents referenced in xsl:include and xsl:import.
+ *
+ * @param loader The SourceLoader to use for include/import
*/
- public void setTemplateInlining(boolean templateInlining) {
- _templateInlining = templateInlining;
+ public void setSourceLoader(SourceLoader loader) {
+ _loader = loader;
}
/**
* Set the parameters to use to locate the correct <?xml-stylesheet ...?>
* processing instruction in the case where the input document to the
* compiler (and parser) is an XML document.
+ *
* @param media The media attribute to be matched. May be null, in which
* case the prefered templates will be used (i.e. alternate = no).
* @param title The value of the title attribute to match. May be null.
@@ -257,6 +275,7 @@
/**
* Compiles an XSL stylesheet pointed to by a URL
+ *
* @param url An URL containing the input XSL stylesheet
*/
public boolean compile(URL url) {
@@ -274,9 +293,10 @@
}
/**
- * Compiles an XSL stylesheet pointed to by a URL
- * @param url An URL containing the input XSL stylesheet
- * @param name The name to assign to the translet class
+ * Compiles an XSL stylesheet pointed to by a URL.
+ *
+ * @param url An URL containing the input XSL stylesheet.
+ * @param name The name to assign to the translet class.
*/
public boolean compile(URL url, String name) {
try {
@@ -287,16 +307,19 @@
return compile(input, name);
}
catch (IOException e) {
- _parser.reportError(Constants.FATAL, new ErrorMsg(e.getMessage()));
+ _parser.reportError(Constants.FATAL,
+ new ErrorMsg(e.getMessage()));
return false;
}
}
/**
- * Compiles an XSL stylesheet passed in through an InputStream
- * @param input An InputStream that will pass in the stylesheet contents
- * @param name The name of the translet class to generate
- * @return 'true' if the compilation was successful
+ * Compiles an XSL stylesheet from an InputStream.
+ *
+ * @param input An InputStream that will pass in the stylesheet
+ * contents.
+ * @param name The name of the translet class to generate.
+ * @return 'true' if the compilation was successful.
*/
public boolean compile(InputStream stream, String name) {
final InputSource input = new InputSource(stream);
@@ -305,6 +328,43 @@
}
/**
+ * Compiles a set of stylesheets from a list of URLs.
+ *
+ * @param stylesheets A ArrayList containing URLs.
+ * @return 'true' if the compilation was successful.
+ */
+ public boolean compile(ArrayList stylesheets) {
+ // Get the number of stylesheets (ie. URLs) in the vector
+ final int count = stylesheets.size();
+
+ // Return straight away if the vector is empty
+ if (count == 0) return true;
+
+ // Special handling needed if the URL count is one, becuase the
+ // _className global must not be reset if it was set explicitly
+ if (count == 1) {
+ final Object url = stylesheets.get(0);
+ if (url instanceof URL) {
+ return compile((URL)url);
+ }
+ return false;
+ }
+ else {
+ // Traverse all elements in the vector and compile
+ final Iterator urls = stylesheets.iterator();
+
+ while (urls.hasNext()) {
+ _className = null; // reset, so that new name will be
computed
+ final Object url = urls.next();
+ if (url instanceof URL) {
+ if (!compile((URL)url)) return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ /**
* Compiles an XSL stylesheet passed in through an InputStream
* @param input An InputSource that will pass in the stylesheet contents
* @param name The name of the translet class to generate - can be null
@@ -323,12 +383,15 @@
// Set the translet class name if not already set
if (_className == null) {
- if (name != null)
+ if (name != null) {
setClassName(name);
- else if ((systemId != null) && (!systemId.equals("")))
+ }
+ else if ((systemId != null) && (!systemId.equals(""))) {
setClassName(Util.baseName(systemId));
- else
+ }
+ else {
setClassName("GregorSamsa"); // default translet name
+ }
}
// Get the root node of the abstract syntax tree
@@ -341,23 +404,23 @@
}
// Compile the translet - this is where the work is done!
- if ((!_parser.errorsFound()) && (element != null)) {
+ if (!_parser.errorsFound() && element != null) {
// Create a Stylesheet element from the root node
_stylesheet = _parser.makeStylesheet(element);
_stylesheet.setSourceLoader(_loader);
_stylesheet.setSystemId(systemId);
_stylesheet.setParentStylesheet(null);
- _stylesheet.setTemplateInlining(_templateInlining);
- _parser.setCurrentStylesheet(_stylesheet);
- // Create AST under the Stylesheet element (parse & type-check)
+ // Set current stylesheet in static context
+ StaticContext scontext = StaticContext.getInstance(null);
+ scontext.setCurrentStylesheet(_stylesheet);
+
+ // Create, parse and typecheck AST
_parser.createAST(_stylesheet);
}
- // Generate the bytecodes and output the translet class(es)
- if ((!_parser.errorsFound()) && (_stylesheet != null)) {
- _stylesheet.setCallsNodeset(_callsNodeset);
- _stylesheet.setMultiDocument(_multiDocument);
+ // Generate the bytecodes and output the translet class(es)
+ if (!_parser.errorsFound() && _stylesheet != null) {
// Class synchronization is needed for BCEL
synchronized (getClass()) {
_stylesheet.translate();
@@ -379,66 +442,35 @@
}
/**
- * Compiles a set of stylesheets pointed to by a ArrayList of URLs
- * @param stylesheets A ArrayList containing URLs pointing to the
stylesheets
- * @return 'true' if the compilation was successful
- */
- public boolean compile(ArrayList stylesheets) {
- // Get the number of stylesheets (ie. URLs) in the vector
- final int count = stylesheets.size();
-
- // Return straight away if the vector is empty
- if (count == 0) return true;
-
- // Special handling needed if the URL count is one, becuase the
- // _className global must not be reset if it was set explicitly
- if (count == 1) {
- final Object url = stylesheets.get(0);
- if (url instanceof URL)
- return compile((URL)url);
- else
- return false;
- }
- else {
- // Traverse all elements in the vector and compile
- final Iterator urls = stylesheets.iterator();
- while (urls.hasNext()) {
- _className = null; // reset, so that new name will be computed
- final Object url = urls.next();
- if (url instanceof URL) {
- if (!compile((URL)url)) return false;
- }
- }
- }
- return true;
- }
-
- /**
- * Returns an array of bytecode arrays generated by a compilation.
- * @return JVM bytecodes that represent translet class definition
+ * Returns an array of bytecode arrays generated by the compilation
+ * process.
+ *
+ * @return JVM bytecodes for translet and helper classes.
*/
public byte[][] getBytecodes() {
final int count = _classes.size();
final byte[][] result = new byte[count][1];
- for (int i = 0; i < count; i++)
+ for (int i = 0; i < count; i++) {
result[i] = (byte[])_classes.get(i);
+ }
return result;
}
/**
- * Compiles a stylesheet pointed to by a URL. The result is put in a
- * set of byte arrays. One byte array for each generated class.
- * @param name The name of the translet class to generate
- * @param input An InputSource that will pass in the stylesheet contents
- * @param outputType The output type
- * @return JVM bytecodes that represent translet class definition
+ * Compiles a stylesheet from an InputSource. The result is returned
+ * as an array of byte arrays.
+ *
+ * @param name The name of the translet class to generate.
+ * @param input An InputSource that will pass in the stylesheet contents.
+ * @param outputType The output type.
+ * @return JVM bytecodes that represent translet class definition.
*/
public byte[][] compile(String name, InputSource input, int outputType) {
_outputType = outputType;
- if (compile(input, name))
+ if (compile(input, name)) {
return getBytecodes();
- else
- return null;
+ }
+ return null;
}
/**
@@ -491,31 +523,6 @@
}
/**
- * This method is called by the XPathParser when it encounters a call
- * to the document() function. Affects the DOM used by the translet.
- */
- protected void setMultiDocument(boolean flag) {
- _multiDocument = flag;
- }
-
- 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;
- }
-
- /**
* Set the class name for the generated translet. This class name is
* overridden if multiple stylesheets are compiled in one go using the
* compile(ArrayList urls) method.
@@ -526,10 +533,12 @@
final String noext = Util.noExtName(base);
String name = Util.toJavaName(noext);
- if (_packageName == null)
+ if (_packageName == null) {
_className = name;
- else
+ }
+ else {
_className = _packageName + '.' + name;
+ }
}
/**
@@ -551,10 +560,12 @@
* Generate an output File object to send the translet to
*/
private File getOutputFile(String className) {
- if (_destDir != null)
+ if (_destDir != null) {
return new File(_destDir, classFileName(className));
- else
+ }
+ else {
return new File(classFileName(className));
+ }
}
/**
@@ -587,10 +598,12 @@
*/
public void setJarFileName(String jarFileName) {
final String JAR_EXT = ".jar";
- if (jarFileName.endsWith(JAR_EXT))
+ if (jarFileName.endsWith(JAR_EXT)) {
_jarFileName = jarFileName;
- else
+ }
+ else {
_jarFileName = jarFileName + JAR_EXT;
+ }
_outputType = JAR_OUTPUT;
}
@@ -612,108 +625,6 @@
return _stylesheet;
}
- /**
- * Registers an attribute and gives it a type so that it can be mapped to
- * DOM attribute types at run-time.
- */
- public int registerAttribute(QName name) {
- Integer code = (Integer)_attributes.get(name.toString());
- if (code == null) {
- code = new Integer(_nextGType++);
- _attributes.put(name.toString(), code);
- final String uri = name.getNamespace();
- final String local = "@"+name.getLocalPart();
- if ((uri != null) && (!uri.equals("")))
- _namesIndex.add(uri+":"+local);
- else
- _namesIndex.add(local);
- if (name.getLocalPart().equals("*")) {
- registerNamespace(name.getNamespace());
- }
- }
- return code.intValue();
- }
-
- /**
- * Registers an element and gives it a type so that it can be mapped to
- * DOM element types at run-time.
- */
- public int registerElement(QName name) {
- // Register element (full QName)
- Integer code = (Integer)_elements.get(name.toString());
- if (code == null) {
- _elements.put(name.toString(), code = new Integer(_nextGType++));
- _namesIndex.add(name.toString());
- }
- if (name.getLocalPart().equals("*")) {
- registerNamespace(name.getNamespace());
- }
- return code.intValue();
- }
-
- /**
- * Registers an element and gives it a type so that it can be mapped to
- * DOM element types at run-time.
- */
- public int registerNamespace(QName name, StaticContext scontext) {
- final String uri = scontext.getNamespace(name.toString());
- return registerNamespace(uri);
- }
-
- /**
- * Registers a namespace and gives it a type so that it can be mapped to
- * DOM namespace types at run-time.
- */
- public int registerNamespace(String namespaceURI) {
- Integer code = (Integer)_namespaces.get(namespaceURI);
- if (code == null) {
- code = new Integer(_nextNSType++);
- _namespaces.put(namespaceURI,code);
- _namespaceIndex.add(namespaceURI);
- }
- return code.intValue();
- }
-
- public int nextModeSerial() {
- return _modeSerial++;
- }
-
- public int nextStylesheetSerial() {
- return _stylesheetSerial++;
- }
-
- public int nextStepPatternSerial() {
- return _stepPatternSerial++;
- }
-
- public int[] getNumberFieldIndexes() {
- return _numberFieldIndexes;
- }
-
- public int nextHelperClassSerial() {
- return _helperClassSerial++;
- }
-
- public int nextAttributeSetSerial() {
- return _attributeSetSerial++;
- }
-
- public ArrayList getNamesIndex() {
- return _namesIndex;
- }
-
- public ArrayList getNamespaceIndex() {
- return _namespaceIndex;
- }
-
- /**
- * Returns a unique name for every helper class needed to
- * execute a translet.
- */
- public String getHelperClassName() {
- return getClassName() + '$' + _helperClassSerial++;
- }
-
public void dumpClass(JavaClass clazz) {
if (_outputType == FILE_OUTPUT ||
@@ -783,11 +694,13 @@
final String now = (new Date()).toString();
final java.util.jar.Attributes.Name dateAttr =
new java.util.jar.Attributes.Name("Date");
+
while (classes.hasNext()) {
final JavaClass clazz = (JavaClass)classes.next();
final String className = clazz.getClassName().replace('.','/');
final java.util.jar.Attributes attr = new
java.util.jar.Attributes();
- attr.put(dateAttr, now);
+
+ attr.put(dateAttr, now);
map.put(className+".class", attr);
}
@@ -795,7 +708,8 @@
final JarOutputStream jos =
new JarOutputStream(new FileOutputStream(jarFile), manifest);
classes = _bcelClasses.iterator();
- while (classes.hasNext()) {
+
+ while (classes.hasNext()) {
final JavaClass clazz = (JavaClass)classes.next();
final String className = clazz.getClassName().replace('.','/');
jos.putNextEntry(new JarEntry(className+".class"));
@@ -805,19 +719,4 @@
}
jos.close();
}
-
- /**
- * Turn debugging messages on/off
- */
- public void setDebug(boolean debug) {
- _debug = debug;
- }
-
- /**
- * Get current debugging message setting
- */
- public boolean debug() {
- return _debug;
- }
-
}
1.18.2.1.2.4 +2 -2
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/XslAttribute.java
Index: XslAttribute.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/XslAttribute.java,v
retrieving revision 1.18.2.1.2.3
retrieving revision 1.18.2.1.2.4
diff -u -r1.18.2.1.2.3 -r1.18.2.1.2.4
--- XslAttribute.java 15 Jan 2003 14:43:05 -0000 1.18.2.1.2.3
+++ XslAttribute.java 24 Jan 2003 19:36:53 -0000 1.18.2.1.2.4
@@ -147,7 +147,7 @@
_prefix = prefix;
}
else {
- _prefix = ccontext.generateNamespacePrefix();
+ _prefix = ccontext.getFreshNsPrefix();
generated = true;
}
}
1.17.2.1.2.5 +3 -3
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/XslElement.java
Index: XslElement.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/XslElement.java,v
retrieving revision 1.17.2.1.2.4
retrieving revision 1.17.2.1.2.5
diff -u -r1.17.2.1.2.4 -r1.17.2.1.2.5
--- XslElement.java 15 Jan 2003 14:43:05 -0000 1.17.2.1.2.4
+++ XslElement.java 24 Jan 2003 19:36:54 -0000 1.17.2.1.2.5
@@ -150,7 +150,7 @@
return;
}
- final QName qname = parser.getQNameSafe(name);
+ final QName qname = parser.getQName(name, true);
String prefix = qname.getPrefix();
String local = qname.getLocalPart();
@@ -176,7 +176,7 @@
if (isLiteral(namespace)) {
prefix = lookupPrefix(namespace);
if (prefix == null) {
- prefix = ccontext.generateNamespacePrefix();
+ prefix = ccontext.getFreshNsPrefix();
}
}
1.39.2.1.2.4 +15 -10
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.39.2.1.2.3
retrieving revision 1.39.2.1.2.4
diff -u -r1.39.2.1.2.3 -r1.39.2.1.2.4
--- xpath.cup 15 Jan 2003 14:43:05 -0000 1.39.2.1.2.3
+++ xpath.cup 24 Jan 2003 19:36:54 -0000 1.39.2.1.2.4
@@ -107,10 +107,16 @@
*/
public StaticContext _scontext;
+ /**
+ * Reference to the compiler context.
+ */
+ public CompilerContext _ccontext;
+
public XPathParser(CompilerContext ccontext, StaticContext scontext) {
_parser = ccontext.getParser();
_xsltc = ccontext.getXSLTC();
_scontext = scontext;
+ _ccontext = ccontext;
}
public int getLineNumber() {
@@ -122,11 +128,11 @@
}
public void setMultiDocument(boolean flag) {
- _xsltc.setMultiDocument(flag);
+ _ccontext.setMultiDocument(flag);
}
public void setCallsNodeset(boolean flag) {
- _xsltc.setCallsNodeset(flag);
+ _ccontext.setCallsNodeset(flag);
}
public int findNodeType(int axis, Object test) {
@@ -140,15 +146,14 @@
}
else {
QName name = (QName)test;
+ final String local = name.getLocalPart();
if (axis == Axis.NAMESPACE) {
- return (name.toString().equals("*")) ? -1
- : _xsltc.registerNamespace(name, _scontext);
+ return (local.equals("*")) ? -1
+ : _ccontext.registerPrefix(local);
}
if (name.getNamespace() == null) {
- final String local = name.getLocalPart();
-
if (local.equals("*")) {
return (axis == Axis.ATTRIBUTE) ? NodeTest.ATTRIBUTE
: NodeTest.ELEMENT;
@@ -158,8 +163,8 @@
}
}
- return (axis == Axis.ATTRIBUTE) ? _xsltc.registerAttribute(name)
- : _xsltc.registerElement(name);
+ return (axis == Axis.ATTRIBUTE) ? _ccontext.registerAttribute(name)
+ : _ccontext.registerElement(name);
}
}
@@ -195,7 +200,7 @@
*/
final SyntaxTreeNode lookupName(QName name) {
// Is it a local var or param ?
- final SyntaxTreeNode result = _parser.lookupVariable(name);
+ final SyntaxTreeNode result = _scontext.getVariable(name);
if (result != null)
return(result);
else
No revision
No revision
1.14.2.1.2.2 +12 -12
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.14.2.1.2.1
retrieving revision 1.14.2.1.2.2
diff -u -r1.14.2.1.2.1 -r1.14.2.1.2.2
--- ErrorMsg.java 2 Dec 2002 15:51:22 -0000 1.14.2.1.2.1
+++ ErrorMsg.java 24 Jan 2003 19:36:59 -0000 1.14.2.1.2.2
@@ -180,14 +180,14 @@
public static final int ERROR_MSG = 88;
public static final int TRANSFORM_WITH_TRANSLET_STR = 89;
public static final int TRANSFORM_WITH_JAR_STR = 90;
-
+
// All error messages are localized and are stored in resource bundles.
// This array and the following 4 strings are read from that bundle.
private static String[] _errorMessages;
private static String _compileError;
private static String _compileWarning;
private static String _runtimeError;
-
+
public final static String ERROR_MESSAGES_KEY = "error-messages";
public final static String COMPILER_ERROR_KEY = "compile-error";
public final static String COMPILER_WARNING_KEY = "compile-warning";
@@ -205,7 +205,7 @@
_code = code;
_line = 0;
}
-
+
public ErrorMsg(String message) {
_code = -1;
_message = message;
@@ -274,11 +274,11 @@
}
private String getFileName(SyntaxTreeNode node) {
- Stylesheet stylesheet = node.getStylesheet();
- if (stylesheet != null)
+ final Stylesheet stylesheet = node.getStylesheet();
+ if (stylesheet != null) {
return stylesheet.getSystemId();
- else
- return null;
+ }
+ return null;
}
private String formatLine() {
@@ -294,26 +294,26 @@
}
return result.toString();
}
-
+
/**
* This version of toString() uses the _params instance variable
* to format the message. If the <code>_code</code> is negative
* the use _message as the error string.
*/
public String toString() {
- String suffix = (_params == null) ?
+ String suffix = (_params == null) ?
(_code >= 0 ? new String(_errorMessages[_code]) : _message)
: MessageFormat.format(_errorMessages[_code], _params);
return formatLine() + suffix;
}
-
+
public String toString(Object obj) {
Object params[] = new Object[1];
params[0] = obj.toString();
String suffix = MessageFormat.format(_errorMessages[_code], params);
return formatLine() + suffix;
}
-
+
public String toString(Object obj0, Object obj1) {
Object params[] = new Object[2];
params[0] = obj0.toString();
No revision
No revision
1.14.2.1.2.2 +15 -11
xml-xalan/java/src/org/apache/xalan/xsltc/trax/TemplatesHandlerImpl.java
Index: TemplatesHandlerImpl.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/trax/TemplatesHandlerImpl.java,v
retrieving revision 1.14.2.1.2.1
retrieving revision 1.14.2.1.2.2
diff -u -r1.14.2.1.2.1 -r1.14.2.1.2.2
--- TemplatesHandlerImpl.java 2 Dec 2002 15:51:28 -0000 1.14.2.1.2.1
+++ TemplatesHandlerImpl.java 24 Jan 2003 19:37:00 -0000 1.14.2.1.2.2
@@ -76,8 +76,8 @@
/**
* Implementation of a JAXP1.1 TemplatesHandler
*/
-public class TemplatesHandlerImpl extends Parser
- implements TemplatesHandler, SourceLoader
+public class TemplatesHandlerImpl extends Parser
+ implements TemplatesHandler, SourceLoader
{
/**
* System ID for this stylesheet.
@@ -103,8 +103,8 @@
/**
* Default constructor
*/
- protected TemplatesHandlerImpl(int indentNumber,
- TransformerFactoryImpl tfactory)
+ protected TemplatesHandlerImpl(int indentNumber,
+ TransformerFactoryImpl tfactory)
{
super(null);
_indentNumber = indentNumber;
@@ -191,18 +191,22 @@
stylesheet = makeStylesheet(root);
stylesheet.setSystemId(_systemId);
stylesheet.setParentStylesheet(null);
- setCurrentStylesheet(stylesheet);
+
+ // Set current stylesheet in static context
+ StaticContext scontext = StaticContext.getInstance(null);
+ scontext.setCurrentStylesheet(stylesheet);
// Set it as top-level in the XSLTC object
xsltc.setStylesheet(stylesheet);
- // Create AST under the Stylesheet element
+ // Create AST under the Stylesheet element
createAST(stylesheet);
}
// Generate the bytecodes and output the translet class(es)
if (!errorsFound() && stylesheet != null) {
- stylesheet.setMultiDocument(xsltc.isMultiDocument());
+ stylesheet.setMultiDocument(
+ xsltc.getCompilerContext().getMultiDocument());
stylesheet.translate();
}
@@ -210,8 +214,8 @@
// Check that the transformation went well before returning
final byte[][] bytecodes = xsltc.getBytecodes();
if (bytecodes != null) {
- final TemplatesImpl templates =
- new TemplatesImpl(xsltc.getBytecodes(), transletName,
+ final TemplatesImpl templates =
+ new TemplatesImpl(xsltc.getBytecodes(), transletName,
getOutputProperties(), _indentNumber, _tfactory);
// Set URIResolver on templates object
@@ -231,7 +235,7 @@
/**
* Recieve an object for locating the origin of SAX document events.
* Most SAX parsers will use this method to inform content handler
- * of the location of the parsed document.
+ * of the location of the parsed document.
*/
public void setDocumentLocator(Locator locator) {
super.setDocumentLocator(locator);
1.45.2.1.2.3 +4 -2
xml-xalan/java/src/org/apache/xalan/xsltc/trax/TransformerFactoryImpl.java
Index: TransformerFactoryImpl.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/trax/TransformerFactoryImpl.java,v
retrieving revision 1.45.2.1.2.2
retrieving revision 1.45.2.1.2.3
diff -u -r1.45.2.1.2.2 -r1.45.2.1.2.3
--- TransformerFactoryImpl.java 10 Jan 2003 16:50:50 -0000
1.45.2.1.2.2
+++ TransformerFactoryImpl.java 24 Jan 2003 19:37:00 -0000
1.45.2.1.2.3
@@ -568,7 +568,9 @@
// Create and initialize a stylesheet compiler
final XSLTC xsltc = new XSLTC();
if (_debug) xsltc.setDebug(true);
- if (_enableInlining) xsltc.setTemplateInlining(true);
+ if (_enableInlining) {
+ xsltc.getCompilerContext().setTemplateInlining(true);
+ }
xsltc.init();
// Set a document loader (for xsl:include/import) if defined
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]