1 16 19 20 package com.sun.org.apache.xalan.internal.xsltc.compiler; 21 22 import java.util.Vector ; 23 24 import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen; 25 import com.sun.org.apache.bcel.internal.generic.INVOKESTATIC; 26 import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL; 27 import com.sun.org.apache.bcel.internal.generic.InstructionList; 28 import com.sun.org.apache.bcel.internal.generic.PUSH; 29 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator; 30 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator; 31 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.RealType; 32 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.StringType; 33 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type; 34 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError; 35 36 41 final class FormatNumberCall extends FunctionCall { 42 private Expression _value; 43 private Expression _format; 44 private Expression _name; 45 private QName _resolvedQName = null; 46 47 public FormatNumberCall(QName fname, Vector arguments) { 48 super(fname, arguments); 49 _value = argument(0); 50 _format = argument(1); 51 _name = argumentCount() == 3 ? argument(2) : null; 52 } 53 54 public Type typeCheck(SymbolTable stable) throws TypeCheckError { 55 56 getStylesheet().numberFormattingUsed(); 58 59 final Type tvalue = _value.typeCheck(stable); 60 if (tvalue instanceof RealType == false) { 61 _value = new CastExpr(_value, Type.Real); 62 } 63 final Type tformat = _format.typeCheck(stable); 64 if (tformat instanceof StringType == false) { 65 _format = new CastExpr(_format, Type.String); 66 } 67 if (argumentCount() == 3) { 68 final Type tname = _name.typeCheck(stable); 69 70 if (_name instanceof LiteralExpr) { 71 final LiteralExpr literal = (LiteralExpr) _name; 72 _resolvedQName = 73 getParser().getQNameIgnoreDefaultNs(literal.getValue()); 74 } 75 else if (tname instanceof StringType == false) { 76 _name = new CastExpr(_name, Type.String); 77 } 78 } 79 return _type = Type.String; 80 } 81 82 public void translate(ClassGenerator classGen, MethodGenerator methodGen) { 83 final ConstantPoolGen cpg = classGen.getConstantPool(); 84 final InstructionList il = methodGen.getInstructionList(); 85 86 _value.translate(classGen, methodGen); 87 _format.translate(classGen, methodGen); 88 89 final int fn3arg = cpg.addMethodref(BASIS_LIBRARY_CLASS, 90 "formatNumber", 91 "(DLjava/lang/String;"+ 92 "Ljava/text/DecimalFormat;)"+ 93 "Ljava/lang/String;"); 94 final int get = cpg.addMethodref(TRANSLET_CLASS, 95 "getDecimalFormat", 96 "(Ljava/lang/String;)"+ 97 "Ljava/text/DecimalFormat;"); 98 99 il.append(classGen.loadTranslet()); 100 if (_name == null) { 101 il.append(new PUSH(cpg, EMPTYSTRING)); 102 } 103 else if (_resolvedQName != null) { 104 il.append(new PUSH(cpg, _resolvedQName.toString())); 105 } 106 else { 107 _name.translate(classGen, methodGen); 108 } 109 il.append(new INVOKEVIRTUAL(get)); 110 il.append(new INVOKESTATIC(fn3arg)); 111 } 112 } 113 | Popular Tags |