src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/util/ReferenceType.java
author joehw
Wed, 18 Oct 2017 13:25:49 -0700
changeset 47359 e1a6c0168741
parent 47216 71c04702a3d5
child 48409 5ab69533994b
permissions -rw-r--r--
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked Reviewed-by: lancea, rriggs, mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
     2
 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
     3
 * @LastModified: Oct 2017
6
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.ALOAD;
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
import com.sun.org.apache.bcel.internal.generic.ASTORE;
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.IFEQ;
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
import com.sun.org.apache.bcel.internal.generic.ILOAD;
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE;
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
import com.sun.org.apache.bcel.internal.generic.INVOKESTATIC;
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
import com.sun.org.apache.bcel.internal.generic.Instruction;
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
import com.sun.org.apache.bcel.internal.generic.InstructionList;
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    33
import com.sun.org.apache.bcel.internal.generic.PUSH;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
import com.sun.org.apache.xalan.internal.xsltc.compiler.Constants;
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
import com.sun.org.apache.xalan.internal.xsltc.compiler.FlowList;
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
import com.sun.org.apache.xml.internal.dtm.DTM;
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
 * @author Jacek Ambroziak
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
 * @author Santiago Pericas-Geertsen
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
 * @author Erwin Bolwidt <ejb@klomp.org>
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
public final class ReferenceType extends Type {
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
    protected ReferenceType() {}
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
    public String toString() {
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
        return "reference";
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
    public boolean identicalTo(Type other) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
        return this == other;
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 String toSignature() {
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
        return "Ljava/lang/Object;";
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 com.sun.org.apache.bcel.internal.generic.Type toJCType() {
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
        return com.sun.org.apache.bcel.internal.generic.Type.OBJECT;
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
     * Translates a reference to an object of internal type <code>type</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
     * The translation to int is undefined since references
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
     * are always converted to reals in arithmetic expressions.
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#translateTo
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
    public void translateTo(ClassGenerator classGen, MethodGenerator methodGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
                            Type type) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
        if (type == Type.String) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
            translateTo(classGen, methodGen, (StringType) type);
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
        else if (type == Type.Real) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
            translateTo(classGen, methodGen, (RealType) type);
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
        else if (type == Type.Boolean) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
            translateTo(classGen, methodGen, (BooleanType) type);
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
        else if (type == Type.NodeSet) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
            translateTo(classGen, methodGen, (NodeSetType) type);
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
        else if (type == Type.Node) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
            translateTo(classGen, methodGen, (NodeType) type);
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
        else if (type == Type.ResultTree) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
            translateTo(classGen, methodGen, (ResultTreeType) type);
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
        else if (type == Type.Object) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
            translateTo(classGen, methodGen, (ObjectType) type);
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
        else if (type == Type.Reference ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
            ErrorMsg err = new ErrorMsg(ErrorMsg.INTERNAL_ERR, type.toString());
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
            classGen.getParser().reportError(Constants.FATAL, err);
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
     * Translates reference into object of internal type <code>type</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
     * @see     com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
    public void translateTo(ClassGenerator classGen, MethodGenerator methodGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
                            StringType type) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
        final int current = methodGen.getLocalIndex("current");
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
        ConstantPoolGen cpg = classGen.getConstantPool();
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
        InstructionList il = methodGen.getInstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
        // If no current, conversion is a top-level
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
        if (current < 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
            il.append(new PUSH(cpg, DTM.ROOT_NODE));  // push root node
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
            il.append(new ILOAD(current));
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
        il.append(methodGen.loadDOM());
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
        final int stringF = cpg.addMethodref(BASIS_LIBRARY_CLASS,
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
                                             "stringF",
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
                                             "("
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
                                             + OBJECT_SIG
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
                                             + NODE_SIG
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
                                             + DOM_INTF_SIG
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
                                             + ")" + STRING_SIG);
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
        il.append(new INVOKESTATIC(stringF));
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
     * Translates a reference into an object of internal type <code>type</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
     * @see     com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
    public void translateTo(ClassGenerator classGen, MethodGenerator methodGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
                            RealType type) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
        final ConstantPoolGen cpg = classGen.getConstantPool();
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
        final InstructionList il = methodGen.getInstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
        il.append(methodGen.loadDOM());
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
        int index = cpg.addMethodref(BASIS_LIBRARY_CLASS, "numberF",
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
                                     "("
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
                                     + OBJECT_SIG
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
                                     + DOM_INTF_SIG
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
                                     + ")D");
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
        il.append(new INVOKESTATIC(index));
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
     * Translates a reference to an object of internal type <code>type</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
     * @see     com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
    public void translateTo(ClassGenerator classGen, MethodGenerator methodGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
                            BooleanType type) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
        final ConstantPoolGen cpg = classGen.getConstantPool();
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
        final InstructionList il = methodGen.getInstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
        int index = cpg.addMethodref(BASIS_LIBRARY_CLASS, "booleanF",
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
                                     "("
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
                                     + OBJECT_SIG
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
                                     + ")Z");
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
        il.append(new INVOKESTATIC(index));
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
     * Casts a reference into a NodeIterator.
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
     * @see     com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
    public void translateTo(ClassGenerator classGen, MethodGenerator methodGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
                            NodeSetType type) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
        final ConstantPoolGen cpg = classGen.getConstantPool();
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
        final InstructionList il = methodGen.getInstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
        int index = cpg.addMethodref(BASIS_LIBRARY_CLASS, "referenceToNodeSet",
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
                                     "("
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
                                     + OBJECT_SIG
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
                                     + ")"
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
                                     + NODE_ITERATOR_SIG);
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
        il.append(new INVOKESTATIC(index));
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
        // Reset this iterator
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
        index = cpg.addInterfaceMethodref(NODE_ITERATOR, RESET, RESET_SIG);
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
        il.append(new INVOKEINTERFACE(index, 1));
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
     * Casts a reference into a Node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
     * @see com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
    public void translateTo(ClassGenerator classGen, MethodGenerator methodGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
                            NodeType type) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
        translateTo(classGen, methodGen, Type.NodeSet);
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
        Type.NodeSet.translateTo(classGen, methodGen, type);
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
     * Casts a reference into a ResultTree.
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
     * @see     com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
    public void translateTo(ClassGenerator classGen, MethodGenerator methodGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
                            ResultTreeType type) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
        final ConstantPoolGen cpg = classGen.getConstantPool();
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
        final InstructionList il = methodGen.getInstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
        int index = cpg.addMethodref(BASIS_LIBRARY_CLASS, "referenceToResultTree",
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
                                     "(" + OBJECT_SIG + ")" + DOM_INTF_SIG);
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
        il.append(new INVOKESTATIC(index));
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
     * Subsume reference into ObjectType.
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
     * @see     com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
    public void translateTo(ClassGenerator classGen, MethodGenerator methodGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
                            ObjectType type) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
        methodGen.getInstructionList().append(NOP);
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
     * Translates a reference into the Java type denoted by <code>clazz</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
    public void translateTo(ClassGenerator classGen, MethodGenerator methodGen,
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   225
                            Class<?> clazz) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
        final ConstantPoolGen cpg = classGen.getConstantPool();
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
        final InstructionList il = methodGen.getInstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
        int referenceToLong = cpg.addMethodref(BASIS_LIBRARY_CLASS,
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
                                               "referenceToLong",
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
                                               "(" + OBJECT_SIG + ")J");
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
        int referenceToDouble = cpg.addMethodref(BASIS_LIBRARY_CLASS,
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
                                                 "referenceToDouble",
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
                                                "(" + OBJECT_SIG + ")D");
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
        int referenceToBoolean = cpg.addMethodref(BASIS_LIBRARY_CLASS,
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
                                                  "referenceToBoolean",
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
                                                 "(" + OBJECT_SIG + ")Z");
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
        if (clazz.getName().equals("java.lang.Object")) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
            il.append(NOP);
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
        else if (clazz == Double.TYPE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
            il.append(new INVOKESTATIC(referenceToDouble));
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
        else if (clazz.getName().equals("java.lang.Double")) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
            il.append(new INVOKESTATIC(referenceToDouble));
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
            Type.Real.translateTo(classGen, methodGen, Type.Reference);
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
        else if (clazz == Float.TYPE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
            il.append(new INVOKESTATIC(referenceToDouble));
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
            il.append(D2F);
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
        else if (clazz.getName().equals("java.lang.String")) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
            int index = cpg.addMethodref(BASIS_LIBRARY_CLASS, "referenceToString",
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
                                         "("
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
                                         + OBJECT_SIG
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
                                         + DOM_INTF_SIG
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
                                         + ")"
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
                                         + "Ljava/lang/String;");
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
            il.append(methodGen.loadDOM());
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
            il.append(new INVOKESTATIC(index));
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
        else if (clazz.getName().equals("org.w3c.dom.Node")) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
            int index = cpg.addMethodref(BASIS_LIBRARY_CLASS, "referenceToNode",
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
                                         "("
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
                                         + OBJECT_SIG
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
                                         + DOM_INTF_SIG
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
                                         + ")"
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
                                         + "Lorg/w3c/dom/Node;");
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
            il.append(methodGen.loadDOM());
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
            il.append(new INVOKESTATIC(index));
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
        else if (clazz.getName().equals("org.w3c.dom.NodeList")) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
            int index = cpg.addMethodref(BASIS_LIBRARY_CLASS, "referenceToNodeList",
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
                                         "("
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
                                         + OBJECT_SIG
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
                                         + DOM_INTF_SIG
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
                                         + ")"
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
                                         + "Lorg/w3c/dom/NodeList;");
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
            il.append(methodGen.loadDOM());
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
            il.append(new INVOKESTATIC(index));
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
        else if (clazz.getName().equals("com.sun.org.apache.xalan.internal.xsltc.DOM")) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
            translateTo(classGen, methodGen, Type.ResultTree);
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
        else if (clazz == Long.TYPE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
            il.append(new INVOKESTATIC(referenceToLong));
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
        else if (clazz == Integer.TYPE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
            il.append(new INVOKESTATIC(referenceToLong));
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
            il.append(L2I);
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
        else if (clazz == Short.TYPE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
            il.append(new INVOKESTATIC(referenceToLong));
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
            il.append(L2I);
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
            il.append(I2S);
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
        else if (clazz == Byte.TYPE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
            il.append(new INVOKESTATIC(referenceToLong));
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
            il.append(L2I);
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
            il.append(I2B);
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
        else if (clazz == Character.TYPE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
            il.append(new INVOKESTATIC(referenceToLong));
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
            il.append(L2I);
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
            il.append(I2C);
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
        else if (clazz == java.lang.Boolean.TYPE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
            il.append(new INVOKESTATIC(referenceToBoolean));
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   311
        else if (clazz.getName().equals("java.lang.Boolean")) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   312
            il.append(new INVOKESTATIC(referenceToBoolean));
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
            Type.Boolean.translateTo(classGen, methodGen, Type.Reference);
7f561c08de6b Initial load
duke
parents:
diff changeset
   314
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   315
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   316
            ErrorMsg err = new ErrorMsg(ErrorMsg.DATA_CONVERSION_ERR,
7f561c08de6b Initial load
duke
parents:
diff changeset
   317
                                        toString(), clazz.getName());
7f561c08de6b Initial load
duke
parents:
diff changeset
   318
            classGen.getParser().reportError(Constants.FATAL, err);
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   321
7f561c08de6b Initial load
duke
parents:
diff changeset
   322
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
     * Translates an external Java type into a reference. Only conversion
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
     * allowed is from java.lang.Object.
7f561c08de6b Initial load
duke
parents:
diff changeset
   325
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   326
    public void translateFrom(ClassGenerator classGen, MethodGenerator methodGen,
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   327
                              Class<?> clazz) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   328
        if (clazz.getName().equals("java.lang.Object")) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   329
            methodGen.getInstructionList().append(NOP);
7f561c08de6b Initial load
duke
parents:
diff changeset
   330
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   331
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   332
            ErrorMsg err = new ErrorMsg(ErrorMsg.DATA_CONVERSION_ERR,
7f561c08de6b Initial load
duke
parents:
diff changeset
   333
                                toString(), clazz.getName());
7f561c08de6b Initial load
duke
parents:
diff changeset
   334
            classGen.getParser().reportError(Constants.FATAL, err);
7f561c08de6b Initial load
duke
parents:
diff changeset
   335
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   336
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   337
7f561c08de6b Initial load
duke
parents:
diff changeset
   338
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   339
     * Expects a reference on the stack and translates it to a non-synthesized
7f561c08de6b Initial load
duke
parents:
diff changeset
   340
     * boolean. It does not push a 0 or a 1 but instead returns branchhandle
7f561c08de6b Initial load
duke
parents:
diff changeset
   341
     * list to be appended to the false list.
7f561c08de6b Initial load
duke
parents:
diff changeset
   342
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   343
     * @see com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateToDesynthesized
7f561c08de6b Initial load
duke
parents:
diff changeset
   344
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   345
    public FlowList translateToDesynthesized(ClassGenerator classGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   346
                                             MethodGenerator methodGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   347
                                             BooleanType type) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   348
        InstructionList il = methodGen.getInstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
   349
        translateTo(classGen, methodGen, type);
7f561c08de6b Initial load
duke
parents:
diff changeset
   350
        return new FlowList(il.append(new IFEQ(null)));
7f561c08de6b Initial load
duke
parents:
diff changeset
   351
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   352
7f561c08de6b Initial load
duke
parents:
diff changeset
   353
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   354
     * Translates an object of this type to its boxed representation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   355
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   356
    public void translateBox(ClassGenerator classGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   357
                             MethodGenerator methodGen) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   358
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   359
7f561c08de6b Initial load
duke
parents:
diff changeset
   360
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   361
     * Translates an object of this type to its unboxed representation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   362
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   363
    public void translateUnBox(ClassGenerator classGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   364
                               MethodGenerator methodGen) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   365
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   366
7f561c08de6b Initial load
duke
parents:
diff changeset
   367
7f561c08de6b Initial load
duke
parents:
diff changeset
   368
    public Instruction LOAD(int slot) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   369
        return new ALOAD(slot);
7f561c08de6b Initial load
duke
parents:
diff changeset
   370
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   371
7f561c08de6b Initial load
duke
parents:
diff changeset
   372
    public Instruction STORE(int slot) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   373
        return new ASTORE(slot);
7f561c08de6b Initial load
duke
parents:
diff changeset
   374
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   375
}