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.CHECKCAST; 26 import org.apache.bcel.generic.InstructionList; 27 import org.apache.xalan.xsltc.compiler.util.ClassGenerator; 28 import org.apache.xalan.xsltc.compiler.util.MethodGenerator; 29 import org.apache.xalan.xsltc.compiler.util.ErrorMsg; 30 import org.apache.xalan.xsltc.compiler.util.Type; 31 import org.apache.xalan.xsltc.compiler.util.ObjectType; 32 import org.apache.xalan.xsltc.compiler.util.TypeCheckError; 33 34 37 final class CastCall extends FunctionCall { 38 39 43 private String _className; 44 45 48 private Expression _right; 49 50 53 public CastCall(QName fname, Vector arguments) { 54 super(fname, arguments); 55 } 56 57 60 public Type typeCheck(SymbolTable stable) throws TypeCheckError { 61 if (argumentCount() != 2) { 63 throw new TypeCheckError(new ErrorMsg(ErrorMsg.ILLEGAL_ARG_ERR, 64 getName(), this)); 65 } 66 67 Expression exp = argument(0); 69 if (exp instanceof LiteralExpr) { 70 _className = ((LiteralExpr) exp).getValue(); 71 _type = Type.newObjectType(_className); 72 } 73 else { 74 throw new TypeCheckError(new ErrorMsg(ErrorMsg.NEED_LITERAL_ERR, 75 getName(), this)); 76 } 77 78 _right = argument(1); 80 Type tright = _right.typeCheck(stable); 81 if (tright != Type.Reference && 82 tright instanceof ObjectType == false) 83 { 84 throw new TypeCheckError(new ErrorMsg(ErrorMsg.DATA_CONVERSION_ERR, 85 tright, _type, this)); 86 } 87 88 return _type; 89 } 90 91 public void translate(ClassGenerator classGen, MethodGenerator methodGen) { 92 final ConstantPoolGen cpg = classGen.getConstantPool(); 93 final InstructionList il = methodGen.getInstructionList(); 94 95 _right.translate(classGen, methodGen); 96 il.append(new CHECKCAST(cpg.addClass(_className))); 97 } 98 } 99 | Popular Tags |