1. /*
  2. * Copyright 2001-2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /*
  17. * $Id: FilteredAbsoluteLocationPath.java,v 1.6 2004/02/16 22:24:28 minchau Exp $
  18. */
  19. package com.sun.org.apache.xalan.internal.xsltc.compiler;
  20. import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
  21. import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE;
  22. import com.sun.org.apache.bcel.internal.generic.INVOKESPECIAL;
  23. import com.sun.org.apache.bcel.internal.generic.InstructionList;
  24. import com.sun.org.apache.bcel.internal.generic.NEW;
  25. import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
  26. import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
  27. import com.sun.org.apache.xalan.internal.xsltc.compiler.util.NodeType;
  28. import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
  29. import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
  30. /**
  31. * @author G. Todd Miller
  32. */
  33. final class FilteredAbsoluteLocationPath extends Expression {
  34. private Expression _path; // may be null
  35. public FilteredAbsoluteLocationPath() {
  36. _path = null;
  37. }
  38. public FilteredAbsoluteLocationPath(Expression path) {
  39. _path = path;
  40. if (path != null) {
  41. _path.setParent(this);
  42. }
  43. }
  44. public void setParser(Parser parser) {
  45. super.setParser(parser);
  46. if (_path != null) {
  47. _path.setParser(parser);
  48. }
  49. }
  50. public Expression getPath() {
  51. return(_path);
  52. }
  53. public String toString() {
  54. return "FilteredAbsoluteLocationPath(" +
  55. (_path != null ? _path.toString() : "null") + ')';
  56. }
  57. public Type typeCheck(SymbolTable stable) throws TypeCheckError {
  58. if (_path != null) {
  59. final Type ptype = _path.typeCheck(stable);
  60. if (ptype instanceof NodeType) { // promote to node-set
  61. _path = new CastExpr(_path, Type.NodeSet);
  62. }
  63. }
  64. return _type = Type.NodeSet;
  65. }
  66. public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
  67. final ConstantPoolGen cpg = classGen.getConstantPool();
  68. final InstructionList il = methodGen.getInstructionList();
  69. if (_path != null) {
  70. final int initDFI = cpg.addMethodref(DUP_FILTERED_ITERATOR,
  71. "<init>",
  72. "("
  73. + NODE_ITERATOR_SIG
  74. + ")V");
  75. // Create new Dup Filter Iterator
  76. il.append(new NEW(cpg.addClass(DUP_FILTERED_ITERATOR)));
  77. il.append(DUP);
  78. // Compile relative path iterator(s)
  79. _path.translate(classGen, methodGen);
  80. // Initialize Dup Filter Iterator with iterator from the stack
  81. il.append(new INVOKESPECIAL(initDFI));
  82. }
  83. else {
  84. final int git = cpg.addInterfaceMethodref(DOM_INTF,
  85. "getIterator",
  86. "()"+NODE_ITERATOR_SIG);
  87. il.append(methodGen.loadDOM());
  88. il.append(new INVOKEINTERFACE(git, 1));
  89. }
  90. }
  91. }