1 16 19 20 package org.apache.xalan.xsltc.compiler; 21 22 import java.util.Vector ; 23 24 import org.apache.bcel.generic.ConstantPoolGen; 25 import org.apache.bcel.generic.INVOKESPECIAL; 26 import org.apache.bcel.generic.INVOKEVIRTUAL; 27 import org.apache.bcel.generic.Instruction; 28 import org.apache.bcel.generic.InstructionList; 29 import org.apache.bcel.generic.NEW; 30 import org.apache.bcel.generic.PUSH; 31 import org.apache.xalan.xsltc.compiler.util.ClassGenerator; 32 import org.apache.xalan.xsltc.compiler.util.MethodGenerator; 33 import org.apache.xalan.xsltc.compiler.util.Type; 34 import org.apache.xalan.xsltc.compiler.util.TypeCheckError; 35 36 40 final class ConcatCall extends FunctionCall { 41 public ConcatCall(QName fname, Vector arguments) { 42 super(fname, arguments); 43 } 44 45 public Type typeCheck(SymbolTable stable) throws TypeCheckError { 46 for (int i = 0; i < argumentCount(); i++) { 47 final Expression exp = argument(i); 48 if (!exp.typeCheck(stable).identicalTo(Type.String)) { 49 setArgument(i, new CastExpr(exp, Type.String)); 50 } 51 } 52 return _type = Type.String; 53 } 54 55 56 public void translate(ClassGenerator classGen, MethodGenerator methodGen) { 57 final ConstantPoolGen cpg = classGen.getConstantPool(); 58 final InstructionList il = methodGen.getInstructionList(); 59 final int nArgs = argumentCount(); 60 61 switch (nArgs) { 62 case 0: 63 il.append(new PUSH(cpg, EMPTYSTRING)); 64 break; 65 66 case 1: 67 argument().translate(classGen, methodGen); 68 break; 69 70 default: 71 final int initBuffer = cpg.addMethodref(STRING_BUFFER_CLASS, 72 "<init>", "()V"); 73 final Instruction append = 74 new INVOKEVIRTUAL(cpg.addMethodref(STRING_BUFFER_CLASS, 75 "append", 76 "("+STRING_SIG+")" 77 +STRING_BUFFER_SIG)); 78 79 final int toString = cpg.addMethodref(STRING_BUFFER_CLASS, 80 "toString", 81 "()"+STRING_SIG); 82 83 il.append(new NEW(cpg.addClass(STRING_BUFFER_CLASS))); 84 il.append(DUP); 85 il.append(new INVOKESPECIAL(initBuffer)); 86 for (int i = 0; i < nArgs; i++) { 87 argument(i).translate(classGen, methodGen); 88 il.append(append); 89 } 90 il.append(new INVOKEVIRTUAL(toString)); 91 } 92 } 93 } 94 | Popular Tags |