src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/StepPattern.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) 2017, Oracle and/or its affiliates. All rights reserved.
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
     3
 * @LastModified: Oct 2017
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
/*
44797
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     6
 * Licensed to the Apache Software Foundation (ASF) under one or more
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     7
 * contributor license agreements.  See the NOTICE file distributed with
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     8
 * this work for additional information regarding copyright ownership.
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     9
 * The ASF licenses this file to You under the Apache License, Version 2.0
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    10
 * (the "License"); you may not use this file except in compliance with
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    11
 * the License.  You may obtain a copy of the License at
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *
44797
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    13
 *      http://www.apache.org/licenses/LICENSE-2.0
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * Unless required by applicable law or agreed to in writing, software
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * distributed under the License is distributed on an "AS IS" BASIS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * See the License for the specific language governing permissions and
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 * limitations under the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
package com.sun.org.apache.xalan.internal.xsltc.compiler;
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.ASTORE;
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.GETFIELD;
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
import com.sun.org.apache.bcel.internal.generic.GOTO;
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
import com.sun.org.apache.bcel.internal.generic.GOTO_W;
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
import com.sun.org.apache.bcel.internal.generic.IFLT;
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
import com.sun.org.apache.bcel.internal.generic.IFNE;
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
import com.sun.org.apache.bcel.internal.generic.IFNONNULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
import com.sun.org.apache.bcel.internal.generic.IF_ICMPEQ;
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
import com.sun.org.apache.bcel.internal.generic.IF_ICMPLT;
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
import com.sun.org.apache.bcel.internal.generic.IF_ICMPNE;
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
import com.sun.org.apache.bcel.internal.generic.ILOAD;
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE;
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
import com.sun.org.apache.bcel.internal.generic.INVOKESPECIAL;
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
import com.sun.org.apache.bcel.internal.generic.ISTORE;
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
import com.sun.org.apache.bcel.internal.generic.InstructionHandle;
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
import com.sun.org.apache.bcel.internal.generic.InstructionList;
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
import com.sun.org.apache.bcel.internal.generic.LocalVariableGen;
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
import com.sun.org.apache.bcel.internal.generic.NEW;
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
import com.sun.org.apache.bcel.internal.generic.PUSH;
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
import com.sun.org.apache.bcel.internal.generic.PUTFIELD;
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
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;
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
import com.sun.org.apache.xml.internal.dtm.DTM;
47359
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
 * @author Jacek Ambroziak
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
 * @author Santiago Pericas-Geertsen
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
 * @author Erwin Bolwidt <ejb@klomp.org>
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
class StepPattern extends RelativePathPattern {
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
    private static final int NO_CONTEXT = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
    private static final int SIMPLE_CONTEXT = 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
    private static final int GENERAL_CONTEXT = 2;
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
    protected final int _axis;
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
    protected final int _nodeType;
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    70
    protected List<Predicate> _predicates;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
    private Step    _step = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
    private boolean _isEpsilon = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
    private int     _contextCase;
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
    private double  _priority = Double.MAX_VALUE;
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    78
    public StepPattern(int axis, int nodeType, List<Predicate> predicates) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
        _axis = axis;
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
        _nodeType = nodeType;
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
        _predicates = predicates;
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
    public void setParser(Parser parser) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
        super.setParser(parser);
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
        if (_predicates != null) {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    87
            for (Predicate exp : _predicates) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
                exp.setParser(parser);
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
                exp.setParent(this);
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
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
    public int getNodeType() {
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
        return _nodeType;
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
    public void setPriority(double priority) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
        _priority = priority;
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
    public StepPattern getKernelPattern() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
        return this;
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
    public boolean isWildcard() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
        return _isEpsilon && hasPredicates() == false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   110
    public StepPattern setPredicates(List<Predicate> predicates) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
        _predicates = predicates;
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
        return(this);
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
    protected boolean hasPredicates() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
        return _predicates != null && _predicates.size() > 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
    public double getDefaultPriority() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
        if (_priority != Double.MAX_VALUE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
            return _priority;
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
        if (hasPredicates()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
            return 0.5;
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
            switch(_nodeType) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
            case -1:
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
                return -0.5;    // node()
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
            case 0:
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
                return 0.0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
            default:
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
                return (_nodeType >= NodeTest.GTYPE) ? 0.0 : -0.5;
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
    public int getAxis() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
        return _axis;
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
    public void reduceKernelPattern() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
        _isEpsilon = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
    public String toString() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
        final StringBuffer buffer = new StringBuffer("stepPattern(\"");
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   149
        buffer.append(Axis.getNames(_axis))
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
            .append("\", ")
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
            .append(_isEpsilon ?
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
                        ("epsilon{" + Integer.toString(_nodeType) + "}") :
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
                         Integer.toString(_nodeType));
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
        if (_predicates != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
            buffer.append(", ").append(_predicates.toString());
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
        return buffer.append(')').toString();
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
    private int analyzeCases() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
        boolean noContext = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
        final int n = _predicates.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
        for (int i = 0; i < n && noContext; i++) {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   164
            Predicate pred = _predicates.get(i);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
            if (pred.isNthPositionFilter() ||
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
                pred.hasPositionCall() ||
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
                pred.hasLastCall())
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
                noContext = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
        if (noContext) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
            return NO_CONTEXT;
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
        else if (n == 1) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
            return SIMPLE_CONTEXT;
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
        return GENERAL_CONTEXT;
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
    private String getNextFieldName() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
        return  "__step_pattern_iter_" + getXSLTC().nextStepPatternSerial();
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
    public Type typeCheck(SymbolTable stable) throws TypeCheckError {
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
        if (hasPredicates()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
            // Type check all the predicates (e -> position() = e)
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   189
            for (Predicate pred : _predicates) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
                pred.typeCheck(stable);
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
            // Analyze context cases
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
            _contextCase = analyzeCases();
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
            Step step = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
            // Create an instance of Step to do the translation
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
            if (_contextCase == SIMPLE_CONTEXT) {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   200
                Predicate pred = _predicates.get(0);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
                if (pred.isNthPositionFilter()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
                    _contextCase = GENERAL_CONTEXT;
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
                    step = new Step(_axis, _nodeType, _predicates);
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
                } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
                    step = new Step(_axis, _nodeType, null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
            } else if (_contextCase == GENERAL_CONTEXT) {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   208
                for (Predicate pred : _predicates) {
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   209
                    pred.dontOptimize();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
                step = new Step(_axis, _nodeType, _predicates);
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
            if (step != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
                step.setParser(getParser());
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
                step.typeCheck(stable);
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
                _step = step;
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
        return _axis == Axis.CHILD ? Type.Element : Type.Attribute;
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
    private void translateKernel(ClassGenerator classGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
                                 MethodGenerator methodGen) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
        final ConstantPoolGen cpg = classGen.getConstantPool();
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
        final InstructionList il = methodGen.getInstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
        if (_nodeType == DTM.ELEMENT_NODE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
            final int check = cpg.addInterfaceMethodref(DOM_INTF,
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
                                                        "isElement", "(I)Z");
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
            il.append(methodGen.loadDOM());
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
            il.append(SWAP);
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
            il.append(new INVOKEINTERFACE(check, 2));
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
            // Need to allow for long jumps here
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
            final BranchHandle icmp = il.append(new IFNE(null));
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
            _falseList.add(il.append(new GOTO_W(null)));
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
            icmp.setTarget(il.append(NOP));
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
        else if (_nodeType == DTM.ATTRIBUTE_NODE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
            final int check = cpg.addInterfaceMethodref(DOM_INTF,
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
                                                        "isAttribute", "(I)Z");
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
            il.append(methodGen.loadDOM());
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
            il.append(SWAP);
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
            il.append(new INVOKEINTERFACE(check, 2));
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
            // Need to allow for long jumps here
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
            final BranchHandle icmp = il.append(new IFNE(null));
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
            _falseList.add(il.append(new GOTO_W(null)));
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
            icmp.setTarget(il.append(NOP));
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
            // context node is on the stack
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
            final int getEType = cpg.addInterfaceMethodref(DOM_INTF,
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
                                                          "getExpandedTypeID",
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
                                                          "(I)I");
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
            il.append(methodGen.loadDOM());
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
            il.append(SWAP);
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
            il.append(new INVOKEINTERFACE(getEType, 2));
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
            il.append(new PUSH(cpg, _nodeType));
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
            // Need to allow for long jumps here
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
            final BranchHandle icmp = il.append(new IF_ICMPEQ(null));
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
            _falseList.add(il.append(new GOTO_W(null)));
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
            icmp.setTarget(il.append(NOP));
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
    private void translateNoContext(ClassGenerator classGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
                                    MethodGenerator methodGen) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
        final ConstantPoolGen cpg = classGen.getConstantPool();
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
        final InstructionList il = methodGen.getInstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
        // Push current node on the stack
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
        il.append(methodGen.loadCurrentNode());
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
        il.append(SWAP);
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
        // Overwrite current node with matching node
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
        il.append(methodGen.storeCurrentNode());
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
        // If pattern not reduced then check kernel
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
        if (!_isEpsilon) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
            il.append(methodGen.loadCurrentNode());
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
            translateKernel(classGen, methodGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
        // Compile the expressions within the predicates
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   289
        for (Predicate pred : _predicates) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
            Expression exp = pred.getExpr();
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
            exp.translateDesynthesized(classGen, methodGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
            _trueList.append(exp._trueList);
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
            _falseList.append(exp._falseList);
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
        // Backpatch true list and restore current iterator/node
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
        InstructionHandle restore;
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
        restore = il.append(methodGen.storeCurrentNode());
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
        backPatchTrueList(restore);
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
        BranchHandle skipFalse = il.append(new GOTO(null));
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
        // Backpatch false list and restore current iterator/node
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
        restore = il.append(methodGen.storeCurrentNode());
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
        backPatchFalseList(restore);
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
        _falseList.add(il.append(new GOTO(null)));
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
        // True list falls through
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
        skipFalse.setTarget(il.append(NOP));
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
7f561c08de6b Initial load
duke
parents:
diff changeset
   311
    private void translateSimpleContext(ClassGenerator classGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   312
                                        MethodGenerator methodGen) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
        int index;
7f561c08de6b Initial load
duke
parents:
diff changeset
   314
        final ConstantPoolGen cpg = classGen.getConstantPool();
7f561c08de6b Initial load
duke
parents:
diff changeset
   315
        final InstructionList il = methodGen.getInstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
   316
7f561c08de6b Initial load
duke
parents:
diff changeset
   317
        // Store matching node into a local variable
7f561c08de6b Initial load
duke
parents:
diff changeset
   318
        LocalVariableGen match;
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
        match = methodGen.addLocalVariable("step_pattern_tmp1",
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
                                           Util.getJCRefType(NODE_SIG),
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   321
                                           null, null);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   322
        match.setStart(il.append(new ISTORE(match.getIndex())));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
        // If pattern not reduced then check kernel
7f561c08de6b Initial load
duke
parents:
diff changeset
   325
        if (!_isEpsilon) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   326
            il.append(new ILOAD(match.getIndex()));
7f561c08de6b Initial load
duke
parents:
diff changeset
   327
            translateKernel(classGen, methodGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   328
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   329
7f561c08de6b Initial load
duke
parents:
diff changeset
   330
        // Push current iterator and current node on the stack
7f561c08de6b Initial load
duke
parents:
diff changeset
   331
        il.append(methodGen.loadCurrentNode());
7f561c08de6b Initial load
duke
parents:
diff changeset
   332
        il.append(methodGen.loadIterator());
7f561c08de6b Initial load
duke
parents:
diff changeset
   333
7f561c08de6b Initial load
duke
parents:
diff changeset
   334
        // Create a new matching iterator using the matching node
7f561c08de6b Initial load
duke
parents:
diff changeset
   335
        index = cpg.addMethodref(MATCHING_ITERATOR, "<init>",
7f561c08de6b Initial load
duke
parents:
diff changeset
   336
                                 "(I" + NODE_ITERATOR_SIG + ")V");
7f561c08de6b Initial load
duke
parents:
diff changeset
   337
7f561c08de6b Initial load
duke
parents:
diff changeset
   338
        // Backwards branches are prohibited if an uninitialized object is
7f561c08de6b Initial load
duke
parents:
diff changeset
   339
        // on the stack by section 4.9.4 of the JVM Specification, 2nd Ed.
7f561c08de6b Initial load
duke
parents:
diff changeset
   340
        // We don't know whether this code might contain backwards branches,
7f561c08de6b Initial load
duke
parents:
diff changeset
   341
        // so we mustn't create the new object until after we've created
7f561c08de6b Initial load
duke
parents:
diff changeset
   342
        // the suspect arguments to its constructor.  Instead we calculate
7f561c08de6b Initial load
duke
parents:
diff changeset
   343
        // the values of the arguments to the constructor first, store them
7f561c08de6b Initial load
duke
parents:
diff changeset
   344
        // in temporary variables, create the object and reload the
7f561c08de6b Initial load
duke
parents:
diff changeset
   345
        // arguments from the temporaries to avoid the problem.
7f561c08de6b Initial load
duke
parents:
diff changeset
   346
7f561c08de6b Initial load
duke
parents:
diff changeset
   347
        _step.translate(classGen, methodGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   348
        LocalVariableGen stepIteratorTemp =
7f561c08de6b Initial load
duke
parents:
diff changeset
   349
                methodGen.addLocalVariable("step_pattern_tmp2",
7f561c08de6b Initial load
duke
parents:
diff changeset
   350
                                           Util.getJCRefType(NODE_ITERATOR_SIG),
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   351
                                           null, null);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   352
        stepIteratorTemp.setStart(
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   353
                il.append(new ASTORE(stepIteratorTemp.getIndex())));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   354
7f561c08de6b Initial load
duke
parents:
diff changeset
   355
        il.append(new NEW(cpg.addClass(MATCHING_ITERATOR)));
7f561c08de6b Initial load
duke
parents:
diff changeset
   356
        il.append(DUP);
7f561c08de6b Initial load
duke
parents:
diff changeset
   357
        il.append(new ILOAD(match.getIndex()));
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   358
        stepIteratorTemp.setEnd(
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   359
                il.append(new ALOAD(stepIteratorTemp.getIndex())));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   360
        il.append(new INVOKESPECIAL(index));
7f561c08de6b Initial load
duke
parents:
diff changeset
   361
7f561c08de6b Initial load
duke
parents:
diff changeset
   362
        // Get the parent of the matching node
7f561c08de6b Initial load
duke
parents:
diff changeset
   363
        il.append(methodGen.loadDOM());
7f561c08de6b Initial load
duke
parents:
diff changeset
   364
        il.append(new ILOAD(match.getIndex()));
7f561c08de6b Initial load
duke
parents:
diff changeset
   365
        index = cpg.addInterfaceMethodref(DOM_INTF, GET_PARENT, GET_PARENT_SIG);
7f561c08de6b Initial load
duke
parents:
diff changeset
   366
        il.append(new INVOKEINTERFACE(index, 2));
7f561c08de6b Initial load
duke
parents:
diff changeset
   367
7f561c08de6b Initial load
duke
parents:
diff changeset
   368
        // Start the iterator with the parent
7f561c08de6b Initial load
duke
parents:
diff changeset
   369
        il.append(methodGen.setStartNode());
7f561c08de6b Initial load
duke
parents:
diff changeset
   370
7f561c08de6b Initial load
duke
parents:
diff changeset
   371
        // Overwrite current iterator and current node
7f561c08de6b Initial load
duke
parents:
diff changeset
   372
        il.append(methodGen.storeIterator());
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   373
        match.setEnd(il.append(new ILOAD(match.getIndex())));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   374
        il.append(methodGen.storeCurrentNode());
7f561c08de6b Initial load
duke
parents:
diff changeset
   375
7f561c08de6b Initial load
duke
parents:
diff changeset
   376
        // Translate the expression of the predicate
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   377
        Predicate pred = _predicates.get(0);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   378
        Expression exp = pred.getExpr();
7f561c08de6b Initial load
duke
parents:
diff changeset
   379
        exp.translateDesynthesized(classGen, methodGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   380
7f561c08de6b Initial load
duke
parents:
diff changeset
   381
        // Backpatch true list and restore current iterator/node
7f561c08de6b Initial load
duke
parents:
diff changeset
   382
        InstructionHandle restore = il.append(methodGen.storeIterator());
7f561c08de6b Initial load
duke
parents:
diff changeset
   383
        il.append(methodGen.storeCurrentNode());
7f561c08de6b Initial load
duke
parents:
diff changeset
   384
        exp.backPatchTrueList(restore);
7f561c08de6b Initial load
duke
parents:
diff changeset
   385
        BranchHandle skipFalse = il.append(new GOTO(null));
7f561c08de6b Initial load
duke
parents:
diff changeset
   386
7f561c08de6b Initial load
duke
parents:
diff changeset
   387
        // Backpatch false list and restore current iterator/node
7f561c08de6b Initial load
duke
parents:
diff changeset
   388
        restore = il.append(methodGen.storeIterator());
7f561c08de6b Initial load
duke
parents:
diff changeset
   389
        il.append(methodGen.storeCurrentNode());
7f561c08de6b Initial load
duke
parents:
diff changeset
   390
        exp.backPatchFalseList(restore);
7f561c08de6b Initial load
duke
parents:
diff changeset
   391
        _falseList.add(il.append(new GOTO(null)));
7f561c08de6b Initial load
duke
parents:
diff changeset
   392
7f561c08de6b Initial load
duke
parents:
diff changeset
   393
        // True list falls through
7f561c08de6b Initial load
duke
parents:
diff changeset
   394
        skipFalse.setTarget(il.append(NOP));
7f561c08de6b Initial load
duke
parents:
diff changeset
   395
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   396
7f561c08de6b Initial load
duke
parents:
diff changeset
   397
    private void translateGeneralContext(ClassGenerator classGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   398
                                         MethodGenerator methodGen) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   399
        final ConstantPoolGen cpg = classGen.getConstantPool();
7f561c08de6b Initial load
duke
parents:
diff changeset
   400
        final InstructionList il = methodGen.getInstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
   401
7f561c08de6b Initial load
duke
parents:
diff changeset
   402
        int iteratorIndex = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   403
        BranchHandle ifBlock = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   404
        LocalVariableGen iter, node, node2;
7f561c08de6b Initial load
duke
parents:
diff changeset
   405
        final String iteratorName = getNextFieldName();
7f561c08de6b Initial load
duke
parents:
diff changeset
   406
7f561c08de6b Initial load
duke
parents:
diff changeset
   407
        // Store node on the stack into a local variable
7f561c08de6b Initial load
duke
parents:
diff changeset
   408
        node = methodGen.addLocalVariable("step_pattern_tmp1",
7f561c08de6b Initial load
duke
parents:
diff changeset
   409
                                          Util.getJCRefType(NODE_SIG),
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   410
                                          null, null);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   411
        node.setStart(il.append(new ISTORE(node.getIndex())));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   412
7f561c08de6b Initial load
duke
parents:
diff changeset
   413
        // Create a new local to store the iterator
7f561c08de6b Initial load
duke
parents:
diff changeset
   414
        iter = methodGen.addLocalVariable("step_pattern_tmp2",
7f561c08de6b Initial load
duke
parents:
diff changeset
   415
                                          Util.getJCRefType(NODE_ITERATOR_SIG),
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   416
                                          null, null);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   417
7f561c08de6b Initial load
duke
parents:
diff changeset
   418
        // Add a new private field if this is the main class
7f561c08de6b Initial load
duke
parents:
diff changeset
   419
        if (!classGen.isExternal()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   420
            final Field iterator =
7f561c08de6b Initial load
duke
parents:
diff changeset
   421
                new Field(ACC_PRIVATE,
7f561c08de6b Initial load
duke
parents:
diff changeset
   422
                          cpg.addUtf8(iteratorName),
7f561c08de6b Initial load
duke
parents:
diff changeset
   423
                          cpg.addUtf8(NODE_ITERATOR_SIG),
7f561c08de6b Initial load
duke
parents:
diff changeset
   424
                          null, cpg.getConstantPool());
7f561c08de6b Initial load
duke
parents:
diff changeset
   425
            classGen.addField(iterator);
7f561c08de6b Initial load
duke
parents:
diff changeset
   426
            iteratorIndex = cpg.addFieldref(classGen.getClassName(),
7f561c08de6b Initial load
duke
parents:
diff changeset
   427
                                            iteratorName,
7f561c08de6b Initial load
duke
parents:
diff changeset
   428
                                            NODE_ITERATOR_SIG);
7f561c08de6b Initial load
duke
parents:
diff changeset
   429
7f561c08de6b Initial load
duke
parents:
diff changeset
   430
            il.append(classGen.loadTranslet());
7f561c08de6b Initial load
duke
parents:
diff changeset
   431
            il.append(new GETFIELD(iteratorIndex));
7f561c08de6b Initial load
duke
parents:
diff changeset
   432
            il.append(DUP);
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   433
            iter.setStart(il.append(new ASTORE(iter.getIndex())));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   434
            ifBlock = il.append(new IFNONNULL(null));
7f561c08de6b Initial load
duke
parents:
diff changeset
   435
            il.append(classGen.loadTranslet());
7f561c08de6b Initial load
duke
parents:
diff changeset
   436
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   437
7f561c08de6b Initial load
duke
parents:
diff changeset
   438
        // Compile the step created at type checking time
7f561c08de6b Initial load
duke
parents:
diff changeset
   439
        _step.translate(classGen, methodGen);
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   440
        InstructionHandle iterStore = il.append(new ASTORE(iter.getIndex()));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   441
7f561c08de6b Initial load
duke
parents:
diff changeset
   442
        // If in the main class update the field too
7f561c08de6b Initial load
duke
parents:
diff changeset
   443
        if (!classGen.isExternal()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   444
            il.append(new ALOAD(iter.getIndex()));
7f561c08de6b Initial load
duke
parents:
diff changeset
   445
            il.append(new PUTFIELD(iteratorIndex));
7f561c08de6b Initial load
duke
parents:
diff changeset
   446
            ifBlock.setTarget(il.append(NOP));
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   447
        } else {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   448
            // If class is not external, start of range for iter variable was
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   449
            // set above
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   450
            iter.setStart(iterStore);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   451
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   452
7f561c08de6b Initial load
duke
parents:
diff changeset
   453
        // Get the parent of the node on the stack
7f561c08de6b Initial load
duke
parents:
diff changeset
   454
        il.append(methodGen.loadDOM());
7f561c08de6b Initial load
duke
parents:
diff changeset
   455
        il.append(new ILOAD(node.getIndex()));
7f561c08de6b Initial load
duke
parents:
diff changeset
   456
        int index = cpg.addInterfaceMethodref(DOM_INTF,
7f561c08de6b Initial load
duke
parents:
diff changeset
   457
                                              GET_PARENT, GET_PARENT_SIG);
7f561c08de6b Initial load
duke
parents:
diff changeset
   458
        il.append(new INVOKEINTERFACE(index, 2));
7f561c08de6b Initial load
duke
parents:
diff changeset
   459
7f561c08de6b Initial load
duke
parents:
diff changeset
   460
        // Initialize the iterator with the parent
7f561c08de6b Initial load
duke
parents:
diff changeset
   461
        il.append(new ALOAD(iter.getIndex()));
7f561c08de6b Initial load
duke
parents:
diff changeset
   462
        il.append(SWAP);
7f561c08de6b Initial load
duke
parents:
diff changeset
   463
        il.append(methodGen.setStartNode());
7f561c08de6b Initial load
duke
parents:
diff changeset
   464
7f561c08de6b Initial load
duke
parents:
diff changeset
   465
        /*
7f561c08de6b Initial load
duke
parents:
diff changeset
   466
         * Inline loop:
7f561c08de6b Initial load
duke
parents:
diff changeset
   467
         *
7f561c08de6b Initial load
duke
parents:
diff changeset
   468
         * int node2;
7f561c08de6b Initial load
duke
parents:
diff changeset
   469
         * while ((node2 = iter.next()) != NodeIterator.END
7f561c08de6b Initial load
duke
parents:
diff changeset
   470
         *                && node2 < node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   471
         * return node2 == node;
7f561c08de6b Initial load
duke
parents:
diff changeset
   472
         */
7f561c08de6b Initial load
duke
parents:
diff changeset
   473
        BranchHandle skipNext;
7f561c08de6b Initial load
duke
parents:
diff changeset
   474
        InstructionHandle begin, next;
7f561c08de6b Initial load
duke
parents:
diff changeset
   475
        node2 = methodGen.addLocalVariable("step_pattern_tmp3",
7f561c08de6b Initial load
duke
parents:
diff changeset
   476
                                           Util.getJCRefType(NODE_SIG),
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   477
                                           null, null);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   478
7f561c08de6b Initial load
duke
parents:
diff changeset
   479
        skipNext = il.append(new GOTO(null));
7f561c08de6b Initial load
duke
parents:
diff changeset
   480
        next = il.append(new ALOAD(iter.getIndex()));
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   481
        node2.setStart(next);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   482
        begin = il.append(methodGen.nextNode());
7f561c08de6b Initial load
duke
parents:
diff changeset
   483
        il.append(DUP);
7f561c08de6b Initial load
duke
parents:
diff changeset
   484
        il.append(new ISTORE(node2.getIndex()));
7f561c08de6b Initial load
duke
parents:
diff changeset
   485
        _falseList.add(il.append(new IFLT(null)));      // NodeIterator.END
7f561c08de6b Initial load
duke
parents:
diff changeset
   486
7f561c08de6b Initial load
duke
parents:
diff changeset
   487
        il.append(new ILOAD(node2.getIndex()));
7f561c08de6b Initial load
duke
parents:
diff changeset
   488
        il.append(new ILOAD(node.getIndex()));
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   489
        iter.setEnd(il.append(new IF_ICMPLT(next)));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   490
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   491
        node2.setEnd(il.append(new ILOAD(node2.getIndex())));
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   492
        node.setEnd(il.append(new ILOAD(node.getIndex())));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   493
        _falseList.add(il.append(new IF_ICMPNE(null)));
7f561c08de6b Initial load
duke
parents:
diff changeset
   494
7f561c08de6b Initial load
duke
parents:
diff changeset
   495
        skipNext.setTarget(begin);
7f561c08de6b Initial load
duke
parents:
diff changeset
   496
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   497
7f561c08de6b Initial load
duke
parents:
diff changeset
   498
    public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   499
        final ConstantPoolGen cpg = classGen.getConstantPool();
7f561c08de6b Initial load
duke
parents:
diff changeset
   500
        final InstructionList il = methodGen.getInstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
   501
7f561c08de6b Initial load
duke
parents:
diff changeset
   502
        if (hasPredicates()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   503
            switch (_contextCase) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   504
            case NO_CONTEXT:
7f561c08de6b Initial load
duke
parents:
diff changeset
   505
                translateNoContext(classGen, methodGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   506
                break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   507
7f561c08de6b Initial load
duke
parents:
diff changeset
   508
            case SIMPLE_CONTEXT:
7f561c08de6b Initial load
duke
parents:
diff changeset
   509
                translateSimpleContext(classGen, methodGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   510
                break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   511
7f561c08de6b Initial load
duke
parents:
diff changeset
   512
            default:
7f561c08de6b Initial load
duke
parents:
diff changeset
   513
                translateGeneralContext(classGen, methodGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   514
                break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   515
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   516
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   517
        else if (isWildcard()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   518
            il.append(POP);     // true list falls through
7f561c08de6b Initial load
duke
parents:
diff changeset
   519
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   520
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   521
            translateKernel(classGen, methodGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   522
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   523
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   524
}