src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/Sort.java
author joehw
Wed, 18 Oct 2017 13:25:49 -0700
changeset 47359 e1a6c0168741
parent 47216 71c04702a3d5
child 47712 bde0215f1f70
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) 2016, 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: 36486
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: 36486
diff changeset
     7
 * contributor license agreements.  See the NOTICE file distributed with
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 36486
diff changeset
     8
 * this work for additional information regarding copyright ownership.
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 36486
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: 36486
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: 36486
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: 36486
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;
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
import com.sun.org.apache.bcel.internal.classfile.Field;
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
import com.sun.org.apache.bcel.internal.generic.ALOAD;
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
import com.sun.org.apache.bcel.internal.generic.ANEWARRAY;
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
import com.sun.org.apache.bcel.internal.generic.ASTORE;
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
import com.sun.org.apache.bcel.internal.generic.CHECKCAST;
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
import com.sun.org.apache.bcel.internal.generic.GETFIELD;
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
import com.sun.org.apache.bcel.internal.generic.ILOAD;
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE;
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
import com.sun.org.apache.bcel.internal.generic.INVOKESPECIAL;
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
import com.sun.org.apache.bcel.internal.generic.InstructionHandle;
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
import com.sun.org.apache.bcel.internal.generic.InstructionList;
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
import com.sun.org.apache.bcel.internal.generic.LocalVariableGen;
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
import com.sun.org.apache.bcel.internal.generic.NEW;
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
import com.sun.org.apache.bcel.internal.generic.NOP;
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
import com.sun.org.apache.bcel.internal.generic.PUSH;
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
import com.sun.org.apache.bcel.internal.generic.PUTFIELD;
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
import com.sun.org.apache.bcel.internal.generic.TABLESWITCH;
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.CompareGenerator;
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.IntType;
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.NodeSortRecordFactGenerator;
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.NodeSortRecordGenerator;
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.StringType;
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util;
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
import com.sun.org.apache.xml.internal.dtm.Axis;
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    54
import java.util.ArrayList;
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    55
import java.util.List;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
 * @author Jacek Ambroziak
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
 * @author Santiago Pericas-Geertsen
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
 * @author Morten Jorgensen
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
final class Sort extends Instruction implements Closure {
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
    private Expression     _select;
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
    private AttributeValue _order;
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
    private AttributeValue _caseOrder;
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
    private AttributeValue _dataType;
36486
b84e564d2358 8150704: XALAN: ERROR: 'No more DTM IDs are available' when transforming with lots of temporary result trees
joehw
parents: 25868
diff changeset
    69
    private String         _lang; // bug! see 26869
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
    private String _className = null;
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    72
    private List<VariableRefBase> _closureVars = null;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
    private boolean _needsSortRecordFactory = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
    // -- Begin Closure interface --------------------
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
     * Returns true if this closure is compiled in an inner class (i.e.
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
     * if this is a real closure).
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
    public boolean inInnerClass() {
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
        return (_className != null);
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
     * Returns a reference to its parent closure or null if outermost.
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
    public Closure getParentClosure() {
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
        return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
     * Returns the name of the auxiliary class or null if this predicate
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
     * is compiled inside the Translet.
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
    public String getInnerClassName() {
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
        return _className;
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
     * Add new variable to the closure.
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
    public void addVariable(VariableRefBase variableRef) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
        if (_closureVars == null) {
36486
b84e564d2358 8150704: XALAN: ERROR: 'No more DTM IDs are available' when transforming with lots of temporary result trees
joehw
parents: 25868
diff changeset
   105
            _closureVars = new ArrayList<>();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
        // Only one reference per variable
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
        if (!_closureVars.contains(variableRef)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
            _closureVars.add(variableRef);
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
            _needsSortRecordFactory = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
    // -- End Closure interface ----------------------
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
    private void setInnerClassName(String className) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
        _className = className;
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
     * Parse the attributes of the xsl:sort element
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
    public void parseContents(Parser parser) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
        final SyntaxTreeNode parent = getParent();
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
        if (!(parent instanceof ApplyTemplates) &&
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
            !(parent instanceof ForEach)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
            reportError(this, parser, ErrorMsg.STRAY_SORT_ERR, null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
            return;
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
        // Parse the select expression (node string value if no expression)
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
        _select = parser.parseExpression(this, "select", "string(.)");
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
        // Get the sort order; default is 'ascending'
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
        String val = getAttribute("order");
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
        if (val.length() == 0) val = "ascending";
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
        _order = AttributeValue.create(this, val, parser);
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
        // Get the sort data type; default is text
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
        val = getAttribute("data-type");
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
        if (val.length() == 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
            try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
                final Type type = _select.typeCheck(parser.getSymbolTable());
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
                if (type instanceof IntType)
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
                    val = "number";
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
                else
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
                    val = "text";
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
            catch (TypeCheckError e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
                val = "text";
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
        _dataType = AttributeValue.create(this, val, parser);
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
         _lang =  getAttribute("lang"); // bug! see 26869
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
  // val =  getAttribute("lang");
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
  // _lang = AttributeValue.create(this, val, parser);
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
        // Get the case order; default is language dependant
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
    val = getAttribute("case-order");
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
    _caseOrder = AttributeValue.create(this, val, parser);
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
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
     * Run type checks on the attributes; expression must return a string
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
     * which we will use as a sort key
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
    public Type typeCheck(SymbolTable stable) throws TypeCheckError {
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
        final Type tselect = _select.typeCheck(stable);
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
        // If the sort data-type is not set we use the natural data-type
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
        // of the data we will sort
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
        if (!(tselect instanceof StringType)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
            _select = new CastExpr(_select, Type.String);
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
        _order.typeCheck(stable);
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
        _caseOrder.typeCheck(stable);
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
        _dataType.typeCheck(stable);
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
        return Type.Void;
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
     * These two methods are needed in the static methods that compile the
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
     * overloaded NodeSortRecord.compareType() and NodeSortRecord.sortOrder()
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
    public void translateSortType(ClassGenerator classGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
                                  MethodGenerator methodGen) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
        _dataType.translate(classGen, methodGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
    public void translateSortOrder(ClassGenerator classGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
                                   MethodGenerator methodGen) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
        _order.translate(classGen, methodGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
     public void translateCaseOrder(ClassGenerator classGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
                   MethodGenerator methodGen) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
    _caseOrder.translate(classGen, methodGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
    public void translateLang(ClassGenerator classGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
                   MethodGenerator methodGen) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
    final ConstantPoolGen cpg = classGen.getConstantPool();
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
    final InstructionList il = methodGen.getInstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
    il.append(new PUSH(cpg, _lang)); // bug! see 26869
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
     * This method compiles code for the select expression for this
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
     * xsl:sort element. The method is called from the static code-generating
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
     * methods in this class.
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
    public void translateSelect(ClassGenerator classGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
                                MethodGenerator methodGen) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
        _select.translate(classGen,methodGen);
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
     * This method should not produce any code
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
    public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
        // empty
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
     * Compiles code that instantiates a SortingIterator object.
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
     * This object's constructor needs referencdes to the current iterator
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
     * and a node sort record producing objects as its parameters.
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
    public static void translateSortIterator(ClassGenerator classGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
                                      MethodGenerator methodGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
                                      Expression nodeSet,
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   236
                                      List<Sort> sortObjects)
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
        final ConstantPoolGen cpg = classGen.getConstantPool();
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
        final InstructionList il = methodGen.getInstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
        // SortingIterator.SortingIterator(NodeIterator,NodeSortRecordFactory);
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
        final int init = cpg.addMethodref(SORT_ITERATOR, "<init>",
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
                                          "("
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
                                          + NODE_ITERATOR_SIG
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
                                          + NODE_SORT_FACTORY_SIG
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
                                          + ")V");
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
        // Backwards branches are prohibited if an uninitialized object is
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
        // on the stack by section 4.9.4 of the JVM Specification, 2nd Ed.
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
        // We don't know whether this code might contain backwards branches
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
        // so we mustn't create the new object until after we've created
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
        // the suspect arguments to its constructor.  Instead we calculate
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
        // the values of the arguments to the constructor first, store them
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
        // in temporary variables, create the object and reload the
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
        // arguments from the temporaries to avoid the problem.
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
        LocalVariableGen nodesTemp =
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
            methodGen.addLocalVariable("sort_tmp1",
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
                                       Util.getJCRefType(NODE_ITERATOR_SIG),
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   260
                                       null, null);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
        LocalVariableGen sortRecordFactoryTemp =
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
            methodGen.addLocalVariable("sort_tmp2",
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
                                      Util.getJCRefType(NODE_SORT_FACTORY_SIG),
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   265
                                      null, null);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
        // Get the current node iterator
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
        if (nodeSet == null) {  // apply-templates default
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
            final int children = cpg.addInterfaceMethodref(DOM_INTF,
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
                                                           "getAxisIterator",
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
                                                           "(I)"+
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
                                                           NODE_ITERATOR_SIG);
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
            il.append(methodGen.loadDOM());
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
            il.append(new PUSH(cpg, Axis.CHILD));
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
            il.append(new INVOKEINTERFACE(children, 2));
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
            nodeSet.translate(classGen, methodGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   281
        nodesTemp.setStart(il.append(new ASTORE(nodesTemp.getIndex())));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
        // Compile the code for the NodeSortRecord producing class and pass
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
        // that as the last argument to the SortingIterator constructor.
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
        compileSortRecordFactory(sortObjects, classGen, methodGen);
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   286
        sortRecordFactoryTemp.setStart(
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   287
                il.append(new ASTORE(sortRecordFactoryTemp.getIndex())));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
        il.append(new NEW(cpg.addClass(SORT_ITERATOR)));
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
        il.append(DUP);
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   291
        nodesTemp.setEnd(il.append(new ALOAD(nodesTemp.getIndex())));
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   292
        sortRecordFactoryTemp.setEnd(
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   293
                il.append(new ALOAD(sortRecordFactoryTemp.getIndex())));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
        il.append(new INVOKESPECIAL(init));
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
    }
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
     * Compiles code that instantiates a NodeSortRecordFactory object which
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
     * will produce NodeSortRecord objects of a specific type.
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
     */
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   302
    public static void compileSortRecordFactory(List<Sort> sortObjects,
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
        ClassGenerator classGen, MethodGenerator methodGen)
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
        String sortRecordClass =
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
            compileSortRecord(sortObjects, classGen, methodGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
        boolean needsSortRecordFactory = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
        final int nsorts = sortObjects.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
        for (int i = 0; i < nsorts; i++) {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   311
            final Sort sort = sortObjects.get(i);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   312
            needsSortRecordFactory |= sort._needsSortRecordFactory;
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   314
7f561c08de6b Initial load
duke
parents:
diff changeset
   315
        String sortRecordFactoryClass = NODE_SORT_FACTORY;
7f561c08de6b Initial load
duke
parents:
diff changeset
   316
        if (needsSortRecordFactory) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   317
            sortRecordFactoryClass =
7f561c08de6b Initial load
duke
parents:
diff changeset
   318
                compileSortRecordFactory(sortObjects, classGen, methodGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
                    sortRecordClass);
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   321
7f561c08de6b Initial load
duke
parents:
diff changeset
   322
        final ConstantPoolGen cpg = classGen.getConstantPool();
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
        final InstructionList il = methodGen.getInstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
7f561c08de6b Initial load
duke
parents:
diff changeset
   325
        // Backwards branches are prohibited if an uninitialized object is
7f561c08de6b Initial load
duke
parents:
diff changeset
   326
        // on the stack by section 4.9.4 of the JVM Specification, 2nd Ed.
7f561c08de6b Initial load
duke
parents:
diff changeset
   327
        // We don't know whether this code might contain backwards branches
7f561c08de6b Initial load
duke
parents:
diff changeset
   328
        // so we mustn't create the new object until after we've created
7f561c08de6b Initial load
duke
parents:
diff changeset
   329
        // the suspect arguments to its constructor.  Instead we calculate
7f561c08de6b Initial load
duke
parents:
diff changeset
   330
        // the values of the arguments to the constructor first, store them
7f561c08de6b Initial load
duke
parents:
diff changeset
   331
        // in temporary variables, create the object and reload the
7f561c08de6b Initial load
duke
parents:
diff changeset
   332
        // arguments from the temporaries to avoid the problem.
7f561c08de6b Initial load
duke
parents:
diff changeset
   333
7f561c08de6b Initial load
duke
parents:
diff changeset
   334
        // Compile code that initializes the static _sortOrder
7f561c08de6b Initial load
duke
parents:
diff changeset
   335
        LocalVariableGen sortOrderTemp
7f561c08de6b Initial load
duke
parents:
diff changeset
   336
                 = methodGen.addLocalVariable("sort_order_tmp",
7f561c08de6b Initial load
duke
parents:
diff changeset
   337
                                      Util.getJCRefType("[" + STRING_SIG),
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   338
                                      null, null);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   339
        il.append(new PUSH(cpg, nsorts));
7f561c08de6b Initial load
duke
parents:
diff changeset
   340
        il.append(new ANEWARRAY(cpg.addClass(STRING)));
7f561c08de6b Initial load
duke
parents:
diff changeset
   341
        for (int level = 0; level < nsorts; level++) {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   342
            final Sort sort = sortObjects.get(level);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   343
            il.append(DUP);
7f561c08de6b Initial load
duke
parents:
diff changeset
   344
            il.append(new PUSH(cpg, level));
7f561c08de6b Initial load
duke
parents:
diff changeset
   345
            sort.translateSortOrder(classGen, methodGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   346
            il.append(AASTORE);
7f561c08de6b Initial load
duke
parents:
diff changeset
   347
        }
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   348
        sortOrderTemp.setStart(il.append(new ASTORE(sortOrderTemp.getIndex())));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   349
7f561c08de6b Initial load
duke
parents:
diff changeset
   350
        LocalVariableGen sortTypeTemp
7f561c08de6b Initial load
duke
parents:
diff changeset
   351
                 = methodGen.addLocalVariable("sort_type_tmp",
7f561c08de6b Initial load
duke
parents:
diff changeset
   352
                                      Util.getJCRefType("[" + STRING_SIG),
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   353
                                      null, null);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   354
        il.append(new PUSH(cpg, nsorts));
7f561c08de6b Initial load
duke
parents:
diff changeset
   355
        il.append(new ANEWARRAY(cpg.addClass(STRING)));
7f561c08de6b Initial load
duke
parents:
diff changeset
   356
        for (int level = 0; level < nsorts; level++) {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   357
            final Sort sort = sortObjects.get(level);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   358
            il.append(DUP);
7f561c08de6b Initial load
duke
parents:
diff changeset
   359
            il.append(new PUSH(cpg, level));
7f561c08de6b Initial load
duke
parents:
diff changeset
   360
            sort.translateSortType(classGen, methodGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   361
            il.append(AASTORE);
7f561c08de6b Initial load
duke
parents:
diff changeset
   362
        }
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   363
        sortTypeTemp.setStart(il.append(new ASTORE(sortTypeTemp.getIndex())));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   364
7f561c08de6b Initial load
duke
parents:
diff changeset
   365
        LocalVariableGen sortLangTemp
7f561c08de6b Initial load
duke
parents:
diff changeset
   366
                 = methodGen.addLocalVariable("sort_lang_tmp",
7f561c08de6b Initial load
duke
parents:
diff changeset
   367
                                      Util.getJCRefType("[" + STRING_SIG),
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   368
                                      null, null);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   369
        il.append(new PUSH(cpg, nsorts));
7f561c08de6b Initial load
duke
parents:
diff changeset
   370
        il.append(new ANEWARRAY(cpg.addClass(STRING)));
7f561c08de6b Initial load
duke
parents:
diff changeset
   371
        for (int level = 0; level < nsorts; level++) {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   372
              final Sort sort = sortObjects.get(level);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   373
              il.append(DUP);
7f561c08de6b Initial load
duke
parents:
diff changeset
   374
              il.append(new PUSH(cpg, level));
7f561c08de6b Initial load
duke
parents:
diff changeset
   375
              sort.translateLang(classGen, methodGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   376
              il.append(AASTORE);
7f561c08de6b Initial load
duke
parents:
diff changeset
   377
        }
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   378
        sortLangTemp.setStart(il.append(new ASTORE(sortLangTemp.getIndex())));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   379
7f561c08de6b Initial load
duke
parents:
diff changeset
   380
        LocalVariableGen sortCaseOrderTemp
7f561c08de6b Initial load
duke
parents:
diff changeset
   381
                 = methodGen.addLocalVariable("sort_case_order_tmp",
7f561c08de6b Initial load
duke
parents:
diff changeset
   382
                                      Util.getJCRefType("[" + STRING_SIG),
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   383
                                      null, null);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   384
        il.append(new PUSH(cpg, nsorts));
7f561c08de6b Initial load
duke
parents:
diff changeset
   385
        il.append(new ANEWARRAY(cpg.addClass(STRING)));
7f561c08de6b Initial load
duke
parents:
diff changeset
   386
        for (int level = 0; level < nsorts; level++) {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   387
            final Sort sort = sortObjects.get(level);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   388
            il.append(DUP);
7f561c08de6b Initial load
duke
parents:
diff changeset
   389
            il.append(new PUSH(cpg, level));
7f561c08de6b Initial load
duke
parents:
diff changeset
   390
            sort.translateCaseOrder(classGen, methodGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   391
            il.append(AASTORE);
7f561c08de6b Initial load
duke
parents:
diff changeset
   392
        }
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   393
        sortCaseOrderTemp.setStart(
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   394
                il.append(new ASTORE(sortCaseOrderTemp.getIndex())));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   395
7f561c08de6b Initial load
duke
parents:
diff changeset
   396
        il.append(new NEW(cpg.addClass(sortRecordFactoryClass)));
7f561c08de6b Initial load
duke
parents:
diff changeset
   397
        il.append(DUP);
7f561c08de6b Initial load
duke
parents:
diff changeset
   398
        il.append(methodGen.loadDOM());
7f561c08de6b Initial load
duke
parents:
diff changeset
   399
        il.append(new PUSH(cpg, sortRecordClass));
7f561c08de6b Initial load
duke
parents:
diff changeset
   400
        il.append(classGen.loadTranslet());
7f561c08de6b Initial load
duke
parents:
diff changeset
   401
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   402
        sortOrderTemp.setEnd(il.append(new ALOAD(sortOrderTemp.getIndex())));
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   403
        sortTypeTemp.setEnd(il.append(new ALOAD(sortTypeTemp.getIndex())));
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   404
        sortLangTemp.setEnd(il.append(new ALOAD(sortLangTemp.getIndex())));
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   405
        sortCaseOrderTemp.setEnd(
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   406
                il.append(new ALOAD(sortCaseOrderTemp.getIndex())));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   407
7f561c08de6b Initial load
duke
parents:
diff changeset
   408
        il.append(new INVOKESPECIAL(
7f561c08de6b Initial load
duke
parents:
diff changeset
   409
            cpg.addMethodref(sortRecordFactoryClass, "<init>",
7f561c08de6b Initial load
duke
parents:
diff changeset
   410
                "(" + DOM_INTF_SIG
7f561c08de6b Initial load
duke
parents:
diff changeset
   411
                    + STRING_SIG
7f561c08de6b Initial load
duke
parents:
diff changeset
   412
                    + TRANSLET_INTF_SIG
7f561c08de6b Initial load
duke
parents:
diff changeset
   413
                    + "[" + STRING_SIG
7f561c08de6b Initial load
duke
parents:
diff changeset
   414
                    + "[" + STRING_SIG
7f561c08de6b Initial load
duke
parents:
diff changeset
   415
                    + "[" + STRING_SIG
7f561c08de6b Initial load
duke
parents:
diff changeset
   416
                    + "[" + STRING_SIG + ")V")));
7f561c08de6b Initial load
duke
parents:
diff changeset
   417
7f561c08de6b Initial load
duke
parents:
diff changeset
   418
        // Initialize closure variables in sortRecordFactory
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   419
        final List<VariableRefBase> dups = new ArrayList<>();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   420
7f561c08de6b Initial load
duke
parents:
diff changeset
   421
        for (int j = 0; j < nsorts; j++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   422
            final Sort sort = (Sort) sortObjects.get(j);
7f561c08de6b Initial load
duke
parents:
diff changeset
   423
            final int length = (sort._closureVars == null) ? 0 :
7f561c08de6b Initial load
duke
parents:
diff changeset
   424
                sort._closureVars.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   425
7f561c08de6b Initial load
duke
parents:
diff changeset
   426
            for (int i = 0; i < length; i++) {
36486
b84e564d2358 8150704: XALAN: ERROR: 'No more DTM IDs are available' when transforming with lots of temporary result trees
joehw
parents: 25868
diff changeset
   427
                VariableRefBase varRef = sort._closureVars.get(i);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   428
7f561c08de6b Initial load
duke
parents:
diff changeset
   429
                // Discard duplicate variable references
7f561c08de6b Initial load
duke
parents:
diff changeset
   430
                if (dups.contains(varRef)) continue;
7f561c08de6b Initial load
duke
parents:
diff changeset
   431
7f561c08de6b Initial load
duke
parents:
diff changeset
   432
                final VariableBase var = varRef.getVariable();
7f561c08de6b Initial load
duke
parents:
diff changeset
   433
7f561c08de6b Initial load
duke
parents:
diff changeset
   434
                // Store variable in new closure
7f561c08de6b Initial load
duke
parents:
diff changeset
   435
                il.append(DUP);
7f561c08de6b Initial load
duke
parents:
diff changeset
   436
                il.append(var.loadInstruction());
7f561c08de6b Initial load
duke
parents:
diff changeset
   437
                il.append(new PUTFIELD(
7f561c08de6b Initial load
duke
parents:
diff changeset
   438
                        cpg.addFieldref(sortRecordFactoryClass, var.getEscapedName(),
7f561c08de6b Initial load
duke
parents:
diff changeset
   439
                            var.getType().toSignature())));
7f561c08de6b Initial load
duke
parents:
diff changeset
   440
                dups.add(varRef);
7f561c08de6b Initial load
duke
parents:
diff changeset
   441
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   442
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   443
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   444
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   445
    public static String compileSortRecordFactory(List<Sort> sortObjects,
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   446
        ClassGenerator classGen, MethodGenerator methodGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   447
        String sortRecordClass)
7f561c08de6b Initial load
duke
parents:
diff changeset
   448
    {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   449
        final XSLTC xsltc = (sortObjects.get(0)).getXSLTC();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   450
        final String className = xsltc.getHelperClassName();
7f561c08de6b Initial load
duke
parents:
diff changeset
   451
7f561c08de6b Initial load
duke
parents:
diff changeset
   452
        final NodeSortRecordFactGenerator sortRecordFactory =
7f561c08de6b Initial load
duke
parents:
diff changeset
   453
            new NodeSortRecordFactGenerator(className,
7f561c08de6b Initial load
duke
parents:
diff changeset
   454
                                        NODE_SORT_FACTORY,
7f561c08de6b Initial load
duke
parents:
diff changeset
   455
                                        className + ".java",
7f561c08de6b Initial load
duke
parents:
diff changeset
   456
                                        ACC_PUBLIC | ACC_SUPER | ACC_FINAL,
7f561c08de6b Initial load
duke
parents:
diff changeset
   457
                                        new String[] {},
7f561c08de6b Initial load
duke
parents:
diff changeset
   458
                                        classGen.getStylesheet());
7f561c08de6b Initial load
duke
parents:
diff changeset
   459
7f561c08de6b Initial load
duke
parents:
diff changeset
   460
        ConstantPoolGen cpg = sortRecordFactory.getConstantPool();
7f561c08de6b Initial load
duke
parents:
diff changeset
   461
7f561c08de6b Initial load
duke
parents:
diff changeset
   462
        // Add a new instance variable for each var in closure
7f561c08de6b Initial load
duke
parents:
diff changeset
   463
        final int nsorts = sortObjects.size();
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   464
        final List<VariableRefBase> dups = new ArrayList<>();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   465
7f561c08de6b Initial load
duke
parents:
diff changeset
   466
        for (int j = 0; j < nsorts; j++) {
36486
b84e564d2358 8150704: XALAN: ERROR: 'No more DTM IDs are available' when transforming with lots of temporary result trees
joehw
parents: 25868
diff changeset
   467
            final Sort sort = sortObjects.get(j);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   468
            final int length = (sort._closureVars == null) ? 0 :
7f561c08de6b Initial load
duke
parents:
diff changeset
   469
                sort._closureVars.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   470
7f561c08de6b Initial load
duke
parents:
diff changeset
   471
            for (int i = 0; i < length; i++) {
36486
b84e564d2358 8150704: XALAN: ERROR: 'No more DTM IDs are available' when transforming with lots of temporary result trees
joehw
parents: 25868
diff changeset
   472
                final VariableRefBase varRef = sort._closureVars.get(i);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   473
7f561c08de6b Initial load
duke
parents:
diff changeset
   474
                // Discard duplicate variable references
7f561c08de6b Initial load
duke
parents:
diff changeset
   475
                if (dups.contains(varRef)) continue;
7f561c08de6b Initial load
duke
parents:
diff changeset
   476
7f561c08de6b Initial load
duke
parents:
diff changeset
   477
                final VariableBase var = varRef.getVariable();
7f561c08de6b Initial load
duke
parents:
diff changeset
   478
                sortRecordFactory.addField(new Field(ACC_PUBLIC,
7f561c08de6b Initial load
duke
parents:
diff changeset
   479
                                           cpg.addUtf8(var.getEscapedName()),
7f561c08de6b Initial load
duke
parents:
diff changeset
   480
                                           cpg.addUtf8(var.getType().toSignature()),
7f561c08de6b Initial load
duke
parents:
diff changeset
   481
                                           null, cpg.getConstantPool()));
7f561c08de6b Initial load
duke
parents:
diff changeset
   482
                dups.add(varRef);
7f561c08de6b Initial load
duke
parents:
diff changeset
   483
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   484
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   485
7f561c08de6b Initial load
duke
parents:
diff changeset
   486
        // Define a constructor for this class
7f561c08de6b Initial load
duke
parents:
diff changeset
   487
        final com.sun.org.apache.bcel.internal.generic.Type[] argTypes =
7f561c08de6b Initial load
duke
parents:
diff changeset
   488
            new com.sun.org.apache.bcel.internal.generic.Type[7];
7f561c08de6b Initial load
duke
parents:
diff changeset
   489
        argTypes[0] = Util.getJCRefType(DOM_INTF_SIG);
7f561c08de6b Initial load
duke
parents:
diff changeset
   490
        argTypes[1] = Util.getJCRefType(STRING_SIG);
7f561c08de6b Initial load
duke
parents:
diff changeset
   491
        argTypes[2] = Util.getJCRefType(TRANSLET_INTF_SIG);
7f561c08de6b Initial load
duke
parents:
diff changeset
   492
        argTypes[3] = Util.getJCRefType("[" + STRING_SIG);
7f561c08de6b Initial load
duke
parents:
diff changeset
   493
        argTypes[4] = Util.getJCRefType("[" + STRING_SIG);
7f561c08de6b Initial load
duke
parents:
diff changeset
   494
  argTypes[5] = Util.getJCRefType("[" + STRING_SIG);
7f561c08de6b Initial load
duke
parents:
diff changeset
   495
  argTypes[6] = Util.getJCRefType("[" + STRING_SIG);
7f561c08de6b Initial load
duke
parents:
diff changeset
   496
7f561c08de6b Initial load
duke
parents:
diff changeset
   497
        final String[] argNames = new String[7];
7f561c08de6b Initial load
duke
parents:
diff changeset
   498
        argNames[0] = DOCUMENT_PNAME;
7f561c08de6b Initial load
duke
parents:
diff changeset
   499
        argNames[1] = "className";
7f561c08de6b Initial load
duke
parents:
diff changeset
   500
        argNames[2] = TRANSLET_PNAME;
7f561c08de6b Initial load
duke
parents:
diff changeset
   501
        argNames[3] = "order";
7f561c08de6b Initial load
duke
parents:
diff changeset
   502
        argNames[4] = "type";
7f561c08de6b Initial load
duke
parents:
diff changeset
   503
  argNames[5] = "lang";
7f561c08de6b Initial load
duke
parents:
diff changeset
   504
  argNames[6] = "case_order";
7f561c08de6b Initial load
duke
parents:
diff changeset
   505
7f561c08de6b Initial load
duke
parents:
diff changeset
   506
7f561c08de6b Initial load
duke
parents:
diff changeset
   507
        InstructionList il = new InstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
   508
        final MethodGenerator constructor =
7f561c08de6b Initial load
duke
parents:
diff changeset
   509
            new MethodGenerator(ACC_PUBLIC,
7f561c08de6b Initial load
duke
parents:
diff changeset
   510
                                com.sun.org.apache.bcel.internal.generic.Type.VOID,
7f561c08de6b Initial load
duke
parents:
diff changeset
   511
                                argTypes, argNames, "<init>",
7f561c08de6b Initial load
duke
parents:
diff changeset
   512
                                className, il, cpg);
7f561c08de6b Initial load
duke
parents:
diff changeset
   513
7f561c08de6b Initial load
duke
parents:
diff changeset
   514
        // Push all parameters onto the stack and called super.<init>()
7f561c08de6b Initial load
duke
parents:
diff changeset
   515
        il.append(ALOAD_0);
7f561c08de6b Initial load
duke
parents:
diff changeset
   516
        il.append(ALOAD_1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   517
        il.append(ALOAD_2);
7f561c08de6b Initial load
duke
parents:
diff changeset
   518
        il.append(new ALOAD(3));
7f561c08de6b Initial load
duke
parents:
diff changeset
   519
        il.append(new ALOAD(4));
7f561c08de6b Initial load
duke
parents:
diff changeset
   520
        il.append(new ALOAD(5));
7f561c08de6b Initial load
duke
parents:
diff changeset
   521
  il.append(new ALOAD(6));
7f561c08de6b Initial load
duke
parents:
diff changeset
   522
  il.append(new ALOAD(7));
7f561c08de6b Initial load
duke
parents:
diff changeset
   523
        il.append(new INVOKESPECIAL(cpg.addMethodref(NODE_SORT_FACTORY,
7f561c08de6b Initial load
duke
parents:
diff changeset
   524
            "<init>",
7f561c08de6b Initial load
duke
parents:
diff changeset
   525
            "(" + DOM_INTF_SIG
7f561c08de6b Initial load
duke
parents:
diff changeset
   526
                + STRING_SIG
7f561c08de6b Initial load
duke
parents:
diff changeset
   527
                + TRANSLET_INTF_SIG
7f561c08de6b Initial load
duke
parents:
diff changeset
   528
                + "[" + STRING_SIG
7f561c08de6b Initial load
duke
parents:
diff changeset
   529
    + "[" + STRING_SIG
7f561c08de6b Initial load
duke
parents:
diff changeset
   530
    + "[" + STRING_SIG
7f561c08de6b Initial load
duke
parents:
diff changeset
   531
                + "[" + STRING_SIG + ")V")));
7f561c08de6b Initial load
duke
parents:
diff changeset
   532
        il.append(RETURN);
7f561c08de6b Initial load
duke
parents:
diff changeset
   533
7f561c08de6b Initial load
duke
parents:
diff changeset
   534
        // Override the definition of makeNodeSortRecord()
7f561c08de6b Initial load
duke
parents:
diff changeset
   535
        il = new InstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
   536
        final MethodGenerator makeNodeSortRecord =
7f561c08de6b Initial load
duke
parents:
diff changeset
   537
            new MethodGenerator(ACC_PUBLIC,
7f561c08de6b Initial load
duke
parents:
diff changeset
   538
                Util.getJCRefType(NODE_SORT_RECORD_SIG),
7f561c08de6b Initial load
duke
parents:
diff changeset
   539
                new com.sun.org.apache.bcel.internal.generic.Type[] {
7f561c08de6b Initial load
duke
parents:
diff changeset
   540
                    com.sun.org.apache.bcel.internal.generic.Type.INT,
7f561c08de6b Initial load
duke
parents:
diff changeset
   541
                    com.sun.org.apache.bcel.internal.generic.Type.INT },
7f561c08de6b Initial load
duke
parents:
diff changeset
   542
                new String[] { "node", "last" }, "makeNodeSortRecord",
7f561c08de6b Initial load
duke
parents:
diff changeset
   543
                className, il, cpg);
7f561c08de6b Initial load
duke
parents:
diff changeset
   544
7f561c08de6b Initial load
duke
parents:
diff changeset
   545
        il.append(ALOAD_0);
7f561c08de6b Initial load
duke
parents:
diff changeset
   546
        il.append(ILOAD_1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   547
        il.append(ILOAD_2);
7f561c08de6b Initial load
duke
parents:
diff changeset
   548
        il.append(new INVOKESPECIAL(cpg.addMethodref(NODE_SORT_FACTORY,
7f561c08de6b Initial load
duke
parents:
diff changeset
   549
            "makeNodeSortRecord", "(II)" + NODE_SORT_RECORD_SIG)));
7f561c08de6b Initial load
duke
parents:
diff changeset
   550
        il.append(DUP);
7f561c08de6b Initial load
duke
parents:
diff changeset
   551
        il.append(new CHECKCAST(cpg.addClass(sortRecordClass)));
7f561c08de6b Initial load
duke
parents:
diff changeset
   552
7f561c08de6b Initial load
duke
parents:
diff changeset
   553
        // Initialize closure in record class
7f561c08de6b Initial load
duke
parents:
diff changeset
   554
        final int ndups = dups.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   555
        for (int i = 0; i < ndups; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   556
            final VariableRefBase varRef = (VariableRefBase) dups.get(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
   557
            final VariableBase var = varRef.getVariable();
7f561c08de6b Initial load
duke
parents:
diff changeset
   558
            final Type varType = var.getType();
7f561c08de6b Initial load
duke
parents:
diff changeset
   559
7f561c08de6b Initial load
duke
parents:
diff changeset
   560
            il.append(DUP);
7f561c08de6b Initial load
duke
parents:
diff changeset
   561
7f561c08de6b Initial load
duke
parents:
diff changeset
   562
            // Get field from factory class
7f561c08de6b Initial load
duke
parents:
diff changeset
   563
            il.append(ALOAD_0);
7f561c08de6b Initial load
duke
parents:
diff changeset
   564
            il.append(new GETFIELD(
7f561c08de6b Initial load
duke
parents:
diff changeset
   565
                cpg.addFieldref(className,
7f561c08de6b Initial load
duke
parents:
diff changeset
   566
                    var.getEscapedName(), varType.toSignature())));
7f561c08de6b Initial load
duke
parents:
diff changeset
   567
7f561c08de6b Initial load
duke
parents:
diff changeset
   568
            // Put field in record class
7f561c08de6b Initial load
duke
parents:
diff changeset
   569
            il.append(new PUTFIELD(
7f561c08de6b Initial load
duke
parents:
diff changeset
   570
                cpg.addFieldref(sortRecordClass,
7f561c08de6b Initial load
duke
parents:
diff changeset
   571
                    var.getEscapedName(), varType.toSignature())));
7f561c08de6b Initial load
duke
parents:
diff changeset
   572
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   573
        il.append(POP);
7f561c08de6b Initial load
duke
parents:
diff changeset
   574
        il.append(ARETURN);
7f561c08de6b Initial load
duke
parents:
diff changeset
   575
7f561c08de6b Initial load
duke
parents:
diff changeset
   576
        constructor.setMaxLocals();
7f561c08de6b Initial load
duke
parents:
diff changeset
   577
        constructor.setMaxStack();
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   578
        sortRecordFactory.addMethod(constructor);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   579
        makeNodeSortRecord.setMaxLocals();
7f561c08de6b Initial load
duke
parents:
diff changeset
   580
        makeNodeSortRecord.setMaxStack();
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   581
        sortRecordFactory.addMethod(makeNodeSortRecord);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   582
        xsltc.dumpClass(sortRecordFactory.getJavaClass());
7f561c08de6b Initial load
duke
parents:
diff changeset
   583
7f561c08de6b Initial load
duke
parents:
diff changeset
   584
        return className;
7f561c08de6b Initial load
duke
parents:
diff changeset
   585
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   586
7f561c08de6b Initial load
duke
parents:
diff changeset
   587
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   588
     * Create a new auxillary class extending NodeSortRecord.
7f561c08de6b Initial load
duke
parents:
diff changeset
   589
     */
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   590
    private static String compileSortRecord(List<Sort> sortObjects,
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   591
                                            ClassGenerator classGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   592
                                            MethodGenerator methodGen) {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   593
        final XSLTC  xsltc = sortObjects.get(0).getXSLTC();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   594
        final String className = xsltc.getHelperClassName();
7f561c08de6b Initial load
duke
parents:
diff changeset
   595
7f561c08de6b Initial load
duke
parents:
diff changeset
   596
        // This generates a new class for handling this specific sort
7f561c08de6b Initial load
duke
parents:
diff changeset
   597
        final NodeSortRecordGenerator sortRecord =
7f561c08de6b Initial load
duke
parents:
diff changeset
   598
            new NodeSortRecordGenerator(className,
7f561c08de6b Initial load
duke
parents:
diff changeset
   599
                                        NODE_SORT_RECORD,
7f561c08de6b Initial load
duke
parents:
diff changeset
   600
                                        "sort$0.java",
7f561c08de6b Initial load
duke
parents:
diff changeset
   601
                                        ACC_PUBLIC | ACC_SUPER | ACC_FINAL,
7f561c08de6b Initial load
duke
parents:
diff changeset
   602
                                        new String[] {},
7f561c08de6b Initial load
duke
parents:
diff changeset
   603
                                        classGen.getStylesheet());
7f561c08de6b Initial load
duke
parents:
diff changeset
   604
7f561c08de6b Initial load
duke
parents:
diff changeset
   605
        final ConstantPoolGen cpg = sortRecord.getConstantPool();
7f561c08de6b Initial load
duke
parents:
diff changeset
   606
7f561c08de6b Initial load
duke
parents:
diff changeset
   607
        // Add a new instance variable for each var in closure
7f561c08de6b Initial load
duke
parents:
diff changeset
   608
        final int nsorts = sortObjects.size();
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   609
        final List<VariableRefBase> dups = new ArrayList<>();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   610
7f561c08de6b Initial load
duke
parents:
diff changeset
   611
        for (int j = 0; j < nsorts; j++) {
36486
b84e564d2358 8150704: XALAN: ERROR: 'No more DTM IDs are available' when transforming with lots of temporary result trees
joehw
parents: 25868
diff changeset
   612
            final Sort sort = sortObjects.get(j);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   613
7f561c08de6b Initial load
duke
parents:
diff changeset
   614
            // Set the name of the inner class in this sort object
7f561c08de6b Initial load
duke
parents:
diff changeset
   615
            sort.setInnerClassName(className);
7f561c08de6b Initial load
duke
parents:
diff changeset
   616
7f561c08de6b Initial load
duke
parents:
diff changeset
   617
            final int length = (sort._closureVars == null) ? 0 :
7f561c08de6b Initial load
duke
parents:
diff changeset
   618
                sort._closureVars.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   619
            for (int i = 0; i < length; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   620
                final VariableRefBase varRef = (VariableRefBase) sort._closureVars.get(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
   621
7f561c08de6b Initial load
duke
parents:
diff changeset
   622
                // Discard duplicate variable references
7f561c08de6b Initial load
duke
parents:
diff changeset
   623
                if (dups.contains(varRef)) continue;
7f561c08de6b Initial load
duke
parents:
diff changeset
   624
7f561c08de6b Initial load
duke
parents:
diff changeset
   625
                final VariableBase var = varRef.getVariable();
7f561c08de6b Initial load
duke
parents:
diff changeset
   626
                sortRecord.addField(new Field(ACC_PUBLIC,
7f561c08de6b Initial load
duke
parents:
diff changeset
   627
                                    cpg.addUtf8(var.getEscapedName()),
7f561c08de6b Initial load
duke
parents:
diff changeset
   628
                                    cpg.addUtf8(var.getType().toSignature()),
7f561c08de6b Initial load
duke
parents:
diff changeset
   629
                                    null, cpg.getConstantPool()));
7f561c08de6b Initial load
duke
parents:
diff changeset
   630
                dups.add(varRef);
7f561c08de6b Initial load
duke
parents:
diff changeset
   631
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   632
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   633
36486
b84e564d2358 8150704: XALAN: ERROR: 'No more DTM IDs are available' when transforming with lots of temporary result trees
joehw
parents: 25868
diff changeset
   634
        MethodGenerator init = compileInit(sortRecord, cpg, className);
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   635
        MethodGenerator extract = compileExtract(sortObjects, sortRecord,
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   636
                                        cpg, className);
7f561c08de6b Initial load
duke
parents:
diff changeset
   637
        sortRecord.addMethod(init);
7f561c08de6b Initial load
duke
parents:
diff changeset
   638
        sortRecord.addMethod(extract);
7f561c08de6b Initial load
duke
parents:
diff changeset
   639
7f561c08de6b Initial load
duke
parents:
diff changeset
   640
        xsltc.dumpClass(sortRecord.getJavaClass());
7f561c08de6b Initial load
duke
parents:
diff changeset
   641
        return className;
7f561c08de6b Initial load
duke
parents:
diff changeset
   642
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   643
7f561c08de6b Initial load
duke
parents:
diff changeset
   644
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   645
     * Create a constructor for the new class. Updates the reference to the
7f561c08de6b Initial load
duke
parents:
diff changeset
   646
     * collator in the super calls only when the stylesheet specifies a new
7f561c08de6b Initial load
duke
parents:
diff changeset
   647
     * language in xsl:sort.
7f561c08de6b Initial load
duke
parents:
diff changeset
   648
     */
36486
b84e564d2358 8150704: XALAN: ERROR: 'No more DTM IDs are available' when transforming with lots of temporary result trees
joehw
parents: 25868
diff changeset
   649
    private static MethodGenerator compileInit(NodeSortRecordGenerator sortRecord,
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   650
                                           ConstantPoolGen cpg,
7f561c08de6b Initial load
duke
parents:
diff changeset
   651
                                           String className)
7f561c08de6b Initial load
duke
parents:
diff changeset
   652
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   653
        final InstructionList il = new InstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
   654
        final MethodGenerator init =
7f561c08de6b Initial load
duke
parents:
diff changeset
   655
            new MethodGenerator(ACC_PUBLIC,
7f561c08de6b Initial load
duke
parents:
diff changeset
   656
                                com.sun.org.apache.bcel.internal.generic.Type.VOID,
7f561c08de6b Initial load
duke
parents:
diff changeset
   657
                                null, null, "<init>", className,
7f561c08de6b Initial load
duke
parents:
diff changeset
   658
                                il, cpg);
7f561c08de6b Initial load
duke
parents:
diff changeset
   659
7f561c08de6b Initial load
duke
parents:
diff changeset
   660
        // Call the constructor in the NodeSortRecord superclass
7f561c08de6b Initial load
duke
parents:
diff changeset
   661
        il.append(ALOAD_0);
7f561c08de6b Initial load
duke
parents:
diff changeset
   662
        il.append(new INVOKESPECIAL(cpg.addMethodref(NODE_SORT_RECORD,
7f561c08de6b Initial load
duke
parents:
diff changeset
   663
                                                     "<init>", "()V")));
7f561c08de6b Initial load
duke
parents:
diff changeset
   664
7f561c08de6b Initial load
duke
parents:
diff changeset
   665
7f561c08de6b Initial load
duke
parents:
diff changeset
   666
7f561c08de6b Initial load
duke
parents:
diff changeset
   667
        il.append(RETURN);
7f561c08de6b Initial load
duke
parents:
diff changeset
   668
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   669
        return init;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   670
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   671
7f561c08de6b Initial load
duke
parents:
diff changeset
   672
7f561c08de6b Initial load
duke
parents:
diff changeset
   673
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   674
     * Compiles a method that overloads NodeSortRecord.extractValueFromDOM()
7f561c08de6b Initial load
duke
parents:
diff changeset
   675
     */
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   676
    private static MethodGenerator compileExtract(List<Sort> sortObjects,
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   677
                                         NodeSortRecordGenerator sortRecord,
7f561c08de6b Initial load
duke
parents:
diff changeset
   678
                                         ConstantPoolGen cpg,
7f561c08de6b Initial load
duke
parents:
diff changeset
   679
                                         String className) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   680
        final InstructionList il = new InstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
   681
7f561c08de6b Initial load
duke
parents:
diff changeset
   682
        // String NodeSortRecord.extractValueFromDOM(dom,node,level);
7f561c08de6b Initial load
duke
parents:
diff changeset
   683
        final CompareGenerator extractMethod =
7f561c08de6b Initial load
duke
parents:
diff changeset
   684
            new CompareGenerator(ACC_PUBLIC | ACC_FINAL,
7f561c08de6b Initial load
duke
parents:
diff changeset
   685
                                 com.sun.org.apache.bcel.internal.generic.Type.STRING,
7f561c08de6b Initial load
duke
parents:
diff changeset
   686
                                 new com.sun.org.apache.bcel.internal.generic.Type[] {
7f561c08de6b Initial load
duke
parents:
diff changeset
   687
                                     Util.getJCRefType(DOM_INTF_SIG),
7f561c08de6b Initial load
duke
parents:
diff changeset
   688
                                     com.sun.org.apache.bcel.internal.generic.Type.INT,
7f561c08de6b Initial load
duke
parents:
diff changeset
   689
                                     com.sun.org.apache.bcel.internal.generic.Type.INT,
7f561c08de6b Initial load
duke
parents:
diff changeset
   690
                                     Util.getJCRefType(TRANSLET_SIG),
7f561c08de6b Initial load
duke
parents:
diff changeset
   691
                                     com.sun.org.apache.bcel.internal.generic.Type.INT
7f561c08de6b Initial load
duke
parents:
diff changeset
   692
                                 },
7f561c08de6b Initial load
duke
parents:
diff changeset
   693
                                 new String[] { "dom",
7f561c08de6b Initial load
duke
parents:
diff changeset
   694
                                                "current",
7f561c08de6b Initial load
duke
parents:
diff changeset
   695
                                                "level",
7f561c08de6b Initial load
duke
parents:
diff changeset
   696
                                                "translet",
7f561c08de6b Initial load
duke
parents:
diff changeset
   697
                                                "last"
7f561c08de6b Initial load
duke
parents:
diff changeset
   698
                                 },
7f561c08de6b Initial load
duke
parents:
diff changeset
   699
                                 "extractValueFromDOM", className, il, cpg);
7f561c08de6b Initial load
duke
parents:
diff changeset
   700
7f561c08de6b Initial load
duke
parents:
diff changeset
   701
        // Values needed for the switch statement
7f561c08de6b Initial load
duke
parents:
diff changeset
   702
        final int levels = sortObjects.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   703
        final int match[] = new int[levels];
7f561c08de6b Initial load
duke
parents:
diff changeset
   704
        final InstructionHandle target[] = new InstructionHandle[levels];
7f561c08de6b Initial load
duke
parents:
diff changeset
   705
        InstructionHandle tblswitch = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   706
7f561c08de6b Initial load
duke
parents:
diff changeset
   707
        // Compile switch statement only if the key has multiple levels
7f561c08de6b Initial load
duke
parents:
diff changeset
   708
        if (levels > 1) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   709
            // Put the parameter to the swtich statement on the stack
7f561c08de6b Initial load
duke
parents:
diff changeset
   710
            il.append(new ILOAD(extractMethod.getLocalIndex("level")));
7f561c08de6b Initial load
duke
parents:
diff changeset
   711
            // Append the switch statement here later on
7f561c08de6b Initial load
duke
parents:
diff changeset
   712
            tblswitch = il.append(new NOP());
7f561c08de6b Initial load
duke
parents:
diff changeset
   713
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   714
7f561c08de6b Initial load
duke
parents:
diff changeset
   715
        // Append all the cases for the switch statment
7f561c08de6b Initial load
duke
parents:
diff changeset
   716
        for (int level = 0; level < levels; level++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   717
            match[level] = level;
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   718
            final Sort sort = sortObjects.get(level);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   719
            target[level] = il.append(NOP);
7f561c08de6b Initial load
duke
parents:
diff changeset
   720
            sort.translateSelect(sortRecord, extractMethod);
7f561c08de6b Initial load
duke
parents:
diff changeset
   721
            il.append(ARETURN);
7f561c08de6b Initial load
duke
parents:
diff changeset
   722
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   723
7f561c08de6b Initial load
duke
parents:
diff changeset
   724
        // Compile def. target for switch statement if key has multiple levels
7f561c08de6b Initial load
duke
parents:
diff changeset
   725
        if (levels > 1) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   726
            // Append the default target - it will _NEVER_ be reached
7f561c08de6b Initial load
duke
parents:
diff changeset
   727
            InstructionHandle defaultTarget =
7f561c08de6b Initial load
duke
parents:
diff changeset
   728
                il.append(new PUSH(cpg, EMPTYSTRING));
7f561c08de6b Initial load
duke
parents:
diff changeset
   729
            il.insert(tblswitch,new TABLESWITCH(match, target, defaultTarget));
7f561c08de6b Initial load
duke
parents:
diff changeset
   730
            il.append(ARETURN);
7f561c08de6b Initial load
duke
parents:
diff changeset
   731
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   732
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   733
        return extractMethod;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   734
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   735
}