jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/util/RealType.java
author joehw
Tue, 17 Apr 2012 11:17:59 -0700
changeset 12458 d601e4bba306
parent 12457 c348e06f0e82
permissions -rw-r--r--
7160380: Sync JDK8 with JAXP 1.4.5 Summary: bring JDK8 up to date to what we have in 7u4 Reviewed-by: lancea, mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     2
 * reserved comment block
7f561c08de6b Initial load
duke
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     6
 * Copyright 2001-2004 The Apache Software Foundation.
7f561c08de6b Initial load
duke
parents:
diff changeset
     7
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
     8
 * Licensed under the Apache License, Version 2.0 (the "License");
7f561c08de6b Initial load
duke
parents:
diff changeset
     9
 * you may not use this file except in compliance with the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    10
 * You may obtain a copy of the License at
7f561c08de6b Initial load
duke
parents:
diff changeset
    11
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *     http://www.apache.org/licenses/LICENSE-2.0
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 * Unless required by applicable law or agreed to in writing, software
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * distributed under the License is distributed on an "AS IS" BASIS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * See the License for the specific language governing permissions and
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * limitations under the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
 * $Id: RealType.java,v 1.2.4.1 2005/09/05 11:28:45 pvedula Exp $
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
package com.sun.org.apache.xalan.internal.xsltc.compiler.util;
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
import com.sun.org.apache.bcel.internal.generic.BranchHandle;
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
import com.sun.org.apache.bcel.internal.generic.CHECKCAST;
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
import com.sun.org.apache.bcel.internal.generic.DLOAD;
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
import com.sun.org.apache.bcel.internal.generic.DSTORE;
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
import com.sun.org.apache.bcel.internal.generic.GOTO;
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
import com.sun.org.apache.bcel.internal.generic.IFEQ;
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
import com.sun.org.apache.bcel.internal.generic.IFNE;
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
import com.sun.org.apache.bcel.internal.generic.INVOKESPECIAL;
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
import com.sun.org.apache.bcel.internal.generic.INVOKESTATIC;
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL;
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
import com.sun.org.apache.bcel.internal.generic.Instruction;
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
import com.sun.org.apache.bcel.internal.generic.InstructionConstants;
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
import com.sun.org.apache.bcel.internal.generic.InstructionList;
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
import com.sun.org.apache.bcel.internal.generic.LocalVariableGen;
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
import com.sun.org.apache.bcel.internal.generic.NEW;
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
import com.sun.org.apache.xalan.internal.xsltc.compiler.Constants;
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
import com.sun.org.apache.xalan.internal.xsltc.compiler.FlowList;
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
 * @author Jacek Ambroziak
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
 * @author Santiago Pericas-Geertsen
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
public final class RealType extends NumberType {
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
    protected RealType() {}
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
    public String toString() {
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
        return "real";
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
    public boolean identicalTo(Type other) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
        return this == other;
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
    public String toSignature() {
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
        return "D";
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
    public com.sun.org.apache.bcel.internal.generic.Type toJCType() {
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
        return com.sun.org.apache.bcel.internal.generic.Type.DOUBLE;
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
     * @see     com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#distanceTo
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
    public int distanceTo(Type type) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
        if (type == this) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
            return 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
        else if (type == Type.Int) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
            return 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
            return Integer.MAX_VALUE;
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
     * Translates a real into an object of internal type <code>type</code>. The
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
     * translation to int is undefined since reals are never converted to ints.
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
     * @see     com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
    public void translateTo(ClassGenerator classGen, MethodGenerator methodGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
                            Type type) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
        if (type == Type.String) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
            translateTo(classGen, methodGen, (StringType) type);
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
        else if (type == Type.Boolean) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
            translateTo(classGen, methodGen, (BooleanType) type);
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
        else if (type == Type.Reference) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
            translateTo(classGen, methodGen, (ReferenceType) type);
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
        else if (type == Type.Int) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
            translateTo(classGen, methodGen, (IntType) type);
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
            ErrorMsg err = new ErrorMsg(ErrorMsg.DATA_CONVERSION_ERR,
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
                                        toString(), type.toString());
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
            classGen.getParser().reportError(Constants.FATAL, err);
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
     * Expects a real on the stack and pushes its string value by calling
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
     * <code>Double.toString(double d)</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
     * @see     com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
    public void translateTo(ClassGenerator classGen, MethodGenerator methodGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
                            StringType type) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
        final ConstantPoolGen cpg = classGen.getConstantPool();
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
        final InstructionList il = methodGen.getInstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
        il.append(new INVOKESTATIC(cpg.addMethodref(BASIS_LIBRARY_CLASS,
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
                                                    "realToString",
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
                                                    "(D)" + STRING_SIG)));
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
     * Expects a real on the stack and pushes a 0 if that number is 0.0 and
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
     * a 1 otherwise.
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
     * @see     com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
    public void translateTo(ClassGenerator classGen, MethodGenerator methodGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
                            BooleanType type) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
        final InstructionList il = methodGen.getInstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
        FlowList falsel = translateToDesynthesized(classGen, methodGen, type);
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
        il.append(ICONST_1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
        final BranchHandle truec = il.append(new GOTO(null));
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
        falsel.backPatch(il.append(ICONST_0));
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
        truec.setTarget(il.append(NOP));
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
     * Expects a real on the stack and pushes a truncated integer value
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
     * @see     com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
    public void translateTo(ClassGenerator classGen, MethodGenerator methodGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
                            IntType type) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
        final ConstantPoolGen cpg = classGen.getConstantPool();
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
        final InstructionList il = methodGen.getInstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
        il.append(new INVOKESTATIC(cpg.addMethodref(BASIS_LIBRARY_CLASS,
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
                                                    "realToInt","(D)I")));
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
     * Translates a real into a non-synthesized boolean. It does not push a
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
     * 0 or a 1 but instead returns branchhandle list to be appended to the
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
     * false list. A NaN must be converted to "false".
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
     * @see     com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateToDesynthesized
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
    public FlowList translateToDesynthesized(ClassGenerator classGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
                                             MethodGenerator methodGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
                                             BooleanType type) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
        LocalVariableGen local;
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
        final FlowList flowlist = new FlowList();
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
        final ConstantPoolGen cpg = classGen.getConstantPool();
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
        final InstructionList il = methodGen.getInstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
        // Store real into a local variable
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
        il.append(DUP2);
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
        local = methodGen.addLocalVariable("real_to_boolean_tmp",
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
                                           com.sun.org.apache.bcel.internal.generic.Type.DOUBLE,
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   173
                                           null, null);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   174
        local.setStart(il.append(new DSTORE(local.getIndex())));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
        // Compare it to 0.0
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
        il.append(DCONST_0);
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
        il.append(DCMPG);
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
        flowlist.add(il.append(new IFEQ(null)));
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
        //!!! call isNaN
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
        // Compare it to itself to see if NaN
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
        il.append(new DLOAD(local.getIndex()));
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   184
        local.setEnd(il.append(new DLOAD(local.getIndex())));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
        il.append(DCMPG);
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
        flowlist.add(il.append(new IFNE(null)));        // NaN != NaN
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
        return flowlist;
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
     * Expects a double on the stack and pushes a boxed double. Boxed
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
     * double are represented by an instance of <code>java.lang.Double</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
     * @see     com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
    public void translateTo(ClassGenerator classGen, MethodGenerator methodGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
                            ReferenceType type) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
        final ConstantPoolGen cpg = classGen.getConstantPool();
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
        final InstructionList il = methodGen.getInstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
        il.append(new NEW(cpg.addClass(DOUBLE_CLASS)));
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
        il.append(DUP_X2);
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
        il.append(DUP_X2);
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
        il.append(POP);
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
        il.append(new INVOKESPECIAL(cpg.addMethodref(DOUBLE_CLASS,
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
                                                     "<init>", "(D)V")));
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
     * Translates a real into the Java type denoted by <code>clazz</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
     * Expects a real on the stack and pushes a number of the appropriate
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
     * type after coercion.
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
    public void translateTo(ClassGenerator classGen, MethodGenerator methodGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
                            final Class clazz) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
        final InstructionList il = methodGen.getInstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
        if (clazz == Character.TYPE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
            il.append(D2I);
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
            il.append(I2C);
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
        else if (clazz == Byte.TYPE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
            il.append(D2I);
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
            il.append(I2B);
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
        else if (clazz == Short.TYPE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
            il.append(D2I);
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
            il.append(I2S);
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
        else if (clazz == Integer.TYPE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
            il.append(D2I);
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
        else if (clazz == Long.TYPE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
            il.append(D2L);
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
        else if (clazz == Float.TYPE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
            il.append(D2F);
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
        else if (clazz == Double.TYPE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
            il.append(NOP);
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
        // Is Double <: clazz? I.e. clazz in { Double, Number, Object }
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
        else if (clazz.isAssignableFrom(java.lang.Double.class)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
            translateTo(classGen, methodGen, Type.Reference);
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
            ErrorMsg err = new ErrorMsg(ErrorMsg.DATA_CONVERSION_ERR,
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
                                        toString(), clazz.getName());
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
            classGen.getParser().reportError(Constants.FATAL, err);
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
     * Translates an external (primitive) Java type into a real. Expects a java
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
     * object on the stack and pushes a real (i.e., a double).
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
    public void translateFrom(ClassGenerator classGen, MethodGenerator methodGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
                              Class clazz) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
        InstructionList il = methodGen.getInstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
        if (clazz == Character.TYPE || clazz == Byte.TYPE ||
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
            clazz == Short.TYPE || clazz == Integer.TYPE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
            il.append(I2D);
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
        else if (clazz == Long.TYPE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
            il.append(L2D);
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
        else if (clazz == Float.TYPE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
            il.append(F2D);
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
        else if (clazz == Double.TYPE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
            il.append(NOP);
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
            ErrorMsg err = new ErrorMsg(ErrorMsg.DATA_CONVERSION_ERR,
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
                                        toString(), clazz.getName());
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
            classGen.getParser().reportError(Constants.FATAL, err);
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
     * Translates an object of this type to its boxed representation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
    public void translateBox(ClassGenerator classGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
                             MethodGenerator methodGen) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
        translateTo(classGen, methodGen, Type.Reference);
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
     * Translates an object of this type to its unboxed representation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
    public void translateUnBox(ClassGenerator classGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
                               MethodGenerator methodGen) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
        final ConstantPoolGen cpg = classGen.getConstantPool();
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
        final InstructionList il = methodGen.getInstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
        il.append(new CHECKCAST(cpg.addClass(DOUBLE_CLASS)));
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
        il.append(new INVOKEVIRTUAL(cpg.addMethodref(DOUBLE_CLASS,
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
                                                     DOUBLE_VALUE,
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
                                                     DOUBLE_VALUE_SIG)));
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
    public Instruction ADD() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
        return InstructionConstants.DADD;
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
    public Instruction SUB() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
        return InstructionConstants.DSUB;
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
    public Instruction MUL() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
        return InstructionConstants.DMUL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   311
7f561c08de6b Initial load
duke
parents:
diff changeset
   312
    public Instruction DIV() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
        return InstructionConstants.DDIV;
7f561c08de6b Initial load
duke
parents:
diff changeset
   314
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   315
7f561c08de6b Initial load
duke
parents:
diff changeset
   316
    public Instruction REM() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   317
        return InstructionConstants.DREM;
7f561c08de6b Initial load
duke
parents:
diff changeset
   318
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
    public Instruction NEG() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   321
        return InstructionConstants.DNEG;
7f561c08de6b Initial load
duke
parents:
diff changeset
   322
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
    public Instruction LOAD(int slot) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   325
        return new DLOAD(slot);
7f561c08de6b Initial load
duke
parents:
diff changeset
   326
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   327
7f561c08de6b Initial load
duke
parents:
diff changeset
   328
    public Instruction STORE(int slot) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   329
        return new DSTORE(slot);
7f561c08de6b Initial load
duke
parents:
diff changeset
   330
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   331
7f561c08de6b Initial load
duke
parents:
diff changeset
   332
    public Instruction POP() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   333
        return POP2;
7f561c08de6b Initial load
duke
parents:
diff changeset
   334
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   335
7f561c08de6b Initial load
duke
parents:
diff changeset
   336
    public Instruction CMP(boolean less) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   337
        return less ? InstructionConstants.DCMPG : InstructionConstants.DCMPL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   338
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   339
7f561c08de6b Initial load
duke
parents:
diff changeset
   340
    public Instruction DUP() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   341
        return DUP2;
7f561c08de6b Initial load
duke
parents:
diff changeset
   342
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   343
}