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: LastCall.java,v 1.11 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.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. */
  32. final class LastCall extends FunctionCall {
  33. public LastCall(QName fname) {
  34. super(fname);
  35. }
  36. public boolean hasPositionCall() {
  37. return true;
  38. }
  39. public boolean hasLastCall() {
  40. return true;
  41. }
  42. public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
  43. final InstructionList il = methodGen.getInstructionList();
  44. if (methodGen instanceof CompareGenerator) {
  45. il.append(((CompareGenerator)methodGen).loadLastNode());
  46. }
  47. else if (methodGen instanceof TestGenerator) {
  48. il.append(new ILOAD(LAST_INDEX));
  49. }
  50. else {
  51. final ConstantPoolGen cpg = classGen.getConstantPool();
  52. final int getLast = cpg.addInterfaceMethodref(NODE_ITERATOR,
  53. "getLast",
  54. "()I");
  55. il.append(methodGen.loadIterator());
  56. il.append(new INVOKEINTERFACE(getLast, 1));
  57. }
  58. }
  59. }