morten 01/06/06 03:47:05
Modified: java/src/org/apache/xalan/xsltc/compiler ApplyImports.java
ApplyTemplates.java Attribute.java
AttributeSet.java AttributeValueTemplate.java
BinOpExpr.java CallTemplate.java Comment.java
ConcatCall.java Constants.java Copy.java
CopyOf.java DecimalFormatting.java
DocumentCall.java Expression.java Fallback.java
ForEach.java FormatNumberCall.java
FunctionAvailableCall.java FunctionCall.java
If.java Import.java Include.java Key.java
LiteralAttribute.java LiteralElement.java
LiteralExpr.java LogicalExpr.java Message.java
NamespaceAlias.java Number.java Output.java
Param.java Parser.java ProcessingInstruction.java
QName.java RelationalExpr.java Sort.java
Stylesheet.java SymbolTable.java
SyntaxTreeNode.java Template.java Text.java
TransletOutput.java UnaryOpExpr.java ValueOf.java
Variable.java When.java Whitespace.java
WithParam.java XSLTC.java XslAttribute.java
XslElement.java xpath.cup
java/src/org/apache/xalan/xsltc/compiler/util
MethodType.java
Log:
Removed the intermediate DOM used to contain the input document (the
stylesheet) for the compiler. The compiler now uses SAX2 to import
the stylesheet, and all references to DOM interfaces have been removed.
This means that most classes representing XSL elements have been
changed, but most classes representing XPath functions, expressions
and patterns are unchanged.
PR: After suggestion from Scott Boag
Obtained from: n/a
Submitted by: [EMAIL PROTECTED]
Reviewed by: [EMAIL PROTECTED]
Revision Changes Path
1.3 +6 -7
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/ApplyImports.java
Index: ApplyImports.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/ApplyImports.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ApplyImports.java 2001/05/02 10:24:32 1.2
+++ ApplyImports.java 2001/06/06 10:44:34 1.3
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: ApplyImports.java,v 1.2 2001/05/02 10:24:32 morten Exp $
+ * @(#)$Id: ApplyImports.java,v 1.3 2001/06/06 10:44:34 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -68,7 +68,6 @@
import javax.xml.parsers.*;
-import org.w3c.dom.*;
import org.xml.sax.*;
import org.apache.xalan.xsltc.compiler.util.Type;
@@ -98,12 +97,12 @@
return hasContents();
}
- public void parseContents(Element element, Parser parser) {
- final String select = element.getAttribute("select");
- final String mode = element.getAttribute("mode");
+ public void parseContents(Parser parser) {
+ final String select = getAttribute("select");
+ final String mode = getAttribute("mode");
if (select.length() > 0) {
- _select = parser.parseExpression(this, element, "select");
+ _select = parser.parseExpression(this, "select", null);
}
if (mode.length() > 0) {
@@ -113,7 +112,7 @@
// instantiate Mode if needed, cache (apply temp) function name
_functionName =
parser.getTopLevelStylesheet().getMode(_modeName).functionName();
- parseChildren(element, parser); // with-params
+ parseChildren(parser); // with-params
}
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
1.3 +6 -7
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/ApplyTemplates.java
Index: ApplyTemplates.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/ApplyTemplates.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ApplyTemplates.java 2001/05/02 10:24:33 1.2
+++ ApplyTemplates.java 2001/06/06 10:44:35 1.3
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: ApplyTemplates.java,v 1.2 2001/05/02 10:24:33 morten Exp $
+ * @(#)$Id: ApplyTemplates.java,v 1.3 2001/06/06 10:44:35 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -68,7 +68,6 @@
import javax.xml.parsers.*;
-import org.w3c.dom.*;
import org.xml.sax.*;
import org.apache.xalan.xsltc.compiler.util.Type;
@@ -97,12 +96,12 @@
return hasContents();
}
- public void parseContents(Element element, Parser parser) {
- final String select = element.getAttribute("select");
- final String mode = element.getAttribute("mode");
+ public void parseContents(Parser parser) {
+ final String select = getAttribute("select");
+ final String mode = getAttribute("mode");
if (select.length() > 0) {
- _select = parser.parseExpression(this, element, "select");
+ _select = parser.parseExpression(this, "select", null);
}
if (mode.length() > 0) {
@@ -112,7 +111,7 @@
// instantiate Mode if needed, cache (apply temp) function name
_functionName =
parser.getTopLevelStylesheet().getMode(_modeName).functionName();
- parseChildren(element, parser); // with-params
+ parseChildren(parser);// with-params
}
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
1.3 +4 -7
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Attribute.java
Index: Attribute.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Attribute.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Attribute.java 2001/05/02 10:24:35 1.2
+++ Attribute.java 2001/06/06 10:44:37 1.3
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: Attribute.java,v 1.2 2001/05/02 10:24:35 morten Exp $
+ * @(#)$Id: Attribute.java,v 1.3 2001/06/06 10:44:37 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -63,8 +63,6 @@
package org.apache.xalan.xsltc.compiler;
-import org.w3c.dom.*;
-
import org.apache.xalan.xsltc.compiler.util.*;
final class Attribute extends Instruction {
@@ -76,10 +74,9 @@
displayContents(indent + IndentIncrement);
}
- public void parseContents(Element element, Parser parser) {
- _name = parser.getQName(element.getAttribute("name"));
- parseChildren(element, parser);
-
+ public void parseContents(Parser parser) {
+ _name = parser.getQName(getAttribute("name"));
+ parseChildren(parser);
//!!! add text nodes
//!!! take care of value templates
}
1.3 +5 -6
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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AttributeSet.java 2001/05/02 10:24:36 1.2
+++ AttributeSet.java 2001/06/06 10:44:38 1.3
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: AttributeSet.java,v 1.2 2001/05/02 10:24:36 morten Exp $
+ * @(#)$Id: AttributeSet.java,v 1.3 2001/06/06 10:44:38 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -69,7 +69,6 @@
import javax.xml.parsers.*;
-import org.w3c.dom.*;
import org.xml.sax.*;
import org.apache.xalan.xsltc.compiler.util.Type;
@@ -83,14 +82,14 @@
private UseAttributeSets _useSets;
private String _methodName;
- public void parseContents(Element element, Parser parser) {
- _name = parser.getQName(element.getAttribute("name"));
- final String useSets = element.getAttribute("use-attribute-sets");
+ public void parseContents(Parser parser) {
+ _name = parser.getQName(getAttribute("name"));
+ final String useSets = getAttribute("use-attribute-sets");
if (useSets.length() > 0) {
_useSets = new UseAttributeSets(useSets, parser);
}
//!!! add check whether children are XslAttributes
- parseChildren(element, parser);
+ parseChildren(parser);
}
public QName getName() {
1.2 +3 -4
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/AttributeValueTemplate.java
Index: AttributeValueTemplate.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/AttributeValueTemplate.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AttributeValueTemplate.java 2001/04/17 18:51:20 1.1
+++ AttributeValueTemplate.java 2001/06/06 10:44:39 1.2
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: AttributeValueTemplate.java,v 1.1 2001/04/17 18:51:20 sboag Exp $
+ * @(#)$Id: AttributeValueTemplate.java,v 1.2 2001/06/06 10:44:39 morten Exp
$
*
* The Apache Software License, Version 1.1
*
@@ -109,7 +109,7 @@
if (close > open + 1) {
str = text.substring(open + 1, close);
str = removeDuplicateBraces(text.substring(open+1,close));
- addElement(parser.parseExpression(this,str));
+ addElement(parser.parseExpression(this, str));
}
// Parse rest of string
parseAVTemplate(close + 1, text, parser);
@@ -148,7 +148,7 @@
contents.setElementAt(new CastExpr(exp, Type.String), i);
}
}
- return _type = Type.Void;
+ return _type = Type.String;
}
public String toString() {
@@ -162,7 +162,6 @@
return buffer.append(']').toString();
}
- // return (new StringBuffer()).append("A").append("B").toString();
public void translate(ClassGenerator classGen, MethodGenerator
methodGen) {
if (elementCount() == 1) {
final Expression exp = (Expression)elementAt(0);
1.2 +3 -4
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/BinOpExpr.java
Index: BinOpExpr.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/BinOpExpr.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- BinOpExpr.java 2001/04/17 18:51:21 1.1
+++ BinOpExpr.java 2001/06/06 10:44:41 1.2
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: BinOpExpr.java,v 1.1 2001/04/17 18:51:21 sboag Exp $
+ * @(#)$Id: BinOpExpr.java,v 1.2 2001/06/06 10:44:41 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -96,8 +96,7 @@
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
final Type tleft = _left.typeCheck(stable);
final Type tright = _right.typeCheck(stable);
- final MethodType ptype = lookupPrimop(stable,
- getParser().getQName(Ops[_op]),
+ final MethodType ptype = lookupPrimop(stable, Ops[_op],
new MethodType(Type.Void,
tleft, tright));
if (ptype != null) {
@@ -137,7 +136,7 @@
il.append(_type.REM());
break;
default:
- getParser().internalError();
+ getParser().addFatalError("Unknown operator for binary expression");
}
}
1.3 +4 -5
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/CallTemplate.java
Index: CallTemplate.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/CallTemplate.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- CallTemplate.java 2001/05/02 10:24:39 1.2
+++ CallTemplate.java 2001/06/06 10:44:43 1.3
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: CallTemplate.java,v 1.2 2001/05/02 10:24:39 morten Exp $
+ * @(#)$Id: CallTemplate.java,v 1.3 2001/06/06 10:44:43 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -65,7 +65,6 @@
import javax.xml.parsers.*;
-import org.w3c.dom.*;
import org.xml.sax.*;
import org.apache.xalan.xsltc.compiler.util.Type;
@@ -86,9 +85,9 @@
return elementCount() > 0;
}
- public void parseContents(Element element, Parser parser) {
- _name = parser.getQName(element.getAttribute("name"));
- parseChildren(element, parser);
+ public void parseContents(Parser parser) {
+ _name = parser.getQName(getAttribute("name"));
+ parseChildren(parser);
}
/**
1.3 +3 -5
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Comment.java
Index: Comment.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Comment.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Comment.java 2001/05/02 10:24:41 1.2
+++ Comment.java 2001/06/06 10:44:44 1.3
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: Comment.java,v 1.2 2001/05/02 10:24:41 morten Exp $
+ * @(#)$Id: Comment.java,v 1.3 2001/06/06 10:44:44 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -66,10 +66,8 @@
import javax.xml.parsers.*;
-import org.w3c.dom.*;
import org.xml.sax.*;
-import org.w3c.dom.*;
import java.util.Vector;
import java.util.Enumeration;
@@ -82,8 +80,8 @@
final class Comment extends Instruction {
- public void parseContents(Element element, Parser parser) {
- parseChildren(element, parser);
+ public void parseContents(Parser parser) {
+ parseChildren(parser);
}
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
1.2 +2 -2
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/ConcatCall.java
Index: ConcatCall.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/ConcatCall.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ConcatCall.java 2001/04/17 18:51:23 1.1
+++ ConcatCall.java 2001/06/06 10:44:46 1.2
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: ConcatCall.java,v 1.1 2001/04/17 18:51:23 sboag Exp $
+ * @(#)$Id: ConcatCall.java,v 1.2 2001/06/06 10:44:46 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -93,7 +93,7 @@
switch (nArgs) {
case 0:
- il.append(new PUSH(cpg, ""));
+ il.append(new PUSH(cpg, Constants.EMPTYSTRING));
break;
case 1:
1.4 +24 -27
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.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Constants.java 2001/05/17 13:35:38 1.3
+++ Constants.java 2001/06/06 10:44:47 1.4
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: Constants.java,v 1.3 2001/05/17 13:35:38 morten Exp $
+ * @(#)$Id: Constants.java,v 1.4 2001/06/06 10:44:47 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -66,12 +66,32 @@
import de.fub.bytecode.generic.InstructionConstants;
public interface Constants extends InstructionConstants {
+
+ // Error categories used to report errors to Parser.reportError()
+
+ // Unexpected internal errors, such as null-ptr exceptions, etc.
+ // Immediately terminates compilation, no translet produced
+ public final int INTERNAL = 0;
+ // XSLT elements that are not implemented and unsupported ext.
+ // Immediately terminates compilation, no translet produced
+ public final int UNSUPPORTED = 1;
+ // Fatal error in the stylesheet input (parsing or content)
+ // Immediately terminates compilation, no translet produced
+ public final int FATAL = 2;
+ // Other error in the stylesheet input (parsing or content)
+ // Does not terminate compilation, no translet produced
+ public final int ERROR = 3;
+ // Other error in the stylesheet input (content errors only)
+ // Does not terminate compilation, a translet is produced
+ public final int WARNING = 4;
+
+ public static final String EMPTYSTRING = "";
+
public static final String TRANSLET_INTF
= "org.apache.xalan.xsltc.Translet";
public static final String TRANSLET_INTF_SIG
= "Lorg/apache/xalan/xsltc/Translet;";
- // -- deprecated
public static final String ATTRIBUTES_SIG
= "Lorg/apache/xalan/xsltc/runtime/Attributes;";
public static final String NODE_ITERATOR_SIG
@@ -93,7 +113,6 @@
public static final String STRING
= "java.lang.String";
- // -- deprecated
public static final int ACC_PUBLIC
= de.fub.bytecode.Constants.ACC_PUBLIC;
@@ -310,14 +329,7 @@
= "setStartNode";
public static final String RESET
= "reset";
- /*
- public static final String APPLY_TEMPLATES_SIG
- = "("
- + DOM_CLASS_SIG
- + NODE_ITERATOR_SIG
- + TRANSLET_OUTPUT_SIG
- + ")V";
- */
+
public static final String GET_NODE_NAME_SIG
= "(" + NODE_SIG + ")" + STRING_SIG;
public static final String CHARACTERSW_SIG
@@ -350,26 +362,11 @@
public static final String NAMESPACE_INDEX_SIG
= "[" + STRING_SIG;
- /*
- public static final String MAP_FIELD
- = "mapping";
- public static final String REV_MAP_FIELD
- = "reverseMapping";
- public static final String TYPE_FIELD
- = "type";
- */
public static final String DOM_FIELD
= "_dom";
public static final String FORMAT_SYMBOLS_FIELD
= "format_symbols";
- /*
- public static final String MAP_FIELD_SIG
- = "[S";
- public static final String TYPE_FIELD_SIG
- = "[S";
- public static final String REV_MAP_FIELD_SIG
- = "[S";
- */
+
public static final String ITERATOR_FIELD_SIG
= NODE_ITERATOR_SIG;
public static final String NODE_FIELD
1.3 +4 -5
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Copy.java
Index: Copy.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Copy.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Copy.java 2001/05/02 10:24:42 1.2
+++ Copy.java 2001/06/06 10:44:48 1.3
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: Copy.java,v 1.2 2001/05/02 10:24:42 morten Exp $
+ * @(#)$Id: Copy.java,v 1.3 2001/06/06 10:44:48 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -69,7 +69,6 @@
import javax.xml.parsers.*;
-import org.w3c.dom.*;
import org.xml.sax.*;
import org.apache.xalan.xsltc.compiler.util.Type;
@@ -79,12 +78,12 @@
final class Copy extends Instruction {
private UseAttributeSets _useSets;
- public void parseContents(Element element, Parser parser) {
- final String useSets = element.getAttribute("use-attribute-sets");
+ public void parseContents(Parser parser) {
+ final String useSets = getAttribute("use-attribute-sets");
if (useSets.length() > 0) {
_useSets = new UseAttributeSets(useSets, parser);
}
- parseChildren(element, parser);
+ parseChildren(parser);
}
public void display(int indent) {
1.3 +4 -5
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/CopyOf.java
Index: CopyOf.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/CopyOf.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- CopyOf.java 2001/05/02 10:24:43 1.2
+++ CopyOf.java 2001/06/06 10:44:50 1.3
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: CopyOf.java,v 1.2 2001/05/02 10:24:43 morten Exp $
+ * @(#)$Id: CopyOf.java,v 1.3 2001/06/06 10:44:50 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -65,7 +65,6 @@
import javax.xml.parsers.*;
-import org.w3c.dom.*;
import org.xml.sax.*;
import org.apache.xalan.xsltc.compiler.util.Type;
@@ -83,11 +82,11 @@
Util.println("select " + _select.toString());
}
- public void parseContents(Element element, Parser parser) {
- _select = parser.parseExpression(this, element, "select");
+ public void parseContents(Parser parser) {
+ _select = parser.parseExpression(this, "select", null);
// make sure required attribute(s) have been set
if (_select.isDummy()) {
- reportError(element, parser, ErrorMsg.NREQATTR_ERR, "select");
+ reportError(this, parser, ErrorMsg.NREQATTR_ERR, "select");
return;
}
}
1.4 +3 -14
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.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DecimalFormatting.java 2001/05/02 10:24:44 1.3
+++ DecimalFormatting.java 2001/06/06 10:44:52 1.4
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: DecimalFormatting.java,v 1.3 2001/05/02 10:24:44 morten Exp $
+ * @(#)$Id: DecimalFormatting.java,v 1.4 2001/06/06 10:44:52 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -66,7 +66,6 @@
import javax.xml.parsers.*;
-import org.w3c.dom.*;
import org.xml.sax.*;
import org.apache.xalan.xsltc.compiler.util.Type;
@@ -82,19 +81,9 @@
final class DecimalFormatting extends TopLevelElement {
- private AttributeList _attributes = new AttributeList();
private static final String DFS_CLASS = "java.text.DecimalFormatSymbols";
private static final String DFS_SIG =
"Ljava/text/DecimalFormatSymbols;";
- public void parseContents(Element element, Parser parser) {
- NamedNodeMap attributes = element.getAttributes();
- final int nAttributes = attributes.getLength();
- for (int i = 0; i < nAttributes; i++) {
- final Attr attr = (Attr)attributes.item(i);
- _attributes.add(attr.getName(), attr.getValue());
- }
- }
-
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
return Type.Void;
}
@@ -113,7 +102,7 @@
// Push the format name on the stack for call to addDecimalFormat()
il.append(classGen.loadTranslet());
- il.append(new PUSH(cpg, _attributes.getValue("name")));
+ il.append(new PUSH(cpg, getAttribute("name")));
// Manufacture a DecimalFormatSymbols on the stack
// for call to addDecimalFormat()
@@ -213,7 +202,7 @@
// Push the format name, which is empty, on the stack
// for call to addDecimalFormat()
il.append(classGen.loadTranslet());
- il.append(new PUSH(cpg, ""));
+ il.append(new PUSH(cpg, Constants.EMPTYSTRING));
// Manufacture a DecimalFormatSymbols on the stack
// for call to addDecimalFormat()
1.2 +4 -3
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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DocumentCall.java 2001/04/17 18:51:26 1.1
+++ DocumentCall.java 2001/06/06 10:44:53 1.2
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: DocumentCall.java,v 1.1 2001/04/17 18:51:26 sboag Exp $
+ * @(#)$Id: DocumentCall.java,v 1.2 2001/06/06 10:44:53 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -103,14 +103,15 @@
_uri = argument(0);
if (_uri instanceof LiteralExpr) {
LiteralExpr expr = (LiteralExpr)_uri;
- if (expr.getValue().equals("")) {
+ if (expr.getValue().equals(Constants.EMPTYSTRING)) {
Stylesheet stylesheet = getStylesheet();
if (stylesheet == null) {
ErrorMsg msg = new ErrorMsg("Illegal argument "+
"to document() function");
throw new TypeCheckError(msg);
}
- _uri = new LiteralExpr(stylesheet.getURL().toString(),"");
+ _uri = new LiteralExpr(stylesheet.getURL().toString(),
+ Constants.EMPTYSTRING);
}
}
1.2 +3 -3
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Expression.java
Index: Expression.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Expression.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Expression.java 2001/04/17 18:51:27 1.1
+++ Expression.java 2001/06/06 10:44:54 1.2
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: Expression.java,v 1.1 2001/04/17 18:51:27 sboag Exp $
+ * @(#)$Id: Expression.java,v 1.2 2001/06/06 10:44:54 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -208,10 +208,10 @@
* first entry in the vector of primops that has the right arity is
* considered to be the default one.
*/
- public MethodType lookupPrimop(SymbolTable stable, QName op,
+ public MethodType lookupPrimop(SymbolTable stable, String op,
MethodType ctype) {
MethodType result = null;
- final Vector primop = stable.lookupPrimop(op);
+ final Vector primop = stable.lookupPrimop(op);
if (primop != null) {
final int n = primop.size();
int minDistance = Integer.MAX_VALUE;
1.3 +10 -11
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Fallback.java
Index: Fallback.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Fallback.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Fallback.java 2001/05/02 10:24:45 1.2
+++ Fallback.java 2001/06/06 10:44:55 1.3
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: Fallback.java,v 1.2 2001/05/02 10:24:45 morten Exp $
+ * @(#)$Id: Fallback.java,v 1.3 2001/06/06 10:44:55 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -68,7 +68,6 @@
import javax.xml.parsers.*;
-import org.w3c.dom.*;
import org.xml.sax.*;
import org.apache.xalan.xsltc.compiler.util.Type;
@@ -83,8 +82,12 @@
* This element never produces any data on the stack
*/
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
- typeCheckContents(stable);
- return Type.Void;
+ if (_active) {
+ return(typeCheckContents(stable));
+ }
+ else {
+ return Type.Void;
+ }
}
/**
@@ -102,10 +105,8 @@
* Parse contents only if this fallback element is put in place of
* some unsupported element or non-XSLTC extension element
*/
- public void parseContents(Element element, Parser parser) {
- if (_active) {
- parseChildren(element, parser);
- }
+ public void parseContents(Parser parser) {
+ if (_active) parseChildren(parser);
}
/**
@@ -116,8 +117,6 @@
final ConstantPoolGen cpg = classGen.getConstantPool();
final InstructionList il = methodGen.getInstructionList();
- if (_active) {
- translateContents(classGen, methodGen);
- }
+ if (_active) translateContents(classGen, methodGen);
}
}
1.3 +5 -6
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/ForEach.java
Index: ForEach.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/ForEach.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ForEach.java 2001/05/02 10:24:46 1.2
+++ ForEach.java 2001/06/06 10:44:57 1.3
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: ForEach.java,v 1.2 2001/05/02 10:24:46 morten Exp $
+ * @(#)$Id: ForEach.java,v 1.3 2001/06/06 10:44:57 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -69,7 +69,6 @@
import javax.xml.parsers.*;
-import org.w3c.dom.*;
import org.xml.sax.*;
import org.apache.xalan.xsltc.compiler.util.Type;
@@ -88,13 +87,13 @@
displayContents(indent + IndentIncrement);
}
- public void parseContents(Element element, Parser parser) {
- _select = parser.parseExpression(this, element, "select");
- parseChildren(element, parser);
+ public void parseContents(Parser parser) {
+ _select = parser.parseExpression(this, "select", null);
+ parseChildren(parser);
// make sure required attribute(s) have been set
if (_select.isDummy()) {
- reportError(element, parser, ErrorMsg.NREQATTR_ERR, "select");
+ reportError(this, parser, ErrorMsg.NREQATTR_ERR, "select");
return;
}
}
1.3 +2 -2
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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- FormatNumberCall.java 2001/05/21 14:46:08 1.2
+++ FormatNumberCall.java 2001/06/06 10:44:58 1.3
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: FormatNumberCall.java,v 1.2 2001/05/21 14:46:08 morten Exp $
+ * @(#)$Id: FormatNumberCall.java,v 1.3 2001/06/06 10:44:58 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -124,7 +124,7 @@
il.append(classGen.loadTranslet());
if (_name == null) {
- il.append(new PUSH(cpg,""));
+ il.append(new PUSH(cpg, Constants.EMPTYSTRING));
}
else {
_name.translate(classGen, methodGen);
1.2 +7 -6
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/FunctionAvailableCall.java
Index: FunctionAvailableCall.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/FunctionAvailableCall.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FunctionAvailableCall.java 2001/04/17 18:51:29 1.1
+++ FunctionAvailableCall.java 2001/06/06 10:44:59 1.2
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: FunctionAvailableCall.java,v 1.1 2001/04/17 18:51:29 sboag Exp $
+ * @(#)$Id: FunctionAvailableCall.java,v 1.2 2001/06/06 10:44:59 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -79,16 +79,16 @@
AvailableFunctions.add("contains");
AvailableFunctions.add("count");
AvailableFunctions.add("current");
- // AvailableFunctions.add("document");
+ AvailableFunctions.add("document");
AvailableFunctions.add("element-available");
AvailableFunctions.add("false");
AvailableFunctions.add("floor");
AvailableFunctions.add("format-number");
AvailableFunctions.add("function-available");
AvailableFunctions.add("generate-id");
- // AvailableFunctions.add("id");
- // AvailableFunctions.add("key");
- // AvailableFunctions.add("lang");
+ AvailableFunctions.add("id");
+ AvailableFunctions.add("key");
+ AvailableFunctions.add("lang");
AvailableFunctions.add("last");
AvailableFunctions.add("local-name");
AvailableFunctions.add("name");
@@ -108,7 +108,7 @@
AvailableFunctions.add("system-property");
AvailableFunctions.add("translate");
AvailableFunctions.add("true");
- // AvailableFunctions.add("unparsed-entity-uri");
+ AvailableFunctions.add("unparsed-entity-uri");
}
public FunctionAvailableCall(QName fname, Vector arguments) {
@@ -136,6 +136,7 @@
final LiteralExpr arg = (LiteralExpr)argument();
final String namespace = arg.getNamespace();
boolean result = false;
+
if (namespace == null) {
result = AvailableFunctions.contains(arg.getValue());
}
1.2 +19 -8
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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FunctionCall.java 2001/04/17 18:51:30 1.1
+++ FunctionCall.java 2001/06/06 10:45:00 1.2
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: FunctionCall.java,v 1.1 2001/04/17 18:51:30 sboag Exp $
+ * @(#)$Id: FunctionCall.java,v 1.2 2001/06/06 10:45:00 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -182,7 +182,13 @@
*/
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
final String namespace = _fname.getNamespace();
- if (namespace != null) {
+
+ // XPath functions have no namespace
+ if (isStandard()) {
+ return typeCheckStandard(stable);
+ }
+ // Handle extension functions (they all have a namespace)
+ else {
final int len = ExtPrefix.length();
if (namespace.length() >= len &&
namespace.substring(0, len).equals(ExtPrefix)) {
@@ -193,9 +199,6 @@
}
return typeCheckExternal(stable);
}
- else {
- return typeCheckStandard(stable);
- }
}
/**
@@ -204,10 +207,14 @@
* thrown, then catch it and re-throw it with a new "this".
*/
public Type typeCheckStandard(SymbolTable stable) throws TypeCheckError {
+
+ _fname.clearNamespace(); // HACK!!!
+
final int n = _arguments.size();
final Vector argsType = typeCheckArgs(stable);
+ final MethodType args = new MethodType(Type.Void, argsType);
final MethodType ptype =
- lookupPrimop(stable, _fname, new MethodType(Type.Void, argsType));
+ lookupPrimop(stable, _fname.getLocalPart(), args);
if (ptype != null) {
for (int i = 0; i < n; i++) {
@@ -325,7 +332,7 @@
// append "F" to the function's name
final String name = _fname.toString().replace('-', '_') + "F";
- String args = "";
+ String args = Constants.EMPTYSTRING;
// Special precautions for some method calls
if (name.equals("sumF")) {
@@ -383,7 +390,11 @@
}
public boolean isStandard() {
- return _fname.getNamespace() == null;
+ final String namespace = _fname.getNamespace();
+ if ((namespace == null) || (namespace.equals(Constants.EMPTYSTRING)))
+ return true;
+ else
+ return false;
}
/**
1.3 +5 -6
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/If.java
Index: If.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/If.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- If.java 2001/05/02 10:24:47 1.2
+++ If.java 2001/06/06 10:45:01 1.3
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: If.java,v 1.2 2001/05/02 10:24:47 morten Exp $
+ * @(#)$Id: If.java,v 1.3 2001/06/06 10:45:01 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -65,7 +65,6 @@
import javax.xml.parsers.*;
-import org.w3c.dom.*;
import org.xml.sax.*;
import org.apache.xalan.xsltc.compiler.util.Type;
@@ -84,13 +83,13 @@
displayContents(indent + IndentIncrement);
}
- public void parseContents(Element element, Parser parser) {
- _test = parser.parseExpression(this, element, "test");
- parseChildren(element, parser);
+ public void parseContents(Parser parser) {
+ _test = parser.parseExpression(this, "test", null);
+ parseChildren(parser);
// make sure required attribute(s) have been set
if (_test.isDummy()) {
- reportError(element, parser, ErrorMsg.NREQATTR_ERR, "test");
+ reportError(this, parser, ErrorMsg.NREQATTR_ERR, "test");
return;
}
}
1.3 +7 -9
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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Import.java 2001/05/02 10:24:48 1.2
+++ Import.java 2001/06/06 10:45:02 1.3
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: Import.java,v 1.2 2001/05/02 10:24:48 morten Exp $
+ * @(#)$Id: Import.java,v 1.3 2001/06/06 10:45:02 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -69,7 +69,6 @@
import javax.xml.parsers.*;
-import org.w3c.dom.*;
import org.xml.sax.*;
import org.apache.xalan.xsltc.compiler.util.Type;
@@ -85,17 +84,17 @@
return(_imported);
}
- public void parseContents(Element element, final Parser parser) {
+ public void parseContents(final Parser parser) {
try {
final Stylesheet context = parser.getCurrentStylesheet();
- final String href = element.getAttribute("href");
+ final String href = getAttribute("href");
final URL toImport = new URL(context.getURL(), href);
if (context.checkForLoop(toImport))
throw new Exception(toImport.toString() + " already loaded");
- final Element stylesheetEl = parser.parse(toImport);
- if (stylesheetEl == null) return;
- final Stylesheet _imported = parser.makeStylesheet(stylesheetEl);
+ final SyntaxTreeNode root = parser.parse(toImport);
+ if (root == null) return;
+ final Stylesheet _imported = parser.makeStylesheet(root);
if (_imported == null) return;
_imported.setURL(toImport);
@@ -106,9 +105,8 @@
final int nextPrecedence = parser.getNextImportPrecedence();
_imported.setImportPrecedence(currPrecedence);
context.setImportPrecedence(nextPrecedence);
-
parser.setCurrentStylesheet(_imported);
- _imported.parseContents(stylesheetEl, parser);
+ _imported.parseContents(parser);
final Enumeration elements = _imported.elements();
final Stylesheet topStylesheet = parser.getTopLevelStylesheet();
1.3 +7 -8
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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Include.java 2001/05/02 10:24:50 1.2
+++ Include.java 2001/06/06 10:45:03 1.3
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: Include.java,v 1.2 2001/05/02 10:24:50 morten Exp $
+ * @(#)$Id: Include.java,v 1.3 2001/06/06 10:45:03 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -69,7 +69,6 @@
import javax.xml.parsers.*;
-import org.w3c.dom.*;
import org.xml.sax.*;
import org.apache.xalan.xsltc.compiler.util.Type;
@@ -85,17 +84,17 @@
return(_included);
}
- public void parseContents(Element element, final Parser parser) {
+ public void parseContents(final Parser parser) {
try {
final Stylesheet context = parser.getCurrentStylesheet();
- final String href = element.getAttribute("href");
+ final String href = getAttribute("href");
final URL toInclude = new URL(context.getURL(), href);
if (context.checkForLoop(toInclude))
throw new Exception(toInclude.toString() + " already loaded");
- final Element stylesheetEl = parser.parse(toInclude);
- if (stylesheetEl == null) return;
- final Stylesheet _included = parser.makeStylesheet(stylesheetEl);
+ final SyntaxTreeNode root = parser.parse(toInclude);
+ if (root == null) return;
+ final Stylesheet _included = parser.makeStylesheet(root);
if (_included == null) return;
_included.setURL(toInclude);
@@ -107,7 +106,7 @@
_included.setImportPrecedence(precedence);
parser.setCurrentStylesheet(_included);
- _included.parseContents(stylesheetEl, parser);
+ _included.parseContents(parser);
final Enumeration elements = _included.elements();
final Stylesheet topStylesheet = parser.getTopLevelStylesheet();
1.3 +7 -8
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Key.java
Index: Key.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Key.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Key.java 2001/05/02 10:24:51 1.2
+++ Key.java 2001/06/06 10:45:05 1.3
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: Key.java,v 1.2 2001/05/02 10:24:51 morten Exp $
+ * @(#)$Id: Key.java,v 1.3 2001/06/06 10:45:05 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -64,7 +64,6 @@
import javax.xml.parsers.*;
-import org.w3c.dom.*;
import org.xml.sax.*;
import de.fub.bytecode.generic.*;
@@ -80,19 +79,19 @@
private Expression _use;
private Type _useType;
- public void parseContents(Element element, Parser parser) {
+ public void parseContents(Parser parser) {
// make sure values are provided
- _name = parser.getQName(element.getAttribute("name"));
- _match = parser.parsePattern(this, element, "match");
- _use = parser.parseExpression(this, element, "use");
+ _name = parser.getQName(getAttribute("name"));
+ _match = parser.parsePattern(this, "match", null);
+ _use = parser.parseExpression(this, "use", null);
// make sure required attribute(s) have been set
if (_match.isDummy()) {
- reportError(element, parser, ErrorMsg.NREQATTR_ERR, "match");
+ reportError(this, parser, ErrorMsg.NREQATTR_ERR, "match");
return;
}
if (_use.isDummy()) {
- reportError(element, parser, ErrorMsg.NREQATTR_ERR, "use");
+ reportError(this, parser, ErrorMsg.NREQATTR_ERR, "use");
return;
}
}
1.2 +2 -4
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/LiteralAttribute.java
Index: LiteralAttribute.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/LiteralAttribute.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- LiteralAttribute.java 2001/04/17 18:51:34 1.1
+++ LiteralAttribute.java 2001/06/06 10:45:08 1.2
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: LiteralAttribute.java,v 1.1 2001/04/17 18:51:34 sboag Exp $
+ * @(#)$Id: LiteralAttribute.java,v 1.2 2001/06/06 10:45:08 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -65,14 +65,12 @@
package org.apache.xalan.xsltc.compiler;
import org.apache.xalan.xsltc.compiler.util.Type;
-import org.w3c.dom.*;
import de.fub.bytecode.generic.*;
import org.apache.xalan.xsltc.compiler.util.*;
final class LiteralAttribute extends Instruction {
private final String _name;
private final AttributeValue _value;
- // private final String _namespace;
public LiteralAttribute(String name, String value, Parser parser) {
_name = name;
@@ -89,7 +87,7 @@
typeCheckContents(stable);
return Type.Void;
}
-
+
public boolean contextDependent() {
return _value.contextDependent();
}
1.5 +108 -43
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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- LiteralElement.java 2001/05/21 15:12:26 1.4
+++ LiteralElement.java 2001/06/06 10:45:09 1.5
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: LiteralElement.java,v 1.4 2001/05/21 15:12:26 morten Exp $
+ * @(#)$Id: LiteralElement.java,v 1.5 2001/06/06 10:45:09 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -70,20 +70,19 @@
import javax.xml.parsers.*;
-import org.w3c.dom.*;
import org.xml.sax.*;
+import org.apache.xalan.xsltc.compiler.util.Type;
import de.fub.bytecode.generic.*;
import org.apache.xalan.xsltc.compiler.util.*;
final class LiteralElement extends Instruction {
private String _name;
- private QName _qname;
private Hashtable _accessedPrefixes = null;
private LiteralElement _parent;
+ private Vector _attributeElements = null;
private final static String XMLNS_STRING = "xmlns";
- private final static String EMPTY_STRING = "";
/**
* Returns the QName for this literal element
@@ -104,7 +103,7 @@
/**
* Returns the namespace URI for which a prefix is pointing to
*/
- public String lookupNamespace(String prefix) {
+ public String accessedNamespace(String prefix) {
if (_accessedPrefixes == null)
return(null);
else
@@ -121,9 +120,9 @@
// Check if the parent has a declaration for this namespace
if (_parent != null) {
- final String parentUri = _parent.lookupNamespace(prefix);
+ final String parentUri = _parent.accessedNamespace(prefix);
if (parentUri == null) {
- _parent.registerNamespace(prefix,uri,stable,declared);
+ _parent.registerNamespace(prefix, uri, stable, declared);
return;
}
if (parentUri.equals(uri)) return;
@@ -136,17 +135,19 @@
else {
if (!declared) {
// Check if this node has a declaration for this namespace
- final String ourUri = (String)_accessedPrefixes.get(prefix);
- if ((ourUri != null) && (ourUri.equals(uri))) {
- return;
+ final String old = (String)_accessedPrefixes.get(prefix);
+ if (old != null) {
+ if (old.equals(uri))
+ return;
+ else
+ prefix = stable.generateNamespacePrefix();
}
- else {
- prefix = stable.generateNamespacePrefix();
- }
}
}
- if (!prefix.equals("xml"))
+
+ if (!prefix.equals("xml")) {
_accessedPrefixes.put(prefix,uri);
+ }
}
/**
@@ -161,7 +162,7 @@
// Treat default namespace as "" and not null
if (prefix == null)
- prefix = EMPTY_STRING;
+ prefix = Constants.EMPTYSTRING;
else if (prefix.equals(XMLNS_STRING))
return(XMLNS_STRING);
@@ -173,25 +174,76 @@
}
// Get the namespace this prefix refers to
- String uri = stable.lookupNamespace(prefix);
+ String uri = lookupNamespace(prefix);
if (uri == null) return(localname);
// Register the namespace as accessed
- registerNamespace(prefix,uri,stable,false);
+ registerNamespace(prefix, uri, stable, false);
// Construct the new name for the element (may be unchanged)
- if (!prefix.equals(EMPTY_STRING))
+ if (prefix != Constants.EMPTYSTRING)
return(prefix+":"+localname);
else
return(localname);
}
/**
+ *
+ */
+ private void addAttribute(SyntaxTreeNode attribute) {
+ if (_attributeElements == null) {
+ _attributeElements = new Vector(2);
+ }
+ _attributeElements.add(attribute);
+ }
+
+
+ public Type typeCheck(SymbolTable stable) throws TypeCheckError {
+ // Type-check all attributes
+ if (_attributeElements != null) {
+ final int count = _attributeElements.size();
+ for (int i = 0; i < count; i++) {
+ SyntaxTreeNode node =
+ (SyntaxTreeNode)_attributeElements.elementAt(i);
+ node.typeCheck(stable);
+ }
+ }
+ typeCheckContents(stable);
+ return Type.Void;
+ }
+
+ /**
+ * This method starts at a given node, traverses all namespace mappings,
+ * and assembles a list of all prefixes that (for the given node) maps
+ * to _ANY_ namespace URI. Used by literal result elements to determine
+ */
+ public Enumeration getNamespaceScope(SyntaxTreeNode node) {
+ Hashtable all = new Hashtable();
+
+ while (node != null) {
+ Hashtable mapping = node.getPrefixMapping();
+ if (mapping != null) {
+ Enumeration prefixes = mapping.keys();
+ while (prefixes.hasMoreElements()) {
+ String prefix = (String)prefixes.nextElement();
+ if (!all.containsKey(prefix)) {
+ all.put(prefix, mapping.get(prefix));
+ }
+ }
+ }
+ node = node.getParent();
+ }
+ return(all.keys());
+ }
+
+ /**
* Determines the final QName for the element and its attributes.
* Registers all namespaces that are used by the element/attributes
*/
- public void parseContents(Element element, Parser parser) {
+ public void parseContents(Parser parser) {
+
final SymbolTable stable = parser.getSymbolTable();
+ stable.setCurrentNode(this);
// Find the closest literal element ancestor (if there is one)
SyntaxTreeNode _parent = getParent();
@@ -200,20 +252,18 @@
if (!(_parent instanceof LiteralElement))
_parent = null;
- _qname = parser.getQName(element.getTagName());
- _name = translateQName(_qname,stable);
+ _name = translateQName(_qname, stable);
// Process all attributes and register all namespaces they use
- final NamedNodeMap attributes = element.getAttributes();
- for (int i = 0; i < attributes.getLength(); i++) {
+ final int count = _attributes.getLength();
+ for (int i = 0; i < count; i++) {
- final Attr attribute = (Attr)attributes.item(i);
- final QName qname = parser.getQName(attribute.getName());
- final String val = attribute.getValue();
+ final QName qname = parser.getQName(_attributes.getQName(i));
+ final String val = _attributes.getValue(i);
// Handle xsl:use-attribute-sets
if (qname == parser.getUseAttributeSets()) {
- addElement(new UseAttributeSets(val, parser));
+ addAttribute(new UseAttributeSets(val, parser));
}
// Handle xsl:extension-element-prefixes
else if (qname == parser.getExtensionElementPrefixes()) {
@@ -229,20 +279,21 @@
}
// Handle literal attributes (attributes not in XSL namespace)
else {
- // Namespace declarations are handled separately !!!
- final String name = translateQName(qname,stable);
- if (name != XMLNS_STRING)
- addElement(new LiteralAttribute(name, val, parser));
+ final String name = translateQName(qname, stable);
+ LiteralAttribute attr = new LiteralAttribute(name, val, parser);
+ addAttribute(attr);
+ attr.setParent(this);
+ attr.parseContents(parser);
}
}
// Register all namespaces that are in scope, except for those that
// are listed in the xsl:stylesheet element's *-prefixes attributes
- final Enumeration include = stable.getInScopeNamespaces();
+ final Enumeration include = getNamespaceScope(this);
while (include.hasMoreElements()) {
final String prefix = (String)include.nextElement();
if (!prefix.equals("xml")) {
- final String uri = stable.lookupNamespace(prefix);
+ final String uri = lookupNamespace(prefix);
if ((uri != null) && (!uri.equals(XSLT_URI))) {
if (!stable.isExcludedNamespace(uri))
registerNamespace(prefix,uri,stable,true);
@@ -250,13 +301,13 @@
}
}
- parseChildren(element, parser);
+ parseChildren(parser);
// Process all attributes and register all namespaces they use
- for (int i = 0; i < attributes.getLength(); i++) {
- final Attr attribute = (Attr)attributes.item(i);
- final QName qname = parser.getQName(attribute.getName());
- final String val = attribute.getValue();
+ for (int i = 0; i < count; i++) {
+
+ final QName qname = parser.getQName(_attributes.getQName(i));
+ final String val = _attributes.getValue(i);
// Handle xsl:extension-element-prefixes
if (qname == parser.getExtensionElementPrefixes()) {
@@ -282,6 +333,7 @@
* then the element contents, and then the element end tag.
*/
public void translate(ClassGenerator classGen, MethodGenerator
methodGen) {
+
final ConstantPoolGen cpg = classGen.getConstantPool();
final InstructionList il = methodGen.getInstructionList();
@@ -291,19 +343,32 @@
il.append(DUP2); // duplicate these 2 args for endElement
il.append(methodGen.startElement());
+ // Output all attributes
+ if (_attributeElements != null) {
+ final int count = _attributeElements.size();
+ for (int i = 0; i < count; i++) {
+ SyntaxTreeNode node =
+ (SyntaxTreeNode)_attributeElements.elementAt(i);
+ node.translate(classGen, methodGen);
+ }
+ }
+
// Compile code to emit namespace attributes
if (_accessedPrefixes != null) {
Enumeration e = _accessedPrefixes.keys();
while (e.hasMoreElements()) {
final String prefix = (String)e.nextElement();
final String uri = (String)_accessedPrefixes.get(prefix);
- il.append(methodGen.loadHandler());
- il.append(new PUSH(cpg,prefix));
- il.append(new PUSH(cpg,uri));
- il.append(methodGen.namespace());
+ if ((uri != Constants.EMPTYSTRING) ||
+ (prefix != Constants.EMPTYSTRING)) {
+ il.append(methodGen.loadHandler());
+ il.append(new PUSH(cpg,prefix));
+ il.append(new PUSH(cpg,uri));
+ il.append(methodGen.namespace());
+ }
}
}
-
+
// Compile code to emit attributes and child elements
translateContents(classGen, methodGen);
1.2 +6 -2
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/LiteralExpr.java
Index: LiteralExpr.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/LiteralExpr.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- LiteralExpr.java 2001/04/17 18:51:34 1.1
+++ LiteralExpr.java 2001/06/06 10:45:11 1.2
@@ -1,5 +1,6 @@
+
/*
- * @(#)$Id: LiteralExpr.java,v 1.1 2001/04/17 18:51:34 sboag Exp $
+ * @(#)$Id: LiteralExpr.java,v 1.2 2001/06/06 10:45:11 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -78,7 +79,10 @@
public LiteralExpr(String value, String namespace) {
_value = value;
- _namespace = namespace;
+ if (namespace.equals(Constants.EMPTYSTRING))
+ _namespace = null;
+ else
+ _namespace = namespace;
}
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
1.2 +2 -3
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/LogicalExpr.java
Index: LogicalExpr.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/LogicalExpr.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- LogicalExpr.java 2001/04/17 18:51:35 1.1
+++ LogicalExpr.java 2001/06/06 10:45:12 1.2
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: LogicalExpr.java,v 1.1 2001/04/17 18:51:35 sboag Exp $
+ * @(#)$Id: LogicalExpr.java,v 1.2 2001/06/06 10:45:12 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -102,8 +102,7 @@
Type tleft = _left.typeCheck(stable);
Type tright = _right.typeCheck(stable);
- MethodType ptype = lookupPrimop(stable,
- getParser().getQName(Ops[_op]),
+ MethodType ptype = lookupPrimop(stable, Ops[_op],
new MethodType(Type.Void,
tleft, tright));
1.3 +4 -6
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Message.java
Index: Message.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Message.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Message.java 2001/05/02 10:24:54 1.2
+++ Message.java 2001/06/06 10:45:14 1.3
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: Message.java,v 1.2 2001/05/02 10:24:54 morten Exp $
+ * @(#)$Id: Message.java,v 1.3 2001/06/06 10:45:14 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -64,8 +64,6 @@
package org.apache.xalan.xsltc.compiler;
-import org.w3c.dom.*;
-
import org.apache.xalan.xsltc.compiler.util.Type;
import de.fub.bytecode.generic.*;
@@ -76,12 +74,12 @@
final class Message extends Instruction {
private boolean _terminate = false;
- public void parseContents(Element element, Parser parser) {
- String termstr = element.getAttribute("terminate");
+ public void parseContents(Parser parser) {
+ String termstr = getAttribute("terminate");
if (termstr != null) {
_terminate = termstr.equals("yes");
}
- parseChildren(element, parser);
+ parseChildren(parser);
}
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
1.3 +4 -6
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/NamespaceAlias.java
Index: NamespaceAlias.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/NamespaceAlias.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- NamespaceAlias.java 2001/05/02 10:24:55 1.2
+++ NamespaceAlias.java 2001/06/06 10:45:15 1.3
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: NamespaceAlias.java,v 1.2 2001/05/02 10:24:55 morten Exp $
+ * @(#)$Id: NamespaceAlias.java,v 1.3 2001/06/06 10:45:15 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -67,8 +67,6 @@
import java.util.Enumeration;
import java.util.StringTokenizer;
-import org.w3c.dom.*;
-
import org.apache.xalan.xsltc.compiler.util.Type;
import de.fub.bytecode.generic.*;
import org.apache.xalan.xsltc.compiler.util.*;
@@ -82,9 +80,9 @@
* The namespace alias definitions given here have an impact only on
* literal elements and literal attributes.
*/
- public void parseContents(Element element, Parser parser) {
- sPrefix = element.getAttribute("stylesheet-prefix");
- rPrefix = element.getAttribute("result-prefix");
+ public void parseContents(Parser parser) {
+ sPrefix = getAttribute("stylesheet-prefix");
+ rPrefix = getAttribute("result-prefix");
parser.getSymbolTable().addPrefixAlias(sPrefix,rPrefix);
}
1.3 +15 -19
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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Number.java 2001/05/02 10:24:56 1.2
+++ Number.java 2001/06/06 10:45:16 1.3
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: Number.java,v 1.2 2001/05/02 10:24:56 morten Exp $
+ * @(#)$Id: Number.java,v 1.3 2001/06/06 10:45:16 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -63,8 +63,6 @@
package org.apache.xalan.xsltc.compiler;
-import org.w3c.dom.*;
-
import org.apache.xalan.xsltc.compiler.util.Type;
import org.apache.xalan.xsltc.compiler.util.ReferenceType;
import de.fub.bytecode.classfile.JavaClass;
@@ -92,9 +90,9 @@
private boolean _formatNeeded = false;
static final private String[] ClassNames = {
- "org.apache.xalan.xsltc.dom.SingleNodeCounter", // LEVEL_SINGLE
- "org.apache.xalan.xsltc.dom.MultipleNodeCounter", //
LEVEL_MULTIPLE
- "org.apache.xalan.xsltc.dom.AnyNodeCounter" // LEVEL_ANY
+ "org.apache.xalan.xsltc.dom.SingleNodeCounter", // LEVEL_SINGLE
+ "org.apache.xalan.xsltc.dom.MultipleNodeCounter", // LEVEL_MULTIPLE
+ "org.apache.xalan.xsltc.dom.AnyNodeCounter" // LEVEL_ANY
};
static final private String[] FieldNames = {
@@ -102,24 +100,22 @@
"___multiple_node_counter", // LEVEL_MULTIPLE
"___any_node_counter" // LEVEL_ANY
};
+
+ public void parseContents(Parser parser) {
+ final int count = _attributes.getLength();
- public void parseContents(Element element, Parser parser) {
- NamedNodeMap attributes = element.getAttributes();
- final int nAttributes = attributes.getLength();
-
- for (int i = 0; i < nAttributes; i++) {
- final Attr attribute = (Attr) attributes.item(i);
- final String name = attribute.getName();
- final String value = attribute.getValue();
+ for (int i = 0; i < count; i++) {
+ final String name = _attributes.getQName(i);
+ final String value = _attributes.getValue(i);
if (name.equals("value")) {
- _value = parser.parseExpression(this, element, name);
+ _value = parser.parseExpression(this, name, null);
}
else if (name.equals("count")) {
- _count = parser.parsePattern(this, element, name);
+ _count = parser.parsePattern(this, name, null);
}
else if (name.equals("from")) {
- _from = parser.parsePattern(this, element, name);
+ _from = parser.parsePattern(this, name, null);
}
else if (name.equals("level")) {
if (value.equals("single")) {
@@ -514,14 +510,14 @@
_letterValue.translate(classGen, methodGen);
}
else {
- il.append(new PUSH(cpg, ""));
+ il.append(new PUSH(cpg, Constants.EMPTYSTRING));
}
if (_groupingSeparator != null) {
_groupingSeparator.translate(classGen, methodGen);
}
else {
- il.append(new PUSH(cpg, ""));
+ il.append(new PUSH(cpg, Constants.EMPTYSTRING));
}
if (_groupingSize != null) {
1.4 +24 -27
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.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Output.java 2001/05/17 14:28:13 1.3
+++ Output.java 2001/06/06 10:45:18 1.4
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: Output.java,v 1.3 2001/05/17 14:28:13 tmiller Exp $
+ * @(#)$Id: Output.java,v 1.4 2001/06/06 10:45:18 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -68,8 +68,6 @@
import java.util.Enumeration;
import java.util.StringTokenizer;
-import org.w3c.dom.*;
-
import de.fub.bytecode.generic.*;
import de.fub.bytecode.classfile.JavaClass;
@@ -112,24 +110,22 @@
*/
private String generateXmlHeader() {
// No header if user doesn't want one.
- if (_omitXmlDeclaration) {
- return("");
- }
+ if (_omitXmlDeclaration) return(Constants.EMPTYSTRING);
// Start off XML header
final StringBuffer hdr = new StringBuffer("<?xml ");
- if ((_version != null) && (!_version.equals("")))
+ if ((_version != null) && (_version !=Constants.EMPTYSTRING))
hdr.append("version=\"" + _version + "\" ");
else
hdr.append("version=\"1.0\" ");
- if ((_encoding != null) && (!_encoding.equals("")))
+ if ((_encoding != null) && (_encoding !=Constants.EMPTYSTRING))
hdr.append("encoding=\"" + _encoding + "\" ");
else
hdr.append("encoding=\"utf-8\" ");
- if ((_standalone != null) && (!_standalone.equals("")))
+ if ((_standalone != null) && (_standalone != Constants.EMPTYSTRING))
hdr.append("standalone=\"" + _standalone + "\" ");
// Finish off XML header and return string.
@@ -140,26 +136,26 @@
/**
* Scans the attribute list for the xsl:output instruction
*/
- public void parseContents(Element element, Parser parser) {
+ public void parseContents(Parser parser) {
- _method = element.getAttribute("method");
- _version = element.getAttribute("version");
- _encoding = element.getAttribute("encoding");
- _doctypeSystem = element.getAttribute("doctype-system");
- _doctypePublic = element.getAttribute("doctype-public");
- _cdataElements = element.getAttribute("cdata-section-elements");
- _mediaType = element.getAttribute("media-type");
- _standalone = element.getAttribute("standalone");
+ _method = getAttribute("method");
+ _version = getAttribute("version");
+ _encoding = getAttribute("encoding");
+ _doctypeSystem = getAttribute("doctype-system");
+ _doctypePublic = getAttribute("doctype-public");
+ _cdataElements = getAttribute("cdata-section-elements");
+ _mediaType = getAttribute("media-type");
+ _standalone = getAttribute("standalone");
- if ((_method == null) || (_method.equals("")))
+ if ((_method == null) || (_method == Constants.EMPTYSTRING))
_method = "xml";
- String attrib = element.getAttribute("omit-xml-declaration");
+ String attrib = getAttribute("omit-xml-declaration");
if ((attrib != null) && (attrib.equals("yes")))
_omitXmlDeclaration = true;
if (_method.equals("xml") || _method.equals("html")) {
- attrib = element.getAttribute("indent");
+ attrib = getAttribute("indent");
if ((attrib != null) && (attrib.equals("yes")))
_indent = true;
}
@@ -169,7 +165,7 @@
else
_header = null;
- parseChildren(element, parser);
+ parseChildren(parser);
parser.setOutput(this);
}
@@ -200,12 +196,13 @@
"setType", "(I)V");
il.append(methodGen.loadHandler());
if (_method.equals("text")) {
- il.append(new PUSH(cpg,
org.apache.xalan.xsltc.runtime.TextOutput.TEXT));
+ il.append(new PUSH(cpg, TextOutput.TEXT));
}
else if (_method.equals("xml")) {
// Handle any XML elements that should be turned into
// CDATA elements in the XML output document.
- if ((_cdataElements != null) && (_cdataElements != "")) {
+ if ((_cdataElements != null) &&
+ (_cdataElements != Constants.EMPTYSTRING)) {
StringTokenizer st = new StringTokenizer(_cdataElements,",");
final int cdata = cpg.addInterfaceMethodref(OUTPUT_HANDLER,
"insertCdataElement",
@@ -216,13 +213,13 @@
il.append(new INVOKEINTERFACE(cdata,2));
}
}
- il.append(new
PUSH(cpg,org.apache.xalan.xsltc.runtime.TextOutput.XML));
+ il.append(new PUSH(cpg, TextOutput.XML));
}
else if (_method.equals("html")) {
- il.append(new
PUSH(cpg,org.apache.xalan.xsltc.runtime.TextOutput.HTML));
+ il.append(new PUSH(cpg, TextOutput.HTML));
}
else {
- il.append(new PUSH(cpg,
org.apache.xalan.xsltc.runtime.TextOutput.QNAME));
+ il.append(new PUSH(cpg, TextOutput.QNAME));
}
il.append(new INVOKEINTERFACE(type,2));
1.3 +13 -11
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Param.java
Index: Param.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Param.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Param.java 2001/05/02 10:24:59 1.2
+++ Param.java 2001/06/06 10:45:20 1.3
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: Param.java,v 1.2 2001/05/02 10:24:59 morten Exp $
+ * @(#)$Id: Param.java,v 1.3 2001/06/06 10:45:20 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -65,8 +65,6 @@
import java.util.Vector;
-import org.w3c.dom.*;
-
import org.apache.xalan.xsltc.compiler.util.Type;
import org.apache.xalan.xsltc.compiler.util.ReferenceType;
@@ -101,6 +99,10 @@
displayContents(indent + IndentIncrement);
}
+ public String toString() {
+ return("param("+_name+")");
+ }
+
public void addReference(ParameterRef pref) {
_refs.addElement(pref);
}
@@ -137,15 +139,15 @@
return _name;
}
- public void parseContents(Element element, Parser parser) {
+ public void parseContents(Parser parser) {
// Parse attributes name and select (if present)
- final String name = element.getAttribute("name");
+ final String name = getAttribute("name");
if (name.length() > 0) {
_name = parser.getQName(name);
}
else {
- reportError(element, parser, ErrorMsg.NREQATTR_ERR, "name");
+ reportError(this, parser, ErrorMsg.NREQATTR_ERR, "name");
}
// check whether variable/param of the same name is already in scope
@@ -154,13 +156,13 @@
parser.addError(error);
}
- final String select = element.getAttribute("select");
+ final String select = getAttribute("select");
if (select.length() > 0) {
- _select = parser.parseExpression(this, element, "select");
+ _select = parser.parseExpression(this, "select", null);
}
// Children must be parsed first -> static scoping
- parseChildren(element, parser);
+ parseChildren(parser);
// Add a ref to this param to its enclosing construct
final SyntaxTreeNode parent = getParent();
@@ -247,7 +249,7 @@
}
else {
// If no select and no contents push the empty string
- il.append(new PUSH(cpg, ""));
+ il.append(new PUSH(cpg, Constants.EMPTYSTRING));
}
}
else {
@@ -289,7 +291,7 @@
}
else {
// If no select and no contents push the empty string
- il.append(new PUSH(cpg, ""));
+ il.append(new PUSH(cpg, Constants.EMPTYSTRING));
}
}
else {
1.6 +509 -444
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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Parser.java 2001/06/05 13:00:58 1.5
+++ Parser.java 2001/06/06 10:45:21 1.6
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: Parser.java,v 1.5 2001/06/05 13:00:58 tmiller Exp $
+ * @(#)$Id: Parser.java,v 1.6 2001/06/06 10:45:21 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -72,6 +72,7 @@
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.StringTokenizer;
+import java.util.Stack;
import java.net.MalformedURLException;
import javax.xml.parsers.*;
@@ -85,8 +86,9 @@
import java_cup.runtime.Symbol;
import org.apache.xalan.xsltc.compiler.util.*;
+import org.apache.xalan.xsltc.runtime.AttributeList;
-public final class Parser implements Constants {
+public final class Parser implements Constants, ContentHandler {
private static final String XSL = "xsl"; // standard prefix
private static final String TRANSLET = "translet"; // extension prefix
@@ -96,6 +98,8 @@
private Vector _errors; // Contains all compilation errors
private Vector _warnings; // Contains all compilation errors
+ private ErrorListener _errorListener = null;
+
private Hashtable _instructionClasses; // Maps instructions to classes
private Hashtable _qNames;
private Hashtable _namespaces;
@@ -108,25 +112,31 @@
private Output _output = null;
private Template _template; // Reference to the template being
parsed.
- private int _currentImportPrecedence = 1;
+ private SyntaxTreeNode _root = null;
- private ErrorListener _errorListener = null;
+ private String _target;
- public void setErrorListener(ErrorListener listener) {
- _errorListener = listener;
- }
+ private int _currentImportPrecedence = 1;
+ private final static String CLASS_NOT_FOUND =
+ "Internal XSLTC class not in classpath: ";
+ private final static String INTERNAL_ERROR =
+ "Unrecoverable XSLTC compilation error: ";
+ private final static String UNSUPPORTED_XSL_ERROR =
+ "Unsupported XSL element: ";
+ private final static String INVALID_EXT_ERROR =
+ "Invalid XSLTC extension: ";
+ private final static String UNSUPPORTED_EXT_ERROR =
+ "Unsupported XSLT extension: ";
+ private final static String TEXT_NODE_ERROR =
+ "Text data outside of top-level <xsl:stylesheet> element.";
+ private final static String MISSING_HREF_ERROR =
+ "Processing instruction <?xml-stylesheet ... ?> is missing href data.";
+
public Parser(XSLTC xsltc) {
_xsltc = xsltc;
}
- public void setOutput(Output output) {
- if (_output == null)
- _output = output;
- else
- output.disable();
- }
-
public void init() {
_qNames = new Hashtable(512);
_namespaces = new Hashtable();
@@ -144,12 +154,24 @@
initExtClasses();
initSymbolTable();
- _useAttributeSets = getQName(XSLT_URI, XSL, "use-attribute-sets");
- _excludeResultPrefixes
- = getQName(XSLT_URI, XSL, "exclude-result-prefixes");
- _extensionElementPrefixes
- = getQName(XSLT_URI, XSL, "extension-element-prefixes");
+ _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) {
+ if (_output == null)
+ _output = output;
+ else
+ output.disable();
}
+
+ public void setErrorListener(ErrorListener listener) {
+ _errorListener = listener;
+ }
public void addVariable(Variable var) {
_variableScope.put(var.getName(), var);
@@ -202,12 +224,12 @@
// Get the namespace uri from the symbol table
if (prefix.equals("xmlns") == false) {
namespace = _symbolTable.lookupNamespace(prefix);
- if (namespace == null) namespace = "";
+ if (namespace == null) namespace = Constants.EMPTYSTRING;
}
return getQName(namespace, prefix, localname);
}
else {
- return getQName(_symbolTable.lookupNamespace(""), null, stringRep);
+ return
getQName(_symbolTable.lookupNamespace(Constants.EMPTYSTRING), null, stringRep);
}
}
@@ -224,12 +246,14 @@
namespace = _symbolTable.lookupNamespace(prefix);
if (namespace == null) {
addError(new ErrorMsg(ErrorMsg.NSPUNDEF_ERR, prefix));
+ Exception e = new Exception();
+ e.printStackTrace();
}
}
return getQName(namespace, prefix, localname);
}
else {
- return getQName(_symbolTable.lookupNamespace(""), null, stringRep);
+ return
getQName(_symbolTable.lookupNamespace(Constants.EMPTYSTRING), null, stringRep);
}
}
@@ -286,34 +310,20 @@
* and then parse, typecheck and compile the instance.
* Must be called after <code>parse()</code>.
*/
- public Stylesheet makeStylesheet(Element element)
+ public Stylesheet makeStylesheet(SyntaxTreeNode element)
throws CompilerException {
try {
Stylesheet stylesheet;
- // Push any namespaces declared in the root element
- pushNamespaces(element);
-
- // Get the name of this element and try to map it to a class
- final QName qName = getQName(element.getTagName());
- final String namespace = element.getNamespaceURI();
- final String classname = (String)_instructionClasses.get(qName);
-
- // Make a Stylesheet object from the root node if it is an
- // xsl:stylesheet element
- if (classname != null) {
- stylesheet = (Stylesheet)makeInstance(element);
+ if (element instanceof Stylesheet) {
+ stylesheet = (Stylesheet)element;
}
- // Otherwise we create an empty Stylesheet object, and tag it
- // as a simplified stylesheet (a simplified stylesheet will have
- // to insert a <xsl:template match="/"/> as its only child).
else {
stylesheet = new Stylesheet();
stylesheet.setSimplified();
+ stylesheet.addElement(element);
}
-
stylesheet.setParser(this);
- popNamespaces(element);
return stylesheet;
}
catch (ClassCastException e) {
@@ -322,68 +332,19 @@
}
}
- /**
- * Update the symbol table with the namespace declarations defined in
- * <tt>element</tt>.
- */
- public void pushNamespaces(Element element) {
- pushPopNamespaces(element, true);
- }
-
- /**
- * Update the symbol table with the namespace declarations defined in
- * <tt>element</tt>.
- */
- public void popNamespaces(Element element) {
- pushPopNamespaces(element, false);
- }
-
/**
- * Update the symbol table with the namespace declarations defined in
- * <tt>element</tt>. The declarations are added or removed form the
- * symbol table depending on the value of <tt>push</tt>.
+ * Instanciates a SAX2 parser and generate the AST from the input.
*/
- private void pushPopNamespaces(Element element, boolean push) {
- final NamedNodeMap map = element.getAttributes();
- final int n = map.getLength();
- for (int i = 0; i < n; i++) {
- final Node node = map.item(i);
- final String name = node.getNodeName();
- String prefix;
-
- if (name.equals("xmlns")) {
- prefix = ""; // default namespace
- }
- else {
- final int index = name.indexOf(':');
- if (index >= 0 && name.substring(0, index).equals("xmlns")) {
- prefix = name.substring(index + 1);
- }
- else {
- continue;
- }
- }
-
- if (push)
- _symbolTable.pushNamespace(prefix, node.getNodeValue());
- else
- _symbolTable.popNamespace(prefix);
- }
- }
-
- public void createAST(Element element, Stylesheet stylesheet) {
+ public void createAST(Stylesheet stylesheet) {
try {
if (stylesheet != null) {
- stylesheet.parseContents(element, this);
+ stylesheet.parseContents(this);
final int precedence = stylesheet.getImportPrecedence();
final Enumeration elements = stylesheet.elements();
while (elements.hasMoreElements()) {
Object child = elements.nextElement();
- // GTM: fixed bug # 4415344
- if (child instanceof Text){
- throw new TypeCheckError(new ErrorMsg(
- "character data '" + ((Text)child).getText() +
- "' found outside top level stylesheet element."));
+ if (child instanceof Text) {
+ addError(new ErrorMsg(TEXT_NODE_ERROR));
}
}
if (!errorsFound()) {
@@ -392,37 +353,42 @@
}
}
catch (TypeCheckError e) {
- //e.printStackTrace();
- addError(new ErrorMsg(e.toString())); // TODO
+ addError(new ErrorMsg(e.toString()));
}
}
- public Element parse(URL url) {
- return(parse(url.toString()));
+ /**
+ * Instanciates a SAX2 parser and generate the AST from the input.
+ */
+ public SyntaxTreeNode parse(URL url) {
+ return(parse(url.toString(), true));
}
- public Element parse(String stylesheetURL) {
+ /**
+ * Instanciates a SAX2 parser and generate the AST from the input.
+ */
+ public SyntaxTreeNode parse(String location, boolean isURL) {
try {
- // Get an instance of the document builder factory
- final DocumentBuilderFactory factory =
- DocumentBuilderFactory.newInstance();
- factory.setNamespaceAware(true);
-
- // Then make an instance of the actual document builder
- final DocumentBuilder builder = factory.newDocumentBuilder();
- if (!builder.isNamespaceAware()) { // Must be namespace aware
- addError(new ErrorMsg("SAX parser is not namespace aware"));
- }
+ // Create a SAX parser and get the XMLReader object it uses
+ final SAXParserFactory factory = SAXParserFactory.newInstance();
+ final SAXParser parser = factory.newSAXParser();
+ final XMLReader reader = parser.getXMLReader();
+
+ // Parse the input document and build the abstract syntax tree
+ reader.setContentHandler(this);
+ if (isURL)
+ reader.parse(location);
+ else
+ reader.parse("file:"+(new File(location).getAbsolutePath()));
- // Parse the stylesheet document and return the root element
- Document document = builder.parse(stylesheetURL);
- return document.getDocumentElement();
+ // Find the start of the stylesheet within the tree
+ return (SyntaxTreeNode)getStylesheet(_root);
}
catch (ParserConfigurationException e) {
addError(new ErrorMsg("JAXP parser not configured correctly"));
}
catch (IOException e) {
- addError(new ErrorMsg(ErrorMsg.FILECANT_ERR, stylesheetURL));
+ addError(new ErrorMsg(ErrorMsg.FILECANT_ERR, location));
}
catch (SAXParseException e){
addError(new ErrorMsg(e.getMessage(),e.getLineNumber()));
@@ -430,6 +396,9 @@
catch (SAXException e) {
addError(new ErrorMsg(e.getMessage()));
}
+ catch (CompilerException e) {
+ addError(new ErrorMsg(e.getMessage()));
+ }
return null;
}
@@ -442,154 +411,66 @@
* as the 'href' data of the P.I. The extracted DOM representing the
* stylesheet is returned as an Element object.
*/
- private Element getStylesheet(Document doc) throws CompilerException {
+ private SyntaxTreeNode getStylesheet(SyntaxTreeNode root)
+ throws CompilerException {
- // Get the xml-stylesheet processing instruction (P.I.)
- org.w3c.dom.ProcessingInstruction stylesheetPI = getStylesheetPI(doc);
- // If there is none we assume this is a pure XSL file and return root.
- if (stylesheetPI == null ) return (Element)doc.getDocumentElement();
-
- // Get href value from P.I. to identify the correct stylesheet
- String href = getXmlStylesheetPIHrefValue(stylesheetPI);
- if (href == null) {
- throw new CompilerException(
- "Processing instruction <?xml-stylesheet ... ?> is " +
- "missing the href data.");
- }
-
- // Create list of all xsl:stylesheet (or alt. xsl:transform) elements
- NodeList elements = doc.getElementsByTagName("xsl:stylesheet");
- if (elements.getLength() == 0)
- elements = doc.getElementsByTagName("xsl:transform");
-
- // Scan all elements to find the one that matches the href in the PI
- for(int i=0; i<elements.getLength(); i++) {
- Node curr = elements.item(i);
- NamedNodeMap map = curr.getAttributes();
- if (map.getLength() != 0) {
- Node attr = map.getNamedItem("id");
- String attrValue = attr.getNodeValue();
- if ((href == null) || (href.equals(attrValue))) {
- return (Element)curr;
- }
- }
+ // Assume that this is a pure XSL stylesheet if there is not
+ // <?xml-stylesheet ....?> processing instruction
+ if (_target == null) return(root);
+
+ // Find the xsl:stylesheet or xsl:transform with this reference
+ if (_target.charAt(0) == '#') {
+ SyntaxTreeNode element = findStylesheet(root, _target.substring(1));
+ return(element);
}
-
- // If there is none we assume this is a pure XSL file and return root.
- // GTM Note: removed this line because it was causing failures
- // in test suite, the presence of a xml-stylesheet P.I. AND
- // the absence of an href should be an error. See 'href == null'
- // above.... we will remove this comment and associated line
- // after test suite confirms it has not damaged anything else.
- // if (href == null) return (Element)doc.getDocumentElement();
-
- // If we did not find the references stylesheet in the current XML
- // file we assume it is an external file and load that...
- return(loadExternalStylesheet(doc, href));
+ else {
+ return(loadExternalStylesheet(_target));
+ }
}
/**
- * For embedded stylesheets: Load an external file with stylesheet
+ * Find a Stylesheet element with a specific ID attribute value.
+ * This method is used to find a Stylesheet node that is referred
+ * in a <?xml-stylesheet ... ?> processing instruction.
*/
- private Element loadExternalStylesheet(Document doc, String url)
- throws CompilerException {
- try {
- // Check if the URL is a local file
- if ((new File(url)).exists()) url = "file:"+url;
+ private SyntaxTreeNode findStylesheet(SyntaxTreeNode root, String href) {
- // Get an instance of the document builder factory
- final DocumentBuilderFactory factory =
- DocumentBuilderFactory.newInstance();
- factory.setNamespaceAware(true);
-
- // Then make an instance of the actual document builder
- final DocumentBuilder builder = factory.newDocumentBuilder();
- if (!builder.isNamespaceAware()) { // Must be namespace aware
- addError(new ErrorMsg("SAX parser is not namespace aware"));
- }
+ if (root == null) return null;
- // Parse the stylesheet document and return the root element
- Document document = builder.parse(url);
- return document.getDocumentElement();
- }
- catch (ParserConfigurationException e) {
- throw new CompilerException("JAXP parser not configured "+
- "correctly");
+ if (root instanceof Stylesheet) {
+ String id = root.getAttribute("id");
+ if (id.equals(href)) return root;
}
- catch (IOException e) {
- throw new CompilerException("Could not find stylesheet - '"+url+
- "' is not a named element in the "+
- "current file nor a local file.");
- }
- catch (SAXException e) {
- throw new CompilerException("Could not parse stylesheet with id='"+
- url+"' (referenced in stylesheet PI)");
+ Vector children = root.getContents();
+ if (children != null) {
+ final int count = children.size();
+ for (int i = 0; i < count; i++) {
+ SyntaxTreeNode child = (SyntaxTreeNode)children.elementAt(i);
+ SyntaxTreeNode node = findStylesheet(child, href);
+ if (node != null) return node;
+ }
}
+ return null;
}
/**
- * Returns the first xml-stylesheet processing instruction found in the
DOM.
+ * For embedded stylesheets: Load an external file with stylesheet
*/
- private org.w3c.dom.ProcessingInstruction getStylesheetPI(Document doc) {
+ private SyntaxTreeNode loadExternalStylesheet(String url)
+ throws CompilerException {
- Node node = doc;
+ // Check if the URL is a local file
+ if ((new File(url)).exists()) url = "file:"+url;
- while (node != null) {
- switch (node.getNodeType ()) {
- case Node.PROCESSING_INSTRUCTION_NODE:
- org.w3c.dom.ProcessingInstruction pi =
- (org.w3c.dom.ProcessingInstruction)node;
- if (pi.getTarget().equals("xml-stylesheet")) return pi;
- // FALLTHROUGH
- case Node.DOCUMENT_FRAGMENT_NODE:
- case Node.DOCUMENT_NODE:
- case Node.ELEMENT_NODE:
- // First try to traverse any children of the node
- Node child = node.getFirstChild();
- if (child != null) {
- node = child;
- break;
- }
- // FALLTHROUGH
- default:
- // Then try the siblings
- Node next = node.getNextSibling();
- if (next == null) {
- // Then step up to the parent node
- Node parent = node.getParentNode();
- if ((parent == null) || (node == doc)) return null;
- node = parent;
- }
- else {
- node = next;
- }
- }
- }
- return null;
- }
+ SyntaxTreeNode external = (SyntaxTreeNode)parse(url, true);
- /**
- * Extracts the value of the 'href' in an xml-stylesheet processing
- * instruction. The value of the P.I. href is prefixed with the '#'
- * character, this method removes the prefix before returning it to
- * caller. Returns: String (without '#' prefix) or null if none found.
- */
- private String getXmlStylesheetPIHrefValue(
- org.w3c.dom.ProcessingInstruction pi)
- {
- String data = pi.getData();
- int start = -1;
- if ((start = data.indexOf("href")) < 0) {
- return null;
- }
- String hrefportion = data.substring(start);
- StringTokenizer tok = new StringTokenizer(hrefportion, "\"");
- tok.nextToken(); // throw away 'href='
- String retval = tok.nextToken();
- return (retval.startsWith("#")) ? retval.substring(1):retval;
+ return(external);
}
-
+ /**
+ * Initialize the _instructionClasses Hashtable, which maps XSL element
+ * names to Java classes in this package.
+ */
private void initStdClasses() {
initStdClass("template", "Template");
initStdClass("stylesheet", "Stylesheet");
@@ -701,93 +582,93 @@
*/
// The following functions are inlined
- _symbolTable.addPrimop(getQName("current"), A_V);
- _symbolTable.addPrimop(getQName("last"), I_V);
- _symbolTable.addPrimop(getQName("position"), I_V);
- _symbolTable.addPrimop(getQName("true"), B_V);
- _symbolTable.addPrimop(getQName("false"), B_V);
- _symbolTable.addPrimop(getQName("not"), B_B);
- _symbolTable.addPrimop(getQName("name"), S_V);
- _symbolTable.addPrimop(getQName("name"), S_A);
- _symbolTable.addPrimop(getQName("generate-id"), S_V);
- _symbolTable.addPrimop(getQName("generate-id"), S_A);
- _symbolTable.addPrimop(getQName("ceiling"), R_R);
- _symbolTable.addPrimop(getQName("floor"), R_R);
- _symbolTable.addPrimop(getQName("round"), I_R);
- _symbolTable.addPrimop(getQName("contains"), B_SS);
- _symbolTable.addPrimop(getQName("number"), R_O);
- _symbolTable.addPrimop(getQName("number"), R_V);
- _symbolTable.addPrimop(getQName("boolean"), B_O);
- _symbolTable.addPrimop(getQName("string"), S_O);
- _symbolTable.addPrimop(getQName("string"), S_V);
- _symbolTable.addPrimop(getQName("translate"), S_SSS);
- _symbolTable.addPrimop(getQName("string-length"), I_V);
- _symbolTable.addPrimop(getQName("string-length"), I_S);
- _symbolTable.addPrimop(getQName("starts-with"), B_SS);
- _symbolTable.addPrimop(getQName("format-number"), S_DS);
- _symbolTable.addPrimop(getQName("format-number"), S_DSS);
- _symbolTable.addPrimop(getQName("unparsed-entity-uri"), S_S);
- _symbolTable.addPrimop(getQName("key"), D_SS);
- _symbolTable.addPrimop(getQName("key"), D_SD);
- _symbolTable.addPrimop(getQName("id"), D_S);
- _symbolTable.addPrimop(getQName("id"), D_D);
- _symbolTable.addPrimop(getQName("namespace-uri"), S_V);
+ _symbolTable.addPrimop("current", A_V);
+ _symbolTable.addPrimop("last", I_V);
+ _symbolTable.addPrimop("position", I_V);
+ _symbolTable.addPrimop("true", B_V);
+ _symbolTable.addPrimop("false", B_V);
+ _symbolTable.addPrimop("not", B_B);
+ _symbolTable.addPrimop("name", S_V);
+ _symbolTable.addPrimop("name", S_A);
+ _symbolTable.addPrimop("generate-id", S_V);
+ _symbolTable.addPrimop("generate-id", S_A);
+ _symbolTable.addPrimop("ceiling", R_R);
+ _symbolTable.addPrimop("floor", R_R);
+ _symbolTable.addPrimop("round", I_R);
+ _symbolTable.addPrimop("contains", B_SS);
+ _symbolTable.addPrimop("number", R_O);
+ _symbolTable.addPrimop("number", R_V);
+ _symbolTable.addPrimop("boolean", B_O);
+ _symbolTable.addPrimop("string", S_O);
+ _symbolTable.addPrimop("string", S_V);
+ _symbolTable.addPrimop("translate", S_SSS);
+ _symbolTable.addPrimop("string-length", I_V);
+ _symbolTable.addPrimop("string-length", I_S);
+ _symbolTable.addPrimop("starts-with", B_SS);
+ _symbolTable.addPrimop("format-number", S_DS);
+ _symbolTable.addPrimop("format-number", S_DSS);
+ _symbolTable.addPrimop("unparsed-entity-uri", S_S);
+ _symbolTable.addPrimop("key", D_SS);
+ _symbolTable.addPrimop("key", D_SD);
+ _symbolTable.addPrimop("id", D_S);
+ _symbolTable.addPrimop("id", D_D);
+ _symbolTable.addPrimop("namespace-uri", S_V);
+
// The following functions are implemented in the basis library
- _symbolTable.addPrimop(getQName("count"), I_D);
- _symbolTable.addPrimop(getQName("sum"), R_D);
- _symbolTable.addPrimop(getQName("local-name"), S_V);
- _symbolTable.addPrimop(getQName("local-name"), S_D);
- _symbolTable.addPrimop(getQName("namespace-uri"), S_V);
- _symbolTable.addPrimop(getQName("namespace-uri"), S_D);
- _symbolTable.addPrimop(getQName("substring"), S_SR);
- _symbolTable.addPrimop(getQName("substring"), S_SRR);
- _symbolTable.addPrimop(getQName("substring-after"), S_SS);
- _symbolTable.addPrimop(getQName("substring-before"), S_SS);
- _symbolTable.addPrimop(getQName("normalize-space"), S_V);
- _symbolTable.addPrimop(getQName("normalize-space"), S_S);
- _symbolTable.addPrimop(getQName("function-available"), B_S);
- _symbolTable.addPrimop(getQName("system-property"), S_S);
+ _symbolTable.addPrimop("count", I_D);
+ _symbolTable.addPrimop("sum", R_D);
+ _symbolTable.addPrimop("local-name", S_V);
+ _symbolTable.addPrimop("local-name", S_D);
+ _symbolTable.addPrimop("namespace-uri", S_V);
+ _symbolTable.addPrimop("namespace-uri", S_D);
+ _symbolTable.addPrimop("substring", S_SR);
+ _symbolTable.addPrimop("substring", S_SRR);
+ _symbolTable.addPrimop("substring-after", S_SS);
+ _symbolTable.addPrimop("substring-before", S_SS);
+ _symbolTable.addPrimop("normalize-space", S_V);
+ _symbolTable.addPrimop("normalize-space", S_S);
+ _symbolTable.addPrimop("function-available", B_S);
+ _symbolTable.addPrimop("system-property", S_S);
// Operators +, -, *, /, % defined on real types.
- _symbolTable.addPrimop(getQName("+"), R_RR);
- _symbolTable.addPrimop(getQName("-"), R_RR);
- _symbolTable.addPrimop(getQName("*"), R_RR);
- _symbolTable.addPrimop(getQName("/"), R_RR);
- _symbolTable.addPrimop(getQName("%"), R_RR);
+ _symbolTable.addPrimop("+", R_RR);
+ _symbolTable.addPrimop("-", R_RR);
+ _symbolTable.addPrimop("*", R_RR);
+ _symbolTable.addPrimop("/", R_RR);
+ _symbolTable.addPrimop("%", R_RR);
// Operators +, -, * defined on integer types.
// Operators / and % are not defined on integers (may cause exception)
- _symbolTable.addPrimop(getQName("+"), I_II);
- _symbolTable.addPrimop(getQName("-"), I_II);
- _symbolTable.addPrimop(getQName("*"), I_II);
+ _symbolTable.addPrimop("+", I_II);
+ _symbolTable.addPrimop("-", I_II);
+ _symbolTable.addPrimop("*", I_II);
// Operators <, <= >, >= defined on real types.
- _symbolTable.addPrimop(getQName("<"), B_RR);
- _symbolTable.addPrimop(getQName("<="), B_RR);
- _symbolTable.addPrimop(getQName(">"), B_RR);
- _symbolTable.addPrimop(getQName(">="), B_RR);
+ _symbolTable.addPrimop("<", B_RR);
+ _symbolTable.addPrimop("<=", B_RR);
+ _symbolTable.addPrimop(">", B_RR);
+ _symbolTable.addPrimop(">=", B_RR);
// Operators <, <= >, >= defined on int types.
- _symbolTable.addPrimop(getQName("<"), B_II);
- _symbolTable.addPrimop(getQName("<="), B_II);
- _symbolTable.addPrimop(getQName(">"), B_II);
- _symbolTable.addPrimop(getQName(">="), B_II);
+ _symbolTable.addPrimop("<", B_II);
+ _symbolTable.addPrimop("<=", B_II);
+ _symbolTable.addPrimop(">", B_II);
+ _symbolTable.addPrimop(">=", B_II);
// Operators <, <= >, >= defined on boolean types.
- _symbolTable.addPrimop(getQName("<"), B_BB);
- _symbolTable.addPrimop(getQName("<="), B_BB);
- _symbolTable.addPrimop(getQName(">"), B_BB);
- _symbolTable.addPrimop(getQName(">="), B_BB);
+ _symbolTable.addPrimop("<", B_BB);
+ _symbolTable.addPrimop("<=", B_BB);
+ _symbolTable.addPrimop(">", B_BB);
+ _symbolTable.addPrimop(">=", B_BB);
// Operators 'and' and 'or'.
- _symbolTable.addPrimop(getQName("or"), B_BB);
- _symbolTable.addPrimop(getQName("and"), B_BB);
+ _symbolTable.addPrimop("or", B_BB);
+ _symbolTable.addPrimop("and", B_BB);
// Unary minus.
- _symbolTable.addPrimop(getQName("u-"), R_R);
- _symbolTable.addPrimop(getQName("u-"), I_I);
- _symbolTable.pushNamespace("xml", "xml");
+ _symbolTable.addPrimop("u-", R_R);
+ _symbolTable.addPrimop("u-", I_I);
}
public SymbolTable getSymbolTable() {
@@ -798,173 +679,150 @@
return _template;
}
- int _templateIndex = 0;
-
- public int getTemplateIndex() {
- return(_templateIndex++);
- }
-
- //!!! temporarily here
- public void internalError() {
- _xsltc.internalError();
- }
-
- public void notYetImplemented(String feature) {
- _xsltc.notYetImplemented(feature);
- }
-
public void setTemplate(Template template) {
_template = template;
}
- private Element findFallback(Element root) {
- final NodeList nodes = root.getChildNodes();
- final int length = (nodes != null) ? nodes.getLength() : 0;
-
- for (int i = 0; i < length; i++) {
- Node node = nodes.item(i);
- if (node.getNodeType() == Node.ELEMENT_NODE) {
- Element child = (Element)node;
- String namespace = child.getNamespaceURI();
- String localname = child.getLocalName();
- if (namespace.equals(XSLT_URI) &&
- localname.equals("fallback")) {
- return child;
- }
- else {
- Element result = findFallback(child);
- if (result != null) return result;
- }
- }
- }
- return null;
- }
-
- public Fallback makeFallback(Element root) {
- Element element = findFallback(root);
- if (element != null) {
- Fallback fallback = (Fallback)makeInstance(FALLBACK_CLASS, element);
- fallback.activate();
- fallback.parseContents(element, this);
- return(fallback);
- }
- else {
- return(null);
- }
+ /*
+ private int _templateIndex = 0;
+ public int getTemplateIndex() {
+ return(_templateIndex++);
}
+ */
/**
- * Creates an object that is of a sub-class of SyntaxTreeNode
- * from the node in the DOM (if possible).
+ * Creates a new node in the abstract syntax tree. This node can be
+ * o) a supported XSLT 1.0 element
+ * o) an unsupported XSLT element (post 1.0)
+ * o) a supported XSLT extension
+ * o) an unsupported XSLT extension
+ * o) a literal result element (not an XSLT element and not an
extension)
+ * Unsupported elements do not directly generate an error. We have to
wait
+ * until we have received all child elements of an unsupported element to
+ * see if any <xsl:fallback> elements exist.
*/
- public SyntaxTreeNode makeInstance(Element element) {
- QName qName = getQName(element.getTagName());
- String className = (String)_instructionClasses.get(qName);
- if (className != null) {
- return makeInstance(className, element);
- }
- else {
- final String namespace = element.getNamespaceURI();
- if (namespace != null) {
- // Check if the element belongs in our namespace
- if (namespace.equals(XSLT_URI)) {
- Fallback fallback = makeFallback(element);
- if (fallback == null)
- _xsltc.notYetImplemented(element.getTagName());
- return(fallback);
- }
- // Check if this is an XSLTC extension element
- else if (namespace.equals(TRANSLET_URI)) {
- Fallback fallback = makeFallback(element);
- if (fallback == null)
- _xsltc.extensionNotSupported(element.getTagName());
- return(fallback);
- }
- // Check if this is an extension of some other XSLT processor
- else if (_xsltc.getStylesheet().isExtension(namespace)) {
- Fallback fallback = makeFallback(element);
- if (fallback == null)
- _xsltc.extensionNotSupported(element.getTagName());
- return(fallback);
- }
- }
- return new LiteralElement();
- }
- }
-
- private SyntaxTreeNode makeInstance(String className, Element element) {
+ public SyntaxTreeNode makeInstance(String uri, String prefix, String
local){
+ QName qname = getQName(uri, prefix, local);
+ String className = (String)_instructionClasses.get(qname);
+ SyntaxTreeNode node = null;
+
if (className != null) {
try {
final Class clazz = Class.forName(className);
- SyntaxTreeNode node = (SyntaxTreeNode)clazz.newInstance();
+ node = (SyntaxTreeNode)clazz.newInstance();
+ node.setQName(qname);
node.setParser(this);
- return node;
+ if (node instanceof Stylesheet) {
+ _xsltc.setStylesheet((Stylesheet)node);
+ }
}
catch (ClassNotFoundException e) {
- e.printStackTrace();
+ addError(new ErrorMsg(CLASS_NOT_FOUND+className));
}
catch (Exception e) {
- e.printStackTrace();
- _xsltc.internalError();
+ addError(new ErrorMsg(INTERNAL_ERROR+e.getMessage()));
}
}
else {
- _xsltc.notYetImplemented(element.getTagName());
+ if (uri != null) {
+ // Check if the element belongs in our namespace
+ if (uri.equals(XSLT_URI)) {
+ node = new UnsupportedElement(uri, prefix, local);
+ UnsupportedElement element = (UnsupportedElement)node;
+ element.setErrorMessage(UNSUPPORTED_XSL_ERROR+local);
+ }
+ // Check if this is an XSLTC extension element
+ else if (uri.equals(TRANSLET_URI)) {
+ node = new UnsupportedElement(uri, prefix, local);
+ UnsupportedElement element = (UnsupportedElement)node;
+ element.setErrorMessage(INVALID_EXT_ERROR+local);
+ }
+ // Check if this is an extension of some other XSLT processor
+ else if ((_xsltc.getStylesheet() != null) &&
+ (_xsltc.getStylesheet().isExtension(uri))) {
+ node = new UnsupportedElement(uri, prefix, local);
+ UnsupportedElement element = (UnsupportedElement)node;
+ element.setErrorMessage(UNSUPPORTED_EXT_ERROR+
+ prefix+":"+local);
+ }
+ }
+ if (node == null) node = new LiteralElement();
}
- return null;
- }
-
- public Expression parseExpression(SyntaxTreeNode parent,
- String expression) {
- return (Expression)parseTopLevel(parent, "<EXPRESSION>"+expression,
- 0, null);
+ if ((node != null) && (node instanceof LiteralElement)) {
+ ((LiteralElement)node).setQName(qname);
+ }
+ return(node);
}
- public Expression parseExpression(SyntaxTreeNode parent,
- Element element, String attrName) {
- return parseExpression(parent, element, attrName, null);
+ /**
+ * Parse an XPath expression:
+ * @parent - XSL element where the expression occured
+ * @exp - textual representation of the expression
+ */
+ public Expression parseExpression(SyntaxTreeNode parent, String exp) {
+ return (Expression)parseTopLevel(parent, "<EXPRESSION>"+exp, 0, null);
}
+ /**
+ * Parse an XPath expression:
+ * @parent - XSL element where the expression occured
+ * @attr - name of this element's attribute to get expression from
+ * @def - default expression (if the attribute was not found)
+ */
public Expression parseExpression(SyntaxTreeNode parent,
- Element element, String attrName,
- String defaultValue) {
- String expression = element.getAttribute(attrName);
- if (expression.length() == 0 && defaultValue != null) {
- expression = defaultValue;
- }
- //final int line = ((Integer)element.getUserObject()).intValue();
- return (Expression)parseTopLevel(parent, "<EXPRESSION>" +
expression,
- -1 /*line*/, expression);
+ String attr, String def) {
+ // Get the textual representation of the expression (if any)
+ String exp = parent.getAttribute(attr);
+ // Use the default expression if none was found
+ if ((exp.length() == 0) && (def != null)) exp = def;
+ // Invoke the XPath parser
+ return (Expression)parseTopLevel(parent, "<EXPRESSION>"+exp, 0, exp);
}
+ /**
+ * Parse an XPath pattern:
+ * @parent - XSL element where the pattern occured
+ * @exp - textual representation of the pattern
+ */
public Pattern parsePattern(SyntaxTreeNode parent, String pattern) {
return (Pattern)parseTopLevel(parent, "<PATTERN>"+pattern, 0, pattern);
}
+ /**
+ * Parse an XPath pattern:
+ * @parent - XSL element where the pattern occured
+ * @attr - name of this element's attribute to get pattern from
+ * @def - default pattern (if the attribute was not found)
+ */
public Pattern parsePattern(SyntaxTreeNode parent,
- Element element, String attrName) {
- final String pattern = element.getAttribute(attrName);
- //final int line = ((Integer)element.getUserObject()).intValue();
- return (Pattern)parseTopLevel(parent, "<PATTERN>" + pattern,
- -1 /*line*/, pattern);
+ String attr, String def) {
+ // Get the textual representation of the pattern (if any)
+ String pattern = parent.getAttribute(attr);
+ // Use the default pattern if none was found
+ if ((pattern.length() == 0) && (def != null)) pattern = def;
+ // Invoke the XPath parser
+ return (Pattern)parseTopLevel(parent, "<PATTERN>"+pattern, 0,
pattern);
}
+ /**
+ * Parse an XPath expression or pattern using the generated XPathParser
+ * The method will return a Dummy node if the XPath parser fails.
+ */
private SyntaxTreeNode parseTopLevel(SyntaxTreeNode parent,
- String text, int lineNumber,
+ String text, int line,
String expression) {
try {
_xpathParser.setScanner(new XPathLexer(new StringReader(text)));
- Symbol result = _xpathParser.parse(lineNumber);
+ Symbol result = _xpathParser.parse(line);
if (result != null) {
final SyntaxTreeNode node = (SyntaxTreeNode)result.value;
- node.setParser(this);
- node.setParent(parent);
- return node;
+ if (node != null) {
+ node.setParser(this);
+ node.setParent(parent);
+ return node;
+ }
}
- else {
- addError(new ErrorMsg(ErrorMsg.XPATHPAR_ERR,
- lineNumber, expression));
- }
+ addError(new ErrorMsg(ErrorMsg.XPATHPAR_ERR, line, expression));
}
catch (Exception e) {
if (_xsltc.debug()) {
@@ -984,18 +842,18 @@
return _errors.size() > 0;
}
- public boolean warnings() {
- return _warnings.size() > 0;
- }
-
/**
* Adds an error to the vector containing compile-time errors.
*/
public void addError(ErrorMsg error) {
_errors.addElement(error);
+ }
+
+ public void addFatalError(String message) {
+ _errors.addElement(new ErrorMsg(message));
// support for TrAX Error Listener
if (_errorListener != null ) {
- postErrorToListener(error.toString());
+ postErrorToListener(message);
}
}
@@ -1016,9 +874,21 @@
*/
public void addWarning(ErrorMsg msg) {
_warnings.addElement(msg);
+ }
+
+ public void internalError() {
+ Exception e = new Exception();
+ e.printStackTrace();
+ addFatalError("Internal compiler error.\n"+
+ "Please report to [EMAIL PROTECTED]"+
+ "(include stack trace)");
+ }
+
+ public void notYetImplemented(String message) {
+ addWarning(new ErrorMsg("Unsupported: "+message));
// support for TrAX Error Listener
if (_errorListener != null ) {
- postWarningToListener(msg.toString());
+ postWarningToListener(message);
}
}
@@ -1046,6 +916,9 @@
}
}
+ /**
+ * Prints all compile-time warnings
+ */
public void printWarnings() {
if (_errorListener != null) return; //support for TrAX Error Listener
if (_warnings.size() > 0) {
@@ -1056,4 +929,196 @@
}
}
}
+
+ /**
+ * Suggested common error handler - not in use yet!!!
+ */
+ public void reportError(final int category, final ErrorMsg error) {
+ try {
+ switch (category) {
+ // Unexpected internal errors, such as null-ptr exceptions, etc.
+ // Immediately terminates compilation, no translet produced
+ case Constants.INTERNAL:
+ // XSLT elements that are not implemented and unsupported ext.
+ // Immediately terminates compilation, no translet produced
+ case Constants.UNSUPPORTED:
+ // Fatal error in the stylesheet input (parsing or content)
+ // Immediately terminates compilation, no translet produced
+ case Constants.FATAL:
+ // Other error in the stylesheet input (parsing or content)
+ // Does not terminate compilation, no translet produced
+ case Constants.ERROR:
+ // Other error in the stylesheet input (content errors only)
+ // Does not terminate compilation, a translet is produced
+ _errors.addElement(error);
+ if (_errorListener != null) {
+ final String msg = error.toString();
+ _errorListener.error(new TransformerException(msg));
+ }
+ case Constants.WARNING:
+ _warnings.addElement(error);
+ if (_errorListener != null) {
+ final String msg = error.toString();
+ _errorListener.warning(new TransformerException(msg));
+ }
+ break;
+ }
+ }
+ catch (TransformerException e) {
+ // If the error listener does not handle the exception then
+ // we're certainly not doing anything about it....
+ }
+ }
+
+ /************************ SAX2 ContentHandler INTERFACE
*****************/
+
+ private Stack _parentStack = null;
+ private Hashtable _prefixMapping = null;
+
+ /**
+ * SAX2: Receive notification of the beginning of a document.
+ */
+ public void startDocument() {
+ _root = null;
+ _target = null;
+ _prefixMapping = null;
+ _parentStack = new Stack();
+ }
+
+ /**
+ * SAX2: Receive notification of the end of a document.
+ */
+ public void endDocument() { }
+
+
+ /**
+ * SAX2: Begin the scope of a prefix-URI Namespace mapping.
+ * This has to be passed on to the symbol table!
+ */
+ public void startPrefixMapping(String prefix, String uri) {
+ if (_prefixMapping == null) _prefixMapping = new Hashtable();
+ _prefixMapping.put(prefix, uri);
+ //System.err.println("starting mapping for "+prefix+"="+uri);
+ }
+
+ /**
+ * SAX2: End the scope of a prefix-URI Namespace mapping.
+ * This has to be passed on to the symbol table!
+ */
+ public void endPrefixMapping(String prefix) {
+ //System.err.println("ending mapping for "+prefix);
+ }
+
+ /**
+ * SAX2: Receive notification of the beginning of an element.
+ * The parser may re-use the attribute list that we're passed so
+ * we clone the attributes in our own Attributes implementation
+ */
+ public void startElement(String uri, String localname,
+ String qname, Attributes attributes)
+ throws SAXException {
+
+ final int col = qname.lastIndexOf(':');
+ final String prefix;
+ if (col == -1)
+ prefix = null;
+ else
+ prefix = qname.substring(0, col);
+
+ SyntaxTreeNode element = makeInstance(uri, prefix, localname);
+ if (element == null) {
+ throw new SAXException("Error while parsing stylesheet.");
+ }
+
+ if (_root == null) {
+ _root = element;
+ }
+ else {
+ SyntaxTreeNode parent = (SyntaxTreeNode)_parentStack.peek();
+ parent.addElement(element);
+ element.setParent(parent);
+ }
+ element.setAttributes((Attributes)new AttributeList(attributes));
+ element.setPrefixMapping(_prefixMapping);
+
+ if (element instanceof Stylesheet) {
+ // Extension elements and excluded elements have to be
+ // handled at this point in order to correctly generate
+ // Fallback elements from <xsl:fallback>s.
+ getSymbolTable().setCurrentNode(element);
+ ((Stylesheet)element).excludeExtensionPrefixes(this);
+ }
+
+ _prefixMapping = null;
+ _parentStack.push(element);
+ }
+
+ /**
+ * SAX2: Receive notification of the end of an element.
+ */
+ public void endElement(String uri, String localname, String qname) {
+ _parentStack.pop();
+ }
+
+ /**
+ * SAX2: Receive notification of character data.
+ */
+ public void characters(char[] ch, int start, int length) {
+ String string = new String(ch, start, length);
+ SyntaxTreeNode parent = (SyntaxTreeNode)_parentStack.peek();
+
+ // If this text occurs within an <xsl:text> element we append it
+ // as-is to the existing text element
+ if (parent instanceof Text) {
+ if (string.length() > 0) {
+ ((Text)parent).setText(string);
+ }
+ }
+ // Ignore text nodes that occur directly under <xsl:stylesheet>
+ else if (parent instanceof Stylesheet) {
+
+ }
+ // Add it as a regular text node otherwise
+ else {
+ if (string.trim().length() > 0) {
+ parent.addElement(new Text(string));
+ }
+ }
+ }
+
+ /**
+ * SAX2: Receive notification of a processing instruction.
+ * These require special handling for stylesheet PIs.
+ */
+ public void processingInstruction(String name, String value) {
+ if ((_target == null) && (name.equals("xml-stylesheet"))) {
+ StringTokenizer tokens = new StringTokenizer(value);
+ while (tokens.hasMoreElements()) {
+ String token = (String)tokens.nextElement();
+ if (token.startsWith("href=")) {
+ _target = token.substring(5);
+ final int start = _target.indexOf('"');
+ final int stop = _target.lastIndexOf('"');
+ _target = _target.substring(start+1,stop);
+ return;
+ }
+ }
+ }
+ }
+
+ /**
+ * IGNORED - all ignorable whitespace is ignored
+ */
+ public void ignorableWhitespace(char[] ch, int start, int length) { }
+
+ /**
+ * IGNORED - we do not have to do anything with skipped entities
+ */
+ public void skippedEntity(String name) { }
+
+ /**
+ * IGNORED - we already know what the origin of the document is
+ */
+ public void setDocumentLocator(Locator locator) { }
+
}
1.3 +7 -8
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/ProcessingInstruction.java
Index: ProcessingInstruction.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/ProcessingInstruction.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ProcessingInstruction.java 2001/05/02 10:25:01 1.2
+++ ProcessingInstruction.java 2001/06/06 10:45:24 1.3
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: ProcessingInstruction.java,v 1.2 2001/05/02 10:25:01 morten Exp $
+ * @(#)$Id: ProcessingInstruction.java,v 1.3 2001/06/06 10:45:24 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -63,24 +63,23 @@
package org.apache.xalan.xsltc.compiler;
-import org.w3c.dom.*;
-
import org.apache.xalan.xsltc.compiler.util.Type;
import de.fub.bytecode.generic.*;
import org.apache.xalan.xsltc.compiler.util.*;
final class ProcessingInstruction extends Instruction {
+
private AttributeValue _name; // name treated as AVT (7.1.3)
- public void parseContents(Element element, Parser parser) {
- final String name =element.getAttribute("name");
+ public void parseContents(Parser parser) {
+ final String name = getAttribute("name");
_name = AttributeValue.create(this, name, parser);
if (name.equals("xml")) {
- reportError(element, parser, ErrorMsg.ILLEG_PI_ERR, "xml");
+ reportError(this, parser, ErrorMsg.ILLEG_PI_ERR, "xml");
}
- parseChildren(element, parser);
+ parseChildren(parser);
}
-
+
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
_name.typeCheck(stable);
typeCheckContents(stable);
1.2 +17 -3
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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- QName.java 2001/04/17 18:51:45 1.1
+++ QName.java 2001/06/06 10:45:25 1.2
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: QName.java,v 1.1 2001/04/17 18:51:45 sboag Exp $
+ * @(#)$Id: QName.java,v 1.2 2001/06/06 10:45:25 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -65,8 +65,8 @@
package org.apache.xalan.xsltc.compiler;
final class QName {
- private final String _prefix;
private final String _localname;
+ private String _prefix;
private String _namespace;
private String _stringRep;
private int _hashCode;
@@ -75,7 +75,13 @@
_namespace = namespace;
_prefix = prefix;
_localname = localname;
- _stringRep = namespace != null ? namespace+':'+localname : localname;
+ if ((namespace != null) && (!namespace.equals(Constants.EMPTYSTRING))) {
+ _stringRep = namespace+':'+localname;
+ }
+ else {
+ _stringRep = localname;
+ }
+
_hashCode = _stringRep.hashCode() + 19; // cached for speed
}
@@ -87,6 +93,10 @@
}
}
+ public void clearNamespace() {
+ _namespace = Constants.EMPTYSTRING;
+ }
+
public String toString() {
return _stringRep;
}
@@ -113,5 +123,9 @@
public int hashCode() {
return _hashCode;
+ }
+
+ public String dump() {
+ return(new String("QName: "+_namespace+"("+_prefix+"):"+_localname));
}
}
1.2 +4 -4
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/RelationalExpr.java
Index: RelationalExpr.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/RelationalExpr.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- RelationalExpr.java 2001/04/17 18:51:46 1.1
+++ RelationalExpr.java 2001/06/06 10:45:26 1.2
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: RelationalExpr.java,v 1.1 2001/04/17 18:51:46 sboag Exp $
+ * @(#)$Id: RelationalExpr.java,v 1.2 2001/06/06 10:45:26 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -101,6 +101,7 @@
}
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
+
Type tleft = _left.typeCheck(stable);
Type tright = _right.typeCheck(stable);
@@ -150,8 +151,7 @@
}
// Lookup the table of primops to find the best match
- final QName opName = getParser().getQName(Operators.names[_op]);
- MethodType ptype = lookupPrimop(stable, opName,
+ MethodType ptype = lookupPrimop(stable, Operators.names[_op],
new MethodType(Type.Void,
tleft, tright));
@@ -242,7 +242,7 @@
break;
default:
- getParser().internalError();
+ getParser().addFatalError("Unknown operator for relational
expression");
}
_falseList.add(il.append(bi)); // must be backpatched
1.3 +14 -11
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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Sort.java 2001/05/02 10:25:02 1.2
+++ Sort.java 2001/06/06 10:45:27 1.3
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: Sort.java,v 1.2 2001/05/02 10:25:02 morten Exp $
+ * @(#)$Id: Sort.java,v 1.3 2001/06/06 10:45:27 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -69,8 +69,6 @@
import java.util.NoSuchElementException;
import java.text.Collator;
-import org.w3c.dom.*;
-
import org.apache.xalan.xsltc.compiler.util.Type;
import org.apache.xalan.xsltc.compiler.util.ReferenceType;
@@ -83,6 +81,7 @@
import org.apache.xalan.xsltc.dom.*;
import org.apache.xalan.xsltc.compiler.util.*;
+
final class Sort extends Instruction {
private Expression _select;
private AttributeValue _order;
@@ -92,30 +91,33 @@
public String _lang;
public String _country;
+ private final static String EMPTYSTRING =
+ org.apache.xalan.xsltc.compiler.Constants.EMPTYSTRING;
+
/**
* Parse the attributes of the xsl:sort element
*/
- public void parseContents(Element element, Parser parser) {
+ public void parseContents(Parser parser) {
// Parse the select expression (node string value if no expression)
- _select = parser.parseExpression(this, element, "select", "string(.)");
+ _select = parser.parseExpression(this, "select", "string(.)");
// Get the sort order; default is 'ascending'
- String val = element.getAttribute("order");
+ String val = getAttribute("order");
_order = AttributeValue
.create(this, val.length() > 0 ? val : "ascending", parser);
// Get the case order; default is language dependant
- val = element.getAttribute("case-order");
+ val = getAttribute("case-order");
_caseOrder = AttributeValue
.create(this, val.length() > 0 ? val : "upper-first", parser);
// Get the sort data type; default is text
- val = element.getAttribute("data-type");
+ val = getAttribute("data-type");
_dataType = AttributeValue
.create(this, val.length() > 0 ? val : "text", parser);
// Get the language whose sort rules we will use; default is env.dep.
- if ((val = element.getAttribute("lang")) != null) {
+ if ((val = getAttribute("lang")) != null) {
try {
StringTokenizer st = new StringTokenizer(val,"-",false);
_lang = st.nextToken();
@@ -401,7 +403,7 @@
il.append(new NEW(cpg.addClass("java/util/Locale")));
il.append(DUP);
il.append(new PUSH(cpg, language));
- il.append(new PUSH(cpg, country != null ? country : ""));
+ il.append(new PUSH(cpg, (country != null ? country : EMPTYSTRING)));
il.append(new INVOKESPECIAL(initLocale));
// Use that Locale object to get the required Collator object
@@ -486,7 +488,8 @@
// Compile def. target for switch statement if key has multiple levels
if (levels > 1) {
// Append the default target - it will _NEVER_ be reached
- InstructionHandle defaultTarget = il.append(new PUSH(cpg,""));
+ InstructionHandle defaultTarget =
+ il.append(new PUSH(cpg, EMPTYSTRING));
il.insert(tblswitch,new TABLESWITCH(match, target, defaultTarget));
il.append(ARETURN);
}
1.6 +36 -103
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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Stylesheet.java 2001/05/21 14:46:12 1.5
+++ Stylesheet.java 2001/06/06 10:45:29 1.6
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: Stylesheet.java,v 1.5 2001/05/21 14:46:12 morten Exp $
+ * @(#)$Id: Stylesheet.java,v 1.6 2001/06/06 10:45:29 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -72,7 +72,6 @@
import javax.xml.parsers.*;
-import org.w3c.dom.*;
import org.xml.sax.*;
import org.apache.xalan.xsltc.compiler.util.Type;
@@ -90,7 +89,6 @@
public final class Stylesheet extends SyntaxTreeNode {
private String _version;
- private NamedNodeMap _stylesheetAttributes;
private QName _name;
private URL _url;
@@ -242,7 +240,7 @@
StringTokenizer tokens = new StringTokenizer(prefixes);
while (tokens.hasMoreTokens()) {
final String prefix = tokens.nextToken();
- final String uri = stable.lookupNamespace(prefix);
+ final String uri = lookupNamespace(prefix);
if (uri != null) {
_extensions.put(uri, prefix);
}
@@ -254,28 +252,28 @@
return (_extensions.get(uri) != null);
}
+ public void excludeExtensionPrefixes(Parser parser) {
+ final SymbolTable stable = parser.getSymbolTable();
+ final String excludePrefixes = getAttribute("exclude-result-prefixes");
+ final String extensionPrefixes =
+ getAttribute("extension-element-prefixes");
+ stable.excludeNamespaces(excludePrefixes);
+ stable.excludeNamespaces(extensionPrefixes);
+ extensionURI(extensionPrefixes, stable);
+ }
+
/**
* Parse the version and uri fields of the stylesheet and add an
* entry to the symbol table mapping the name <tt>%stylesheet%</tt>
* to an instance of this class.
*/
- public void parseContents(Element element, Parser parser) {
+ public void parseContents(Parser parser) {
final SymbolTable stable = parser.getSymbolTable();
- // Add namespace declarations to symbol table
- parser.pushNamespaces(element);
+ _version = getAttribute("version");
- _version = element.getAttribute("version");
- _stylesheetAttributes = element.getAttributes();
+ addPrefixMapping("xml", "xml"); // Make sure 'xml' maps to 'xml'
- final String excludePrefixes =
- element.getAttribute("exclude-result-prefixes");
- final String extensionPrefixes =
- element.getAttribute("extension-element-prefixes");
- stable.excludeNamespaces(excludePrefixes);
- stable.excludeNamespaces(extensionPrefixes);
- extensionURI(extensionPrefixes, stable);
-
// Report and error if more than one stylesheet defined
final Stylesheet sheet = stable.addStylesheet(_name, this);
if (sheet != null) {
@@ -292,101 +290,46 @@
if (_simplified) {
stable.excludeURI(XSLT_URI);
Template template = new Template();
- addElement(template);
- template.setParent(this);
- template.parseSimplified(element, parser);
+ template.parseSimplified(this, parser);
}
// Parse the children of this node
else {
- parseOwnChildren(element, parser);
+ parseOwnChildren(parser);
}
-
- // Remove namespaces from symbol table
- parser.popNamespaces(element);
}
/**
* Parse all the children of <tt>element</tt>.
* XSLT commands are recognized by the XSLT namespace
*/
- public final void parseOwnChildren(Element element, Parser parser) {
- final NodeList nl = element.getChildNodes();
- final int n = nl != null ? nl.getLength() : 0;
- Vector locals = null; // only create when needed
+ public final void parseOwnChildren(Parser parser) {
+
+ final Vector contents = getContents();
+ final int count = contents.size();
// We have to scan the stylesheet element's top-level elements for
// variables and/or parameters before we parse the other elements...
- for (int i = 0; i < n; i++) {
- final Node node = nl.item(i);
- if (node.getNodeType() == Node.ELEMENT_NODE) {
- final Element child = (Element)node;
- final String uri = child.getNamespaceURI();
- final String tag = child.getLocalName();
- if (uri.equals(XSLT_URI)) {
- if (tag.equals("param") || tag.equals("variable")) {
- parser.pushNamespaces(child);
- SyntaxTreeNode instance = parser.makeInstance(child);
- addElement(instance);
- instance.parseContents(child, parser);
- QName varOrParamName = updateScope(parser, instance);
- if (varOrParamName != null) {
- if (locals == null) {
- locals = new Vector(2);
- }
- locals.addElement(varOrParamName);
- }
- parser.popNamespaces(child);
- }
- }
+ for (int i=0; i<count; i++) {
+ SyntaxTreeNode child = (SyntaxTreeNode)contents.elementAt(i);
+ if ((child instanceof Param) || (child instanceof Variable)) {
+ parser.getSymbolTable().setCurrentNode(child);
+ child.parseContents(parser);
}
}
// Now go through all the other top-level elements...
- for (int i = 0; i < n; i++) {
- final Node node = nl.item(i);
- switch (node.getNodeType()) {
- case Node.ELEMENT_NODE:
-
- final Element child = (Element)node;
- final String uri = child.getNamespaceURI();
- final String tag = child.getLocalName();
- // Skip if this is a variable/parameter
- if (uri.equals(XSLT_URI)) {
- if (tag.equals("param") || tag.equals("variable")) break;
- }
-
- // Add namespace declarations to symbol table
- parser.pushNamespaces(child);
- final SyntaxTreeNode instance = parser.makeInstance(child);
- addElement(instance);
- if (!(instance instanceof Fallback))
- instance.parseContents(child, parser);
- // Remove namespace declarations from symbol table
- parser.popNamespaces(child);
- break;
-
- case Node.TEXT_NODE:
- // !!! need to take a look at whitespace stripping
- final String temp = node.getNodeValue();
- if (temp.trim().length() > 0) {
- addElement(new Text(temp));
- }
- break;
+ for (int i=0; i<count; i++) {
+ SyntaxTreeNode child = (SyntaxTreeNode)contents.elementAt(i);
+ if (!((child instanceof Param) || (child instanceof Variable))) {
+ parser.getSymbolTable().setCurrentNode(child);
+ child.parseContents(parser);
}
}
-
- // after the last element, remove any locals from scope
- if (locals != null) {
- final int nLocals = locals.size();
- for (int i = 0; i < nLocals; i++) {
- parser.removeVariable((QName)locals.elementAt(i));
- }
- }
}
public void processModes() {
if (_defaultMode == null)
- _defaultMode = new Mode(null, this, "");
+ _defaultMode = new Mode(null, this, Constants.EMPTYSTRING);
_defaultMode.processPatterns(_keys);
final Enumeration modes = _modes.elements();
while (modes.hasMoreElements()) {
@@ -407,7 +350,7 @@
public Mode getMode(QName modeName) {
if (modeName == null) {
if (_defaultMode == null) {
- _defaultMode = new Mode(null, this, "");
+ _defaultMode = new Mode(null, this, Constants.EMPTYSTRING);
}
return _defaultMode;
}
@@ -456,8 +399,7 @@
final ClassGenerator classGen =
new ClassGenerator(_className,
TRANSLET_CLASS,
- //getXSLTC().getFileName(),
- "",
+ Constants.EMPTYSTRING,
ACC_PUBLIC | ACC_SUPER,
null, this);
@@ -917,24 +859,15 @@
return _globals.size() - 1;
}
- // overridden from SyntaxTreeNode
- protected final QName updateScope(Parser parser, SyntaxTreeNode node) {
- return null;
- }
-
public void display(int indent) {
indent(indent);
Util.println("Stylesheet");
displayContents(indent + IndentIncrement);
}
+ // do we need this wrapper ?????
public String getNamespace(String prefix) {
- /* WRONG - WRONG - WRONG - namespace delcarations are not passed
- as attributes.
- final Node attr = _stylesheetAttributes.getNamedItem("xmlns:" + prefix);
- return attr != null ? attr.getNodeValue() : null;
- */
- return getParser().getSymbolTable().lookupNamespace(prefix);
+ return lookupNamespace(prefix);
}
public String getClassName() {
1.3 +26 -66
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/SymbolTable.java
Index: SymbolTable.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/SymbolTable.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SymbolTable.java 2001/05/01 13:16:19 1.2
+++ SymbolTable.java 2001/06/06 10:45:30 1.3
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: SymbolTable.java,v 1.2 2001/05/01 13:16:19 morten Exp $
+ * @(#)$Id: SymbolTable.java,v 1.3 2001/06/06 10:45:30 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -100,24 +100,29 @@
}
public Variable addVariable(Variable variable) {
- return (Variable)_variables.put(variable.getName(), variable);
+ final String name = variable.getName().getStringRep();
+ return (Variable)_variables.put(name, variable);
}
- public Variable lookupVariable(QName name) {
+ public Param addParam(Param parameter) {
+ final String name = parameter.getName().getStringRep();
+ return (Param)_variables.put(name, parameter);
+ }
+
+ public Variable lookupVariable(QName qname) {
+ final String name = qname.getStringRep();
final Object obj = _variables.get(name);
return obj instanceof Variable ? (Variable)obj : null;
}
- public Param addParam(Param parameter) {
- return (Param)_variables.put(parameter.getName(), parameter);
- }
-
- public Param lookupParam(QName name) {
+ public Param lookupParam(QName qname) {
+ final String name = qname.getStringRep();
final Object obj = _variables.get(name);
return obj instanceof Param ? (Param)obj : null;
}
- public SyntaxTreeNode lookupName(QName name) {
+ public SyntaxTreeNode lookupName(QName qname) {
+ final String name = qname.getStringRep();
return (SyntaxTreeNode)_variables.get(name);
}
@@ -134,7 +139,7 @@
* name clashes with user-defined names, the prefix <tt>PrimopPrefix</tt>
* is prepended.
*/
- public void addPrimop(QName name, MethodType mtype) {
+ public void addPrimop(String name, MethodType mtype) {
Vector methods = (Vector)_primops.get(name);
if (methods == null) {
_primops.put(name, methods = new Vector());
@@ -146,46 +151,11 @@
* Lookup a primitive operator or function in the symbol table by
* prepending the prefix <tt>PrimopPrefix</tt>.
*/
- public Vector lookupPrimop(QName name) {
+ public Vector lookupPrimop(String name) {
return (Vector)_primops.get(name);
}
/**
- * Insert a namespace declaration into the symbol table. To avoid name
- * clashes with user-defined names, the prefix <tt>NameSpacePrefix</tt>
- * is prepened.
- */
- public void pushNamespace(String prefix, String uri) {
- StringStack stack;
-
- if ((stack = (StringStack)_namespaces.get(prefix)) == null) {
- stack = new StringStack();
- _namespaces.put(prefix, stack);
- }
- stack.pushString(uri);
-
- if ((stack = (StringStack)_prefixes.get(uri)) == null) {
- stack = new StringStack();
- _prefixes.put(uri, stack);
- }
- stack.pushString(prefix);
- }
-
- /**
- * Remove a namespace declaration from the symbol table when its scope
- * has ended.
- */
- public void popNamespace(String prefix) {
- StringStack stack;
- if ((stack = (StringStack)_namespaces.get(prefix)) != null) {
- final String uri = stack.popString();
- if ((stack = (StringStack)_prefixes.get(uri)) != null) {
- stack.popString();
- }
- }
- }
-
- /**
* This is used for xsl:attribute elements that have a "namespace"
* attribute that is currently not defined using xmlns:
*/
@@ -197,18 +167,16 @@
/**
* Use a namespace prefix to lookup a namespace URI
*/
- public String lookupNamespace(String prefix) {
- if (prefix == null) return null;
- final StringStack stack = (StringStack)_namespaces.get(prefix);
- return stack != null && !stack.isEmpty() ? stack.peekString() : null;
+ private SyntaxTreeNode _current = null;
+ public void setCurrentNode(SyntaxTreeNode node) {
+ _current = node;
}
- /**
- * Use a namespace URI to lookup a namespace prefix
- */
- public String lookupPrefix(String uri) {
- final StringStack stack = (StringStack)_prefixes.get(uri);
- return stack != null && !stack.isEmpty() ? stack.peekString() : null;
+ public String lookupNamespace(String prefix) {
+ if (_current != null)
+ return(_current.lookupNamespace(prefix));
+ else
+ return(Constants.EMPTYSTRING);
}
/**
@@ -226,14 +194,6 @@
}
/**
- * Returns a list of the prefixes of all namespaces that are currently
- * in scope (used when outputting literal result elements).
- */
- public Enumeration getInScopeNamespaces() {
- return(Enumeration)_namespaces.keys();
- }
-
- /**
*
*/
public void excludeURI(String uri) {
@@ -256,7 +216,7 @@
final String prefix = tokens.nextToken();
final String uri;
if (prefix.equals("#default"))
- uri = lookupNamespace("");
+ uri = lookupNamespace(Constants.EMPTYSTRING);
else
uri = lookupNamespace(prefix);
if (uri != null) excludeURI(uri);
@@ -285,7 +245,7 @@
final String prefix = tokens.nextToken();
final String uri;
if (prefix.equals("#default"))
- uri = lookupNamespace("");
+ uri = lookupNamespace(Constants.EMPTYSTRING);
else
uri = lookupNamespace(prefix);
Integer refcnt = (Integer)_excludedURI.get(uri);
1.3 +148 -73
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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SyntaxTreeNode.java 2001/05/02 10:25:05 1.2
+++ SyntaxTreeNode.java 2001/06/06 10:45:30 1.3
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: SyntaxTreeNode.java,v 1.2 2001/05/02 10:25:05 morten Exp $
+ * @(#)$Id: SyntaxTreeNode.java,v 1.3 2001/06/06 10:45:30 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -59,6 +59,7 @@
* @author Jacek Ambroziak
* @author Santiago Pericas-Geertsen
* @author G. Todd Miller
+ * @author Morten Jorensen
*
*/
@@ -66,51 +67,146 @@
import java.util.Vector;
import java.util.Enumeration;
+import java.util.Hashtable;
import javax.xml.parsers.*;
-import org.w3c.dom.*;
import org.xml.sax.*;
import org.apache.xalan.xsltc.compiler.util.*;
public abstract class SyntaxTreeNode implements Constants {
+
+ // Reference to the AST parser
private Parser _parser;
- private final int _line; // line number in input
- private final Vector _contents = new Vector(2);
- private static final int NSpaces = 64;
- private static final char[] Spaces = new char[NSpaces];
- protected static final int IndentIncrement = 4;
- public static final SyntaxTreeNode Dummy = new AbsolutePathPattern(null);
+ // This node's line number in the input file (not obtainable!!!!)
+ private final int _line;
- /**
- * A vector of references to all the parameters defined in
- * this node.
- */
- private Vector _params;
+ // Reference to this node's parent node
+ private SyntaxTreeNode _parent;
+ // Contains all child nodes of this node
+ private final Vector _contents = new Vector(2);
- /**
- * A vector of references to all the local variables defined
- * in this node.
- */
+ // All parameters defined in this AST node
+ private Vector _params;
+ // All variables defined in this AST node
private Vector _vars;
- private SyntaxTreeNode _parent;
+ // The QName of this element (contains uri, prefix and localname)
+ protected QName _qname;
+ // The attributes (if any) of this element
+ protected Attributes _attributes = null;
+ // The namespace declarations (if any) of this element
+ private Hashtable _prefixMapping = null;
- static {
- for (int i = 0; i < NSpaces; i++)
- Spaces[i] = ' ';
- }
+ // Sentinel
+ public static final SyntaxTreeNode Dummy = new AbsolutePathPattern(null);
+
+ // These two are used for indenting nodes in the AST (debug output)
+ private static final char[] _spaces =
+ " ".toCharArray();
+ protected static final int IndentIncrement = 4;
public SyntaxTreeNode() {
_line = 0;
+ _qname = null;
}
public SyntaxTreeNode(int line) {
_line = line;
+ _qname = null;
}
+ public SyntaxTreeNode(String uri, String prefix, String localname) {
+ _line = 0;
+ setQName(uri, prefix, localname);
+ }
+
+ public void setQName(QName qname) {
+ _qname = qname;
+ }
+
+ public void setQName(String uri, String prefix, String localname) {
+ _qname = new QName(uri, prefix, localname);
+ }
+
+ public QName getQName() {
+ return(_qname);
+ }
+
+ public void setAttributes(Attributes attributes) {
+ _attributes = attributes;
+ }
+
+ public String getAttribute(String qname) {
+ if (_attributes == null)
+ return(Constants.EMPTYSTRING);
+ final String value = _attributes.getValue(qname);
+ if (value == null)
+ return(Constants.EMPTYSTRING);
+ else
+ return(value);
+ }
+
+ public Attributes getAttributes() {
+ return(_attributes);
+ }
+
+ public void setPrefixMapping(Hashtable mapping) {
+ _prefixMapping = mapping;
+ }
+
+ public Hashtable getPrefixMapping() {
+ return _prefixMapping;
+ }
+
+ public void addPrefixMapping(String prefix, String uri) {
+ if (_prefixMapping == null)
+ _prefixMapping = new Hashtable();
+ _prefixMapping.put(prefix, uri);
+ }
+
+ public String lookupNamespace(String prefix) {
+ // Initialise the output (default is 'null' for undefined)
+ String uri = null;
+
+ // First look up the prefix/uri mapping in our own hashtable...
+ if (_prefixMapping != null)
+ uri = (String)_prefixMapping.get(prefix);
+ // ... but if we can't find it there we ask our parent for the mapping
+ if ((uri == null) && (_parent != null)) {
+ uri = _parent.lookupNamespace(prefix);
+ if ((prefix == Constants.EMPTYSTRING) && (uri == null))
+ uri = Constants.EMPTYSTRING;
+ }
+ // ... and then we return whatever URI we've got.
+ return(uri);
+ }
+
+ public String lookupPrefix(String uri) {
+ // Initialise the output (default is 'null' for undefined)
+ String prefix = null;
+
+ // First look up the prefix/uri mapping in our own hashtable...
+ if ((_prefixMapping != null) &&
+ (_prefixMapping.contains(uri))) {
+ Enumeration prefixes = _prefixMapping.keys();
+ while (prefixes.hasMoreElements()) {
+ prefix = (String)prefixes.nextElement();
+ String mapsTo = (String)_prefixMapping.get(prefix);
+ if (mapsTo.equals(uri)) return(prefix);
+ }
+ }
+ // ... but if we can't find it there we ask our parent for the mapping
+ else if (_parent != null) {
+ prefix = _parent.lookupPrefix(uri);
+ if ((uri == Constants.EMPTYSTRING) && (prefix == null))
+ prefix = Constants.EMPTYSTRING;
+ }
+ return(prefix);
+ }
+
public void setParser(Parser parser) {
_parser = parser;
}
@@ -183,54 +279,35 @@
* This method is normally overriden by subclasses.
* By default, it parses all the children of <tt>element</tt>.
*/
- public void parseContents(Element element, Parser parser) {
- parseChildren(element, parser);
+ public void parseContents(Parser parser) {
+ parseChildren(parser);
}
/**
* Parse all the children of <tt>element</tt>.
* XSLT commands are recognized by the XSLT namespace
*/
- public final void parseChildren(Element element, Parser parser) {
- final NodeList nl = element.getChildNodes();
- final int n = nl != null ? nl.getLength() : 0;
- Vector locals = null; // only create when needed
+ public final void parseChildren(Parser parser) {
- for (int i = 0; i < n; i++) {
- final Node node = nl.item(i);
- switch (node.getNodeType()) {
- case Node.ELEMENT_NODE:
-
- final Element child = (Element)node;
- // Add namespace declarations to symbol table
- parser.pushNamespaces(child);
- final SyntaxTreeNode instance = parser.makeInstance(child);
- addElement(instance);
- if (!(instance instanceof Fallback))
- instance.parseContents(child, parser);
-
- // if variable or parameter, add it to scope
- final QName varOrParamName = updateScope(parser, instance);
- if (varOrParamName != null) {
- if (locals == null) {
- locals = new Vector(2);
- }
- locals.addElement(varOrParamName);
- }
- // Remove namespace declarations from symbol table
- parser.popNamespaces(child);
- break;
-
- case Node.TEXT_NODE:
- // !!! need to take a look at whitespace stripping
- final String temp = node.getNodeValue();
- if (temp.trim().length() > 0) {
- addElement(new Text(temp));
+ Vector locals = null; // only create when needed
+
+ final int count = _contents.size();
+ for (int i=0; i<count; i++) {
+ SyntaxTreeNode child = (SyntaxTreeNode)_contents.elementAt(i);
+ parser.getSymbolTable().setCurrentNode(child);
+ child.parseContents(parser);
+ // if variable or parameter, add it to scope
+ final QName varOrParamName = updateScope(parser, child);
+ if (varOrParamName != null) {
+ if (locals == null) {
+ locals = new Vector(2);
}
- break;
+ locals.addElement(varOrParamName);
}
}
-
+
+ parser.getSymbolTable().setCurrentNode(this);
+
// after the last element, remove any locals from scope
if (locals != null) {
final int nLocals = locals.size();
@@ -240,9 +317,10 @@
}
}
- /** if node represents a variable or a parameter,
- add it to the current scope and return name of the var/par
- */
+ /**
+ * Add a node to the current scope and return name of a variable or
+ * parameter if the node represents a variable or a parameter.
+ */
protected QName updateScope(Parser parser, SyntaxTreeNode node) {
if (node instanceof Variable) {
final Variable var = (Variable)node;
@@ -363,26 +441,23 @@
}
protected final void indent(int indent) {
- System.out.print(new String(Spaces, 0, indent));
+ System.out.print(new String(_spaces, 0, indent));
}
public final int getLineNumber() {
return _line;
}
- protected static void reportError(Element element, Parser parser,
- int errorCode, String errMsg) {
- //final int lineNumber = ((Integer)element.getUserObject()).intValue();
- final ErrorMsg error = new ErrorMsg(errorCode, -1 /*lineNumber*/,
errMsg);
+ protected static void reportError(SyntaxTreeNode element, Parser parser,
+ int errorCode, String msg) {
+ final ErrorMsg error = new ErrorMsg(errorCode, 0 /*lineNumber*/, msg);
parser.addError(error);
}
- protected static void reportWarning(Element element, Parser parser,
- int errorCode, String errMsg) {
- //final int lineNumber = ((Integer)element.getUserObject()).intValue();
- final ErrorMsg error = new ErrorMsg(errorCode, -1 /*lineNumber*/,
errMsg);
+ protected static void reportWarning(SyntaxTreeNode element, Parser
parser,
+ int errorCode, String msg) {
+ final ErrorMsg error = new ErrorMsg(errorCode, 0 /*lineNumber*/, msg);
parser.addWarning(error);
}
-
}
1.5 +35 -20
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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Template.java 2001/05/17 11:07:47 1.4
+++ Template.java 2001/06/06 10:45:32 1.5
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: Template.java,v 1.4 2001/05/17 11:07:47 morten Exp $
+ * @(#)$Id: Template.java,v 1.5 2001/06/06 10:45:32 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -68,8 +68,6 @@
import java.util.Enumeration;
import java.util.Hashtable;
-import org.w3c.dom.*;
-
import org.apache.xalan.xsltc.compiler.util.Type;
import de.fub.bytecode.generic.*;
@@ -207,12 +205,12 @@
return _stylesheet;
}
- public void parseContents(Element element, Parser parser) {
+ public void parseContents(Parser parser) {
- final String name = element.getAttribute("name");
- final String mode = element.getAttribute("mode");
- final String match = element.getAttribute("match");
- final String priority = element.getAttribute("priority");
+ final String name = getAttribute("name");
+ final String mode = getAttribute("mode");
+ final String match = getAttribute("match");
+ final String priority = getAttribute("priority");
_stylesheet = super.getStylesheet();
@@ -225,7 +223,7 @@
}
if (match.length() > 0) {
- _pattern = parser.parsePattern(this, element, "match");
+ _pattern = parser.parsePattern(this, "match", null);
}
if (priority.length() > 0) {
@@ -242,31 +240,48 @@
if (_name != null) {
Template other = parser.getSymbolTable().addTemplate(this);
if (!resolveNamedTemplates(other, parser)) {
- parser.addError(new ErrorMsg(ErrorMsg.TMPREDEF_ERR,
- _name, this));
+ parser.addError(new ErrorMsg(ErrorMsg.TMPREDEF_ERR,_name,this));
}
}
parser.setTemplate(this); // set current template
- parseChildren(element, parser);
+ parseChildren(parser);
parser.setTemplate(null); // clear template
}
- public void parseSimplified(Element element, Parser parser) {
+ /**
+ * When the parser realises that it is dealign with a simplified
stylesheet
+ * it will create an empty Stylesheet object with the root element of the
+ * stylesheet (a LiteralElement object) as its only child. The Stylesheet
+ * object will then create this Template object and invoke this method to
+ * force some specific behaviour. What we need to do is:
+ * o) create a pattern matching on the root node
+ * o) add the LRE root node (the only child of the Stylesheet) as our
+ * only child node
+ * o) set the empty Stylesheet as our parent
+ * o) set this template as the Stylesheet's only child
+ */
+ public void parseSimplified(Stylesheet stylesheet, Parser parser) {
- _stylesheet = super.getStylesheet();
+ _stylesheet = stylesheet;
+ setParent(stylesheet);
_name = null;
_mode = null;
_priority = Double.NaN;
_pattern = parser.parsePattern(this, "/");
- parser.setTemplate(this); // set current template
- LiteralElement lre = new LiteralElement();
- addElement(lre);
- lre.setParent(this);
- lre.parseContents(element, parser);
- parser.setTemplate(null); // clear template
+ final Vector contents = _stylesheet.getContents();
+ final SyntaxTreeNode root = (SyntaxTreeNode)contents.elementAt(0);
+
+ if (root instanceof LiteralElement) {
+ addElement(root);
+ root.setParent(this);
+ contents.set(0, this);
+ parser.setTemplate(this);
+ root.parseContents(parser);
+ parser.setTemplate(null);
+ }
}
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
1.4 +13 -12
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Text.java
Index: Text.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Text.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Text.java 2001/05/23 15:22:59 1.3
+++ Text.java 2001/06/06 10:45:33 1.4
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: Text.java,v 1.3 2001/05/23 15:22:59 tmiller Exp $
+ * @(#)$Id: Text.java,v 1.4 2001/06/06 10:45:33 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -58,12 +58,13 @@
*
* @author Jacek Ambroziak
* @author Santiago Pericas-Geertsen
+ * @author Morten Jorgensen
*
*/
package org.apache.xalan.xsltc.compiler;
-import org.w3c.dom.*;
+import java.util.Vector;
import org.apache.xalan.xsltc.compiler.util.Type;
import de.fub.bytecode.generic.*;
@@ -83,6 +84,13 @@
return _text;
}
+ public void setText(String text) {
+ if (_text == null)
+ _text = text;
+ else
+ _text = _text + text; // compliation phase, so OK (well, maybe not)
+ }
+
public void display(int indent) {
indent(indent);
Util.println("Text");
@@ -90,18 +98,11 @@
Util.println(_text);
}
- public void parseContents(Element element, Parser parser) {
- final String str = element.getAttribute("disable-output-escaping");
+ public void parseContents(Parser parser) {
+ final String str = getAttribute("disable-output-escaping");
if ((str != null) && (str.equals("yes"))) {
_escaping = false;
}
- final NodeList nl = element.getChildNodes();
- for (int i = 0; i < nl.getLength(); i++) {
- final Node node = nl.item(i);
- if (node.getNodeType() == Node.TEXT_NODE) {
- _text = node.getNodeValue();
- }
- }
}
public boolean contextDependent() {
@@ -141,6 +142,6 @@
il.append(new INVOKEINTERFACE(esc, 2));
il.append(POP);
}
-
+ translateContents(classGen, methodGen);
}
}
1.3 +4 -7
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/TransletOutput.java
Index: TransletOutput.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/TransletOutput.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TransletOutput.java 2001/05/02 10:25:10 1.2
+++ TransletOutput.java 2001/06/06 10:45:35 1.3
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: TransletOutput.java,v 1.2 2001/05/02 10:25:10 morten Exp $
+ * @(#)$Id: TransletOutput.java,v 1.3 2001/06/06 10:45:35 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -63,8 +63,6 @@
package org.apache.xalan.xsltc.compiler;
-import org.w3c.dom.*;
-
import org.apache.xalan.xsltc.compiler.util.Type;
import de.fub.bytecode.generic.*;
import org.apache.xalan.xsltc.compiler.util.*;
@@ -77,10 +75,9 @@
Util.println("TransletOutput " + _port);
}
- public void parseContents(Element element, Parser parser) {
- _port = AttributeValue.create(this,
- element.getAttribute("port"), parser);
- parseChildren(element, parser);
+ public void parseContents(Parser parser) {
+ _port = AttributeValue.create(this, getAttribute("port"), parser);
+ parseChildren(parser);
}
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
1.2 +2 -3
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/UnaryOpExpr.java
Index: UnaryOpExpr.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/UnaryOpExpr.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- UnaryOpExpr.java 2001/04/17 18:51:50 1.1
+++ UnaryOpExpr.java 2001/06/06 10:45:36 1.2
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: UnaryOpExpr.java,v 1.1 2001/04/17 18:51:50 sboag Exp $
+ * @(#)$Id: UnaryOpExpr.java,v 1.2 2001/06/06 10:45:36 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -81,8 +81,7 @@
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
final Type tleft = _left.typeCheck(stable);
- final MethodType ptype = lookupPrimop(stable,
- getParser().getQName("u-"),
+ final MethodType ptype = lookupPrimop(stable, "u-",
new MethodType(Type.Void,
tleft));
1.3 +6 -10
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/ValueOf.java
Index: ValueOf.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/ValueOf.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ValueOf.java 2001/05/02 10:25:13 1.2
+++ ValueOf.java 2001/06/06 10:45:37 1.3
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: ValueOf.java,v 1.2 2001/05/02 10:25:13 morten Exp $
+ * @(#)$Id: ValueOf.java,v 1.3 2001/06/06 10:45:37 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -64,8 +64,6 @@
package org.apache.xalan.xsltc.compiler;
-import org.w3c.dom.*;
-
import de.fub.bytecode.generic.*;
import org.apache.xalan.xsltc.compiler.util.Type;
@@ -83,19 +81,17 @@
Util.println("select " + _select.toString());
}
- public void parseContents(Element element, Parser parser) {
- _select = parser.parseExpression(this, element, "select");
+ public void parseContents(Parser parser) {
+ _select = parser.parseExpression(this, "select", null);
// make sure required attribute(s) have been set
if (_select.isDummy()) {
- reportError(element, parser, ErrorMsg.NREQATTR_ERR, "select");
+ reportError(this, parser, ErrorMsg.NREQATTR_ERR, "select");
return;
}
- final String str = element.getAttribute("disable-output-escaping");
- if ((str != null) && (str.equals("yes"))) {
- _escaping = false;
- }
+ final String str = getAttribute("disable-output-escaping");
+ if ((str != null) && (str.equals("yes"))) _escaping = false;
}
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
1.4 +10 -12
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.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Variable.java 2001/05/17 11:05:38 1.3
+++ Variable.java 2001/06/06 10:45:39 1.4
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: Variable.java,v 1.3 2001/05/17 11:05:38 morten Exp $
+ * @(#)$Id: Variable.java,v 1.4 2001/06/06 10:45:39 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -66,8 +66,6 @@
import java.util.Vector;
-import org.w3c.dom.*;
-
import org.apache.xalan.xsltc.compiler.util.Type;
import de.fub.bytecode.generic.Instruction;
import de.fub.bytecode.generic.*;
@@ -181,14 +179,14 @@
return _stackIndex;
}
- public void parseContents(Element element, Parser parser) {
+ public void parseContents(Parser parser) {
// parse attributes name and select (if present)
- final String name = element.getAttribute("name");
+ final String name = getAttribute("name");
if (name.length() > 0) {
_name = parser.getQName(name);
}
else {
- reportError(element, parser, ErrorMsg.NREQATTR_ERR, "name");
+ reportError(this, parser, ErrorMsg.NREQATTR_ERR, "name");
}
// check whether variable/param of the same name is already in scope
@@ -197,13 +195,13 @@
parser.addError(error);
}
- final String select = element.getAttribute("select");
+ final String select = getAttribute("select");
if (select.length() > 0) {
- _select = parser.parseExpression(this, element, "select");
+ _select = parser.parseExpression(this, "select", null);
}
// Children must be parsed first -> static scoping
- parseChildren(element, parser);
+ parseChildren(parser);
// Add a ref to this var to its enclosing construct
SyntaxTreeNode parent = getParent();
@@ -218,7 +216,7 @@
final int them = var.getImportPrecedence();
// It is an error if the two have the same import precedence
if (us == them) {
- ErrorMsg error =
+ ErrorMsg error =
new ErrorMsg(ErrorMsg.VARREDEF_ERR, _name, this);
parser.addError(error);
}
@@ -381,7 +379,7 @@
}
else {
// If no select and no contents push the empty string
- il.append(new PUSH(cpg, ""));
+ il.append(new PUSH(cpg, Constants.EMPTYSTRING));
}
}
else {
@@ -443,7 +441,7 @@
}
else {
// If no select and no contents push the empty string
- il.append(new PUSH(cpg, ""));
+ il.append(new PUSH(cpg, Constants.EMPTYSTRING));
}
}
else {
1.3 +5 -7
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/When.java
Index: When.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/When.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- When.java 2001/05/02 10:25:16 1.2
+++ When.java 2001/06/06 10:45:40 1.3
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: When.java,v 1.2 2001/05/02 10:25:16 morten Exp $
+ * @(#)$Id: When.java,v 1.3 2001/06/06 10:45:40 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -63,8 +63,6 @@
package org.apache.xalan.xsltc.compiler;
-import org.w3c.dom.*;
-
import org.apache.xalan.xsltc.compiler.util.*;
final class When extends Instruction {
@@ -83,21 +81,21 @@
return _test;
}
- public void parseContents(Element element, Parser parser) {
+ public void parseContents(Parser parser) {
boolean ignore = false;
- _test = parser.parseExpression(this, element, "test");
+ _test = parser.parseExpression(this, "test", null);
if (_test instanceof ElementAvailableCall) {
ElementAvailableCall call = (ElementAvailableCall)_test;
ignore = !call.getResult();
}
if (!ignore) {
- parseChildren(element, parser);
+ parseChildren(parser);
}
// make sure required attribute(s) have been set
if (_test.isDummy()) {
- reportError(element, parser, ErrorMsg.NREQATTR_ERR, "test");
+ reportError(this, parser, ErrorMsg.NREQATTR_ERR, "test");
return;
}
}
1.4 +11 -13
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.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Whitespace.java 2001/05/22 17:26:15 1.3
+++ Whitespace.java 2001/06/06 10:45:41 1.4
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: Whitespace.java,v 1.3 2001/05/22 17:26:15 morten Exp $
+ * @(#)$Id: Whitespace.java,v 1.4 2001/06/06 10:45:41 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -65,8 +65,6 @@
import java.util.Vector;
import java.util.StringTokenizer;
-import org.w3c.dom.*;
-
import org.apache.xalan.xsltc.compiler.util.Type;
import org.apache.xalan.xsltc.compiler.util.ReferenceType;
@@ -118,7 +116,7 @@
_element = element.substring(colon+1,element.length());
}
else {
- _namespace = "";
+ _namespace = Constants.EMPTYSTRING;
_element = element;
}
@@ -127,7 +125,7 @@
// Get the strip/preserve type; either "NS:EL", "NS:*" or "*"
if (_element.equals("*")) {
- if (_namespace.equals("")) {
+ if (_namespace == Constants.EMPTYSTRING) {
_type = RULE_ALL; // Strip/preserve _all_ elements
_priority += 2; // Lowest priority
}
@@ -161,24 +159,24 @@
* Parse the attributes of the xsl:strip/preserve-space element.
* The element should have not contents (ignored if any).
*/
- public void parseContents(Element element, Parser parser) {
+ public void parseContents(Parser parser) {
// Determine if this is an xsl:strip- or preserve-space element
- _action = element.getTagName().endsWith("strip-space")
+ _action = _qname.getLocalPart().endsWith("strip-space")
? STRIP_SPACE : PRESERVE_SPACE;
// Determine the import precedence
_importPrecedence = parser.getCurrentImportPrecedence();
// Get the list of elements to strip/preserve
- _elementList = element.getAttribute("elements");
+ _elementList = getAttribute("elements");
if (_elementList == null || _elementList.length() == 0) {
- reportError(element, parser, ErrorMsg.NREQATTR_ERR, "elements");
+ reportError(this, parser, ErrorMsg.NREQATTR_ERR, "elements");
return;
}
final SymbolTable stable = parser.getSymbolTable();
StringTokenizer list = new StringTokenizer(_elementList);
- StringBuffer elements = new StringBuffer("");
+ StringBuffer elements = new StringBuffer(Constants.EMPTYSTRING);
while (list.hasMoreElements()) {
String token = list.nextToken();
@@ -190,10 +188,10 @@
prefix = token.substring(0,col);
}
else {
- prefix = "";
+ prefix = Constants.EMPTYSTRING;
}
- namespace = stable.lookupNamespace(prefix);
+ namespace = lookupNamespace(prefix);
if (namespace != null)
elements.append(namespace+":"+
token.substring(col+1,token.length()));
@@ -432,7 +430,7 @@
// Create the QName for the element
final Parser parser = classGen.getParser();
QName qname;
- if (rule.getNamespace() != "" )
+ if (rule.getNamespace() != Constants.EMPTYSTRING )
qname = parser.getQName(rule.getNamespace(), null,
rule.getElement());
else
1.3 +7 -9
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/WithParam.java
Index: WithParam.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/WithParam.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- WithParam.java 2001/05/02 10:25:18 1.2
+++ WithParam.java 2001/06/06 10:45:42 1.3
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: WithParam.java,v 1.2 2001/05/02 10:25:18 morten Exp $
+ * @(#)$Id: WithParam.java,v 1.3 2001/06/06 10:45:42 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -63,8 +63,6 @@
package org.apache.xalan.xsltc.compiler;
-import org.w3c.dom.*;
-
import org.apache.xalan.xsltc.compiler.util.Type;
import org.apache.xalan.xsltc.compiler.util.ReferenceType;
import de.fub.bytecode.generic.*;
@@ -84,21 +82,21 @@
displayContents(indent + IndentIncrement);
}
- public void parseContents(Element element, Parser parser) {
- final String name = element.getAttribute("name");
+ public void parseContents(Parser parser) {
+ final String name = getAttribute("name");
if (name.length() > 0) {
_name = parser.getQName(name);
}
else {
- reportError(element, parser, ErrorMsg.NREQATTR_ERR, "name");
+ reportError(this, parser, ErrorMsg.NREQATTR_ERR, "name");
}
- final String select = element.getAttribute("select");
+ final String select = getAttribute("select");
if (select.length() > 0) {
- _select = parser.parseExpression(this, element, "select");
+ _select = parser.parseExpression(this, "select", null);
}
- parseChildren(element, parser);
+ parseChildren(parser);
}
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
1.5 +28 -39
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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- XSLTC.java 2001/06/05 13:01:24 1.4
+++ XSLTC.java 2001/06/06 10:45:44 1.5
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: XSLTC.java,v 1.4 2001/06/05 13:01:24 tmiller Exp $
+ * @(#)$Id: XSLTC.java,v 1.5 2001/06/06 10:45:44 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -79,13 +79,11 @@
import java.net.MalformedURLException;
import java.util.jar.*;
-import javax.xml.parsers.*;
+import org.xml.sax.*;
+import javax.xml.parsers.*;
import javax.xml.transform.ErrorListener;
-import org.w3c.dom.Element;
-import org.xml.sax.*;
-
import org.apache.xalan.xsltc.compiler.util.*;
import org.apache.xalan.xsltc.util.getopt.*;
import org.apache.xalan.xsltc.DOM;
@@ -185,41 +183,34 @@
* is successful. - 'false' otherwise. ErrorListener arg (may be null)
* added to support TrAX API.
*/
- public boolean compile(URL stylesheet, ErrorListener elistener) {
+ public boolean compile(URL url, ErrorListener elistener) {
if (elistener != null) {
_parser.setErrorListener(elistener);
}
try {
reset();
- final String name = stylesheet.getFile();
+ final String name = url.getFile();
if (_className == null) {
final String baseName = Util.baseName(name);
setClassName(Util.toJavaName(Util.noExtName(baseName)));
}
- final Element stylesheetElement = _parser.parse(stylesheet);
+ // Get the root node of the abstract syntax tree
+ final SyntaxTreeNode element = _parser.parse(url);
+ // Process any error and/or warning messages
+ _parser.printWarnings();
if (_parser.errorsFound()) {
_parser.printErrors();
return false;
}
-
- _parser.printWarnings();
- /* REMOVED: The first element is not necessarily in the XSL
- namespace if we're compiling a simplified stylesheet
- final String namespace = stylesheetElement.getNamespace();
- // Does it start with an element of the xsl namespace ?
- if (namespace != null && !namespace.equals(Constants.XSLT_URI)) {
- _parser.addError(new ErrorMsg(ErrorMsg.STYORTRA_ERR));
- }
- */
- if ((!_parser.errorsFound()) && (stylesheetElement != null)) {
- _stylesheet = _parser.makeStylesheet(stylesheetElement);
- _stylesheet.setURL(stylesheet);
+ if ((!_parser.errorsFound()) && (element != null)) {
+ _stylesheet = _parser.makeStylesheet(element);
+ _stylesheet.setURL(url);
// This is the top level stylesheet - it has no parent
_stylesheet.setParentStylesheet(null);
_parser.setCurrentStylesheet(_stylesheet);
- _parser.createAST(stylesheetElement, _stylesheet);
+ _parser.createAST(_stylesheet);
if (_stylesheet != null && _parser.errorsFound() == false) {
_stylesheet.setMultiDocument(_multiDocument);
_stylesheet.translate();
@@ -235,6 +226,7 @@
return !_parser.errorsFound();
}
catch (CompilerException e) {
+ e.printStackTrace();
_parser.addError(new ErrorMsg(e.getMessage()));
_parser.printErrors();
return false;
@@ -280,6 +272,11 @@
private void setDebug(boolean debug) {
_debug = debug;
}
+
+
+ public boolean debug() {
+ return _debug;
+ }
private void setDestDirectory(String dstDirName) throws
CompilerException {
final File dir = new File(dstDirName);
@@ -305,6 +302,11 @@
return _stylesheet;
}
+ public void setStylesheet(Stylesheet stylesheet) {
+ if (_stylesheet == null)
+ _stylesheet = stylesheet;
+ }
+
private File getOutputFile(String className) {
return new File(_dumpDir != null ? _dumpDir : _destDir,
classFileName(className));
@@ -314,10 +316,6 @@
return className.replace('.', File.separatorChar) + ".class";
}
- public boolean debug() {
- return _debug;
- }
-
public Vector getNamesIndex() {
return _namesIndex;
}
@@ -334,7 +332,6 @@
Integer code = (Integer)_attributes.get(name);
if (code == null) {
_attributes.put(name, code = new Integer(_nextGType++));
- //_namesIndex.addElement("@" + name.toString());
final String uri = name.getNamespace();
final String local = "@"+name.getLocalPart();
if ((uri != null) && (!uri.equals("")))
@@ -380,22 +377,11 @@
}
/**
- * Aborts the execution of the compiler as a result of an
- * unrecoverable error.
- */
- public void internalError() {
- System.err.println("Internal error");
- if (debug()) {
- _parser.errorsFound(); // print stack
- }
- doSystemExit(1); throw new RuntimeException("System.exit(1) here!");
- }
-
- /**
* Aborts the execution of the compiler if something found in the source
* file can't be compiled. It also prints which feature is not
implemented
* if specified.
*/
+ /*
public void notYetImplemented(String feature) {
System.err.println("'"+feature+"' is not supported by XSLTC.");
if (debug()) {
@@ -403,12 +389,14 @@
}
doSystemExit(1); throw new RuntimeException("System.exit(1) here!");
}
+ */
/**
* Aborts the execution of the compiler if something found in the source
* file can't be compiled. It also prints which feature is not
implemented
* if specified.
*/
+ /*
public void extensionNotSupported(String feature) {
System.err.println("Extension element '"+feature+
"' is not supported by XSLTC.");
@@ -417,6 +405,7 @@
}
doSystemExit(1); throw new RuntimeException("System.exit(1) here!");
}
+ */
public int nextVariableSerial() {
return _variableSerial++;
1.4 +12 -14
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.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- XslAttribute.java 2001/05/21 15:12:31 1.3
+++ XslAttribute.java 2001/06/06 10:45:45 1.4
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: XslAttribute.java,v 1.3 2001/05/21 15:12:31 morten Exp $
+ * @(#)$Id: XslAttribute.java,v 1.4 2001/06/06 10:45:45 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -66,8 +66,6 @@
import java.util.Vector;
-import org.w3c.dom.*;
-
import org.apache.xalan.xsltc.compiler.util.Type;
import de.fub.bytecode.generic.*;
import org.apache.xalan.xsltc.compiler.util.*;
@@ -97,17 +95,17 @@
/**
* Parses the attribute's contents. Special care taken for namespaces.
*/
- public void parseContents(Element element, Parser parser) {
+ public void parseContents(Parser parser) {
final SymbolTable stable = parser.getSymbolTable();
- String namespace = element.getAttribute("namespace");
- String name = element.getAttribute("name");
+ String namespace = getAttribute("namespace");
+ String name = getAttribute("name");
QName qname = parser.getQName(name);
final String prefix = qname.getPrefix();
boolean generated = false;
if ((prefix != null) && (prefix.equals("xmlns"))) {
- reportError(element, parser, ErrorMsg.ILL_ATTR_ERR, name);
+ reportError(this, parser, ErrorMsg.ILL_ATTR_ERR, name);
return;
}
@@ -121,21 +119,21 @@
!(item instanceof UseAttributeSets) &&
!(item instanceof LiteralAttribute)) {
_ignore = true;
- reportWarning(element, parser, ErrorMsg.ATTROUTS_ERR, name);
+ reportWarning(this, parser, ErrorMsg.ATTROUTS_ERR, name);
return;
}
}
// Get namespace from namespace attribute?
- if (namespace != "") {
+ if ((namespace != null) && (namespace != Constants.EMPTYSTRING)) {
// Prefix could be in symbol table
- _prefix = stable.lookupPrefix(namespace);
+ //_prefix = stable.lookupPrefix(namespace);
_namespace = new AttributeValueTemplate(namespace, parser);
}
// Get namespace from prefix in name attribute?
- else if (prefix != "") {
+ else if ((prefix != null) && (prefix != Constants.EMPTYSTRING)) {
_prefix = prefix;
- namespace = stable.lookupNamespace(prefix);
+ namespace = lookupNamespace(prefix);
if (namespace != null)
_namespace = new AttributeValueTemplate(namespace, parser);
}
@@ -154,7 +152,7 @@
}
}
- if (_prefix.equals("")) {
+ if (_prefix == Constants.EMPTYSTRING) {
name = qname.getLocalPart();
}
else {
@@ -173,7 +171,7 @@
_name = AttributeValue.create(this, name, parser);
- parseChildren(element, parser);
+ parseChildren(parser);
}
/**
1.5 +17 -22
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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- XslElement.java 2001/05/21 15:12:33 1.4
+++ XslElement.java 2001/06/06 10:45:46 1.5
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: XslElement.java,v 1.4 2001/05/21 15:12:33 morten Exp $
+ * @(#)$Id: XslElement.java,v 1.5 2001/06/06 10:45:46 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -68,8 +68,6 @@
import java.util.Enumeration;
import java.util.StringTokenizer;
-import org.w3c.dom.*;
-
import org.apache.xalan.xsltc.compiler.util.Type;
import de.fub.bytecode.generic.*;
import org.apache.xalan.xsltc.compiler.util.*;
@@ -100,22 +98,23 @@
* around the problem by treating the namaspace attribute as a constant.
* (Yes, I know this is a hack, bad, bad, bad.)
*/
- public void parseContents(Element element, Parser parser) {
+ public void parseContents(Parser parser) {
final SymbolTable stable = parser.getSymbolTable();
// First try to get namespace from the namespace attribute
- String namespace = element.getAttribute("namespace");
+ String namespace = getAttribute("namespace");
// If that is undefied we use the prefix in the supplied QName
- String name = element.getAttribute("name");
+ String name = getAttribute("name");
QName qname = parser.getQNameSafe(name);
final String prefix = qname.getPrefix();
- if ((namespace == null || namespace == "") && (prefix != null)) {
- namespace = stable.lookupNamespace(prefix);
+ if ((namespace == null || namespace == Constants.EMPTYSTRING) &&
+ (prefix != null)) {
+ namespace = lookupNamespace(prefix);
if (namespace == null) {
parser.addWarning(new ErrorMsg(ErrorMsg.NSPUNDEF_ERR, prefix));
- parseChildren(element, parser);
+ parseChildren(parser);
_ignore = true; // Ignore the element if prefix is undeclared
return;
}
@@ -125,24 +124,23 @@
if (qname.getLocalPart().indexOf(' ') > -1) {
parser.addWarning(new ErrorMsg("You can't call an element \""+
qname.getLocalPart()+"\""));
- parseChildren(element, parser);
+ parseChildren(parser);
_ignore = true; // Ignore the element if the local part is invalid
return;
}
// Check if this element belongs in a specific namespace
- if (namespace != "") {
+ if (namespace != Constants.EMPTYSTRING) {
// Get the namespace requested by the xsl:element
- _namespace = new AttributeValueTemplate(namespace,parser);
+ _namespace = new AttributeValueTemplate(namespace, parser);
// Get the current prefix for that namespace (if any)
- _namespacePrefix = stable.lookupPrefix(namespace);
+ _namespacePrefix = lookupPrefix(namespace);
// Is it the default namespace?
- if ((_namespacePrefix = prefix) == null) _namespacePrefix = "";
- // Make this prefix-namespace mapping in scope (in symbol table)
- stable.pushNamespace(_namespacePrefix,namespace);
+ if ((_namespacePrefix = prefix) == null)
+ _namespacePrefix = Constants.EMPTYSTRING;
// Construct final element QName
- if (_namespacePrefix.equals(""))
+ if (_namespacePrefix == Constants.EMPTYSTRING)
name = qname.getLocalPart();
else
name = _namespacePrefix+":"+qname.getLocalPart();
@@ -151,15 +149,12 @@
_name = AttributeValue.create(this, name, parser);
// Handle the 'use-attribute-sets' attribute
- final String useSets = element.getAttribute("use-attribute-sets");
+ final String useSets = getAttribute("use-attribute-sets");
if (useSets.length() > 0) {
addElement(new UseAttributeSets(useSets, parser));
}
-
- parseChildren(element, parser);
- // Make any prefix-namespace mapping out-of-scope
- if (_namespace != null) stable.popNamespace(_namespacePrefix);
+ parseChildren(parser);
}
/**
1.2 +9 -28
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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- xpath.cup 2001/04/17 18:51:54 1.1
+++ xpath.cup 2001/06/06 10:45:46 1.2
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: xpath.cup,v 1.1 2001/04/17 18:51:54 sboag Exp $
+ * @(#)$Id: xpath.cup,v 1.2 2001/06/06 10:45:46 morten Exp $
*
* Copyright 2000 Sun Microsystems, Inc. All Rights Reserved.
*
@@ -124,29 +124,10 @@
final SyntaxTreeNode lookupName(QName name) {
// Is it a local var or param ?
final SyntaxTreeNode result = _parser.lookupVariable(name);
- return result != null ? result : _symbolTable.lookupName(name);
-
- /*
- // Is it a global var or param ?
- if (result == null) {
- result = _symbolTable.lookupName(name);
- }
- else {
- System.out.println("looked up " + name);
- result.display(0);
- }
- */
-
- /*
- if (result != null) {
- System.out.println("looked up " + name);
- result.display(0);
- }
- else {
- System.out.println("looked up failure");
- }
- return result;
- */
+ if (result != null)
+ return(result);
+ else
+ return(_symbolTable.lookupName(name));
}
public final void addError(ErrorMsg error) {
@@ -600,7 +581,7 @@
final int index = string.indexOf(':');
final String prefix = index >= 0
? string.substring(0, index)
- : "";
+ : Constants.EMPTYSTRING;
String namespace = parser._symbolTable.lookupNamespace(prefix);
RESULT = namespace == null
? new LiteralExpr(string)
@@ -636,7 +617,7 @@
RESULT = new ParameterRef((Param)node);
}
else {
- node.getParser().internalError();
+ node.getParser().addFatalError("Cannot resolve variable
or parameter feference to "+varName);
}
}
else {
@@ -782,8 +763,8 @@
FunctionName ::= QName:fname
{:
- fname.clearDefaultNamespace();
- RESULT = fname;
+ fname.clearDefaultNamespace();
+ RESULT = fname;
:};
Argument ::= Expr:ex
1.2 +14 -2
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util/MethodType.java
Index: MethodType.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util/MethodType.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- MethodType.java 2001/04/17 18:52:16 1.1
+++ MethodType.java 2001/06/06 10:47:02 1.2
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: MethodType.java,v 1.1 2001/04/17 18:52:16 sboag Exp $
+ * @(#)$Id: MethodType.java,v 1.2 2001/06/06 10:47:02 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -106,7 +106,19 @@
}
public String toString() {
- return "method-type";
+ StringBuffer result = new StringBuffer("method{");
+ if (_argsType != null) {
+ final int count = _argsType.size();
+ for (int i=0; i<count; i++) {
+ result.append(_argsType.elementAt(i));
+ if (i != (count-1)) result.append(',');
+ }
+ }
+ else {
+ result.append("void");
+ }
+ result.append('}');
+ return result.toString();
}
public String toSignature() {
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]