src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/util/NodeSetType.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.BranchHandle;
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
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.IFLT;
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE;
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
import com.sun.org.apache.bcel.internal.generic.INVOKESTATIC;
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
import com.sun.org.apache.bcel.internal.generic.Instruction;
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
import com.sun.org.apache.bcel.internal.generic.InstructionList;
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
import com.sun.org.apache.bcel.internal.generic.PUSH;
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
import com.sun.org.apache.xalan.internal.xsltc.compiler.Constants;
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
import com.sun.org.apache.xalan.internal.xsltc.compiler.FlowList;
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
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
public final class NodeSetType extends Type {
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
    protected NodeSetType() {}
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
    public String toString() {
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
        return "node-set";
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
    public boolean identicalTo(Type other) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
        return this == other;
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 String toSignature() {
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
        return NODE_ITERATOR_SIG;
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 com.sun.org.apache.bcel.internal.generic.Type toJCType() {
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
        return new com.sun.org.apache.bcel.internal.generic.ObjectType(NODE_ITERATOR);
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
     * Translates a node-set into an object of internal type
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
     * <code>type</code>. The translation to int is undefined
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
     * since node-sets are always converted to
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
     * 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.Boolean) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
            translateTo(classGen, methodGen, (BooleanType) type);
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
        else if (type == Type.Real) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
            translateTo(classGen, methodGen, (RealType) type);
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
        else if (type == Type.Node) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
            translateTo(classGen, methodGen, (NodeType) type);
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
        else if (type == Type.Reference) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
            translateTo(classGen, methodGen, (ReferenceType) type);
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
        else if (type == Type.Object) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
            translateTo(classGen, methodGen, (ObjectType) type);
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
            ErrorMsg err = new ErrorMsg(ErrorMsg.DATA_CONVERSION_ERR,
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
                                        toString(), type.toString());
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
            classGen.getParser().reportError(Constants.FATAL, err);
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
     * Translates an external Java Class into an internal type.
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
     * Expects the Java object on the stack, pushes the internal type
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
    public void translateFrom(ClassGenerator classGen,
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   101
        MethodGenerator methodGen, Class<?> clazz)
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
        InstructionList il = methodGen.getInstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
        ConstantPoolGen cpg = classGen.getConstantPool();
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
        if (clazz.getName().equals("org.w3c.dom.NodeList")) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
           // w3c NodeList is on the stack from the external Java function call.
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
           // call BasisFunction to consume NodeList and leave Iterator on
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
           //    the stack.
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
           il.append(classGen.loadTranslet());   // push translet onto stack
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
           il.append(methodGen.loadDOM());       // push DOM onto stack
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
           final int convert = cpg.addMethodref(BASIS_LIBRARY_CLASS,
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
                                        "nodeList2Iterator",
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
                                        "("
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
                                         + "Lorg/w3c/dom/NodeList;"
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
                                         + TRANSLET_INTF_SIG
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
                                         + DOM_INTF_SIG
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
                                         + ")" + NODE_ITERATOR_SIG );
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
           il.append(new INVOKESTATIC(convert));
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
        else if (clazz.getName().equals("org.w3c.dom.Node")) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
           // w3c Node is on the stack from the external Java function call.
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
           // call BasisLibrary.node2Iterator() to consume Node and leave
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
           // Iterator on the stack.
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
           il.append(classGen.loadTranslet());   // push translet onto stack
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
           il.append(methodGen.loadDOM());       // push DOM onto stack
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
           final int convert = cpg.addMethodref(BASIS_LIBRARY_CLASS,
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
                                        "node2Iterator",
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
                                        "("
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
                                         + "Lorg/w3c/dom/Node;"
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
                                         + TRANSLET_INTF_SIG
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
                                         + DOM_INTF_SIG
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
                                         + ")" + NODE_ITERATOR_SIG );
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
           il.append(new INVOKESTATIC(convert));
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
            ErrorMsg err = new ErrorMsg(ErrorMsg.DATA_CONVERSION_ERR,
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
                toString(), clazz.getName());
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
            classGen.getParser().reportError(Constants.FATAL, err);
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
     * Translates a node-set into a synthesized boolean.
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
     * The boolean value of a node-set is "true" if non-empty
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
     * and "false" otherwise. Notice that the
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
     * function getFirstNode() is called in translateToDesynthesized().
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
     * @see     com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
    public void translateTo(ClassGenerator classGen, MethodGenerator methodGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
                            BooleanType type) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
        final InstructionList il = methodGen.getInstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
        FlowList falsel = translateToDesynthesized(classGen, methodGen, type);
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
        il.append(ICONST_1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
        final BranchHandle truec = il.append(new GOTO(null));
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
        falsel.backPatch(il.append(ICONST_0));
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
        truec.setTarget(il.append(NOP));
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
     * Translates a node-set into a string. The string value of a node-set is
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
     * value of its first element.
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
     * @see     com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
    public void translateTo(ClassGenerator classGen, MethodGenerator methodGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
                            StringType type) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
        final InstructionList il = methodGen.getInstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
        getFirstNode(classGen, methodGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
        il.append(DUP);
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
        final BranchHandle falsec = il.append(new IFLT(null));
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
        Type.Node.translateTo(classGen, methodGen, type);
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
        final BranchHandle truec = il.append(new GOTO(null));
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
        falsec.setTarget(il.append(POP));
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
        il.append(new PUSH(classGen.getConstantPool(), ""));
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
        truec.setTarget(il.append(NOP));
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
     * Expects a node-set on the stack and pushes a real.
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
     * First the node-set is converted to string, and from string to real.
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
     * @see     com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
    public void translateTo(ClassGenerator classGen, MethodGenerator methodGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
                            RealType type) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
        translateTo(classGen, methodGen, Type.String);
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
        Type.String.translateTo(classGen, methodGen, Type.Real);
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
     * Expects a node-set on the stack and pushes a node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
     * @see     com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
    public void translateTo(ClassGenerator classGen, MethodGenerator methodGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
                            NodeType type) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
        getFirstNode(classGen, methodGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
     * Subsume node-set into ObjectType.
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
     * @see     com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
    public void translateTo(ClassGenerator classGen, MethodGenerator methodGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
                            ObjectType type) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
            methodGen.getInstructionList().append(NOP);
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
     * Translates a node-set into a non-synthesized boolean. It does not
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
     * push a 0 or a 1 but instead returns branchhandle list to be appended
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
     * to the false list.
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
     * @see     com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateToDesynthesized
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
    public FlowList translateToDesynthesized(ClassGenerator classGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
                                             MethodGenerator methodGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
                                             BooleanType type) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
        final InstructionList il = methodGen.getInstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
        getFirstNode(classGen, methodGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
        return new FlowList(il.append(new IFLT(null)));
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
     * Expects a node-set on the stack and pushes a boxed node-set.
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
     * Node sets are already boxed so the translation is just a NOP.
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
     * @see     com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
    public void translateTo(ClassGenerator classGen, MethodGenerator methodGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
                            ReferenceType type) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
        methodGen.getInstructionList().append(NOP);
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
     * Translates a node-set into the Java type denoted by <code>clazz</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
     * Expects a node-set on the stack and pushes an object of the appropriate
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
     * type after coercion.
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
    public void translateTo(ClassGenerator classGen, MethodGenerator methodGen,
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   245
                            Class<?> clazz) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
        final ConstantPoolGen cpg = classGen.getConstantPool();
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
        final InstructionList il = methodGen.getInstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
        final String className = clazz.getName();
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
        il.append(methodGen.loadDOM());
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
        il.append(SWAP);
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
        if (className.equals("org.w3c.dom.Node")) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
            int index = cpg.addInterfaceMethodref(DOM_INTF,
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
                                                  MAKE_NODE,
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
                                                  MAKE_NODE_SIG2);
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
            il.append(new INVOKEINTERFACE(index, 2));
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
        else if (className.equals("org.w3c.dom.NodeList") ||
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
                 className.equals("java.lang.Object")) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
            int index = cpg.addInterfaceMethodref(DOM_INTF,
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
                                                  MAKE_NODE_LIST,
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
                                                  MAKE_NODE_LIST_SIG2);
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
            il.append(new INVOKEINTERFACE(index, 2));
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
        else if (className.equals("java.lang.String")) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
            int next = cpg.addInterfaceMethodref(NODE_ITERATOR,
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
                                                 "next", "()I");
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
            int index = cpg.addInterfaceMethodref(DOM_INTF,
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
                                                 GET_NODE_VALUE,
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
                                                 "(I)"+STRING_SIG);
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
            // Get next node from the iterator
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
            il.append(new INVOKEINTERFACE(next, 1));
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
            // Get the node's string value (from the DOM)
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
            il.append(new INVOKEINTERFACE(index, 2));
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
            ErrorMsg err = new ErrorMsg(ErrorMsg.DATA_CONVERSION_ERR,
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
                                        toString(), className);
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
            classGen.getParser().reportError(Constants.FATAL, err);
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
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
     * Some type conversions require gettting the first node from the node-set.
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
     * This function is defined to avoid code repetition.
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
    private void getFirstNode(ClassGenerator classGen, MethodGenerator methodGen) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
        final ConstantPoolGen cpg = classGen.getConstantPool();
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
        final InstructionList il = methodGen.getInstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
        il.append(new INVOKEINTERFACE(cpg.addInterfaceMethodref(NODE_ITERATOR,
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
                                                                NEXT,
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
                                                                NEXT_SIG), 1));
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
     * Translates an object of this type to its boxed representation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
    public void translateBox(ClassGenerator classGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
                             MethodGenerator methodGen) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
        translateTo(classGen, methodGen, Type.Reference);
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
     * Translates an object of this type to its unboxed representation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
    public void translateUnBox(ClassGenerator classGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
                               MethodGenerator methodGen) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   311
        methodGen.getInstructionList().append(NOP);
7f561c08de6b Initial load
duke
parents:
diff changeset
   312
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
7f561c08de6b Initial load
duke
parents:
diff changeset
   314
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   315
     * Returns the class name of an internal type's external representation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   316
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   317
    public String getClassName() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   318
        return(NODE_ITERATOR);
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
    public Instruction LOAD(int slot) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
        return new ALOAD(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 ASTORE(slot);
7f561c08de6b Initial load
duke
parents:
diff changeset
   328
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   329
}