src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/Key.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
/*
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
     6
 * Licensed to the Apache Software Foundation (ASF) under one or more
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
     7
 * contributor license agreements.  See the NOTICE file distributed with
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
     8
 * this work for additional information regarding copyright ownership.
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
     9
 * The ASF licenses this file to You under the Apache License, Version 2.0
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    10
 * (the "License"); you may not use this file except in compliance with
975138b77cff 8068842: Better JAXP data handling
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
 *
33349
975138b77cff 8068842: Better JAXP data handling
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
 * $Id: Key.java,v 1.6 2006/04/25 02:25:08 jeffsuttor Exp $
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
package com.sun.org.apache.xalan.internal.xsltc.compiler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
import com.sun.org.apache.bcel.internal.generic.BranchHandle;
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
import com.sun.org.apache.bcel.internal.generic.GOTO;
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
import com.sun.org.apache.bcel.internal.generic.IFEQ;
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
import com.sun.org.apache.bcel.internal.generic.IFGE;
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
import com.sun.org.apache.bcel.internal.generic.IFGT;
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
import com.sun.org.apache.bcel.internal.generic.ILOAD;
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE;
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL;
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
import com.sun.org.apache.bcel.internal.generic.ISTORE;
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
import com.sun.org.apache.bcel.internal.generic.InstructionHandle;
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
import com.sun.org.apache.bcel.internal.generic.InstructionList;
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
import com.sun.org.apache.bcel.internal.generic.LocalVariableGen;
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
import com.sun.org.apache.bcel.internal.generic.PUSH;
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.NodeSetType;
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.StringType;
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util;
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
import com.sun.org.apache.xml.internal.dtm.Axis;
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
import com.sun.org.apache.xml.internal.utils.XML11Char;
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
 * @author Morten Jorgensen
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
 * @author Santiago Pericas-Geertsen
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
final class Key extends TopLevelElement {
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
     * The name of this key as defined in xsl:key.
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
    private QName _name;
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
     * The pattern to match starting at the root node.
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
    private Pattern _match;
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
     * The expression that generates the values for this key.
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
    private Expression _use;
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
     * The type of the _use expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
    private Type _useType;
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
     * Parse the <xsl:key> element and attributes
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
     * @param parser A reference to the stylesheet parser
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
    public void parseContents(Parser parser) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
        // Get the required attributes and parser XPath expressions
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
        final String name = getAttribute("name");
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
        if (!XML11Char.isXML11ValidQName(name)){
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
            ErrorMsg err = new ErrorMsg(ErrorMsg.INVALID_QNAME_ERR, name, this);
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
            parser.reportError(Constants.ERROR, err);
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
        // Parse key name and add to symbol table
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
        _name = parser.getQNameIgnoreDefaultNs(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
        getSymbolTable().addKey(_name, this);
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
        _match = parser.parsePattern(this, "match", null);
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
        _use = parser.parseExpression(this, "use", null);
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
        // Make sure required attribute(s) have been set
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
        if (_name == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
            reportError(this, parser, ErrorMsg.REQUIRED_ATTR_ERR, "name");
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
            return;
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
        if (_match.isDummy()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
            reportError(this, parser, ErrorMsg.REQUIRED_ATTR_ERR, "match");
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
            return;
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
        if (_use.isDummy()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
            reportError(this, parser, ErrorMsg.REQUIRED_ATTR_ERR, "use");
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
            return;
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
     * Returns a String-representation of this key's name
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
     * @return The key's name (from the <xsl:key> elements 'name' attribute).
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
    public String getName() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
        return _name.toString();
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
    public Type typeCheck(SymbolTable stable) throws TypeCheckError {
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
        // Type check match pattern
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
        _match.typeCheck(stable);
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
        // Cast node values to string values (except for nodesets)
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
        _useType = _use.typeCheck(stable);
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
        if (_useType instanceof StringType == false &&
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
            _useType instanceof NodeSetType == false)
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
            _use = new CastExpr(_use, Type.String);
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
        return Type.Void;
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
     * This method is called if the "use" attribute of the key contains a
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
     * node set. In this case we must traverse all nodes in the set and
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
     * create one entry in this key's index for each node in the set.
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
    public void traverseNodeSet(ClassGenerator classGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
                                MethodGenerator methodGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
                                int buildKeyIndex) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
        final ConstantPoolGen cpg = classGen.getConstantPool();
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
        final InstructionList il = methodGen.getInstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
        // DOM.getStringValueX(nodeIndex) => String
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
        final int getNodeValue = cpg.addInterfaceMethodref(DOM_INTF,
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
                                                           GET_NODE_VALUE,
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
                                                           "(I)"+STRING_SIG);
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
        final int getNodeIdent = cpg.addInterfaceMethodref(DOM_INTF,
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
                                                           "getNodeIdent",
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
                                                           "(I)"+NODE_SIG);
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
        // AbstractTranslet.SetKeyIndexDom(name, Dom) => void
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
        final int keyDom = cpg.addMethodref(TRANSLET_CLASS,
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
                                         "setKeyIndexDom",
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
                                         "("+STRING_SIG+DOM_INTF_SIG+")V");
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
        // This variable holds the id of the node we found with the "match"
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
        // attribute of xsl:key. This is the id we store, with the value we
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
        // get from the nodes we find here, in the index for this key.
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
        final LocalVariableGen parentNode =
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
            methodGen.addLocalVariable("parentNode",
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
                                       Util.getJCRefType("I"),
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   168
                                       null, null);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
        // Get the 'parameter' from the stack and store it in a local var.
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   171
        parentNode.setStart(il.append(new ISTORE(parentNode.getIndex())));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
        // Save current node and current iterator on the stack
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
        il.append(methodGen.loadCurrentNode());
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
        il.append(methodGen.loadIterator());
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
        // Overwrite current iterator with one that gives us only what we want
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
        _use.translate(classGen, methodGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
        _use.startIterator(classGen, methodGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
        il.append(methodGen.storeIterator());
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
        final BranchHandle nextNode = il.append(new GOTO(null));
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
        final InstructionHandle loop = il.append(NOP);
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
        // Prepare to call buildKeyIndex(String name, int node, String value);
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
        il.append(classGen.loadTranslet());
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
        il.append(new PUSH(cpg, _name.toString()));
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   188
        parentNode.setEnd(il.append(new ILOAD(parentNode.getIndex())));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   190
        // Now get the node value and push it on the parameter stack
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
        il.append(methodGen.loadDOM());
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
        il.append(methodGen.loadCurrentNode());
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
        il.append(new INVOKEINTERFACE(getNodeValue, 2));
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
        // Finally do the call to add an entry in the index for this key.
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
        il.append(new INVOKEVIRTUAL(buildKeyIndex));
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
        il.append(classGen.loadTranslet());
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
        il.append(new PUSH(cpg, getName()));
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
        il.append(methodGen.loadDOM());
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
        il.append(new INVOKEVIRTUAL(keyDom));
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
        nextNode.setTarget(il.append(methodGen.loadIterator()));
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
        il.append(methodGen.nextNode());
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
        il.append(DUP);
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
        il.append(methodGen.storeCurrentNode());
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
        il.append(new IFGE(loop)); // Go on to next matching node....
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
        // Restore current node and current iterator from the stack
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
        il.append(methodGen.storeIterator());
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
        il.append(methodGen.storeCurrentNode());
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
     * Gather all nodes that match the expression in the attribute "match"
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
     * and add one (or more) entries in this key's index.
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
    public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
        final ConstantPoolGen cpg = classGen.getConstantPool();
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
        final InstructionList il = methodGen.getInstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
        final int current = methodGen.getLocalIndex("current");
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
        // AbstractTranslet.buildKeyIndex(name,node_id,value) => void
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
        final int key = cpg.addMethodref(TRANSLET_CLASS,
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
                                         "buildKeyIndex",
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   228
                                         "("+STRING_SIG+"I"+STRING_SIG+")V");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
        // AbstractTranslet.SetKeyIndexDom(name, Dom) => void
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
        final int keyDom = cpg.addMethodref(TRANSLET_CLASS,
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
                                         "setKeyIndexDom",
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
                                         "("+STRING_SIG+DOM_INTF_SIG+")V");
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
        final int getNodeIdent = cpg.addInterfaceMethodref(DOM_INTF,
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
                                                           "getNodeIdent",
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
                                                           "(I)"+NODE_SIG);
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
        // DOM.getAxisIterator(root) => NodeIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
        final int git = cpg.addInterfaceMethodref(DOM_INTF,
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
                                                  "getAxisIterator",
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
                                                  "(I)"+NODE_ITERATOR_SIG);
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
        il.append(methodGen.loadCurrentNode());
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
        il.append(methodGen.loadIterator());
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
        // Get an iterator for all nodes in the DOM
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
        il.append(methodGen.loadDOM());
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
        il.append(new PUSH(cpg,Axis.DESCENDANT));
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
        il.append(new INVOKEINTERFACE(git, 2));
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
        // Reset the iterator to start with the root node
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
        il.append(methodGen.loadCurrentNode());
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
        il.append(methodGen.setStartNode());
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
        il.append(methodGen.storeIterator());
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
        // Loop for traversing all nodes in the DOM
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
        final BranchHandle nextNode = il.append(new GOTO(null));
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
        final InstructionHandle loop = il.append(NOP);
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
        // Check if the current node matches the pattern in "match"
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
        il.append(methodGen.loadCurrentNode());
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
        _match.translate(classGen, methodGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
        _match.synthesize(classGen, methodGen); // Leaves 0 or 1 on stack
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
        final BranchHandle skipNode = il.append(new IFEQ(null));
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
        // If this is a node-set we must go through each node in the set
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
        if (_useType instanceof NodeSetType) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
            // Pass current node as parameter (we're indexing on that node)
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
            il.append(methodGen.loadCurrentNode());
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
            traverseNodeSet(classGen, methodGen, key);
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
            il.append(classGen.loadTranslet());
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
            il.append(DUP);
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
            il.append(new PUSH(cpg, _name.toString()));
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
            il.append(DUP_X1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
            il.append(methodGen.loadCurrentNode());
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
            _use.translate(classGen, methodGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
            il.append(new INVOKEVIRTUAL(key));
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
            il.append(methodGen.loadDOM());
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
            il.append(new INVOKEVIRTUAL(keyDom));
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
        // Get the next node from the iterator and do loop again...
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
        final InstructionHandle skip = il.append(NOP);
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
        il.append(methodGen.loadIterator());
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
        il.append(methodGen.nextNode());
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
        il.append(DUP);
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
        il.append(methodGen.storeCurrentNode());
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
        il.append(new IFGT(loop));
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
        // Restore current node and current iterator from the stack
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
        il.append(methodGen.storeIterator());
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
        il.append(methodGen.storeCurrentNode());
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
        nextNode.setTarget(skip);
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
        skipNode.setTarget(skip);
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
}