KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xalan > internal > xsltc > compiler > LastCall


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
20 package com.sun.org.apache.xalan.internal.xsltc.compiler;
21
22 import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
23 import com.sun.org.apache.bcel.internal.generic.ILOAD;
24 import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE;
25 import com.sun.org.apache.bcel.internal.generic.InstructionList;
26 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
27 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.CompareGenerator;
28 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
29 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TestGenerator;
30
31 /**
32  * @author Jacek Ambroziak
33  * @author Santiago Pericas-Geertsen
34  */

35 final class LastCall extends FunctionCall {
36
37     public LastCall(QName fname) {
38     super(fname);
39     }
40
41     public boolean hasPositionCall() {
42     return true;
43     }
44
45     public boolean hasLastCall() {
46     return true;
47     }
48
49     public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
50     final InstructionList il = methodGen.getInstructionList();
51
52     if (methodGen instanceof CompareGenerator) {
53         il.append(((CompareGenerator)methodGen).loadLastNode());
54     }
55     else if (methodGen instanceof TestGenerator) {
56         il.append(new ILOAD(LAST_INDEX));
57     }
58     else {
59         final ConstantPoolGen cpg = classGen.getConstantPool();
60         final int getLast = cpg.addInterfaceMethodref(NODE_ITERATOR,
61                               "getLast",
62                               "()I");
63         il.append(methodGen.loadIterator());
64         il.append(new INVOKEINTERFACE(getLast, 1));
65     }
66     }
67 }
68
Popular Tags