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: PositionCall.java,v 1.14 2004/02/16 22:24:29 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.ILOAD;
  22. import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE;
  23. import com.sun.org.apache.bcel.internal.generic.InstructionList;
  24. import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
  25. import com.sun.org.apache.xalan.internal.xsltc.compiler.util.CompareGenerator;
  26. import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
  27. import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TestGenerator;
  28. /**
  29. * @author Jacek Ambroziak
  30. * @author Santiago Pericas-Geertsen
  31. * @author Morten Jorgensen
  32. */
  33. final class PositionCall extends FunctionCall {
  34. public PositionCall(QName fname) {
  35. super(fname);
  36. }
  37. public boolean hasPositionCall() {
  38. return true;
  39. }
  40. public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
  41. final InstructionList il = methodGen.getInstructionList();
  42. if (methodGen instanceof CompareGenerator) {
  43. il.append(((CompareGenerator)methodGen).loadCurrentNode());
  44. }
  45. else if (methodGen instanceof TestGenerator) {
  46. il.append(new ILOAD(POSITION_INDEX));
  47. }
  48. else {
  49. final ConstantPoolGen cpg = classGen.getConstantPool();
  50. final int index = cpg.addInterfaceMethodref(NODE_ITERATOR,
  51. "getPosition",
  52. "()I");
  53. il.append(methodGen.loadIterator());
  54. il.append(new INVOKEINTERFACE(index,1));
  55. }
  56. }
  57. }