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