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