|
1 /* |
|
2 * reserved comment block |
|
3 * DO NOT REMOVE OR ALTER! |
|
4 */ |
|
5 /* |
|
6 * Copyright 2001-2004 The Apache Software Foundation. |
|
7 * |
|
8 * Licensed under the Apache License, Version 2.0 (the "License"); |
|
9 * you may not use this file except in compliance with the License. |
|
10 * You may obtain a copy of the License at |
|
11 * |
|
12 * http://www.apache.org/licenses/LICENSE-2.0 |
|
13 * |
|
14 * Unless required by applicable law or agreed to in writing, software |
|
15 * distributed under the License is distributed on an "AS IS" BASIS, |
|
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
17 * See the License for the specific language governing permissions and |
|
18 * limitations under the License. |
|
19 */ |
|
20 /* |
|
21 * $Id: LastCall.java,v 1.2.4.1 2005/09/01 15:55:34 pvedula Exp $ |
|
22 */ |
|
23 |
|
24 package com.sun.org.apache.xalan.internal.xsltc.compiler; |
|
25 |
|
26 import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen; |
|
27 import com.sun.org.apache.bcel.internal.generic.ILOAD; |
|
28 import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE; |
|
29 import com.sun.org.apache.bcel.internal.generic.InstructionList; |
|
30 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator; |
|
31 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.CompareGenerator; |
|
32 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator; |
|
33 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TestGenerator; |
|
34 |
|
35 /** |
|
36 * @author Jacek Ambroziak |
|
37 * @author Santiago Pericas-Geertsen |
|
38 */ |
|
39 final class LastCall extends FunctionCall { |
|
40 |
|
41 public LastCall(QName fname) { |
|
42 super(fname); |
|
43 } |
|
44 |
|
45 public boolean hasPositionCall() { |
|
46 return true; |
|
47 } |
|
48 |
|
49 public boolean hasLastCall() { |
|
50 return true; |
|
51 } |
|
52 |
|
53 public void translate(ClassGenerator classGen, MethodGenerator methodGen) { |
|
54 final InstructionList il = methodGen.getInstructionList(); |
|
55 |
|
56 if (methodGen instanceof CompareGenerator) { |
|
57 il.append(((CompareGenerator)methodGen).loadLastNode()); |
|
58 } |
|
59 else if (methodGen instanceof TestGenerator) { |
|
60 il.append(new ILOAD(LAST_INDEX)); |
|
61 } |
|
62 else { |
|
63 final ConstantPoolGen cpg = classGen.getConstantPool(); |
|
64 final int getLast = cpg.addInterfaceMethodref(NODE_ITERATOR, |
|
65 "getLast", |
|
66 "()I"); |
|
67 il.append(methodGen.loadIterator()); |
|
68 il.append(new INVOKEINTERFACE(getLast, 1)); |
|
69 } |
|
70 } |
|
71 } |