You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by mu...@apache.org on 2026/05/02 06:34:11 UTC
(xalan-java) branch xalan-j_xslt3.0_mvn updated: committing support for previous xsltc (that supports most of xslt 1.0 processing) processing within xalan-j xslt3.0 implementation
This is an automated email from the ASF dual-hosted git repository.
mukulgandhi pushed a commit to branch xalan-j_xslt3.0_mvn
in repository https://gitbox.apache.org/repos/asf/xalan-java.git
The following commit(s) were added to refs/heads/xalan-j_xslt3.0_mvn by this push:
new b4a85b848 committing support for previous xsltc (that supports most of xslt 1.0 processing) processing within xalan-j xslt3.0 implementation
b4a85b848 is described below
commit b4a85b848d10371d63c49e16afb57bdb3b5b55f0
Author: Mukul Gandhi <ga...@gmail.com>
AuthorDate: Sat May 2 12:03:43 2026 +0530
committing support for previous xsltc (that supports most of xslt 1.0 processing) processing within xalan-j xslt3.0 implementation
---
libs/JLex/JLex/1.0/jlex-1.0.jar | Bin 0 -> 54603 bytes
libs/JLex/JLex/1.0/jlex-1.0.pom | 9 +
.../cs/cup_runtime/1.0/cup_runtime-1.0.jar | Bin 0 -> 7820 bytes
.../cs/cup_runtime/1.0/cup_runtime-1.0.pom | 9 +
.../edu/princeton/cs/java_cup/1.0/java_cup-1.0.jar | Bin 0 -> 62365 bytes
.../edu/princeton/cs/java_cup/1.0/java_cup-1.0.pom | 9 +
pom.xml | 36 +-
.../apache/xalan/processor/XSLTAttributeDef.java | 9 +-
.../java/org/apache/xalan/templates/Constants.java | 8 +
.../apache/xalan/templates/ElemApplyTemplates.java | 4 +-
.../templates/TemplateSubPatternAssociation.java | 4 +-
src/main/java/org/apache/xalan/xslt/Process.java | 18 +-
.../org/apache/xalan/xsltc/CollatorFactory.java | 35 +
src/main/java/org/apache/xalan/xsltc/DOM.java | 105 +
src/main/java/org/apache/xalan/xsltc/DOMCache.java | 56 +
.../org/apache/xalan/xsltc/DOMEnhancedForDTM.java | 45 +
.../java/org/apache/xalan/xsltc/NodeIterator.java | 84 +
.../org/apache/xalan/xsltc/ProcessorVersion.java | 49 +
.../java/org/apache/xalan/xsltc/StripFilter.java | 31 +
src/main/java/org/apache/xalan/xsltc/Translet.java | 52 +
.../org/apache/xalan/xsltc/TransletException.java | 45 +
.../org/apache/xalan/xsltc/cmdline/Compile.java | 153 +
.../apache/xalan/xsltc/cmdline/ObjectFactory.java | 656 ++++
.../xalan/xsltc/cmdline/SecuritySupport.java | 144 +
.../org/apache/xalan/xsltc/cmdline/Transform.java | 295 ++
.../apache/xalan/xsltc/cmdline/getopt/GetOpt.java | 254 ++
.../xsltc/cmdline/getopt/GetOptsException.java | 32 +
.../cmdline/getopt/IllegalArgumentException.java | 30 +
.../cmdline/getopt/MissingOptArgException.java | 33 +
.../xalan/xsltc/compiler/AbsoluteLocationPath.java | 128 +
.../xalan/xsltc/compiler/AbsolutePathPattern.java | 140 +
.../xalan/xsltc/compiler/AlternativePattern.java | 100 +
.../xalan/xsltc/compiler/AncestorPattern.java | 182 ++
.../apache/xalan/xsltc/compiler/ApplyImports.java | 152 +
.../xalan/xsltc/compiler/ApplyTemplates.java | 202 ++
.../apache/xalan/xsltc/compiler/ArgumentList.java | 42 +
.../org/apache/xalan/xsltc/compiler/Attribute.java | 45 +
.../apache/xalan/xsltc/compiler/AttributeSet.java | 206 ++
.../xalan/xsltc/compiler/AttributeValue.java | 48 +
.../xsltc/compiler/AttributeValueTemplate.java | 261 ++
.../org/apache/xalan/xsltc/compiler/BinOpExpr.java | 130 +
.../apache/xalan/xsltc/compiler/BooleanCall.java | 57 +
.../apache/xalan/xsltc/compiler/BooleanExpr.java | 79 +
.../apache/xalan/xsltc/compiler/CallTemplate.java | 238 ++
.../org/apache/xalan/xsltc/compiler/CastCall.java | 100 +
.../org/apache/xalan/xsltc/compiler/CastExpr.java | 237 ++
.../apache/xalan/xsltc/compiler/CeilingCall.java | 48 +
.../org/apache/xalan/xsltc/compiler/Choose.java | 168 ++
.../org/apache/xalan/xsltc/compiler/Closure.java | 50 +
.../org/apache/xalan/xsltc/compiler/Comment.java | 116 +
.../xalan/xsltc/compiler/CompilerException.java | 54 +
.../apache/xalan/xsltc/compiler/ConcatCall.java | 95 +
.../org/apache/xalan/xsltc/compiler/Constants.java | 537 ++++
.../apache/xalan/xsltc/compiler/ContainsCall.java | 107 +
.../java/org/apache/xalan/xsltc/compiler/Copy.java | 151 +
.../org/apache/xalan/xsltc/compiler/CopyOf.java | 141 +
.../apache/xalan/xsltc/compiler/CurrentCall.java | 39 +
.../xalan/xsltc/compiler/DecimalFormatting.java | 256 ++
.../apache/xalan/xsltc/compiler/DocumentCall.java | 155 +
.../xalan/xsltc/compiler/ElementAvailableCall.java | 93 +
.../apache/xalan/xsltc/compiler/EqualityExpr.java | 359 +++
.../apache/xalan/xsltc/compiler/Expression.java | 222 ++
.../org/apache/xalan/xsltc/compiler/Fallback.java | 79 +
.../apache/xalan/xsltc/compiler/FilterExpr.java | 246 ++
.../xalan/xsltc/compiler/FilterParentPath.java | 174 ++
.../compiler/FilteredAbsoluteLocationPath.java | 125 +
.../org/apache/xalan/xsltc/compiler/FloorCall.java | 46 +
.../org/apache/xalan/xsltc/compiler/FlowList.java | 117 +
.../org/apache/xalan/xsltc/compiler/ForEach.java | 196 ++
.../xalan/xsltc/compiler/FormatNumberCall.java | 114 +
.../xsltc/compiler/FunctionAvailableCall.java | 193 ++
.../apache/xalan/xsltc/compiler/FunctionCall.java | 1093 +++++++
.../xalan/xsltc/compiler/GenerateIdCall.java | 55 +
.../apache/xalan/xsltc/compiler/IdKeyPattern.java | 127 +
.../org/apache/xalan/xsltc/compiler/IdPattern.java | 35 +
.../java/org/apache/xalan/xsltc/compiler/If.java | 110 +
.../xalan/xsltc/compiler/IllegalCharException.java | 33 +
.../org/apache/xalan/xsltc/compiler/Import.java | 148 +
.../org/apache/xalan/xsltc/compiler/Include.java | 147 +
.../apache/xalan/xsltc/compiler/Instruction.java | 50 +
.../org/apache/xalan/xsltc/compiler/IntExpr.java | 56 +
.../java/org/apache/xalan/xsltc/compiler/Key.java | 299 ++
.../org/apache/xalan/xsltc/compiler/KeyCall.java | 224 ++
.../apache/xalan/xsltc/compiler/KeyPattern.java | 34 +
.../org/apache/xalan/xsltc/compiler/LangCall.java | 91 +
.../org/apache/xalan/xsltc/compiler/LastCall.java | 69 +
.../xalan/xsltc/compiler/LiteralAttribute.java | 157 +
.../xalan/xsltc/compiler/LiteralElement.java | 547 ++++
.../apache/xalan/xsltc/compiler/LiteralExpr.java | 85 +
.../apache/xalan/xsltc/compiler/LocalNameCall.java | 74 +
.../xalan/xsltc/compiler/LocationPathPattern.java | 107 +
.../apache/xalan/xsltc/compiler/LogicalExpr.java | 233 ++
.../org/apache/xalan/xsltc/compiler/Makefile.inc | 58 +
.../org/apache/xalan/xsltc/compiler/Message.java | 167 ++
.../java/org/apache/xalan/xsltc/compiler/Mode.java | 1513 ++++++++++
.../org/apache/xalan/xsltc/compiler/NameBase.java | 128 +
.../org/apache/xalan/xsltc/compiler/NameCall.java | 66 +
.../xalan/xsltc/compiler/NamespaceAlias.java | 55 +
.../xalan/xsltc/compiler/NamespaceUriCall.java | 67 +
.../org/apache/xalan/xsltc/compiler/NodeTest.java | 43 +
.../org/apache/xalan/xsltc/compiler/NotCall.java | 58 +
.../org/apache/xalan/xsltc/compiler/Number.java | 592 ++++
.../apache/xalan/xsltc/compiler/NumberCall.java | 68 +
.../apache/xalan/xsltc/compiler/ObjectFactory.java | 656 ++++
.../org/apache/xalan/xsltc/compiler/Otherwise.java | 53 +
.../org/apache/xalan/xsltc/compiler/Output.java | 419 +++
.../org/apache/xalan/xsltc/compiler/Param.java | 254 ++
.../apache/xalan/xsltc/compiler/ParameterRef.java | 109 +
.../xalan/xsltc/compiler/ParentLocationPath.java | 244 ++
.../apache/xalan/xsltc/compiler/ParentPattern.java | 150 +
.../org/apache/xalan/xsltc/compiler/Parser.java | 1401 +++++++++
.../org/apache/xalan/xsltc/compiler/Pattern.java | 60 +
.../apache/xalan/xsltc/compiler/PositionCall.java | 67 +
.../org/apache/xalan/xsltc/compiler/Predicate.java | 617 ++++
.../xsltc/compiler/ProcessingInstruction.java | 140 +
.../compiler/ProcessingInstructionPattern.java | 158 +
.../org/apache/xalan/xsltc/compiler/QName.java | 85 +
.../org/apache/xalan/xsltc/compiler/RealExpr.java | 56 +
.../xalan/xsltc/compiler/RelationalExpr.java | 281 ++
.../xalan/xsltc/compiler/RelativeLocationPath.java | 31 +
.../xalan/xsltc/compiler/RelativePathPattern.java | 28 +
.../org/apache/xalan/xsltc/compiler/RoundCall.java | 51 +
.../xalan/xsltc/compiler/SecuritySupport.java | 144 +
.../xalan/xsltc/compiler/SimpleAttributeValue.java | 75 +
.../java/org/apache/xalan/xsltc/compiler/Sort.java | 738 +++++
.../apache/xalan/xsltc/compiler/SourceLoader.java | 42 +
.../xalan/xsltc/compiler/StartsWithCall.java | 91 +
.../java/org/apache/xalan/xsltc/compiler/Step.java | 521 ++++
.../apache/xalan/xsltc/compiler/StepPattern.java | 532 ++++
.../apache/xalan/xsltc/compiler/StringCall.java | 74 +
.../xalan/xsltc/compiler/StringLengthCall.java | 55 +
.../apache/xalan/xsltc/compiler/Stylesheet.java | 1561 ++++++++++
.../apache/xalan/xsltc/compiler/SymbolTable.java | 295 ++
.../xalan/xsltc/compiler/SyntaxTreeNode.java | 942 ++++++
.../org/apache/xalan/xsltc/compiler/Template.java | 340 +++
.../org/apache/xalan/xsltc/compiler/TestSeq.java | 287 ++
.../java/org/apache/xalan/xsltc/compiler/Text.java | 245 ++
.../xalan/xsltc/compiler/TopLevelElement.java | 98 +
.../xalan/xsltc/compiler/TransletOutput.java | 147 +
.../apache/xalan/xsltc/compiler/UnaryOpExpr.java | 89 +
.../apache/xalan/xsltc/compiler/UnionPathExpr.java | 146 +
.../xsltc/compiler/UnparsedEntityUriCall.java | 70 +
.../apache/xalan/xsltc/compiler/UnresolvedRef.java | 102 +
.../xalan/xsltc/compiler/UnsupportedElement.java | 150 +
.../xalan/xsltc/compiler/UseAttributeSets.java | 115 +
.../org/apache/xalan/xsltc/compiler/ValueOf.java | 138 +
.../org/apache/xalan/xsltc/compiler/Variable.java | 200 ++
.../apache/xalan/xsltc/compiler/VariableBase.java | 272 ++
.../apache/xalan/xsltc/compiler/VariableRef.java | 95 +
.../xalan/xsltc/compiler/VariableRefBase.java | 158 +
.../java/org/apache/xalan/xsltc/compiler/When.java | 105 +
.../apache/xalan/xsltc/compiler/Whitespace.java | 531 ++++
.../org/apache/xalan/xsltc/compiler/WithParam.java | 209 ++
.../apache/xalan/xsltc/compiler/XPathLexer.java | 1643 ++++++++++
.../apache/xalan/xsltc/compiler/XPathParser.java | 3149 ++++++++++++++++++++
.../org/apache/xalan/xsltc/compiler/XSLTC.java | 1006 +++++++
.../apache/xalan/xsltc/compiler/XslAttribute.java | 293 ++
.../apache/xalan/xsltc/compiler/XslElement.java | 323 ++
.../java/org/apache/xalan/xsltc/compiler/sym.java | 68 +
.../compiler/util/AttributeSetMethodGenerator.java | 99 +
.../xalan/xsltc/compiler/util/BooleanType.java | 223 ++
.../xalan/xsltc/compiler/util/ClassGenerator.java | 142 +
.../xsltc/compiler/util/CompareGenerator.java | 118 +
.../xalan/xsltc/compiler/util/ErrorMessages.java | 1004 +++++++
.../xsltc/compiler/util/ErrorMessages_ca.java | 912 ++++++
.../xsltc/compiler/util/ErrorMessages_cs.java | 913 ++++++
.../xsltc/compiler/util/ErrorMessages_de.java | 913 ++++++
.../xsltc/compiler/util/ErrorMessages_es.java | 913 ++++++
.../xsltc/compiler/util/ErrorMessages_fr.java | 913 ++++++
.../xsltc/compiler/util/ErrorMessages_hu.java | 913 ++++++
.../xsltc/compiler/util/ErrorMessages_it.java | 913 ++++++
.../xsltc/compiler/util/ErrorMessages_ja.java | 913 ++++++
.../xsltc/compiler/util/ErrorMessages_ko.java | 913 ++++++
.../xsltc/compiler/util/ErrorMessages_no.java | 222 ++
.../xsltc/compiler/util/ErrorMessages_pl.java | 913 ++++++
.../xsltc/compiler/util/ErrorMessages_pt_BR.java | 913 ++++++
.../xsltc/compiler/util/ErrorMessages_ru.java | 913 ++++++
.../xsltc/compiler/util/ErrorMessages_sk.java | 913 ++++++
.../xsltc/compiler/util/ErrorMessages_sl.java | 913 ++++++
.../xsltc/compiler/util/ErrorMessages_tr.java | 913 ++++++
.../xsltc/compiler/util/ErrorMessages_zh.java | 913 ++++++
.../xsltc/compiler/util/ErrorMessages_zh_TW.java | 913 ++++++
.../apache/xalan/xsltc/compiler/util/ErrorMsg.java | 317 ++
.../xalan/xsltc/compiler/util/FilterGenerator.java | 64 +
.../apache/xalan/xsltc/compiler/util/IntType.java | 300 ++
.../xalan/xsltc/compiler/util/InternalError.java | 36 +
.../xsltc/compiler/util/MarkerInstruction.java | 97 +
.../xalan/xsltc/compiler/util/MatchGenerator.java | 102 +
.../xalan/xsltc/compiler/util/MethodGenerator.java | 2147 +++++++++++++
.../xalan/xsltc/compiler/util/MethodType.java | 171 ++
.../xalan/xsltc/compiler/util/MultiHashtable.java | 55 +
.../xsltc/compiler/util/NamedMethodGenerator.java | 65 +
.../xsltc/compiler/util/NodeCounterGenerator.java | 73 +
.../xalan/xsltc/compiler/util/NodeSetType.java | 329 ++
.../compiler/util/NodeSortRecordFactGenerator.java | 47 +
.../compiler/util/NodeSortRecordGenerator.java | 63 +
.../apache/xalan/xsltc/compiler/util/NodeType.java | 323 ++
.../xalan/xsltc/compiler/util/NumberType.java | 38 +
.../xalan/xsltc/compiler/util/ObjectFactory.java | 656 ++++
.../xalan/xsltc/compiler/util/ObjectType.java | 177 ++
.../xsltc/compiler/util/OutlineableChunkEnd.java | 70 +
.../xsltc/compiler/util/OutlineableChunkStart.java | 79 +
.../apache/xalan/xsltc/compiler/util/RealType.java | 342 +++
.../xalan/xsltc/compiler/util/ReferenceType.java | 378 +++
.../xalan/xsltc/compiler/util/ResultTreeType.java | 463 +++
.../xsltc/compiler/util/RtMethodGenerator.java | 68 +
.../xalan/xsltc/compiler/util/SecuritySupport.java | 144 +
.../xalan/xsltc/compiler/util/SlotAllocator.java | 100 +
.../xalan/xsltc/compiler/util/StringStack.java | 43 +
.../xalan/xsltc/compiler/util/StringType.java | 226 ++
.../xalan/xsltc/compiler/util/TestGenerator.java | 115 +
.../org/apache/xalan/xsltc/compiler/util/Type.java | 291 ++
.../xalan/xsltc/compiler/util/TypeCheckError.java | 77 +
.../org/apache/xalan/xsltc/compiler/util/Util.java | 202 ++
.../apache/xalan/xsltc/compiler/util/VoidType.java | 98 +
.../java/org/apache/xalan/xsltc/compiler/xpath.cup | 1113 +++++++
.../java/org/apache/xalan/xsltc/compiler/xpath.lex | 257 ++
.../apache/xalan/xsltc/dom/AbsoluteIterator.java | 99 +
.../xalan/xsltc/dom/AdaptiveResultTreeImpl.java | 1320 ++++++++
.../org/apache/xalan/xsltc/dom/AnyNodeCounter.java | 122 +
.../xalan/xsltc/dom/ArrayNodeListIterator.java | 89 +
.../java/org/apache/xalan/xsltc/dom/BitArray.java | 266 ++
.../xalan/xsltc/dom/CachedNodeListIterator.java | 113 +
.../xalan/xsltc/dom/ClonedNodeListIterator.java | 81 +
.../xalan/xsltc/dom/CollatorFactoryBase.java | 50 +
.../xalan/xsltc/dom/CurrentNodeListFilter.java | 35 +
.../xalan/xsltc/dom/CurrentNodeListIterator.java | 199 ++
.../org/apache/xalan/xsltc/dom/DOMAdapter.java | 466 +++
.../org/apache/xalan/xsltc/dom/DOMBuilder.java | 27 +
.../org/apache/xalan/xsltc/dom/DOMWSFilter.java | 130 +
.../org/apache/xalan/xsltc/dom/DocumentCache.java | 339 +++
.../apache/xalan/xsltc/dom/DupFilterIterator.java | 165 +
.../org/apache/xalan/xsltc/dom/EmptyFilter.java | 32 +
.../org/apache/xalan/xsltc/dom/ExtendedSAX.java | 34 +
.../java/org/apache/xalan/xsltc/dom/Filter.java | 30 +
.../org/apache/xalan/xsltc/dom/FilterIterator.java | 118 +
.../xalan/xsltc/dom/FilteredStepIterator.java | 54 +
.../xalan/xsltc/dom/ForwardPositionIterator.java | 107 +
.../java/org/apache/xalan/xsltc/dom/KeyIndex.java | 892 ++++++
.../org/apache/xalan/xsltc/dom/LoadDocument.java | 289 ++
.../apache/xalan/xsltc/dom/MatchingIterator.java | 127 +
.../java/org/apache/xalan/xsltc/dom/MultiDOM.java | 665 +++++
.../xsltc/dom/MultiValuedNodeHeapIterator.java | 294 ++
.../xalan/xsltc/dom/MultipleNodeCounter.java | 111 +
.../org/apache/xalan/xsltc/dom/NodeCounter.java | 350 +++
.../apache/xalan/xsltc/dom/NodeIteratorBase.java | 170 ++
.../org/apache/xalan/xsltc/dom/NodeSortRecord.java | 243 ++
.../xalan/xsltc/dom/NodeSortRecordFactory.java | 164 +
.../org/apache/xalan/xsltc/dom/NthIterator.java | 115 +
.../org/apache/xalan/xsltc/dom/ObjectFactory.java | 656 ++++
.../java/org/apache/xalan/xsltc/dom/SAXImpl.java | 1903 ++++++++++++
.../apache/xalan/xsltc/dom/SecuritySupport.java | 144 +
.../xalan/xsltc/dom/SimpleResultTreeImpl.java | 1018 +++++++
.../apache/xalan/xsltc/dom/SingleNodeCounter.java | 133 +
.../apache/xalan/xsltc/dom/SingletonIterator.java | 92 +
.../org/apache/xalan/xsltc/dom/SortSettings.java | 138 +
.../apache/xalan/xsltc/dom/SortingIterator.java | 149 +
.../org/apache/xalan/xsltc/dom/StepIterator.java | 138 +
.../xalan/xsltc/dom/StripWhitespaceFilter.java | 32 +
.../org/apache/xalan/xsltc/dom/UnionIterator.java | 98 +
.../apache/xalan/xsltc/dom/XSLTCDTMManager.java | 416 +++
.../xsltc/javax.xml.transform.TransformerFactory | 1 +
.../xalan/xsltc/runtime/AbstractTranslet.java | 754 +++++
.../apache/xalan/xsltc/runtime/AttributeList.java | 228 ++
.../org/apache/xalan/xsltc/runtime/Attributes.java | 63 +
.../apache/xalan/xsltc/runtime/BasisLibrary.java | 1731 +++++++++++
.../org/apache/xalan/xsltc/runtime/Constants.java | 51 +
.../apache/xalan/xsltc/runtime/ErrorMessages.java | 285 ++
.../xalan/xsltc/runtime/ErrorMessages_ca.java | 285 ++
.../xalan/xsltc/runtime/ErrorMessages_cs.java | 285 ++
.../xalan/xsltc/runtime/ErrorMessages_de.java | 285 ++
.../xalan/xsltc/runtime/ErrorMessages_es.java | 285 ++
.../xalan/xsltc/runtime/ErrorMessages_fr.java | 285 ++
.../xalan/xsltc/runtime/ErrorMessages_hu.java | 285 ++
.../xalan/xsltc/runtime/ErrorMessages_it.java | 285 ++
.../xalan/xsltc/runtime/ErrorMessages_ja.java | 285 ++
.../xalan/xsltc/runtime/ErrorMessages_ko.java | 285 ++
.../xalan/xsltc/runtime/ErrorMessages_no.java | 85 +
.../xalan/xsltc/runtime/ErrorMessages_pl.java | 285 ++
.../xalan/xsltc/runtime/ErrorMessages_pt_BR.java | 285 ++
.../xalan/xsltc/runtime/ErrorMessages_ru.java | 285 ++
.../xalan/xsltc/runtime/ErrorMessages_sk.java | 285 ++
.../xalan/xsltc/runtime/ErrorMessages_sl.java | 285 ++
.../xalan/xsltc/runtime/ErrorMessages_tr.java | 285 ++
.../xalan/xsltc/runtime/ErrorMessages_zh.java | 285 ++
.../xalan/xsltc/runtime/ErrorMessages_zh_TW.java | 285 ++
.../org/apache/xalan/xsltc/runtime/Hashtable.java | 343 +++
.../xalan/xsltc/runtime/InternalRuntimeError.java | 34 +
.../apache/xalan/xsltc/runtime/MessageHandler.java | 31 +
.../java/org/apache/xalan/xsltc/runtime/Node.java | 38 +
.../apache/xalan/xsltc/runtime/ObjectFactory.java | 656 ++++
.../org/apache/xalan/xsltc/runtime/Operators.java | 58 +
.../org/apache/xalan/xsltc/runtime/Parameter.java | 46 +
.../xalan/xsltc/runtime/SecuritySupport.java | 144 +
.../xalan/xsltc/runtime/StringValueHandler.java | 125 +
.../xalan/xsltc/runtime/output/OutputBuffer.java | 36 +
.../xsltc/runtime/output/StringOutputBuffer.java | 54 +
.../output/TransletOutputHandlerFactory.java | 189 ++
.../xsltc/runtime/output/WriterOutputBuffer.java | 96 +
.../java/org/apache/xalan/xsltc/trax/DOM2SAX.java | 474 +++
.../java/org/apache/xalan/xsltc/trax/DOM2TO.java | 393 +++
.../org/apache/xalan/xsltc/trax/ObjectFactory.java | 656 ++++
.../apache/xalan/xsltc/trax/OutputSettings.java | 47 +
.../java/org/apache/xalan/xsltc/trax/SAX2DOM.java | 249 ++
.../apache/xalan/xsltc/trax/SecuritySupport.java | 144 +
.../xsltc/trax/SmartTransformerFactoryImpl.java | 452 +++
.../xalan/xsltc/trax/TemplatesHandlerImpl.java | 343 +++
.../org/apache/xalan/xsltc/trax/TemplatesImpl.java | 410 +++
.../org/apache/xalan/xsltc/trax/TrAXFilter.java | 144 +
.../xalan/xsltc/trax/TransformerFactoryImpl.java | 1413 +++++++++
.../xalan/xsltc/trax/TransformerHandlerImpl.java | 470 +++
.../apache/xalan/xsltc/trax/TransformerImpl.java | 1277 ++++++++
.../java/org/apache/xalan/xsltc/trax/Util.java | 195 ++
.../org/apache/xalan/xsltc/trax/XSLTCSource.java | 140 +
.../org/apache/xalan/xsltc/util/IntegerArray.java | 226 ++
.../apache/xalan/xsltc/util/JavaCupRedirect.java | 97 +
316 files changed, 90596 insertions(+), 25 deletions(-)
diff --git a/libs/JLex/JLex/1.0/jlex-1.0.jar b/libs/JLex/JLex/1.0/jlex-1.0.jar
new file mode 100644
index 000000000..1c977f32a
Binary files /dev/null and b/libs/JLex/JLex/1.0/jlex-1.0.jar differ
diff --git a/libs/JLex/JLex/1.0/jlex-1.0.pom b/libs/JLex/JLex/1.0/jlex-1.0.pom
new file mode 100644
index 000000000..83a8a0b4a
--- /dev/null
+++ b/libs/JLex/JLex/1.0/jlex-1.0.pom
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>JLex</groupId>
+ <artifactId>JLex</artifactId>
+ <version>1.0</version>
+ <description>https://www.cs.princeton.edu/~appel/modern/java/JLex/</description>
+</project>
\ No newline at end of file
diff --git a/libs/edu/princeton/cs/cup_runtime/1.0/cup_runtime-1.0.jar b/libs/edu/princeton/cs/cup_runtime/1.0/cup_runtime-1.0.jar
new file mode 100644
index 000000000..c74baf197
Binary files /dev/null and b/libs/edu/princeton/cs/cup_runtime/1.0/cup_runtime-1.0.jar differ
diff --git a/libs/edu/princeton/cs/cup_runtime/1.0/cup_runtime-1.0.pom b/libs/edu/princeton/cs/cup_runtime/1.0/cup_runtime-1.0.pom
new file mode 100644
index 000000000..a0a3c0ffa
--- /dev/null
+++ b/libs/edu/princeton/cs/cup_runtime/1.0/cup_runtime-1.0.pom
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>edu.princeton.cs</groupId>
+ <artifactId>cup_runtime</artifactId>
+ <version>1.0</version>
+ <description>http://www2.cs.tum.edu/projects/cup/</description>
+</project>
\ No newline at end of file
diff --git a/libs/edu/princeton/cs/java_cup/1.0/java_cup-1.0.jar b/libs/edu/princeton/cs/java_cup/1.0/java_cup-1.0.jar
new file mode 100644
index 000000000..3e12262fb
Binary files /dev/null and b/libs/edu/princeton/cs/java_cup/1.0/java_cup-1.0.jar differ
diff --git a/libs/edu/princeton/cs/java_cup/1.0/java_cup-1.0.pom b/libs/edu/princeton/cs/java_cup/1.0/java_cup-1.0.pom
new file mode 100644
index 000000000..c258c5617
--- /dev/null
+++ b/libs/edu/princeton/cs/java_cup/1.0/java_cup-1.0.pom
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>edu.princeton.cs</groupId>
+ <artifactId>java_cup</artifactId>
+ <version>1.0</version>
+ <description>http://www2.cs.tum.edu/projects/cup/</description>
+</project>
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 577d01a88..77a779f2d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -46,6 +46,26 @@
</properties>
<dependencies>
+ <dependency>
+ <groupId>org.apache.bcel</groupId>
+ <artifactId>bcel</artifactId>
+ <version>6.7.0</version>
+ </dependency>
+ <dependency>
+ <groupId>edu.princeton.cs</groupId>
+ <artifactId>java_cup</artifactId>
+ <version>1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>edu.princeton.cs</groupId>
+ <artifactId>cup_runtime</artifactId>
+ <version>1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>Jlex</groupId>
+ <artifactId>Jlex</artifactId>
+ <version>1.0</version>
+ </dependency>
<dependency>
<groupId>org.apache.xerces</groupId>
<artifactId>xercesImpl</artifactId>
@@ -55,7 +75,7 @@
<groupId>org.apache.xerces</groupId>
<artifactId>xml-apis</artifactId>
<version>1.4.02</version>
- </dependency>
+ </dependency>
<!-- Apache Bean Scripting framework dependency. This despatches
Xalan-J's JavaScript extension calls to Mozilla Rhino
JavaScript implementation. -->
@@ -64,19 +84,19 @@
<artifactId>bsf</artifactId>
<version>2.4.0</version>
</dependency>
- <!-- Mozilla JavaScript library dependency, licensed with
- the Mozilla Public License Version 2.0 -->
- <dependency>
- <groupId>org.mozilla</groupId>
- <artifactId>rhino</artifactId>
- <version>1.7.15.1</version>
- </dependency>
<!-- Apache Commons Logging framework dependency -->
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
+ <!-- Mozilla JavaScript library dependency, licensed with
+ the Mozilla Public License Version 2.0 -->
+ <dependency>
+ <groupId>org.mozilla</groupId>
+ <artifactId>rhino</artifactId>
+ <version>1.7.15.1</version>
+ </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
diff --git a/src/main/java/org/apache/xalan/processor/XSLTAttributeDef.java b/src/main/java/org/apache/xalan/processor/XSLTAttributeDef.java
index 5e1cf953f..0af5c8295 100644
--- a/src/main/java/org/apache/xalan/processor/XSLTAttributeDef.java
+++ b/src/main/java/org/apache/xalan/processor/XSLTAttributeDef.java
@@ -27,7 +27,6 @@ import java.util.stream.IntStream;
import javax.xml.transform.SourceLocator;
import javax.xml.transform.TransformerException;
-import org.apache.xalan.extensions.ExtensionNamespaceContext;
import org.apache.xalan.res.XSLMessages;
import org.apache.xalan.res.XSLTErrorResources;
import org.apache.xalan.templates.AVT;
@@ -1061,22 +1060,22 @@ public class XSLTAttributeDef
if ((Constants.ATTRVAL_DEFAULT_PREFIX).equals(value)) {
// We use, an XML non-standard namespace for this QName object
// instance, because string #default is not a valid QName string.
- qname = new QName(ExtensionNamespaceContext.JAVA_EXT_URI, "default", true);
+ qname = new QName(Constants.S_EXTENSIONS_JAVA_URL, Constants.ATTRVAL_DEFAULT, true);
}
else if ((Constants.ATTRVAL_UNNAMED_PREFIX).equals(value)) {
// We use, an XML non-standard namespace for this QName object
// instance, because string #unnamed is not a valid QName string.
- qname = new QName(ExtensionNamespaceContext.JAVA_EXT_URI, "unnamed", true);
+ qname = new QName(Constants.S_EXTENSIONS_JAVA_URL, Constants.ATTRVAL_UNNAMED, true);
}
else if ((Constants.ATTRVAL_CURRENT_PREFIX).equals(value)) {
// We use, an XML non-standard namespace for this QName object
// instance, because string #current is not a valid QName string.
- qname = new QName(ExtensionNamespaceContext.JAVA_EXT_URI, "current", true);
+ qname = new QName(Constants.S_EXTENSIONS_JAVA_URL, Constants.ATTRVAL_CURRENT, true);
}
else if ((Constants.ATTRVAL_ALL_PREFIX).equals(value)) {
// We use, an XML non-standard namespace for this QName object
// instance, because string #all is not a valid QName string.
- qname = new QName(ExtensionNamespaceContext.JAVA_EXT_URI, "all", true);
+ qname = new QName(Constants.S_EXTENSIONS_JAVA_URL, Constants.ATTRVAL_ALL, true);
}
else {
qname = new QName(value, handler, true);
diff --git a/src/main/java/org/apache/xalan/templates/Constants.java b/src/main/java/org/apache/xalan/templates/Constants.java
index f9c9b40da..90a4baa41 100644
--- a/src/main/java/org/apache/xalan/templates/Constants.java
+++ b/src/main/java/org/apache/xalan/templates/Constants.java
@@ -493,6 +493,14 @@ public class Constants extends org.apache.xml.utils.Constants
public static final String ATTRVAL_FAIL = "fail".intern();
public static final String ATTRVAL_USE_LAST = "use-last".intern();
+ public static final String ATTRVAL_DEFAULT = "default";
+
+ public static final String ATTRVAL_UNNAMED = "unnamed";
+
+ public static final String ATTRVAL_CURRENT = "current";
+
+ public static final String ATTRVAL_ALL = "all";
+
// This is Xalan-J XSLT 3.0 string constant internal value, for an
// implementation of XPath 3.1 function fn:random-number-generator.
public static final String FN_XALAN_RNG_PERMUTE = "'FnXalanPermute'";
diff --git a/src/main/java/org/apache/xalan/templates/ElemApplyTemplates.java b/src/main/java/org/apache/xalan/templates/ElemApplyTemplates.java
index 05db7403a..8a63f7fa2 100644
--- a/src/main/java/org/apache/xalan/templates/ElemApplyTemplates.java
+++ b/src/main/java/org/apache/xalan/templates/ElemApplyTemplates.java
@@ -626,8 +626,8 @@ public class ElemApplyTemplates extends ElemCallTemplate
QName mode = transformer.getMode();
- QName qnameCurrent = new QName("http://xml.apache.org/xalan/java", "current", true);
- QName qnameUnnamed = new QName("http://xml.apache.org/xalan/java", "unnamed", true);
+ QName qnameCurrent = new QName(Constants.S_EXTENSIONS_JAVA_URL, Constants.ATTRVAL_CURRENT, true);
+ QName qnameUnnamed = new QName(Constants.S_EXTENSIONS_JAVA_URL, Constants.ATTRVAL_UNNAMED, true);
if (qnameCurrent.equals(mode)) {
mode = transformer.getCurrentMode();
}
diff --git a/src/main/java/org/apache/xalan/templates/TemplateSubPatternAssociation.java b/src/main/java/org/apache/xalan/templates/TemplateSubPatternAssociation.java
index 0be074c09..953dc8fad 100644
--- a/src/main/java/org/apache/xalan/templates/TemplateSubPatternAssociation.java
+++ b/src/main/java/org/apache/xalan/templates/TemplateSubPatternAssociation.java
@@ -140,8 +140,8 @@ public class TemplateSubPatternAssociation implements Serializable, Cloneable
{
boolean result = false;
- QName defaultMode = new QName("http://xml.apache.org/xalan/java", "default", true);
- QName modeAll = new QName("http://xml.apache.org/xalan/java", "all", true);
+ QName defaultMode = new QName(Constants.S_EXTENSIONS_JAVA_URL, Constants.ATTRVAL_DEFAULT, true);
+ QName modeAll = new QName(Constants.S_EXTENSIONS_JAVA_URL, Constants.ATTRVAL_ALL, true);
if (modeAll.equals(m2)) {
result = true;
diff --git a/src/main/java/org/apache/xalan/xslt/Process.java b/src/main/java/org/apache/xalan/xslt/Process.java
index e44351bd3..84996ae9a 100644
--- a/src/main/java/org/apache/xalan/xslt/Process.java
+++ b/src/main/java/org/apache/xalan/xslt/Process.java
@@ -57,7 +57,6 @@ import org.apache.xalan.templates.Constants;
import org.apache.xalan.templates.StylesheetRoot;
import org.apache.xalan.trace.PrintTraceListener;
import org.apache.xalan.trace.TraceManager;
-import org.apache.xalan.transformer.TransformerImpl;
import org.apache.xalan.transformer.XalanProperties;
import org.apache.xalan.xslt.util.XslTransformData;
import org.apache.xml.utils.DefaultErrorHandler;
@@ -855,14 +854,17 @@ public class Process
Transformer transformer = flavor.equals("th") ? null : stylesheet.newTransformer();
- if (null != xslFileName) {
- File file = new File(xslFileName);
- URI uri = file.toURI();
- ((TransformerImpl)transformer).setUriStrOfXslStylesheet(uri.toString());
- }
+ if (!useXSLTC) {
+ if (null != xslFileName) {
+ File file = new File(xslFileName);
+ URI uri = file.toURI();
+ ((org.apache.xalan.transformer.TransformerImpl)transformer).setUriStrOfXslStylesheet(uri.toString());
+ }
- if (isXslEvaluate) {
- ((TransformerImpl)transformer).setProperty(TransformerImpl.XSL_EVALUATE_PROPERTY, Boolean.TRUE);
+ if (isXslEvaluate) {
+ ((org.apache.xalan.transformer.TransformerImpl)transformer).setProperty(org.apache.xalan.transformer.TransformerImpl.
+ XSL_EVALUATE_PROPERTY, Boolean.TRUE);
+ }
}
transformer.setErrorListener(new DefaultErrorHandler(true));
diff --git a/src/main/java/org/apache/xalan/xsltc/CollatorFactory.java b/src/main/java/org/apache/xalan/xsltc/CollatorFactory.java
new file mode 100644
index 000000000..ad680b678
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/CollatorFactory.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc;
+
+import java.text.Collator;
+import java.util.Locale;
+
+/**
+ * @author W. Eliot Kimber (eliot@isogen.com)
+ * @author Santiago Pericas-Geertsen
+ */
+public interface CollatorFactory {
+
+ public Collator getCollator(String lang, String country);
+ public Collator getCollator(Locale locale);
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/DOM.java b/src/main/java/org/apache/xalan/xsltc/DOM.java
new file mode 100644
index 000000000..e252e1a18
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/DOM.java
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc;
+
+import org.apache.xalan.xsltc.runtime.Hashtable;
+import org.apache.xml.dtm.DTMAxisIterator;
+
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import org.apache.xml.serializer.SerializationHandler;
+
+/**
+ * @author Jacek Ambroziak
+ * @author Santiago Pericas-Geertsen
+ */
+public interface DOM {
+ public final static int FIRST_TYPE = 0;
+
+ public final static int NO_TYPE = -1;
+
+ // 0 is reserved for NodeIterator.END
+ public final static int NULL = 0;
+
+ // used by some node iterators to know which node to return
+ public final static int RETURN_CURRENT = 0;
+ public final static int RETURN_PARENT = 1;
+
+ // Constants used by getResultTreeFrag to indicate the types of the RTFs.
+ public final static int SIMPLE_RTF = 0;
+ public final static int ADAPTIVE_RTF = 1;
+ public final static int TREE_RTF = 2;
+
+ /** returns singleton iterator containg the document root */
+ public DTMAxisIterator getIterator();
+ public String getStringValue();
+
+ public DTMAxisIterator getChildren(final int node);
+ public DTMAxisIterator getTypedChildren(final int type);
+ public DTMAxisIterator getAxisIterator(final int axis);
+ public DTMAxisIterator getTypedAxisIterator(final int axis, final int type);
+ public DTMAxisIterator getNthDescendant(int node, int n, boolean includeself);
+ public DTMAxisIterator getNamespaceAxisIterator(final int axis, final int ns);
+ public DTMAxisIterator getNodeValueIterator(DTMAxisIterator iter, int returnType,
+ String value, boolean op);
+ public DTMAxisIterator orderNodes(DTMAxisIterator source, int node);
+ public String getNodeName(final int node);
+ public String getNodeNameX(final int node);
+ public String getNamespaceName(final int node);
+ public int getExpandedTypeID(final int node);
+ public int getNamespaceType(final int node);
+ public int getParent(final int node);
+ public int getAttributeNode(final int gType, final int element);
+ public String getStringValueX(final int node);
+ public void copy(final int node, SerializationHandler handler)
+ throws TransletException;
+ public void copy(DTMAxisIterator nodes, SerializationHandler handler)
+ throws TransletException;
+ public String shallowCopy(final int node, SerializationHandler handler)
+ throws TransletException;
+ public boolean lessThan(final int node1, final int node2);
+ public void characters(final int textNode, SerializationHandler handler)
+ throws TransletException;
+ public Node makeNode(int index);
+ public Node makeNode(DTMAxisIterator iter);
+ public NodeList makeNodeList(int index);
+ public NodeList makeNodeList(DTMAxisIterator iter);
+ public String getLanguage(int node);
+ public int getSize();
+ public String getDocumentURI(int node);
+ public void setFilter(StripFilter filter);
+ public void setupMapping(String[] names, String[] urisArray, int[] typesArray, String[] namespaces);
+ public boolean isElement(final int node);
+ public boolean isAttribute(final int node);
+ public String lookupNamespace(int node, String prefix)
+ throws TransletException;
+ public int getNodeIdent(final int nodehandle);
+ public int getNodeHandle(final int nodeId);
+ public DOM getResultTreeFrag(int initialSize, int rtfType);
+ public DOM getResultTreeFrag(int initialSize, int rtfType, boolean addToDTMManager);
+ public SerializationHandler getOutputDomBuilder();
+ public int getNSType(int node);
+ public int getDocument();
+ public String getUnparsedEntityURI(String name);
+ public Hashtable getElementsWithIDs();
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/DOMCache.java b/src/main/java/org/apache/xalan/xsltc/DOMCache.java
new file mode 100644
index 000000000..3f187ed4b
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/DOMCache.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc;
+
+
+/**
+ * @author Morten Jorgensen
+ */
+public interface DOMCache {
+
+ /**
+ * This method is responsible for:
+ *
+ * (1) building the DOMImpl tree
+ *
+ * Parser _parser = new Parser();
+ * DOMImpl _dom = new DOMImpl();
+ * _parser.setDocumentHandler(_dom.getBuilder());
+ * _parser.setDTDHandler(_dom.getBuilder());
+ * _parser.parse(uri);
+ *
+ * (2) giving the translet an early opportunity to extract anything from
+ * the DOMImpl that it would like
+ *
+ * translet.documentPrepass(_dom);
+ *
+ * (3) setting the document URI:
+ *
+ * _dom.setDocumentURI(uri);
+ *
+ * @param baseURI The base URI used by the document call.
+ * @param href The href argument passed to the document function.
+ * @param translet A reference to the translet requesting the document
+ */
+ public DOM retrieveDocument(String baseURI, String href, Translet translet);
+
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/DOMEnhancedForDTM.java b/src/main/java/org/apache/xalan/xsltc/DOMEnhancedForDTM.java
new file mode 100644
index 000000000..049b54429
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/DOMEnhancedForDTM.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+package org.apache.xalan.xsltc;
+
+/**
+ * Interface for SAXImpl which adds methods used at run-time, over and above
+ * those provided by the XSLTC DOM interface. An attempt to avoid the current
+ * "Is the DTM a DOM, if so is it a SAXImpl, . . .
+ * which was producing some ugly replicated code
+ * and introducing bugs where that multipathing had not been
+ * done. This makes it easier to provide other DOM/DOMEnhancedForDTM
+ * implementations, rather than hard-wiring XSLTC to SAXImpl.
+ *
+ * @author Joseph Kesselman
+ *
+ */
+public interface DOMEnhancedForDTM extends DOM {
+ public short[] getMapping(String[] names, String[] uris, int[] types);
+ public int[] getReverseMapping(String[] names, String[] uris, int[] types);
+ public short[] getNamespaceMapping(String[] namespaces);
+ public short[] getReverseNamespaceMapping(String[] namespaces);
+ public String getDocumentURI();
+ public void setDocumentURI(String uri);
+ public int getExpandedTypeID2(int nodeHandle);
+ public boolean hasDOMSource();
+ public int getElementById(String idString);
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/NodeIterator.java b/src/main/java/org/apache/xalan/xsltc/NodeIterator.java
new file mode 100644
index 000000000..c664e063e
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/NodeIterator.java
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc;
+
+import org.apache.xml.dtm.DTM;
+
+/**
+ * @author Jacek Ambroziak
+ * @author Santiago Pericas-Geertsen
+ */
+public interface NodeIterator extends Cloneable {
+ public static final int END = DTM.NULL;
+
+ /**
+ * Callers should not call next() after it returns END.
+ */
+ public int next();
+
+ /**
+ * Resets the iterator to the last start node.
+ */
+ public NodeIterator reset();
+
+ /**
+ * Returns the number of elements in this iterator.
+ */
+ public int getLast();
+
+ /**
+ * Returns the position of the current node in the set.
+ */
+ public int getPosition();
+
+ /**
+ * Remembers the current node for the next call to gotoMark().
+ */
+ public void setMark();
+
+ /**
+ * Restores the current node remembered by setMark().
+ */
+ public void gotoMark();
+
+ /**
+ * Set start to END should 'close' the iterator,
+ * i.e. subsequent call to next() should return END.
+ */
+ public NodeIterator setStartNode(int node);
+
+ /**
+ * True if this iterator has a reversed axis.
+ */
+ public boolean isReverse();
+
+ /**
+ * Returns a deep copy of this iterator.
+ */
+ public NodeIterator cloneIterator();
+
+ /**
+ * Prevents or allows iterator restarts.
+ */
+ public void setRestartable(boolean isRestartable);
+
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/ProcessorVersion.java b/src/main/java/org/apache/xalan/xsltc/ProcessorVersion.java
new file mode 100644
index 000000000..43c411f3d
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/ProcessorVersion.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc;
+
+
+/**
+ * Admin class that assigns a version number to the XSLTC software.
+ * The version number is made up from three fields as in:
+ * MAJOR.MINOR[.DELTA]. Fields are incremented based on the following:
+ * DELTA field: changes for each bug fix, developer fixing the bug should
+ * increment this field.
+ * MINOR field: API changes or a milestone culminating from several
+ * bug fixes. DELTA field goes to zero and MINOR is
+ * incremented such as: {1.0,1.0.1,1.0.2,1.0.3,...1.0.18,1.1}
+ * MAJOR field: milestone culminating in fundamental API changes or
+ * architectural changes. MINOR field goes to zero
+ * and MAJOR is incremented such as: {...,1.1.14,1.2,2.0}
+ * Stability of a release follows: X.0 > X.X > X.X.X
+ * @author G. Todd Miller
+ */
+public class ProcessorVersion {
+ private static int MAJOR = 1;
+ private static int MINOR = 0;
+ private static int DELTA = 0;
+
+ public static void main(String[] args) {
+ System.out.println("XSLTC version " + MAJOR + "." + MINOR +
+ ((DELTA > 0) ? ("."+DELTA) : ("")));
+ }
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/StripFilter.java b/src/main/java/org/apache/xalan/xsltc/StripFilter.java
new file mode 100644
index 000000000..8c59301a6
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/StripFilter.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc;
+
+
+/**
+ * @author Jacek Ambroziak
+ * @author Santiago Pericas-Geertsen
+ */
+public interface StripFilter {
+ public boolean stripSpace(DOM dom, int node, int type);
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/Translet.java b/src/main/java/org/apache/xalan/xsltc/Translet.java
new file mode 100644
index 000000000..eb1ef4e7f
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/Translet.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc;
+
+import org.apache.xml.dtm.DTMAxisIterator;
+import org.apache.xml.serializer.SerializationHandler;
+
+/**
+ * @author Jacek Ambroziak
+ * @author Santiago Pericas-Geertsen
+ */
+public interface Translet {
+
+ public void transform(DOM document, SerializationHandler handler)
+ throws TransletException;
+ public void transform(DOM document, SerializationHandler[] handlers)
+ throws TransletException;
+ public void transform(DOM document, DTMAxisIterator iterator,
+ SerializationHandler handler)
+ throws TransletException;
+
+ public Object addParameter(String name, Object value);
+
+ public void buildKeys(DOM document, DTMAxisIterator iterator,
+ SerializationHandler handler, int root)
+ throws TransletException;
+ public void addAuxiliaryClass(Class auxClass);
+ public Class getAuxiliaryClass(String className);
+ public String[] getNamesArray();
+ public String[] getUrisArray();
+ public int[] getTypesArray();
+ public String[] getNamespaceArray();
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/TransletException.java b/src/main/java/org/apache/xalan/xsltc/TransletException.java
new file mode 100644
index 000000000..93124dfd0
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/TransletException.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc;
+
+import org.xml.sax.SAXException;
+
+/**
+ * @author Jacek Ambroziak
+ * @author Santiago Pericas-Geertsen
+ * @author Morten Jorgensen
+ */
+public final class TransletException extends SAXException {
+ static final long serialVersionUID = -878916829521217293L;
+
+ public TransletException() {
+ super("Translet error");
+ }
+
+ public TransletException(Exception e) {
+ super(e.toString());
+ }
+
+ public TransletException(String message) {
+ super(message);
+ }
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/cmdline/Compile.java b/src/main/java/org/apache/xalan/xsltc/cmdline/Compile.java
new file mode 100644
index 000000000..c25fc1f37
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/cmdline/Compile.java
@@ -0,0 +1,153 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.cmdline;
+
+import java.io.File;
+import java.net.URL;
+import java.util.Vector;
+
+import org.apache.xalan.xsltc.cmdline.getopt.GetOpt;
+import org.apache.xalan.xsltc.cmdline.getopt.GetOptsException;
+import org.apache.xalan.xsltc.compiler.XSLTC;
+import org.apache.xalan.xsltc.compiler.util.ErrorMsg;
+
+/**
+ * @author Jacek Ambroziak
+ * @author Santiago Pericas-Geertsen
+ * @author G. Todd Miller
+ * @author Morten Jorgensen
+ */
+public final class Compile {
+
+ // Versioning numbers for the compiler -v option output
+ private static int VERSION_MAJOR = 1;
+ private static int VERSION_MINOR = 4;
+ private static int VERSION_DELTA = 0;
+
+
+ public static void printUsage() {
+ StringBuffer vers = new StringBuffer("XSLTC version " + VERSION_MAJOR
+ + "." + VERSION_MINOR
+ + ((VERSION_DELTA > 0) ? ("." + VERSION_DELTA) : ("")));
+ System.err.println(vers + "\n"
+ + new ErrorMsg(ErrorMsg.COMPILE_USAGE_STR));
+ }
+
+ /**
+ * This method implements the command line compiler. See the USAGE_STRING
+ * constant for a description. It may make sense to move the command-line
+ * handling to a separate package (ie. make one xsltc.cmdline.Compiler
+ * class that contains this main() method and one xsltc.cmdline.Transform
+ * class that contains the DefaultRun stuff).
+ */
+ public static void main(String[] args) {
+ try {
+ boolean inputIsURL = false;
+ boolean useStdIn = false;
+ boolean classNameSet = false;
+ final GetOpt getopt = new GetOpt(args, "o:d:j:p:uxhsinv");
+ if (args.length < 1) printUsage();
+
+ final XSLTC xsltc = new XSLTC();
+ xsltc.init();
+
+ int c;
+ while ((c = getopt.getNextOption()) != -1) {
+ switch(c) {
+ case 'i':
+ useStdIn = true;
+ break;
+ case 'o':
+ xsltc.setClassName(getopt.getOptionArg());
+ classNameSet = true;
+ break;
+ case 'd':
+ xsltc.setDestDirectory(getopt.getOptionArg());
+ break;
+ case 'p':
+ xsltc.setPackageName(getopt.getOptionArg());
+ break;
+ case 'j':
+ xsltc.setJarFileName(getopt.getOptionArg());
+ break;
+ case 'x':
+ xsltc.setDebug(true);
+ break;
+ case 'u':
+ inputIsURL = true;
+ break;
+ case 'n':
+ xsltc.setTemplateInlining(true); // used to be 'false'
+ break;
+ case 'v':
+ // fall through to case h
+ case 'h':
+ default:
+ printUsage();
+ break;
+ }
+ }
+
+ boolean compileOK;
+
+ if (useStdIn) {
+ if (!classNameSet) {
+ System.err.println(new ErrorMsg(ErrorMsg.COMPILE_STDIN_ERR));
+ }
+ compileOK = xsltc.compile(System.in, xsltc.getClassName());
+ }
+ else {
+ // Generate a vector containg URLs for all stylesheets specified
+ final String[] stylesheetNames = getopt.getCmdArgs();
+ final Vector stylesheetVector = new Vector();
+ for (int i = 0; i < stylesheetNames.length; i++) {
+ final String name = stylesheetNames[i];
+ URL url;
+ if (inputIsURL)
+ url = new URL(name);
+ else
+ url = (new File(name)).toURL();
+ stylesheetVector.addElement(url);
+ }
+ compileOK = xsltc.compile(stylesheetVector);
+ }
+
+ // Compile the stylesheet and output class/jar file(s)
+ if (compileOK) {
+ xsltc.printWarnings();
+ if (xsltc.getJarFileName() != null) xsltc.outputToJar();
+ }
+ else {
+ xsltc.printWarnings();
+ xsltc.printErrors();
+ }
+ }
+ catch (GetOptsException ex) {
+ System.err.println(ex);
+ printUsage();
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/cmdline/ObjectFactory.java b/src/main/java/org/apache/xalan/xsltc/cmdline/ObjectFactory.java
new file mode 100644
index 000000000..dca6cb560
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/cmdline/ObjectFactory.java
@@ -0,0 +1,656 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.cmdline;
+
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.File;
+import java.io.FileInputStream;
+
+import java.util.Properties;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+
+/**
+ * This class is duplicated for each JAXP subpackage so keep it in sync.
+ * It is package private and therefore is not exposed as part of the JAXP
+ * API.
+ * <p>
+ * This code is designed to implement the JAXP 1.1 spec pluggability
+ * feature and is designed to run on JDK version 1.1 and
+ * later, and to compile on JDK 1.2 and onward.
+ * The code also runs both as part of an unbundled jar file and
+ * when bundled as part of the JDK.
+ * <p>
+ * This class was moved from the <code>javax.xml.parsers.ObjectFactory</code>
+ * class and modified to be used as a general utility for creating objects
+ * dynamically.
+ *
+ * @version $Id$
+ */
+final class ObjectFactory {
+
+ //
+ // Constants
+ //
+
+ // name of default properties file to look for in JDK's jre/lib directory
+ private static final String DEFAULT_PROPERTIES_FILENAME =
+ "xalan.properties";
+
+ private static final String SERVICES_PATH = "META-INF/services/";
+
+ /** Set to true for debugging */
+ private static final boolean DEBUG = false;
+
+ /** cache the contents of the xalan.properties file.
+ * Until an attempt has been made to read this file, this will
+ * be null; if the file does not exist or we encounter some other error
+ * during the read, this will be empty.
+ */
+ private static Properties fXalanProperties = null;
+
+ /***
+ * Cache the time stamp of the xalan.properties file so
+ * that we know if it's been modified and can invalidate
+ * the cache when necessary.
+ */
+ private static long fLastModified = -1;
+
+ //
+ // Public static methods
+ //
+
+ /**
+ * Finds the implementation Class object in the specified order. The
+ * specified order is the following:
+ * <ol>
+ * <li>query the system property using <code>System.getProperty</code>
+ * <li>read <code>META-INF/services/<i>factoryId</i></code> file
+ * <li>use fallback classname
+ * </ol>
+ *
+ * @return instance of factory, never null
+ *
+ * @param factoryId Name of the factory to find, same as
+ * a property name
+ * @param fallbackClassName Implementation class name, if nothing else
+ * is found. Use null to mean no fallback.
+ *
+ * @exception ObjectFactory.ConfigurationError
+ */
+ static Object createObject(String factoryId, String fallbackClassName)
+ throws ConfigurationError {
+ return createObject(factoryId, null, fallbackClassName);
+ } // createObject(String,String):Object
+
+ /**
+ * Finds the implementation Class object in the specified order. The
+ * specified order is the following:
+ * <ol>
+ * <li>query the system property using <code>System.getProperty</code>
+ * <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
+ * <li>read <code>META-INF/services/<i>factoryId</i></code> file
+ * <li>use fallback classname
+ * </ol>
+ *
+ * @return instance of factory, never null
+ *
+ * @param factoryId Name of the factory to find, same as
+ * a property name
+ * @param propertiesFilename The filename in the $java.home/lib directory
+ * of the properties file. If none specified,
+ * ${java.home}/lib/xalan.properties will be used.
+ * @param fallbackClassName Implementation class name, if nothing else
+ * is found. Use null to mean no fallback.
+ *
+ * @exception ObjectFactory.ConfigurationError
+ */
+ static Object createObject(String factoryId,
+ String propertiesFilename,
+ String fallbackClassName)
+ throws ConfigurationError
+ {
+ Class factoryClass = lookUpFactoryClass(factoryId,
+ propertiesFilename,
+ fallbackClassName);
+
+ if (factoryClass == null) {
+ throw new ConfigurationError(
+ "Provider for " + factoryId + " cannot be found", null);
+ }
+
+ try{
+ Object instance = factoryClass.newInstance();
+ debugPrintln("created new instance of factory " + factoryId);
+ return instance;
+ } catch (Exception x) {
+ throw new ConfigurationError(
+ "Provider for factory " + factoryId
+ + " could not be instantiated: " + x, x);
+ }
+ } // createObject(String,String,String):Object
+
+ /**
+ * Finds the implementation Class object in the specified order. The
+ * specified order is the following:
+ * <ol>
+ * <li>query the system property using <code>System.getProperty</code>
+ * <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
+ * <li>read <code>META-INF/services/<i>factoryId</i></code> file
+ * <li>use fallback classname
+ * </ol>
+ *
+ * @return Class object of factory, never null
+ *
+ * @param factoryId Name of the factory to find, same as
+ * a property name
+ * @param propertiesFilename The filename in the $java.home/lib directory
+ * of the properties file. If none specified,
+ * ${java.home}/lib/xalan.properties will be used.
+ * @param fallbackClassName Implementation class name, if nothing else
+ * is found. Use null to mean no fallback.
+ *
+ * @exception ObjectFactory.ConfigurationError
+ */
+ static Class lookUpFactoryClass(String factoryId)
+ throws ConfigurationError
+ {
+ return lookUpFactoryClass(factoryId, null, null);
+ } // lookUpFactoryClass(String):Class
+
+ /**
+ * Finds the implementation Class object in the specified order. The
+ * specified order is the following:
+ * <ol>
+ * <li>query the system property using <code>System.getProperty</code>
+ * <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
+ * <li>read <code>META-INF/services/<i>factoryId</i></code> file
+ * <li>use fallback classname
+ * </ol>
+ *
+ * @return Class object that provides factory service, never null
+ *
+ * @param factoryId Name of the factory to find, same as
+ * a property name
+ * @param propertiesFilename The filename in the $java.home/lib directory
+ * of the properties file. If none specified,
+ * ${java.home}/lib/xalan.properties will be used.
+ * @param fallbackClassName Implementation class name, if nothing else
+ * is found. Use null to mean no fallback.
+ *
+ * @exception ObjectFactory.ConfigurationError
+ */
+ static Class lookUpFactoryClass(String factoryId,
+ String propertiesFilename,
+ String fallbackClassName)
+ throws ConfigurationError
+ {
+ String factoryClassName = lookUpFactoryClassName(factoryId,
+ propertiesFilename,
+ fallbackClassName);
+ ClassLoader cl = findClassLoader();
+
+ if (factoryClassName == null) {
+ factoryClassName = fallbackClassName;
+ }
+
+ // assert(className != null);
+ try{
+ Class providerClass = findProviderClass(factoryClassName,
+ cl,
+ true);
+ debugPrintln("created new instance of " + providerClass +
+ " using ClassLoader: " + cl);
+ return providerClass;
+ } catch (ClassNotFoundException x) {
+ throw new ConfigurationError(
+ "Provider " + factoryClassName + " not found", x);
+ } catch (Exception x) {
+ throw new ConfigurationError(
+ "Provider "+factoryClassName+" could not be instantiated: "+x,
+ x);
+ }
+ } // lookUpFactoryClass(String,String,String):Class
+
+ /**
+ * Finds the name of the required implementation class in the specified
+ * order. The specified order is the following:
+ * <ol>
+ * <li>query the system property using <code>System.getProperty</code>
+ * <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
+ * <li>read <code>META-INF/services/<i>factoryId</i></code> file
+ * <li>use fallback classname
+ * </ol>
+ *
+ * @return name of class that provides factory service, never null
+ *
+ * @param factoryId Name of the factory to find, same as
+ * a property name
+ * @param propertiesFilename The filename in the $java.home/lib directory
+ * of the properties file. If none specified,
+ * ${java.home}/lib/xalan.properties will be used.
+ * @param fallbackClassName Implementation class name, if nothing else
+ * is found. Use null to mean no fallback.
+ *
+ * @exception ObjectFactory.ConfigurationError
+ */
+ static String lookUpFactoryClassName(String factoryId,
+ String propertiesFilename,
+ String fallbackClassName)
+ {
+ // Use the system property first
+ try {
+ String systemProp = SecuritySupport.getSystemProperty(factoryId);
+ if (systemProp != null) {
+ debugPrintln("found system property, value=" + systemProp);
+ return systemProp;
+ }
+ } catch (SecurityException se) {
+ // Ignore and continue w/ next location
+ }
+
+ // Try to read from propertiesFilename, or
+ // $java.home/lib/xalan.properties
+ String factoryClassName = null;
+ // no properties file name specified; use
+ // $JAVA_HOME/lib/xalan.properties:
+ if (propertiesFilename == null) {
+ File propertiesFile = null;
+ boolean propertiesFileExists = false;
+ try {
+ String javah = SecuritySupport.getSystemProperty("java.home");
+ propertiesFilename = javah + File.separator +
+ "lib" + File.separator + DEFAULT_PROPERTIES_FILENAME;
+ propertiesFile = new File(propertiesFilename);
+ propertiesFileExists = SecuritySupport.getFileExists(propertiesFile);
+ } catch (SecurityException e) {
+ // try again...
+ fLastModified = -1;
+ fXalanProperties = null;
+ }
+
+ synchronized (ObjectFactory.class) {
+ boolean loadProperties = false;
+ FileInputStream fis = null;
+ try {
+ // file existed last time
+ if(fLastModified >= 0) {
+ if(propertiesFileExists &&
+ (fLastModified < (fLastModified = SecuritySupport.getLastModified(propertiesFile)))) {
+ loadProperties = true;
+ } else {
+ // file has stopped existing...
+ if(!propertiesFileExists) {
+ fLastModified = -1;
+ fXalanProperties = null;
+ } // else, file wasn't modified!
+ }
+ } else {
+ // file has started to exist:
+ if(propertiesFileExists) {
+ loadProperties = true;
+ fLastModified = SecuritySupport.getLastModified(propertiesFile);
+ } // else, nothing's changed
+ }
+ if(loadProperties) {
+ // must never have attempted to read xalan.properties
+ // before (or it's outdeated)
+ fXalanProperties = new Properties();
+ fis = SecuritySupport.getFileInputStream(propertiesFile);
+ fXalanProperties.load(fis);
+ }
+ } catch (Exception x) {
+ fXalanProperties = null;
+ fLastModified = -1;
+ // assert(x instanceof FileNotFoundException
+ // || x instanceof SecurityException)
+ // In both cases, ignore and continue w/ next location
+ }
+ finally {
+ // try to close the input stream if one was opened.
+ if (fis != null) {
+ try {
+ fis.close();
+ }
+ // Ignore the exception.
+ catch (IOException exc) {}
+ }
+ }
+ }
+ if(fXalanProperties != null) {
+ factoryClassName = fXalanProperties.getProperty(factoryId);
+ }
+ } else {
+ FileInputStream fis = null;
+ try {
+ fis = SecuritySupport.getFileInputStream(new File(propertiesFilename));
+ Properties props = new Properties();
+ props.load(fis);
+ factoryClassName = props.getProperty(factoryId);
+ } catch (Exception x) {
+ // assert(x instanceof FileNotFoundException
+ // || x instanceof SecurityException)
+ // In both cases, ignore and continue w/ next location
+ }
+ finally {
+ // try to close the input stream if one was opened.
+ if (fis != null) {
+ try {
+ fis.close();
+ }
+ // Ignore the exception.
+ catch (IOException exc) {}
+ }
+ }
+ }
+ if (factoryClassName != null) {
+ debugPrintln("found in " + propertiesFilename + ", value="
+ + factoryClassName);
+ return factoryClassName;
+ }
+
+ // Try Jar Service Provider Mechanism
+ return findJarServiceProviderName(factoryId);
+ } // lookUpFactoryClass(String,String):String
+
+ //
+ // Private static methods
+ //
+
+ /** Prints a message to standard error if debugging is enabled. */
+ private static void debugPrintln(String msg) {
+ if (DEBUG) {
+ System.err.println("JAXP: " + msg);
+ }
+ } // debugPrintln(String)
+
+ /**
+ * Figure out which ClassLoader to use. For JDK 1.2 and later use
+ * the context ClassLoader.
+ */
+ static ClassLoader findClassLoader()
+ throws ConfigurationError
+ {
+ // Figure out which ClassLoader to use for loading the provider
+ // class. If there is a Context ClassLoader then use it.
+ ClassLoader context = SecuritySupport.getContextClassLoader();
+ ClassLoader system = SecuritySupport.getSystemClassLoader();
+
+ ClassLoader chain = system;
+ while (true) {
+ if (context == chain) {
+ // Assert: we are on JDK 1.1 or we have no Context ClassLoader
+ // or any Context ClassLoader in chain of system classloader
+ // (including extension ClassLoader) so extend to widest
+ // ClassLoader (always look in system ClassLoader if Xalan
+ // is in boot/extension/system classpath and in current
+ // ClassLoader otherwise); normal classloaders delegate
+ // back to system ClassLoader first so this widening doesn't
+ // change the fact that context ClassLoader will be consulted
+ ClassLoader current = ObjectFactory.class.getClassLoader();
+
+ chain = system;
+ while (true) {
+ if (current == chain) {
+ // Assert: Current ClassLoader in chain of
+ // boot/extension/system ClassLoaders
+ return system;
+ }
+ if (chain == null) {
+ break;
+ }
+ chain = SecuritySupport.getParentClassLoader(chain);
+ }
+
+ // Assert: Current ClassLoader not in chain of
+ // boot/extension/system ClassLoaders
+ return current;
+ }
+
+ if (chain == null) {
+ // boot ClassLoader reached
+ break;
+ }
+
+ // Check for any extension ClassLoaders in chain up to
+ // boot ClassLoader
+ chain = SecuritySupport.getParentClassLoader(chain);
+ };
+
+ // Assert: Context ClassLoader not in chain of
+ // boot/extension/system ClassLoaders
+ return context;
+ } // findClassLoader():ClassLoader
+
+ /**
+ * Create an instance of a class using the specified ClassLoader
+ */
+ static Object newInstance(String className, ClassLoader cl,
+ boolean doFallback)
+ throws ConfigurationError
+ {
+ // assert(className != null);
+ try{
+ Class providerClass = findProviderClass(className, cl, doFallback);
+ Object instance = providerClass.newInstance();
+ debugPrintln("created new instance of " + providerClass +
+ " using ClassLoader: " + cl);
+ return instance;
+ } catch (ClassNotFoundException x) {
+ throw new ConfigurationError(
+ "Provider " + className + " not found", x);
+ } catch (Exception x) {
+ throw new ConfigurationError(
+ "Provider " + className + " could not be instantiated: " + x,
+ x);
+ }
+ }
+
+ /**
+ * Find a Class using the specified ClassLoader
+ */
+ static Class findProviderClass(String className, ClassLoader cl,
+ boolean doFallback)
+ throws ClassNotFoundException, ConfigurationError
+ {
+ //throw security exception if the calling thread is not allowed to access the
+ //class. Restrict the access to the package classes as specified in java.security policy.
+ SecurityManager security = System.getSecurityManager();
+ try{
+ if (security != null){
+ final int lastDot = className.lastIndexOf('.');
+ String packageName = className;
+ if (lastDot != -1) packageName = className.substring(0, lastDot);
+ security.checkPackageAccess(packageName);
+ }
+ }catch(SecurityException e){
+ throw e;
+ }
+
+ Class providerClass;
+ if (cl == null) {
+ // XXX Use the bootstrap ClassLoader. There is no way to
+ // load a class using the bootstrap ClassLoader that works
+ // in both JDK 1.1 and Java 2. However, this should still
+ // work b/c the following should be true:
+ //
+ // (cl == null) iff current ClassLoader == null
+ //
+ // Thus Class.forName(String) will use the current
+ // ClassLoader which will be the bootstrap ClassLoader.
+ providerClass = Class.forName(className);
+ } else {
+ try {
+ providerClass = cl.loadClass(className);
+ } catch (ClassNotFoundException x) {
+ if (doFallback) {
+ // Fall back to current classloader
+ ClassLoader current = ObjectFactory.class.getClassLoader();
+ if (current == null) {
+ providerClass = Class.forName(className);
+ } else if (cl != current) {
+ cl = current;
+ providerClass = cl.loadClass(className);
+ } else {
+ throw x;
+ }
+ } else {
+ throw x;
+ }
+ }
+ }
+
+ return providerClass;
+ }
+
+ /**
+ * Find the name of service provider using Jar Service Provider Mechanism
+ *
+ * @return instance of provider class if found or null
+ */
+ private static String findJarServiceProviderName(String factoryId)
+ {
+ String serviceId = SERVICES_PATH + factoryId;
+ InputStream is = null;
+
+ // First try the Context ClassLoader
+ ClassLoader cl = findClassLoader();
+
+ is = SecuritySupport.getResourceAsStream(cl, serviceId);
+
+ // If no provider found then try the current ClassLoader
+ if (is == null) {
+ ClassLoader current = ObjectFactory.class.getClassLoader();
+ if (cl != current) {
+ cl = current;
+ is = SecuritySupport.getResourceAsStream(cl, serviceId);
+ }
+ }
+
+ if (is == null) {
+ // No provider found
+ return null;
+ }
+
+ debugPrintln("found jar resource=" + serviceId +
+ " using ClassLoader: " + cl);
+
+ // Read the service provider name in UTF-8 as specified in
+ // the jar spec. Unfortunately this fails in Microsoft
+ // VJ++, which does not implement the UTF-8
+ // encoding. Theoretically, we should simply let it fail in
+ // that case, since the JVM is obviously broken if it
+ // doesn't support such a basic standard. But since there
+ // are still some users attempting to use VJ++ for
+ // development, we have dropped in a fallback which makes a
+ // second attempt using the platform's default encoding. In
+ // VJ++ this is apparently ASCII, which is a subset of
+ // UTF-8... and since the strings we'll be reading here are
+ // also primarily limited to the 7-bit ASCII range (at
+ // least, in English versions), this should work well
+ // enough to keep us on the air until we're ready to
+ // officially decommit from VJ++. [Edited comment from
+ // jkesselm]
+ BufferedReader rd;
+ try {
+ rd = new BufferedReader(new InputStreamReader(is, "UTF-8"));
+ } catch (java.io.UnsupportedEncodingException e) {
+ rd = new BufferedReader(new InputStreamReader(is));
+ }
+
+ String factoryClassName = null;
+ try {
+ // XXX Does not handle all possible input as specified by the
+ // Jar Service Provider specification
+ factoryClassName = rd.readLine();
+ } catch (IOException x) {
+ // No provider found
+ return null;
+ }
+ finally {
+ try {
+ // try to close the reader.
+ rd.close();
+ }
+ // Ignore the exception.
+ catch (IOException exc) {}
+ }
+
+ if (factoryClassName != null &&
+ ! "".equals(factoryClassName)) {
+ debugPrintln("found in resource, value="
+ + factoryClassName);
+
+ // Note: here we do not want to fall back to the current
+ // ClassLoader because we want to avoid the case where the
+ // resource file was found using one ClassLoader and the
+ // provider class was instantiated using a different one.
+ return factoryClassName;
+ }
+
+ // No provider found
+ return null;
+ }
+
+ //
+ // Classes
+ //
+
+ /**
+ * A configuration error.
+ */
+ static class ConfigurationError
+ extends Error {
+ static final long serialVersionUID = -6072257854297546607L;
+ //
+ // Data
+ //
+
+ /** Exception. */
+ private Exception exception;
+
+ //
+ // Constructors
+ //
+
+ /**
+ * Construct a new instance with the specified detail string and
+ * exception.
+ */
+ ConfigurationError(String msg, Exception x) {
+ super(msg);
+ this.exception = x;
+ } // <init>(String,Exception)
+
+ //
+ // Public methods
+ //
+
+ /** Returns the exception associated to this error. */
+ Exception getException() {
+ return exception;
+ } // getException():Exception
+
+ } // class ConfigurationError
+
+} // class ObjectFactory
diff --git a/src/main/java/org/apache/xalan/xsltc/cmdline/SecuritySupport.java b/src/main/java/org/apache/xalan/xsltc/cmdline/SecuritySupport.java
new file mode 100644
index 000000000..b9e01d5d2
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/cmdline/SecuritySupport.java
@@ -0,0 +1,144 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.cmdline;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
+/**
+ * This class is duplicated for each Xalan-Java subpackage so keep it in sync.
+ * It is package private and therefore is not exposed as part of the Xalan-Java
+ * API.
+ *
+ * Security related methods that only work on J2SE 1.2 and newer.
+ */
+final class SecuritySupport {
+
+ static ClassLoader getContextClassLoader() {
+ return (ClassLoader)
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ ClassLoader cl = null;
+ try {
+ cl = Thread.currentThread().getContextClassLoader();
+ } catch (SecurityException ex) { }
+ return cl;
+ }
+ });
+ }
+
+ static ClassLoader getSystemClassLoader() {
+ return (ClassLoader)
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ ClassLoader cl = null;
+ try {
+ cl = ClassLoader.getSystemClassLoader();
+ } catch (SecurityException ex) {}
+ return cl;
+ }
+ });
+ }
+
+ static ClassLoader getParentClassLoader(final ClassLoader cl) {
+ return (ClassLoader)
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ ClassLoader parent = null;
+ try {
+ parent = cl.getParent();
+ } catch (SecurityException ex) {}
+
+ // eliminate loops in case of the boot
+ // ClassLoader returning itself as a parent
+ return (parent == cl) ? null : parent;
+ }
+ });
+ }
+
+ static String getSystemProperty(final String propName) {
+ return (String)
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ return System.getProperty(propName);
+ }
+ });
+ }
+
+ static FileInputStream getFileInputStream(final File file)
+ throws FileNotFoundException
+ {
+ try {
+ return (FileInputStream)
+ AccessController.doPrivileged(new PrivilegedExceptionAction() {
+ public Object run() throws FileNotFoundException {
+ return new FileInputStream(file);
+ }
+ });
+ } catch (PrivilegedActionException e) {
+ throw (FileNotFoundException)e.getException();
+ }
+ }
+
+ static InputStream getResourceAsStream(final ClassLoader cl,
+ final String name)
+ {
+ return (InputStream)
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ InputStream ris;
+ if (cl == null) {
+ ris = ClassLoader.getSystemResourceAsStream(name);
+ } else {
+ ris = cl.getResourceAsStream(name);
+ }
+ return ris;
+ }
+ });
+ }
+
+ static boolean getFileExists(final File f) {
+ return ((Boolean)
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ return f.exists() ? Boolean.TRUE : Boolean.FALSE;
+ }
+ })).booleanValue();
+ }
+
+ static long getLastModified(final File f) {
+ return ((Long)
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ return new Long(f.lastModified());
+ }
+ })).longValue();
+ }
+
+ private SecuritySupport () {}
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/cmdline/Transform.java b/src/main/java/org/apache/xalan/xsltc/cmdline/Transform.java
new file mode 100644
index 000000000..b6694fc84
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/cmdline/Transform.java
@@ -0,0 +1,295 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.cmdline;
+
+import java.io.FileNotFoundException;
+import java.net.MalformedURLException;
+import java.net.UnknownHostException;
+import java.util.Vector;
+
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+import javax.xml.transform.sax.SAXSource;
+
+import org.apache.xalan.xsltc.TransletException;
+import org.apache.xalan.xsltc.compiler.util.ErrorMsg;
+import org.apache.xalan.xsltc.DOMEnhancedForDTM;
+import org.apache.xalan.xsltc.dom.XSLTCDTMManager;
+import org.apache.xalan.xsltc.runtime.AbstractTranslet;
+import org.apache.xalan.xsltc.runtime.Constants;
+import org.apache.xalan.xsltc.runtime.Parameter;
+import org.apache.xalan.xsltc.runtime.output.TransletOutputHandlerFactory;
+import org.apache.xml.serializer.SerializationHandler;
+
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+
+import org.apache.xalan.xsltc.StripFilter;
+import org.apache.xml.dtm.DTMWSFilter;
+import org.apache.xalan.xsltc.dom.DOMWSFilter;
+
+/**
+ * @author Jacek Ambroziak
+ * @author Santiago Pericas-Geertsen
+ * @author G. Todd Miller
+ * @author Morten Jorgensen
+ */
+final public class Transform {
+
+ private SerializationHandler _handler;
+
+ private String _fileName;
+ private String _className;
+ private String _jarFileSrc;
+ private boolean _isJarFileSpecified = false;
+ private Vector _params = null;
+ private boolean _uri, _debug;
+ private int _iterations;
+
+ public Transform(String className, String fileName,
+ boolean uri, boolean debug, int iterations) {
+ _fileName = fileName;
+ _className = className;
+ _uri = uri;
+ _debug = debug;
+ _iterations = iterations;
+ }
+
+ public String getFileName(){return _fileName;}
+ public String getClassName(){return _className;}
+
+ public void setParameters(Vector params) {
+ _params = params;
+ }
+
+ private void setJarFileInputSrc(boolean flag, String jarFile) {
+ // TODO: at this time we do not do anything with this
+ // information, attempts to add the jarfile to the CLASSPATH
+ // were successful via System.setProperty, but the effects
+ // were not visible to the running JVM. For now we add jarfile
+ // to CLASSPATH in the wrapper script that calls this program.
+ _isJarFileSpecified = flag;
+ // TODO verify jarFile exists...
+ _jarFileSrc = jarFile;
+ }
+
+ private void doTransform() {
+ try {
+ final Class clazz = ObjectFactory.findProviderClass(
+ _className, ObjectFactory.findClassLoader(), true);
+ final AbstractTranslet translet = (AbstractTranslet)clazz.newInstance();
+ translet.postInitialization();
+
+ // Create a SAX parser and get the XMLReader object it uses
+ final SAXParserFactory factory = SAXParserFactory.newInstance();
+ try {
+ factory.setFeature(Constants.NAMESPACE_FEATURE,true);
+ }
+ catch (Exception e) {
+ factory.setNamespaceAware(true);
+ }
+ final SAXParser parser = factory.newSAXParser();
+ final XMLReader reader = parser.getXMLReader();
+
+ // Set the DOM's DOM builder as the XMLReader's SAX2 content handler
+ XSLTCDTMManager dtmManager =
+ (XSLTCDTMManager)XSLTCDTMManager.getDTMManagerClass()
+ .newInstance();
+
+ DTMWSFilter wsfilter;
+ if (translet != null && translet instanceof StripFilter) {
+ wsfilter = new DOMWSFilter(translet);
+ } else {
+ wsfilter = null;
+ }
+
+ final DOMEnhancedForDTM dom =
+ (DOMEnhancedForDTM)dtmManager.getDTM(
+ new SAXSource(reader, new InputSource(_fileName)),
+ false, wsfilter, true, false, translet.hasIdCall());
+
+ dom.setDocumentURI(_fileName);
+ translet.prepassDocument(dom);
+
+ // Pass global parameters
+ int n = _params.size();
+ for (int i = 0; i < n; i++) {
+ Parameter param = (Parameter) _params.elementAt(i);
+ translet.addParameter(param._name, param._value);
+ }
+
+ // Transform the document
+ TransletOutputHandlerFactory tohFactory =
+ TransletOutputHandlerFactory.newInstance();
+ tohFactory.setOutputType(TransletOutputHandlerFactory.STREAM);
+ tohFactory.setEncoding(translet._encoding);
+ tohFactory.setOutputMethod(translet._method);
+
+ if (_iterations == -1) {
+ translet.transform(dom, tohFactory.getSerializationHandler());
+ }
+ else if (_iterations > 0) {
+ long mm = System.currentTimeMillis();
+ for (int i = 0; i < _iterations; i++) {
+ translet.transform(dom,
+ tohFactory.getSerializationHandler());
+ }
+ mm = System.currentTimeMillis() - mm;
+
+ System.err.println("\n<!--");
+ System.err.println(" transform = "
+ + (((double) mm) / ((double) _iterations))
+ + " ms");
+ System.err.println(" throughput = "
+ + (1000.0 / (((double) mm)
+ / ((double) _iterations)))
+ + " tps");
+ System.err.println("-->");
+ }
+ }
+ catch (TransletException e) {
+ if (_debug) e.printStackTrace();
+ System.err.println(new ErrorMsg(ErrorMsg.RUNTIME_ERROR_KEY)+
+ e.getMessage());
+ }
+ catch (RuntimeException e) {
+ if (_debug) e.printStackTrace();
+ System.err.println(new ErrorMsg(ErrorMsg.RUNTIME_ERROR_KEY)+
+ e.getMessage());
+ }
+ catch (FileNotFoundException e) {
+ if (_debug) e.printStackTrace();
+ ErrorMsg err = new ErrorMsg(ErrorMsg.FILE_NOT_FOUND_ERR, _fileName);
+ System.err.println(new ErrorMsg(ErrorMsg.RUNTIME_ERROR_KEY)+
+ err.toString());
+ }
+ catch (MalformedURLException e) {
+ if (_debug) e.printStackTrace();
+ ErrorMsg err = new ErrorMsg(ErrorMsg.INVALID_URI_ERR, _fileName);
+ System.err.println(new ErrorMsg(ErrorMsg.RUNTIME_ERROR_KEY)+
+ err.toString());
+ }
+ catch (ClassNotFoundException e) {
+ if (_debug) e.printStackTrace();
+ ErrorMsg err= new ErrorMsg(ErrorMsg.CLASS_NOT_FOUND_ERR,_className);
+ System.err.println(new ErrorMsg(ErrorMsg.RUNTIME_ERROR_KEY)+
+ err.toString());
+ }
+ catch (UnknownHostException e) {
+ if (_debug) e.printStackTrace();
+ ErrorMsg err = new ErrorMsg(ErrorMsg.INVALID_URI_ERR, _fileName);
+ System.err.println(new ErrorMsg(ErrorMsg.RUNTIME_ERROR_KEY)+
+ err.toString());
+ }
+ catch (SAXException e) {
+ Exception ex = e.getException();
+ if (_debug) {
+ if (ex != null) ex.printStackTrace();
+ e.printStackTrace();
+ }
+ System.err.print(new ErrorMsg(ErrorMsg.RUNTIME_ERROR_KEY));
+ if (ex != null)
+ System.err.println(ex.getMessage());
+ else
+ System.err.println(e.getMessage());
+ }
+ catch (Exception e) {
+ if (_debug) e.printStackTrace();
+ System.err.println(new ErrorMsg(ErrorMsg.RUNTIME_ERROR_KEY)+
+ e.getMessage());
+ }
+ }
+
+ public static void printUsage() {
+ System.err.println(new ErrorMsg(ErrorMsg.TRANSFORM_USAGE_STR));
+ }
+
+ public static void main(String[] args) {
+ try {
+ if (args.length > 0) {
+ int i;
+ int iterations = -1;
+ boolean uri = false, debug = false;
+ boolean isJarFileSpecified = false;
+ String jarFile = null;
+
+ // Parse options starting with '-'
+ for (i = 0; i < args.length && args[i].charAt(0) == '-'; i++) {
+ if (args[i].equals("-u")) {
+ uri = true;
+ }
+ else if (args[i].equals("-x")) {
+ debug = true;
+ }
+ else if (args[i].equals("-j")) {
+ isJarFileSpecified = true;
+ jarFile = args[++i];
+ }
+ else if (args[i].equals("-n")) {
+ try {
+ iterations = Integer.parseInt(args[++i]);
+ }
+ catch (NumberFormatException e) {
+ // ignore
+ }
+ }
+ else {
+ printUsage();
+ }
+ }
+
+ // Enough arguments left ?
+ if (args.length - i < 2) printUsage();
+
+ // Get document file and class name
+ Transform handler = new Transform(args[i+1], args[i], uri,
+ debug, iterations);
+ handler.setJarFileInputSrc(isJarFileSpecified, jarFile);
+
+ // Parse stylesheet parameters
+ Vector params = new Vector();
+ for (i += 2; i < args.length; i++) {
+ final int equal = args[i].indexOf('=');
+ if (equal > 0) {
+ final String name = args[i].substring(0, equal);
+ final String value = args[i].substring(equal+1);
+ params.addElement(new Parameter(name, value));
+ }
+ else {
+ printUsage();
+ }
+ }
+
+ if (i == args.length) {
+ handler.setParameters(params);
+ handler.doTransform();
+ }
+ } else {
+ printUsage();
+ }
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/cmdline/getopt/GetOpt.java b/src/main/java/org/apache/xalan/xsltc/cmdline/getopt/GetOpt.java
new file mode 100644
index 000000000..baacede99
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/cmdline/getopt/GetOpt.java
@@ -0,0 +1,254 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.cmdline.getopt;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.ListIterator;
+
+import org.apache.xalan.xsltc.compiler.util.ErrorMsg;
+
+
+/**
+* GetOpt is a Java equivalent to the C getopt() library function
+* discussed in man page getopt(3C). It provides command line
+* parsing for Java applications. It supports the most rules of the
+* command line standard (see man page intro(1)) including stacked
+* options such as '-sxm' (which is equivalent to -s -x -m); it
+* handles special '--' option that signifies the end of options.
+* Additionally this implementation of getopt will check for
+* mandatory arguments to options such as in the case of
+* '-d <file>' it will throw a MissingOptArgException if the
+* option argument '<file>' is not included on the commandline.
+* getopt(3C) does not check for this.
+ * @author G Todd Miller
+*/
+public class GetOpt{
+ public GetOpt(String[] args, String optString){
+ theOptions = new ArrayList();
+ int currOptIndex = 0;
+ theCmdArgs = new ArrayList();
+ theOptionMatcher = new OptionMatcher(optString);
+ // fill in the options list
+ for(int i=0; i<args.length; i++){
+ String token = args[i];
+ int tokenLength = token.length();
+ if(token.equals("--")){ // end of opts
+ currOptIndex = i+1; // set index of first operand
+ break; // end of options
+ }
+ else if(token.startsWith("-") && tokenLength == 2){
+ // simple option token such as '-s' found
+ theOptions.add(new Option(token.charAt(1)));
+ }
+ else if(token.startsWith("-") && tokenLength > 2){
+ // stacked options found, such as '-shm'
+ // iterate thru the tokens after the dash and
+ // add them to theOptions list
+ for(int j=1; j<tokenLength; j++){
+ theOptions.add(new Option(token.charAt(j)));
+ }
+ }
+ else if(!token.startsWith("-")){
+ // case 1- there are not options stored yet therefore
+ // this must be an command argument, not an option argument
+ if(theOptions.size() == 0){
+ currOptIndex = i;
+ break; // stop processing options
+ }
+ else {
+ // case 2-
+ // there are options stored, check to see if
+ // this arg belong to the last arg stored
+ int indexoflast=0;
+ indexoflast = theOptions.size()-1;
+ Option op = (Option)theOptions.get(indexoflast);
+ char opLetter = op.getArgLetter();
+ if(!op.hasArg() && theOptionMatcher.hasArg(opLetter)){
+ op.setArg(token);
+ }
+ else{
+ // case 3 -
+ // the last option stored does not take
+ // an argument, so again, this argument
+ // must be a command argument, not
+ // an option argument
+ currOptIndex = i;
+ break; // end of options
+ }
+ }
+ }// end option does not start with "-"
+ } // end for args loop
+
+ // attach an iterator to list of options
+ theOptionsIterator = theOptions.listIterator();
+
+ // options are done, now fill out cmd arg list with remaining args
+ for(int i=currOptIndex; i<args.length; i++){
+ String token = args[i];
+ theCmdArgs.add(token);
+ }
+ }
+
+
+ /**
+ * debugging routine to print out all options collected
+ */
+ public void printOptions(){
+ for(ListIterator it=theOptions.listIterator(); it.hasNext();){
+ Option opt = (Option)it.next();
+ System.out.print("OPT =" + opt.getArgLetter());
+ String arg = opt.getArgument();
+ if(arg != null){
+ System.out.print(" " + arg);
+ }
+ System.out.println();
+ }
+ }
+
+ /**
+ * gets the next option found in the commandline. Distinguishes
+ * between two bad cases, one case is when an illegal option
+ * is found, and then other case is when an option takes an
+ * argument but no argument was found for that option.
+ * If the option found was not declared in the optString, then
+ * an IllegalArgumentException will be thrown (case 1).
+ * If the next option found has been declared to take an argument,
+ * and no such argument exists, then a MissingOptArgException
+ * is thrown (case 2).
+ * @return int - the next option found.
+ * @throws IllegalArgumentException, MissingOptArgException.
+ */
+ public int getNextOption() throws IllegalArgumentException,
+ MissingOptArgException
+ {
+ int retval = -1;
+ if(theOptionsIterator.hasNext()){
+ theCurrentOption = (Option)theOptionsIterator.next();
+ char c = theCurrentOption.getArgLetter();
+ boolean shouldHaveArg = theOptionMatcher.hasArg(c);
+ String arg = theCurrentOption.getArgument();
+ if(!theOptionMatcher.match(c)) {
+ ErrorMsg msg = new ErrorMsg(ErrorMsg.ILLEGAL_CMDLINE_OPTION_ERR,
+ new Character(c));
+ throw (new IllegalArgumentException(msg.toString()));
+ }
+ else if(shouldHaveArg && (arg == null)) {
+ ErrorMsg msg = new ErrorMsg(ErrorMsg.CMDLINE_OPT_MISSING_ARG_ERR,
+ new Character(c));
+ throw (new MissingOptArgException(msg.toString()));
+ }
+ retval = c;
+ }
+ return retval;
+ }
+
+ /**
+ * gets the argument for the current parsed option. For example,
+ * in case of '-d <file>', if current option parsed is 'd' then
+ * getOptionArg() would return '<file>'.
+ * @return String - argument for current parsed option.
+ */
+ public String getOptionArg(){
+ String retval = null;
+ String tmp = theCurrentOption.getArgument();
+ char c = theCurrentOption.getArgLetter();
+ if(theOptionMatcher.hasArg(c)){
+ retval = tmp;
+ }
+ return retval;
+ }
+
+ /**
+ * gets list of the commandline arguments. For example, in command
+ * such as 'cmd -s -d file file2 file3 file4' with the usage
+ * 'cmd [-s] [-d <file>] <file>...', getCmdArgs() would return
+ * the list {file2, file3, file4}.
+ * @return String[] - list of command arguments that may appear
+ * after options and option arguments.
+ */
+ public String[] getCmdArgs(){
+ String[] retval = new String[theCmdArgs.size()];
+ int i=0;
+ for(ListIterator it=theCmdArgs.listIterator(); it.hasNext();){
+ retval[i++] = (String)it.next();
+ }
+ return retval;
+ }
+
+
+ private Option theCurrentOption = null;
+ private ListIterator theOptionsIterator;
+ private List theOptions = null;
+ private List theCmdArgs = null;
+ private OptionMatcher theOptionMatcher = null;
+
+ ///////////////////////////////////////////////////////////
+ //
+ // Inner Classes
+ //
+ ///////////////////////////////////////////////////////////
+
+ // inner class to model an option
+ static class Option{
+ private char theArgLetter;
+ private String theArgument = null;
+ public Option(char argLetter) { theArgLetter = argLetter; }
+ public void setArg(String arg) {
+ theArgument = arg;
+ }
+ public boolean hasArg() { return (theArgument != null); }
+ public char getArgLetter() { return theArgLetter; }
+ public String getArgument() { return theArgument; }
+ } // end class Option
+
+
+ // inner class to query optString for a possible option match,
+ // and whether or not a given legal option takes an argument.
+ //
+ static class OptionMatcher{
+ public OptionMatcher(String optString){
+ theOptString = optString;
+ }
+ public boolean match(char c){
+ boolean retval = false;
+ if(theOptString.indexOf(c) != -1){
+ retval = true;
+ }
+ return retval;
+ }
+ public boolean hasArg(char c){
+ boolean retval = false;
+ int index = theOptString.indexOf(c)+1;
+ if (index == theOptString.length()){
+ // reached end of theOptString
+ retval = false;
+ }
+ else if(theOptString.charAt(index) == ':'){
+ retval = true;
+ }
+ return retval;
+ }
+ private String theOptString = null;
+ } // end class OptionMatcher
+}// end class GetOpt
+
diff --git a/src/main/java/org/apache/xalan/xsltc/cmdline/getopt/GetOptsException.java b/src/main/java/org/apache/xalan/xsltc/cmdline/getopt/GetOptsException.java
new file mode 100644
index 000000000..85c7dbdb2
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/cmdline/getopt/GetOptsException.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.cmdline.getopt;
+
+/**
+ * @author G Todd Miller
+ */
+public class GetOptsException extends Exception{
+ static final long serialVersionUID = 8736874967183039804L;
+ public GetOptsException(String msg){
+ super(msg);
+ }
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/cmdline/getopt/IllegalArgumentException.java b/src/main/java/org/apache/xalan/xsltc/cmdline/getopt/IllegalArgumentException.java
new file mode 100644
index 000000000..4bd26c107
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/cmdline/getopt/IllegalArgumentException.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.cmdline.getopt;
+
+
+class IllegalArgumentException extends GetOptsException{
+ static final long serialVersionUID = 8642122427294793651L;
+ public IllegalArgumentException(String msg){
+ super(msg);
+ }
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/cmdline/getopt/MissingOptArgException.java b/src/main/java/org/apache/xalan/xsltc/cmdline/getopt/MissingOptArgException.java
new file mode 100644
index 000000000..7b1670df9
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/cmdline/getopt/MissingOptArgException.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.cmdline.getopt;
+
+
+/**
+ * @author G Todd Miller
+ */
+class MissingOptArgException extends GetOptsException{
+ static final long serialVersionUID = -1972471465394544822L;
+ public MissingOptArgException(String msg){
+ super(msg);
+ }
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/compiler/AbsoluteLocationPath.java b/src/main/java/org/apache/xalan/xsltc/compiler/AbsoluteLocationPath.java
new file mode 100644
index 000000000..dfd876a64
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/compiler/AbsoluteLocationPath.java
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.compiler;
+
+import org.apache.bcel.generic.ALOAD;
+import org.apache.bcel.generic.ASTORE;
+import org.apache.bcel.generic.ConstantPoolGen;
+import org.apache.bcel.generic.INVOKEINTERFACE;
+import org.apache.bcel.generic.INVOKESPECIAL;
+import org.apache.bcel.generic.InstructionList;
+import org.apache.bcel.generic.LocalVariableGen;
+import org.apache.bcel.generic.NEW;
+import org.apache.xalan.xsltc.compiler.util.ClassGenerator;
+import org.apache.xalan.xsltc.compiler.util.MethodGenerator;
+import org.apache.xalan.xsltc.compiler.util.NodeType;
+import org.apache.xalan.xsltc.compiler.util.Type;
+import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
+import org.apache.xalan.xsltc.compiler.util.Util;
+
+/**
+ * @author Jacek Ambroziak
+ * @author Santiago Pericas-Geertsen
+ */
+final class AbsoluteLocationPath extends Expression {
+ private Expression _path; // may be null
+
+ public AbsoluteLocationPath() {
+ _path = null;
+ }
+
+ public AbsoluteLocationPath(Expression path) {
+ _path = path;
+ if (path != null) {
+ _path.setParent(this);
+ }
+ }
+
+ public void setParser(Parser parser) {
+ super.setParser(parser);
+ if (_path != null) {
+ _path.setParser(parser);
+ }
+ }
+
+ public Expression getPath() {
+ return(_path);
+ }
+
+ public String toString() {
+ return "AbsoluteLocationPath(" +
+ (_path != null ? _path.toString() : "null") + ')';
+ }
+
+ public Type typeCheck(SymbolTable stable) throws TypeCheckError {
+ if (_path != null) {
+ final Type ptype = _path.typeCheck(stable);
+ if (ptype instanceof NodeType) { // promote to node-set
+ _path = new CastExpr(_path, Type.NodeSet);
+ }
+ }
+ return _type = Type.NodeSet;
+ }
+
+ public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
+ final ConstantPoolGen cpg = classGen.getConstantPool();
+ final InstructionList il = methodGen.getInstructionList();
+ if (_path != null) {
+ final int initAI = cpg.addMethodref(ABSOLUTE_ITERATOR,
+ "<init>",
+ "("
+ + NODE_ITERATOR_SIG
+ + ")V");
+
+ // Compile relative path iterator(s)
+ //
+ // Backwards branches are prohibited if an uninitialized object is
+ // on the stack by section 4.9.4 of the JVM Specification, 2nd Ed.
+ // We don't know whether this code might contain backwards branches,
+ // so we mustn't create the new object until after we've created
+ // this argument to its constructor. Instead we calculate the
+ // value of the argument to the constructor first, store it in
+ // a temporary variable, create the object and reload the argument
+ // from the temporary to avoid the problem.
+ _path.translate(classGen, methodGen);
+ LocalVariableGen relPathIterator
+ = methodGen.addLocalVariable("abs_location_path_tmp",
+ Util.getJCRefType(NODE_ITERATOR_SIG),
+ null, null);
+ relPathIterator.setStart(
+ il.append(new ASTORE(relPathIterator.getIndex())));
+
+ // Create new AbsoluteIterator
+ il.append(new NEW(cpg.addClass(ABSOLUTE_ITERATOR)));
+ il.append(DUP);
+ relPathIterator.setEnd(
+ il.append(new ALOAD(relPathIterator.getIndex())));
+
+ // Initialize AbsoluteIterator with iterator from the stack
+ il.append(new INVOKESPECIAL(initAI));
+ }
+ else {
+ final int gitr = cpg.addInterfaceMethodref(DOM_INTF,
+ "getIterator",
+ "()"+NODE_ITERATOR_SIG);
+ il.append(methodGen.loadDOM());
+ il.append(new INVOKEINTERFACE(gitr, 1));
+ }
+ }
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/compiler/AbsolutePathPattern.java b/src/main/java/org/apache/xalan/xsltc/compiler/AbsolutePathPattern.java
new file mode 100644
index 000000000..b8d69905e
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/compiler/AbsolutePathPattern.java
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.compiler;
+
+import org.apache.bcel.generic.BranchHandle;
+import org.apache.bcel.generic.ConstantPoolGen;
+import org.apache.bcel.generic.GOTO_W;
+import org.apache.bcel.generic.IF_ICMPEQ;
+import org.apache.bcel.generic.ILOAD;
+import org.apache.bcel.generic.INVOKEINTERFACE;
+import org.apache.bcel.generic.ISTORE;
+import org.apache.bcel.generic.InstructionHandle;
+import org.apache.bcel.generic.InstructionList;
+import org.apache.bcel.generic.LocalVariableGen;
+import org.apache.bcel.generic.PUSH;
+import org.apache.xalan.xsltc.compiler.util.ClassGenerator;
+import org.apache.xalan.xsltc.compiler.util.MethodGenerator;
+import org.apache.xalan.xsltc.compiler.util.Type;
+import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
+import org.apache.xalan.xsltc.compiler.util.Util;
+import org.apache.xml.dtm.DTM;
+
+/**
+ * @author Jacek Ambroziak
+ * @author Santiago Pericas-Geertsen
+ */
+final class AbsolutePathPattern extends LocationPathPattern {
+ private final RelativePathPattern _left; // may be null
+
+ public AbsolutePathPattern(RelativePathPattern left) {
+ _left = left;
+ if (left != null) {
+ left.setParent(this);
+ }
+ }
+
+ public void setParser(Parser parser) {
+ super.setParser(parser);
+ if (_left != null)
+ _left.setParser(parser);
+ }
+
+ public Type typeCheck(SymbolTable stable) throws TypeCheckError {
+ return _left == null ? Type.Root : _left.typeCheck(stable);
+ }
+
+ public boolean isWildcard() {
+ return false;
+ }
+
+ public StepPattern getKernelPattern() {
+ return _left != null ? _left.getKernelPattern() : null;
+ }
+
+ public void reduceKernelPattern() {
+ _left.reduceKernelPattern();
+ }
+
+ public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
+ final ConstantPoolGen cpg = classGen.getConstantPool();
+ final InstructionList il = methodGen.getInstructionList();
+
+ if (_left != null) {
+ if (_left instanceof StepPattern) {
+ final LocalVariableGen local =
+ // absolute path pattern temporary
+ methodGen.addLocalVariable2("apptmp",
+ Util.getJCRefType(NODE_SIG),
+ null);
+ il.append(DUP);
+ local.setStart(il.append(new ISTORE(local.getIndex())));
+ _left.translate(classGen, methodGen);
+ il.append(methodGen.loadDOM());
+ local.setEnd(il.append(new ILOAD(local.getIndex())));
+ methodGen.removeLocalVariable(local);
+ }
+ else {
+ _left.translate(classGen, methodGen);
+ }
+ }
+
+ final int getParent = cpg.addInterfaceMethodref(DOM_INTF,
+ GET_PARENT,
+ GET_PARENT_SIG);
+ final int getType = cpg.addInterfaceMethodref(DOM_INTF,
+ "getExpandedTypeID",
+ "(I)I");
+
+ InstructionHandle begin = il.append(methodGen.loadDOM());
+ il.append(SWAP);
+ il.append(new INVOKEINTERFACE(getParent, 2));
+ if (_left instanceof AncestorPattern) {
+ il.append(methodGen.loadDOM());
+ il.append(SWAP);
+ }
+ il.append(new INVOKEINTERFACE(getType, 2));
+ il.append(new PUSH(cpg, DTM.DOCUMENT_NODE));
+
+ final BranchHandle skip = il.append(new IF_ICMPEQ(null));
+ _falseList.add(il.append(new GOTO_W(null)));
+ skip.setTarget(il.append(NOP));
+
+ if (_left != null) {
+ _left.backPatchTrueList(begin);
+
+ /*
+ * If _left is an ancestor pattern, backpatch this pattern's false
+ * list to the loop that searches for more ancestors.
+ */
+ if (_left instanceof AncestorPattern) {
+ final AncestorPattern ancestor = (AncestorPattern) _left;
+ _falseList.backPatch(ancestor.getLoopHandle()); // clears list
+ }
+ _falseList.append(_left._falseList);
+ }
+ }
+
+ public String toString() {
+ return "absolutePathPattern(" + (_left != null ? _left.toString() : ")");
+ }
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/compiler/AlternativePattern.java b/src/main/java/org/apache/xalan/xsltc/compiler/AlternativePattern.java
new file mode 100644
index 000000000..b8fb0f066
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/compiler/AlternativePattern.java
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.compiler;
+
+import org.apache.bcel.generic.GOTO;
+import org.apache.bcel.generic.InstructionHandle;
+import org.apache.bcel.generic.InstructionList;
+import org.apache.xalan.xsltc.compiler.util.ClassGenerator;
+import org.apache.xalan.xsltc.compiler.util.MethodGenerator;
+import org.apache.xalan.xsltc.compiler.util.Type;
+import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
+
+/**
+ * @author Jacek Ambroziak
+ * @author Santiago Pericas-Geertsen
+ */
+final class AlternativePattern extends Pattern {
+ private final Pattern _left;
+ private final Pattern _right;
+
+ /**
+ * Construct an alternative pattern. The method <code>setParent</code>
+ * should not be called in this case.
+ */
+ public AlternativePattern(Pattern left, Pattern right) {
+ _left = left;
+ _right = right;
+ }
+
+ public void setParser(Parser parser) {
+ super.setParser(parser);
+ _left.setParser(parser);
+ _right.setParser(parser);
+ }
+
+ public Pattern getLeft() {
+ return _left;
+ }
+
+ public Pattern getRight() {
+ return _right;
+ }
+
+ /**
+ * The type of an '|' is not really defined, hence null is returned.
+ */
+ public Type typeCheck(SymbolTable stable) throws TypeCheckError {
+ _left.typeCheck(stable);
+ _right.typeCheck(stable);
+ return null;
+ }
+
+ public double getPriority() {
+ double left = _left.getPriority();
+ double right = _right.getPriority();
+
+ if (left < right)
+ return(left);
+ else
+ return(right);
+ }
+
+ public String toString() {
+ return "alternative(" + _left + ", " + _right + ')';
+ }
+
+ public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
+ final InstructionList il = methodGen.getInstructionList();
+
+ _left.translate(classGen, methodGen);
+ final InstructionHandle gotot = il.append(new GOTO(null));
+ il.append(methodGen.loadContextNode());
+ _right.translate(classGen, methodGen);
+
+ _left._trueList.backPatch(gotot);
+ _left._falseList.backPatch(gotot.getNext());
+
+ _trueList.append(_right._trueList.add(gotot));
+ _falseList.append(_right._falseList);
+ }
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/compiler/AncestorPattern.java b/src/main/java/org/apache/xalan/xsltc/compiler/AncestorPattern.java
new file mode 100644
index 000000000..625a6b0cb
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/compiler/AncestorPattern.java
@@ -0,0 +1,182 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.compiler;
+
+import org.apache.bcel.generic.BranchHandle;
+import org.apache.bcel.generic.ConstantPoolGen;
+import org.apache.bcel.generic.GOTO;
+import org.apache.bcel.generic.IFLT;
+import org.apache.bcel.generic.ILOAD;
+import org.apache.bcel.generic.INVOKEINTERFACE;
+import org.apache.bcel.generic.ISTORE;
+import org.apache.bcel.generic.InstructionHandle;
+import org.apache.bcel.generic.InstructionList;
+import org.apache.bcel.generic.LocalVariableGen;
+import org.apache.xalan.xsltc.compiler.util.ClassGenerator;
+import org.apache.xalan.xsltc.compiler.util.MethodGenerator;
+import org.apache.xalan.xsltc.compiler.util.Type;
+import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
+import org.apache.xalan.xsltc.compiler.util.Util;
+
+/**
+ * @author Jacek Ambroziak
+ * @author Santiago Pericas-Geertsen
+ * @author Erwin Bolwidt <ej...@klomp.org>
+ */
+final class AncestorPattern extends RelativePathPattern {
+
+ private final Pattern _left; // may be null
+ private final RelativePathPattern _right;
+ private InstructionHandle _loop;
+
+ public AncestorPattern(RelativePathPattern right) {
+ this(null, right);
+ }
+
+ public AncestorPattern(Pattern left, RelativePathPattern right) {
+ _left = left;
+ (_right = right).setParent(this);
+ if (left != null) {
+ left.setParent(this);
+ }
+ }
+
+ public InstructionHandle getLoopHandle() {
+ return _loop;
+ }
+
+ public void setParser(Parser parser) {
+ super.setParser(parser);
+ if (_left != null) {
+ _left.setParser(parser);
+ }
+ _right.setParser(parser);
+ }
+
+ public boolean isWildcard() {
+ //!!! can be wildcard
+ return false;
+ }
+
+ public StepPattern getKernelPattern() {
+ return _right.getKernelPattern();
+ }
+
+ public void reduceKernelPattern() {
+ _right.reduceKernelPattern();
+ }
+
+ public Type typeCheck(SymbolTable stable) throws TypeCheckError {
+ if (_left != null) {
+ _left.typeCheck(stable);
+ }
+ return _right.typeCheck(stable);
+ }
+
+ public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
+ InstructionHandle parent;
+ final ConstantPoolGen cpg = classGen.getConstantPool();
+ final InstructionList il = methodGen.getInstructionList();
+
+ /*
+ * The scope of this local var must be the entire method since
+ * a another pattern may decide to jump back into the loop
+ */
+ final LocalVariableGen local =
+ methodGen.addLocalVariable2("app", Util.getJCRefType(NODE_SIG),
+ il.getEnd());
+
+ final org.apache.bcel.generic.Instruction loadLocal =
+ new ILOAD(local.getIndex());
+ final org.apache.bcel.generic.Instruction storeLocal =
+ new ISTORE(local.getIndex());
+
+ if (_right instanceof StepPattern) {
+ il.append(DUP);
+ il.append(storeLocal);
+ _right.translate(classGen, methodGen);
+ il.append(methodGen.loadDOM());
+ il.append(loadLocal);
+ }
+ else {
+ _right.translate(classGen, methodGen);
+
+ if (_right instanceof AncestorPattern) {
+ il.append(methodGen.loadDOM());
+ il.append(SWAP);
+ }
+ }
+
+ if (_left != null) {
+ final int getParent = cpg.addInterfaceMethodref(DOM_INTF,
+ GET_PARENT,
+ GET_PARENT_SIG);
+ parent = il.append(new INVOKEINTERFACE(getParent, 2));
+
+ il.append(DUP);
+ il.append(storeLocal);
+ _falseList.add(il.append(new IFLT(null)));
+ il.append(loadLocal);
+
+ _left.translate(classGen, methodGen);
+
+ final SyntaxTreeNode p = getParent();
+ if (p == null || p instanceof Instruction ||
+ p instanceof TopLevelElement)
+ {
+ // do nothing
+ }
+ else {
+ il.append(loadLocal);
+ }
+
+ final BranchHandle exit = il.append(new GOTO(null));
+ _loop = il.append(methodGen.loadDOM());
+ il.append(loadLocal);
+ local.setEnd(_loop);
+ il.append(new GOTO(parent));
+ exit.setTarget(il.append(NOP));
+ _left.backPatchFalseList(_loop);
+
+ _trueList.append(_left._trueList);
+ }
+ else {
+ il.append(POP2);
+ }
+
+ /*
+ * If _right is an ancestor pattern, backpatch this pattern's false
+ * list to the loop that searches for more ancestors.
+ */
+ if (_right instanceof AncestorPattern) {
+ final AncestorPattern ancestor = (AncestorPattern) _right;
+ _falseList.backPatch(ancestor.getLoopHandle()); // clears list
+ }
+
+ _trueList.append(_right._trueList);
+ _falseList.append(_right._falseList);
+ }
+
+ public String toString() {
+ return "AncestorPattern(" + _left + ", " + _right + ')';
+ }
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/compiler/ApplyImports.java b/src/main/java/org/apache/xalan/xsltc/compiler/ApplyImports.java
new file mode 100644
index 000000000..8477b1976
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/compiler/ApplyImports.java
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.compiler;
+
+import org.apache.bcel.generic.ConstantPoolGen;
+import org.apache.bcel.generic.INVOKEVIRTUAL;
+import org.apache.bcel.generic.InstructionList;
+import org.apache.xalan.xsltc.compiler.util.ClassGenerator;
+import org.apache.xalan.xsltc.compiler.util.MethodGenerator;
+import org.apache.xalan.xsltc.compiler.util.Type;
+import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
+import org.apache.xalan.xsltc.compiler.util.Util;
+
+final class ApplyImports extends Instruction {
+
+ private QName _modeName;
+ private int _precedence;
+
+ public void display(int indent) {
+ indent(indent);
+ Util.println("ApplyTemplates");
+ indent(indent + IndentIncrement);
+ if (_modeName != null) {
+ indent(indent + IndentIncrement);
+ Util.println("mode " + _modeName);
+ }
+ }
+
+ /**
+ * Returns true if this <xsl:apply-imports/> element has parameters
+ */
+ public boolean hasWithParams() {
+ return hasContents();
+ }
+
+ /**
+ * Determine the lowest import precedence for any stylesheet imported
+ * or included by the stylesheet in which this <xsl:apply-imports/>
+ * element occured. The templates that are imported by the stylesheet in
+ * which this element occured will all have higher import precedence than
+ * the integer returned by this method.
+ */
+ private int getMinPrecedence(int max) {
+ // Move to root of include tree
+ Stylesheet includeRoot = getStylesheet();
+ while (includeRoot._includedFrom != null) {
+ includeRoot = includeRoot._includedFrom;
+ }
+
+ return includeRoot.getMinimumDescendantPrecedence();
+ }
+
+ /**
+ * Parse the attributes and contents of an <xsl:apply-imports/> element.
+ */
+ public void parseContents(Parser parser) {
+ // Indicate to the top-level stylesheet that all templates must be
+ // compiled into separate methods.
+ Stylesheet stylesheet = getStylesheet();
+ stylesheet.setTemplateInlining(false);
+
+ // Get the mode we are currently in (might not be any)
+ Template template = getTemplate();
+ _modeName = template.getModeName();
+ _precedence = template.getImportPrecedence();
+
+ parseChildren(parser); // with-params
+ }
+
+ /**
+ * Type-check the attributes/contents of an <xsl:apply-imports/> element.
+ */
+ public Type typeCheck(SymbolTable stable) throws TypeCheckError {
+ typeCheckContents(stable); // with-params
+ return Type.Void;
+ }
+
+ /**
+ * Translate call-template. A parameter frame is pushed only if
+ * some template in the stylesheet uses parameters.
+ */
+ public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
+ final Stylesheet stylesheet = classGen.getStylesheet();
+ final ConstantPoolGen cpg = classGen.getConstantPool();
+ final InstructionList il = methodGen.getInstructionList();
+ final int current = methodGen.getLocalIndex("current");
+
+ // Push the arguments that are passed to applyTemplates()
+ il.append(classGen.loadTranslet());
+ il.append(methodGen.loadDOM());
+ il.append(methodGen.loadIterator());
+ il.append(methodGen.loadHandler());
+ il.append(methodGen.loadCurrentNode());
+
+ // Push a new parameter frame in case imported template might expect
+ // parameters. The apply-imports has nothing that it can pass.
+ if (stylesheet.hasLocalParams()) {
+ il.append(classGen.loadTranslet());
+ final int pushFrame = cpg.addMethodref(TRANSLET_CLASS,
+ PUSH_PARAM_FRAME,
+ PUSH_PARAM_FRAME_SIG);
+ il.append(new INVOKEVIRTUAL(pushFrame));
+ }
+
+ // Get the [min,max> precedence of all templates imported under the
+ // current stylesheet
+ final int maxPrecedence = _precedence;
+ final int minPrecedence = getMinPrecedence(maxPrecedence);
+ final Mode mode = stylesheet.getMode(_modeName);
+
+ // Get name of appropriate apply-templates function for this
+ // xsl:apply-imports instruction
+ String functionName = mode.functionName(minPrecedence, maxPrecedence);
+
+ // Construct the translet class-name and the signature of the method
+ final String className = classGen.getStylesheet().getClassName();
+ final String signature = classGen.getApplyTemplatesSigForImport();
+ final int applyTemplates = cpg.addMethodref(className,
+ functionName,
+ signature);
+ il.append(new INVOKEVIRTUAL(applyTemplates));
+
+ // Pop any parameter frame that was pushed above.
+ if (stylesheet.hasLocalParams()) {
+ il.append(classGen.loadTranslet());
+ final int pushFrame = cpg.addMethodref(TRANSLET_CLASS,
+ POP_PARAM_FRAME,
+ POP_PARAM_FRAME_SIG);
+ il.append(new INVOKEVIRTUAL(pushFrame));
+ }
+ }
+
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/compiler/ApplyTemplates.java b/src/main/java/org/apache/xalan/xsltc/compiler/ApplyTemplates.java
new file mode 100644
index 000000000..9562147e7
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/compiler/ApplyTemplates.java
@@ -0,0 +1,202 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.compiler;
+
+import java.util.Enumeration;
+import java.util.Vector;
+
+import org.apache.bcel.generic.ConstantPoolGen;
+import org.apache.bcel.generic.INVOKEINTERFACE;
+import org.apache.bcel.generic.INVOKEVIRTUAL;
+import org.apache.bcel.generic.InstructionList;
+import org.apache.xalan.xsltc.compiler.util.ClassGenerator;
+import org.apache.xalan.xsltc.compiler.util.ErrorMsg;
+import org.apache.xalan.xsltc.compiler.util.MethodGenerator;
+import org.apache.xalan.xsltc.compiler.util.NodeSetType;
+import org.apache.xalan.xsltc.compiler.util.NodeType;
+import org.apache.xalan.xsltc.compiler.util.ReferenceType;
+import org.apache.xalan.xsltc.compiler.util.ResultTreeType;
+import org.apache.xalan.xsltc.compiler.util.Type;
+import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
+import org.apache.xalan.xsltc.compiler.util.Util;
+import org.apache.xml.utils.XML11Char;
+
+/**
+ * @author Jacek Ambroziak
+ * @author Santiago Pericas-Geertsen
+ */
+final class ApplyTemplates extends Instruction {
+ private Expression _select;
+ private Type _type = null;
+ private QName _modeName;
+ private String _functionName;
+
+ public void display(int indent) {
+ indent(indent);
+ Util.println("ApplyTemplates");
+ indent(indent + IndentIncrement);
+ Util.println("select " + _select.toString());
+ if (_modeName != null) {
+ indent(indent + IndentIncrement);
+ Util.println("mode " + _modeName);
+ }
+ }
+
+ public boolean hasWithParams() {
+ return hasContents();
+ }
+
+ public void parseContents(Parser parser) {
+ final String select = getAttribute("select");
+ final String mode = getAttribute("mode");
+
+ if (select.length() > 0) {
+ _select = parser.parseExpression(this, "select", null);
+
+ }
+
+ if (mode.length() > 0) {
+ if (!XML11Char.isXML11ValidQName(mode)) {
+ ErrorMsg err = new ErrorMsg(ErrorMsg.INVALID_QNAME_ERR, mode, this);
+ parser.reportError(Constants.ERROR, err);
+ }
+ _modeName = parser.getQNameIgnoreDefaultNs(mode);
+ }
+
+ // instantiate Mode if needed, cache (apply temp) function name
+ _functionName =
+ parser.getTopLevelStylesheet().getMode(_modeName).functionName();
+ parseChildren(parser);// with-params
+ }
+
+ public Type typeCheck(SymbolTable stable) throws TypeCheckError {
+ if (_select != null) {
+ _type = _select.typeCheck(stable);
+ if (_type instanceof NodeType || _type instanceof ReferenceType) {
+ _select = new CastExpr(_select, Type.NodeSet);
+ _type = Type.NodeSet;
+ }
+ if (_type instanceof NodeSetType||_type instanceof ResultTreeType) {
+ typeCheckContents(stable); // with-params
+ return Type.Void;
+ }
+ throw new TypeCheckError(this);
+ }
+ else {
+ typeCheckContents(stable); // with-params
+ return Type.Void;
+ }
+ }
+
+ /**
+ * Translate call-template. A parameter frame is pushed only if
+ * some template in the stylesheet uses parameters.
+ */
+ public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
+ boolean setStartNodeCalled = false;
+ final Stylesheet stylesheet = classGen.getStylesheet();
+ final ConstantPoolGen cpg = classGen.getConstantPool();
+ final InstructionList il = methodGen.getInstructionList();
+ final int current = methodGen.getLocalIndex("current");
+
+ // check if sorting nodes is required
+ final Vector sortObjects = new Vector();
+ final Enumeration children = elements();
+ while (children.hasMoreElements()) {
+ final Object child = children.nextElement();
+ if (child instanceof Sort) {
+ sortObjects.addElement(child);
+ }
+ }
+
+ // Push a new parameter frame
+ if (stylesheet.hasLocalParams() || hasContents()) {
+ il.append(classGen.loadTranslet());
+ final int pushFrame = cpg.addMethodref(TRANSLET_CLASS,
+ PUSH_PARAM_FRAME,
+ PUSH_PARAM_FRAME_SIG);
+ il.append(new INVOKEVIRTUAL(pushFrame));
+ // translate with-params
+ translateContents(classGen, methodGen);
+ }
+
+
+ il.append(classGen.loadTranslet());
+
+ // The 'select' expression is a result-tree
+ if ((_type != null) && (_type instanceof ResultTreeType)) {
+ // <xsl:sort> cannot be applied to a result tree - issue warning
+ if (sortObjects.size() > 0) {
+ ErrorMsg err = new ErrorMsg(ErrorMsg.RESULT_TREE_SORT_ERR,this);
+ getParser().reportError(WARNING, err);
+ }
+ // Put the result tree (a DOM adapter) on the stack
+ _select.translate(classGen, methodGen);
+ // Get back the DOM and iterator (not just iterator!!!)
+ _type.translateTo(classGen, methodGen, Type.NodeSet);
+ }
+ else {
+ il.append(methodGen.loadDOM());
+
+ // compute node iterator for applyTemplates
+ if (sortObjects.size() > 0) {
+ Sort.translateSortIterator(classGen, methodGen,
+ _select, sortObjects);
+ int setStartNode = cpg.addInterfaceMethodref(NODE_ITERATOR,
+ SET_START_NODE,
+ "(I)"+
+ NODE_ITERATOR_SIG);
+ il.append(methodGen.loadCurrentNode());
+ il.append(new INVOKEINTERFACE(setStartNode,2));
+ setStartNodeCalled = true;
+ }
+ else {
+ if (_select == null)
+ Mode.compileGetChildren(classGen, methodGen, current);
+ else
+ _select.translate(classGen, methodGen);
+ }
+ }
+
+ if (_select != null && !setStartNodeCalled) {
+ _select.startIterator(classGen, methodGen);
+ }
+
+ //!!! need to instantiate all needed modes
+ final String className = classGen.getStylesheet().getClassName();
+ il.append(methodGen.loadHandler());
+ final String applyTemplatesSig = classGen.getApplyTemplatesSig();
+ final int applyTemplates = cpg.addMethodref(className,
+ _functionName,
+ applyTemplatesSig);
+ il.append(new INVOKEVIRTUAL(applyTemplates));
+
+ // Pop parameter frame
+ if (stylesheet.hasLocalParams() || hasContents()) {
+ il.append(classGen.loadTranslet());
+ final int popFrame = cpg.addMethodref(TRANSLET_CLASS,
+ POP_PARAM_FRAME,
+ POP_PARAM_FRAME_SIG);
+ il.append(new INVOKEVIRTUAL(popFrame));
+ }
+ }
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/compiler/ArgumentList.java b/src/main/java/org/apache/xalan/xsltc/compiler/ArgumentList.java
new file mode 100644
index 000000000..225a95c4f
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/compiler/ArgumentList.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.compiler;
+
+/**
+ * @author Jacek Ambroziak
+ * @author Santiago Pericas-Geertsen
+ */
+final class ArgumentList {
+ private final Expression _arg;
+ private final ArgumentList _rest;
+
+ public ArgumentList(Expression arg, ArgumentList rest) {
+ _arg = arg;
+ _rest = rest;
+ }
+
+ public String toString() {
+ return _rest == null
+ ? _arg.toString()
+ : _arg.toString() + ", " + _rest.toString();
+ }
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/compiler/Attribute.java b/src/main/java/org/apache/xalan/xsltc/compiler/Attribute.java
new file mode 100644
index 000000000..d24577d63
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/compiler/Attribute.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.compiler;
+
+import org.apache.xalan.xsltc.compiler.util.Util;
+
+/**
+ * @author Jacek Ambroziak
+ * @author Santiago Pericas-Geertsen
+ */
+final class Attribute extends Instruction {
+ private QName _name;
+
+ public void display(int indent) {
+ indent(indent);
+ Util.println("Attribute " + _name);
+ displayContents(indent + IndentIncrement);
+ }
+
+ public void parseContents(Parser parser) {
+ _name = parser.getQName(getAttribute("name"));
+ parseChildren(parser);
+ //!!! add text nodes
+ //!!! take care of value templates
+ }
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/compiler/AttributeSet.java b/src/main/java/org/apache/xalan/xsltc/compiler/AttributeSet.java
new file mode 100644
index 000000000..1900bb0a0
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/compiler/AttributeSet.java
@@ -0,0 +1,206 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.compiler;
+
+import java.util.Enumeration;
+import java.util.Vector;
+
+import org.apache.bcel.generic.ConstantPoolGen;
+import org.apache.bcel.generic.INVOKESPECIAL;
+import org.apache.bcel.generic.InstructionList;
+import org.apache.xalan.xsltc.compiler.util.AttributeSetMethodGenerator;
+import org.apache.xalan.xsltc.compiler.util.ClassGenerator;
+import org.apache.xalan.xsltc.compiler.util.ErrorMsg;
+import org.apache.xalan.xsltc.compiler.util.MethodGenerator;
+import org.apache.xalan.xsltc.compiler.util.Type;
+import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
+import org.apache.xalan.xsltc.compiler.util.Util;
+import org.apache.xml.utils.XML11Char;
+
+/**
+ * @author Jacek Ambroziak
+ * @author Santiago Pericas-Geertsen
+ * @author Morten Jorgensen
+ */
+final class AttributeSet extends TopLevelElement {
+
+ // This prefix is used for the method name of attribute set methods
+ private static final String AttributeSetPrefix = "$as$";
+
+ // Element contents
+ private QName _name;
+ private UseAttributeSets _useSets;
+ private AttributeSet _mergeSet;
+ private String _method;
+ private boolean _ignore = false;
+
+ /**
+ * Returns the QName of this attribute set
+ */
+ public QName getName() {
+ return _name;
+ }
+
+ /**
+ * Returns the method name of this attribute set. This method name is
+ * generated by the compiler (XSLTC)
+ */
+ public String getMethodName() {
+ return _method;
+ }
+
+ /**
+ * Call this method to prevent a method for being compiled for this set.
+ * This is used in case several <xsl:attribute-set...> elements constitute
+ * a single set (with one name). The last element will merge itself with
+ * any previous set(s) with the same name and disable the other set(s).
+ */
+ public void ignore() {
+ _ignore = true;
+ }
+
+ /**
+ * Parse the contents of this attribute set. Recognised attributes are
+ * "name" (required) and "use-attribute-sets" (optional).
+ */
+ public void parseContents(Parser parser) {
+
+ // Get this attribute set's name
+ final String name = getAttribute("name");
+
+ if (!XML11Char.isXML11ValidQName(name)) {
+ ErrorMsg err = new ErrorMsg(ErrorMsg.INVALID_QNAME_ERR, name, this);
+ parser.reportError(Constants.ERROR, err);
+ }
+ _name = parser.getQNameIgnoreDefaultNs(name);
+ if ((_name == null) || (_name.equals(EMPTYSTRING))) {
+ ErrorMsg msg = new ErrorMsg(ErrorMsg.UNNAMED_ATTRIBSET_ERR, this);
+ parser.reportError(Constants.ERROR, msg);
+ }
+
+ // Get any included attribute sets (similar to inheritance...)
+ final String useSets = getAttribute("use-attribute-sets");
+ if (useSets.length() > 0) {
+ if (!Util.isValidQNames(useSets)) {
+ ErrorMsg err = new ErrorMsg(ErrorMsg.INVALID_QNAME_ERR, useSets, this);
+ parser.reportError(Constants.ERROR, err);
+ }
+ _useSets = new UseAttributeSets(useSets, parser);
+ }
+
+ // Parse the contents of this node. All child elements must be
+ // <xsl:attribute> elements. Other elements cause an error.
+ final Vector contents = getContents();
+ final int count = contents.size();
+ for (int i=0; i<count; i++) {
+ SyntaxTreeNode child = (SyntaxTreeNode)contents.elementAt(i);
+ if (child instanceof XslAttribute) {
+ parser.getSymbolTable().setCurrentNode(child);
+ child.parseContents(parser);
+ }
+ else if (child instanceof Text) {
+ // ignore
+ }
+ else {
+ ErrorMsg msg = new ErrorMsg(ErrorMsg.ILLEGAL_CHILD_ERR, this);
+ parser.reportError(Constants.ERROR, msg);
+ }
+ }
+
+ // Point the symbol table back at us...
+ parser.getSymbolTable().setCurrentNode(this);
+ }
+
+ /**
+ * Type check the contents of this element
+ */
+ public Type typeCheck(SymbolTable stable) throws TypeCheckError {
+
+ if (_ignore) return (Type.Void);
+
+ // _mergeSet Point to any previous definition of this attribute set
+ _mergeSet = stable.addAttributeSet(this);
+
+ _method = AttributeSetPrefix + getXSLTC().nextAttributeSetSerial();
+
+ if (_useSets != null) _useSets.typeCheck(stable);
+ typeCheckContents(stable);
+ return Type.Void;
+ }
+
+ /**
+ * Compile a method that outputs the attributes in this set
+ */
+ public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
+
+ if (_ignore) return;
+
+ // Create a new method generator for an attribute set method
+ methodGen = new AttributeSetMethodGenerator(_method, classGen);
+
+ // Generate a reference to previous attribute-set definitions with the
+ // same name first. Those later in the stylesheet take precedence.
+ if (_mergeSet != null) {
+ final ConstantPoolGen cpg = classGen.getConstantPool();
+ final InstructionList il = methodGen.getInstructionList();
+ final String methodName = _mergeSet.getMethodName();
+
+ il.append(classGen.loadTranslet());
+ il.append(methodGen.loadDOM());
+ il.append(methodGen.loadIterator());
+ il.append(methodGen.loadHandler());
+ final int method = cpg.addMethodref(classGen.getClassName(),
+ methodName, ATTR_SET_SIG);
+ il.append(new INVOKESPECIAL(method));
+ }
+
+ // Translate other used attribute sets first, as local attributes
+ // take precedence (last attributes overrides first)
+ if (_useSets != null) _useSets.translate(classGen, methodGen);
+
+ // Translate all local attributes
+ final Enumeration attributes = elements();
+ while (attributes.hasMoreElements()) {
+ SyntaxTreeNode element = (SyntaxTreeNode)attributes.nextElement();
+ if (element instanceof XslAttribute) {
+ final XslAttribute attribute = (XslAttribute)element;
+ attribute.translate(classGen, methodGen);
+ }
+ }
+ final InstructionList il = methodGen.getInstructionList();
+ il.append(RETURN);
+
+ classGen.addMethod(methodGen);
+ }
+
+ public String toString() {
+ StringBuffer buf = new StringBuffer("attribute-set: ");
+ // Translate all local attributes
+ final Enumeration attributes = elements();
+ while (attributes.hasMoreElements()) {
+ final XslAttribute attribute =
+ (XslAttribute)attributes.nextElement();
+ buf.append(attribute);
+ }
+ return(buf.toString());
+ }
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/compiler/AttributeValue.java b/src/main/java/org/apache/xalan/xsltc/compiler/AttributeValue.java
new file mode 100644
index 000000000..833e218b0
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/compiler/AttributeValue.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.compiler;
+
+
+/**
+ * @author Jacek Ambroziak
+ * @author Santiago Pericas-Geertsen
+ */
+abstract class AttributeValue extends Expression {
+
+ public static final AttributeValue create(SyntaxTreeNode parent,
+ String text, Parser parser) {
+
+ AttributeValue result;
+ if (text.indexOf('{') != -1) {
+ result = new AttributeValueTemplate(text, parser, parent);
+ }
+ else if (text.indexOf('}') != -1) {
+ result = new AttributeValueTemplate(text, parser, parent);
+ }
+ else {
+ result = new SimpleAttributeValue(text);
+ result.setParser(parser);
+ result.setParent(parent);
+ }
+ return result;
+ }
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/compiler/AttributeValueTemplate.java b/src/main/java/org/apache/xalan/xsltc/compiler/AttributeValueTemplate.java
new file mode 100644
index 000000000..2b5f6b850
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/compiler/AttributeValueTemplate.java
@@ -0,0 +1,261 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.compiler;
+
+import java.util.Enumeration;
+import java.util.Vector;
+import java.util.StringTokenizer;
+import java.util.NoSuchElementException;
+
+import org.apache.bcel.generic.ConstantPoolGen;
+import org.apache.bcel.generic.INVOKESPECIAL;
+import org.apache.bcel.generic.INVOKEVIRTUAL;
+import org.apache.bcel.generic.Instruction;
+import org.apache.bcel.generic.InstructionList;
+import org.apache.bcel.generic.NEW;
+import org.apache.xalan.xsltc.compiler.util.ClassGenerator;
+import org.apache.xalan.xsltc.compiler.util.ErrorMsg;
+import org.apache.xalan.xsltc.compiler.util.MethodGenerator;
+import org.apache.xalan.xsltc.compiler.util.Type;
+import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
+
+/**
+ * @author Jacek Ambroziak
+ * @author Santiago Pericas-Geertsen
+ */
+final class AttributeValueTemplate extends AttributeValue {
+
+ final static int OUT_EXPR = 0;
+ final static int IN_EXPR = 1;
+ final static int IN_EXPR_SQUOTES = 2;
+ final static int IN_EXPR_DQUOTES = 3;
+ final static String DELIMITER = "\uFFFE"; // A Unicode nonchar
+
+ public AttributeValueTemplate(String value, Parser parser,
+ SyntaxTreeNode parent)
+ {
+ setParent(parent);
+ setParser(parser);
+
+ try {
+ parseAVTemplate(value, parser);
+ }
+ catch (NoSuchElementException e) {
+ reportError(parent, parser,
+ ErrorMsg.ATTR_VAL_TEMPLATE_ERR, value);
+ }
+ }
+
+ /**
+ * Two-pass parsing of ATVs. In the first pass, double curly braces are
+ * replaced by one, and expressions are delimited using DELIMITER. The
+ * second pass splits up the resulting buffer into literal and non-literal
+ * expressions. Errors are reported during the first pass.
+ */
+ private void parseAVTemplate(String text, Parser parser) {
+ StringTokenizer tokenizer =
+ new StringTokenizer(text, "{}\"\'", true);
+
+ /*
+ * First pass: replace double curly braces and delimit expressions
+ * Simple automaton to parse ATVs, delimit expressions and report
+ * errors.
+ */
+ String t = null;
+ String lookahead = null;
+ StringBuffer buffer = new StringBuffer();
+ int state = OUT_EXPR;
+
+ while (tokenizer.hasMoreTokens()) {
+ // Use lookahead if available
+ if (lookahead != null) {
+ t = lookahead;
+ lookahead = null;
+ }
+ else {
+ t = tokenizer.nextToken();
+ }
+
+ if (t.length() == 1) {
+ switch (t.charAt(0)) {
+ case '{':
+ switch (state) {
+ case OUT_EXPR:
+ lookahead = tokenizer.nextToken();
+ if (lookahead.equals("{")) {
+ buffer.append(lookahead); // replace {{ by {
+ lookahead = null;
+ }
+ else {
+ buffer.append(DELIMITER);
+ state = IN_EXPR;
+ }
+ break;
+ case IN_EXPR:
+ case IN_EXPR_SQUOTES:
+ case IN_EXPR_DQUOTES:
+ reportError(getParent(), parser,
+ ErrorMsg.ATTR_VAL_TEMPLATE_ERR, text);
+ break;
+ }
+ break;
+ case '}':
+ switch (state) {
+ case OUT_EXPR:
+ lookahead = tokenizer.nextToken();
+ if (lookahead.equals("}")) {
+ buffer.append(lookahead); // replace }} by }
+ lookahead = null;
+ }
+ else {
+ reportError(getParent(), parser,
+ ErrorMsg.ATTR_VAL_TEMPLATE_ERR, text);
+ }
+ break;
+ case IN_EXPR:
+ buffer.append(DELIMITER);
+ state = OUT_EXPR;
+ break;
+ case IN_EXPR_SQUOTES:
+ case IN_EXPR_DQUOTES:
+ buffer.append(t);
+ break;
+ }
+ break;
+ case '\'':
+ switch (state) {
+ case IN_EXPR:
+ state = IN_EXPR_SQUOTES;
+ break;
+ case IN_EXPR_SQUOTES:
+ state = IN_EXPR;
+ break;
+ case OUT_EXPR:
+ case IN_EXPR_DQUOTES:
+ break;
+ }
+ buffer.append(t);
+ break;
+ case '\"':
+ switch (state) {
+ case IN_EXPR:
+ state = IN_EXPR_DQUOTES;
+ break;
+ case IN_EXPR_DQUOTES:
+ state = IN_EXPR;
+ break;
+ case OUT_EXPR:
+ case IN_EXPR_SQUOTES:
+ break;
+ }
+ buffer.append(t);
+ break;
+ default:
+ buffer.append(t);
+ break;
+ }
+ }
+ else {
+ buffer.append(t);
+ }
+ }
+
+ // Must be in OUT_EXPR at the end of parsing
+ if (state != OUT_EXPR) {
+ reportError(getParent(), parser,
+ ErrorMsg.ATTR_VAL_TEMPLATE_ERR, text);
+ }
+
+ /*
+ * Second pass: split up buffer into literal and non-literal expressions.
+ */
+ tokenizer = new StringTokenizer(buffer.toString(), DELIMITER, true);
+
+ while (tokenizer.hasMoreTokens()) {
+ t = tokenizer.nextToken();
+
+ if (t.equals(DELIMITER)) {
+ addElement(parser.parseExpression(this, tokenizer.nextToken()));
+ tokenizer.nextToken(); // consume other delimiter
+ }
+ else {
+ addElement(new LiteralExpr(t));
+ }
+ }
+ }
+
+ public Type typeCheck(SymbolTable stable) throws TypeCheckError {
+ final Vector contents = getContents();
+ final int n = contents.size();
+ for (int i = 0; i < n; i++) {
+ final Expression exp = (Expression)contents.elementAt(i);
+ if (!exp.typeCheck(stable).identicalTo(Type.String)) {
+ contents.setElementAt(new CastExpr(exp, Type.String), i);
+ }
+ }
+ return _type = Type.String;
+ }
+
+ public String toString() {
+ final StringBuffer buffer = new StringBuffer("AVT:[");
+ final int count = elementCount();
+ for (int i = 0; i < count; i++) {
+ buffer.append(elementAt(i).toString());
+ if (i < count - 1)
+ buffer.append(' ');
+ }
+ return buffer.append(']').toString();
+ }
+
+ public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
+ if (elementCount() == 1) {
+ final Expression exp = (Expression)elementAt(0);
+ exp.translate(classGen, methodGen);
+ }
+ else {
+ final ConstantPoolGen cpg = classGen.getConstantPool();
+ final InstructionList il = methodGen.getInstructionList();
+ final int initBuffer = cpg.addMethodref(STRING_BUFFER_CLASS,
+ "<init>", "()V");
+ final Instruction append =
+ new INVOKEVIRTUAL(cpg.addMethodref(STRING_BUFFER_CLASS,
+ "append",
+ "(" + STRING_SIG + ")"
+ + STRING_BUFFER_SIG));
+
+ final int toString = cpg.addMethodref(STRING_BUFFER_CLASS,
+ "toString",
+ "()"+STRING_SIG);
+ il.append(new NEW(cpg.addClass(STRING_BUFFER_CLASS)));
+ il.append(DUP);
+ il.append(new INVOKESPECIAL(initBuffer));
+ // StringBuffer is on the stack
+ final Enumeration elements = elements();
+ while (elements.hasMoreElements()) {
+ final Expression exp = (Expression)elements.nextElement();
+ exp.translate(classGen, methodGen);
+ il.append(append);
+ }
+ il.append(new INVOKEVIRTUAL(toString));
+ }
+ }
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/compiler/BinOpExpr.java b/src/main/java/org/apache/xalan/xsltc/compiler/BinOpExpr.java
new file mode 100644
index 000000000..04bc90b29
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/compiler/BinOpExpr.java
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.compiler;
+
+import org.apache.bcel.generic.InstructionList;
+import org.apache.xalan.xsltc.compiler.util.ClassGenerator;
+import org.apache.xalan.xsltc.compiler.util.ErrorMsg;
+import org.apache.xalan.xsltc.compiler.util.MethodGenerator;
+import org.apache.xalan.xsltc.compiler.util.MethodType;
+import org.apache.xalan.xsltc.compiler.util.Type;
+import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
+
+/**
+ * @author Jacek Ambroziak
+ * @author Santiago Pericas-Geertsen
+ */
+final class BinOpExpr extends Expression {
+ public static final int PLUS = 0;
+ public static final int MINUS = 1;
+ public static final int TIMES = 2;
+ public static final int DIV = 3;
+ public static final int MOD = 4;
+
+ private static final String[] Ops = {
+ "+", "-", "*", "/", "%"
+ };
+
+ private int _op;
+ private Expression _left, _right;
+
+ public BinOpExpr(int op, Expression left, Expression right) {
+ _op = op;
+ (_left = left).setParent(this);
+ (_right = right).setParent(this);
+ }
+
+ /**
+ * Returns true if this expressions contains a call to position(). This is
+ * needed for context changes in node steps containing multiple predicates.
+ */
+ public boolean hasPositionCall() {
+ if (_left.hasPositionCall()) return true;
+ if (_right.hasPositionCall()) return true;
+ return false;
+ }
+
+ /**
+ * Returns true if this expressions contains a call to last()
+ */
+ public boolean hasLastCall() {
+ return (_left.hasLastCall() || _right.hasLastCall());
+ }
+
+ public void setParser(Parser parser) {
+ super.setParser(parser);
+ _left.setParser(parser);
+ _right.setParser(parser);
+ }
+
+ public Type typeCheck(SymbolTable stable) throws TypeCheckError {
+ final Type tleft = _left.typeCheck(stable);
+ final Type tright = _right.typeCheck(stable);
+ final MethodType ptype = lookupPrimop(stable, Ops[_op],
+ new MethodType(Type.Void,
+ tleft, tright));
+ if (ptype != null) {
+ final Type arg1 = (Type) ptype.argsType().elementAt(0);
+ if (!arg1.identicalTo(tleft)) {
+ _left = new CastExpr(_left, arg1);
+ }
+ final Type arg2 = (Type) ptype.argsType().elementAt(1);
+ if (!arg2.identicalTo(tright)) {
+ _right = new CastExpr(_right, arg1);
+ }
+ return _type = ptype.resultType();
+ }
+ throw new TypeCheckError(this);
+ }
+
+ public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
+ final InstructionList il = methodGen.getInstructionList();
+
+ _left.translate(classGen, methodGen);
+ _right.translate(classGen, methodGen);
+
+ switch (_op) {
+ case PLUS:
+ il.append(_type.ADD());
+ break;
+ case MINUS:
+ il.append(_type.SUB());
+ break;
+ case TIMES:
+ il.append(_type.MUL());
+ break;
+ case DIV:
+ il.append(_type.DIV());
+ break;
+ case MOD:
+ il.append(_type.REM());
+ break;
+ default:
+ ErrorMsg msg = new ErrorMsg(ErrorMsg.ILLEGAL_BINARY_OP_ERR, this);
+ getParser().reportError(Constants.ERROR, msg);
+ }
+ }
+
+ public String toString() {
+ return Ops[_op] + '(' + _left + ", " + _right + ')';
+ }
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/compiler/BooleanCall.java b/src/main/java/org/apache/xalan/xsltc/compiler/BooleanCall.java
new file mode 100644
index 000000000..7d0e1b637
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/compiler/BooleanCall.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.compiler;
+
+import java.util.Vector;
+
+import org.apache.xalan.xsltc.compiler.util.ClassGenerator;
+import org.apache.xalan.xsltc.compiler.util.MethodGenerator;
+import org.apache.xalan.xsltc.compiler.util.Type;
+import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
+
+/**
+ * @author Jacek Ambroziak
+ * @author Santiago Pericas-Geertsen
+ */
+final class BooleanCall extends FunctionCall {
+
+ private Expression _arg = null;
+
+ public BooleanCall(QName fname, Vector arguments) {
+ super(fname, arguments);
+ _arg = argument(0);
+ }
+
+ public Type typeCheck(SymbolTable stable) throws TypeCheckError {
+ _arg.typeCheck(stable);
+ return _type = Type.Boolean;
+ }
+
+ public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
+ _arg.translate(classGen, methodGen);
+ final Type targ = _arg.getType();
+ if (!targ.identicalTo(Type.Boolean)) {
+ _arg.startIterator(classGen, methodGen);
+ targ.translateTo(classGen, methodGen, Type.Boolean);
+ }
+ }
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/compiler/BooleanExpr.java b/src/main/java/org/apache/xalan/xsltc/compiler/BooleanExpr.java
new file mode 100644
index 000000000..fca3d1a1d
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/compiler/BooleanExpr.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.compiler;
+
+import org.apache.bcel.generic.ConstantPoolGen;
+import org.apache.bcel.generic.GOTO;
+import org.apache.bcel.generic.InstructionList;
+import org.apache.bcel.generic.PUSH;
+import org.apache.xalan.xsltc.compiler.util.ClassGenerator;
+import org.apache.xalan.xsltc.compiler.util.MethodGenerator;
+import org.apache.xalan.xsltc.compiler.util.Type;
+import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
+
+/**
+ * This class implements inlined calls to the XSLT standard functions
+ * true() and false().
+ * @author Jacek Ambroziak
+ * @author Santiago Pericas-Geertsen
+ */
+final class BooleanExpr extends Expression {
+ private boolean _value;
+
+ public BooleanExpr(boolean value) {
+ _value = value;
+ }
+
+ public Type typeCheck(SymbolTable stable) throws TypeCheckError {
+ _type = Type.Boolean;
+ return _type;
+ }
+
+ public String toString() {
+ return _value ? "true()" : "false()";
+ }
+
+ public boolean getValue() {
+ return _value;
+ }
+
+ public boolean contextDependent() {
+ return false;
+ }
+
+ public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
+ ConstantPoolGen cpg = classGen.getConstantPool();
+ InstructionList il = methodGen.getInstructionList();
+ il.append(new PUSH(cpg, _value));
+ }
+
+ public void translateDesynthesized(ClassGenerator classGen,
+ MethodGenerator methodGen) {
+ final InstructionList il = methodGen.getInstructionList();
+ if (_value) {
+ il.append(NOP); // true list falls through
+ }
+ else {
+ _falseList.add(il.append(new GOTO(null)));
+ }
+ }
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/compiler/CallTemplate.java b/src/main/java/org/apache/xalan/xsltc/compiler/CallTemplate.java
new file mode 100644
index 000000000..37edeab19
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/compiler/CallTemplate.java
@@ -0,0 +1,238 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.compiler;
+
+import java.util.Vector;
+
+import org.apache.bcel.generic.ConstantPoolGen;
+import org.apache.bcel.generic.INVOKEVIRTUAL;
+import org.apache.bcel.generic.InstructionList;
+import org.apache.xalan.xsltc.compiler.util.ClassGenerator;
+import org.apache.xalan.xsltc.compiler.util.ErrorMsg;
+import org.apache.xalan.xsltc.compiler.util.MethodGenerator;
+import org.apache.xalan.xsltc.compiler.util.Type;
+import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
+import org.apache.xalan.xsltc.compiler.util.Util;
+import org.apache.xml.utils.XML11Char;
+
+/**
+ * @author Jacek Ambroziak
+ * @author Santiago Pericas-Geertsen
+ * @author Erwin Bolwidt <ej...@klomp.org>
+ */
+final class CallTemplate extends Instruction {
+
+ /**
+ * Name of template to call.
+ */
+ private QName _name;
+
+ /**
+ * The array of effective parameters in this CallTemplate. An object in
+ * this array can be either a WithParam or a Param if no WithParam
+ * exists for a particular parameter.
+ */
+ private Object[] _parameters = null;
+
+ /**
+ * The corresponding template which this CallTemplate calls.
+ */
+ private Template _calleeTemplate = null;
+
+ public void display(int indent) {
+ indent(indent);
+ System.out.print("CallTemplate");
+ Util.println(" name " + _name);
+ displayContents(indent + IndentIncrement);
+ }
+
+ public boolean hasWithParams() {
+ return elementCount() > 0;
+ }
+
+ public void parseContents(Parser parser) {
+ final String name = getAttribute("name");
+ if (name.length() > 0) {
+ if (!XML11Char.isXML11ValidQName(name)) {
+ ErrorMsg err = new ErrorMsg(ErrorMsg.INVALID_QNAME_ERR, name, this);
+ parser.reportError(Constants.ERROR, err);
+ }
+ _name = parser.getQNameIgnoreDefaultNs(name);
+ }
+ else {
+ reportError(this, parser, ErrorMsg.REQUIRED_ATTR_ERR, "name");
+ }
+ parseChildren(parser);
+ }
+
+ /**
+ * Verify that a template with this name exists.
+ */
+ public Type typeCheck(SymbolTable stable) throws TypeCheckError {
+ final Template template = stable.lookupTemplate(_name);
+ if (template != null) {
+ typeCheckContents(stable);
+ }
+ else {
+ ErrorMsg err = new ErrorMsg(ErrorMsg.TEMPLATE_UNDEF_ERR,_name,this);
+ throw new TypeCheckError(err);
+ }
+ return Type.Void;
+ }
+
+ public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
+ final Stylesheet stylesheet = classGen.getStylesheet();
+ final ConstantPoolGen cpg = classGen.getConstantPool();
+ final InstructionList il = methodGen.getInstructionList();
+
+ // If there are Params in the stylesheet or WithParams in this call?
+ if (stylesheet.hasLocalParams() || hasContents()) {
+ _calleeTemplate = getCalleeTemplate();
+
+ // Build the parameter list if the called template is simple named
+ if (_calleeTemplate != null) {
+ buildParameterList();
+ }
+ // This is only needed when the called template is not
+ // a simple named template.
+ else {
+ // Push parameter frame
+ final int push = cpg.addMethodref(TRANSLET_CLASS,
+ PUSH_PARAM_FRAME,
+ PUSH_PARAM_FRAME_SIG);
+ il.append(classGen.loadTranslet());
+ il.append(new INVOKEVIRTUAL(push));
+ translateContents(classGen, methodGen);
+ }
+ }
+
+ // Generate a valid Java method name
+ final String className = stylesheet.getClassName();
+ String methodName = Util.escape(_name.toString());
+
+ // Load standard arguments
+ il.append(classGen.loadTranslet());
+ il.append(methodGen.loadDOM());
+ il.append(methodGen.loadIterator());
+ il.append(methodGen.loadHandler());
+ il.append(methodGen.loadCurrentNode());
+
+ // Initialize prefix of method signature
+ StringBuffer methodSig = new StringBuffer("(" + DOM_INTF_SIG
+ + NODE_ITERATOR_SIG + TRANSLET_OUTPUT_SIG + NODE_SIG);
+
+ // If calling a simply named template, push actual arguments
+ if (_calleeTemplate != null) {
+ Vector calleeParams = _calleeTemplate.getParameters();
+ int numParams = _parameters.length;
+
+ for (int i = 0; i < numParams; i++) {
+ SyntaxTreeNode node = (SyntaxTreeNode)_parameters[i];
+ methodSig.append(OBJECT_SIG); // append Object to signature
+
+ // Push 'null' if Param to indicate no actual parameter specified
+ if (node instanceof Param) {
+ il.append(ACONST_NULL);
+ }
+ else { // translate WithParam
+ node.translate(classGen, methodGen);
+ }
+ }
+ }
+
+ // Complete signature and generate invokevirtual call
+ methodSig.append(")V");
+ il.append(new INVOKEVIRTUAL(cpg.addMethodref(className,
+ methodName,
+ methodSig.toString())));
+
+ // Do not need to call Translet.popParamFrame() if we are
+ // calling a simple named template.
+ if (_calleeTemplate == null && (stylesheet.hasLocalParams() || hasContents())) {
+ // Pop parameter frame
+ final int pop = cpg.addMethodref(TRANSLET_CLASS,
+ POP_PARAM_FRAME,
+ POP_PARAM_FRAME_SIG);
+ il.append(classGen.loadTranslet());
+ il.append(new INVOKEVIRTUAL(pop));
+ }
+ }
+
+ /**
+ * Return the simple named template which this CallTemplate calls.
+ * Return false if there is no matched template or the matched
+ * template is not a simple named template.
+ */
+ public Template getCalleeTemplate() {
+ Template foundTemplate
+ = getXSLTC().getParser().getSymbolTable().lookupTemplate(_name);
+
+ return foundTemplate.isSimpleNamedTemplate() ? foundTemplate : null;
+ }
+
+ /**
+ * Build the list of effective parameters in this CallTemplate.
+ * The parameters of the called template are put into the array first.
+ * Then we visit the WithParam children of this CallTemplate and replace
+ * the Param with a corresponding WithParam having the same name.
+ */
+ private void buildParameterList() {
+ // Put the parameters from the called template into the array first.
+ // This is to ensure the order of the parameters.
+ Vector defaultParams = _calleeTemplate.getParameters();
+ int numParams = defaultParams.size();
+ _parameters = new Object[numParams];
+ for (int i = 0; i < numParams; i++) {
+ _parameters[i] = defaultParams.elementAt(i);
+ }
+
+ // Replace a Param with a WithParam if they have the same name.
+ int count = elementCount();
+ for (int i = 0; i < count; i++) {
+ Object node = elementAt(i);
+
+ // Ignore if not WithParam
+ if (node instanceof WithParam) {
+ WithParam withParam = (WithParam)node;
+ QName name = withParam.getName();
+
+ // Search for a Param with the same name
+ for (int k = 0; k < numParams; k++) {
+ Object object = _parameters[k];
+ if (object instanceof Param
+ && ((Param)object).getName().equals(name)) {
+ withParam.setDoParameterOptimization(true);
+ _parameters[k] = withParam;
+ break;
+ }
+ else if (object instanceof WithParam
+ && ((WithParam)object).getName().equals(name)) {
+ withParam.setDoParameterOptimization(true);
+ _parameters[k] = withParam;
+ break;
+ }
+ }
+ }
+ }
+ }
+}
+
diff --git a/src/main/java/org/apache/xalan/xsltc/compiler/CastCall.java b/src/main/java/org/apache/xalan/xsltc/compiler/CastCall.java
new file mode 100644
index 000000000..fd2690494
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/compiler/CastCall.java
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.compiler;
+
+import java.util.Vector;
+
+import org.apache.bcel.generic.ConstantPoolGen;
+import org.apache.bcel.generic.CHECKCAST;
+import org.apache.bcel.generic.InstructionList;
+import org.apache.xalan.xsltc.compiler.util.ClassGenerator;
+import org.apache.xalan.xsltc.compiler.util.MethodGenerator;
+import org.apache.xalan.xsltc.compiler.util.ErrorMsg;
+import org.apache.xalan.xsltc.compiler.util.Type;
+import org.apache.xalan.xsltc.compiler.util.ObjectType;
+import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
+
+/**
+ * @author Santiago Pericas-Geertsen
+ */
+final class CastCall extends FunctionCall {
+
+ /**
+ * Name of the class that is the target of the cast. Must be a
+ * fully-qualified Java class Name.
+ */
+ private String _className;
+
+ /**
+ * A reference to the expression being casted.
+ */
+ private Expression _right;
+
+ /**
+ * Constructor.
+ */
+ public CastCall(QName fname, Vector arguments) {
+ super(fname, arguments);
+ }
+
+ /**
+ * Type check the two parameters for this function
+ */
+ public Type typeCheck(SymbolTable stable) throws TypeCheckError {
+ // Check that the function was passed exactly two arguments
+ if (argumentCount() != 2) {
+ throw new TypeCheckError(new ErrorMsg(ErrorMsg.ILLEGAL_ARG_ERR,
+ getName(), this));
+ }
+
+ // The first argument must be a literal String
+ Expression exp = argument(0);
+ if (exp instanceof LiteralExpr) {
+ _className = ((LiteralExpr) exp).getValue();
+ _type = Type.newObjectType(_className);
+ }
+ else {
+ throw new TypeCheckError(new ErrorMsg(ErrorMsg.NEED_LITERAL_ERR,
+ getName(), this));
+ }
+
+ // Second argument must be of type reference or object
+ _right = argument(1);
+ Type tright = _right.typeCheck(stable);
+ if (tright != Type.Reference &&
+ tright instanceof ObjectType == false)
+ {
+ throw new TypeCheckError(new ErrorMsg(ErrorMsg.DATA_CONVERSION_ERR,
+ tright, _type, this));
+ }
+
+ return _type;
+ }
+
+ public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
+ final ConstantPoolGen cpg = classGen.getConstantPool();
+ final InstructionList il = methodGen.getInstructionList();
+
+ _right.translate(classGen, methodGen);
+ il.append(new CHECKCAST(cpg.addClass(_className)));
+ }
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/compiler/CastExpr.java b/src/main/java/org/apache/xalan/xsltc/compiler/CastExpr.java
new file mode 100644
index 000000000..83b2fd87e
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/compiler/CastExpr.java
@@ -0,0 +1,237 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.compiler;
+
+import org.apache.bcel.generic.ConstantPoolGen;
+import org.apache.bcel.generic.IF_ICMPNE;
+import org.apache.bcel.generic.INVOKEINTERFACE;
+import org.apache.bcel.generic.InstructionList;
+import org.apache.bcel.generic.SIPUSH;
+import org.apache.xalan.xsltc.compiler.util.BooleanType;
+import org.apache.xalan.xsltc.compiler.util.ClassGenerator;
+import org.apache.xalan.xsltc.compiler.util.ErrorMsg;
+import org.apache.xalan.xsltc.compiler.util.MethodGenerator;
+import org.apache.xalan.xsltc.compiler.util.MultiHashtable;
+import org.apache.xalan.xsltc.compiler.util.NodeType;
+import org.apache.xalan.xsltc.compiler.util.ResultTreeType;
+import org.apache.xalan.xsltc.compiler.util.Type;
+import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
+import org.apache.xml.dtm.Axis;
+
+/**
+ * @author Jacek Ambroziak
+ * @author Santiago Pericas-Geertsen
+ * @author Morten Jorgensen
+ * @author Erwin Bolwidt <ej...@klomp.org>
+ */
+final class CastExpr extends Expression {
+ private final Expression _left;
+
+ /**
+ * Legal conversions between internal types.
+ */
+ static private MultiHashtable InternalTypeMap = new MultiHashtable();
+
+ static {
+ // Possible type conversions between internal types
+ InternalTypeMap.put(Type.Boolean, Type.Boolean);
+ InternalTypeMap.put(Type.Boolean, Type.Real);
+ InternalTypeMap.put(Type.Boolean, Type.String);
+ InternalTypeMap.put(Type.Boolean, Type.Reference);
+ InternalTypeMap.put(Type.Boolean, Type.Object);
+
+ InternalTypeMap.put(Type.Real, Type.Real);
+ InternalTypeMap.put(Type.Real, Type.Int);
+ InternalTypeMap.put(Type.Real, Type.Boolean);
+ InternalTypeMap.put(Type.Real, Type.String);
+ InternalTypeMap.put(Type.Real, Type.Reference);
+ InternalTypeMap.put(Type.Real, Type.Object);
+
+ InternalTypeMap.put(Type.Int, Type.Int);
+ InternalTypeMap.put(Type.Int, Type.Real);
+ InternalTypeMap.put(Type.Int, Type.Boolean);
+ InternalTypeMap.put(Type.Int, Type.String);
+ InternalTypeMap.put(Type.Int, Type.Reference);
+ InternalTypeMap.put(Type.Int, Type.Object);
+
+ InternalTypeMap.put(Type.String, Type.String);
+ InternalTypeMap.put(Type.String, Type.Boolean);
+ InternalTypeMap.put(Type.String, Type.Real);
+ InternalTypeMap.put(Type.String, Type.Reference);
+ InternalTypeMap.put(Type.String, Type.Object);
+
+ InternalTypeMap.put(Type.NodeSet, Type.NodeSet);
+ InternalTypeMap.put(Type.NodeSet, Type.Boolean);
+ InternalTypeMap.put(Type.NodeSet, Type.Real);
+ InternalTypeMap.put(Type.NodeSet, Type.String);
+ InternalTypeMap.put(Type.NodeSet, Type.Node);
+ InternalTypeMap.put(Type.NodeSet, Type.Reference);
+ InternalTypeMap.put(Type.NodeSet, Type.Object);
+
+ InternalTypeMap.put(Type.Node, Type.Node);
+ InternalTypeMap.put(Type.Node, Type.Boolean);
+ InternalTypeMap.put(Type.Node, Type.Real);
+ InternalTypeMap.put(Type.Node, Type.String);
+ InternalTypeMap.put(Type.Node, Type.NodeSet);
+ InternalTypeMap.put(Type.Node, Type.Reference);
+ InternalTypeMap.put(Type.Node, Type.Object);
+
+ InternalTypeMap.put(Type.ResultTree, Type.ResultTree);
+ InternalTypeMap.put(Type.ResultTree, Type.Boolean);
+ InternalTypeMap.put(Type.ResultTree, Type.Real);
+ InternalTypeMap.put(Type.ResultTree, Type.String);
+ InternalTypeMap.put(Type.ResultTree, Type.NodeSet);
+ InternalTypeMap.put(Type.ResultTree, Type.Reference);
+ InternalTypeMap.put(Type.ResultTree, Type.Object);
+
+ InternalTypeMap.put(Type.Reference, Type.Reference);
+ InternalTypeMap.put(Type.Reference, Type.Boolean);
+ InternalTypeMap.put(Type.Reference, Type.Int);
+ InternalTypeMap.put(Type.Reference, Type.Real);
+ InternalTypeMap.put(Type.Reference, Type.String);
+ InternalTypeMap.put(Type.Reference, Type.Node);
+ InternalTypeMap.put(Type.Reference, Type.NodeSet);
+ InternalTypeMap.put(Type.Reference, Type.ResultTree);
+ InternalTypeMap.put(Type.Reference, Type.Object);
+
+ InternalTypeMap.put(Type.Object, Type.String);
+
+ InternalTypeMap.put(Type.Void, Type.String);
+ }
+
+ private boolean _typeTest = false;
+
+ /**
+ * Construct a cast expression and check that the conversion is
+ * valid by calling typeCheck().
+ */
+ public CastExpr(Expression left, Type type) throws TypeCheckError {
+ _left = left;
+ _type = type; // use inherited field
+
+ if ((_left instanceof Step) && (_type == Type.Boolean)) {
+ Step step = (Step)_left;
+ if ((step.getAxis() == Axis.SELF) && (step.getNodeType() != -1))
+ _typeTest = true;
+ }
+
+ // check if conversion is valid
+ setParser(left.getParser());
+ setParent(left.getParent());
+ left.setParent(this);
+ typeCheck(left.getParser().getSymbolTable());
+ }
+
+ public Expression getExpr() {
+ return _left;
+ }
+
+ /**
+ * Returns true if this expressions contains a call to position(). This is
+ * needed for context changes in node steps containing multiple predicates.
+ */
+ public boolean hasPositionCall() {
+ return(_left.hasPositionCall());
+ }
+
+ public boolean hasLastCall() {
+ return(_left.hasLastCall());
+ }
+
+ public String toString() {
+ return "cast(" + _left + ", " + _type + ")";
+ }
+
+ /**
+ * Type checking a cast expression amounts to verifying that the
+ * type conversion is legal. Cast expressions are created during
+ * type checking, but typeCheck() is usually not called on them.
+ * As a result, this method is called from the constructor.
+ */
+ public Type typeCheck(SymbolTable stable) throws TypeCheckError {
+ Type tleft = _left.getType();
+ if (tleft == null) {
+ tleft = _left.typeCheck(stable);
+ }
+ if (tleft instanceof NodeType) {
+ tleft = Type.Node; // multiple instances
+ }
+ else if (tleft instanceof ResultTreeType) {
+ tleft = Type.ResultTree; // multiple instances
+ }
+ if (InternalTypeMap.maps(tleft, _type) != null) {
+ return _type;
+ }
+ // throw new TypeCheckError(this);
+ throw new TypeCheckError(new ErrorMsg(
+ ErrorMsg.DATA_CONVERSION_ERR, tleft.toString(), _type.toString()));
+ }
+
+ public void translateDesynthesized(ClassGenerator classGen,
+ MethodGenerator methodGen) {
+ FlowList fl;
+ final Type ltype = _left.getType();
+
+ // This is a special case for the self:: axis. Instead of letting
+ // the Step object create and iterator that we cast back to a single
+ // node, we simply ask the DOM for the node type.
+ if (_typeTest) {
+ final ConstantPoolGen cpg = classGen.getConstantPool();
+ final InstructionList il = methodGen.getInstructionList();
+
+ final int idx = cpg.addInterfaceMethodref(DOM_INTF,
+ "getExpandedTypeID",
+ "(I)I");
+ il.append(new SIPUSH((short)((Step)_left).getNodeType()));
+ il.append(methodGen.loadDOM());
+ il.append(methodGen.loadContextNode());
+ il.append(new INVOKEINTERFACE(idx, 2));
+ _falseList.add(il.append(new IF_ICMPNE(null)));
+ }
+ else {
+
+ _left.translate(classGen, methodGen);
+ if (_type != ltype) {
+ _left.startIterator(classGen, methodGen);
+ if (_type instanceof BooleanType) {
+ fl = ltype.translateToDesynthesized(classGen, methodGen,
+ _type);
+ if (fl != null) {
+ _falseList.append(fl);
+ }
+ }
+ else {
+ ltype.translateTo(classGen, methodGen, _type);
+ }
+ }
+ }
+ }
+
+ public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
+ final Type ltype = _left.getType();
+ _left.translate(classGen, methodGen);
+ if (_type.identicalTo(ltype) == false) {
+ _left.startIterator(classGen, methodGen);
+ ltype.translateTo(classGen, methodGen, _type);
+ }
+ }
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/compiler/CeilingCall.java b/src/main/java/org/apache/xalan/xsltc/compiler/CeilingCall.java
new file mode 100644
index 000000000..ec6a43352
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/compiler/CeilingCall.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.compiler;
+
+import java.util.Vector;
+
+import org.apache.bcel.generic.ConstantPoolGen;
+import org.apache.bcel.generic.INVOKESTATIC;
+import org.apache.bcel.generic.InstructionList;
+import org.apache.xalan.xsltc.compiler.util.ClassGenerator;
+import org.apache.xalan.xsltc.compiler.util.MethodGenerator;
+
+/**
+ * @author Jacek Ambroziak
+ * @author Santiago Pericas-Geertsen
+ */
+final class CeilingCall extends FunctionCall {
+ public CeilingCall(QName fname, Vector arguments) {
+ super(fname, arguments);
+ }
+
+ public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
+ final ConstantPoolGen cpg = classGen.getConstantPool();
+ final InstructionList il = methodGen.getInstructionList();
+ argument(0).translate(classGen, methodGen);
+ il.append(new INVOKESTATIC(cpg.addMethodref(MATH_CLASS,
+ "ceil", "(D)D")));
+ }
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/compiler/Choose.java b/src/main/java/org/apache/xalan/xsltc/compiler/Choose.java
new file mode 100644
index 000000000..b558cccbe
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/compiler/Choose.java
@@ -0,0 +1,168 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.compiler;
+
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.bcel.generic.BranchHandle;
+import org.apache.bcel.generic.GOTO;
+import org.apache.bcel.generic.IFEQ;
+import org.apache.bcel.generic.InstructionHandle;
+import org.apache.bcel.generic.InstructionList;
+import org.apache.xalan.xsltc.compiler.util.ClassGenerator;
+import org.apache.xalan.xsltc.compiler.util.ErrorMsg;
+import org.apache.xalan.xsltc.compiler.util.MethodGenerator;
+import org.apache.xalan.xsltc.compiler.util.Type;
+import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
+import org.apache.xalan.xsltc.compiler.util.Util;
+
+/**
+ * @author Jacek Ambroziak
+ * @author Santiago Pericas-Geertsen
+ * @author Morten Jorgensen
+ */
+final class Choose extends Instruction {
+
+ /**
+ * Display the element contents (a lot of when's and an otherwise)
+ */
+ public void display(int indent) {
+ indent(indent);
+ Util.println("Choose");
+ indent(indent + IndentIncrement);
+ displayContents(indent + IndentIncrement);
+ }
+
+ /**
+ * Translate this Choose element. Generate a test-chain for the various
+ * <xsl:when> elements and default to the <xsl:otherwise> if present.
+ */
+ public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
+ final List whenElements = new ArrayList();
+ Otherwise otherwise = null;
+ Enumeration elements = elements();
+
+ // These two are for reporting errors only
+ ErrorMsg error = null;
+ final int line = getLineNumber();
+
+ // Traverse all child nodes - must be either When or Otherwise
+ while (elements.hasMoreElements()) {
+ Object element = elements.nextElement();
+ // Add a When child element
+ if (element instanceof When) {
+ whenElements.add(element);
+ }
+ // Add an Otherwise child element
+ else if (element instanceof Otherwise) {
+ if (otherwise == null) {
+ otherwise = (Otherwise)element;
+ }
+ else {
+ error = new ErrorMsg(ErrorMsg.MULTIPLE_OTHERWISE_ERR, this);
+ getParser().reportError(Constants.ERROR, error);
+ }
+ }
+ else if (element instanceof Text) {
+ ((Text)element).ignore();
+ }
+ // It is an error if we find some other element here
+ else {
+ error = new ErrorMsg(ErrorMsg.WHEN_ELEMENT_ERR, this);
+ getParser().reportError(Constants.ERROR, error);
+ }
+ }
+
+ // Make sure that there is at least one <xsl:when> element
+ if (whenElements.size() == 0) {
+ error = new ErrorMsg(ErrorMsg.MISSING_WHEN_ERR, this);
+ getParser().reportError(Constants.ERROR, error);
+ return;
+ }
+
+ InstructionList il = methodGen.getInstructionList();
+
+ // next element will hold a handle to the beginning of next
+ // When/Otherwise if test on current When fails
+ BranchHandle nextElement = null;
+ List exitHandles = new ArrayList();
+ InstructionHandle exit = null;
+
+ Iterator whens = whenElements.iterator();
+ while (whens.hasNext()) {
+ final When when = (When)whens.next();
+ final Expression test = when.getTest();
+
+ InstructionHandle truec = il.getEnd();
+
+ if (nextElement != null)
+ nextElement.setTarget(il.append(NOP));
+ test.translateDesynthesized(classGen, methodGen);
+
+ if (test instanceof FunctionCall) {
+ FunctionCall call = (FunctionCall)test;
+ try {
+ Type type = call.typeCheck(getParser().getSymbolTable());
+ if (type != Type.Boolean) {
+ test._falseList.add(il.append(new IFEQ(null)));
+ }
+ }
+ catch (TypeCheckError e) {
+ // handled later!
+ }
+ }
+ // remember end of condition
+ truec = il.getEnd();
+
+ // The When object should be ignored completely in case it tests
+ // for the support of a non-available element
+ if (!when.ignore()) when.translateContents(classGen, methodGen);
+
+ // goto exit after executing the body of when
+ exitHandles.add(il.append(new GOTO(null)));
+ if (whens.hasNext() || otherwise != null) {
+ nextElement = il.append(new GOTO(null));
+ test.backPatchFalseList(nextElement);
+ }
+ else
+ test.backPatchFalseList(exit = il.append(NOP));
+ test.backPatchTrueList(truec.getNext());
+ }
+
+ // Translate any <xsl:otherwise> element
+ if (otherwise != null) {
+ nextElement.setTarget(il.append(NOP));
+ otherwise.translateContents(classGen, methodGen);
+ exit = il.append(NOP);
+ }
+
+ // now that end is known set targets of exit gotos
+ Iterator exitGotos = exitHandles.iterator();
+ while (exitGotos.hasNext()) {
+ BranchHandle gotoExit = (BranchHandle)exitGotos.next();
+ gotoExit.setTarget(exit);
+ }
+ }
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/compiler/Closure.java b/src/main/java/org/apache/xalan/xsltc/compiler/Closure.java
new file mode 100644
index 000000000..dd99b0bd5
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/compiler/Closure.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.compiler;
+
+/**
+ * @author Santiago Pericas-Geertsen
+ */
+public interface Closure {
+
+ /**
+ * Returns true if this closure is compiled in an inner class (i.e.
+ * if this is a real closure).
+ */
+ public boolean inInnerClass();
+
+ /**
+ * Returns a reference to its parent closure or null if outermost.
+ */
+ public Closure getParentClosure();
+
+ /**
+ * Returns the name of the auxiliary class or null if this predicate
+ * is compiled inside the Translet.
+ */
+ public String getInnerClassName();
+
+ /**
+ * Add new variable to the closure.
+ */
+ public void addVariable(VariableRefBase variableRef);
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/compiler/Comment.java b/src/main/java/org/apache/xalan/xsltc/compiler/Comment.java
new file mode 100644
index 000000000..8f8d68843
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/compiler/Comment.java
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.compiler;
+
+import org.apache.bcel.generic.ConstantPoolGen;
+import org.apache.bcel.generic.GETFIELD;
+import org.apache.bcel.generic.INVOKEINTERFACE;
+import org.apache.bcel.generic.INVOKEVIRTUAL;
+import org.apache.bcel.generic.PUSH;
+import org.apache.bcel.generic.InstructionList;
+import org.apache.xalan.xsltc.compiler.util.ClassGenerator;
+import org.apache.xalan.xsltc.compiler.util.MethodGenerator;
+import org.apache.xalan.xsltc.compiler.util.Type;
+import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
+
+/**
+ * @author Jacek Ambroziak
+ * @author Santiago Pericas-Geertsen
+ * @author Morten Jorgensen
+ */
+final class Comment extends Instruction {
+
+ public void parseContents(Parser parser) {
+ parseChildren(parser);
+ }
+
+ public Type typeCheck(SymbolTable stable) throws TypeCheckError {
+ typeCheckContents(stable);
+ return Type.String;
+ }
+
+ public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
+ final ConstantPoolGen cpg = classGen.getConstantPool();
+ final InstructionList il = methodGen.getInstructionList();
+
+ // Shortcut for literal strings
+ Text rawText = null;
+ if (elementCount() == 1) {
+ Object content = elementAt(0);
+ if (content instanceof Text) {
+ rawText = (Text) content;
+ }
+ }
+
+ // If the content is literal text, call comment(char[],int,int) or
+ // comment(String), as appropriate. Otherwise, use a
+ // StringValueHandler to gather the textual content of the xsl:comment
+ // and call comment(String) with the result.
+ if (rawText != null) {
+ il.append(methodGen.loadHandler());
+
+ if (rawText.canLoadAsArrayOffsetLength()) {
+ rawText.loadAsArrayOffsetLength(classGen, methodGen);
+ final int comment =
+ cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE,
+ "comment",
+ "([CII)V");
+ il.append(new INVOKEINTERFACE(comment, 4));
+ } else {
+ il.append(new PUSH(cpg, rawText.getText()));
+ final int comment =
+ cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE,
+ "comment",
+ "(" + STRING_SIG + ")V");
+ il.append(new INVOKEINTERFACE(comment, 2));
+ }
+ } else {
+ // Save the current handler base on the stack
+ il.append(methodGen.loadHandler());
+ il.append(DUP); // first arg to "comment" call
+
+ // Get the translet's StringValueHandler
+ il.append(classGen.loadTranslet());
+ il.append(new GETFIELD(cpg.addFieldref(TRANSLET_CLASS,
+ "stringValueHandler",
+ STRING_VALUE_HANDLER_SIG)));
+ il.append(DUP);
+ il.append(methodGen.storeHandler());
+
+ // translate contents with substituted handler
+ translateContents(classGen, methodGen);
+
+ // get String out of the handler
+ il.append(new INVOKEVIRTUAL(cpg.addMethodref(STRING_VALUE_HANDLER,
+ "getValue",
+ "()" + STRING_SIG)));
+ // call "comment"
+ final int comment =
+ cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE,
+ "comment",
+ "(" + STRING_SIG + ")V");
+ il.append(new INVOKEINTERFACE(comment, 2));
+ // Restore old handler base from stack
+ il.append(methodGen.storeHandler());
+ }
+ }
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/compiler/CompilerException.java b/src/main/java/org/apache/xalan/xsltc/compiler/CompilerException.java
new file mode 100644
index 000000000..97a894c60
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/compiler/CompilerException.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.compiler;
+
+/**
+ * @author Morten Jorgensen
+ */
+public final class CompilerException extends Exception {
+ static final long serialVersionUID = 1732939618562742663L;
+
+ private String _msg;
+
+ public CompilerException() {
+ super();
+ }
+
+ public CompilerException(Exception e) {
+ super(e.toString());
+ _msg = e.toString();
+ }
+
+ public CompilerException(String message) {
+ super(message);
+ _msg = message;
+ }
+
+ public String getMessage() {
+ final int col = _msg.indexOf(':');
+
+ if (col > -1)
+ return(_msg.substring(col));
+ else
+ return(_msg);
+ }
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/compiler/ConcatCall.java b/src/main/java/org/apache/xalan/xsltc/compiler/ConcatCall.java
new file mode 100644
index 000000000..9056431be
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/compiler/ConcatCall.java
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.compiler;
+
+import java.util.Vector;
+
+import org.apache.bcel.generic.ConstantPoolGen;
+import org.apache.bcel.generic.INVOKESPECIAL;
+import org.apache.bcel.generic.INVOKEVIRTUAL;
+import org.apache.bcel.generic.Instruction;
+import org.apache.bcel.generic.InstructionList;
+import org.apache.bcel.generic.NEW;
+import org.apache.bcel.generic.PUSH;
+import org.apache.xalan.xsltc.compiler.util.ClassGenerator;
+import org.apache.xalan.xsltc.compiler.util.MethodGenerator;
+import org.apache.xalan.xsltc.compiler.util.Type;
+import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
+
+/**
+ * @author Jacek Ambroziak
+ * @author Santiago Pericas-Geertsen
+ */
+final class ConcatCall extends FunctionCall {
+ public ConcatCall(QName fname, Vector arguments) {
+ super(fname, arguments);
+ }
+
+ public Type typeCheck(SymbolTable stable) throws TypeCheckError {
+ for (int i = 0; i < argumentCount(); i++) {
+ final Expression exp = argument(i);
+ if (!exp.typeCheck(stable).identicalTo(Type.String)) {
+ setArgument(i, new CastExpr(exp, Type.String));
+ }
+ }
+ return _type = Type.String;
+ }
+
+ /** translate leaves a String on the stack */
+ public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
+ final ConstantPoolGen cpg = classGen.getConstantPool();
+ final InstructionList il = methodGen.getInstructionList();
+ final int nArgs = argumentCount();
+
+ switch (nArgs) {
+ case 0:
+ il.append(new PUSH(cpg, EMPTYSTRING));
+ break;
+
+ case 1:
+ argument().translate(classGen, methodGen);
+ break;
+
+ default:
+ final int initBuffer = cpg.addMethodref(STRING_BUFFER_CLASS,
+ "<init>", "()V");
+ final Instruction append =
+ new INVOKEVIRTUAL(cpg.addMethodref(STRING_BUFFER_CLASS,
+ "append",
+ "("+STRING_SIG+")"
+ +STRING_BUFFER_SIG));
+
+ final int toString = cpg.addMethodref(STRING_BUFFER_CLASS,
+ "toString",
+ "()"+STRING_SIG);
+
+ il.append(new NEW(cpg.addClass(STRING_BUFFER_CLASS)));
+ il.append(DUP);
+ il.append(new INVOKESPECIAL(initBuffer));
+ for (int i = 0; i < nArgs; i++) {
+ argument(i).translate(classGen, methodGen);
+ il.append(append);
+ }
+ il.append(new INVOKEVIRTUAL(toString));
+ }
+ }
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/compiler/Constants.java b/src/main/java/org/apache/xalan/xsltc/compiler/Constants.java
new file mode 100644
index 000000000..865d542d9
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/compiler/Constants.java
@@ -0,0 +1,537 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.compiler;
+
+import org.apache.bcel.generic.InstructionConstants;
+import org.apache.xml.serializer.SerializerBase;
+
+/**
+ * @author Jacek Ambroziak
+ * @author Santiago Pericas-Geertsen
+ */
+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 NAMESPACE_FEATURE =
+ "http://xml.org/sax/features/namespaces";
+
+ public static final String TRANSLET_INTF
+ = "org.apache.xalan.xsltc.Translet";
+ public static final String TRANSLET_INTF_SIG
+ = "Lorg/apache/xalan/xsltc/Translet;";
+
+ public static final String ATTRIBUTES_SIG
+ = "Lorg/apache/xalan/xsltc/runtime/Attributes;";
+ public static final String NODE_ITERATOR_SIG
+ = "Lorg/apache/xml/dtm/DTMAxisIterator;";
+ public static final String DOM_INTF_SIG
+ = "Lorg/apache/xalan/xsltc/DOM;";
+ public static final String DOM_IMPL_CLASS
+ = "org/apache/xalan/xsltc/DOM"; // xml/dtm/ref/DTMDefaultBaseIterators"; //xalan/xsltc/dom/DOMImpl";
+ public static final String SAX_IMPL_CLASS
+ = "org/apache/xalan/xsltc/DOM/SAXImpl";
+ public static final String DOM_IMPL_SIG
+ = "Lorg/apache/xalan/xsltc/dom/SAXImpl;"; //xml/dtm/ref/DTMDefaultBaseIterators"; //xalan/xsltc/dom/DOMImpl;";
+ public static final String SAX_IMPL_SIG
+ = "Lorg/apache/xalan/xsltc/dom/SAXImpl;";
+ public static final String DOM_ADAPTER_CLASS
+ = "org/apache/xalan/xsltc/dom/DOMAdapter";
+ public static final String DOM_ADAPTER_SIG
+ = "Lorg/apache/xalan/xsltc/dom/DOMAdapter;";
+ public static final String MULTI_DOM_CLASS
+ = "org.apache.xalan.xsltc.dom.MultiDOM";
+ public static final String MULTI_DOM_SIG
+ = "Lorg/apache/xalan/xsltc/dom/MultiDOM;";
+
+ public static final String STRING
+ = "java.lang.String";
+
+ public static final int ACC_PUBLIC
+ = org.apache.bcel.Constants.ACC_PUBLIC;
+ public static final int ACC_SUPER
+ = org.apache.bcel.Constants.ACC_SUPER;
+ public static final int ACC_FINAL
+ = org.apache.bcel.Constants.ACC_FINAL;
+ public static final int ACC_PRIVATE
+ = org.apache.bcel.Constants.ACC_PRIVATE;
+ public static final int ACC_PROTECTED
+ = org.apache.bcel.Constants.ACC_PROTECTED;
+ public static final int ACC_STATIC
+ = org.apache.bcel.Constants.ACC_STATIC;
+
+ public static final String STRING_SIG
+ = "Ljava/lang/String;";
+ public static final String STRING_BUFFER_SIG
+ = "Ljava/lang/StringBuffer;";
+ public static final String OBJECT_SIG
+ = "Ljava/lang/Object;";
+ public static final String DOUBLE_SIG
+ = "Ljava/lang/Double;";
+ public static final String INTEGER_SIG
+ = "Ljava/lang/Integer;";
+ public static final String COLLATOR_CLASS
+ = "java/text/Collator";
+ public static final String COLLATOR_SIG
+ = "Ljava/text/Collator;";
+
+ public static final String NODE
+ = "int";
+ public static final String NODE_ITERATOR
+ = "org.apache.xml.dtm.DTMAxisIterator";
+ public static final String NODE_ITERATOR_BASE
+ = "org.apache.xml.dtm.ref.DTMAxisIteratorBase";
+ public static final String SORT_ITERATOR
+ = "org.apache.xalan.xsltc.dom.SortingIterator";
+ public static final String SORT_ITERATOR_SIG
+ = "Lorg.apache.xalan.xsltc.dom.SortingIterator;";
+ public static final String NODE_SORT_RECORD
+ = "org.apache.xalan.xsltc.dom.NodeSortRecord";
+ public static final String NODE_SORT_FACTORY
+ = "org/apache/xalan/xsltc/dom/NodeSortRecordFactory";
+ public static final String NODE_SORT_RECORD_SIG
+ = "Lorg/apache/xalan/xsltc/dom/NodeSortRecord;";
+ public static final String NODE_SORT_FACTORY_SIG
+ = "Lorg/apache/xalan/xsltc/dom/NodeSortRecordFactory;";
+ public static final String LOCALE_CLASS
+ = "java.util.Locale";
+ public static final String LOCALE_SIG
+ = "Ljava/util/Locale;";
+ public static final String STRING_VALUE_HANDLER
+ = "org.apache.xalan.xsltc.runtime.StringValueHandler";
+ public static final String STRING_VALUE_HANDLER_SIG
+ = "Lorg/apache/xalan/xsltc/runtime/StringValueHandler;";
+ public static final String OUTPUT_HANDLER
+ = SerializerBase.PKG_PATH+"/SerializationHandler";
+ public static final String OUTPUT_HANDLER_SIG
+ = "L"+SerializerBase.PKG_PATH+"/SerializationHandler;";
+ public static final String FILTER_INTERFACE
+ = "org.apache.xalan.xsltc.dom.Filter";
+ public static final String FILTER_INTERFACE_SIG
+ = "Lorg/apache/xalan/xsltc/dom/Filter;";
+ public static final String UNION_ITERATOR_CLASS
+ = "org.apache.xalan.xsltc.dom.UnionIterator";
+ public static final String STEP_ITERATOR_CLASS
+ = "org.apache.xalan.xsltc.dom.StepIterator";
+ public static final String CACHED_NODE_LIST_ITERATOR_CLASS
+ = "org.apache.xalan.xsltc.dom.CachedNodeListIterator";
+ public static final String NTH_ITERATOR_CLASS
+ = "org.apache.xalan.xsltc.dom.NthIterator";
+ public static final String ABSOLUTE_ITERATOR
+ = "org.apache.xalan.xsltc.dom.AbsoluteIterator";
+ public static final String DUP_FILTERED_ITERATOR
+ = "org.apache.xalan.xsltc.dom.DupFilterIterator";
+ public static final String CURRENT_NODE_LIST_ITERATOR
+ = "org.apache.xalan.xsltc.dom.CurrentNodeListIterator";
+ public static final String CURRENT_NODE_LIST_FILTER
+ = "org.apache.xalan.xsltc.dom.CurrentNodeListFilter";
+ public static final String CURRENT_NODE_LIST_ITERATOR_SIG
+ = "Lorg/apache/xalan/xsltc/dom/CurrentNodeListIterator;";
+ public static final String CURRENT_NODE_LIST_FILTER_SIG
+ = "Lorg/apache/xalan/xsltc/dom/CurrentNodeListFilter;";
+ public static final String FILTER_STEP_ITERATOR
+ = "org.apache.xalan.xsltc.dom.FilteredStepIterator";
+ public static final String FILTER_ITERATOR
+ = "org.apache.xalan.xsltc.dom.FilterIterator";
+ public static final String SINGLETON_ITERATOR
+ = "org.apache.xalan.xsltc.dom.SingletonIterator";
+ public static final String MATCHING_ITERATOR
+ = "org.apache.xalan.xsltc.dom.MatchingIterator";
+ public static final String NODE_SIG
+ = "I";
+ public static final String GET_PARENT
+ = "getParent";
+ public static final String GET_PARENT_SIG
+ = "(" + NODE_SIG + ")" + NODE_SIG;
+ public static final String NEXT_SIG
+ = "()" + NODE_SIG;
+ public static final String NEXT
+ = "next";
+ public static final String NEXTID
+ = "nextNodeID";
+ public static final String MAKE_NODE
+ = "makeNode";
+ public static final String MAKE_NODE_LIST
+ = "makeNodeList";
+ public static final String GET_UNPARSED_ENTITY_URI
+ = "getUnparsedEntityURI";
+ public static final String STRING_TO_REAL
+ = "stringToReal";
+ public static final String STRING_TO_REAL_SIG
+ = "(" + STRING_SIG + ")D";
+ public static final String STRING_TO_INT
+ = "stringToInt";
+ public static final String STRING_TO_INT_SIG
+ = "(" + STRING_SIG + ")I";
+
+ public static final String XSLT_PACKAGE
+ = "org.apache.xalan.xsltc";
+ public static final String COMPILER_PACKAGE
+ = XSLT_PACKAGE + ".compiler";
+ public static final String RUNTIME_PACKAGE
+ = XSLT_PACKAGE + ".runtime";
+ public static final String TRANSLET_CLASS
+ = RUNTIME_PACKAGE + ".AbstractTranslet";
+
+ public static final String TRANSLET_SIG
+ = "Lorg/apache/xalan/xsltc/runtime/AbstractTranslet;";
+ public static final String UNION_ITERATOR_SIG
+ = "Lorg/apache/xalan/xsltc/dom/UnionIterator;";
+ public static final String TRANSLET_OUTPUT_SIG
+ = "L"+SerializerBase.PKG_PATH+"/SerializationHandler;";
+ public static final String MAKE_NODE_SIG
+ = "(I)Lorg/w3c/dom/Node;";
+ public static final String MAKE_NODE_SIG2
+ = "(" + NODE_ITERATOR_SIG + ")Lorg/w3c/dom/Node;";
+ public static final String MAKE_NODE_LIST_SIG
+ = "(I)Lorg/w3c/dom/NodeList;";
+ public static final String MAKE_NODE_LIST_SIG2
+ = "(" + NODE_ITERATOR_SIG + ")Lorg/w3c/dom/NodeList;";
+
+ public static final String STREAM_XML_OUTPUT
+ = SerializerBase.PKG_NAME+".ToXMLStream";
+
+ public static final String OUTPUT_BASE
+ = SerializerBase.PKG_NAME+".SerializerBase";
+
+ public static final String LOAD_DOCUMENT_CLASS
+ = "org.apache.xalan.xsltc.dom.LoadDocument";
+
+ public static final String KEY_INDEX_CLASS
+ = "org/apache/xalan/xsltc/dom/KeyIndex";
+ public static final String KEY_INDEX_SIG
+ = "Lorg/apache/xalan/xsltc/dom/KeyIndex;";
+ public static final String KEY_INDEX_ITERATOR_SIG
+ = "Lorg/apache/xalan/xsltc/dom/KeyIndex$KeyIndexIterator;";
+
+ public static final String DOM_INTF
+ = "org.apache.xalan.xsltc.DOM";
+ public static final String DOM_IMPL
+ = "org.apache.xalan.xsltc.dom.SAXImpl";
+ public static final String SAX_IMPL
+ = "org.apache.xalan.xsltc.dom.SAXImpl";
+ public static final String STRING_CLASS
+ = "java.lang.String";
+ public static final String OBJECT_CLASS
+ = "java.lang.Object";
+ public static final String BOOLEAN_CLASS
+ = "java.lang.Boolean";
+ public static final String STRING_BUFFER_CLASS
+ = "java.lang.StringBuffer";
+ public static final String STRING_WRITER
+ = "java.io.StringWriter";
+ public static final String WRITER_SIG
+ = "Ljava/io/Writer;";
+
+ public static final String TRANSLET_OUTPUT_BASE
+ = "org.apache.xalan.xsltc.TransletOutputBase";
+ // output interface
+ public static final String TRANSLET_OUTPUT_INTERFACE
+ = SerializerBase.PKG_NAME+".SerializationHandler";
+ public static final String BASIS_LIBRARY_CLASS
+ = "org.apache.xalan.xsltc.runtime.BasisLibrary";
+ public static final String ATTRIBUTE_LIST_IMPL_CLASS
+ = "org.apache.xalan.xsltc.runtime.AttributeListImpl";
+ public static final String DOUBLE_CLASS
+ = "java.lang.Double";
+ public static final String INTEGER_CLASS
+ = "java.lang.Integer";
+ public static final String RUNTIME_NODE_CLASS
+ = "org.apache.xalan.xsltc.runtime.Node";
+ public static final String MATH_CLASS
+ = "java.lang.Math";
+
+ public static final String BOOLEAN_VALUE
+ = "booleanValue";
+ public static final String BOOLEAN_VALUE_SIG
+ = "()Z";
+ public static final String INT_VALUE
+ = "intValue";
+ public static final String INT_VALUE_SIG
+ = "()I";
+ public static final String DOUBLE_VALUE
+ = "doubleValue";
+ public static final String DOUBLE_VALUE_SIG
+ = "()D";
+
+ public static final String DOM_PNAME
+ = "dom";
+ public static final String NODE_PNAME
+ = "node";
+ public static final String TRANSLET_OUTPUT_PNAME
+ = "handler";
+ public static final String ITERATOR_PNAME
+ = "iterator";
+ public static final String DOCUMENT_PNAME
+ = "document";
+ public static final String TRANSLET_PNAME
+ = "translet";
+
+ public static final String INVOKE_METHOD
+ = "invokeMethod";
+ public static final String GET_NODE_NAME
+ = "getNodeNameX";
+ public static final String CHARACTERSW
+ = "characters";
+ public static final String GET_CHILDREN
+ = "getChildren";
+ public static final String GET_TYPED_CHILDREN
+ = "getTypedChildren";
+ public static final String CHARACTERS
+ = "characters";
+ public static final String APPLY_TEMPLATES
+ = "applyTemplates";
+ public static final String GET_NODE_TYPE
+ = "getNodeType";
+ public static final String GET_NODE_VALUE
+ = "getStringValueX";
+ public static final String GET_ELEMENT_VALUE
+ = "getElementValue";
+ public static final String GET_ATTRIBUTE_VALUE
+ = "getAttributeValue";
+ public static final String HAS_ATTRIBUTE
+ = "hasAttribute";
+ public static final String ADD_ITERATOR
+ = "addIterator";
+ public static final String SET_START_NODE
+ = "setStartNode";
+ public static final String RESET
+ = "reset";
+
+ public static final String ATTR_SET_SIG
+ = "(" + DOM_INTF_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
+ = "(" + STRING_SIG + TRANSLET_OUTPUT_SIG + ")V";
+ public static final String CHARACTERS_SIG
+ = "(" + NODE_SIG + TRANSLET_OUTPUT_SIG + ")V";
+ public static final String GET_CHILDREN_SIG
+ = "(" + NODE_SIG +")" + NODE_ITERATOR_SIG;
+ public static final String GET_TYPED_CHILDREN_SIG
+ = "(I)" + NODE_ITERATOR_SIG;
+ public static final String GET_NODE_TYPE_SIG
+ = "()S";
+ public static final String GET_NODE_VALUE_SIG
+ = "(I)" + STRING_SIG;
+ public static final String GET_ELEMENT_VALUE_SIG
+ = "(I)" + STRING_SIG;
+ public static final String GET_ATTRIBUTE_VALUE_SIG
+ = "(II)" + STRING_SIG;
+ public static final String HAS_ATTRIBUTE_SIG
+ = "(II)Z";
+ public static final String GET_ITERATOR_SIG
+ = "()" + NODE_ITERATOR_SIG;
+
+ public static final String NAMES_INDEX
+ = "namesArray";
+ public static final String NAMES_INDEX_SIG
+ = "[" + STRING_SIG;
+ public static final String URIS_INDEX
+ = "urisArray";
+ public static final String URIS_INDEX_SIG
+ = "[" + STRING_SIG;
+ public static final String TYPES_INDEX
+ = "typesArray";
+ public static final String TYPES_INDEX_SIG
+ = "[I";
+ public static final String NAMESPACE_INDEX
+ = "namespaceArray";
+ public static final String NAMESPACE_INDEX_SIG
+ = "[" + STRING_SIG;
+ public static final String NS_ANCESTORS_INDEX_SIG
+ = "[I";
+ public static final String PREFIX_URIS_IDX_SIG
+ = "[I";
+ public static final String PREFIX_URIS_ARRAY_SIG
+ = "[" + STRING_SIG;
+ public static final String HASIDCALL_INDEX
+ = "_hasIdCall";
+ public static final String HASIDCALL_INDEX_SIG
+ = "Z";
+ public static final String TRANSLET_VERSION_INDEX
+ = "transletVersion";
+ public static final String TRANSLET_VERSION_INDEX_SIG
+ = "I";
+ public static final String LOOKUP_STYLESHEET_QNAME_NS_REF
+ = "lookupStylesheetQNameNamespace";
+ public static final String LOOKUP_STYLESHEET_QNAME_NS_SIG
+ = "(" + STRING_SIG
+ + "I"
+ + NS_ANCESTORS_INDEX_SIG
+ + PREFIX_URIS_IDX_SIG
+ + PREFIX_URIS_ARRAY_SIG
+ + "Z)" + STRING_SIG;
+ public static final String EXPAND_STYLESHEET_QNAME_REF
+ = "expandStylesheetQNameRef";
+ public static final String EXPAND_STYLESHEET_QNAME_SIG
+ = "(" + STRING_SIG
+ + "I"
+ + NS_ANCESTORS_INDEX_SIG
+ + PREFIX_URIS_IDX_SIG
+ + PREFIX_URIS_ARRAY_SIG
+ + "Z)" + STRING_SIG;
+
+ public static final String DOM_FIELD
+ = "_dom";
+ public static final String STATIC_NAMES_ARRAY_FIELD
+ = "_sNamesArray";
+ public static final String STATIC_URIS_ARRAY_FIELD
+ = "_sUrisArray";
+ public static final String STATIC_TYPES_ARRAY_FIELD
+ = "_sTypesArray";
+ public static final String STATIC_NAMESPACE_ARRAY_FIELD
+ = "_sNamespaceArray";
+ public static final String STATIC_NS_ANCESTORS_ARRAY_FIELD
+ = "_sNamespaceAncestorsArray";
+ public static final String STATIC_PREFIX_URIS_IDX_ARRAY_FIELD
+ = "_sPrefixURIsIdxArray";
+ public static final String STATIC_PREFIX_URIS_ARRAY_FIELD
+ = "_sPrefixURIPairsArray";
+ public static final String STATIC_CHAR_DATA_FIELD
+ = "_scharData";
+ public static final String STATIC_CHAR_DATA_FIELD_SIG
+ = "[C";
+ public static final String FORMAT_SYMBOLS_FIELD
+ = "format_symbols";
+
+ public static final String ITERATOR_FIELD_SIG
+ = NODE_ITERATOR_SIG;
+ public static final String NODE_FIELD
+ = "node";
+ public static final String NODE_FIELD_SIG
+ = "I";
+
+ public static final String EMPTYATTR_FIELD
+ = "EmptyAttributes";
+ public static final String ATTRIBUTE_LIST_FIELD
+ = "attributeList";
+ public static final String CLEAR_ATTRIBUTES
+ = "clear";
+ public static final String ADD_ATTRIBUTE
+ = "addAttribute";
+ public static final String ATTRIBUTE_LIST_IMPL_SIG
+ = "Lorg/apache/xalan/xsltc/runtime/AttributeListImpl;";
+ public static final String CLEAR_ATTRIBUTES_SIG
+ = "()" + ATTRIBUTE_LIST_IMPL_SIG;
+ public static final String ADD_ATTRIBUTE_SIG
+ = "(" + STRING_SIG + STRING_SIG + ")" + ATTRIBUTE_LIST_IMPL_SIG;
+
+ public static final String ADD_ITERATOR_SIG
+ = "(" + NODE_ITERATOR_SIG +")" + UNION_ITERATOR_SIG;
+
+ public static final String ORDER_ITERATOR
+ = "orderNodes";
+ public static final String ORDER_ITERATOR_SIG
+ = "("+NODE_ITERATOR_SIG+"I)"+NODE_ITERATOR_SIG;
+
+ public static final String SET_START_NODE_SIG
+ = "(" + NODE_SIG + ")" + NODE_ITERATOR_SIG;
+
+ public static final String NODE_COUNTER
+ = "org.apache.xalan.xsltc.dom.NodeCounter";
+ public static final String NODE_COUNTER_SIG
+ = "Lorg/apache/xalan/xsltc/dom/NodeCounter;";
+ public static final String DEFAULT_NODE_COUNTER
+ = "org.apache.xalan.xsltc.dom.DefaultNodeCounter";
+ public static final String DEFAULT_NODE_COUNTER_SIG
+ = "Lorg/apache/xalan/xsltc/dom/DefaultNodeCounter;";
+ public static final String TRANSLET_FIELD
+ = "translet";
+ public static final String TRANSLET_FIELD_SIG
+ = TRANSLET_SIG;
+
+ public static final String RESET_SIG
+ = "()" + NODE_ITERATOR_SIG;
+ public static final String GET_PARAMETER
+ = "getParameter";
+ public static final String ADD_PARAMETER
+ = "addParameter";
+ public static final String PUSH_PARAM_FRAME
+ = "pushParamFrame";
+ public static final String PUSH_PARAM_FRAME_SIG
+ = "()V";
+ public static final String POP_PARAM_FRAME
+ = "popParamFrame";
+ public static final String POP_PARAM_FRAME_SIG
+ = "()V";
+ public static final String GET_PARAMETER_SIG
+ = "(" + STRING_SIG + ")" + OBJECT_SIG;
+ public static final String ADD_PARAMETER_SIG
+ = "(" + STRING_SIG + OBJECT_SIG + "Z)" + OBJECT_SIG;
+
+ public static final String STRIP_SPACE
+ = "stripSpace";
+ public static final String STRIP_SPACE_INTF
+ = "org/apache/xalan/xsltc/StripFilter";
+ public static final String STRIP_SPACE_SIG
+ = "Lorg/apache/xalan/xsltc/StripFilter;";
+ public static final String STRIP_SPACE_PARAMS
+ = "(Lorg/apache/xalan/xsltc/DOM;II)Z";
+
+ public static final String GET_NODE_VALUE_ITERATOR
+ = "getNodeValueIterator";
+ public static final String GET_NODE_VALUE_ITERATOR_SIG
+ = "("+NODE_ITERATOR_SIG+"I"+STRING_SIG+"Z)"+NODE_ITERATOR_SIG;
+
+ public static final String GET_UNPARSED_ENTITY_URI_SIG
+ = "("+STRING_SIG+")"+STRING_SIG;
+
+ public static final int POSITION_INDEX = 2;
+ public static final int LAST_INDEX = 3;
+
+ public static final String XMLNS_PREFIX = "xmlns";
+ public static final String XMLNS_STRING = "xmlns:";
+ public static final String XMLNS_URI
+ = "http://www.w3.org/2000/xmlns/";
+ public static final String XSLT_URI
+ = "http://www.w3.org/1999/XSL/Transform";
+ public static final String XHTML_URI
+ = "http://www.w3.org/1999/xhtml";
+ public static final String TRANSLET_URI
+ = "http://xml.apache.org/xalan/xsltc";
+ public static final String REDIRECT_URI
+ = "http://xml.apache.org/xalan/redirect";
+ public static final String FALLBACK_CLASS
+ = "org.apache.xalan.xsltc.compiler.Fallback";
+
+ public static final int RTF_INITIAL_SIZE = 32;
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/compiler/ContainsCall.java b/src/main/java/org/apache/xalan/xsltc/compiler/ContainsCall.java
new file mode 100644
index 000000000..c6dd654b0
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/compiler/ContainsCall.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.compiler;
+
+import java.util.Vector;
+
+import org.apache.bcel.generic.ConstantPoolGen;
+import org.apache.bcel.generic.IFLT;
+import org.apache.bcel.generic.INVOKEVIRTUAL;
+import org.apache.bcel.generic.InstructionList;
+import org.apache.xalan.xsltc.compiler.util.ClassGenerator;
+import org.apache.xalan.xsltc.compiler.util.ErrorMsg;
+import org.apache.xalan.xsltc.compiler.util.MethodGenerator;
+import org.apache.xalan.xsltc.compiler.util.Type;
+import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
+
+/**
+ * @author Jacek Ambroziak
+ * @author Santiago Pericas-Geertsen
+ * @author Morten Jorgensen
+ */
+final class ContainsCall extends FunctionCall {
+
+ private Expression _base = null;
+ private Expression _token = null;
+
+ /**
+ * Create a contains() call - two arguments, both strings
+ */
+ public ContainsCall(QName fname, Vector arguments) {
+ super(fname, arguments);
+ }
+
+ /**
+ * This XPath function returns true/false values
+ */
+ public boolean isBoolean() {
+ return true;
+ }
+
+ /**
+ * Type check the two parameters for this function
+ */
+ public Type typeCheck(SymbolTable stable) throws TypeCheckError {
+
+ // Check that the function was passed exactly two arguments
+ if (argumentCount() != 2) {
+ throw new TypeCheckError(ErrorMsg.ILLEGAL_ARG_ERR, getName(), this);
+ }
+
+ // The first argument must be a String, or cast to a String
+ _base = argument(0);
+ Type baseType = _base.typeCheck(stable);
+ if (baseType != Type.String)
+ _base = new CastExpr(_base, Type.String);
+
+ // The second argument must also be a String, or cast to a String
+ _token = argument(1);
+ Type tokenType = _token.typeCheck(stable);
+ if (tokenType != Type.String)
+ _token = new CastExpr(_token, Type.String);
+
+ return _type = Type.Boolean;
+ }
+
+ /**
+ * Compile the expression - leave boolean expression on stack
+ */
+ public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
+ translateDesynthesized(classGen, methodGen);
+ synthesize(classGen, methodGen);
+ }
+
+ /**
+ * Compile expression and update true/false-lists
+ */
+ public void translateDesynthesized(ClassGenerator classGen,
+ MethodGenerator methodGen) {
+ final ConstantPoolGen cpg = classGen.getConstantPool();
+ final InstructionList il = methodGen.getInstructionList();
+ _base.translate(classGen, methodGen);
+ _token.translate(classGen, methodGen);
+ il.append(new INVOKEVIRTUAL(cpg.addMethodref(STRING_CLASS,
+ "indexOf",
+ "("+STRING_SIG+")I")));
+ _falseList.add(il.append(new IFLT(null)));
+ }
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/compiler/Copy.java b/src/main/java/org/apache/xalan/xsltc/compiler/Copy.java
new file mode 100644
index 000000000..6ca4ca529
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/compiler/Copy.java
@@ -0,0 +1,151 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.compiler;
+
+import org.apache.bcel.generic.ALOAD;
+import org.apache.bcel.generic.ASTORE;
+import org.apache.bcel.generic.BranchHandle;
+import org.apache.bcel.generic.ConstantPoolGen;
+import org.apache.bcel.generic.IFEQ;
+import org.apache.bcel.generic.IFNULL;
+import org.apache.bcel.generic.ILOAD;
+import org.apache.bcel.generic.INVOKEINTERFACE;
+import org.apache.bcel.generic.INVOKEVIRTUAL;
+import org.apache.bcel.generic.ISTORE;
+import org.apache.bcel.generic.InstructionHandle;
+import org.apache.bcel.generic.InstructionList;
+import org.apache.bcel.generic.LocalVariableGen;
+import org.apache.xalan.xsltc.compiler.util.ClassGenerator;
+import org.apache.xalan.xsltc.compiler.util.ErrorMsg;
+import org.apache.xalan.xsltc.compiler.util.MethodGenerator;
+import org.apache.xalan.xsltc.compiler.util.Type;
+import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
+import org.apache.xalan.xsltc.compiler.util.Util;
+
+/**
+ * @author Jacek Ambroziak
+ * @author Santiago Pericas-Geertsen
+ */
+final class Copy extends Instruction {
+ private UseAttributeSets _useSets;
+
+ public void parseContents(Parser parser) {
+ final String useSets = getAttribute("use-attribute-sets");
+ if (useSets.length() > 0) {
+ if (!Util.isValidQNames(useSets)) {
+ ErrorMsg err = new ErrorMsg(ErrorMsg.INVALID_QNAME_ERR, useSets, this);
+ parser.reportError(Constants.ERROR, err);
+ }
+ _useSets = new UseAttributeSets(useSets, parser);
+ }
+ parseChildren(parser);
+ }
+
+ public void display(int indent) {
+ indent(indent);
+ Util.println("Copy");
+ indent(indent + IndentIncrement);
+ displayContents(indent + IndentIncrement);
+ }
+
+ public Type typeCheck(SymbolTable stable) throws TypeCheckError {
+ if (_useSets != null) {
+ _useSets.typeCheck(stable);
+ }
+ typeCheckContents(stable);
+ return Type.Void;
+ }
+
+ public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
+ final ConstantPoolGen cpg = classGen.getConstantPool();
+ final InstructionList il = methodGen.getInstructionList();
+
+ final LocalVariableGen name =
+ methodGen.addLocalVariable2("name",
+ Util.getJCRefType(STRING_SIG),
+ null);
+ final LocalVariableGen length =
+ methodGen.addLocalVariable2("length",
+ Util.getJCRefType("I"),
+ null);
+
+ // Get the name of the node to copy and save for later
+ il.append(methodGen.loadDOM());
+ il.append(methodGen.loadCurrentNode());
+ il.append(methodGen.loadHandler());
+ final int cpy = cpg.addInterfaceMethodref(DOM_INTF,
+ "shallowCopy",
+ "("
+ + NODE_SIG
+ + TRANSLET_OUTPUT_SIG
+ + ")" + STRING_SIG);
+ il.append(new INVOKEINTERFACE(cpy, 3));
+ il.append(DUP);
+ name.setStart(il.append(new ASTORE(name.getIndex())));
+ final BranchHandle ifBlock1 = il.append(new IFNULL(null));
+
+ // Get the length of the node name and save for later
+ il.append(new ALOAD(name.getIndex()));
+ final int lengthMethod = cpg.addMethodref(STRING_CLASS,"length","()I");
+ il.append(new INVOKEVIRTUAL(lengthMethod));
+ length.setStart(il.append(new ISTORE(length.getIndex())));
+
+ // Copy in attribute sets if specified
+ if (_useSets != null) {
+ // If the parent of this element will result in an element being
+ // output then we know that it is safe to copy out the attributes
+ final SyntaxTreeNode parent = getParent();
+ if ((parent instanceof LiteralElement) ||
+ (parent instanceof LiteralElement)) {
+ _useSets.translate(classGen, methodGen);
+ }
+ // If not we have to check to see if the copy will result in an
+ // element being output.
+ else {
+ // check if element; if not skip to translate body
+ il.append(new ILOAD(length.getIndex()));
+ final BranchHandle ifBlock2 = il.append(new IFEQ(null));
+ // length != 0 -> element -> do attribute sets
+ _useSets.translate(classGen, methodGen);
+ // not an element; root
+ ifBlock2.setTarget(il.append(NOP));
+ }
+ }
+
+ // Instantiate body of xsl:copy
+ translateContents(classGen, methodGen);
+
+ // Call the output handler's endElement() if we copied an element
+ // (The DOM.shallowCopy() method calls startElement().)
+ length.setEnd(il.append(new ILOAD(length.getIndex())));
+ final BranchHandle ifBlock3 = il.append(new IFEQ(null));
+ il.append(methodGen.loadHandler());
+ name.setEnd(il.append(new ALOAD(name.getIndex())));
+ il.append(methodGen.endElement());
+
+ final InstructionHandle end = il.append(NOP);
+ ifBlock1.setTarget(end);
+ ifBlock3.setTarget(end);
+ methodGen.removeLocalVariable(name);
+ methodGen.removeLocalVariable(length);
+ }
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/compiler/CopyOf.java b/src/main/java/org/apache/xalan/xsltc/compiler/CopyOf.java
new file mode 100644
index 000000000..55f7ee5f9
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/compiler/CopyOf.java
@@ -0,0 +1,141 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.compiler;
+
+import org.apache.bcel.generic.ConstantPoolGen;
+import org.apache.bcel.generic.INVOKEINTERFACE;
+import org.apache.bcel.generic.INVOKESTATIC;
+import org.apache.bcel.generic.INVOKEVIRTUAL;
+import org.apache.bcel.generic.InstructionList;
+import org.apache.xalan.xsltc.compiler.util.ClassGenerator;
+import org.apache.xalan.xsltc.compiler.util.ErrorMsg;
+import org.apache.xalan.xsltc.compiler.util.MethodGenerator;
+import org.apache.xalan.xsltc.compiler.util.NodeSetType;
+import org.apache.xalan.xsltc.compiler.util.NodeType;
+import org.apache.xalan.xsltc.compiler.util.ReferenceType;
+import org.apache.xalan.xsltc.compiler.util.ResultTreeType;
+import org.apache.xalan.xsltc.compiler.util.Type;
+import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
+import org.apache.xalan.xsltc.compiler.util.Util;
+
+/**
+ * @author Jacek Ambroziak
+ * @author Santiago Pericas-Geertsen
+ */
+final class CopyOf extends Instruction {
+ private Expression _select;
+
+ public void display(int indent) {
+ indent(indent);
+ Util.println("CopyOf");
+ indent(indent + IndentIncrement);
+ Util.println("select " + _select.toString());
+ }
+
+ public void parseContents(Parser parser) {
+ _select = parser.parseExpression(this, "select", null);
+ // make sure required attribute(s) have been set
+ if (_select.isDummy()) {
+ reportError(this, parser, ErrorMsg.REQUIRED_ATTR_ERR, "select");
+ return;
+ }
+ }
+
+ public Type typeCheck(SymbolTable stable) throws TypeCheckError {
+ final Type tselect = _select.typeCheck(stable);
+ if (tselect instanceof NodeType ||
+ tselect instanceof NodeSetType ||
+ tselect instanceof ReferenceType ||
+ tselect instanceof ResultTreeType) {
+ // falls through
+ }
+ else {
+ _select = new CastExpr(_select, Type.String);
+ }
+ return Type.Void;
+ }
+
+ public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
+ final ConstantPoolGen cpg = classGen.getConstantPool();
+ final InstructionList il = methodGen.getInstructionList();
+ final Type tselect = _select.getType();
+
+ final String CPY1_SIG = "("+NODE_ITERATOR_SIG+TRANSLET_OUTPUT_SIG+")V";
+ final int cpy1 = cpg.addInterfaceMethodref(DOM_INTF, "copy", CPY1_SIG);
+
+ final String CPY2_SIG = "("+NODE_SIG+TRANSLET_OUTPUT_SIG+")V";
+ final int cpy2 = cpg.addInterfaceMethodref(DOM_INTF, "copy", CPY2_SIG);
+
+ final String getDoc_SIG = "()"+NODE_SIG;
+ final int getDoc = cpg.addInterfaceMethodref(DOM_INTF, "getDocument", getDoc_SIG);
+
+
+ if (tselect instanceof NodeSetType) {
+ il.append(methodGen.loadDOM());
+
+ // push NodeIterator
+ _select.translate(classGen, methodGen);
+ _select.startIterator(classGen, methodGen);
+
+ // call copy from the DOM 'library'
+ il.append(methodGen.loadHandler());
+ il.append(new INVOKEINTERFACE(cpy1, 3));
+ }
+ else if (tselect instanceof NodeType) {
+ il.append(methodGen.loadDOM());
+ _select.translate(classGen, methodGen);
+ il.append(methodGen.loadHandler());
+ il.append(new INVOKEINTERFACE(cpy2, 3));
+ }
+ else if (tselect instanceof ResultTreeType) {
+ _select.translate(classGen, methodGen);
+ // We want the whole tree, so we start with the root node
+ il.append(DUP); //need a pointer to the DOM ;
+ il.append(new INVOKEINTERFACE(getDoc,1)); //ICONST_0);
+ il.append(methodGen.loadHandler());
+ il.append(new INVOKEINTERFACE(cpy2, 3));
+ }
+ else if (tselect instanceof ReferenceType) {
+ _select.translate(classGen, methodGen);
+ il.append(methodGen.loadHandler());
+ il.append(methodGen.loadCurrentNode());
+ il.append(methodGen.loadDOM());
+ final int copy = cpg.addMethodref(BASIS_LIBRARY_CLASS, "copy",
+ "("
+ + OBJECT_SIG
+ + TRANSLET_OUTPUT_SIG
+ + NODE_SIG
+ + DOM_INTF_SIG
+ + ")V");
+ il.append(new INVOKESTATIC(copy));
+ }
+ else {
+ il.append(classGen.loadTranslet());
+ _select.translate(classGen, methodGen);
+ il.append(methodGen.loadHandler());
+ il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS,
+ CHARACTERSW,
+ CHARACTERSW_SIG)));
+ }
+
+ }
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/compiler/CurrentCall.java b/src/main/java/org/apache/xalan/xsltc/compiler/CurrentCall.java
new file mode 100644
index 000000000..98b4fc497
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/compiler/CurrentCall.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.compiler;
+
+import org.apache.xalan.xsltc.compiler.util.ClassGenerator;
+import org.apache.xalan.xsltc.compiler.util.MethodGenerator;
+
+/**
+ * @author Jacek Ambroziak
+ * @author Santiago Pericas-Geertsen
+ */
+final class CurrentCall extends FunctionCall {
+ public CurrentCall(QName fname) {
+ super(fname);
+ }
+
+ public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
+ methodGen.getInstructionList().append(methodGen.loadCurrentNode());
+ }
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/compiler/DecimalFormatting.java b/src/main/java/org/apache/xalan/xsltc/compiler/DecimalFormatting.java
new file mode 100644
index 000000000..300b3e031
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/compiler/DecimalFormatting.java
@@ -0,0 +1,256 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.compiler;
+
+import org.apache.bcel.generic.ConstantPoolGen;
+import org.apache.bcel.generic.GETSTATIC;
+import org.apache.bcel.generic.INVOKESPECIAL;
+import org.apache.bcel.generic.INVOKEVIRTUAL;
+import org.apache.bcel.generic.InstructionList;
+import org.apache.bcel.generic.NEW;
+import org.apache.bcel.generic.PUSH;
+import org.apache.xalan.xsltc.compiler.util.ClassGenerator;
+import org.apache.xalan.xsltc.compiler.util.ErrorMsg;
+import org.apache.xalan.xsltc.compiler.util.MethodGenerator;
+import org.apache.xalan.xsltc.compiler.util.Type;
+import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
+import org.apache.xml.utils.XML11Char;
+
+/**
+ * @author Jacek Ambroziak
+ * @author Santiago Pericas-Geertsen
+ * @author Morten Jorgensen
+ */
+final class DecimalFormatting extends TopLevelElement {
+
+ private static final String DFS_CLASS = "java.text.DecimalFormatSymbols";
+ private static final String DFS_SIG = "Ljava/text/DecimalFormatSymbols;";
+
+ private QName _name = null;
+
+ /**
+ * No type check needed for the <xsl:decimal-formatting/> element
+ */
+ public Type typeCheck(SymbolTable stable) throws TypeCheckError {
+ return Type.Void;
+ }
+
+ /**
+ * Parse the name of the <xsl:decimal-formatting/> element
+ */
+ public void parseContents(Parser parser) {
+ // Get the name of these decimal formatting symbols
+ final String name = getAttribute("name");
+ if (name.length() > 0) {
+ if (!XML11Char.isXML11ValidQName(name)){
+ ErrorMsg err = new ErrorMsg(ErrorMsg.INVALID_QNAME_ERR, name, this);
+ parser.reportError(Constants.ERROR, err);
+ }
+ }
+ _name = parser.getQNameIgnoreDefaultNs(name);
+ if (_name == null) {
+ _name = parser.getQNameIgnoreDefaultNs(EMPTYSTRING);
+ }
+
+ // Check if a set of symbols has already been registered under this name
+ SymbolTable stable = parser.getSymbolTable();
+ if (stable.getDecimalFormatting(_name) != null) {
+ reportWarning(this, parser, ErrorMsg.SYMBOLS_REDEF_ERR,
+ _name.toString());
+ }
+ else {
+ stable.addDecimalFormatting(_name, this);
+ }
+ }
+
+ /**
+ * This method is called when the constructor is compiled in
+ * Stylesheet.compileConstructor() and not as the syntax tree is traversed.
+ */
+ public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
+
+ ConstantPoolGen cpg = classGen.getConstantPool();
+ InstructionList il = methodGen.getInstructionList();
+
+ // DecimalFormatSymbols.<init>(Locale);
+ // xsl:decimal-format - except for the NaN and infinity attributes.
+ final int init = cpg.addMethodref(DFS_CLASS, "<init>",
+ "("+LOCALE_SIG+")V");
+
+ // Push the format name on the stack for call to addDecimalFormat()
+ il.append(classGen.loadTranslet());
+ il.append(new PUSH(cpg, _name.toString()));
+
+ // Manufacture a DecimalFormatSymbols on the stack
+ // for call to addDecimalFormat()
+ // Use the US Locale as the default, as most of its settings
+ // are equivalent to the default settings required of
+ il.append(new NEW(cpg.addClass(DFS_CLASS)));
+ il.append(DUP);
+ il.append(new GETSTATIC(cpg.addFieldref(LOCALE_CLASS, "US",
+ LOCALE_SIG)));
+ il.append(new INVOKESPECIAL(init));
+
+ String tmp = getAttribute("NaN");
+ if ((tmp == null) || (tmp.equals(EMPTYSTRING))) {
+ int nan = cpg.addMethodref(DFS_CLASS,
+ "setNaN", "(Ljava/lang/String;)V");
+ il.append(DUP);
+ il.append(new PUSH(cpg, "NaN"));
+ il.append(new INVOKEVIRTUAL(nan));
+ }
+
+ tmp = getAttribute("infinity");
+ if ((tmp == null) || (tmp.equals(EMPTYSTRING))) {
+ int inf = cpg.addMethodref(DFS_CLASS,
+ "setInfinity",
+ "(Ljava/lang/String;)V");
+ il.append(DUP);
+ il.append(new PUSH(cpg, "Infinity"));
+ il.append(new INVOKEVIRTUAL(inf));
+ }
+
+ final int nAttributes = _attributes.getLength();
+ for (int i = 0; i < nAttributes; i++) {
+ final String name = _attributes.getQName(i);
+ final String value = _attributes.getValue(i);
+
+ boolean valid = true;
+ int method = 0;
+
+ if (name.equals("decimal-separator")) {
+ // DecimalFormatSymbols.setDecimalSeparator();
+ method = cpg.addMethodref(DFS_CLASS,
+ "setDecimalSeparator", "(C)V");
+ }
+ else if (name.equals("grouping-separator")) {
+ method = cpg.addMethodref(DFS_CLASS,
+ "setGroupingSeparator", "(C)V");
+ }
+ else if (name.equals("minus-sign")) {
+ method = cpg.addMethodref(DFS_CLASS,
+ "setMinusSign", "(C)V");
+ }
+ else if (name.equals("percent")) {
+ method = cpg.addMethodref(DFS_CLASS,
+ "setPercent", "(C)V");
+ }
+ else if (name.equals("per-mille")) {
+ method = cpg.addMethodref(DFS_CLASS,
+ "setPerMill", "(C)V");
+ }
+ else if (name.equals("zero-digit")) {
+ method = cpg.addMethodref(DFS_CLASS,
+ "setZeroDigit", "(C)V");
+ }
+ else if (name.equals("digit")) {
+ method = cpg.addMethodref(DFS_CLASS,
+ "setDigit", "(C)V");
+ }
+ else if (name.equals("pattern-separator")) {
+ method = cpg.addMethodref(DFS_CLASS,
+ "setPatternSeparator", "(C)V");
+ }
+ else if (name.equals("NaN")) {
+ method = cpg.addMethodref(DFS_CLASS,
+ "setNaN", "(Ljava/lang/String;)V");
+ il.append(DUP);
+ il.append(new PUSH(cpg, value));
+ il.append(new INVOKEVIRTUAL(method));
+ valid = false;
+ }
+ else if (name.equals("infinity")) {
+ method = cpg.addMethodref(DFS_CLASS,
+ "setInfinity",
+ "(Ljava/lang/String;)V");
+ il.append(DUP);
+ il.append(new PUSH(cpg, value));
+ il.append(new INVOKEVIRTUAL(method));
+ valid = false;
+ }
+ else {
+ valid = false;
+ }
+
+ if (valid) {
+ il.append(DUP);
+ il.append(new PUSH(cpg, value.charAt(0)));
+ il.append(new INVOKEVIRTUAL(method));
+ }
+
+ }
+
+ final int put = cpg.addMethodref(TRANSLET_CLASS,
+ "addDecimalFormat",
+ "("+STRING_SIG+DFS_SIG+")V");
+ il.append(new INVOKEVIRTUAL(put));
+ }
+
+ /**
+ * Creates the default, nameless, DecimalFormat object in
+ * AbstractTranslet's format_symbols hashtable.
+ * This should be called for every stylesheet, and the entry
+ * may be overridden by later nameless xsl:decimal-format instructions.
+ */
+ public static void translateDefaultDFS(ClassGenerator classGen,
+ MethodGenerator methodGen) {
+
+ ConstantPoolGen cpg = classGen.getConstantPool();
+ InstructionList il = methodGen.getInstructionList();
+ final int init = cpg.addMethodref(DFS_CLASS, "<init>",
+ "("+LOCALE_SIG+")V");
+
+ // Push the format name, which is empty, on the stack
+ // for call to addDecimalFormat()
+ il.append(classGen.loadTranslet());
+ il.append(new PUSH(cpg, EMPTYSTRING));
+
+ // Manufacture a DecimalFormatSymbols on the stack for
+ // call to addDecimalFormat(). Use the US Locale as the
+ // default, as most of its settings are equivalent to
+ // the default settings required of xsl:decimal-format -
+ // except for the NaN and infinity attributes.
+ il.append(new NEW(cpg.addClass(DFS_CLASS)));
+ il.append(DUP);
+ il.append(new GETSTATIC(cpg.addFieldref(LOCALE_CLASS, "US",
+ LOCALE_SIG)));
+ il.append(new INVOKESPECIAL(init));
+
+ int nan = cpg.addMethodref(DFS_CLASS,
+ "setNaN", "(Ljava/lang/String;)V");
+ il.append(DUP);
+ il.append(new PUSH(cpg, "NaN"));
+ il.append(new INVOKEVIRTUAL(nan));
+
+ int inf = cpg.addMethodref(DFS_CLASS,
+ "setInfinity",
+ "(Ljava/lang/String;)V");
+ il.append(DUP);
+ il.append(new PUSH(cpg, "Infinity"));
+ il.append(new INVOKEVIRTUAL(inf));
+
+ final int put = cpg.addMethodref(TRANSLET_CLASS,
+ "addDecimalFormat",
+ "("+STRING_SIG+DFS_SIG+")V");
+ il.append(new INVOKEVIRTUAL(put));
+ }
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/compiler/DocumentCall.java b/src/main/java/org/apache/xalan/xsltc/compiler/DocumentCall.java
new file mode 100644
index 000000000..fc3666a8e
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/compiler/DocumentCall.java
@@ -0,0 +1,155 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.compiler;
+
+import java.util.Vector;
+
+import org.apache.bcel.generic.ConstantPoolGen;
+import org.apache.bcel.generic.GETFIELD;
+import org.apache.bcel.generic.INVOKESTATIC;
+import org.apache.bcel.generic.InstructionList;
+import org.apache.bcel.generic.PUSH;
+import org.apache.xalan.xsltc.compiler.util.ClassGenerator;
+import org.apache.xalan.xsltc.compiler.util.ErrorMsg;
+import org.apache.xalan.xsltc.compiler.util.MethodGenerator;
+import org.apache.xalan.xsltc.compiler.util.Type;
+import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
+
+/**
+ * @author Jacek Ambroziak
+ * @author Morten Jorgensen
+ */
+final class DocumentCall extends FunctionCall {
+
+ private Expression _arg1 = null;
+ private Expression _arg2 = null;
+ private Type _arg1Type;
+
+ /**
+ * Default function call constructor
+ */
+ public DocumentCall(QName fname, Vector arguments) {
+ super(fname, arguments);
+ }
+
+ /**
+ * Type checks the arguments passed to the document() function. The first
+ * argument can be any type (we must cast it to a string) and contains the
+ * URI of the document
+ */
+ public Type typeCheck(SymbolTable stable) throws TypeCheckError {
+ // At least one argument - two at most
+ final int ac = argumentCount();
+ if ((ac < 1) || (ac > 2)) {
+ ErrorMsg msg = new ErrorMsg(ErrorMsg.ILLEGAL_ARG_ERR, this);
+ throw new TypeCheckError(msg);
+ }
+ if (getStylesheet() == null) {
+ ErrorMsg msg = new ErrorMsg(ErrorMsg.ILLEGAL_ARG_ERR, this);
+ throw new TypeCheckError(msg);
+ }
+
+ // Parse the first argument
+ _arg1 = argument(0);
+
+ if (_arg1 == null) {// should not happened
+ ErrorMsg msg = new ErrorMsg(ErrorMsg.DOCUMENT_ARG_ERR, this);
+ throw new TypeCheckError(msg);
+ }
+
+ _arg1Type = _arg1.typeCheck(stable);
+ if ((_arg1Type != Type.NodeSet) && (_arg1Type != Type.String)) {
+ _arg1 = new CastExpr(_arg1, Type.String);
+ }
+
+ // Parse the second argument
+ if (ac == 2) {
+ _arg2 = argument(1);
+
+ if (_arg2 == null) {// should not happened
+ ErrorMsg msg = new ErrorMsg(ErrorMsg.DOCUMENT_ARG_ERR, this);
+ throw new TypeCheckError(msg);
+ }
+
+ final Type arg2Type = _arg2.typeCheck(stable);
+
+ if (arg2Type.identicalTo(Type.Node)) {
+ _arg2 = new CastExpr(_arg2, Type.NodeSet);
+ } else if (arg2Type.identicalTo(Type.NodeSet)) {
+ // falls through
+ } else {
+ ErrorMsg msg = new ErrorMsg(ErrorMsg.DOCUMENT_ARG_ERR, this);
+ throw new TypeCheckError(msg);
+ }
+ }
+
+ return _type = Type.NodeSet;
+ }
+
+ /**
+ * Translates the document() function call to a call to LoadDocument()'s
+ * static method document().
+ */
+ public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
+ final ConstantPoolGen cpg = classGen.getConstantPool();
+ final InstructionList il = methodGen.getInstructionList();
+ final int ac = argumentCount();
+
+ final int domField = cpg.addFieldref(classGen.getClassName(),
+ DOM_FIELD,
+ DOM_INTF_SIG);
+
+ String docParamList = null;
+ if (ac == 1) {
+ // documentF(Object,String,AbstractTranslet,DOM)
+ docParamList = "("+OBJECT_SIG+STRING_SIG+TRANSLET_SIG+DOM_INTF_SIG
+ +")"+NODE_ITERATOR_SIG;
+ } else { //ac == 2; ac < 1 or as >2 was tested in typeChec()
+ // documentF(Object,DTMAxisIterator,String,AbstractTranslet,DOM)
+ docParamList = "("+OBJECT_SIG+NODE_ITERATOR_SIG+STRING_SIG
+ +TRANSLET_SIG+DOM_INTF_SIG+")"+NODE_ITERATOR_SIG;
+ }
+ final int docIdx = cpg.addMethodref(LOAD_DOCUMENT_CLASS, "documentF",
+ docParamList);
+
+
+ // The URI can be either a node-set or something else cast to a string
+ _arg1.translate(classGen, methodGen);
+ if (_arg1Type == Type.NodeSet) {
+ _arg1.startIterator(classGen, methodGen);
+ }
+
+ if (ac == 2) {
+ //_arg2 == null was tested in typeChec()
+ _arg2.translate(classGen, methodGen);
+ _arg2.startIterator(classGen, methodGen);
+ }
+
+ // Process the rest of the parameters on the stack
+ il.append(new PUSH(cpg, getStylesheet().getSystemId()));
+ il.append(classGen.loadTranslet());
+ il.append(DUP);
+ il.append(new GETFIELD(domField));
+ il.append(new INVOKESTATIC(docIdx));
+ }
+
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/compiler/ElementAvailableCall.java b/src/main/java/org/apache/xalan/xsltc/compiler/ElementAvailableCall.java
new file mode 100644
index 000000000..161c549a8
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/compiler/ElementAvailableCall.java
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.compiler;
+
+import java.util.Vector;
+
+import org.apache.bcel.generic.ConstantPoolGen;
+import org.apache.bcel.generic.PUSH;
+import org.apache.xalan.xsltc.compiler.util.ClassGenerator;
+import org.apache.xalan.xsltc.compiler.util.ErrorMsg;
+import org.apache.xalan.xsltc.compiler.util.MethodGenerator;
+import org.apache.xalan.xsltc.compiler.util.Type;
+import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
+
+/**
+ * @author Jacek Ambroziak
+ * @author Santiago Pericas-Geertsen
+ */
+final class ElementAvailableCall extends FunctionCall {
+
+ public ElementAvailableCall(QName fname, Vector arguments) {
+ super(fname, arguments);
+ }
+
+ /**
+ * Force the argument to this function to be a literal string.
+ */
+ public Type typeCheck(SymbolTable stable) throws TypeCheckError {
+ if (argument() instanceof LiteralExpr) {
+ return _type = Type.Boolean;
+ }
+ ErrorMsg err = new ErrorMsg(ErrorMsg.NEED_LITERAL_ERR,
+ "element-available", this);
+ throw new TypeCheckError(err);
+ }
+
+ /**
+ * Returns an object representing the compile-time evaluation
+ * of an expression. We are only using this for function-available
+ * and element-available at this time.
+ */
+ public Object evaluateAtCompileTime() {
+ return getResult() ? Boolean.TRUE : Boolean.FALSE;
+ }
+
+ /**
+ * Returns the result that this function will return
+ */
+ public boolean getResult() {
+ try {
+ final LiteralExpr arg = (LiteralExpr) argument();
+ final String qname = arg.getValue();
+ final int index = qname.indexOf(':');
+ final String localName = (index > 0) ?
+ qname.substring(index + 1) : qname;
+ return getParser().elementSupported(arg.getNamespace(),
+ localName);
+ }
+ catch (ClassCastException e) {
+ return false;
+ }
+ }
+
+ /**
+ * Calls to 'element-available' are resolved at compile time since
+ * the namespaces declared in the stylsheet are not available at run
+ * time. Consequently, arguments to this function must be literals.
+ */
+ public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
+ final ConstantPoolGen cpg = classGen.getConstantPool();
+ final boolean result = getResult();
+ methodGen.getInstructionList().append(new PUSH(cpg, result));
+ }
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/compiler/EqualityExpr.java b/src/main/java/org/apache/xalan/xsltc/compiler/EqualityExpr.java
new file mode 100644
index 000000000..5a22dfead
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/compiler/EqualityExpr.java
@@ -0,0 +1,359 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.compiler;
+
+import org.apache.bcel.generic.BranchHandle;
+import org.apache.bcel.generic.BranchInstruction;
+import org.apache.bcel.generic.ConstantPoolGen;
+import org.apache.bcel.generic.GOTO;
+import org.apache.bcel.generic.IFEQ;
+import org.apache.bcel.generic.IFNE;
+import org.apache.bcel.generic.IF_ICMPEQ;
+import org.apache.bcel.generic.IF_ICMPNE;
+import org.apache.bcel.generic.INVOKESTATIC;
+import org.apache.bcel.generic.INVOKEVIRTUAL;
+import org.apache.bcel.generic.InstructionList;
+import org.apache.bcel.generic.PUSH;
+import org.apache.xalan.xsltc.compiler.util.BooleanType;
+import org.apache.xalan.xsltc.compiler.util.ClassGenerator;
+import org.apache.xalan.xsltc.compiler.util.IntType;
+import org.apache.xalan.xsltc.compiler.util.MethodGenerator;
+import org.apache.xalan.xsltc.compiler.util.NodeSetType;
+import org.apache.xalan.xsltc.compiler.util.NodeType;
+import org.apache.xalan.xsltc.compiler.util.NumberType;
+import org.apache.xalan.xsltc.compiler.util.RealType;
+import org.apache.xalan.xsltc.compiler.util.ReferenceType;
+import org.apache.xalan.xsltc.compiler.util.ResultTreeType;
+import org.apache.xalan.xsltc.compiler.util.StringType;
+import org.apache.xalan.xsltc.compiler.util.Type;
+import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
+import org.apache.xalan.xsltc.runtime.Operators;
+
+/**
+ * @author Jacek Ambroziak
+ * @author Santiago Pericas-Geertsen
+ * @author Morten Jorgensen
+ * @author Erwin Bolwidt <ej...@klomp.org>
+ */
+final class EqualityExpr extends Expression {
+
+ private final int _op;
+ private Expression _left;
+ private Expression _right;
+
+ public EqualityExpr(int op, Expression left, Expression right) {
+ _op = op;
+ (_left = left).setParent(this);
+ (_right = right).setParent(this);
+ }
+
+ public void setParser(Parser parser) {
+ super.setParser(parser);
+ _left.setParser(parser);
+ _right.setParser(parser);
+ }
+
+ public String toString() {
+ return Operators.getOpNames(_op) + '(' + _left + ", " + _right + ')';
+ }
+
+ public Expression getLeft() {
+ return _left;
+ }
+
+ public Expression getRight() {
+ return _right;
+ }
+
+ public boolean getOp() {
+ return (_op != Operators.NE);
+ }
+
+ /**
+ * Returns true if this expressions contains a call to position(). This is
+ * needed for context changes in node steps containing multiple predicates.
+ */
+ public boolean hasPositionCall() {
+ if (_left.hasPositionCall()) return true;
+ if (_right.hasPositionCall()) return true;
+ return false;
+ }
+
+ public boolean hasLastCall() {
+ if (_left.hasLastCall()) return true;
+ if (_right.hasLastCall()) return true;
+ return false;
+ }
+
+ private void swapArguments() {
+ final Expression temp = _left;
+ _left = _right;
+ _right = temp;
+ }
+
+ /**
+ * Typing rules: see XSLT Reference by M. Kay page 345.
+ */
+ public Type typeCheck(SymbolTable stable) throws TypeCheckError {
+ final Type tleft = _left.typeCheck(stable);
+ final Type tright = _right.typeCheck(stable);
+
+ if (tleft.isSimple() && tright.isSimple()) {
+ if (tleft != tright) {
+ if (tleft instanceof BooleanType) {
+ _right = new CastExpr(_right, Type.Boolean);
+ }
+ else if (tright instanceof BooleanType) {
+ _left = new CastExpr(_left, Type.Boolean);
+ }
+ else if (tleft instanceof NumberType ||
+ tright instanceof NumberType) {
+ _left = new CastExpr(_left, Type.Real);
+ _right = new CastExpr(_right, Type.Real);
+ }
+ else { // both compared as strings
+ _left = new CastExpr(_left, Type.String);
+ _right = new CastExpr(_right, Type.String);
+ }
+ }
+ }
+ else if (tleft instanceof ReferenceType) {
+ _right = new CastExpr(_right, Type.Reference);
+ }
+ else if (tright instanceof ReferenceType) {
+ _left = new CastExpr(_left, Type.Reference);
+ }
+ // the following 2 cases optimize @attr|.|.. = 'string'
+ else if (tleft instanceof NodeType && tright == Type.String) {
+ _left = new CastExpr(_left, Type.String);
+ }
+ else if (tleft == Type.String && tright instanceof NodeType) {
+ _right = new CastExpr(_right, Type.String);
+ }
+ // optimize node/node
+ else if (tleft instanceof NodeType && tright instanceof NodeType) {
+ _left = new CastExpr(_left, Type.String);
+ _right = new CastExpr(_right, Type.String);
+ }
+ else if (tleft instanceof NodeType && tright instanceof NodeSetType) {
+ // compare(Node, NodeSet) will be invoked
+ }
+ else if (tleft instanceof NodeSetType && tright instanceof NodeType) {
+ swapArguments(); // for compare(Node, NodeSet)
+ }
+ else {
+ // At least one argument is of type node, node-set or result-tree
+
+ // Promote an expression of type node to node-set
+ if (tleft instanceof NodeType) {
+ _left = new CastExpr(_left, Type.NodeSet);
+ }
+ if (tright instanceof NodeType) {
+ _right = new CastExpr(_right, Type.NodeSet);
+ }
+
+ // If one arg is a node-set then make it the left one
+ if (tleft.isSimple() ||
+ tleft instanceof ResultTreeType &&
+ tright instanceof NodeSetType) {
+ swapArguments();
+ }
+
+ // Promote integers to doubles to have fewer compares
+ if (_right.getType() instanceof IntType) {
+ _right = new CastExpr(_right, Type.Real);
+ }
+ }
+ return _type = Type.Boolean;
+ }
+
+ public void translateDesynthesized(ClassGenerator classGen,
+ MethodGenerator methodGen) {
+ final Type tleft = _left.getType();
+ final InstructionList il = methodGen.getInstructionList();
+
+ if (tleft instanceof BooleanType) {
+ _left.translate(classGen, methodGen);
+ _right.translate(classGen, methodGen);
+ _falseList.add(il.append(_op == Operators.EQ ?
+ (BranchInstruction)new IF_ICMPNE(null) :
+ (BranchInstruction)new IF_ICMPEQ(null)));
+ }
+ else if (tleft instanceof NumberType) {
+ _left.translate(classGen, methodGen);
+ _right.translate(classGen, methodGen);
+
+ if (tleft instanceof RealType) {
+ il.append(DCMPG);
+ _falseList.add(il.append(_op == Operators.EQ ?
+ (BranchInstruction)new IFNE(null) :
+ (BranchInstruction)new IFEQ(null)));
+ }
+ else {
+ _falseList.add(il.append(_op == Operators.EQ ?
+ (BranchInstruction)new IF_ICMPNE(null) :
+ (BranchInstruction)new IF_ICMPEQ(null)));
+ }
+ }
+ else {
+ translate(classGen, methodGen);
+ desynthesize(classGen, methodGen);
+ }
+ }
+
+ public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
+ final ConstantPoolGen cpg = classGen.getConstantPool();
+ final InstructionList il = methodGen.getInstructionList();
+
+ final Type tleft = _left.getType();
+ Type tright = _right.getType();
+
+ if (tleft instanceof BooleanType || tleft instanceof NumberType) {
+ translateDesynthesized(classGen, methodGen);
+ synthesize(classGen, methodGen);
+ return;
+ }
+
+ if (tleft instanceof StringType) {
+ final int equals = cpg.addMethodref(STRING_CLASS,
+ "equals",
+ "(" + OBJECT_SIG +")Z");
+ _left.translate(classGen, methodGen);
+ _right.translate(classGen, methodGen);
+ il.append(new INVOKEVIRTUAL(equals));
+
+ if (_op == Operators.NE) {
+ il.append(ICONST_1);
+ il.append(IXOR); // not x <-> x xor 1
+ }
+ return;
+ }
+
+ BranchHandle truec, falsec;
+
+ if (tleft instanceof ResultTreeType) {
+ if (tright instanceof BooleanType) {
+ _right.translate(classGen, methodGen);
+ if (_op == Operators.NE) {
+ il.append(ICONST_1);
+ il.append(IXOR); // not x <-> x xor 1
+ }
+ return;
+ }
+
+ if (tright instanceof RealType) {
+ _left.translate(classGen, methodGen);
+ tleft.translateTo(classGen, methodGen, Type.Real);
+ _right.translate(classGen, methodGen);
+
+ il.append(DCMPG);
+ falsec = il.append(_op == Operators.EQ ?
+ (BranchInstruction) new IFNE(null) :
+ (BranchInstruction) new IFEQ(null));
+ il.append(ICONST_1);
+ truec = il.append(new GOTO(null));
+ falsec.setTarget(il.append(ICONST_0));
+ truec.setTarget(il.append(NOP));
+ return;
+ }
+
+ // Next, result-tree/string and result-tree/result-tree comparisons
+
+ _left.translate(classGen, methodGen);
+ tleft.translateTo(classGen, methodGen, Type.String);
+ _right.translate(classGen, methodGen);
+
+ if (tright instanceof ResultTreeType) {
+ tright.translateTo(classGen, methodGen, Type.String);
+ }
+
+ final int equals = cpg.addMethodref(STRING_CLASS,
+ "equals",
+ "(" +OBJECT_SIG+ ")Z");
+ il.append(new INVOKEVIRTUAL(equals));
+
+ if (_op == Operators.NE) {
+ il.append(ICONST_1);
+ il.append(IXOR); // not x <-> x xor 1
+ }
+ return;
+ }
+
+ if (tleft instanceof NodeSetType && tright instanceof BooleanType) {
+ _left.translate(classGen, methodGen);
+ _left.startIterator(classGen, methodGen);
+ Type.NodeSet.translateTo(classGen, methodGen, Type.Boolean);
+ _right.translate(classGen, methodGen);
+
+ il.append(IXOR); // x != y <-> x xor y
+ if (_op == Operators.EQ) {
+ il.append(ICONST_1);
+ il.append(IXOR); // not x <-> x xor 1
+ }
+ return;
+ }
+
+ if (tleft instanceof NodeSetType && tright instanceof StringType) {
+ _left.translate(classGen, methodGen);
+ _left.startIterator(classGen, methodGen); // needed ?
+ _right.translate(classGen, methodGen);
+ il.append(new PUSH(cpg, _op));
+ il.append(methodGen.loadDOM());
+ final int cmp = cpg.addMethodref(BASIS_LIBRARY_CLASS,
+ "compare",
+ "("
+ + tleft.toSignature()
+ + tright.toSignature()
+ + "I"
+ + DOM_INTF_SIG
+ + ")Z");
+ il.append(new INVOKESTATIC(cmp));
+ return;
+ }
+
+ // Next, node-set/t for t in {real, string, node-set, result-tree}
+ _left.translate(classGen, methodGen);
+ _left.startIterator(classGen, methodGen);
+ _right.translate(classGen, methodGen);
+ _right.startIterator(classGen, methodGen);
+
+ // Cast a result tree to a string to use an existing compare
+ if (tright instanceof ResultTreeType) {
+ tright.translateTo(classGen, methodGen, Type.String);
+ tright = Type.String;
+ }
+
+ // Call the appropriate compare() from the BasisLibrary
+ il.append(new PUSH(cpg, _op));
+ il.append(methodGen.loadDOM());
+
+ final int compare = cpg.addMethodref(BASIS_LIBRARY_CLASS,
+ "compare",
+ "("
+ + tleft.toSignature()
+ + tright.toSignature()
+ + "I"
+ + DOM_INTF_SIG
+ + ")Z");
+ il.append(new INVOKESTATIC(compare));
+ }
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/compiler/Expression.java b/src/main/java/org/apache/xalan/xsltc/compiler/Expression.java
new file mode 100644
index 000000000..b9ca0c394
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/compiler/Expression.java
@@ -0,0 +1,222 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.compiler;
+
+import java.util.Vector;
+
+import org.apache.bcel.generic.BranchHandle;
+import org.apache.bcel.generic.ConstantPoolGen;
+import org.apache.bcel.generic.GOTO_W;
+import org.apache.bcel.generic.IFEQ;
+import org.apache.bcel.generic.InstructionHandle;
+import org.apache.bcel.generic.InstructionList;
+import org.apache.xalan.xsltc.compiler.util.BooleanType;
+import org.apache.xalan.xsltc.compiler.util.ClassGenerator;
+import org.apache.xalan.xsltc.compiler.util.ErrorMsg;
+import org.apache.xalan.xsltc.compiler.util.MethodGenerator;
+import org.apache.xalan.xsltc.compiler.util.MethodType;
+import org.apache.xalan.xsltc.compiler.util.NodeSetType;
+import org.apache.xalan.xsltc.compiler.util.Type;
+import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
+
+/**
+ * @author Jacek Ambroziak
+ * @author Santiago Pericas-Geertsen
+ * @author Morten Jorgensen
+ * @author Erwin Bolwidt <ej...@klomp.org>
+ */
+abstract class Expression extends SyntaxTreeNode {
+ /**
+ * The type of this expression. It is set after calling
+ * <code>typeCheck()</code>.
+ */
+ protected Type _type;
+
+ /**
+ * Instruction handles that comprise the true list.
+ */
+ protected FlowList _trueList = new FlowList();
+
+ /**
+ * Instruction handles that comprise the false list.
+ */
+ protected FlowList _falseList = new FlowList();
+
+ public Type getType() {
+ return _type;
+ }
+
+ public abstract String toString();
+
+ public boolean hasPositionCall() {
+ return false; // default should be 'false' for StepPattern
+ }
+
+ public boolean hasLastCall() {
+ return false;
+ }
+
+ /**
+ * Returns an object representing the compile-time evaluation
+ * of an expression. We are only using this for function-available
+ * and element-available at this time.
+ */
+ public Object evaluateAtCompileTime() {
+ return null;
+ }
+
+ /**
+ * Type check all the children of this node.
+ */
+ public Type typeCheck(SymbolTable stable) throws TypeCheckError {
+ return typeCheckContents(stable);
+ }
+
+ /**
+ * Translate this node into JVM bytecodes.
+ */
+ public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
+ ErrorMsg msg = new ErrorMsg(ErrorMsg.NOT_IMPLEMENTED_ERR,
+ getClass(), this);
+ getParser().reportError(FATAL, msg);
+ }
+
+ /**
+ * Translate this node into a fresh instruction list.
+ * The original instruction list is saved and restored.
+ */
+ public final InstructionList compile(ClassGenerator classGen,
+ MethodGenerator methodGen) {
+ final InstructionList result, save = methodGen.getInstructionList();
+ methodGen.setInstructionList(result = new InstructionList());
+ translate(classGen, methodGen);
+ methodGen.setInstructionList(save);
+ return result;
+ }
+
+ /**
+ * Redefined by expressions of type boolean that use flow lists.
+ */
+ public void translateDesynthesized(ClassGenerator classGen,
+ MethodGenerator methodGen) {
+ translate(classGen, methodGen);
+ if (_type instanceof BooleanType) {
+ desynthesize(classGen, methodGen);
+ }
+ }
+
+ /**
+ * If this expression is of type node-set and it is not a variable
+ * reference, then call setStartNode() passing the context node.
+ */
+ public void startIterator(ClassGenerator classGen,
+ MethodGenerator methodGen) {
+ // Ignore if type is not node-set
+ if (_type instanceof NodeSetType == false) {
+ return;
+ }
+
+ // setStartNode() should not be called if expr is a variable ref
+ Expression expr = this;
+ if (expr instanceof CastExpr) {
+ expr = ((CastExpr) expr).getExpr();
+ }
+ if (expr instanceof VariableRefBase == false) {
+ final InstructionList il = methodGen.getInstructionList();
+ il.append(methodGen.loadContextNode());
+ il.append(methodGen.setStartNode());
+ }
+ }
+
+ /**
+ * Synthesize a boolean expression, i.e., either push a 0 or 1 onto the
+ * operand stack for the next statement to succeed. Returns the handle
+ * of the instruction to be backpatched.
+ */
+ public void synthesize(ClassGenerator classGen, MethodGenerator methodGen) {
+ final ConstantPoolGen cpg = classGen.getConstantPool();
+ final InstructionList il = methodGen.getInstructionList();
+ _trueList.backPatch(il.append(ICONST_1));
+ final BranchHandle truec = il.append(new GOTO_W(null));
+ _falseList.backPatch(il.append(ICONST_0));
+ truec.setTarget(il.append(NOP));
+ }
+
+ public void desynthesize(ClassGenerator classGen,
+ MethodGenerator methodGen) {
+ final InstructionList il = methodGen.getInstructionList();
+ _falseList.add(il.append(new IFEQ(null)));
+ }
+
+ public FlowList getFalseList() {
+ return _falseList;
+ }
+
+ public FlowList getTrueList() {
+ return _trueList;
+ }
+
+ public void backPatchFalseList(InstructionHandle ih) {
+ _falseList.backPatch(ih);
+ }
+
+ public void backPatchTrueList(InstructionHandle ih) {
+ _trueList.backPatch(ih);
+ }
+
+ /**
+ * Search for a primop in the symbol table that matches the method type
+ * <code>ctype</code>. Two methods match if they have the same arity.
+ * If a primop is overloaded then the "closest match" is returned. The
+ * first entry in the vector of primops that has the right arity is
+ * considered to be the default one.
+ */
+ public MethodType lookupPrimop(SymbolTable stable, String op,
+ MethodType ctype) {
+ MethodType result = null;
+ final Vector primop = stable.lookupPrimop(op);
+ if (primop != null) {
+ final int n = primop.size();
+ int minDistance = Integer.MAX_VALUE;
+ for (int i = 0; i < n; i++) {
+ final MethodType ptype = (MethodType) primop.elementAt(i);
+ // Skip if different arity
+ if (ptype.argsCount() != ctype.argsCount()) {
+ continue;
+ }
+
+ // The first method with the right arity is the default
+ if (result == null) {
+ result = ptype; // default method
+ }
+
+ // Check if better than last one found
+ final int distance = ctype.distanceTo(ptype);
+ if (distance < minDistance) {
+ minDistance = distance;
+ result = ptype;
+ }
+ }
+ }
+ return result;
+ }
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/compiler/Fallback.java b/src/main/java/org/apache/xalan/xsltc/compiler/Fallback.java
new file mode 100644
index 000000000..28d9a8c27
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/compiler/Fallback.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.compiler;
+
+import org.apache.bcel.generic.ConstantPoolGen;
+import org.apache.bcel.generic.InstructionList;
+import org.apache.xalan.xsltc.compiler.util.ClassGenerator;
+import org.apache.xalan.xsltc.compiler.util.MethodGenerator;
+import org.apache.xalan.xsltc.compiler.util.Type;
+import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
+
+/**
+ * @author Morten Jorgensen
+ */
+final class Fallback extends Instruction {
+
+ private boolean _active = false;
+
+ /**
+ * This element never produces any data on the stack
+ */
+ public Type typeCheck(SymbolTable stable) throws TypeCheckError {
+ if (_active) {
+ return(typeCheckContents(stable));
+ }
+ else {
+ return Type.Void;
+ }
+ }
+
+ /**
+ * Activate this fallback element
+ */
+ public void activate() {
+ _active = true;
+ }
+
+ public String toString() {
+ return("fallback");
+ }
+
+ /**
+ * Parse contents only if this fallback element is put in place of
+ * some unsupported element or non-XSLTC extension element
+ */
+ public void parseContents(Parser parser) {
+ if (_active) parseChildren(parser);
+ }
+
+ /**
+ * Translate contents only if this fallback element is put in place of
+ * some unsupported element or non-XSLTC extension element
+ */
+ public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
+ final ConstantPoolGen cpg = classGen.getConstantPool();
+ final InstructionList il = methodGen.getInstructionList();
+
+ if (_active) translateContents(classGen, methodGen);
+ }
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/compiler/FilterExpr.java b/src/main/java/org/apache/xalan/xsltc/compiler/FilterExpr.java
new file mode 100644
index 000000000..aab6cc6c3
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/compiler/FilterExpr.java
@@ -0,0 +1,246 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.compiler;
+
+import java.util.Vector;
+
+import org.apache.bcel.generic.ALOAD;
+import org.apache.bcel.generic.ASTORE;
+import org.apache.bcel.generic.ConstantPoolGen;
+import org.apache.bcel.generic.ILOAD;
+import org.apache.bcel.generic.INVOKESPECIAL;
+import org.apache.bcel.generic.ISTORE;
+import org.apache.bcel.generic.InstructionList;
+import org.apache.bcel.generic.LocalVariableGen;
+import org.apache.bcel.generic.NEW;
+import org.apache.xalan.xsltc.compiler.util.ClassGenerator;
+import org.apache.xalan.xsltc.compiler.util.MethodGenerator;
+import org.apache.xalan.xsltc.compiler.util.NodeSetType;
+import org.apache.xalan.xsltc.compiler.util.ReferenceType;
+import org.apache.xalan.xsltc.compiler.util.Type;
+import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
+import org.apache.xalan.xsltc.compiler.util.Util;
+
+/**
+ * @author Jacek Ambroziak
+ * @author Santiago Pericas-Geertsen
+ * @author Morten Jorgensen
+ */
+class FilterExpr extends Expression {
+
+ /**
+ * Primary expression of this filter. I.e., 'e' in '(e)[p1]...[pn]'.
+ */
+ private Expression _primary;
+
+ /**
+ * Array of predicates in '(e)[p1]...[pn]'.
+ */
+ private final Vector _predicates;
+
+ public FilterExpr(Expression primary, Vector predicates) {
+ _primary = primary;
+ _predicates = predicates;
+ primary.setParent(this);
+ }
+
+ protected Expression getExpr() {
+ if (_primary instanceof CastExpr)
+ return ((CastExpr)_primary).getExpr();
+ else
+ return _primary;
+ }
+
+ public void setParser(Parser parser) {
+ super.setParser(parser);
+ _primary.setParser(parser);
+ if (_predicates != null) {
+ final int n = _predicates.size();
+ for (int i = 0; i < n; i++) {
+ final Expression exp = (Expression)_predicates.elementAt(i);
+ exp.setParser(parser);
+ exp.setParent(this);
+ }
+ }
+ }
+
+ public String toString() {
+ return "filter-expr(" + _primary + ", " + _predicates + ")";
+ }
+
+ /**
+ * Type check a FilterParentPath. If the filter is not a node-set add a
+ * cast to node-set only if it is of reference type. This type coercion
+ * is needed for expressions like $x where $x is a parameter reference.
+ * All optimizations are turned off before type checking underlying
+ * predicates.
+ */
+ public Type typeCheck(SymbolTable stable) throws TypeCheckError {
+ Type ptype = _primary.typeCheck(stable);
+ boolean canOptimize = _primary instanceof KeyCall;
+
+ if (ptype instanceof NodeSetType == false) {
+ if (ptype instanceof ReferenceType) {
+ _primary = new CastExpr(_primary, Type.NodeSet);
+ }
+ else {
+ throw new TypeCheckError(this);
+ }
+ }
+
+ // Type check predicates and turn all optimizations off if appropriate
+ int n = _predicates.size();
+ for (int i = 0; i < n; i++) {
+ Predicate pred = (Predicate) _predicates.elementAt(i);
+
+ if (!canOptimize) {
+ pred.dontOptimize();
+ }
+ pred.typeCheck(stable);
+ }
+ return _type = Type.NodeSet;
+ }
+
+ /**
+ * Translate a filter expression by pushing the appropriate iterator
+ * onto the stack.
+ */
+ public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
+ if (_predicates.size() > 0) {
+ translatePredicates(classGen, methodGen);
+ }
+ else {
+ _primary.translate(classGen, methodGen);
+ }
+ }
+
+ /**
+ * Translate a sequence of predicates. Each predicate is translated
+ * by constructing an instance of <code>CurrentNodeListIterator</code>
+ * which is initialized from another iterator (recursive call), a
+ * filter and a closure (call to translate on the predicate) and "this".
+ */
+ public void translatePredicates(ClassGenerator classGen,
+ MethodGenerator methodGen) {
+ final ConstantPoolGen cpg = classGen.getConstantPool();
+ final InstructionList il = methodGen.getInstructionList();
+
+ // If not predicates left, translate primary expression
+ if (_predicates.size() == 0) {
+ translate(classGen, methodGen);
+ } else {
+ // Remove the next predicate to be translated
+ Predicate predicate = (Predicate)_predicates.lastElement();
+ _predicates.remove(predicate);
+
+ // Translate the rest of the predicates from right to left
+ translatePredicates(classGen, methodGen);
+
+ if (predicate.isNthPositionFilter()) {
+ int nthIteratorIdx = cpg.addMethodref(NTH_ITERATOR_CLASS,
+ "<init>",
+ "("+NODE_ITERATOR_SIG+"I)V");
+
+ // Backwards branches are prohibited if an uninitialized object
+ // is on the stack by section 4.9.4 of the JVM Specification,
+ // 2nd Ed. We don't know whether this code might contain
+ // backwards branches, so we mustn't create the new object unti
+
+ // after we've created the suspect arguments to its constructor
+
+ // Instead we calculate the values of the arguments to the
+ // constructor first, store them in temporary variables, create
+ // the object and reload the arguments from the temporaries to
+ // avoid the problem.
+ LocalVariableGen iteratorTemp
+ = methodGen.addLocalVariable("filter_expr_tmp1",
+ Util.getJCRefType(NODE_ITERATOR_SIG),
+ null, null);
+ iteratorTemp.setStart(
+ il.append(new ASTORE(iteratorTemp.getIndex())));
+
+ predicate.translate(classGen, methodGen);
+ LocalVariableGen predicateValueTemp
+ = methodGen.addLocalVariable("filter_expr_tmp2",
+ Util.getJCRefType("I"),
+ null, null);
+ predicateValueTemp.setStart(
+ il.append(new ISTORE(predicateValueTemp.getIndex())));
+
+ il.append(new NEW(cpg.addClass(NTH_ITERATOR_CLASS)));
+ il.append(DUP);
+ iteratorTemp.setEnd(
+ il.append(new ALOAD(iteratorTemp.getIndex())));
+ predicateValueTemp.setEnd(
+ il.append(new ILOAD(predicateValueTemp.getIndex())));
+ il.append(new INVOKESPECIAL(nthIteratorIdx));
+ } else {
+ // Translate predicates from right to left
+ final int initCNLI =
+ cpg.addMethodref(CURRENT_NODE_LIST_ITERATOR,
+ "<init>",
+ "("+NODE_ITERATOR_SIG+"Z"+
+ CURRENT_NODE_LIST_FILTER_SIG +
+ NODE_SIG+TRANSLET_SIG+")V");
+
+ // Backwards branches are prohibited if an uninitialized object
+ // is on the stack by section 4.9.4 of the JVM Specification,
+ // 2nd Ed. We don't know whether this code might contain
+ // backwards branches, so we mustn't create the new object
+ // until after we've created the suspect arguments to its
+ // constructor. Instead we calculate the values of the
+ // arguments to the constructor first, store them in temporary
+ // variables, create the object and reload the arguments from
+ // the temporaries to avoid the problem.
+
+
+ LocalVariableGen nodeIteratorTemp =
+ methodGen.addLocalVariable("filter_expr_tmp1",
+ Util.getJCRefType(NODE_ITERATOR_SIG),
+ null, null);
+ nodeIteratorTemp.setStart(
+ il.append(new ASTORE(nodeIteratorTemp.getIndex())));
+
+ predicate.translate(classGen, methodGen);
+ LocalVariableGen filterTemp =
+ methodGen.addLocalVariable("filter_expr_tmp2",
+ Util.getJCRefType(CURRENT_NODE_LIST_FILTER_SIG),
+ null, null);
+ filterTemp.setStart(
+ il.append(new ASTORE(filterTemp.getIndex())));
+
+ // Create a CurrentNodeListIterator
+ il.append(new NEW(cpg.addClass(CURRENT_NODE_LIST_ITERATOR)));
+ il.append(DUP);
+
+ // Initialize CurrentNodeListIterator
+ nodeIteratorTemp.setEnd(
+ il.append(new ALOAD(nodeIteratorTemp.getIndex())));
+ il.append(ICONST_1);
+ filterTemp.setEnd(il.append(new ALOAD(filterTemp.getIndex())));
+ il.append(methodGen.loadCurrentNode());
+ il.append(classGen.loadTranslet());
+ il.append(new INVOKESPECIAL(initCNLI));
+ }
+ }
+ }
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/compiler/FilterParentPath.java b/src/main/java/org/apache/xalan/xsltc/compiler/FilterParentPath.java
new file mode 100644
index 000000000..86a8e7938
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/compiler/FilterParentPath.java
@@ -0,0 +1,174 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.compiler;
+
+import org.apache.bcel.generic.ALOAD;
+import org.apache.bcel.generic.ASTORE;
+import org.apache.bcel.generic.ConstantPoolGen;
+import org.apache.bcel.generic.INVOKEINTERFACE;
+import org.apache.bcel.generic.INVOKESPECIAL;
+import org.apache.bcel.generic.INVOKEVIRTUAL;
+import org.apache.bcel.generic.InstructionList;
+import org.apache.bcel.generic.LocalVariableGen;
+import org.apache.bcel.generic.NEW;
+import org.apache.xalan.xsltc.compiler.util.ClassGenerator;
+import org.apache.xalan.xsltc.compiler.util.MethodGenerator;
+import org.apache.xalan.xsltc.compiler.util.NodeSetType;
+import org.apache.xalan.xsltc.compiler.util.NodeType;
+import org.apache.xalan.xsltc.compiler.util.ReferenceType;
+import org.apache.xalan.xsltc.compiler.util.Type;
+import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
+import org.apache.xalan.xsltc.compiler.util.Util;
+
+/**
+ * @author Jacek Ambroziak
+ * @author Santiago Pericas-Geertsen
+ */
+final class FilterParentPath extends Expression {
+
+ private Expression _filterExpr;
+ private Expression _path;
+ private boolean _hasDescendantAxis = false;
+
+ public FilterParentPath(Expression filterExpr, Expression path) {
+ (_path = path).setParent(this);
+ (_filterExpr = filterExpr).setParent(this);
+ }
+
+ public void setParser(Parser parser) {
+ super.setParser(parser);
+ _filterExpr.setParser(parser);
+ _path.setParser(parser);
+ }
+
+ public String toString() {
+ return "FilterParentPath(" + _filterExpr + ", " + _path + ')';
+ }
+
+ public void setDescendantAxis() {
+ _hasDescendantAxis = true;
+ }
+
+ /**
+ * Type check a FilterParentPath. If the filter is not a node-set add a
+ * cast to node-set only if it is of reference type. This type coercion is
+ * needed for expressions like $x/LINE where $x is a parameter reference.
+ */
+ public Type typeCheck(SymbolTable stable) throws TypeCheckError {
+ final Type ftype = _filterExpr.typeCheck(stable);
+ if (ftype instanceof NodeSetType == false) {
+ if (ftype instanceof ReferenceType) {
+ _filterExpr = new CastExpr(_filterExpr, Type.NodeSet);
+ }
+ /*
+ else if (ftype instanceof ResultTreeType) {
+ _filterExpr = new CastExpr(_filterExpr, Type.NodeSet);
+ }
+ */
+ else if (ftype instanceof NodeType) {
+ _filterExpr = new CastExpr(_filterExpr, Type.NodeSet);
+ }
+ else {
+ throw new TypeCheckError(this);
+ }
+ }
+
+ // Wrap single node path in a node set
+ final Type ptype = _path.typeCheck(stable);
+ if (!(ptype instanceof NodeSetType)) {
+ _path = new CastExpr(_path, Type.NodeSet);
+ }
+
+ return _type = Type.NodeSet;
+ }
+
+ public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
+ final ConstantPoolGen cpg = classGen.getConstantPool();
+ final InstructionList il = methodGen.getInstructionList();
+ // Create new StepIterator
+ final int initSI = cpg.addMethodref(STEP_ITERATOR_CLASS,
+ "<init>",
+ "("
+ +NODE_ITERATOR_SIG
+ +NODE_ITERATOR_SIG
+ +")V");
+
+ // Backwards branches are prohibited if an uninitialized object is
+ // on the stack by section 4.9.4 of the JVM Specification, 2nd Ed.
+ // We don't know whether this code might contain backwards branches,
+ // so we mustn't create the new object until after we've created
+ // the suspect arguments to its constructor. Instead we calculate
+ // the values of the arguments to the constructor first, store them
+ // in temporary variables, create the object and reload the
+ // arguments from the temporaries to avoid the problem.
+
+ // Recursively compile 2 iterators
+ _filterExpr.translate(classGen, methodGen);
+ LocalVariableGen filterTemp =
+ methodGen.addLocalVariable("filter_parent_path_tmp1",
+ Util.getJCRefType(NODE_ITERATOR_SIG),
+ null, null);
+ filterTemp.setStart(il.append(new ASTORE(filterTemp.getIndex())));
+
+ _path.translate(classGen, methodGen);
+ LocalVariableGen pathTemp =
+ methodGen.addLocalVariable("filter_parent_path_tmp2",
+ Util.getJCRefType(NODE_ITERATOR_SIG),
+ null, null);
+ pathTemp.setStart(il.append(new ASTORE(pathTemp.getIndex())));
+
+ il.append(new NEW(cpg.addClass(STEP_ITERATOR_CLASS)));
+ il.append(DUP);
+ filterTemp.setEnd(il.append(new ALOAD(filterTemp.getIndex())));
+ pathTemp.setEnd(il.append(new ALOAD(pathTemp.getIndex())));
+
+ // Initialize StepIterator with iterators from the stack
+ il.append(new INVOKESPECIAL(initSI));
+
+ // This is a special case for the //* path with or without predicates
+ if (_hasDescendantAxis) {
+ final int incl = cpg.addMethodref(NODE_ITERATOR_BASE,
+ "includeSelf",
+ "()" + NODE_ITERATOR_SIG);
+ il.append(new INVOKEVIRTUAL(incl));
+ }
+
+ SyntaxTreeNode parent = getParent();
+
+ boolean parentAlreadyOrdered =
+ (parent instanceof RelativeLocationPath)
+ || (parent instanceof FilterParentPath)
+ || (parent instanceof KeyCall)
+ || (parent instanceof CurrentCall)
+ || (parent instanceof DocumentCall);
+
+ if (!parentAlreadyOrdered) {
+ final int order = cpg.addInterfaceMethodref(DOM_INTF,
+ ORDER_ITERATOR,
+ ORDER_ITERATOR_SIG);
+ il.append(methodGen.loadDOM());
+ il.append(SWAP);
+ il.append(methodGen.loadContextNode());
+ il.append(new INVOKEINTERFACE(order, 3));
+ }
+ }
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/compiler/FilteredAbsoluteLocationPath.java b/src/main/java/org/apache/xalan/xsltc/compiler/FilteredAbsoluteLocationPath.java
new file mode 100644
index 000000000..792fe4408
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/compiler/FilteredAbsoluteLocationPath.java
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.compiler;
+
+import org.apache.bcel.generic.ALOAD;
+import org.apache.bcel.generic.ASTORE;
+import org.apache.bcel.generic.ConstantPoolGen;
+import org.apache.bcel.generic.INVOKEINTERFACE;
+import org.apache.bcel.generic.INVOKESPECIAL;
+import org.apache.bcel.generic.InstructionList;
+import org.apache.bcel.generic.LocalVariableGen;
+import org.apache.bcel.generic.NEW;
+import org.apache.xalan.xsltc.compiler.util.ClassGenerator;
+import org.apache.xalan.xsltc.compiler.util.MethodGenerator;
+import org.apache.xalan.xsltc.compiler.util.NodeType;
+import org.apache.xalan.xsltc.compiler.util.Type;
+import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
+import org.apache.xalan.xsltc.compiler.util.Util;
+
+/**
+ * @author G. Todd Miller
+ */
+final class FilteredAbsoluteLocationPath extends Expression {
+ private Expression _path; // may be null
+
+ public FilteredAbsoluteLocationPath() {
+ _path = null;
+ }
+
+ public FilteredAbsoluteLocationPath(Expression path) {
+ _path = path;
+ if (path != null) {
+ _path.setParent(this);
+ }
+ }
+
+ public void setParser(Parser parser) {
+ super.setParser(parser);
+ if (_path != null) {
+ _path.setParser(parser);
+ }
+ }
+
+ public Expression getPath() {
+ return(_path);
+ }
+
+ public String toString() {
+ return "FilteredAbsoluteLocationPath(" +
+ (_path != null ? _path.toString() : "null") + ')';
+ }
+
+ public Type typeCheck(SymbolTable stable) throws TypeCheckError {
+ if (_path != null) {
+ final Type ptype = _path.typeCheck(stable);
+ if (ptype instanceof NodeType) { // promote to node-set
+ _path = new CastExpr(_path, Type.NodeSet);
+ }
+ }
+ return _type = Type.NodeSet;
+ }
+
+ public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
+ final ConstantPoolGen cpg = classGen.getConstantPool();
+ final InstructionList il = methodGen.getInstructionList();
+ if (_path != null) {
+ final int initDFI = cpg.addMethodref(DUP_FILTERED_ITERATOR,
+ "<init>",
+ "("
+ + NODE_ITERATOR_SIG
+ + ")V");
+
+ // Backwards branches are prohibited if an uninitialized object is
+ // on the stack by section 4.9.4 of the JVM Specification, 2nd Ed.
+ // We don't know whether this code might contain backwards branches,
+ // so we mustn't create the new object until after we've created
+ // the suspect arguments to its constructor. Instead we calculate
+ // the values of the arguments to the constructor first, store them
+ // in temporary variables, create the object and reload the
+ // arguments from the temporaries to avoid the problem.
+
+ // Compile relative path iterator(s)
+ LocalVariableGen pathTemp =
+ methodGen.addLocalVariable("filtered_absolute_location_path_tmp",
+ Util.getJCRefType(NODE_ITERATOR_SIG),
+ null, null);
+ _path.translate(classGen, methodGen);
+ pathTemp.setStart(il.append(new ASTORE(pathTemp.getIndex())));
+
+ // Create new Dup Filter Iterator
+ il.append(new NEW(cpg.addClass(DUP_FILTERED_ITERATOR)));
+ il.append(DUP);
+ pathTemp.setEnd(il.append(new ALOAD(pathTemp.getIndex())));
+
+ // Initialize Dup Filter Iterator with iterator from the stack
+ il.append(new INVOKESPECIAL(initDFI));
+ }
+ else {
+ final int git = cpg.addInterfaceMethodref(DOM_INTF,
+ "getIterator",
+ "()"+NODE_ITERATOR_SIG);
+ il.append(methodGen.loadDOM());
+ il.append(new INVOKEINTERFACE(git, 1));
+ }
+ }
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/compiler/FloorCall.java b/src/main/java/org/apache/xalan/xsltc/compiler/FloorCall.java
new file mode 100644
index 000000000..940188f18
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/compiler/FloorCall.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.compiler;
+
+import java.util.Vector;
+
+import org.apache.bcel.generic.INVOKESTATIC;
+import org.apache.xalan.xsltc.compiler.util.ClassGenerator;
+import org.apache.xalan.xsltc.compiler.util.MethodGenerator;
+
+/**
+ * @author Jacek Ambroziak
+ * @author Santiago Pericas-Geertsen
+ */
+final class FloorCall extends FunctionCall {
+ public FloorCall(QName fname, Vector arguments) {
+ super(fname, arguments);
+ }
+
+ public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
+ argument().translate(classGen, methodGen);
+ methodGen.getInstructionList()
+ .append(new INVOKESTATIC(classGen.getConstantPool()
+ .addMethodref(MATH_CLASS,
+ "floor", "(D)D")));
+ }
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/compiler/FlowList.java b/src/main/java/org/apache/xalan/xsltc/compiler/FlowList.java
new file mode 100644
index 000000000..ff2ada4a3
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/compiler/FlowList.java
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.compiler;
+
+import java.util.Iterator;
+import java.util.Vector;
+
+import org.apache.bcel.generic.BranchHandle;
+import org.apache.bcel.generic.InstructionHandle;
+import org.apache.bcel.generic.InstructionList;
+
+/**
+ * @author Jacek Ambroziak
+ * @author Santiago Pericas-Geertsen
+ */
+public final class FlowList {
+ private Vector _elements;
+
+ public FlowList() {
+ _elements = null;
+ }
+
+ public FlowList(InstructionHandle bh) {
+ _elements = new Vector();
+ _elements.addElement(bh);
+ }
+
+ public FlowList(FlowList list) {
+ _elements = list._elements;
+ }
+
+ public FlowList add(InstructionHandle bh) {
+ if (_elements == null) {
+ _elements = new Vector();
+ }
+ _elements.addElement(bh);
+ return this;
+ }
+
+ public FlowList append(FlowList right) {
+ if (_elements == null) {
+ _elements = right._elements;
+ }
+ else {
+ final Vector temp = right._elements;
+ if (temp != null) {
+ final int n = temp.size();
+ for (int i = 0; i < n; i++) {
+ _elements.addElement(temp.elementAt(i));
+ }
+ }
+ }
+ return this;
+ }
+
+ /**
+ * Back patch a flow list. All instruction handles must be branch handles.
+ */
+ public void backPatch(InstructionHandle target) {
+ if (_elements != null) {
+ final int n = _elements.size();
+ for (int i = 0; i < n; i++) {
+ BranchHandle bh = (BranchHandle)_elements.elementAt(i);
+ bh.setTarget(target);
+ }
+ _elements.clear(); // avoid backpatching more than once
+ }
+ }
+
+ /**
+ * Redirect the handles from oldList to newList. "This" flow list
+ * is assumed to be relative to oldList.
+ */
+ public FlowList copyAndRedirect(InstructionList oldList,
+ InstructionList newList)
+ {
+ final FlowList result = new FlowList();
+ if (_elements == null) {
+ return result;
+ }
+
+ final int n = _elements.size();
+ final Iterator oldIter = oldList.iterator();
+ final Iterator newIter = newList.iterator();
+
+ while (oldIter.hasNext()) {
+ final InstructionHandle oldIh = (InstructionHandle) oldIter.next();
+ final InstructionHandle newIh = (InstructionHandle) newIter.next();
+
+ for (int i = 0; i < n; i++) {
+ if (_elements.elementAt(i) == oldIh) {
+ result.add(newIh);
+ }
+ }
+ }
+ return result;
+ }
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/compiler/ForEach.java b/src/main/java/org/apache/xalan/xsltc/compiler/ForEach.java
new file mode 100644
index 000000000..f59cb388e
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/compiler/ForEach.java
@@ -0,0 +1,196 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.compiler;
+
+import java.util.Enumeration;
+import java.util.Vector;
+
+import org.apache.bcel.generic.BranchHandle;
+import org.apache.bcel.generic.ConstantPoolGen;
+import org.apache.bcel.generic.GOTO;
+import org.apache.bcel.generic.IFGT;
+import org.apache.bcel.generic.InstructionHandle;
+import org.apache.bcel.generic.InstructionList;
+import org.apache.xalan.xsltc.compiler.util.ClassGenerator;
+import org.apache.xalan.xsltc.compiler.util.ErrorMsg;
+import org.apache.xalan.xsltc.compiler.util.MethodGenerator;
+import org.apache.xalan.xsltc.compiler.util.NodeSetType;
+import org.apache.xalan.xsltc.compiler.util.NodeType;
+import org.apache.xalan.xsltc.compiler.util.ReferenceType;
+import org.apache.xalan.xsltc.compiler.util.ResultTreeType;
+import org.apache.xalan.xsltc.compiler.util.Type;
+import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
+import org.apache.xalan.xsltc.compiler.util.Util;
+
+/**
+ * @author Jacek Ambroziak
+ * @author Santiago Pericas-Geertsen
+ * @author Morten Jorgensen
+ */
+final class ForEach extends Instruction {
+
+ private Expression _select;
+ private Type _type;
+
+ public void display(int indent) {
+ indent(indent);
+ Util.println("ForEach");
+ indent(indent + IndentIncrement);
+ Util.println("select " + _select.toString());
+ displayContents(indent + IndentIncrement);
+ }
+
+ 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(this, parser, ErrorMsg.REQUIRED_ATTR_ERR, "select");
+ }
+ }
+
+ public Type typeCheck(SymbolTable stable) throws TypeCheckError {
+ _type = _select.typeCheck(stable);
+
+ if (_type instanceof ReferenceType || _type instanceof NodeType) {
+ _select = new CastExpr(_select, Type.NodeSet);
+ typeCheckContents(stable);
+ return Type.Void;
+ }
+ if (_type instanceof NodeSetType||_type instanceof ResultTreeType) {
+ typeCheckContents(stable);
+ return Type.Void;
+ }
+ throw new TypeCheckError(this);
+ }
+
+ public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
+ final ConstantPoolGen cpg = classGen.getConstantPool();
+ final InstructionList il = methodGen.getInstructionList();
+
+ // Save current node and current iterator on the stack
+ il.append(methodGen.loadCurrentNode());
+ il.append(methodGen.loadIterator());
+
+ // Collect sort objects associated with this instruction
+ final Vector sortObjects = new Vector();
+ Enumeration children = elements();
+ while (children.hasMoreElements()) {
+ final Object child = children.nextElement();
+ if (child instanceof Sort) {
+ sortObjects.addElement(child);
+ }
+ }
+
+ if ((_type != null) && (_type instanceof ResultTreeType)) {
+ // Store existing DOM on stack - must be restored when loop is done
+ il.append(methodGen.loadDOM());
+
+ // <xsl:sort> cannot be applied to a result tree - issue warning
+ if (sortObjects.size() > 0) {
+ ErrorMsg msg = new ErrorMsg(ErrorMsg.RESULT_TREE_SORT_ERR,this);
+ getParser().reportError(WARNING, msg);
+ }
+
+ // Put the result tree on the stack (DOM)
+ _select.translate(classGen, methodGen);
+ // Get an iterator for the whole DOM - excluding the root node
+ _type.translateTo(classGen, methodGen, Type.NodeSet);
+ // Store the result tree as the default DOM
+ il.append(SWAP);
+ il.append(methodGen.storeDOM());
+ }
+ else {
+ // Compile node iterator
+ if (sortObjects.size() > 0) {
+ Sort.translateSortIterator(classGen, methodGen,
+ _select, sortObjects);
+ }
+ else {
+ _select.translate(classGen, methodGen);
+ }
+
+ if (_type instanceof ReferenceType == false) {
+ il.append(methodGen.loadContextNode());
+ il.append(methodGen.setStartNode());
+ }
+ }
+
+
+ // Overwrite current iterator
+ il.append(methodGen.storeIterator());
+
+ // Give local variables (if any) default values before starting loop
+ initializeVariables(classGen, methodGen);
+
+ final BranchHandle nextNode = il.append(new GOTO(null));
+ final InstructionHandle loop = il.append(NOP);
+
+ translateContents(classGen, methodGen);
+
+ nextNode.setTarget(il.append(methodGen.loadIterator()));
+ il.append(methodGen.nextNode());
+ il.append(DUP);
+ il.append(methodGen.storeCurrentNode());
+ il.append(new IFGT(loop));
+
+ // Restore current DOM (if result tree was used instead for this loop)
+ if ((_type != null) && (_type instanceof ResultTreeType)) {
+ il.append(methodGen.storeDOM());
+ }
+
+ // Restore current node and current iterator from the stack
+ il.append(methodGen.storeIterator());
+ il.append(methodGen.storeCurrentNode());
+ }
+
+ /**
+ * The code that is generated by nested for-each loops can appear to some
+ * JVMs as if it is accessing un-initialized variables. We must add some
+ * code that pushes the default variable value on the stack and pops it
+ * into the variable slot. This is done by the Variable.initialize()
+ * method. The code that we compile for this loop looks like this:
+ *
+ * initialize iterator
+ * initialize variables <-- HERE!!!
+ * goto Iterate
+ * Loop: :
+ * : (code for <xsl:for-each> contents)
+ * :
+ * Iterate: node = iterator.next();
+ * if (node != END) goto Loop
+ */
+ public void initializeVariables(ClassGenerator classGen,
+ MethodGenerator methodGen) {
+ final int n = elementCount();
+ for (int i = 0; i < n; i++) {
+ final Object child = getContents().elementAt(i);
+ if (child instanceof Variable) {
+ Variable var = (Variable)child;
+ var.initialize(classGen, methodGen);
+ }
+ }
+ }
+
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/compiler/FormatNumberCall.java b/src/main/java/org/apache/xalan/xsltc/compiler/FormatNumberCall.java
new file mode 100644
index 000000000..e11a11fca
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/compiler/FormatNumberCall.java
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.compiler;
+
+import java.util.Vector;
+
+import org.apache.bcel.generic.ConstantPoolGen;
+import org.apache.bcel.generic.INVOKESTATIC;
+import org.apache.bcel.generic.INVOKEVIRTUAL;
+import org.apache.bcel.generic.InstructionList;
+import org.apache.bcel.generic.PUSH;
+import org.apache.xalan.xsltc.compiler.util.ClassGenerator;
+import org.apache.xalan.xsltc.compiler.util.MethodGenerator;
+import org.apache.xalan.xsltc.compiler.util.RealType;
+import org.apache.xalan.xsltc.compiler.util.StringType;
+import org.apache.xalan.xsltc.compiler.util.Type;
+import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
+
+/**
+ * @author Jacek Ambroziak
+ * @author Santiago Pericas-Geertsen
+ * @author Morten Jorgensen
+ */
+final class FormatNumberCall extends FunctionCall {
+ private Expression _value;
+ private Expression _format;
+ private Expression _name;
+ private QName _resolvedQName = null;
+
+ public FormatNumberCall(QName fname, Vector arguments) {
+ super(fname, arguments);
+ _value = argument(0);
+ _format = argument(1);
+ _name = argumentCount() == 3 ? argument(2) : null;
+ }
+
+ public Type typeCheck(SymbolTable stable) throws TypeCheckError {
+
+ // Inform stylesheet to instantiate a DecimalFormat object
+ getStylesheet().numberFormattingUsed();
+
+ final Type tvalue = _value.typeCheck(stable);
+ if (tvalue instanceof RealType == false) {
+ _value = new CastExpr(_value, Type.Real);
+ }
+ final Type tformat = _format.typeCheck(stable);
+ if (tformat instanceof StringType == false) {
+ _format = new CastExpr(_format, Type.String);
+ }
+ if (argumentCount() == 3) {
+ final Type tname = _name.typeCheck(stable);
+
+ if (_name instanceof LiteralExpr) {
+ final LiteralExpr literal = (LiteralExpr) _name;
+ _resolvedQName =
+ getParser().getQNameIgnoreDefaultNs(literal.getValue());
+ }
+ else if (tname instanceof StringType == false) {
+ _name = new CastExpr(_name, Type.String);
+ }
+ }
+ return _type = Type.String;
+ }
+
+ public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
+ final ConstantPoolGen cpg = classGen.getConstantPool();
+ final InstructionList il = methodGen.getInstructionList();
+
+ _value.translate(classGen, methodGen);
+ _format.translate(classGen, methodGen);
+
+ final int fn3arg = cpg.addMethodref(BASIS_LIBRARY_CLASS,
+ "formatNumber",
+ "(DLjava/lang/String;"+
+ "Ljava/text/DecimalFormat;)"+
+ "Ljava/lang/String;");
+ final int get = cpg.addMethodref(TRANSLET_CLASS,
+ "getDecimalFormat",
+ "(Ljava/lang/String;)"+
+ "Ljava/text/DecimalFormat;");
+
+ il.append(classGen.loadTranslet());
+ if (_name == null) {
+ il.append(new PUSH(cpg, EMPTYSTRING));
+ }
+ else if (_resolvedQName != null) {
+ il.append(new PUSH(cpg, _resolvedQName.toString()));
+ }
+ else {
+ _name.translate(classGen, methodGen);
+ }
+ il.append(new INVOKEVIRTUAL(get));
+ il.append(new INVOKESTATIC(fn3arg));
+ }
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/compiler/FunctionAvailableCall.java b/src/main/java/org/apache/xalan/xsltc/compiler/FunctionAvailableCall.java
new file mode 100644
index 000000000..6973666d8
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/compiler/FunctionAvailableCall.java
@@ -0,0 +1,193 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.compiler;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Vector;
+
+import org.apache.bcel.generic.ConstantPoolGen;
+import org.apache.bcel.generic.PUSH;
+import org.apache.xalan.xsltc.compiler.util.ClassGenerator;
+import org.apache.xalan.xsltc.compiler.util.ErrorMsg;
+import org.apache.xalan.xsltc.compiler.util.MethodGenerator;
+import org.apache.xalan.xsltc.compiler.util.Type;
+import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
+import org.apache.xalan.xsltc.compiler.util.Util;
+
+/**
+ * @author G. Todd Miller
+ * @author Santiago Pericas-Geertsen
+ */
+final class FunctionAvailableCall extends FunctionCall {
+
+ private Expression _arg;
+ private String _nameOfFunct = null;
+ private String _namespaceOfFunct = null;
+ private boolean _isFunctionAvailable = false;
+
+ /**
+ * Constructs a FunctionAvailableCall FunctionCall. Takes the
+ * function name qname, for example, 'function-available', and
+ * a list of arguments where the arguments must be instances of
+ * LiteralExpression.
+ */
+ public FunctionAvailableCall(QName fname, Vector arguments) {
+ super(fname, arguments);
+ _arg = (Expression)arguments.elementAt(0);
+ _type = null;
+
+ if (_arg instanceof LiteralExpr) {
+ LiteralExpr arg = (LiteralExpr) _arg;
+ _namespaceOfFunct = arg.getNamespace();
+ _nameOfFunct = arg.getValue();
+
+ if (!isInternalNamespace()) {
+ _isFunctionAvailable = hasMethods();
+ }
+ }
+ }
+
+ /**
+ * Argument of function-available call must be literal, typecheck
+ * returns the type of function-available to be boolean.
+ */
+ public Type typeCheck(SymbolTable stable) throws TypeCheckError {
+ if (_type != null) {
+ return _type;
+ }
+ if (_arg instanceof LiteralExpr) {
+ return _type = Type.Boolean;
+ }
+ ErrorMsg err = new ErrorMsg(ErrorMsg.NEED_LITERAL_ERR,
+ "function-available", this);
+ throw new TypeCheckError(err);
+ }
+
+ /**
+ * Returns an object representing the compile-time evaluation
+ * of an expression. We are only using this for function-available
+ * and element-available at this time.
+ */
+ public Object evaluateAtCompileTime() {
+ return getResult() ? Boolean.TRUE : Boolean.FALSE;
+ }
+
+ /**
+ * for external java functions only: reports on whether or not
+ * the specified method is found in the specifed class.
+ */
+ private boolean hasMethods() {
+
+ // Get the class name from the namespace uri
+ String className = getClassNameFromUri(_namespaceOfFunct);
+
+ // Get the method name from the argument to function-available
+ String methodName = null;
+ int colonIndex = _nameOfFunct.indexOf(":");
+ if (colonIndex > 0) {
+ String functionName = _nameOfFunct.substring(colonIndex+1);
+ int lastDotIndex = functionName.lastIndexOf('.');
+ if (lastDotIndex > 0) {
+ methodName = functionName.substring(lastDotIndex+1);
+ if (className != null && className.length() != 0)
+ className = className + "." + functionName.substring(0, lastDotIndex);
+ else
+ className = functionName.substring(0, lastDotIndex);
+ }
+ else
+ methodName = functionName;
+ }
+ else
+ methodName = _nameOfFunct;
+
+ if (className == null || methodName == null) {
+ return false;
+ }
+
+ // Replace the '-' characters in the method name
+ if (methodName.indexOf('-') > 0)
+ methodName = replaceDash(methodName);
+
+ try {
+ final Class clazz = ObjectFactory.findProviderClass(
+ className, ObjectFactory.findClassLoader(), true);
+
+ if (clazz == null) {
+ return false;
+ }
+
+ final Method[] methods = clazz.getMethods();
+
+ for (int i = 0; i < methods.length; i++) {
+ final int mods = methods[i].getModifiers();
+
+ if (Modifier.isPublic(mods) && Modifier.isStatic(mods)
+ && methods[i].getName().equals(methodName))
+ {
+ return true;
+ }
+ }
+ }
+ catch (ClassNotFoundException e) {
+ return false;
+ }
+ return false;
+ }
+
+ /**
+ * Reports on whether the function specified in the argument to
+ * xslt function 'function-available' was found.
+ */
+ public boolean getResult() {
+ if (_nameOfFunct == null) {
+ return false;
+ }
+
+ if (isInternalNamespace()) {
+ final Parser parser = getParser();
+ _isFunctionAvailable =
+ parser.functionSupported(Util.getLocalName(_nameOfFunct));
+ }
+ return _isFunctionAvailable;
+ }
+
+ /**
+ * Return true if the namespace uri is null or it is the XSLTC translet uri.
+ */
+ private boolean isInternalNamespace() {
+ return (_namespaceOfFunct == null ||
+ _namespaceOfFunct.equals(EMPTYSTRING) ||
+ _namespaceOfFunct.equals(TRANSLET_URI));
+ }
+
+ /**
+ * Calls to 'function-available' are resolved at compile time since
+ * the namespaces declared in the stylsheet are not available at run
+ * time. Consequently, arguments to this function must be literals.
+ */
+ public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
+ final ConstantPoolGen cpg = classGen.getConstantPool();
+ methodGen.getInstructionList().append(new PUSH(cpg, getResult()));
+ }
+
+}
diff --git a/src/main/java/org/apache/xalan/xsltc/compiler/FunctionCall.java b/src/main/java/org/apache/xalan/xsltc/compiler/FunctionCall.java
new file mode 100644
index 000000000..9ca1ecef1
--- /dev/null
+++ b/src/main/java/org/apache/xalan/xsltc/compiler/FunctionCall.java
@@ -0,0 +1,1093 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+
+package org.apache.xalan.xsltc.compiler;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Vector;
+
+import org.apache.bcel.generic.ConstantPoolGen;
+import org.apache.bcel.generic.IFEQ;
+import org.apache.bcel.generic.INVOKEINTERFACE;
+import org.apache.bcel.generic.INVOKESPECIAL;
+import org.apache.bcel.generic.INVOKESTATIC;
+import org.apache.bcel.generic.INVOKEVIRTUAL;
+import org.apache.bcel.generic.InstructionConstants;
+import org.apache.bcel.generic.InstructionList;
+import org.apache.bcel.generic.InvokeInstruction;
+import org.apache.bcel.generic.LocalVariableGen;
+import org.apache.bcel.generic.NEW;
+import org.apache.bcel.generic.PUSH;
+import org.apache.xalan.xsltc.compiler.util.BooleanType;
+import org.apache.xalan.xsltc.compiler.util.ClassGenerator;
+import org.apache.xalan.xsltc.compiler.util.ErrorMsg;
+import org.apache.xalan.xsltc.compiler.util.IntType;
+import org.apache.xalan.xsltc.compiler.util.MethodGenerator;
+import org.apache.xalan.xsltc.compiler.util.MethodType;
+import org.apache.xalan.xsltc.compiler.util.MultiHashtable;
+import org.apache.xalan.xsltc.compiler.util.ObjectType;
+import org.apache.xalan.xsltc.compiler.util.ReferenceType;
+import org.apache.xalan.xsltc.compiler.util.Type;
+import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
+
+/**
+ * @author Jacek Ambroziak
+ * @author Santiago Pericas-Geertsen
+ * @author Morten Jorgensen
+ * @author Erwin Bolwidt <ej...@klomp.org>
+ * @author Todd Miller
+ */
+class FunctionCall extends Expression {
+
+ // Name of this function call
+ private QName _fname;
+ // Arguments to this function call (might not be any)
+ private final Vector _arguments;
+ // Empty argument list, used for certain functions
+ private final static Vector EMPTY_ARG_LIST = new Vector(0);
+
+ // Valid namespaces for Java function-call extension
+ protected final static String EXT_XSLTC =
+ TRANSLET_URI;
+
+ protected final static String JAVA_EXT_XSLTC =
+ EXT_XSLTC + "/java";
+
+ protected final static String EXT_XALAN =
+ "http://xml.apache.org/xalan";
+
+ protected final static String JAVA_EXT_XALAN =
+ "http://xml.apache.org/xalan/java";
+
+ protected final static String JAVA_EXT_XALAN_OLD =
+ "http://xml.apache.org/xslt/java";
+
+ protected final static String EXSLT_COMMON =
+ "http://exslt.org/common";
+
+ protected final static String EXSLT_MATH =
+ "http://exslt.org/math";
+
+ protected final static String EXSLT_SETS =
+ "http://exslt.org/sets";
+
+ protected final static String EXSLT_DATETIME =
+ "http://exslt.org/dates-and-times";
+
+ protected final static String EXSLT_STRINGS =
+ "http://exslt.org/strings";
+
+ // Namespace format constants
+ protected final static int NAMESPACE_FORMAT_JAVA = 0;
+ protected final static int NAMESPACE_FORMAT_CLASS = 1;
+ protected final static int NAMESPACE_FORMAT_PACKAGE = 2;
+ protected final static int NAMESPACE_FORMAT_CLASS_OR_PACKAGE = 3;
+
+ // Namespace format
+ private int _namespace_format = NAMESPACE_FORMAT_JAVA;
+
+ /**
+ * Stores reference to object for non-static Java calls
+ */
+ Expression _thisArgument = null;
+
+ // External Java function's class/method/signature
+ private String _className;
+ private Class _clazz;
+ private Method _chosenMethod;
+ private Constructor _chosenConstructor;
+ private MethodType _chosenMethodType;
+
+ // Encapsulates all unsupported external function calls
+ private boolean unresolvedExternal;
+
+ // If FunctionCall is a external java constructor
+ private boolean _isExtConstructor = false;
+
+ // If the java method is static
+ private boolean _isStatic = false;
+
+ // Legal conversions between internal and Java types.
+ private static final MultiHashtable _internal2Java = new MultiHashtable();
+
+ // Legal conversions between Java and internal types.
+ private static final Hashtable _java2Internal = new Hashtable();
+
+ // The mappings between EXSLT extension namespaces and implementation classes
+ private static final Hashtable _extensionNamespaceTable = new Hashtable();
+
+ // Extension functions that are implemented in BasisLibrary
+ private static final Hashtable _extensionFunctionTable = new Hashtable();
+ /**
+ * inner class to used in internal2Java mappings, contains
+ * the Java type and the distance between the internal type and
+ * the Java type.
+ */
+ static class JavaType {
+ public Class type;
+ public int distance;
+
+ public JavaType(Class type, int distance){
+ this.type = type;
+ this.distance = distance;
+ }
+ public boolean equals(Object query){
+ return query.equals(type);
+ }
+ }
+
+ /**
+ * Defines 2 conversion tables:
+ * 1. From internal types to Java types and
+ * 2. From Java types to internal types.
+ * These two tables are used when calling external (Java) functions.
+ */
+ static {
+ try {
+ final Class nodeClass = Class.forName("org.w3c.dom.Node");
+ final Class nodeListClass = Class.forName("org.w3c.dom.NodeList");
+
+ // -- Internal to Java --------------------------------------------
+
+ // Type.Boolean -> { boolean(0), Boolean(1), Object(2) }
+ _internal2Java.put(Type.Boolean, new JavaType(Boolean.TYPE, 0));
+ _internal2Java.put(Type.Boolean, new JavaType(Boolean.class, 1));
+ _internal2Java.put(Type.Boolean, new JavaType(Object.class, 2));
+
+ // Type.Real -> { double(0), Double(1), float(2), long(3), int(4),
+ // short(5), byte(6), char(7), Object(8) }
+ _internal2Java.put(Type.Real, new JavaType(Double.TYPE, 0));
+ _internal2Java.put(Type.Real, new JavaType(Double.class, 1));
+ _internal2Java.put(Type.Real, new JavaType(Float.TYPE, 2));
+ _internal2Java.put(Type.Real, new JavaType(Long.TYPE, 3));
+ _internal2Java.put(Type.Real, new JavaType(Integer.TYPE, 4));
+ _internal2Java.put(Type.Real, new JavaType(Short.TYPE, 5));
+ _internal2Java.put(Type.Real, new JavaType(Byte.TYPE, 6));
+ _internal2Java.put(Type.Real, new JavaType(Character.TYPE, 7));
+ _internal2Java.put(Type.Real, new JavaType(Object.class, 8));
+
+ // Type.Int must be the same as Type.Real
+ _internal2Java.put(Type.Int, new JavaType(Double.TYPE, 0));
+ _internal2Java.put(Type.Int, new JavaType(Double.class, 1));
+ _internal2Java.put(Type.Int, new JavaType(Float.TYPE, 2));
+ _internal2Java.put(Type.Int, new JavaType(Long.TYPE, 3));
+ _internal2Java.put(Type.Int, new JavaType(Integer.TYPE, 4));
+ _internal2Java.put(Type.Int, new JavaType(Short.TYPE, 5));
+ _internal2Java.put(Type.Int, new JavaType(Byte.TYPE, 6));
+ _internal2Java.put(Type.Int, new JavaType(Character.TYPE, 7));
+ _internal2Java.put(Type.Int, new JavaType(Object.class, 8));
+
+ // Type.String -> { String(0), Object(1) }
+ _internal2Java.put(Type.String, new JavaType(String.class, 0));
+ _internal2Java.put(Type.String, new JavaType(Object.class, 1));
+
+ // Type.NodeSet -> { NodeList(0), Node(1), Object(2), String(3) }
+ _internal2Java.put(Type.NodeSet, new JavaType(nodeListClass, 0));
+ _internal2Java.put(Type.NodeSet, new JavaType(nodeClass, 1));
+ _internal2Java.put(Type.NodeSet, new JavaType(Object.class, 2));
+ _internal2Java.put(Type.NodeSet, new JavaType(String.class, 3));
+
+ // Type.Node -> { Node(0), NodeList(1), Object(2), String(3) }
+ _internal2Java.put(Type.Node, new JavaType(nodeListClass, 0));
+ _internal2Java.put(Type.Node, new JavaType(nodeClass, 1));
+ _internal2Java.put(Type.Node, new JavaType(Object.class, 2));
+ _internal2Java.put(Type.Node, new JavaType(String.class, 3));
+
+ // Type.ResultTree -> { NodeList(0), Node(1), Object(2), String(3) }
+ _internal2Java.put(Type.ResultTree, new JavaType(nodeListClass, 0));
+ _internal2Java.put(Type.ResultTree, new JavaType(nodeClass, 1));
+ _internal2Java.put(Type.ResultTree, new JavaType(Object.class, 2));
+ _internal2Java.put(Type.ResultTree, new JavaType(String.class, 3));
+
+ _internal2Java.put(Type.Reference, new JavaType(Object.class, 0));
+
+ // Possible conversions between Java and internal types
+ _java2Internal.put(Boolean.TYPE, Type.Boolean);
+ _java2Internal.put(Void.TYPE, Type.Void);
+ _java2Internal.put(Character.TYPE, Type.Real);
+ _java2Internal.put(Byte.TYPE, Type.Real);
+ _java2Internal.put(Short.TYPE, Type.Real);
+ _java2Internal.put(Integer.TYPE, Type.Real);
+ _java2Internal.put(Long.TYPE, Type.Real);
+ _java2Internal.put(Float.TYPE, Type.Real);
+ _java2Internal.put(Double.TYPE, Type.Real);
+
+ _java2Internal.put(String.class, Type.String);
+
+ _java2Internal.put(Object.class, Type.Reference);
+
+ // Conversions from org.w3c.dom.Node/NodeList to internal NodeSet
+ _java2Internal.put(nodeListClass, Type.NodeSet);
+ _java2Internal.put(nodeClass, Type.NodeSet);
+
+ // Initialize the extension namespace table
+ _extensionNamespaceTable.put(EXT_XALAN, "org.apache.xalan.lib.Extensions");
+ _extensionNamespaceTable.put(EXSLT_COMMON, "org.apache.xalan.lib.ExsltCommon");
+ _extensionNamespaceTable.put(EXSLT_MATH, "org.apache.xalan.lib.ExsltMath");
+ _extensionNamespaceTable.put(EXSLT_SETS, "org.apache.xalan.lib.ExsltSets");
+ _extensionNamespaceTable.put(EXSLT_DATETIME, "org.apache.xalan.lib.ExsltDatetime");
+ _extensionNamespaceTable.put(EXSLT_STRINGS, "org.apache.xalan.lib.ExsltStrings");
+
+ // Initialize the extension function table
+ _extensionFunctionTable.put(EXSLT_COMMON + ":nodeSet", "nodeset");
+ _extensionFunctionTable.put(EXSLT_COMMON + ":objectType", "objectType");
+ _extensionFunctionTable.put(EXT_XALAN + ":nodeset", "nodeset");
+ }
+ catch (ClassNotFoundException e) {
+ System.err.println(e);
+ }
+ }
+
+ public FunctionCall(QName fname, Vector arguments) {
+ _fname = fname;
+ _arguments = arguments;
+ _type = null;
+ }
+
+ public FunctionCall(QName fname) {
+ this(fname, EMPTY_ARG_LIST);
+ }
+
+ public String getName() {
+ return(_fname.toString());
+ }
+
+ public void setParser(Parser parser) {
+ super.setParser(parser);
+ if (_arguments != null) {
+ final int n = _arguments.size();
+ for (int i = 0; i < n; i++) {
+ final Expression exp = (Expression)_arguments.elementAt(i);
+ exp.setParser(parser);
+ exp.setParent(this);
+ }
+ }
+ }
+
+ public String getClassNameFromUri(String uri)
+ {
+ String className = (String)_extensionNamespaceTable.get(uri);
+
+ if (className != null)
+ return className;
+ else {
+ if (uri.startsWith(JAVA_EXT_XSLTC)) {
+ int length = JAVA_EXT_XSLTC.length() + 1;
+ return (uri.length() > length) ? uri.substring(length) : EMPTYSTRING;
+ }
+ else if (uri.startsWith(JAVA_EXT_XALAN)) {
+ int length = JAVA_EXT_XALAN.length() + 1;
+ return (uri.length() > length) ? uri.substring(length) : EMPTYSTRING;
+ }
+ else if (uri.startsWith(JAVA_EXT_XALAN_OLD)) {
+ int length = JAVA_EXT_XALAN_OLD.length() + 1;
+ return (uri.length() > length) ? uri.substring(length) : EMPTYSTRING;
+ }
+ else {
+ int index = uri.lastIndexOf('/');
+ return (index > 0) ? uri.substring(index+1) : uri;
+ }
+ }
+ }
+
+ /**
+ * Type check a function call. Since different type conversions apply,
+ * type checking is different for standard and external (Java) functions.
+ */
+ public Type typeCheck(SymbolTable stable)
+ throws TypeCheckError
+ {
+ if (_type != null) return _type;
+
+ final String namespace = _fname.getNamespace();
+ String local = _fname.getLocalPart();
+
+ if (isExtension()) {
+ _fname = new QName(null, null, local);
+ return typeCheckStandard(stable);
+ }
+ else if (isStandard()) {
+ return typeCheckStandard(stable);
+ }
+ // Handle extension functions (they all have a namespace)
+ else {
+ try {
+ _className = getClassNameFromUri(namespace);
+
+ final int pos = local.lastIndexOf('.');
+ if (pos > 0) {
+ _isStatic = true;
+ if (_className != null && _className.length() > 0) {
+ _namespace_format = NAMESPACE_FORMAT_PACKAGE;
+ _className = _className + "." + local.substring(0, pos);
+ }
+ else {
+ _namespace_format = NAMESPACE_FORMAT_JAVA;
+ _className = local.substring(0, pos);
+ }
+
+ _fname = new QName(namespace, null, local.substring(pos + 1));
+ }
+ else {
+ if (_className != null && _className.length() > 0) {
+ try {
+ _clazz = ObjectFactory.findProviderClass(
+ _className, ObjectFactory.findClassLoader(), true);
+ _namespace_format = NAMESPACE_FORMAT_CLASS;
+ }
+ catch (ClassNotFoundException e) {
+ _namespace_format = NAMESPACE_FORMAT_PACKAGE;
+ }
+ }
+ else
+ _namespace_format = NAMESPACE_FORMAT_JAVA;
+
+ if (local.indexOf('-') > 0) {
+ local = replaceDash(local);
+ }
+
+ String extFunction = (String)_extensionFunctionTable.get(namespace + ":" + local);
+ if (extFunction != null) {
+ _fname = new QName(null, null, extFunction);
+ return typeCheckStandard(stable);
+ }
+ else
+ _fname = new QName(namespace, null, local);
+ }
+
+ return typeCheckExternal(stable);
+ }
+ catch (TypeCheckError e) {
+ ErrorMsg errorMsg = e.getErrorMsg();
+ if (errorMsg == null) {
+ final String name = _fname.getLocalPart();
+ errorMsg = new ErrorMsg(ErrorMsg.METHOD_NOT_FOUND_ERR, name);
+ }
+ getParser().reportError(ERROR, errorMsg);
+ return _type = Type.Void;
+ }
+ }
+ }
+
+ /**
+ * Type check a call to a standard function. Insert CastExprs when needed.
+ * If as a result of the insertion of a CastExpr a type check error is
+ * 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.getLocalPart(), args);
+
+ if (ptype != null) {
+ for (int i = 0; i < n; i++) {
+ final Type argType = (Type) ptype.argsType().elementAt(i);
+ final Expression exp = (Expression)_arguments.elementAt(i);
+ if (!argType.identicalTo(exp.getType())) {
+ try {
+ _arguments.setElementAt(new CastExpr(exp, argType), i);
+ }
+ catch (TypeCheckError e) {
+ throw new TypeCheckError(this); // invalid conversion
+ }
+ }
+ }
+ _chosenMethodType = ptype;
+ return _type = ptype.resultType();
+ }
+ throw new TypeCheckError(this);
+ }
+
+
+
+ public Type typeCheckConstructor(SymbolTable stable) throws TypeCheckError{
+ final Vector constructors = findConstructors();
+ if (constructors == null) {
+ // Constructor not found in this class
+ throw new TypeCheckError(ErrorMsg.CONSTRUCTOR_NOT_FOUND,
+ _className);
+
+ }
+
+ final int nConstructors = constructors.size();
+ final int nArgs = _arguments.size();
+ final Vector argsType = typeCheckArgs(stable);
+
+ // Try all constructors
+ int bestConstrDistance = Integer.MAX_VALUE;
+ _type = null; // reset
+ for (int j, i = 0; i < nConstructors; i++) {
+ // Check if all parameters to this constructor can be converted
+ final Constructor constructor =
+ (Constructor)constructors.elementAt(i);
+ final Class[] paramTypes = constructor.getParameterTypes();
+
+ Class extType = null;
+ int currConstrDistance = 0;
+ for (j = 0; j < nArgs; j++) {
+ // Convert from internal (translet) type to external (Java) type
+ extType = paramTypes[j];
+ final Type intType = (Type)argsType.elementAt(j);
+ Object match = _internal2Java.maps(intType, extType);
+ if (match != null) {
+ currConstrDistance += ((JavaType)match).distance;
+ }
+ else if (intType instanceof ObjectType) {
+ ObjectType objectType = (ObjectType)intType;
+ if (objectType.getJavaClass() == extType)
+ continue;
+ else if (extType.isAssignableFrom(objectType.getJavaClass()))
+ currConstrDistance += 1;
+ else {
+ currConstrDistance = Integer.MAX_VALUE;
+ break;
+ }
+ }
+ else {
+ // no mapping available
+ currConstrDistance = Integer.MAX_VALUE;
+ break;
+ }
+ }
+
+ if (j == nArgs && currConstrDistance < bestConstrDistance ) {
+ _chosenConstructor = constructor;
+ _isExtConstructor = true;
+ bestConstrDistance = currConstrDistance;
+
+ _type = (_clazz != null) ? Type.newObjectType(_clazz)
+ : Type.newObjectType(_className);
+ }
+ }
+
+ if (_type != null) {
+ return _type;
+ }
+
+ throw new TypeCheckError(ErrorMsg.ARGUMENT_CONVERSION_ERR, getMethodSignature(argsType));
+ }
+
+
+ /**
+ * Type check a call to an external (Java) method.
+ * The method must be static an public, and a legal type conversion
+ * must exist for all its arguments and its return type.
+ * Every method of name <code>_fname</code> is inspected
+ * as a possible candidate.
+ */
+ public Type typeCheckExternal(SymbolTable stable) throws TypeCheckError {
+ int nArgs = _arguments.size();
+ final String name = _fname.getLocalPart();
+
+ // check if function is a contructor 'new'
+ if (_fname.getLocalPart().equals("new")) {
+ return typeCheckConstructor(stable);
+ }
+ // check if we are calling an instance method
+ else {
+ boolean hasThisArgument = false;
+
+ if (nArgs == 0)
+ _isStatic = true;
+
+ if (!_isStatic) {
+ if (_namespace_format == NAMESPACE_FORMAT_JAVA
+ || _namespace_format == NAMESPACE_FORMAT_PACKAGE)
+ hasThisArgument = true;
+
+ Expression firstArg = (Expression)_arguments.elementAt(0);
+ Type firstArgType = (Type)firstArg.typeCheck(stable);
+
+ if (_namespace_format == NAMESPACE_FORMAT_CLASS
+ && firstArgType instanceof ObjectType
+ && _clazz != null
+ && _clazz.isAssignableFrom(((ObjectType)firstArgType).getJavaClass()))
+ hasThisArgument = true;
+
+ if (hasThisArgument) {
+ _thisArgument = (Expression) _arguments.elementAt(0);
+ _arguments.remove(0); nArgs--;
+ if (firstArgType instanceof ObjectType) {
+ _className = ((ObjectType) firstArgType).getJavaClassName();
+ }
+ else
+ throw new TypeCheckError(ErrorMsg.NO_JAVA_FUNCT_THIS_REF, name);
+ }
+ }
+ else if (_className.length() == 0) {
+ /*
+ * Warn user if external function could not be resolved.
+ * Warning will _NOT_ be issued is the call is properly
+ * wrapped in an <xsl:if> or <xsl:when> element. For details
+ * see If.parserContents() and When.parserContents()
+ */
+ final Parser parser = getParser();
+ if (parser != null) {
+ reportWarning(this, parser, ErrorMsg.FUNCTION_RESOLVE_ERR,
+ _fname.toString());
+ }
+ unresolvedExternal = true;
+ return _type = Type.Int; // use "Int" as "unknown"
+ }
+ }
+
+ final Vector methods = findMethods();
+
+ if (methods == null) {
+ // Method not found in this class
+ throw new TypeCheckError(ErrorMsg.METHOD_NOT_FOUND_ERR, _className + "." + name);
+ }
+
+ Class extType = null;
+ final int nMethods = methods.size();
+ final Vector argsType = typeCheckArgs(stable);
+
+ // Try all methods to identify the best fit
+ int bestMethodDistance = Integer.MAX_VALUE;
+ _type = null; // reset internal type
+ for (int j, i = 0; i < nMethods; i++) {
+ // Check if all paramteters to this method can be converted
+ final Method method = (Method)methods.elementAt(i);
+ final Class[] paramTypes = method.getParameterTypes();
+
+ int currMethodDistance = 0;
+ for (j = 0; j < nArgs; j++) {
+ // Convert from internal (translet) type to external (Java) type
+ extType = paramTypes[j];
+ final Type intType = (Type)argsType.elementAt(j);
+ Object match = _internal2Java.maps(intType, extType);
+ if (match != null) {
+ currMethodDistance += ((JavaType)match).distance;
+ }
+ else {
+ // no mapping available
+ //
+ // Allow a Reference type to match any external (Java) type at
+ // the moment. The real type checking is performed at runtime.
+ if (intType instanceof ReferenceType) {
+ currMethodDistance += 1;
+ }
+ else if (intType instanceof ObjectType) {
+ ObjectType object = (ObjectType)intType;
+ if (extType.getName().equals(object.getJavaClassName()))
+ currMethodDistance += 0;
+ else if (extType.isAssignableFrom(object.getJavaClass()))
+ currMethodDistance += 1;
+ else {
+ currMethodDistance = Integer.MAX_VALUE;
+ break;
+ }
+ }
+ else {
+ currMethodDistance = Integer.MAX_VALUE;
+ break;
+ }
+ }
+ }
+
+ if (j == nArgs) {
+ // Check if the return type can be converted
+ extType = method.getReturnType();
+
+ _type = (Type) _java2Internal.get(extType);
+ if (_type == null) {
+ _type = Type.newObjectType(extType);
+ }
+
+ // Use this method if all parameters & return type match
+ if (_type != null && currMethodDistance < bestMethodDistance) {
+ _chosenMethod = method;
+ bestMethodDistance = currMethodDistance;
+ }
+ }
+ }
+
+ // It is an error if the chosen method is an instance menthod but we don't
+ // have a this argument.
+ if (_chosenMethod != null && _thisArgument == null &&
+ !Modifier.isStatic(_chosenMethod.getModifiers())) {
+ throw new TypeCheckError(ErrorMsg.NO_JAVA_FUNCT_THIS_REF, getMethodSignature(argsType));
+ }
+
+ if (_type != null) {
+ if (_type == Type.NodeSet) {
+ getXSLTC().setMultiDocument(true);
+ }
+ return _type;
+ }
+
+ throw new TypeCheckError(ErrorMsg.ARGUMENT_CONVERSION_ERR, getMethodSignature(argsType));
+ }
+
+ /**
+ * Type check the actual arguments of this function call.
+ */
+ public Vector typeCheckArgs(SymbolTable stable) throws TypeCheckError {
+ final Vector result = new Vector();
+ final Enumeration e = _arguments.elements();
+ while (e.hasMoreElements()) {
+ final Expression exp = (Expression)e.nextElement();
+ result.addElement(exp.typeCheck(stable));
+ }
+ return result;
+ }
+
+ protected final Expression argument(int i) {
+ return (Expression)_arguments.elementAt(i);
+ }
+
+ protected final Expression argument() {
+ return argument(0);
+ }
+
+ protected final int argumentCount() {
+ return _arguments.size();
+ }
+
+ protected final void setArgument(int i, Expression exp) {
+ _arguments.setElementAt(exp, i);
+ }
+
+ /**
+ * Compile the function call and treat as an expression
+ * Update true/false-lists.
+ */
+ public void translateDesynthesized(ClassGenerator classGen,
+ MethodGenerator methodGen)
+ {
+ Type type = Type.Boolean;
+ if (_chosenMethodType != null)
+ type = _chosenMethodType.resultType();
+
+ final InstructionList il = methodGen.getInstructionList();
+ translate(classGen, methodGen);
+
+ if ((type instanceof BooleanType) || (type instanceof IntType)) {
+ _falseList.add(il.append(new IFEQ(null)));
+ }
+ }
+
+
+ /**
+ * Translate a function call. The compiled code will leave the function's
+ * return value on the JVM's stack.
+ */
+ public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
+ final int n = argumentCount();
+ final ConstantPoolGen cpg = classGen.getConstantPool();
+ final InstructionList il = methodGen.getInstructionList();
+ final boolean isSecureProcessing = classGen.getParser().getXSLTC().isSecureProcessing();
+ int index;
+
+ // Translate calls to methods in the BasisLibrary
+ if (isStandard() || isExtension()) {
+ for (int i = 0; i < n; i++) {
+ final Expression exp = argument(i);
+ exp.translate(classGen, methodGen);
+ exp.startIterator(classGen, methodGen);
+ }
+
+ // append "F" to the function's name
+ final String name = _fname.toString().replace('-', '_') + "F";
+ String args = Constants.EMPTYSTRING;
+
+ // Special precautions for some method calls
+ if (name.equals("sumF")) {
+ args = DOM_INTF_SIG;
+ il.append(methodGen.loadDOM());
+ }
+ else if (name.equals("normalize_spaceF")) {
+ if (_chosenMethodType.toSignature(args).
+ equals("()Ljava/lang/String;")) {
+ args = "I"+DOM_INTF_SIG;
+ il.append(methodGen.loadContextNode());
+ il.append(methodGen.loadDOM());
+ }
+ }
+
... 82921 lines suppressed ...
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xalan.apache.org
For additional commands, e-mail: commits-help@xalan.apache.org